Example usage for org.springframework.util.xml DomUtils getChildElementByTagName

List of usage examples for org.springframework.util.xml DomUtils getChildElementByTagName

Introduction

In this page you can find the example usage for org.springframework.util.xml DomUtils getChildElementByTagName.

Prototype

@Nullable
public static Element getChildElementByTagName(Element ele, String childEleName) 

Source Link

Document

Utility method that returns the first child element identified by its name.

Usage

From source file:com.developmentsprint.spring.breaker.config.BreakerAdviceParser.java

private RootBeanDefinition parseAttributeSource(List<Element> methods, ParserContext parserContext) {
    ManagedMap<TypedStringValue, DefaultCircuitBreakerAttribute> circuitBreakerAttributeMap = new ManagedMap<TypedStringValue, DefaultCircuitBreakerAttribute>(
            methods.size());/*  ww w. j a  va2s . c o  m*/

    circuitBreakerAttributeMap.setSource(parserContext.extractSource(methods));

    for (Element methodEle : methods) {
        String methodName = methodEle.getAttribute(METHOD_NAME_ATTRIBUTE);
        TypedStringValue nameHolder = new TypedStringValue(methodName);
        nameHolder.setSource(parserContext.extractSource(methodEle));

        RuleBasedCircuitBreakerAttribute attribute = new RuleBasedCircuitBreakerAttribute();
        attribute.setMethodName(methodName);

        String cbName = methodEle.getAttribute(CB_NAME_ATTRIBUTE);
        if (StringUtils.isEmpty(cbName)) {
            attribute.setName(methodName);
        } else {
            attribute.setName(cbName);
        }

        ManagedMap<String, String> props = new ManagedMap<String, String>();
        Element propsElement = DomUtils.getChildElementByTagName(methodEle, "properties");
        if (propsElement != null) {
            //Map<String, String> props = new HashMap<String, String>();
            List<Element> propElements = DomUtils.getChildElementsByTagName(propsElement, "prop");
            for (Element propElement : propElements) {
                String key = propElement.getAttribute("key");
                String val = DomUtils.getTextValue(propElement);
                props.put(key, new TypedStringValue(val).getValue());
            }
            attribute.setProperties(props);
        }
        if (log.isDebugEnabled()) {
            for (Map.Entry<String, String> e : attribute.getProperties().entrySet()) {
                log.debug("{} prop : {} : {}", cbName, e.getKey(), e.getValue());
            }
        }

        circuitBreakerAttributeMap.put(nameHolder, attribute);
    }

    RootBeanDefinition attributeSourceDefinition = new RootBeanDefinition(
            NameMatchCircuitBreakerAttributeSource.class);
    attributeSourceDefinition.setSource(parserContext.extractSource(methods));
    attributeSourceDefinition.getPropertyValues().add("nameMap", circuitBreakerAttributeMap);
    return attributeSourceDefinition;
}

