+ private Metadata parseRpcImplementation(Element element, ParserContext context) {
+ registerRpcRegistryServiceRefBean(context);
+
+ MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
+ metadata.setId(context.generateId());
+ metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
+ metadata.setActivation(ReferenceMetadata.ACTIVATION_EAGER);
+ metadata.setRuntimeClass(RpcImplementationBean.class);
+ metadata.setInitMethod("init");
+ metadata.setDestroyMethod("destroy");
+ metadata.addProperty("bundle", createRef(context, "blueprintBundle"));
+ metadata.addProperty("rpcRegistry", createRef(context, RPC_REGISTRY_NAME));
+ metadata.addProperty("implementation", createRef(context, element.getAttribute(REF_ATTR)));
+
+ if(element.hasAttribute(INTERFACE)) {
+ metadata.addProperty("interfaceName", createValue(context, element.getAttribute(INTERFACE)));
+ }
+
+ LOG.debug("parseAddRpcImplementation returning {}", metadata);
+
+ return metadata;
+ }
+
+ private Metadata parseRoutedRpcImplementation(Element element, ParserContext context) {
+ registerRpcRegistryServiceRefBean(context);
+ registerRoutedRpcRegistrationConverter(context);
+
+ ComponentFactoryMetadata metadata = new RoutedRpcMetadata(getId(context, element),
+ element.getAttribute(INTERFACE), element.getAttribute(REF_ATTR));
+
+ LOG.debug("parseRoutedRpcImplementation returning {}", metadata);
+
+ return metadata;
+ }
+
+ private Metadata parseRpcService(Element element, ParserContext context) {
+ ComponentFactoryMetadata metadata = new RpcServiceMetadata(getId(context, element),
+ element.getAttribute(INTERFACE));
+
+ LOG.debug("parseRpcService returning {}", metadata);
+
+ return metadata;
+ }
+
+ private void registerRoutedRpcRegistrationConverter(ParserContext context) {
+ ComponentDefinitionRegistry registry = context.getComponentDefinitionRegistry();
+ if(registry.getComponentDefinition(ROUTED_RPC_REG_CONVERTER_NAME) == null) {
+ MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
+ metadata.setId(ROUTED_RPC_REG_CONVERTER_NAME);
+ metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
+ metadata.setActivation(ReferenceMetadata.ACTIVATION_LAZY);
+ metadata.setRuntimeClass(RoutedRpcRegistrationConverter.class);
+ registry.registerTypeConverter(metadata);
+ }
+ }
+
+ private void registerRpcRegistryServiceRefBean(ParserContext context) {
+ ComponentDefinitionRegistry registry = context.getComponentDefinitionRegistry();
+ if(registry.getComponentDefinition(RPC_REGISTRY_NAME) == null) {
+ MutableReferenceMetadata metadata = createServiceRef(context, RpcProviderRegistry.class, null);
+ metadata.setId(RPC_REGISTRY_NAME);
+ registry.registerComponentDefinition(metadata);
+ }
+ }
+
+ private Metadata parseNotificationListener(Element element, ParserContext context) {
+ registerNotificationServiceRefBean(context);
+
+ MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
+ metadata.setId(context.generateId());
+ metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
+ metadata.setActivation(ReferenceMetadata.ACTIVATION_EAGER);
+ metadata.setRuntimeClass(NotificationListenerBean.class);
+ metadata.setInitMethod("init");
+ metadata.setDestroyMethod("destroy");
+ metadata.addProperty("bundle", createRef(context, "blueprintBundle"));
+ metadata.addProperty("notificationService", createRef(context, NOTIFICATION_SERVICE_NAME));
+ metadata.addProperty("notificationListener", createRef(context, element.getAttribute(REF_ATTR)));
+
+ LOG.debug("parseNotificationListener returning {}", metadata);
+
+ return metadata;
+ }
+
+ private void registerNotificationServiceRefBean(ParserContext context) {
+ ComponentDefinitionRegistry registry = context.getComponentDefinitionRegistry();
+ if(registry.getComponentDefinition(NOTIFICATION_SERVICE_NAME) == null) {
+ MutableReferenceMetadata metadata = createServiceRef(context, NotificationService.class, null);
+ metadata.setId(NOTIFICATION_SERVICE_NAME);
+ registry.registerComponentDefinition(metadata);
+ }
+ }
+
+ private Metadata parseClusteredAppConfig(Element element, ParserContext context) {
+ LOG.debug("parseClusteredAppConfig");
+
+ // Find the default-config child element representing the default app config XML, if present.
+ Element defaultConfigElement = null;
+ NodeList children = element.getChildNodes();
+ for(int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ if(nodeNameEquals(child, DataStoreAppConfigMetadata.DEFAULT_CONFIG)) {
+ defaultConfigElement = (Element) child;
+ break;
+ }
+ }
+
+ Element defaultAppConfigElement = null;
+ if(defaultConfigElement != null) {
+ // Find the CDATA element containing the default app config XML.
+ children = defaultConfigElement.getChildNodes();
+ for(int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ if(child.getNodeType() == Node.CDATA_SECTION_NODE) {
+ defaultAppConfigElement = parseXML(DataStoreAppConfigMetadata.DEFAULT_CONFIG, child.getTextContent());
+ break;
+ }
+ }
+ }
+
+ return new DataStoreAppConfigMetadata(getId(context, element), element.getAttribute(
+ DataStoreAppConfigMetadata.BINDING_CLASS), element.getAttribute(
+ DataStoreAppConfigMetadata.LIST_KEY_VALUE), element.getAttribute(
+ DataStoreAppConfigMetadata.DEFAULT_CONFIG_FILE_NAME), defaultAppConfigElement);
+ }
+
+ private Metadata parseSpecificReferenceList(Element element, ParserContext context) {
+ ComponentFactoryMetadata metadata = new SpecificReferenceListMetadata(getId(context, element),
+ element.getAttribute(INTERFACE));
+
+ LOG.debug("parseSpecificReferenceList returning {}", metadata);
+
+ return metadata;
+ }
+
+ private Metadata parseStaticReference(Element element, ParserContext context) {
+ ComponentFactoryMetadata metadata = new StaticReferenceMetadata(getId(context, element),
+ element.getAttribute(INTERFACE));
+
+ LOG.debug("parseStaticReference returning {}", metadata);
+
+ return metadata;
+ }
+
+ private Element parseXML(String name, String xml) {
+ DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
+ builderFactory.setNamespaceAware(true);
+ builderFactory.setCoalescing(true);
+ builderFactory.setIgnoringElementContentWhitespace(true);
+ builderFactory.setIgnoringComments(true);
+
+ try {
+ return builderFactory.newDocumentBuilder().parse(new InputSource(new StringReader(xml))).getDocumentElement();
+ } catch(Exception e) {
+ throw new ComponentDefinitionException(String.format("Error %s parsing XML: %s", name, xml));
+ }
+ }
+