use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class BlueprintRepository method validate.
public void validate() {
for (Recipe recipe : getAllRecipes()) {
// Check that references are satisfied
String ref = null;
if (recipe instanceof RefRecipe) {
ref = ((RefRecipe) recipe).getIdRef();
} else if (recipe instanceof IdRefRecipe) {
ref = ((IdRefRecipe) recipe).getIdRef();
}
if (ref != null && getRecipe(ref) == null) {
throw new ComponentDefinitionException("Unresolved ref/idref to component: " + ref);
}
// Check service
if (recipe instanceof ServiceRecipe) {
Recipe r = ((ServiceRecipe) recipe).getServiceRecipe();
if (r instanceof RefRecipe) {
r = getRecipe(((RefRecipe) r).getIdRef());
}
if (r instanceof ServiceRecipe) {
throw new ComponentDefinitionException("The target for a <service> element must not be <service> element");
}
if (r instanceof ReferenceListRecipe) {
throw new ComponentDefinitionException("The target for a <service> element must not be <reference-list> element");
}
CollectionRecipe listeners = ((ServiceRecipe) recipe).getListenersRecipe();
for (Recipe lr : listeners.getDependencies()) {
// The listener recipe is a bean recipe with the listener being set in a property
for (Recipe l : lr.getDependencies()) {
if (l instanceof RefRecipe) {
l = getRecipe(((RefRecipe) l).getIdRef());
}
if (l instanceof ServiceRecipe) {
throw new ComponentDefinitionException("The target for a <registration-listener> element must not be <service> element");
}
if (l instanceof ReferenceListRecipe) {
throw new ComponentDefinitionException("The target for a <registration-listener> element must not be <reference-list> element");
}
}
}
}
// Check references
if (recipe instanceof AbstractServiceReferenceRecipe) {
CollectionRecipe listeners = ((AbstractServiceReferenceRecipe) recipe).getListenersRecipe();
for (Recipe lr : listeners.getDependencies()) {
// The listener recipe is a bean recipe with the listener being set in a property
for (Recipe l : lr.getDependencies()) {
if (l instanceof RefRecipe) {
l = getRecipe(((RefRecipe) l).getIdRef());
}
if (l instanceof ServiceRecipe) {
throw new ComponentDefinitionException("The target for a <reference-listener> element must not be <service> element");
}
if (l instanceof ReferenceListRecipe) {
throw new ComponentDefinitionException("The target for a <reference-listener> element must not be <reference-list> element");
}
}
}
}
}
}
use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class ExtNamespaceHandler method mergeList.
private void mergeList(ExtendedBeanMetadata bean1, MutableBeanMetadata bean2, String name) {
Metadata m1 = getProperty(bean1, name);
Metadata m2 = getProperty(bean2, name);
if (m1 == null && m2 != null) {
((MutableBeanMetadata) bean1).addProperty(name, m2);
} else if (m1 != null && m2 != null) {
if (!(m1 instanceof MutableCollectionMetadata) || !(m2 instanceof MutableCollectionMetadata)) {
throw new ComponentDefinitionException("Unable to merge " + name + " list properties");
}
MutableCollectionMetadata c1 = (MutableCollectionMetadata) m1;
MutableCollectionMetadata c2 = (MutableCollectionMetadata) m2;
for (Metadata v : c2.getValues()) {
c1.addValue(v);
}
}
}
use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class ExtNamespaceHandler method mergeMap.
private void mergeMap(ExtendedBeanMetadata bean1, MutableBeanMetadata bean2, String name) {
Metadata m1 = getProperty(bean1, name);
Metadata m2 = getProperty(bean2, name);
if (m1 == null && m2 != null) {
((MutableBeanMetadata) bean1).addProperty(name, m2);
} else if (m1 != null && m2 != null) {
if (!(m1 instanceof MutableMapMetadata) || !(m2 instanceof MutableMapMetadata)) {
throw new ComponentDefinitionException("Unable to merge " + name + " list properties");
}
MutableMapMetadata c1 = (MutableMapMetadata) m1;
MutableMapMetadata c2 = (MutableMapMetadata) m2;
for (MapEntry e : c2.getEntries()) {
c1.addEntry(e);
}
}
}
use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class ExtNamespaceHandler method parsePropertyPlaceholder.
private Metadata 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(PropertyPlaceholder.class);
metadata.setInitMethod("init");
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));
metadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
String defaultsRef = element.hasAttribute(DEFAULTS_REF_ATTRIBUTE) ? element.getAttribute(DEFAULTS_REF_ATTRIBUTE) : null;
if (defaultsRef != null) {
metadata.addProperty("defaultProperties", createRef(context, defaultsRef));
}
String ignoreMissingLocations = element.hasAttribute(IGNORE_MISSING_LOCATIONS_ATTRIBUTE) ? element.getAttribute(IGNORE_MISSING_LOCATIONS_ATTRIBUTE) : null;
if (ignoreMissingLocations != null) {
metadata.addProperty("ignoreMissingLocations", createValue(context, ignoreMissingLocations));
}
String systemProperties = element.hasAttribute(SYSTEM_PROPERTIES_ATTRIBUTE) ? element.getAttribute(SYSTEM_PROPERTIES_ATTRIBUTE) : null;
if (systemProperties != null) {
metadata.addProperty("systemProperties", createValue(context, systemProperties));
}
String evaluator = element.hasAttribute(EVALUATOR_ATTRIBUTE) ? element.getAttribute(EVALUATOR_ATTRIBUTE) : null;
if (evaluator != null) {
throw new IllegalStateException("Evaluators are not supported outside OSGi");
}
// 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 (BLUEPRINT_EXT_NAMESPACE_V1_0.equals(e.getNamespaceURI()) || BLUEPRINT_EXT_NAMESPACE_V1_1.equals(e.getNamespaceURI()) || BLUEPRINT_EXT_NAMESPACE_V1_2.equals(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 (nodeNameEquals(e, LOCATION_ELEMENT)) {
locations.add(getTextValue(e));
}
}
}
}
if (!locations.isEmpty()) {
metadata.addProperty("locations", createList(context, locations));
}
boolean result = validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
return result ? metadata : null;
}
use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class ExtNamespaceHandler method validatePlaceholder.
private boolean validatePlaceholder(MutableBeanMetadata metadata, ComponentDefinitionRegistry registry) {
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())) {
if (arePropertiesEquals(bean, metadata, "placeholderPrefix") && arePropertiesEquals(bean, metadata, "placeholderSuffix")) {
if (!arePropertiesEquals(bean, metadata, "systemProperties") || !arePropertiesEquals(bean, metadata, "ignoreMissingLocations")) {
throw new ComponentDefinitionException("Multiple incompatible placeholders found");
}
// Merge both placeholders
mergeList(bean, metadata, "locations");
mergeMap(bean, metadata, "defaultProperties");
return false;
}
}
}
}
return true;
}
Aggregations