From source file:biz.c24.io.spring.batch.config.ItemReaderParser.java

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder bean) {

    // Optional//from w w  w. ja  v a  2s  . c  om
    String scope = element.getAttribute("scope");
    if (StringUtils.hasText(scope)) {
        bean.setScope(scope);
    } else {
        // Default to step scope
        bean.setScope("step");
    }

    int numSourceDefns = 0;

    // Optional
    String sourceRef = element.getAttribute("source-ref");
    if (StringUtils.hasText(sourceRef)) {
        bean.addPropertyReference("source", sourceRef);
        numSourceDefns++;
    }

    // Mandatory
    String modelRef = element.getAttribute("model-ref");
    bean.addPropertyReference("model", modelRef);

    // Optional
    String elementStartPattern = element.getAttribute("elementStartPattern");
    if (StringUtils.hasText(elementStartPattern)) {
        bean.addPropertyValue("elementStartPattern", elementStartPattern);
    }

    // Optional
    String elementStopPattern = element.getAttribute("elementStopPattern");
    if (StringUtils.hasText(elementStopPattern)) {
        bean.addPropertyValue("elementStopPattern", elementStopPattern);
    }

    // Optional
    String validate = element.getAttribute("validate");
    if (StringUtils.hasText(validate)) {
        bean.addPropertyValue("validate", validate); //don't evaluate as a boolean until Bean creation time to allow for SpEL
    }

    // Optional
    String failfast = element.getAttribute("failfast");
    if (StringUtils.hasText(failfast)) {
        boolean val = Boolean.parseBoolean(failfast);
        bean.addPropertyValue("failfast", val);
    }

    // Optional
    String sourceFactoryRef = element.getAttribute("source-factory-ref");
    if (StringUtils.hasText(sourceFactoryRef)) {
        bean.addPropertyReference("sourceFactory", sourceFactoryRef);
    }

    // Optional
    String parseListenerRef = element.getAttribute("parse-listener-ref");
    if (StringUtils.hasText(parseListenerRef)) {
        bean.addPropertyReference("parseListener", parseListenerRef);
    }

    Element fileSourceElement = DomUtils.getChildElementByTagName(element, "file-source");
    if (fileSourceElement != null) {
        BeanDefinition beanDefinition = parserContext.getDelegate().parseCustomElement(fileSourceElement,
                bean.getBeanDefinition());
        beanDefinition.setBeanClassName(FileSource.class.getName());
        bean.addPropertyValue("source", beanDefinition);
        numSourceDefns++;
    }

    Element zipFileSourceElement = DomUtils.getChildElementByTagName(element, "zip-file-source");
    if (zipFileSourceElement != null) {
        BeanDefinition beanDefinition = parserContext.getDelegate().parseCustomElement(zipFileSourceElement,
                bean.getBeanDefinition());
        beanDefinition.setBeanClassName(ZipFileSource.class.getName());
        bean.addPropertyValue("source", beanDefinition);
        numSourceDefns++;
    }

    if (numSourceDefns > 1) {
        parserContext.getReaderContext()
                .error("Only one of source-ref, file-source and zip-file-source can be used", element);
    } else if (numSourceDefns == 0) {
        parserContext.getReaderContext()
                .error("One of source-ref, file-source and zip-file-source must be specified", element);
    }

}

From source file:com.dangdang.ddframe.rdb.sharding.spring.namespace.parser.ShardingJdbcDataSourceBeanDefinitionParser.java

private Map<String, BeanDefinition> parseTableRulesConfig(final Element element) {
    Element tableRulesElement = DomUtils.getChildElementByTagName(element,
            ShardingJdbcDataSourceBeanDefinitionParserTag.TABLE_RULES_TAG);
    List<Element> tableRuleElements = DomUtils.getChildElementsByTagName(tableRulesElement,
            ShardingJdbcDataSourceBeanDefinitionParserTag.TABLE_RULE_TAG);
    Map<String, BeanDefinition> result = new ManagedMap<>(tableRuleElements.size());
    for (Element each : tableRuleElements) {
        result.put(each.getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.LOGIC_TABLE_ATTRIBUTE),
                parseTableRuleConfig(each));
    }//from w  w w  .  ja va 2s.  c  o  m
    return result;
}

From source file:org.sarons.spring4me.web.page.config.xml.XmlPageConfigFactory.java

private WidgetConfig parseWidget(Element widgetEle, GroupConfig groupConfig) {
    String id = widgetEle.getAttribute("id");
    String name = widgetEle.getAttribute("name");
    String path = widgetEle.getAttribute("path");
    String cacheStr = widgetEle.getAttribute("cache");
    String disabled = widgetEle.getAttribute("disabled");
    ////from   w w w .  ja v  a 2s . c om
    int cache = -1;
    if (StringUtils.hasText(cacheStr)) {
        cache = Integer.valueOf(cacheStr);
    }
    //
    WidgetConfig widgetConfig = new WidgetConfig(groupConfig);
    widgetConfig.setId(id);
    widgetConfig.setName(name);
    widgetConfig.setPath(path);
    widgetConfig.setCache(cache);
    widgetConfig.setDisabled("true".equals(disabled));
    //
    Element titleEle = DomUtils.getChildElementByTagName(widgetEle, "title");
    if (titleEle != null) {
        String title = titleEle.getTextContent();
        widgetConfig.setTitle(title);
    }
    //
    Element descEle = DomUtils.getChildElementByTagName(widgetEle, "description");
    if (descEle != null) {
        String description = descEle.getTextContent();
        widgetConfig.setDescription(description);
    }
    //
    Map<String, String> events = new HashMap<String, String>();
    Element eventsEle = DomUtils.getChildElementByTagName(widgetEle, "events");
    if (eventsEle != null) {
        List<Element> eventEles = DomUtils.getChildElements(eventsEle);
        for (Element eventEle : eventEles) {
            String on = eventEle.getAttribute("on");
            String to = eventEle.getAttribute("to");
            events.put(on, to);
        }
        widgetConfig.getGroupConfig().getPageConfig().setEvents(events);
    }
    //
    Map<String, String> preferences = new HashMap<String, String>();
    Element prefEle = DomUtils.getChildElementByTagName(widgetEle, "preference");
    if (prefEle != null) {
        List<Element> keyValueEles = DomUtils.getChildElements(prefEle);
        for (Element keyValueEle : keyValueEles) {
            String key = keyValueEle.getTagName();
            String value = keyValueEle.getTextContent();
            preferences.put(key, value);
        }
        widgetConfig.setPreferences(preferences);
    }
    //
    return widgetConfig;
}

