Search in sources :

Example 41 with MutableBeanMetadata

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

the class NamespaceHandler method createSubShell.

private void createSubShell(ParserContext context, String scope, String subShellName) {
    if (context.getComponentDefinitionRegistry().containsComponentDefinition(subShellName)) {
        return;
    }
    MutableBeanMetadata subShellAction = context.createMetadata(MutableBeanMetadata.class);
    subShellAction.setRuntimeClass(SubShellAction.class);
    subShellAction.setActivation(MutableBeanMetadata.ACTIVATION_LAZY);
    subShellAction.setScope(MutableBeanMetadata.SCOPE_PROTOTYPE);
    subShellAction.setId(getName());
    subShellAction.addProperty("subShell", createStringValue(context, scope));
    context.getComponentDefinitionRegistry().registerComponentDefinition(subShellAction);
    // generate the sub-shell command
    MutableBeanMetadata subShellCommand = context.createMetadata(MutableBeanMetadata.class);
    subShellCommand.setId(getName());
    subShellCommand.setRuntimeClass(BlueprintCommand.class);
    subShellCommand.addProperty(BLUEPRINT_CONTAINER, createRef(context, BLUEPRINT_CONTAINER));
    subShellCommand.addProperty(BLUEPRINT_CONVERTER, createRef(context, BLUEPRINT_CONVERTER));
    subShellCommand.addProperty(ACTION_ID, createIdRef(context, subShellAction.getId()));
    context.getComponentDefinitionRegistry().registerComponentDefinition(subShellCommand);
    // generate the sub-shell OSGi service
    MutableServiceMetadata subShellCommandService = context.createMetadata(MutableServiceMetadata.class);
    subShellCommandService.setActivation(MutableServiceMetadata.ACTIVATION_LAZY);
    subShellCommandService.setId(subShellName);
    subShellCommandService.setAutoExport(ServiceMetadata.AUTO_EXPORT_INTERFACES);
    subShellCommandService.setServiceComponent(subShellCommand);
    subShellCommandService.addServiceProperty(createStringValue(context, "osgi.command.scope"), createStringValue(context, "*"));
    subShellCommandService.addServiceProperty(createStringValue(context, "osgi.command.function"), createStringValue(context, scope));
    context.getComponentDefinitionRegistry().registerComponentDefinition(subShellCommandService);
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableServiceMetadata(org.apache.aries.blueprint.mutable.MutableServiceMetadata)

Example 42 with MutableBeanMetadata

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

the class NamespaceHandler method parseKeystore.

public ComponentMetadata parseKeystore(Element element, ParserContext context) {
    MutableBeanMetadata bean = context.createMetadata(MutableBeanMetadata.class);
    bean.setRuntimeClass(ResourceKeystoreInstance.class);
    // Parse name
    String name = element.getAttribute("name");
    bean.addProperty("name", createValue(context, name));
    // Parse rank
    String rank = element.getAttribute("rank");
    if (rank != null && rank.length() > 0) {
        bean.addProperty("rank", createValue(context, rank));
    }
    // Parse path
    String path = element.getAttribute("path");
    if (path != null && path.length() > 0) {
        bean.addProperty("path", createValue(context, path));
    }
    // Parse keystorePassword
    String keystorePassword = element.getAttribute("keystorePassword");
    if (keystorePassword != null && keystorePassword.length() > 0) {
        bean.addProperty("keystorePassword", createValue(context, keystorePassword));
    }
    // Parse keyPasswords
    String keyPasswords = element.getAttribute("keyPasswords");
    if (keyPasswords != null && keyPasswords.length() > 0) {
        bean.addProperty("keyPasswords", createValue(context, keyPasswords));
    }
    // Publish Config
    MutableServiceMetadata service = context.createMetadata(MutableServiceMetadata.class);
    service.setId(name);
    service.setServiceComponent(bean);
    service.addInterface(KeystoreInstance.class.getName());
    return service;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) MutableServiceMetadata(org.apache.aries.blueprint.mutable.MutableServiceMetadata) KeystoreInstance(org.apache.karaf.jaas.config.KeystoreInstance) ResourceKeystoreInstance(org.apache.karaf.jaas.config.impl.ResourceKeystoreInstance)

Example 43 with MutableBeanMetadata

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

the class NamespaceHandler method parseConfig.

public ComponentMetadata parseConfig(Element element, ParserContext context) {
    MutableBeanMetadata bean = context.createMetadata(MutableBeanMetadata.class);
    bean.setRuntimeClass(Config.class);
    String name = element.getAttribute("name");
    bean.addProperty("bundleContext", createRef(context, "blueprintBundleContext"));
    bean.addProperty("name", createValue(context, name));
    String rank = element.getAttribute("rank");
    if (rank != null && rank.length() > 0) {
        bean.addProperty("rank", createValue(context, rank));
    }
    NodeList childElements = element.getElementsByTagNameNS(element.getNamespaceURI(), "module");
    if (childElements != null && childElements.getLength() > 0) {
        MutableCollectionMetadata children = context.createMetadata(MutableCollectionMetadata.class);
        for (int i = 0; i < childElements.getLength(); ++i) {
            Element childElement = (Element) childElements.item(i);
            MutableBeanMetadata md = context.createMetadata(MutableBeanMetadata.class);
            md.setRuntimeClass(Module.class);
            md.addProperty("className", createValue(context, childElement.getAttribute("className")));
            if (childElement.getAttribute("name") != null) {
                md.addProperty("name", createValue(context, childElement.getAttribute("name")));
            }
            if (childElement.getAttribute("flags") != null) {
                md.addProperty("flags", createValue(context, childElement.getAttribute("flags")));
            }
            String options = getTextValue(childElement);
            if (options != null && options.length() > 0) {
                md.addProperty("options", createValue(context, options));
            }
            children.addValue(md);
        }
        bean.addProperty("modules", children);
    }
    // Publish Config
    MutableServiceMetadata service = context.createMetadata(MutableServiceMetadata.class);
    service.setId(name);
    service.setServiceComponent(bean);
    service.addInterface(JaasRealm.class.getName());
    service.addServiceProperty(createValue(context, ProxyLoginModule.PROPERTY_MODULE), createValue(context, name));
    return service;
}
Also used : MutableBeanMetadata(org.apache.aries.blueprint.mutable.MutableBeanMetadata) JaasRealm(org.apache.karaf.jaas.config.JaasRealm) MutableServiceMetadata(org.apache.aries.blueprint.mutable.MutableServiceMetadata) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) MutableCollectionMetadata(org.apache.aries.blueprint.mutable.MutableCollectionMetadata)

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