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;
}
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);
}
Aggregations