use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class Parser method parseReference.
private ComponentMetadata parseReference(Element element, boolean topElement) {
ReferenceMetadataImpl reference = new ReferenceMetadataImpl();
if (topElement) {
reference.setId(getId(element));
}
parseReference(element, reference, topElement);
String timeout = element.hasAttribute(TIMEOUT_ATTRIBUTE) ? element.getAttribute(TIMEOUT_ATTRIBUTE) : this.defaultTimeout;
try {
reference.setTimeout(Long.parseLong(timeout));
} catch (NumberFormatException e) {
throw new ComponentDefinitionException("Attribute " + TIMEOUT_ATTRIBUTE + " must be a valid long (was: " + timeout + ")");
}
ComponentMetadata r = reference;
// Parse custom attributes
r = handleCustomAttributes(element.getAttributes(), r);
// Parse custom elements;
r = handleCustomElements(element, r);
return r;
}
use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class Parser method parseInterfaceNames.
public List<String> parseInterfaceNames(Element element) {
List<String> interfaceNames = 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 (nodeNameEquals(e, VALUE_ELEMENT)) {
String v = getTextValue(e).trim();
if (interfaceNames.contains(v)) {
throw new ComponentDefinitionException("The element " + INTERFACES_ELEMENT + " should not contain the same interface twice");
}
interfaceNames.add(getTextValue(e));
} else {
throw new ComponentDefinitionException("Unsupported element " + e.getNodeName() + " inside an " + INTERFACES_ELEMENT + " element");
}
}
}
return interfaceNames;
}
use of org.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class Parser method loadComponents.
private void loadComponents(Document doc) {
defaultTimeout = TIMEOUT_DEFAULT;
defaultAvailability = AVAILABILITY_DEFAULT;
defaultActivation = ACTIVATION_DEFAULT;
Element root = doc.getDocumentElement();
if (!isBlueprintNamespace(root.getNamespaceURI()) || !nodeNameEquals(root, BLUEPRINT_ELEMENT)) {
throw new ComponentDefinitionException("Root element must be {" + BLUEPRINT_NAMESPACE + "}" + BLUEPRINT_ELEMENT + " element");
}
// Parse global attributes
if (root.hasAttribute(DEFAULT_ACTIVATION_ATTRIBUTE)) {
defaultActivation = root.getAttribute(DEFAULT_ACTIVATION_ATTRIBUTE);
}
if (root.hasAttribute(DEFAULT_TIMEOUT_ATTRIBUTE)) {
defaultTimeout = root.getAttribute(DEFAULT_TIMEOUT_ATTRIBUTE);
}
if (root.hasAttribute(DEFAULT_AVAILABILITY_ATTRIBUTE)) {
defaultAvailability = root.getAttribute(DEFAULT_AVAILABILITY_ATTRIBUTE);
}
// Parse custom attributes
handleCustomAttributes(root.getAttributes(), null);
// Parse elements
// Break into 2 loops to ensure we scan the blueprint elements before
// This is needed so that when we process the custom element, we know
// the component definition registry has populated all blueprint components.
NodeList nl = root.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element) {
Element element = (Element) node;
String namespaceUri = element.getNamespaceURI();
if (isBlueprintNamespace(namespaceUri)) {
parseBlueprintElement(element);
}
}
}
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element) {
Element element = (Element) node;
String namespaceUri = element.getNamespaceURI();
if (!isBlueprintNamespace(namespaceUri)) {
Metadata component = parseCustomElement(element, null);
if (component != null) {
if (!(component instanceof ComponentMetadata)) {
throw new ComponentDefinitionException("Expected a ComponentMetadata to be returned when parsing element " + element.getNodeName());
}
registry.registerComponentDefinition((ComponentMetadata) component);
}
}
}
}
}
use of org.osgi.service.blueprint.container.ComponentDefinitionException 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.osgi.service.blueprint.container.ComponentDefinitionException in project aries by apache.
the class Parser method getNamespaceForAttributeValue.
/**
* Takes an Attribute Node containing a namespace prefix qualified attribute value, and resolves the namespace using the DOM Node.<br>
*
* @param attrNode The DOM Node with the qualified attribute value.
* @return The URI if one is resolvable, or null if the attr is null, or not namespace prefixed. (or not a DOM Attribute Node)
* @throws ComponentDefinitionException if the namespace prefix in the attribute value cannot be resolved.
*/
private URI getNamespaceForAttributeValue(Node attrNode) throws ComponentDefinitionException {
URI uri = null;
if (attrNode != null && (attrNode instanceof Attr)) {
Attr attr = (Attr) attrNode;
String attrValue = attr.getValue();
if (attrValue != null && attrValue.indexOf(":") != -1) {
String[] parts = attrValue.split(":");
String uriStr = attr.getOwnerElement().lookupNamespaceURI(parts[0]);
if (uriStr != null) {
uri = URI.create(uriStr);
} else {
throw new ComponentDefinitionException("Unsupported attribute namespace prefix " + parts[0] + " " + attr);
}
}
}
return uri;
}
Aggregations