Search in sources :

Example 6 with Element

use of org.w3c.dom.Element in project sharding-jdbc by dangdangdotcom.

the class ShardingJdbcDataSourceBeanDefinitionParser method parseShardingRuleConfig.

private BeanDefinition parseShardingRuleConfig(final Element element, final ParserContext parserContext) {
    Element shardingRuleElement = DomUtils.getChildElementByTagName(element, ShardingJdbcDataSourceBeanDefinitionParserTag.SHARDING_RULE_CONFIG_TAG);
    BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(ShardingRuleConfig.class);
    factory.addPropertyValue("dataSource", parseDataSources(shardingRuleElement, parserContext));
    parseDefaultDataSource(factory, shardingRuleElement);
    factory.addPropertyValue("tables", parseTableRulesConfig(shardingRuleElement));
    factory.addPropertyValue("bindingTables", parseBindingTablesConfig(shardingRuleElement));
    factory.addPropertyValue("defaultDatabaseStrategy", parseDefaultDatabaseStrategyConfig(shardingRuleElement));
    factory.addPropertyValue("defaultTableStrategy", parseDefaultTableStrategyConfig(shardingRuleElement));
    parseIdGenerator(factory, shardingRuleElement);
    return factory.getBeanDefinition();
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) Element(org.w3c.dom.Element)

Example 7 with Element

use of org.w3c.dom.Element in project sharding-jdbc by dangdangdotcom.

the class ShardingJdbcDataSourceBeanDefinitionParser method parseTableRulesConfig.

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));
    }
    return result;
}
Also used : Element(org.w3c.dom.Element) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 8 with Element

use of org.w3c.dom.Element in project sharding-jdbc by dangdangdotcom.

the class ShardingJdbcDataSourceBeanDefinitionParser method parseBindingTablesConfig.

private List<BeanDefinition> parseBindingTablesConfig(final Element element) {
    Element bindingTableRulesElement = DomUtils.getChildElementByTagName(element, ShardingJdbcDataSourceBeanDefinitionParserTag.BINDING_TABLE_RULES_TAG);
    if (null == bindingTableRulesElement) {
        return Collections.emptyList();
    }
    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;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) Element(org.w3c.dom.Element) ManagedList(org.springframework.beans.factory.support.ManagedList) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 9 with Element

use of org.w3c.dom.Element in project elastic-job by dangdangdotcom.

the class AbstractJobBeanDefinitionParser method createJobListeners.

private List<BeanDefinition> createJobListeners(final Element element) {
    Element listenerElement = DomUtils.getChildElementByTagName(element, LISTENER_TAG);
    Element distributedListenerElement = DomUtils.getChildElementByTagName(element, DISTRIBUTED_LISTENER_TAG);
    List<BeanDefinition> result = new ManagedList<>(2);
    if (null != listenerElement) {
        BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(listenerElement.getAttribute(CLASS_ATTRIBUTE));
        factory.setScope(BeanDefinition.SCOPE_PROTOTYPE);
        result.add(factory.getBeanDefinition());
    }
    if (null != distributedListenerElement) {
        BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(distributedListenerElement.getAttribute(CLASS_ATTRIBUTE));
        factory.setScope(BeanDefinition.SCOPE_PROTOTYPE);
        factory.addConstructorArgValue(distributedListenerElement.getAttribute(DISTRIBUTED_LISTENER_STARTED_TIMEOUT_MILLISECONDS_ATTRIBUTE));
        factory.addConstructorArgValue(distributedListenerElement.getAttribute(DISTRIBUTED_LISTENER_COMPLETED_TIMEOUT_MILLISECONDS_ATTRIBUTE));
        result.add(factory.getBeanDefinition());
    }
    return result;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) Element(org.w3c.dom.Element) ManagedList(org.springframework.beans.factory.support.ManagedList) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 10 with Element

use of org.w3c.dom.Element in project lucida by claritylab.

the class TREC13To16Parser method loadTargets.

/**
	 * Loads the target objects from a file.
	 * 
	 * @param filename file that contains the targets
	 * @return targets or <code>null</code>, if the file could not be parsed
	 */
public static TRECTarget[] loadTargets(String filename) {
    try {
        // create factory object
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        // create DOM parser
        DocumentBuilder parser = factory.newDocumentBuilder();
        // parse file and build tree
        Document trecD = parser.parse(new File(filename));
        NodeList targetL = trecD.getElementsByTagName("target");
        TRECTarget[] targets = new TRECTarget[targetL.getLength()];
        for (int i = 0; i < targets.length; i++) {
            Element targetE = (Element) targetL.item(i);
            String targetId = targetE.getAttribute("id").trim();
            String targetDesc = targetE.getAttribute("text").trim();
            NodeList questionL = targetE.getElementsByTagName("q");
            TRECQuestion[] questions = new TRECQuestion[questionL.getLength()];
            for (int j = 0; j < questions.length; j++) {
                Element questionE = (Element) questionL.item(j);
                String questionId = questionE.getAttribute("id").trim();
                String type = questionE.getAttribute("type").trim();
                String questionString = questionE.getFirstChild().getNodeValue().trim();
                questions[j] = new TRECQuestion(questionId, type, questionString);
            }
            targets[i] = new TRECTarget(targetId, targetDesc, questions);
        }
        return targets;
    } catch (Exception e) {
        MsgPrinter.printErrorMsg("Failed to load or parse question file:");
        MsgPrinter.printErrorMsg(e.toString());
        return null;
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) IOException(java.io.IOException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) File(java.io.File)

Aggregations

Element (org.w3c.dom.Element)9072 Document (org.w3c.dom.Document)2651 NodeList (org.w3c.dom.NodeList)2103 Node (org.w3c.dom.Node)1855 ArrayList (java.util.ArrayList)957 DocumentBuilder (javax.xml.parsers.DocumentBuilder)793 IOException (java.io.IOException)732 Test (org.junit.Test)693 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)591 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)489 HashMap (java.util.HashMap)434 SAXException (org.xml.sax.SAXException)406 File (java.io.File)358 Attr (org.w3c.dom.Attr)333 InputStream (java.io.InputStream)309 QName (javax.xml.namespace.QName)292 Map (java.util.Map)285 JAXBElement (javax.xml.bind.JAXBElement)285 NamedNodeMap (org.w3c.dom.NamedNodeMap)266 List (java.util.List)264