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_ALL_CLASSES);
commandService.setServiceComponent(command);
String scope = null;
if (SHELL_NAMESPACE_1_0_0.equals(element.getNamespaceURI())) {
String location = element.getAttribute(NAME);
location = location.replace('/', ':');
String function;
if (location.lastIndexOf(':') >= 0) {
scope = location.substring(0, location.lastIndexOf(':'));
function = location.substring(location.lastIndexOf(':') + 1);
} else {
scope = "";
function = location;
}
commandService.addServiceProperty(createStringValue(context, "osgi.command.scope"),
createStringValue(context, scope));
commandService.addServiceProperty(createStringValue(context, "osgi.command.function"),
createStringValue(context, function));
} else {
commandService.addServiceProperty(createStringValue(context, "osgi.command.scope"),
getInvocationValue(context, "getScope", action.getClassName()));
commandService.addServiceProperty(createStringValue(context, "osgi.command.function"),
getInvocationValue(context, "getName", action.getClassName()));
}
context.getComponentDefinitionRegistry().registerComponentDefinition(commandService);
String subShellName = ".subshell." + scope;
if (!context.getComponentDefinitionRegistry().containsComponentDefinition(subShellName)) {
// create the sub-shell action
MutableBeanMetadata subShellAction = context.createMetadata(MutableBeanMetadata.class);
subShellAction.setRuntimeClass(SubShellAction.class);
subShellAction.setActivation(MutableBeanMetadata.ACTIVATION_LAZY);
subShellAction.setScope(MutableBeanMetadata.SCOPE_PROTOTYPE);
subShellAction.setId(getName());
if (scope != null && !scope.isEmpty()) {
// it's shell 1.0.0 schema, scope is contained in the descriptor itself
subShellAction.addProperty("subShell", createStringValue(context, scope));
} else {
// it's shell 1.1.0 schema, we inject the scope from the command
subShellAction.addProperty("subShell", getInvocationValue(context, "getScope", action.getClassName()));
}
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_ALL_CLASSES);
subShellCommandService.setServiceComponent(subShellCommand);
subShellCommandService.addServiceProperty(createStringValue(context, "osgi.command.scope"), createStringValue(context, "*"));
if (scope != null && !scope.isEmpty()) {
// it's shell 1.0.0 schema, scope is contained in the descriptor itself
subShellCommandService.addServiceProperty(createStringValue(context, "osgi.command.function"), createStringValue(context, scope));
} else {
// it's shell 1.1.0 schema, we inject the scope from the command
subShellCommandService.addServiceProperty(createStringValue(context, "osgi.command.function"), getInvocationValue(context, "getScope", action.getClassName()));
}
context.getComponentDefinitionRegistry().registerComponentDefinition(subShellCommandService);
}
}