use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class Parser method parseProperty.
private MapEntry parseProperty(Element element) {
// Parse attributes
if (!element.hasAttribute(KEY_ATTRIBUTE)) {
throw new ComponentDefinitionException(KEY_ATTRIBUTE + " attribute is required");
}
String value;
if (element.hasAttribute(VALUE_ATTRIBUTE)) {
value = element.getAttribute(VALUE_ATTRIBUTE);
} else {
value = getTextValue(element);
}
String key = element.getAttribute(KEY_ATTRIBUTE);
return new MapEntryImpl(new ValueMetadataImpl(key), new ValueMetadataImpl(value));
}
use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class Parser method parseReference.
private void parseReference(Element element, ServiceReferenceMetadataImpl reference, boolean topElement) {
// Parse attributes
if (topElement) {
reference.setActivation(parseActivation(element));
} else {
reference.setActivation(ComponentMetadata.ACTIVATION_LAZY);
}
if (element.hasAttribute(DEPENDS_ON_ATTRIBUTE)) {
reference.setDependsOn(parseList(element.getAttribute(DEPENDS_ON_ATTRIBUTE)));
}
if (element.hasAttribute(INTERFACE_ATTRIBUTE)) {
reference.setInterface(element.getAttribute(INTERFACE_ATTRIBUTE));
}
if (element.hasAttribute(FILTER_ATTRIBUTE)) {
reference.setFilter(element.getAttribute(FILTER_ATTRIBUTE));
}
if (element.hasAttribute(COMPONENT_NAME_ATTRIBUTE)) {
reference.setComponentName(element.getAttribute(COMPONENT_NAME_ATTRIBUTE));
}
String availability = element.hasAttribute(AVAILABILITY_ATTRIBUTE) ? element.getAttribute(AVAILABILITY_ATTRIBUTE) : defaultAvailability;
if (AVAILABILITY_MANDATORY.equals(availability)) {
reference.setAvailability(ServiceReferenceMetadata.AVAILABILITY_MANDATORY);
} else if (AVAILABILITY_OPTIONAL.equals(availability)) {
reference.setAvailability(ServiceReferenceMetadata.AVAILABILITY_OPTIONAL);
} else {
throw new ComponentDefinitionException("Illegal value for " + AVAILABILITY_ATTRIBUTE + " attribute: " + availability);
}
// 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, REFERENCE_LISTENER_ELEMENT)) {
reference.addServiceListener(parseServiceListener(e, reference));
}
}
}
}
}
use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class Parser method handleCustomScope.
/**
* Tests if a scope attribute value is a custom scope, and if so invokes
* the appropriate namespace handler, passing the blueprint scope node.
* <p>
* Currently this tests for custom scope by looking for the presence of
* a ':' char within the scope attribute value. This is valid as long as
* the blueprint schema continues to restrict that custom scopes should
* require that characters presence.
* <p>
*
* @param scope Value of scope attribute
* @param bean DOM element for bean associated to this scope
* @return Metadata as processed by NS Handler.
* @throws ComponentDefinitionException if an undeclared prefix is used,
* if a namespace handler is unavailable for a resolved prefix,
* or if the resolved prefix results as the blueprint namespace.
*/
private ComponentMetadata handleCustomScope(Node scope, Element bean, ComponentMetadata metadata) {
URI scopeNS = getNamespaceForAttributeValue(scope);
if (scopeNS != null && !BLUEPRINT_NAMESPACE.equals(scopeNS.toString())) {
NamespaceHandler nsHandler = getNamespaceHandler(scopeNS);
ParserContextImpl context = new ParserContextImpl(this, registry, metadata, scope);
metadata = nsHandler.decorate(scope, metadata, context);
} else if (scopeNS != null) {
throw new ComponentDefinitionException("Custom scopes cannot use the blueprint namespace " + scope);
}
return metadata;
}
use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class BeanRecipe method getInstanceFromFactory.
private Object getInstanceFromFactory(List<Object> args, List<ReifiedType> argTypes) {
Object factoryObj = getFactoryObj();
// Map of matching methods
Map<Method, List<Object>> matches = findMatchingMethods(factoryObj.getClass(), factoryMethod, true, args, argTypes);
if (matches.size() == 1) {
try {
Map.Entry<Method, List<Object>> match = matches.entrySet().iterator().next();
return invoke(match.getKey(), factoryObj, match.getValue().toArray());
} catch (Throwable e) {
throw wrapAsCompDefEx(e);
}
} else if (matches.size() == 0) {
throw new ComponentDefinitionException("Unable to find a matching factory method " + factoryMethod + " on class " + factoryObj.getClass().getName() + " for arguments " + argsToString(args) + " when instanciating bean " + getName());
} else {
throw new ComponentDefinitionException("Multiple matching factory methods " + factoryMethod + " found on class " + factoryObj.getClass().getName() + " for arguments " + argsToString(args) + " when instanciating bean " + getName() + ": " + matches.keySet());
}
}
use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class BeanRecipe method createProxyBean.
private Object createProxyBean(ReferenceRecipe rr) {
try {
VoidableCallable vc = new VoidableCallable();
rr.addVoidableChild(vc);
return blueprintContainer.getProxyManager().createDelegatingProxy(blueprintContainer.getBundleContext().getBundle(), rr.getProxyChildBeanClasses(), vc, vc.call());
} catch (UnableToProxyException e) {
throw new ComponentDefinitionException(e);
}
}
Aggregations