use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.
the class CmNamespaceHandler method parsePropertyPlaceholder.
private ComponentMetadata parsePropertyPlaceholder(ParserContext context, Element element) {
MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
metadata.setProcessor(true);
metadata.setId(getId(context, element));
metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
metadata.setRuntimeClass(CmPropertyPlaceholder.class);
metadata.setInitMethod("init");
metadata.setDestroyMethod("destroy");
metadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
metadata.addProperty("configAdmin", createConfigurationAdminRef(context));
metadata.addProperty("persistentId", createValue(context, element.getAttribute(PERSISTENT_ID_ATTRIBUTE)));
String prefix = element.hasAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE) ? element.getAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE) : "${";
metadata.addProperty("placeholderPrefix", createValue(context, prefix));
String suffix = element.hasAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE) ? element.getAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE) : "}";
metadata.addProperty("placeholderSuffix", createValue(context, suffix));
String defaultsRef = element.hasAttribute(DEFAULTS_REF_ATTRIBUTE) ? element.getAttribute(DEFAULTS_REF_ATTRIBUTE) : null;
if (defaultsRef != null) {
metadata.addProperty("defaultProperties", createRef(context, defaultsRef));
}
String ignoreMissingLocations = extractIgnoreMissingLocations(element);
if (ignoreMissingLocations != null) {
metadata.addProperty("ignoreMissingLocations", createValue(context, ignoreMissingLocations));
}
String systemProperties = extractSystemPropertiesAttribute(element);
if (systemProperties == null) {
systemProperties = SYSTEM_PROPERTIES_NEVER;
}
metadata.addProperty("systemProperties", createValue(context, systemProperties));
String updateStrategy = element.getAttribute(UPDATE_STRATEGY_ATTRIBUTE);
if (updateStrategy != null) {
metadata.addProperty("updateStrategy", createValue(context, updateStrategy));
}
metadata.addProperty("managedObjectManager", createRef(context, MANAGED_OBJECT_MANAGER_NAME));
// Parse elements
List<String> locations = new ArrayList<String>();
NodeList nl = element.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element) {
Element e = (Element) node;
if (isCmNamespace(e.getNamespaceURI())) {
if (nodeNameEquals(e, DEFAULT_PROPERTIES_ELEMENT)) {
if (defaultsRef != null) {
throw new ComponentDefinitionException("Only one of " + DEFAULTS_REF_ATTRIBUTE + " attribute or " + DEFAULT_PROPERTIES_ELEMENT + " element is allowed");
}
Metadata props = parseDefaultProperties(context, metadata, e);
metadata.addProperty("defaultProperties", props);
}
} else if (isExtNamespace(e.getNamespaceURI())) {
if (nodeNameEquals(e, LOCATION_ELEMENT)) {
locations.add(getTextValue(e));
}
}
}
}
if (!locations.isEmpty()) {
metadata.addProperty("locations", createList(context, locations));
}
PlaceholdersUtils.validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
return metadata;
}
use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.
the class AbstractParserProxy method traverse.
/**
* Traverse to find all nested {@link ComponentMetadata} instances
* @param metadata
* @param output
*/
private void traverse(Metadata metadata, Set<ComponentMetadata> output) {
if (metadata instanceof ComponentMetadata) {
traverseComponent((ComponentMetadata) metadata, output);
} else if (metadata instanceof CollectionMetadata) {
CollectionMetadata collection = (CollectionMetadata) metadata;
for (Metadata v : collection.getValues()) traverse(v, output);
} else if (metadata instanceof MapMetadata) {
MapMetadata map = (MapMetadata) metadata;
for (MapEntry e : map.getEntries()) {
traverse(e.getKey(), output);
traverse(e.getValue(), output);
}
}
}
use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.
the class AbstractPropertyPlaceholder method processCollectionMetadata.
protected Metadata processCollectionMetadata(CollectionMetadata metadata) {
List<Metadata> values = new ArrayList<Metadata>(metadata.getValues());
if (!!!values.isEmpty()) {
try {
if (metadata instanceof MutableCollectionMetadata) {
processingStack.add("Collection type: " + metadata.getValueType() + "->");
MutableCollectionMetadata mcm = (MutableCollectionMetadata) metadata;
for (Metadata value : values) {
mcm.removeValue(value);
}
for (Metadata value : values) {
mcm.addValue(processMetadata(value));
}
} else {
printWarning(metadata, "Collection type: " + metadata.getValueType());
processingStack.add("Collection type: " + metadata.getValueType() + "->");
for (Metadata value : values) {
processMetadata(value);
}
}
} finally {
processingStack.removeLast();
}
}
return metadata;
}
use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.
the class Parser method parseRegistrationListener.
public RegistrationListener parseRegistrationListener(Element element, ComponentMetadata enclosingComponent) {
RegistrationListenerImpl listener = new RegistrationListenerImpl();
Metadata listenerComponent = null;
// Parse attributes
if (element.hasAttribute(REF_ATTRIBUTE)) {
listenerComponent = new RefMetadataImpl(element.getAttribute(REF_ATTRIBUTE));
}
String registrationMethod = null;
if (element.hasAttribute(REGISTRATION_METHOD_ATTRIBUTE)) {
registrationMethod = element.getAttribute(REGISTRATION_METHOD_ATTRIBUTE);
listener.setRegistrationMethod(registrationMethod);
}
String unregistrationMethod = null;
if (element.hasAttribute(UNREGISTRATION_METHOD_ATTRIBUTE)) {
unregistrationMethod = element.getAttribute(UNREGISTRATION_METHOD_ATTRIBUTE);
listener.setUnregistrationMethod(unregistrationMethod);
}
if (registrationMethod == null && unregistrationMethod == null) {
throw new ComponentDefinitionException("One of " + REGISTRATION_METHOD_ATTRIBUTE + " or " + UNREGISTRATION_METHOD_ATTRIBUTE + " must be set");
}
// Parse elements
NodeList nl = element.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element) {
Element e = (Element) node;
if (isBlueprintNamespace(e.getNamespaceURI())) {
if (nodeNameEquals(e, REF_ELEMENT)) {
if (listenerComponent != null) {
throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
}
String component = e.getAttribute(COMPONENT_ID_ATTRIBUTE);
if (component == null || component.length() == 0) {
throw new ComponentDefinitionException("Element " + REF_ELEMENT + " must have a valid " + COMPONENT_ID_ATTRIBUTE + " attribute");
}
listenerComponent = new RefMetadataImpl(component);
} else if (nodeNameEquals(e, BEAN_ELEMENT)) {
if (listenerComponent != null) {
throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
}
listenerComponent = parseBeanMetadata(e, false);
} else if (nodeNameEquals(e, REFERENCE_ELEMENT)) {
if (listenerComponent != null) {
throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
}
listenerComponent = parseReference(e, false);
} else if (nodeNameEquals(e, SERVICE_ELEMENT)) {
if (listenerComponent != null) {
throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
}
listenerComponent = parseService(e, false);
}
} else {
if (listenerComponent != null) {
throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
}
listenerComponent = parseCustomElement(e, enclosingComponent);
}
}
}
if (listenerComponent == null) {
throw new ComponentDefinitionException("One of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element must be set");
}
listener.setListenerComponent((Target) listenerComponent);
return listener;
}
use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.
the class Parser method parseBeanArgument.
private BeanArgument parseBeanArgument(ComponentMetadata enclosingComponent, Element element) {
int index = element.hasAttribute(INDEX_ATTRIBUTE) ? Integer.parseInt(element.getAttribute(INDEX_ATTRIBUTE)) : -1;
String type = element.hasAttribute(TYPE_ATTRIBUTE) ? element.getAttribute(TYPE_ATTRIBUTE) : null;
Metadata value = parseArgumentOrPropertyValue(element, enclosingComponent);
return new BeanArgumentImpl(value, type, index);
}
Aggregations