From source file:org.drools.container.spring.namespace.KnowledgeSessionDefinitionParser.java

@SuppressWarnings("unchecked")
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {

    String id = element.getAttribute("id");
    emptyAttributeCheck(element.getLocalName(), "id", id);

    String kbase = element.getAttribute(KBASE_ATTRIBUTE);
    emptyAttributeCheck(element.getLocalName(), KBASE_ATTRIBUTE, kbase);

    String sessionType = element.getAttribute(TYPE_ATTRIBUTE);
    BeanDefinitionBuilder factory;//  w w  w. jav  a2 s  .c  o  m

    if ("stateful".equals(sessionType)) {
        factory = BeanDefinitionBuilder.rootBeanDefinition(StatefulKnowledgeSessionBeanFactory.class);
    } else if ("stateless".equals(sessionType)) {
        factory = BeanDefinitionBuilder.rootBeanDefinition(StatelessKnowledgeSessionBeanFactory.class);
    } else {
        throw new IllegalArgumentException(
                "Invalid value for " + TYPE_ATTRIBUTE + " attribute: " + sessionType);
    }

    factory.addPropertyReference("kbase", kbase);

    String node = element.getAttribute(GRID_NODE_ATTRIBUTE);
    if (node != null && node.length() > 0) {
        factory.addPropertyReference("node", node);
    }

    String name = element.getAttribute(NAME_ATTRIBUTE);
    if (StringUtils.hasText(name)) {
        factory.addPropertyValue("name", name);
    } else {
        factory.addPropertyValue("name", id);
    }

    // Additions for JIRA JBRULES-3076
    String listeners = element.getAttribute(LISTENERS_ATTRIBUTE);
    if (StringUtils.hasText(listeners)) {
        factory.addPropertyValue("eventListenersFromGroup", new RuntimeBeanReference(listeners));
    }
    EventListenersUtil.parseEventListeners(parserContext, factory, element);
    // End of Additions for JIRA JBRULES-3076

    Element ksessionConf = DomUtils.getChildElementByTagName(element, "configuration");
    if (ksessionConf != null) {
        Element persistenceElm = DomUtils.getChildElementByTagName(ksessionConf, "jpa-persistence");
        if (persistenceElm != null) {
            BeanDefinitionBuilder beanBuilder = BeanDefinitionBuilder
                    .genericBeanDefinition(JpaConfiguration.class);

            String loadId = persistenceElm.getAttribute("load");
            if (StringUtils.hasText(loadId)) {
                beanBuilder.addPropertyValue("id", Long.parseLong(loadId));
            }

            Element tnxMng = DomUtils.getChildElementByTagName(persistenceElm, TX_MANAGER_ATTRIBUTE);
            String ref = tnxMng.getAttribute("ref");

            beanBuilder.addPropertyReference("platformTransactionManager", ref);

            Element emf = DomUtils.getChildElementByTagName(persistenceElm, EMF_ATTRIBUTE);
            ref = emf.getAttribute("ref");
            beanBuilder.addPropertyReference("entityManagerFactory", ref);

            Element variablePersisters = DomUtils.getChildElementByTagName(persistenceElm,
                    "variable-persisters");
            if (variablePersisters != null && variablePersisters.hasChildNodes()) {
                List<Element> childPersisterElems = DomUtils.getChildElementsByTagName(variablePersisters,
                        "persister");
                ManagedMap persistors = new ManagedMap(childPersisterElems.size());
                for (Element persisterElem : childPersisterElems) {
                    String forClass = persisterElem.getAttribute(FORCLASS_ATTRIBUTE);
                    String implementation = persisterElem.getAttribute(IMPLEMENTATION_ATTRIBUTE);
                    if (!StringUtils.hasText(forClass)) {
                        throw new RuntimeException("persister element must have valid for-class attribute");
                    }
                    if (!StringUtils.hasText(implementation)) {
                        throw new RuntimeException(
                                "persister element must have valid implementation attribute");
                    }
                    persistors.put(forClass, implementation);
                }
                beanBuilder.addPropertyValue("variablePersisters", persistors);
            }

            factory.addPropertyValue("jpaConfiguration", beanBuilder.getBeanDefinition());
        }
        BeanDefinitionBuilder rbaseConfBuilder = BeanDefinitionBuilder
                .rootBeanDefinition(SessionConfiguration.class);
        Element e = DomUtils.getChildElementByTagName(ksessionConf, KEEP_REFERENCE);
        if (e != null && StringUtils.hasText(e.getAttribute("enabled"))) {
            rbaseConfBuilder.addPropertyValue("keepReference", Boolean.parseBoolean(e.getAttribute("enabled")));
        }

        e = DomUtils.getChildElementByTagName(ksessionConf, CLOCK_TYPE);
        if (e != null && StringUtils.hasText(e.getAttribute("type"))) {
            rbaseConfBuilder.addPropertyValue("clockType", ClockType.resolveClockType(e.getAttribute("type")));
        }
        factory.addPropertyValue("conf", rbaseConfBuilder.getBeanDefinition());

        e = DomUtils.getChildElementByTagName(ksessionConf, WORK_ITEMS);
        if (e != null) {
            List<Element> children = DomUtils.getChildElementsByTagName(e, WORK_ITEM);
            if (children != null && !children.isEmpty()) {
                ManagedMap workDefs = new ManagedMap();
                for (Element child : children) {
                    workDefs.put(child.getAttribute("name"),
                            new RuntimeBeanReference(child.getAttribute("ref")));
                }
                factory.addPropertyValue("workItems", workDefs);
            }
        }
    }

    Element batch = DomUtils.getChildElementByTagName(element, "batch");
    if (batch == null) {
        // just temporary legacy suppport
        batch = DomUtils.getChildElementByTagName(element, "script");
    }
    if (batch != null) {
        // we know there can only ever be one
        ManagedList children = new ManagedList();

        for (int i = 0, length = batch.getChildNodes().getLength(); i < length; i++) {
            Node n = batch.getChildNodes().item(i);
            if (n instanceof Element) {
                Element e = (Element) n;

                BeanDefinitionBuilder beanBuilder = null;
                if ("insert-object".equals(e.getLocalName())) {
                    String ref = e.getAttribute("ref");
                    Element nestedElm = getFirstElement(e.getChildNodes());
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(InsertObjectCommand.class);
                    if (StringUtils.hasText(ref)) {
                        beanBuilder.addConstructorArgReference(ref);
                    } else if (nestedElm != null) {
                        beanBuilder.addConstructorArgValue(
                                parserContext.getDelegate().parsePropertySubElement(nestedElm, null, null));
                    } else {
                        throw new IllegalArgumentException(
                                "insert-object must either specify a 'ref' attribute or have a nested bean");
                    }
                } else if ("set-global".equals(e.getLocalName())) {
                    String ref = e.getAttribute("ref");
                    Element nestedElm = getFirstElement(e.getChildNodes());
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(SetGlobalCommand.class);
                    beanBuilder.addConstructorArgValue(e.getAttribute("identifier"));
                    if (StringUtils.hasText(ref)) {
                        beanBuilder.addConstructorArgReference(ref);
                    } else if (nestedElm != null) {
                        beanBuilder.addConstructorArgValue(
                                parserContext.getDelegate().parsePropertySubElement(nestedElm, null, null));
                    } else {
                        throw new IllegalArgumentException(
                                "set-global must either specify a 'ref' attribute or have a nested bean");
                    }
                } else if ("fire-until-halt".equals(e.getLocalName())) {
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(FireUntilHaltCommand.class);
                } else if ("fire-all-rules".equals(e.getLocalName())) {
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(FireAllRulesCommand.class);
                    String max = e.getAttribute("max");
                    if (StringUtils.hasText(max)) {
                        beanBuilder.addPropertyValue("max", max);
                    }
                } else if ("start-process".equals(e.getLocalName())) {

                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(StartProcessCommand.class);
                    String processId = e.getAttribute("process-id");
                    if (!StringUtils.hasText(processId)) {
                        throw new IllegalArgumentException("start-process must specify a process-id");
                    }
                    beanBuilder.addConstructorArgValue(processId);

                    List<Element> params = DomUtils.getChildElementsByTagName(e, "parameter");
                    if (!params.isEmpty()) {
                        ManagedMap map = new ManagedMap();
                        for (Element param : params) {
                            String identifier = param.getAttribute("identifier");
                            if (!StringUtils.hasText(identifier)) {
                                throw new IllegalArgumentException(
                                        "start-process paramaters must specify an identifier");
                            }

                            String ref = param.getAttribute("ref");
                            Element nestedElm = getFirstElement(param.getChildNodes());
                            if (StringUtils.hasText(ref)) {
                                map.put(identifier, new RuntimeBeanReference(ref));
                            } else if (nestedElm != null) {
                                map.put(identifier, parserContext.getDelegate()
                                        .parsePropertySubElement(nestedElm, null, null));
                            } else {
                                throw new IllegalArgumentException(
                                        "start-process parameters must either specify a 'ref' attribute or have a nested bean");
                            }
                        }
                        beanBuilder.addPropertyValue("parameters", map);
                    }
                } else if ("signal-event".equals(e.getLocalName())) {
                    beanBuilder = BeanDefinitionBuilder.genericBeanDefinition(SignalEventCommand.class);
                    String processInstanceId = e.getAttribute("process-instance-id");
                    if (StringUtils.hasText(processInstanceId)) {
                        beanBuilder.addConstructorArgValue(processInstanceId);
                    }

                    beanBuilder.addConstructorArgValue(e.getAttribute("event-type"));

                    String ref = e.getAttribute("ref");
                    Element nestedElm = getFirstElement(e.getChildNodes());
                    if (StringUtils.hasText(ref)) {
                        beanBuilder.addConstructorArgReference(ref);
                    } else if (nestedElm != null) {
                        beanBuilder.addConstructorArgValue(
                                parserContext.getDelegate().parsePropertySubElement(nestedElm, null, null));
                    } else {
                        throw new IllegalArgumentException(
                                "signal-event must either specify a 'ref' attribute or have a nested bean");
                    }
                }
                if (beanBuilder == null) {
                    throw new IllegalStateException("Unknow element: " + e.getLocalName());
                }
                children.add(beanBuilder.getBeanDefinition());
            }
        }
        factory.addPropertyValue("batch", children);
    }

    // find any kagent's for the current kbase and assign (only if this 
    // is a stateless session)
    if (sessionType.equals("stateless")) {
        for (String beanName : parserContext.getRegistry().getBeanDefinitionNames()) {
            BeanDefinition def = parserContext.getRegistry().getBeanDefinition(beanName);
            if (KnowledgeAgentBeanFactory.class.getName().equals(def.getBeanClassName())) {
                PropertyValue pvalue = def.getPropertyValues().getPropertyValue("kbase");
                RuntimeBeanReference tbf = (RuntimeBeanReference) pvalue.getValue();
                if (kbase.equals(tbf.getBeanName())) {
                    factory.addPropertyValue("knowledgeAgent", new RuntimeBeanReference(beanName));
                }
            }
        }
    }

    return factory.getBeanDefinition();
}

