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();
}
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;
}
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;
}
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;
}
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;
}
}
Aggregations