+ private static void registerSchemaServiceRefBean(final ParserContext context) {
+ registerRefBean(context, SCHEMA_SERVICE_NAME, SchemaService.class);
+ }
+
+ private static void registerRefBean(final ParserContext context, final String name, final Class<?> clazz) {
+ ComponentDefinitionRegistry registry = context.getComponentDefinitionRegistry();
+ if (registry.getComponentDefinition(name) == null) {
+ MutableReferenceMetadata metadata = createServiceRef(context, clazz, null);
+ metadata.setId(name);
+ registry.registerComponentDefinition(metadata);
+ }
+ }
+
+ private static Metadata parseNotificationListener(final Element element, final 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 static void registerNotificationServiceRefBean(final 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 static Metadata parseClusteredAppConfig(final Element element, final 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), parseUpdateStrategy(
+ element.getAttribute(UPDATE_STRATEGY_ATTR)), defaultAppConfigElement);
+ }
+
+ private static UpdateStrategy parseUpdateStrategy(final String updateStrategyValue) {
+ if (Strings.isNullOrEmpty(updateStrategyValue)
+ || updateStrategyValue.equalsIgnoreCase(UpdateStrategy.RELOAD.name())) {
+ return UpdateStrategy.RELOAD;
+ } else if (updateStrategyValue.equalsIgnoreCase(UpdateStrategy.NONE.name())) {
+ return UpdateStrategy.NONE;
+ } else {
+ LOG.warn("update-strategy {} not supported, using reload", updateStrategyValue);
+ return UpdateStrategy.RELOAD;
+ }
+ }
+
+ private static Metadata parseSpecificReferenceList(final Element element, final ParserContext context) {
+ ComponentFactoryMetadata metadata = new SpecificReferenceListMetadata(getId(context, element),
+ element.getAttribute(INTERFACE));
+
+ LOG.debug("parseSpecificReferenceList returning {}", metadata);
+
+ return metadata;
+ }
+
+ private static Metadata parseStaticReference(final Element element, final ParserContext context) {
+ ComponentFactoryMetadata metadata = new StaticReferenceMetadata(getId(context, element),
+ element.getAttribute(INTERFACE));
+
+ LOG.debug("parseStaticReference returning {}", metadata);
+
+ return metadata;
+ }
+
+ private static Element parseXML(final String name, final String xml) {
+ try {
+ return UntrustedXML.newDocumentBuilder().parse(new InputSource(new StringReader(xml))).getDocumentElement();
+ } catch (SAXException | IOException e) {
+ throw new ComponentDefinitionException(String.format("Error %s parsing XML: %s", name, xml), e);
+ }
+ }
+
+ private static ValueMetadata createValue(final ParserContext context, final String value) {
+ MutableValueMetadata metadata = context.createMetadata(MutableValueMetadata.class);
+ metadata.setStringValue(value);
+ return metadata;
+ }
+
+ private static MutableReferenceMetadata createServiceRef(final ParserContext context, final Class<?> cls,
+ final String filter) {
+ MutableReferenceMetadata metadata = context.createMetadata(MutableReferenceMetadata.class);
+ metadata.setRuntimeInterface(cls);
+ metadata.setInterface(cls.getName());
+ metadata.setActivation(ReferenceMetadata.ACTIVATION_EAGER);
+ metadata.setAvailability(ReferenceMetadata.AVAILABILITY_MANDATORY);
+
+ if (filter != null) {
+ metadata.setFilter(filter);
+ }
+
+ return metadata;
+ }
+
+ private static RefMetadata createRef(final ParserContext context, final String id) {