Search in sources :

Example 31 with Metadata

use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.

the class NSHandlerSeven method parse.

//process elements
public Metadata parse(Element element, ParserContext context) {
    Metadata retval = null;
    if (element.getLocalName().equals(ELT_NAME)) {
        final String id = element.getAttributeNS(NSURI, ATTRIB_ID);
        MutableBeanMetadata bm = context.createMetadata(MutableBeanMetadata.class);
        bm.setId(id);
        bm.setScope("PROTOTYPE");
        bm.setClassName(TestBean.class.getName());
        retval = bm;
    }
    return retval;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) MutableRefMetadata(org.apache.aries.blueprint.mutable.MutableRefMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata)

Example 32 with Metadata

use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.

the class NSHandlerSix method parse.

//process elements
public Metadata parse(Element element, ParserContext context) {
    Metadata retval = null;
    if (element.getLocalName().equals(ELT_NAME)) {
        final String id = element.getAttributeNS(NSURI, ATTRIB_ID);
        MutableBeanMetadata bm = context.createMetadata(MutableBeanMetadata.class);
        bm.setId(id);
        bm.setScope("PROTOTYPE");
        bm.setClassName(TestBean.class.getName());
        retval = bm;
    }
    return retval;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) PassThroughMetadata(org.apache.aries.blueprint.PassThroughMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) MutableRefMetadata(org.apache.aries.blueprint.mutable.MutableRefMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata)

Example 33 with Metadata

use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.

the class CmNamespaceHandler method parsePropertyPlaceholder.

