use of org.apache.felix.scr.impl.metadata.ServiceMetadata in project felix by apache.
the class XmlHandler method startElement.
/**
* Method called when a tag opens
*
* @param uri
* @param localName
* @param attributes
* @exception ParseException
*/
public void startElement(String uri, String localName, Attributes attributes) throws ParseException {
// So we check this for the first element, we receive.
if (firstElement) {
firstElement = false;
if (localName.equals("component") && "".equals(uri)) {
overrideNamespace = NAMESPACE_URI;
}
}
if (overrideNamespace != null && "".equals(uri)) {
uri = overrideNamespace;
}
// the namespace - we allow both: with or without namespace!
if (this.isComponent && "".equals(uri)) {
uri = NAMESPACE_URI;
}
// get the namespace code for the namespace uri
DSVersion namespaceCode = NAMESPACE_CODE_MAP.get(uri);
// from now on uri points to the namespace
if (namespaceCode != null) {
try {
// 112.4.3 Component Element
if (localName.equals("component")) {
this.isComponent = true;
// Create a new ComponentMetadata
m_currentComponent = new ComponentMetadata(namespaceCode);
// name attribute is optional (since DS 1.1)
if (attributes.getAttribute("name") != null) {
m_currentComponent.setName(attributes.getAttribute("name"));
}
// enabled attribute is optional
if (attributes.getAttribute("enabled") != null) {
m_currentComponent.setEnabled(attributes.getAttribute("enabled").equals("true"));
}
// immediate attribute is optional
if (attributes.getAttribute("immediate") != null) {
m_currentComponent.setImmediate(attributes.getAttribute("immediate").equals("true"));
}
// factory attribute is optional
if (attributes.getAttribute("factory") != null) {
m_currentComponent.setFactoryIdentifier(attributes.getAttribute("factory"));
}
// configuration-policy is optional (since DS 1.1)
if (attributes.getAttribute("configuration-policy") != null) {
m_currentComponent.setConfigurationPolicy(attributes.getAttribute("configuration-policy"));
}
// activate attribute is optional (since DS 1.1)
if (attributes.getAttribute("activate") != null) {
m_currentComponent.setActivate(attributes.getAttribute("activate"));
}
// deactivate attribute is optional (since DS 1.1)
if (attributes.getAttribute("deactivate") != null) {
m_currentComponent.setDeactivate(attributes.getAttribute("deactivate"));
}
// modified attribute is optional (since DS 1.1)
if (attributes.getAttribute("modified") != null) {
m_currentComponent.setModified(attributes.getAttribute("modified"));
}
// configuration-pid attribute is optional (since DS 1.2)
String configurationPidString = attributes.getAttribute("configuration-pid");
if (configurationPidString != null) {
String[] configurationPid = configurationPidString.split(" ");
m_currentComponent.setConfigurationPid(configurationPid);
}
m_currentComponent.setConfigurableServiceProperties("true".equals(attributes.getAttribute(NAMESPACE_URI_1_0_FELIX_EXTENSIONS, CONFIGURABLE_SERVICE_PROPERTIES)));
m_currentComponent.setPersistentFactoryComponent("true".equals(attributes.getAttribute(NAMESPACE_URI_1_0_FELIX_EXTENSIONS, PERSISTENT_FACTORY_COMPONENT)));
m_currentComponent.setDeleteCallsModify("true".equals(attributes.getAttribute(NAMESPACE_URI_1_0_FELIX_EXTENSIONS, DELETE_CALLS_MODIFY)));
if (attributes.getAttribute(NAMESPACE_URI_1_0_FELIX_EXTENSIONS, OBSOLETE_FACTORY_COMPONENT_FACTORY) != null) {
m_currentComponent.setObsoleteFactoryComponentFactory("true".equals(attributes.getAttribute(NAMESPACE_URI_1_0_FELIX_EXTENSIONS, OBSOLETE_FACTORY_COMPONENT_FACTORY)));
} else if (!namespaceCode.isDS13()) {
m_currentComponent.setObsoleteFactoryComponentFactory(m_globalObsoleteFactoryComponentFactory);
}
m_currentComponent.setConfigureWithInterfaces("true".equals(attributes.getAttribute(NAMESPACE_URI_1_0_FELIX_EXTENSIONS, CONFIGURE_WITH_INTERFACES)));
m_currentComponent.setDelayedKeepInstances(m_globalDelayedKeepInstances || "true".equals(attributes.getAttribute(NAMESPACE_URI_1_0_FELIX_EXTENSIONS, DELAYED_KEEP_INSTANCES)));
// Add this component to the list
m_components.add(m_currentComponent);
} else // not inside a component element, ignore current element
if (!this.isComponent) {
m_logger.log(LogService.LOG_DEBUG, "Not currently parsing a component; ignoring element {0} (bundle {1})", new Object[] { localName, m_bundle.getLocation() }, null, null, null);
} else // 112.4.4 Implementation
if (localName.equals("implementation")) {
// Set the implementation class name (mandatory)
m_currentComponent.setImplementationClassName(attributes.getAttribute("class"));
} else // 112.4.5 [...] Property Elements
if (localName.equals("property")) {
PropertyMetadata prop = new PropertyMetadata();
// name attribute is mandatory
prop.setName(attributes.getAttribute("name"));
// type attribute is optional
if (attributes.getAttribute("type") != null) {
prop.setType(attributes.getAttribute("type"));
}
// 112.4.5: If the value attribute is specified, the body of the element is ignored.
if (attributes.getAttribute("value") != null) {
prop.setValue(attributes.getAttribute("value"));
m_currentComponent.addProperty(prop);
} else {
// hold the metadata pending
m_pendingProperty = prop;
}
} else // 112.4.5 Properties [...] Elements
if (localName.equals("properties")) {
readPropertiesEntry(attributes.getAttribute("entry"));
} else // 112.4.6 Service Element
if (localName.equals("service")) {
m_currentService = new ServiceMetadata();
// servicefactory attribute is optional
if (attributes.getAttribute("servicefactory") != null) {
m_currentService.setServiceFactory(attributes.getAttribute("servicefactory").equals("true"));
}
if (attributes.getAttribute("scope") != null) {
m_currentService.setScope(attributes.getAttribute("scope"));
}
m_currentComponent.setService(m_currentService);
} else if (localName.equals("provide")) {
m_currentService.addProvide(attributes.getAttribute("interface"));
} else // 112.4.7 Reference element
if (localName.equals("reference")) {
ReferenceMetadata ref = new ReferenceMetadata();
// name attribute is optional (since DS 1.1)
if (attributes.getAttribute("name") != null) {
ref.setName(attributes.getAttribute("name"));
}
ref.setInterface(attributes.getAttribute("interface"));
// Cardinality
if (attributes.getAttribute("cardinality") != null) {
ref.setCardinality(attributes.getAttribute("cardinality"));
}
if (attributes.getAttribute("policy") != null) {
ref.setPolicy(attributes.getAttribute("policy"));
}
if (attributes.getAttribute("policy-option") != null) {
ref.setPolicyOption(attributes.getAttribute("policy-option"));
}
if (attributes.getAttribute("scope") != null) {
ref.setScope(attributes.getAttribute("scope"));
}
if (attributes.getAttribute("target") != null) {
ref.setTarget(attributes.getAttribute("target"));
PropertyMetadata prop = new PropertyMetadata();
prop.setName((ref.getName() == null ? ref.getInterface() : ref.getName()) + ".target");
prop.setValue(attributes.getAttribute("target"));
m_currentComponent.addProperty(prop);
}
// method reference
ref.setBind(attributes.getAttribute("bind"));
ref.setUpdated(attributes.getAttribute("updated"));
ref.setUnbind(attributes.getAttribute("unbind"));
// field reference
ref.setField(attributes.getAttribute("field"));
ref.setFieldOption(attributes.getAttribute("field-option"));
ref.setFieldCollectionType(attributes.getAttribute("field-collection-type"));
m_currentComponent.addDependency(ref);
} else // used by the Maven SCR Plugin, which is just silently ignored)
if (!localName.equals("components")) {
m_logger.log(LogService.LOG_DEBUG, "Ignoring unsupported element {0} (bundle {1})", new Object[] { localName, m_bundle.getLocation() }, null, null, null);
}
} catch (Exception ex) {
throw new ParseException("Exception during parsing", ex);
}
} else // used by the Maven SCR Plugin, which is just silently ignored)
if (!localName.equals("components")) {
m_logger.log(LogService.LOG_DEBUG, "Ignoring unsupported element '{'{0}'}'{1} (bundle {2})", new Object[] { uri, localName, m_bundle.getLocation() }, null, null, null);
}
}
use of org.apache.felix.scr.impl.metadata.ServiceMetadata in project felix by apache.
the class AbstractComponentManager method hasServiceRegistrationPermissions.
private boolean hasServiceRegistrationPermissions() {
boolean allowed = true;
if (System.getSecurityManager() != null) {
final ServiceMetadata serviceMetadata = getComponentMetadata().getServiceMetadata();
if (serviceMetadata != null) {
final String[] services = serviceMetadata.getProvides();
if (services != null && services.length > 0) {
final Bundle bundle = getBundle();
for (String service : services) {
final Permission perm = new ServicePermission(service, ServicePermission.REGISTER);
if (!bundle.hasPermission(perm)) {
log(LogService.LOG_DEBUG, "Permission to register service {0} is denied", new Object[] { service }, null);
allowed = false;
}
}
}
}
}
// no security manager or no services to register
return allowed;
}
Aggregations