From source file:org.drools.container.spring.namespace.KnowledgeBaseDefinitionParser.java

@SuppressWarnings("unchecked")
public static ManagedList getResources(Element element, ParserContext parserContext,
        BeanDefinitionBuilder factory) {
    Element resourcesElm = DomUtils.getChildElementByTagName(element, "resources");
    ManagedList resources = null;//from   w w w .java 2s.  c  o m

    if (resourcesElm != null) {
        List<Element> childElements = DomUtils.getChildElementsByTagName(resourcesElm, "resource");
        if (childElements != null && !childElements.isEmpty()) {
            resources = new ManagedList();
            for (Element childResource : childElements) {
                BeanDefinition resourceDefinition = parserContext.getDelegate()
                        .parseCustomElement(childResource, factory.getBeanDefinition());
                resources.add(resourceDefinition);
            }
        }

    }
    return resources;
}

From source file:com.sitewhere.configuration.ConfigurationMigrationSupport.java

/**
 * Perform the migration work./*w w  w . j ava2s .  c om*/
 * 
 * @param document
 * @throws SiteWhereException
 */
protected static void migrateTenantConfiguration(Document document) throws SiteWhereException {
    Element beans = document.getDocumentElement();
    Element config = DomUtils.getChildElementByTagName(beans, "tenant-configuration");
    if (config == null) {
        throw new SiteWhereException("Tenant configuration element not found.");
    }
    Element dcomm = DomUtils.getChildElementByTagName(config, "device-communication");
    if (dcomm == null) {
        throw new SiteWhereException("Device communication element missing.");
    }
    Element asset = DomUtils.getChildElementByTagName(config, "asset-management");
    if (asset == null) {
        throw new SiteWhereException("Asset management element missing.");
    }
    Element eproc = DomUtils.getChildElementByTagName(config, "event-processing");
    if (eproc == null) {
        LOGGER.info("Event processing element missing. Migrating to new configuration format.");
        eproc = document.createElementNS(config.getNamespaceURI(), "event-processing");
        eproc.setPrefix(config.getPrefix());
        config.insertBefore(eproc, asset);

        moveEventProcessingElements(config, dcomm, eproc, document);
    }
    document.normalizeDocument();
}

