use of org.apache.aries.blueprint.reflect.RefMetadataImpl in project aries by apache.
the class Parser method parseBeanMetadata.
private ComponentMetadata parseBeanMetadata(Element element, boolean topElement) {
BeanMetadataImpl metadata = new BeanMetadataImpl();
if (topElement) {
metadata.setId(getId(element));
if (element.hasAttribute(SCOPE_ATTRIBUTE)) {
metadata.setScope(getScope(element.getAttributeNode(SCOPE_ATTRIBUTE)));
if (!metadata.getScope().equals(BeanMetadata.SCOPE_SINGLETON)) {
if (element.hasAttribute(ACTIVATION_ATTRIBUTE)) {
if (element.getAttribute(ACTIVATION_ATTRIBUTE).equals(ACTIVATION_EAGER)) {
throw new ComponentDefinitionException("A <bean> with a prototype or custom scope can not have an eager activation");
}
}
metadata.setActivation(ComponentMetadata.ACTIVATION_LAZY);
} else {
metadata.setActivation(parseActivation(element));
}
} else {
metadata.setActivation(parseActivation(element));
}
} else {
metadata.setActivation(ComponentMetadata.ACTIVATION_LAZY);
}
if (element.hasAttribute(CLASS_ATTRIBUTE)) {
metadata.setClassName(element.getAttribute(CLASS_ATTRIBUTE));
}
if (element.hasAttribute(DEPENDS_ON_ATTRIBUTE)) {
metadata.setDependsOn(parseList(element.getAttribute(DEPENDS_ON_ATTRIBUTE)));
}
if (element.hasAttribute(INIT_METHOD_ATTRIBUTE)) {
metadata.setInitMethod(element.getAttribute(INIT_METHOD_ATTRIBUTE));
}
if (element.hasAttribute(DESTROY_METHOD_ATTRIBUTE)) {
metadata.setDestroyMethod(element.getAttribute(DESTROY_METHOD_ATTRIBUTE));
}
if (element.hasAttribute(FACTORY_REF_ATTRIBUTE)) {
metadata.setFactoryComponent(new RefMetadataImpl(element.getAttribute(FACTORY_REF_ATTRIBUTE)));
}
if (element.hasAttribute(FACTORY_METHOD_ATTRIBUTE)) {
String factoryMethod = element.getAttribute(FACTORY_METHOD_ATTRIBUTE);
metadata.setFactoryMethod(factoryMethod);
}
// Do some validation
if (metadata.getClassName() == null && metadata.getFactoryComponent() == null) {
throw new ComponentDefinitionException("Bean class or factory-ref must be specified");
}
if (metadata.getFactoryComponent() != null && metadata.getFactoryMethod() == null) {
throw new ComponentDefinitionException("factory-method is required when factory-component is set");
}
if (MetadataUtil.isPrototypeScope(metadata) && metadata.getDestroyMethod() != null) {
throw new ComponentDefinitionException("destroy-method must not be set for a <bean> with a prototype scope");
}
// 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(node.getNamespaceURI())) {
if (nodeNameEquals(node, ARGUMENT_ELEMENT)) {
metadata.addArgument(parseBeanArgument(metadata, e));
} else if (nodeNameEquals(node, PROPERTY_ELEMENT)) {
metadata.addProperty(parseBeanProperty(metadata, e));
}
}
}
}
MetadataUtil.validateBeanArguments(metadata.getArguments());
ComponentMetadata m = metadata;
// Parse custom scopes
m = handleCustomScope(element.getAttributeNode(SCOPE_ATTRIBUTE), element, m);
// Parse custom attributes
m = handleCustomAttributes(element.getAttributes(), m);
// Parse custom elements;
m = handleCustomElements(element, m);
return m;
}
use of org.apache.aries.blueprint.reflect.RefMetadataImpl in project aries by apache.
the class Parser method parseArgumentOrPropertyValue.
private Metadata parseArgumentOrPropertyValue(Element element, ComponentMetadata enclosingComponent) {
Metadata[] values = new Metadata[3];
if (element.hasAttribute(REF_ATTRIBUTE)) {
values[0] = new RefMetadataImpl(element.getAttribute(REF_ATTRIBUTE));
}
if (element.hasAttribute(VALUE_ATTRIBUTE)) {
values[1] = new ValueMetadataImpl(element.getAttribute(VALUE_ATTRIBUTE));
}
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(node.getNamespaceURI()) && nodeNameEquals(node, DESCRIPTION_ELEMENT)) {
// Ignore description elements
} else {
values[2] = parseValueGroup(e, enclosingComponent, null, true);
break;
}
}
}
Metadata value = null;
for (Metadata v : values) {
if (v != null) {
if (value == null) {
value = v;
} else {
throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + VALUE_ATTRIBUTE + " attribute or sub element must be set");
}
}
}
if (value == null) {
throw new ComponentDefinitionException("One of " + REF_ATTRIBUTE + " attribute, " + VALUE_ATTRIBUTE + " attribute or sub element must be set");
}
return value;
}
use of org.apache.aries.blueprint.reflect.RefMetadataImpl in project aries by apache.
the class Parser method parseMapEntry.
private MapEntry parseMapEntry(Element element, ComponentMetadata enclosingComponent, String keyType, String valueType) {
// Parse attributes
String key = element.hasAttribute(KEY_ATTRIBUTE) ? element.getAttribute(KEY_ATTRIBUTE) : null;
String keyRef = element.hasAttribute(KEY_REF_ATTRIBUTE) ? element.getAttribute(KEY_REF_ATTRIBUTE) : null;
String value = element.hasAttribute(VALUE_ATTRIBUTE) ? element.getAttribute(VALUE_ATTRIBUTE) : null;
String valueRef = element.hasAttribute(VALUE_REF_ATTRIBUTE) ? element.getAttribute(VALUE_REF_ATTRIBUTE) : null;
// Parse elements
NonNullMetadata keyValue = null;
Metadata valValue = null;
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 (nodeNameEquals(e, KEY_ELEMENT)) {
keyValue = parseMapKeyEntry(e, enclosingComponent, keyType);
} else {
valValue = parseValueGroup(e, enclosingComponent, valueType, true);
}
}
}
// Check key
if (keyValue != null && (key != null || keyRef != null) || (keyValue == null && key == null && keyRef == null)) {
throw new ComponentDefinitionException("Only and only one of " + KEY_ATTRIBUTE + " attribute, " + KEY_REF_ATTRIBUTE + " attribute or " + KEY_ELEMENT + " element must be set");
} else if (keyValue == null && key != null) {
keyValue = new ValueMetadataImpl(key, keyType);
} else if (keyValue == null) /*&& keyRef != null*/
{
keyValue = new RefMetadataImpl(keyRef);
}
// Check value
if (valValue != null && (value != null || valueRef != null) || (valValue == null && value == null && valueRef == null)) {
throw new ComponentDefinitionException("Only and only one of " + VALUE_ATTRIBUTE + " attribute, " + VALUE_REF_ATTRIBUTE + " attribute or sub element must be set");
} else if (valValue == null && value != null) {
valValue = new ValueMetadataImpl(value, valueType);
} else if (valValue == null) /*&& valueRef != null*/
{
valValue = new RefMetadataImpl(valueRef);
}
return new MapEntryImpl(keyValue, valValue);
}
use of org.apache.aries.blueprint.reflect.RefMetadataImpl in project aries by apache.
the class Parser method parseServiceListener.
private ReferenceListener parseServiceListener(Element element, ComponentMetadata enclosingComponent) {
ReferenceListenerImpl listener = new ReferenceListenerImpl();
Metadata listenerComponent = null;
// Parse attributes
if (element.hasAttribute(REF_ATTRIBUTE)) {
listenerComponent = new RefMetadataImpl(element.getAttribute(REF_ATTRIBUTE));
}
String bindMethodName = null;
String unbindMethodName = null;
if (element.hasAttribute(BIND_METHOD_ATTRIBUTE)) {
bindMethodName = element.getAttribute(BIND_METHOD_ATTRIBUTE);
listener.setBindMethod(bindMethodName);
}
if (element.hasAttribute(UNBIND_METHOD_ATTRIBUTE)) {
unbindMethodName = element.getAttribute(UNBIND_METHOD_ATTRIBUTE);
listener.setUnbindMethod(unbindMethodName);
}
if (bindMethodName == null && unbindMethodName == null) {
throw new ComponentDefinitionException("One of " + BIND_METHOD_ATTRIBUTE + " or " + UNBIND_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 + ", " + BLUEPRINT_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 + ", " + BLUEPRINT_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 + ", " + BLUEPRINT_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 + ", " + BLUEPRINT_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 + ", " + BLUEPRINT_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 + ", " + BLUEPRINT_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element must be set");
}
listener.setListenerComponent((Target) listenerComponent);
return listener;
}
use of org.apache.aries.blueprint.reflect.RefMetadataImpl 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;
}
Aggregations