use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class ReferenceRecipe method internalCreate.
@Override
protected Object internalCreate() throws ComponentDefinitionException {
try {
if (explicitDependencies != null) {
for (Recipe recipe : explicitDependencies) {
recipe.create();
}
}
// Create the proxy
Set<Class<?>> interfaces = new HashSet<Class<?>>();
Class<?> clz = getInterfaceClass();
if (clz != null)
interfaces.add(clz);
if (metadata instanceof ExtendedReferenceMetadata) {
interfaces.addAll(loadAllClasses(((ExtendedReferenceMetadata) metadata).getExtraInterfaces()));
}
proxy = createProxy(new ServiceDispatcher(), interfaces);
// Add partially created proxy to the context
ServiceProxyWrapper wrapper = new ServiceProxyWrapper();
addPartialObject(wrapper);
// Handle initial references
createListeners();
updateListeners();
// Return a ServiceProxy that can injection of references or proxies can be done correctly
return wrapper;
} catch (ComponentDefinitionException e) {
throw e;
} catch (Throwable t) {
throw new ComponentDefinitionException(t);
}
}
use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class ExtNamespaceHandler method decorateAdditionalInterfaces.
private ComponentMetadata decorateAdditionalInterfaces(Node node, ComponentMetadata component, ParserContext context) {
if (!(component instanceof MutableReferenceMetadata)) {
throw new ComponentDefinitionException("Expected an instanceof MutableReferenceMetadata");
}
MutableReferenceMetadata mrm = (MutableReferenceMetadata) component;
List<String> list = new ArrayList<String>();
Node nd = node.getFirstChild();
while (nd != null) {
if (nd instanceof Element && nodeNameEquals(nd, INTERFACE_VALUE)) {
list.add(((Element) nd).getTextContent());
}
nd = nd.getNextSibling();
}
mrm.setExtraInterfaces(list);
return component;
}
use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class PlaceholdersUtils method validatePlaceholder.
public static void validatePlaceholder(MutableBeanMetadata metadata, ComponentDefinitionRegistry registry) {
String prefix = getPlaceholderProperty(metadata, "placeholderPrefix");
String suffix = getPlaceholderProperty(metadata, "placeholderSuffix");
for (String id : registry.getComponentDefinitionNames()) {
ComponentMetadata component = registry.getComponentDefinition(id);
if (component instanceof ExtendedBeanMetadata) {
ExtendedBeanMetadata bean = (ExtendedBeanMetadata) component;
if (bean.getRuntimeClass() != null && AbstractPropertyPlaceholder.class.isAssignableFrom(bean.getRuntimeClass())) {
String otherPrefix = getPlaceholderProperty(bean, "placeholderPrefix");
String otherSuffix = getPlaceholderProperty(bean, "placeholderSuffix");
if (prefix.equals(otherPrefix) && suffix.equals(otherSuffix)) {
throw new ComponentDefinitionException("Multiple placeholders with the same prefix and suffix are not allowed");
}
}
}
}
}
use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class MapRecipe method internalCreate.
protected Object internalCreate() throws ComponentDefinitionException {
Class<?> mapType = getMap(typeClass);
if (!ReflectionUtils.hasDefaultConstructor(mapType)) {
throw new ComponentDefinitionException("Type does not have a default constructor " + mapType.getName());
}
Object o;
try {
o = mapType.newInstance();
} catch (Exception e) {
throw new ComponentDefinitionException("Error while creating set instance: " + mapType.getName());
}
Map instance;
if (o instanceof Map) {
instance = (Map) o;
} else if (o instanceof Dictionary) {
instance = new DummyDictionaryAsMap((Dictionary) o);
} else {
throw new ComponentDefinitionException("Specified map type does not implement the Map interface: " + mapType.getName());
}
ReifiedType defaultConvertKeyType = getType(keyType);
ReifiedType defaultConvertValueType = getType(valueType);
// add map entries
try {
for (Recipe[] entry : entries) {
ReifiedType convertKeyType = workOutConversionType(entry[0], defaultConvertKeyType);
Object key = convert(entry[0].create(), convertKeyType);
// Each entry may have its own types
ReifiedType convertValueType = workOutConversionType(entry[1], defaultConvertValueType);
Object value = entry[1] != null ? convert(entry[1].create(), convertValueType) : null;
instance.put(key, value);
}
} catch (Exception e) {
throw new ComponentDefinitionException(e);
}
return instance;
}
use of org.osgi.service.blueprint.container.ComponentDefinitionException 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;
}
Aggregations