From source file:it.pronetics.madstore.common.configuration.spring.MadStoreConfigurationBeanDefinitionParser.java

protected void doParse(Element element, ParserContext parserContext,
        BeanDefinitionBuilder beanDefinitionBuilder) {
    try {/*from ww  w .j  a va  2s. c  o  m*/
        String madStoreDir = MadStoreConfigurationManager.getInstance().getMadStoreHome();
        beanDefinitionBuilder.addPropertyValue(MADSTORE_HOME_BEAN_PROPERTY, madStoreDir);

        Element crawlerElement = DomUtils.getChildElementByTagName(element, CRAWLER);
        Element repositoryElement = DomUtils.getChildElementByTagName(element, REPOSITORY);
        Element serverElement = DomUtils.getChildElementByTagName(element, SERVER);
        Element tasksElement = DomUtils.getChildElementByTagName(element, TASKS_TAG);
        if (repositoryElement == null) {
            throw new IllegalStateException("At least one " + REPOSITORY + " element should be present.");
        }
        if (crawlerElement != null) {
            parseCrawlerConfigurations(crawlerElement, beanDefinitionBuilder);
            parseGridConfiguration(crawlerElement, beanDefinitionBuilder);
        } else {
            dummyCrawlerConfigurations(beanDefinitionBuilder);
        }
        parseJcrConfiguration(repositoryElement, beanDefinitionBuilder);
        parseIndexConfiguration(repositoryElement, beanDefinitionBuilder);
        if (serverElement != null) {
            Element httpCacheEnabled = DomUtils.getChildElementByTagName(serverElement, HTTPCACHE_ENABLED_TAG);
            HttpCacheConfiguration httpCacheConfiguration = new HttpCacheConfiguration();
            Integer maxAge = new Integer(0);
            if (httpCacheEnabled != null) {
                maxAge = new Integer(httpCacheEnabled.getAttribute(MAX_AGE_ATTRIBUTE));
            }
            httpCacheConfiguration.setMaxAge(maxAge);
            beanDefinitionBuilder.addPropertyValue(HTTP_CACHE_CONFIGURATION_BEAN_PROPERTY,
                    httpCacheConfiguration);
            parseAppConfiguration(serverElement, beanDefinitionBuilder);
            parseOsConfiguration(serverElement, beanDefinitionBuilder);
        } else {
            dummyAppConfiguration(beanDefinitionBuilder);
            dummyOsConfiguration(beanDefinitionBuilder);
        }
        parseTasksConfiguration(tasksElement, beanDefinitionBuilder);
    } catch (Exception ex) {
        throw new MadStoreConfigurationException(ex.getMessage(), ex);
    }
}

