Search in sources :

Example 16 with MutableBeanMetadata

use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project karaf by apache.

the class NamespaceHandler method parsePropertyPlaceholder.

public ComponentMetadata parsePropertyPlaceholder(Element element, ParserContext context) {
    MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
    metadata.setProcessor(true);
    metadata.setId(getId(context, element));
    metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
    metadata.setRuntimeClass(EncryptablePropertyPlaceholder.class);
    metadata.setInitMethod("init");
    String prefix = element.hasAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE) ? element.getAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE) : "ENC(";
    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 encryptorRef = element.hasAttribute("encryptor-ref") ? element.getAttribute("encryptor-ref") : null;
    if (encryptorRef != null) {
        metadata.addProperty("encryptor", createRef(context, encryptorRef));
    }
    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 (JASYPT_NAMESPACE_1_0.equals(e.getNamespaceURI())) {
                String name = e.getLocalName() != null ? e.getLocalName() : e.getNodeName();
                if (ENCRYPTOR_ELEMENT.equals(name)) {
                    if (encryptorRef != null) {
                        throw new ComponentDefinitionException("Only one of " + ENCRYPTOR_REF_ATTRIBUTE + " attribute or " + ENCRYPTOR_ELEMENT + " element is allowed");
                    }
                    BeanMetadata encryptor = context.parseElement(BeanMetadata.class, metadata, e);
                    metadata.addProperty("encryptor", encryptor);
                }
            }
        }
    }
    PlaceholdersUtils.validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
    return metadata;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Example 17 with MutableBeanMetadata

use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project karaf by apache.

the class NamespaceHandler method parseCommand.

private void parseCommand(Element element, ParserContext context) {
    MutableBeanMetadata command = context.createMetadata(MutableBeanMetadata.class);
    command.setRuntimeClass(BlueprintCommand.class);
    command.addProperty(BLUEPRINT_CONTAINER, createRef(context, BLUEPRINT_CONTAINER));
    command.addProperty(BLUEPRINT_CONVERTER, createRef(context, BLUEPRINT_CONVERTER));
    NodeList children = element.getChildNodes();
    MutableBeanMetadata action = null;
    for (int i = 0; i < children.getLength(); i++) {
        Node child = children.item(i);
        if (child instanceof Element) {
            Element childElement = (Element) child;
            if (nodeNameEquals(childElement, ACTION)) {
                action = parseAction(context, command, childElement);
                action.setId(getName());
                context.getComponentDefinitionRegistry().registerComponentDefinition(action);
                command.addProperty(ACTION_ID, createIdRef(context, action.getId()));
            } else if (nodeNameEquals(childElement, COMPLETERS)) {
                command.addProperty(COMPLETERS, parseCompleters(context, command, childElement));
            } else if (nodeNameEquals(childElement, OPTIONAL_COMPLETERS)) {
                command.addProperty(OPTIONAL_COMPLETERS_PROPERTY, parseOptionalCompleters(context, command, childElement));
            } else {
                throw new ComponentDefinitionException("Bad xml syntax: unknown element '" + childElement.getNodeName() + "'");
            }
        }
    }
    MutableServiceMetadata commandService = context.createMetadata(MutableServiceMetadata.class);
    commandService.setActivation(MutableServiceMetadata.ACTIVATION_LAZY);
    commandService.setId(getName());
    commandService.setAutoExport(ServiceMetadata.AUTO_EXPORT_INTERFACES);
    commandService.setServiceComponent(command);
    String scope;
    String function;
    if (SHELL_NAMESPACE_1_0_0.equals(element.getNamespaceURI())) {
        String location = element.getAttribute(NAME);
        location = location.replace('/', ':');
        if (location.lastIndexOf(':') >= 0) {
            scope = location.substring(0, location.lastIndexOf(':'));
            function = location.substring(location.lastIndexOf(':') + 1);
        } else {
            scope = "";
            function = location;
        }
    } else {
        try {
            Class actionClass = getBundle(context).loadClass(action.getClassName());
            scope = getScope(actionClass);
            function = getName(actionClass);
        } catch (Throwable e) {
            throw new ComponentDefinitionException("Unable to introspect action " + action.getClassName(), e);
        }
    }
    commandService.addServiceProperty(createStringValue(context, "osgi.command.scope"), createStringValue(context, scope));
    commandService.addServiceProperty(createStringValue(context, "osgi.command.function"), createStringValue(context, function));
    context.getComponentDefinitionRegistry().registerComponentDefinition(commandService);
    String subShellName = null;
    if (scope != null && !scope.isEmpty()) {
        // if it's shell 1.0.0 schema and scope is contained in the descriptor itself
        subShellName = ".subshell." + scope;
    }
    if (subShellName == null || !context.getComponentDefinitionRegistry().containsComponentDefinition(subShellName)) {
        // if the scope is unknown or if the scope has not been defined before
        createSubShell(context, scope, subShellName);
    }
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableServiceMetadata(org.apache.aries.blueprint.mutable.MutableServiceMetadata) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element)

Example 18 with MutableBeanMetadata

use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project karaf by apache.