private ComponentMetadata 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(CmPropertyPlaceholder.class);
    metadata.setInitMethod("init");
    metadata.setDestroyMethod("destroy");
    metadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
    metadata.addProperty("configAdmin", createConfigurationAdminRef(context));
    metadata.addProperty("persistentId", createValue(context, element.getAttribute(PERSISTENT_ID_ATTRIBUTE)));
    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));
    String defaultsRef = element.hasAttribute(DEFAULTS_REF_ATTRIBUTE) ? element.getAttribute(DEFAULTS_REF_ATTRIBUTE) : null;
    if (defaultsRef != null) {
        metadata.addProperty("defaultProperties", createRef(context, defaultsRef));
    }
    String ignoreMissingLocations = extractIgnoreMissingLocations(element);
    if (ignoreMissingLocations != null) {
        metadata.addProperty("ignoreMissingLocations", createValue(context, ignoreMissingLocations));
    }
    String systemProperties = extractSystemPropertiesAttribute(element);
    if (systemProperties == null) {
        systemProperties = SYSTEM_PROPERTIES_NEVER;
    }
    metadata.addProperty("systemProperties", createValue(context, systemProperties));
    String updateStrategy = element.getAttribute(UPDATE_STRATEGY_ATTRIBUTE);
    if (updateStrategy != null) {
        metadata.addProperty("updateStrategy", createValue(context, updateStrategy));
    }
    metadata.addProperty("managedObjectManager", createRef(context, MANAGED_OBJECT_MANAGER_NAME));
    // 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 (isCmNamespace(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 (isExtNamespace(e.getNamespaceURI())) {
                if (nodeNameEquals(e, LOCATION_ELEMENT)) {
                    locations.add(getTextValue(e));
                }
            }
        }
    }
    if (!locations.isEmpty()) {
        metadata.addProperty("locations", createList(context, locations));
    }
    PlaceholdersUtils.validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
    return metadata;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) MutableReferenceMetadata(org.apache.aries.blueprint.mutable.MutableReferenceMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) MutableRefMetadata(org.apache.aries.blueprint.mutable.MutableRefMetadata) IdRefMetadata(org.osgi.service.blueprint.reflect.IdRefMetadata) MutableIdRefMetadata(org.apache.aries.blueprint.mutable.MutableIdRefMetadata) MutableComponentMetadata(org.apache.aries.blueprint.mutable.MutableComponentMetadata) ReferenceMetadata(org.osgi.service.blueprint.reflect.ReferenceMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableValueMetadata(org.apache.aries.blueprint.mutable.MutableValueMetadata) MutableMapMetadata(org.apache.aries.blueprint.mutable.MutableMapMetadata)

Example 34 with Metadata

use of org.osgi.service.blueprint.reflect.Metadata in project cxf by apache.

the class EndpointDefinitionParser method parse.

public Metadata parse(Element element, ParserContext context) {
    // Endpoint definition
    MutableBeanMetadata cxfBean = context.createMetadata(MutableBeanMetadata.class);
    if (!StringUtils.isEmpty(getIdOrName(element))) {
        cxfBean.setId(getIdOrName(element));
    } else {
        cxfBean.setId("cxf.endpoint." + UUID.randomUUID().toString());
    }
    cxfBean.setRuntimeClass(EP_CLASS);
    boolean isAbstract = false;
    boolean publish = true;
    NamedNodeMap atts = element.getAttributes();
    String bus = null;
    Metadata impl = null;
    for (int i = 0; i < atts.getLength(); i++) {
        Attr node = (Attr) atts.item(i);
        String val = node.getValue();
        String pre = node.getPrefix();
        String name = node.getLocalName();
        if ("createdFromAPI".equals(name) || "abstract".equals(name)) {
            cxfBean.setScope(BeanMetadata.SCOPE_PROTOTYPE);
            isAbstract = true;
        } else if ("publish".equals(name)) {
            publish = Boolean.parseBoolean(val);
        } else if ("bus".equals(name)) {
            bus = val;
        } else if (isAttribute(pre, name)) {
            if ("endpointName".equals(name) || "serviceName".equals(name)) {
                QName q = parseQName(element, val);
                cxfBean.addProperty(name, createValue(context, q));
            } else if ("depends-on".equals(name)) {
                cxfBean.addDependsOn(val);
            } else if ("implementor".equals(name)) {
                if (val.startsWith("#")) {
                    impl = createRef(context, val.substring(1));
                } else {
                    impl = createObjectOfClass(context, val);
                }
            } else if (!"name".equals(name)) {
                cxfBean.addProperty(name, createValue(context, val));
            }
        }
    }
    Element elem = DOMUtils.getFirstElement(element);
    while (elem != null) {
        String name = elem.getLocalName();
        if ("properties".equals(name)) {
            Metadata map = parseMapData(context, cxfBean, elem);
            cxfBean.addProperty(name, map);
        } else if ("binding".equals(name)) {
            setFirstChildAsProperty(elem, context, cxfBean, "bindingConfig");
        } else if ("inInterceptors".equals(name) || "inFaultInterceptors".equals(name) || "outInterceptors".equals(name) || "outFaultInterceptors".equals(name) || "features".equals(name) || "schemaLocations".equals(name) || "handlers".equals(name)) {
            Metadata list = parseListData(context, cxfBean, elem);
            cxfBean.addProperty(name, list);
        } else if ("implementor".equals(name)) {
            impl = context.parseElement(Metadata.class, cxfBean, elem);
        } else {
            setFirstChildAsProperty(elem, context, cxfBean, name);
        }
        elem = DOMUtils.getNextElement(elem);
    }
    if (StringUtils.isEmpty(bus)) {
        bus = "cxf";
    }
    cxfBean.addArgument(this.getBusRef(context, bus), Bus.class.getName(), 0);
    cxfBean.addArgument(impl, Object.class.getName(), 1);
    if (!isAbstract) {
        if (publish) {
            cxfBean.setInitMethod("publish");
        }
        cxfBean.setDestroyMethod("stop");
    }
    // We don't want to delay the registration of our Server
    cxfBean.setActivation(ComponentMetadata.ACTIVATION_EAGER);
    return cxfBean;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) Bus(org.apache.cxf.Bus) NamedNodeMap(org.w3c.dom.NamedNodeMap) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) Metadata(org.osgi.service.blueprint.reflect.Metadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) Attr(org.w3c.dom.Attr)

Aggregations

Metadata (org.osgi.service.blueprint.reflect.Metadata)34 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)30 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)24 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)21 ValueMetadata (org.osgi.service.blueprint.reflect.ValueMetadata)19 ServiceMetadata (org.osgi.service.blueprint.reflect.ServiceMetadata)17 MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)16 CollectionMetadata (org.osgi.service.blueprint.reflect.CollectionMetadata)16 MapMetadata (org.osgi.service.blueprint.reflect.MapMetadata)16 Element (org.w3c.dom.Element)16 ReferenceListMetadata (org.osgi.service.blueprint.reflect.ReferenceListMetadata)12 ReferenceMetadata (org.osgi.service.blueprint.reflect.ReferenceMetadata)12 ServiceReferenceMetadata (org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)12 IdRefMetadata (org.osgi.service.blueprint.reflect.IdRefMetadata)11 NonNullMetadata (org.osgi.service.blueprint.reflect.NonNullMetadata)11 NullMetadata (org.osgi.service.blueprint.reflect.NullMetadata)11 PropsMetadata (org.osgi.service.blueprint.reflect.PropsMetadata)11 MutableRefMetadata (org.apache.aries.blueprint.mutable.MutableRefMetadata)9 PassThroughMetadata (org.apache.aries.blueprint.PassThroughMetadata)8 Node (org.w3c.dom.Node)8