Java Code Examples for org.apache.commons.configuration.XMLConfiguration#getList()
The following examples show how to use
org.apache.commons.configuration.XMLConfiguration#getList() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MonetaConfiguration.java From moneta with Apache License 2.0 | 6 votes |
protected void initTopics(XMLConfiguration config) { int nbrTopics = 0; Object temp = config.getList("Topics.Topic[@name]"); if (temp instanceof Collection) { nbrTopics = ((Collection)temp).size(); } Topic topic; String readOnlyStr; for (int i = 0; i < nbrTopics; i++) { topic = new Topic(); gatherTopicAttributes(config, topic, i); gatherAliasAttributes(config, topic); gatherKeyFields(config, topic); validateTopic(topic); topicMap.put(topic.getTopicName(), topic); pluralNameMap.put(topic.getPluralName(), topic); } Validate.isTrue(topicMap.size() > 0, "No Topics configured."); }
Example 2
Source File: MonetaConfiguration.java From moneta with Apache License 2.0 | 6 votes |
protected void gatherAliasAttributes(XMLConfiguration config, Topic topic) { int nbrAliases = 0; Object temp = config.getList("Topics.Topic.Alias[@name]"); if (temp instanceof Collection) { nbrAliases = ((Collection)temp).size(); } String name, column; for (int i = 0; i < nbrAliases; i++) { name=config.getString("Topics.Topic.Alias(" + i + ")[@name]"); column=config.getString("Topics.Topic.Alias(" + i + ")[@column]"); if (StringUtils.isEmpty(name) || StringUtils.isEmpty(column)) { throw new MonetaException("Topic Alias fields must have both name and column specified") .addContextValue("topic", topic.getTopicName()) .addContextValue("name", name) .addContextValue("column", column); } topic.getAliasMap().put(column, name); } }
Example 3
Source File: readMultiNode.java From JavaRock with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws ConfigurationException { XMLConfiguration config = new XMLConfiguration("CourseManagementSystem.xml"); List techIdList = config.getList("Teachers.Teacher.id"); for (Object id : techIdList) { System.out.println(id); } }
Example 4
Source File: MonetaConfiguration.java From moneta with Apache License 2.0 | 5 votes |
protected void gatherKeyFields(XMLConfiguration config, Topic topic) { int nbrKeyFields = 0; Object temp = config.getList("Topics.Topic.PrimaryKey.Field[@name]"); if (temp instanceof Collection) { nbrKeyFields = ((Collection)temp).size(); } String name, typeStr; TopicKeyField.DataType dataType; TopicKeyField keyField; for (int i = 0; i < nbrKeyFields; i++) { name=config.getString("Topics.Topic.PrimaryKey.Field(" + i + ")[@name]"); typeStr=config.getString("Topics.Topic.PrimaryKey.Field(" + i + ")[@type]"); if (StringUtils.isEmpty(name) || StringUtils.isEmpty(typeStr)) { throw new MonetaException("Topic Primary Key Fields fields must have both name and type specified") .addContextValue("topic", topic.getTopicName()) .addContextValue("name", name) .addContextValue("type", typeStr); } try {dataType = TopicKeyField.DataType.valueOf(typeStr.toUpperCase());} catch (Exception e) { throw new MonetaException("Datatype not supported", e) .addContextValue("topic", topic.getTopicName()) .addContextValue("key field", name) .addContextValue("dataType", typeStr); } keyField = new TopicKeyField(); topic.getKeyFieldList().add(keyField); keyField.setColumnName(name); keyField.setDataType(dataType); } }
Example 5
Source File: TestSettings.java From sailfish-core with Apache License 2.0 | 4 votes |
@Test public void testServerSettings() { try { String configFilePath = new File(".").getCanonicalPath(); String fileFQN = configFilePath + File.separator + "cfg" + File.separator + "config.xml"; if(new File(fileFQN).exists()) { XMLConfiguration config = new XMLConfiguration( fileFQN ); config.load(); Object servers = config.getProperty("Environment.ConnectionManager.Services.Service[@name]"); if(servers instanceof Collection<?>) { for(int i = 0 ; i < ((Collection<?>) servers).size(); i++) { String key = String.format( "Environment.ConnectionManager.Services.Service(%d)[@type]", i ); String keyValue = config.getString(key ); if("NTG-Server".equals(keyValue)) { String instIdKey = String.format( "Environment.ConnectionManager.Services.Service(%d).strategies.strategy.instrumentID", i ); Object prop = config.getList(instIdKey); if(prop instanceof Collection<?>) { NTGServerSettings serverSettings = new NTGServerSettings(); Map<String, NTGServerStrategy> strategy = new HashMap<String, NTGServerStrategy>(); int j = 0 ; for(Object instrValue : (Collection<?>)prop) { //String symbol = config.getString(String.format( "Environment.ConnectionManager.Services.Service(%d).strategies.strategy(%d).instrumentID", i, j)); String symbol = instrValue.toString(); if(! strategy.containsKey( symbol )) { String strategyValueString = config.getString(String.format( "Environment.ConnectionManager.Services.Service(%d).strategies.strategy(%d).strategyValue", i, j)); NTGServerStrategy strategyValue = Enum.valueOf(NTGServerStrategy.class, strategyValueString); strategy.put( symbol, strategyValue ); } ++j; } int heartbeatTimeout = config.getInt(String.format("Environment.ConnectionManager.Services.Service(%d).heartbeatTimeout", i )); int maxMissedHeartbeats = config.getInt(String.format("Environment.ConnectionManager.Services.Service(%d).maxMissedHeartbeats", i )); int serverPort = config.getInt( String.format("Environment.ConnectionManager.Services.Service(%d).serverPort", i )); String serverIP = config.getString(String.format("Environment.ConnectionManager.Services.Service(%d).serverIP", i )); serverSettings.setHeartbeatTimeout( heartbeatTimeout ); serverSettings.setMaxMissedHeartbeats( maxMissedHeartbeats ); serverSettings.setServerPort( serverPort ) ; serverSettings.setServerIP( serverIP ) ; serverSettings.setStrategy( strategy ); } break; } Assert.fail(); } } } } catch(Exception ex) { ex.printStackTrace(); Assert.fail(); } }
Example 6
Source File: Test.java From JavaRock with Apache License 2.0 | 3 votes |
public static void main( String[] args ) throws ConfigurationException { XMLConfiguration xml = new XMLConfiguration( "WreSalesSystemInfo.xml" ); List< Object > userIDList = xml.getList( "Users.User.id" ); for (int i = 1 ; i<=userIDList.size() ; i++ ){ userIDList.get(i-1); } }