Search in sources :

Example 6 with MutableServiceMetadata

use of org.apache.aries.blueprint.mutable.MutableServiceMetadata 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)

Example 7 with MutableServiceMetadata

use of org.apache.aries.blueprint.mutable.MutableServiceMetadata 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)

Aggregations

MutableServiceMetadata (org.apache.aries.blueprint.mutable.MutableServiceMetadata)7 MutableBeanMetadata (org.apache.aries.blueprint.mutable.MutableBeanMetadata)4 Element (org.w3c.dom.Element)3 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)2 Target (org.osgi.service.blueprint.reflect.Target)2 NodeList (org.w3c.dom.NodeList)2 ArrayList (java.util.ArrayList)1 NamespaceHandler (org.apache.aries.blueprint.NamespaceHandler)1 MutableCollectionMetadata (org.apache.aries.blueprint.mutable.MutableCollectionMetadata)1 MutableMapEntry (org.apache.aries.blueprint.mutable.MutableMapEntry)1 MutableRefMetadata (org.apache.aries.blueprint.mutable.MutableRefMetadata)1 MutableReferenceMetadata (org.apache.aries.blueprint.mutable.MutableReferenceMetadata)1 MutableRegistrationListener (org.apache.aries.blueprint.mutable.MutableRegistrationListener)1 MutableValueMetadata (org.apache.aries.blueprint.mutable.MutableValueMetadata)1 JaasRealm (org.apache.karaf.jaas.config.JaasRealm)1 KeystoreInstance (org.apache.karaf.jaas.config.KeystoreInstance)1 ResourceKeystoreInstance (org.apache.karaf.jaas.config.impl.ResourceKeystoreInstance)1 BeanMetadata (org.osgi.service.blueprint.reflect.BeanMetadata)1 ComponentMetadata (org.osgi.service.blueprint.reflect.ComponentMetadata)1 MapEntry (org.osgi.service.blueprint.reflect.MapEntry)1