From source file:com.springsource.hq.plugin.tcserver.plugin.serverconfig.general.GeneralConfigConverter.java

/**
 * This method sifts through server.xml to find the AprLifecycleListener. If it exists, but is not defined in the
 * locally cached copy of GeneralConfig, it is stripped out when pushing a new copy of server.xml. If it exists,
 * then the className is forced to the correct fully qualified class name. If it doesn't exist, and IS defined in
 * GeneralConfig, it is added to server.xml.
 *//*from w w  w .j  av a2s.  c  o m*/
private void convertAprLifecycleListener(Document document, Element server,
        AprLifecycleListener configuredAprLifecycleListener) {
    Element aprLifecycleListenerXmlElementInServerXml = null;
    Element lastListener = null;
    boolean foundAprLifecycleXmlElementInServerXml = false;

    List<Element> listeners = DomUtils.getChildElementsByTagName(server, TAG_NAME_LISTENER);

    for (Element listener : listeners) {
        lastListener = listener; // We need to catch the last listener, so we can insert before its nextSibling.
        if (isAprLifecycleListener(listener)) {
            foundAprLifecycleXmlElementInServerXml = true;
            aprLifecycleListenerXmlElementInServerXml = listener;
            if (configuredAprLifecycleListener == null) {
                server.removeChild(aprLifecycleListenerXmlElementInServerXml);
            }
        }
    }

    if (configuredAprLifecycleListener != null) {
        if (!foundAprLifecycleXmlElementInServerXml) {
            aprLifecycleListenerXmlElementInServerXml = document.createElement(TAG_NAME_LISTENER);
        }
        aprLifecycleListenerXmlElementInServerXml.setAttribute(ATTRIBUTE_CLASS_NAME,
                CLASS_NAME_APR_LIFECYCLE_LISTENER);
        if (!foundAprLifecycleXmlElementInServerXml) {
            if (lastListener != null) {
                // Strangely, there doesn't appear to be any sort of insertAfter() call, so we have to fetch the
                // next sibling.
                server.insertBefore(aprLifecycleListenerXmlElementInServerXml, lastListener.getNextSibling());
            } else {
                Element globalNamingResources = DomUtils.getChildElementByTagName(server,
                        "GlobalNamingResources");
                server.insertBefore(aprLifecycleListenerXmlElementInServerXml, globalNamingResources);
            }

        }
    }
}