the class NamespaceHandler method getInvocationValue.

private MutableBeanMetadata getInvocationValue(ParserContext context, String method, String className) {
    MutableBeanMetadata scope = context.createMetadata(MutableBeanMetadata.class);
    scope.setRuntimeClass(NamespaceHandler.class);
    scope.setFactoryMethod(method);
    scope.addArgument(createStringValue(context, className), null, 0);
    return scope;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata)

Example 19 with MutableBeanMetadata

use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project camel by apache.

the class AbstractBeanDefinitionParser method createBeanMetadata.

public MutableBeanMetadata createBeanMetadata(Element element, ParserContext context, Class<?> runtimeClass) {
    MutableBeanMetadata answer = context.createMetadata(MutableBeanMetadata.class);
    answer.setRuntimeClass(runtimeClass);
    answer.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
    answer.addProperty("bundleContext", createRef(context, "blueprintBundleContext"));
    // set the Bean scope to be prototype, so we can get a new instance per looking up
    answer.setScope(BeanMetadata.SCOPE_PROTOTYPE);
    if (!StringUtils.isEmpty(getIdOrName(element))) {
        answer.setId(getIdOrName(element));
    } else {
        // TODO we may need to throw exception for it
        answer.setId("camel.cxf.endpoint." + runtimeClass.getSimpleName() + "." + context.generateId());
    }
    return answer;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata)

Example 20 with MutableBeanMetadata

use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project camel by apache.

the class RsClientDefinitionParser method parse.

public Metadata parse(Element element, ParserContext context) {
    MutableBeanMetadata beanMetadata = createBeanMetadata(element, context, RsClientBlueprintBean.class);
    NamedNodeMap atts = element.getAttributes();
    String bus = 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 ("bus".equals(name)) {
            bus = val;
        } else if (isAttribute(pre, name)) {
            if ("depends-on".equals(name)) {
                beanMetadata.addDependsOn(val);
            } else if (!"name".equals(name)) {
                beanMetadata.addProperty(name, AbstractBPBeanDefinitionParser.createValue(context, val));
            }
        }
    }
    for (Element elem = DOMUtils.getFirstElement(element); elem != null; elem = DOMUtils.getNextElement(elem)) {
        String name = elem.getLocalName();
        if ("properties".equals(name) || "headers".equals(name)) {
            Metadata map = parseMapData(context, beanMetadata, elem);
            beanMetadata.addProperty(name, map);
        } else if ("binding".equals(name)) {
            setFirstChildAsProperty(elem, context, beanMetadata, "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, beanMetadata, elem);
            beanMetadata.addProperty(name, list);
        } else if ("features".equals(name) || "providers".equals(name) || "schemaLocations".equals(name) || "modelBeans".equals(name)) {
            Metadata list = parseListData(context, beanMetadata, elem);
            beanMetadata.addProperty(name, list);
        } else if ("model".equals(name)) {
            List<UserResource> resources = ResourceUtils.getResourcesFromElement(elem);
            MutablePassThroughMetadata value = context.createMetadata(MutablePassThroughMetadata.class);
            value.setObject(resources);
            beanMetadata.addProperty(name, value);
        } else {
            setFirstChildAsProperty(elem, context, beanMetadata, name);
        }
    }
    if (StringUtils.isEmpty(bus)) {
        bus = "cxf";
    }
    //Will create a bus if needed...
    beanMetadata.addProperty("bus", getBusRef(context, bus));
    return beanMetadata;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) NamedNodeMap(org.w3c.dom.NamedNodeMap) Element(org.w3c.dom.Element) Metadata(org.osgi.service.blueprint.reflect.Metadata) MutablePassThroughMetadata(org.apache.aries.blueprint.mutable.MutablePassThroughMetadata) MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) UserResource(org.apache.cxf.jaxrs.model.UserResource) Attr(org.w3c.dom.Attr)

Aggregations

MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)43 Node (org.w3c.dom.Node)13 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)12 MutablePassThroughMetadata (org.apache.aries.blueprint.mutable.MutablePassThroughMetadata)10 Element (org.w3c.dom.Element)10 Metadata (org.osgi.service.blueprint.reflect.Metadata)9 PassThroughMetadata (org.apache.aries.blueprint.PassThroughMetadata)8 JAXBException (javax.xml.bind.JAXBException)7 ExpressionNode (org.apache.camel.model.ExpressionNode)7 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)7 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)7 MutableRefMetadata (org.apache.aries.blueprint.mutable.MutableRefMetadata)6 RefMetadata (org.osgi.service.blueprint.reflect.RefMetadata)6 NodeList (org.w3c.dom.NodeList)6 Attr (org.w3c.dom.Attr)5 List (java.util.List)4 MutableServiceMetadata (org.apache.aries.blueprint.mutable.MutableServiceMetadata)4 NamedNodeMap (org.w3c.dom.NamedNodeMap)4 ComponentDefinitionRegistry (org.apache.aries.blueprint.ComponentDefinitionRegistry)3 MutableCollectionMetadata (org.apache.aries.blueprint.mutable.MutableCollectionMetadata)3