From source file:com.dangdang.ddframe.rdb.sharding.spring.namespace.parser.ShardingJdbcDataSourceBeanDefinitionParser.java

private List<BeanDefinition> parseBindingTablesConfig(final Element element) {
    Element bindingTableRulesElement = DomUtils.getChildElementByTagName(element,
            ShardingJdbcDataSourceBeanDefinitionParserTag.BINDING_TABLE_RULES_TAG);
    if (null == bindingTableRulesElement) {
        return Collections.emptyList();
    }/*from  w  ww.java2s  .  com*/
    List<Element> bindingTableRuleElements = DomUtils.getChildElementsByTagName(bindingTableRulesElement,
            ShardingJdbcDataSourceBeanDefinitionParserTag.BINDING_TABLE_RULE_TAG);
    BeanDefinitionBuilder bindingTableRuleFactory = BeanDefinitionBuilder
            .rootBeanDefinition(BindingTableRuleConfig.class);
    List<BeanDefinition> result = new ManagedList<>(bindingTableRuleElements.size());
    for (Element bindingTableRuleElement : bindingTableRuleElements) {
        bindingTableRuleFactory.addPropertyValue("tableNames", bindingTableRuleElement
                .getAttribute(ShardingJdbcDataSourceBeanDefinitionParserTag.LOGIC_TABLES_ATTRIBUTE));
        result.add(bindingTableRuleFactory.getBeanDefinition());
    }
    return result;
}