PageRenderTime 31ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/servers/diameter/core/jdiameter/impl/src/main/java/org/jdiameter/server/impl/helpers/XMLConfiguration.java

http://mobicents.googlecode.com/
Java | 647 lines | 517 code | 72 blank | 58 comment | 179 complexity | 76f8d026e3e89d3866e83dc34256d25a MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0, LGPL-2.1, GPL-2.0, CC-BY-SA-3.0, CC0-1.0, Apache-2.0, BSD-3-Clause
  1. /*
  2. * JBoss, Home of Professional Open Source
  3. * Copyright 2006, Red Hat, Inc. and individual contributors
  4. * by the @authors tag. See the copyright.txt in the distribution for a
  5. * full listing of individual contributors.
  6. *
  7. * This is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation; either version 2.1 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This software is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this software; if not, write to the Free
  19. * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  21. */
  22. package org.jdiameter.server.impl.helpers;
  23. import org.jdiameter.api.Configuration;
  24. import org.jdiameter.client.impl.helpers.AppConfiguration;
  25. import org.jdiameter.client.impl.helpers.Ordinal;
  26. import static org.jdiameter.server.impl.helpers.ExtensionPoint.*;
  27. import static org.jdiameter.client.impl.helpers.Parameters.Agent;
  28. import static org.jdiameter.client.impl.helpers.Parameters.CipherSuites;
  29. import static org.jdiameter.client.impl.helpers.Parameters.DictionaryClass;
  30. import static org.jdiameter.client.impl.helpers.Parameters.DictionaryEnabled;
  31. import static org.jdiameter.client.impl.helpers.Parameters.DictionaryReceiveLevel;
  32. import static org.jdiameter.client.impl.helpers.Parameters.DictionarySendLevel;
  33. import static org.jdiameter.client.impl.helpers.Parameters.KDFile;
  34. import static org.jdiameter.client.impl.helpers.Parameters.KDManager;
  35. import static org.jdiameter.client.impl.helpers.Parameters.KDPwd;
  36. import static org.jdiameter.client.impl.helpers.Parameters.KDStore;
  37. import static org.jdiameter.client.impl.helpers.Parameters.KeyData;
  38. import static org.jdiameter.client.impl.helpers.Parameters.Properties;
  39. import static org.jdiameter.client.impl.helpers.Parameters.PropertyName;
  40. import static org.jdiameter.client.impl.helpers.Parameters.PropertyValue;
  41. import static org.jdiameter.client.impl.helpers.Parameters.RealmEntry;
  42. import static org.jdiameter.client.impl.helpers.Parameters.SDEnableSessionCreation;
  43. import static org.jdiameter.client.impl.helpers.Parameters.SDName;
  44. import static org.jdiameter.client.impl.helpers.Parameters.SDProtocol;
  45. import static org.jdiameter.client.impl.helpers.Parameters.SDUseClientMode;
  46. import static org.jdiameter.client.impl.helpers.Parameters.Security;
  47. import static org.jdiameter.client.impl.helpers.Parameters.SecurityRef;
  48. import static org.jdiameter.client.impl.helpers.Parameters.StatisticsActiveList;
  49. import static org.jdiameter.client.impl.helpers.Parameters.StatisticsEnabled;
  50. import static org.jdiameter.client.impl.helpers.Parameters.StatisticsLoggerDelay;
  51. import static org.jdiameter.client.impl.helpers.Parameters.StatisticsLoggerPause;
  52. import static org.jdiameter.client.impl.helpers.Parameters.TDFile;
  53. import static org.jdiameter.client.impl.helpers.Parameters.TDManager;
  54. import static org.jdiameter.client.impl.helpers.Parameters.TDPwd;
  55. import static org.jdiameter.client.impl.helpers.Parameters.TDStore;
  56. import static org.jdiameter.client.impl.helpers.Parameters.TrustData;
  57. import static org.jdiameter.server.impl.helpers.Parameters.*;
  58. import org.w3c.dom.Document;
  59. import org.w3c.dom.Element;
  60. import org.w3c.dom.NamedNodeMap;
  61. import org.w3c.dom.Node;
  62. import org.w3c.dom.NodeList;
  63. import javax.xml.XMLConstants;
  64. import javax.xml.parsers.DocumentBuilder;
  65. import javax.xml.parsers.DocumentBuilderFactory;
  66. import javax.xml.transform.Source;
  67. import javax.xml.transform.dom.DOMSource;
  68. import javax.xml.transform.stream.StreamSource;
  69. import javax.xml.validation.Schema;
  70. import javax.xml.validation.SchemaFactory;
  71. import javax.xml.validation.Validator;
  72. import java.io.File;
  73. import java.io.InputStream;
  74. import java.util.ArrayList;
  75. import java.util.Hashtable;
  76. import java.util.List;
  77. /**
  78. * This class provide loading and verification configuration for server from XML file
  79. *
  80. * @author erick.svenson@yahoo.com
  81. * @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a>
  82. * @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a>
  83. */
  84. public class XMLConfiguration extends EmptyConfiguration {
  85. /**
  86. * Create instance of class and load file from defined input stream
  87. *
  88. * @param in input stream
  89. * @throws Exception
  90. */
  91. public XMLConfiguration(InputStream in) throws Exception {
  92. this(in, null, null, false);
  93. }
  94. /**
  95. * Create instance of class and load file from defined input stream
  96. *
  97. * @param in input stream
  98. * @param attributes attributes for DocumentBuilderFactory
  99. * @param features features for DocumentBuilderFactory
  100. * @throws Exception
  101. */
  102. public XMLConfiguration(InputStream in, Hashtable<String, Object> attributes, Hashtable<String, Boolean> features) throws Exception {
  103. this(in, attributes, features, false);
  104. }
  105. /**
  106. * Create instance of class and load file from defined file name
  107. *
  108. * @param filename configuration file name
  109. * @throws Exception
  110. */
  111. public XMLConfiguration(String filename) throws Exception {
  112. this(filename, null, null, false);
  113. }
  114. /**
  115. * Create instance of class and load file from defined input stream
  116. *
  117. * @param filename configuration file name
  118. * @param attributes attributes for DocumentBuilderFactory
  119. * @param features features for DocumentBuilderFactory
  120. * @throws Exception
  121. */
  122. public XMLConfiguration(String filename, Hashtable<String, Object> attributes, Hashtable<String, Boolean> features) throws Exception {
  123. this(filename, attributes, features, false);
  124. }
  125. protected XMLConfiguration(Object in, Hashtable<String, Object> attributes, Hashtable<String, Boolean> features, boolean nop) throws Exception {
  126. DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  127. factory.setNamespaceAware(true);
  128. if (attributes != null) {
  129. for (String key : attributes.keySet()) {
  130. factory.setAttribute(key, attributes.get(key));
  131. }
  132. }
  133. if (features != null) {
  134. for (String key : features.keySet()) {
  135. factory.setFeature(key, features.get(key));
  136. }
  137. }
  138. DocumentBuilder builder = factory.newDocumentBuilder();
  139. Document document;
  140. if (in instanceof InputStream) {
  141. document = builder.parse((InputStream) in);
  142. }
  143. else if (in instanceof String) {
  144. document = builder.parse(new File((String) in));
  145. }
  146. else {
  147. throw new Exception("Unknown type of input data");
  148. }
  149. validate(document);
  150. processing(document);
  151. }
  152. protected void validate(Document document) throws Exception {
  153. SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
  154. Source schemaFile = new StreamSource(getClass().getResourceAsStream("/META-INF/jdiameter-server.xsd"));
  155. Schema schema = factory.newSchema(schemaFile);
  156. Validator validator = schema.newValidator();
  157. validator.validate(new DOMSource(document));
  158. }
  159. protected void processing(Document document) {
  160. Element element = document.getDocumentElement();
  161. NodeList c = element.getChildNodes();
  162. for (int i = 0; i < c.getLength(); i++) {
  163. String nodeName = c.item(i).getNodeName();
  164. if (nodeName.equals("LocalPeer")) {
  165. addLocalPeer(c.item(i));
  166. }
  167. else if (nodeName.equals("Parameters")) {
  168. addParameters(c.item(i));
  169. }
  170. else if (nodeName.equals("Security")) {
  171. addSecurity(c.item(i));
  172. }
  173. else if (nodeName.equals("Network")) {
  174. addNetwork(c.item(i));
  175. }
  176. else if (nodeName.equals("Extensions")) {
  177. addExtensions(c.item(i));
  178. }
  179. }
  180. }
  181. protected void addApplications(Node node) {
  182. NodeList c = node.getChildNodes();
  183. ArrayList<Configuration> items = new ArrayList<Configuration>();
  184. for (int i = 0; i < c.getLength(); i++) {
  185. String nodeName = c.item(i).getNodeName();
  186. if (nodeName.equals("ApplicationID")) {
  187. Configuration m = addApplicationID(c.item(i));
  188. if (m != null) {
  189. items.add(m);
  190. }
  191. }
  192. }
  193. add(ApplicationId, items.toArray(EMPTY_ARRAY));
  194. }
  195. protected Configuration addApplicationID(NodeList node) {
  196. for (int i = 0; i < node.getLength(); i++) {
  197. String nodeName = node.item(i).getNodeName();
  198. if (nodeName.equals("ApplicationID")) {
  199. return addApplicationID(node.item(i));
  200. }
  201. }
  202. return null;
  203. }
  204. protected Configuration addApplicationID(Node node) {
  205. NodeList c = node.getChildNodes();
  206. AppConfiguration e = getInstance();
  207. for (int i = 0; i < c.getLength(); i++) {
  208. String nodeName = c.item(i).getNodeName();
  209. if (nodeName.equals("VendorId")) e.add(VendorId, getLongValue(c.item(i)));
  210. else if (nodeName.equals("AuthApplId")) e.add(AuthApplId, getLongValue(c.item(i)));
  211. else if (nodeName.equals("AcctApplId")) e.add(AcctApplId, getLongValue(c.item(i)));
  212. }
  213. return e;
  214. }
  215. protected void addParameters(Node node) {
  216. NodeList c = node.getChildNodes();
  217. for (int i = 0; i < c.getLength(); i++) {
  218. String nodeName = c.item(i).getNodeName();
  219. if (nodeName.equals("UseUriAsFqdn")) { add(UseUriAsFqdn, Boolean.valueOf(getValue(c.item(i)))); }
  220. else if (nodeName.equals("QueueSize")) { add(QueueSize, getIntValue(c.item(i))); }
  221. else if (nodeName.equals("MessageTimeOut")) { add(MessageTimeOut, getLongValue(c.item(i))); }
  222. else if (nodeName.equals("StopTimeOut")) { add(StopTimeOut, getLongValue(c.item(i))); }
  223. else if (nodeName.equals("CeaTimeOut")) { add(CeaTimeOut, getLongValue(c.item(i))); }
  224. else if (nodeName.equals("IacTimeOut")) { add(IacTimeOut, getLongValue(c.item(i))); }
  225. else if (nodeName.equals("DwaTimeOut")) { add(DwaTimeOut, getLongValue(c.item(i))); }
  226. else if (nodeName.equals("DpaTimeOut")) { add(DpaTimeOut, getLongValue(c.item(i))); }
  227. else if (nodeName.equals("RecTimeOut")) { add(RecTimeOut, getLongValue(c.item(i))); }
  228. else if (nodeName.equals("ThreadPool")) { addThreadPool(c.item(i)); }
  229. else if (nodeName.equals("Statistics")) { addStatisticLogger(Statistics, c.item(i)); }
  230. else if (nodeName.equals("Concurrent")) { addConcurrent(Concurrent, c.item(i)); }
  231. else if (nodeName.equals("Dictionary")) { addDictionary(Dictionary, c.item(i)); }
  232. else if (nodeName.equals("RequestTable")) { addRequestTable(RequestTable, c.item(i)); }
  233. else {
  234. appendOtherParameter(c.item(i));
  235. }
  236. }
  237. }
  238. protected void addThreadPool(Node item) {
  239. AppConfiguration threadPoolConfiguration = EmptyConfiguration.getInstance();
  240. NamedNodeMap attributes = item.getAttributes();
  241. for (int index = 0; index < attributes.getLength(); index++) {
  242. Node n = attributes.item(index);
  243. int v = Integer.parseInt(n.getNodeValue());
  244. if (n.getNodeName().equals("size")) {
  245. threadPoolConfiguration.add(ThreadPoolSize, v);
  246. }
  247. else if (n.getNodeName().equals("priority")) {
  248. threadPoolConfiguration.add(ThreadPoolPriority, v);
  249. }
  250. else {
  251. //log.error("Unkonwn attribute on " + item.getNodeName() + ", attribute name: " + n.getNodeName());
  252. }
  253. }
  254. if (!threadPoolConfiguration.isAttributeExist(ThreadPoolSize.ordinal())) {
  255. threadPoolConfiguration.add(ThreadPoolSize, ThreadPoolSize.defValue());
  256. }
  257. if (!threadPoolConfiguration.isAttributeExist(ThreadPoolPriority.ordinal())) {
  258. threadPoolConfiguration.add(ThreadPoolPriority, ThreadPoolPriority.defValue());
  259. }
  260. this.add(ThreadPool, threadPoolConfiguration);
  261. }
  262. protected void addConcurrent(org.jdiameter.client.impl.helpers.Parameters name, Node node) {
  263. NodeList c = node.getChildNodes();
  264. List<Configuration> items = new ArrayList<Configuration>();
  265. for (int i = 0; i < c.getLength(); i++) {
  266. String nodeName = c.item(i).getNodeName();
  267. if (nodeName.equals("Entity")) addConcurrentEntity(items, c.item(i));
  268. }
  269. add(name, items.toArray(new Configuration[items.size()]));
  270. }
  271. protected void addConcurrentEntity(List<Configuration> items, Node node) {
  272. AppConfiguration cfg = getInstance();
  273. String name = node.getAttributes().getNamedItem("name").getNodeValue();
  274. cfg.add(ConcurrentEntityName, name);
  275. if (node.getAttributes().getNamedItem("description") != null) {
  276. String descr = node.getAttributes().getNamedItem("description").getNodeValue();
  277. cfg.add(ConcurrentEntityDescription, descr);
  278. }
  279. if (node.getAttributes().getNamedItem("size") != null) {
  280. String size = node.getAttributes().getNamedItem("size").getNodeValue();
  281. cfg.add(ConcurrentEntityPoolSize, Integer.parseInt(size));
  282. }
  283. items.add(cfg);
  284. }
  285. protected void addStatisticLogger(org.jdiameter.client.impl.helpers.Parameters name, Node node) {
  286. String pause = node.getAttributes().getNamedItem("pause").getNodeValue();
  287. String delay = node.getAttributes().getNamedItem("delay").getNodeValue();
  288. String enabled = node.getAttributes().getNamedItem("enabled").getNodeValue();
  289. String active_records;
  290. if (node.getAttributes().getNamedItem("active_records") != null) {
  291. active_records = node.getAttributes().getNamedItem("active_records").getNodeValue();
  292. } else {
  293. active_records = (String) StatisticsActiveList.defValue();
  294. }
  295. add(name,
  296. getInstance().
  297. add(StatisticsLoggerPause, Long.parseLong(pause)).
  298. add(StatisticsLoggerDelay, Long.parseLong(delay)).
  299. add(StatisticsEnabled, Boolean.parseBoolean(enabled)).
  300. add(StatisticsActiveList, active_records));
  301. }
  302. protected void addDictionary(org.jdiameter.client.impl.helpers.Parameters name, Node node) {
  303. AppConfiguration dicConfiguration = getInstance();
  304. Node param = node.getAttributes().getNamedItem("class");
  305. if(param != null) {
  306. String clazz = param.getNodeValue();
  307. dicConfiguration.add(DictionaryClass, clazz);
  308. }
  309. param = node.getAttributes().getNamedItem("enabled");
  310. if(param != null) {
  311. String enabled = param.getNodeValue();
  312. dicConfiguration.add(DictionaryEnabled, Boolean.valueOf(enabled));
  313. }
  314. param = node.getAttributes().getNamedItem("sendLevel");
  315. if(param != null) {
  316. String sendLevel = param.getNodeValue();
  317. dicConfiguration.add(DictionarySendLevel, sendLevel);
  318. }
  319. param = node.getAttributes().getNamedItem("receiveLevel");
  320. if(param != null) {
  321. String receiveLevel = param.getNodeValue();
  322. dicConfiguration.add(DictionaryReceiveLevel, receiveLevel);
  323. }
  324. add(name, dicConfiguration);
  325. }
  326. protected void addRequestTable(org.jdiameter.client.impl.helpers.Parameters name, Node node) {
  327. AppConfiguration tableConfiguration = getInstance();
  328. Node param = node.getAttributes().getNamedItem("size");
  329. if(param != null) {
  330. String size = param.getNodeValue();
  331. tableConfiguration.add(Parameters.RequestTableSize, Integer.parseInt(size));
  332. }
  333. param = node.getAttributes().getNamedItem("clear_size");
  334. if(param != null) {
  335. String size = param.getNodeValue();
  336. tableConfiguration.add(Parameters.RequestTableClearSize, Integer.parseInt(size));
  337. }
  338. add(name, tableConfiguration);
  339. }
  340. protected void addSecurity(Node node) {
  341. NodeList c = node.getChildNodes();
  342. List<Configuration> items = new ArrayList<Configuration>();
  343. for (int i = 0; i < c.getLength(); i++) {
  344. String nodeName = c.item(i).getNodeName();
  345. if (nodeName.equals("SecurityData"))
  346. items.add(addSecurityData(c.item(i)));
  347. }
  348. add(Security, items.toArray(EMPTY_ARRAY));
  349. }
  350. protected Configuration addSecurityData(Node node) {
  351. AppConfiguration sd = getInstance().add(SDName, node.getAttributes().getNamedItem("name").getNodeValue())
  352. .add(SDProtocol, node.getAttributes().getNamedItem("protocol").getNodeValue())
  353. .add(SDEnableSessionCreation, Boolean.valueOf(node.getAttributes().getNamedItem("enable_session_creation").getNodeValue()))
  354. .add(SDUseClientMode, Boolean.valueOf(node.getAttributes().getNamedItem("use_client_mode").getNodeValue()));
  355. NodeList c = node.getChildNodes();
  356. for (int i = 0; i < c.getLength(); i++) {
  357. Node cnode = c.item(i);
  358. String nodeName = cnode.getNodeName();
  359. if (nodeName.equals("CipherSuites")) {
  360. sd.add(CipherSuites, cnode.getTextContent().trim());
  361. }
  362. if (nodeName.equals("KeyData")) {
  363. sd.add(KeyData, getInstance().add(KDManager, cnode.getAttributes().getNamedItem("manager").getNodeValue())
  364. .add(KDStore, cnode.getAttributes().getNamedItem("store").getNodeValue())
  365. .add(KDFile, cnode.getAttributes().getNamedItem("file").getNodeValue())
  366. .add(KDPwd, cnode.getAttributes().getNamedItem("pwd").getNodeValue()));
  367. }
  368. if (nodeName.equals("TrustData")) {
  369. sd.add(TrustData, getInstance().add(TDManager, cnode.getAttributes().getNamedItem("manager").getNodeValue())
  370. .add(TDStore, cnode.getAttributes().getNamedItem("store").getNodeValue())
  371. .add(TDFile, cnode.getAttributes().getNamedItem("file").getNodeValue())
  372. .add(TDPwd, cnode.getAttributes().getNamedItem("pwd").getNodeValue()));
  373. }
  374. }
  375. return sd;
  376. }
  377. protected void addNetwork(Node node) {
  378. NodeList c = node.getChildNodes();
  379. for (int i = 0; i < c.getLength(); i++) {
  380. String nodeName = c.item(i).getNodeName();
  381. if (nodeName.equals("Peers")) addPeers(c.item(i));
  382. else if (nodeName.equals("Realms")) addRealms(c.item(i));
  383. }
  384. }
  385. protected void addPeers(Node node) {
  386. NodeList c = node.getChildNodes();
  387. ArrayList<Configuration> items = new ArrayList<Configuration>();
  388. for (int i = 0; i < c.getLength(); i++) {
  389. String nodeName = c.item(i).getNodeName();
  390. if (nodeName.equals("Peer"))
  391. items.add(addPeer(c.item(i)));
  392. }
  393. add(PeerTable, items.toArray(EMPTY_ARRAY));
  394. }
  395. protected void addRealms(Node node) {
  396. NodeList c = node.getChildNodes();
  397. ArrayList<Configuration> items = new ArrayList<Configuration>();
  398. for (int i = 0; i < c.getLength(); i++) {
  399. String nodeName = c.item(i).getNodeName();
  400. if (nodeName.equals("Realm"))
  401. items.add(addRealm(c.item(i)));
  402. }
  403. add(RealmTable, items.toArray(EMPTY_ARRAY));
  404. }
  405. protected Configuration addPeer(Node node) {
  406. String rating = node.getAttributes().getNamedItem("rating").getNodeValue();
  407. String connecting = node.getAttributes().getNamedItem("attempt_connect").getNodeValue();
  408. String name = node.getAttributes().getNamedItem("name").getNodeValue();
  409. AppConfiguration c = getInstance();
  410. c.add(PeerRating, Integer.parseInt(rating));
  411. c.add(PeerAttemptConnection, Boolean.valueOf(connecting));
  412. c.add(PeerName, name);
  413. if (node.getAttributes().getNamedItem("ip") != null) {
  414. c.add(PeerIp, node.getAttributes().getNamedItem("ip").getNodeValue());
  415. }
  416. if (node.getAttributes().getNamedItem("portRange") != null) {
  417. c.add(PeerLocalPortRange, node.getAttributes().getNamedItem("portRange").getNodeValue());
  418. }
  419. if (node.getAttributes().getNamedItem("security_ref") != null) {
  420. c.add(SecurityRef, node.getAttributes().getNamedItem("security_ref").getNodeValue());
  421. }
  422. return c;
  423. }
  424. protected void addLocalPeer(Node node) {
  425. NodeList c = node.getChildNodes();
  426. if (node.getAttributes().getNamedItem("security_ref") != null) {
  427. add(SecurityRef, node.getAttributes().getNamedItem("security_ref").getNodeValue());
  428. }
  429. for (int i = 0; i < c.getLength(); i++) {
  430. String nodeName = c.item(i).getNodeName();
  431. if (nodeName.equals("URI")) add(OwnDiameterURI, getValue(c.item(i)));
  432. addIPAddress(c.item(i));
  433. if (nodeName.equals("Realm")) add(OwnRealm, getValue(c.item(i)));
  434. if (nodeName.equals("VendorID")) add(OwnVendorID, getLongValue(c.item(i)));
  435. if (nodeName.equals("ProductName")) add(OwnProductName, getValue(c.item(i)));
  436. if (nodeName.equals("FirmwareRevision")) add(OwnFirmwareRevision, getLongValue(c.item(i)));
  437. if (nodeName.equals("Applications")) addApplications(c.item(i));
  438. if (nodeName.equals("OverloadMonitor")) addOverloadMonitor(c.item(i));
  439. }
  440. }
  441. private void addOverloadMonitor(Node node) {
  442. NodeList c = node.getChildNodes();
  443. ArrayList<Configuration> items = new ArrayList<Configuration>();
  444. for (int i = 0; i < c.getLength(); i++) {
  445. String nodeName = c.item(i).getNodeName();
  446. if (nodeName.equals("Entry"))
  447. items.add(addOverloadMonitorItem(c.item(i)));
  448. }
  449. add(OverloadMonitor, items.toArray(EMPTY_ARRAY));
  450. }
  451. private Configuration addOverloadMonitorItem(Node node) {
  452. return getInstance().
  453. add(OverloadEntryIndex, Integer.valueOf(getAttrValue(node, "index"))).
  454. add(OverloadEntrylowThreshold, Double.valueOf(getAttrValue(node, "lowThreshold"))).
  455. add(OverloadEntryhighThreshold, Double.valueOf(getAttrValue(node, "highThreshold"))).
  456. add(ApplicationId, addApplicationID(node.getChildNodes()));
  457. }
  458. protected void addIPAddress(Node node) {
  459. String nodeName = node.getNodeName();
  460. if (nodeName.equals("IPAddresses")) addIPAddresses(node);
  461. }
  462. private void addIPAddresses(Node node) {
  463. NodeList c = node.getChildNodes();
  464. ArrayList<Configuration> items = new ArrayList<Configuration>();
  465. for (int i = 0; i < c.getLength(); i++) {
  466. String nodeName = c.item(i).getNodeName();
  467. if (nodeName.equals("IPAddress")) items.add(addIPAddressItem(c.item(i)));
  468. }
  469. add(OwnIPAddresses, items.toArray(EMPTY_ARRAY));
  470. }
  471. protected Configuration addIPAddressItem(Node node) {
  472. return getInstance().
  473. add(OwnIPAddress, getValue(node));
  474. }
  475. protected Configuration addRealm(Node node) {
  476. AppConfiguration realmEntry = getInstance();
  477. realmEntry.
  478. add(ApplicationId, new Configuration[] {addApplicationID(node.getChildNodes())}).
  479. add(RealmName, getAttrValue(node, "name")).
  480. add(RealmHosts, getAttrValue(node, "peers")).
  481. add(RealmLocalAction, getAttrValue(node, "local_action")).
  482. add(RealmEntryIsDynamic, Boolean.valueOf(getAttrValue(node, "dynamic"))).
  483. add(RealmEntryExpTime, Long.valueOf(getAttrValue(node, "exp_time")));
  484. NodeList childNodes = node.getChildNodes();
  485. for (int i = 0; i < childNodes.getLength(); i++) {
  486. String nodeName = childNodes.item(i).getNodeName();
  487. if (nodeName.equals("Agent")) {
  488. realmEntry.add(Agent, addAgent(childNodes.item(i)));
  489. }
  490. }
  491. return getInstance().add(RealmEntry, realmEntry);
  492. }
  493. protected Configuration addAgent(Node node) {
  494. AppConfiguration agentConf = getInstance();
  495. NodeList agentChildren = node.getChildNodes();
  496. for(int index = 0; index < agentChildren.getLength(); index++) {
  497. Node n = agentChildren.item(index);
  498. if(n.getNodeName().equals("Properties")) {
  499. agentConf.add(Properties, getProperties(n).toArray(EMPTY_ARRAY));
  500. }
  501. }
  502. return agentConf;
  503. }
  504. protected List<Configuration> getProperties(Node node) {
  505. List<Configuration> props = new ArrayList<Configuration>();
  506. NodeList propertiesChildren = node.getChildNodes();
  507. for(int index = 0; index < propertiesChildren.getLength(); index++) {
  508. Node n = propertiesChildren.item(index);
  509. if(n.getNodeName().equals("Property")) {
  510. AppConfiguration property = getInstance();
  511. property.add(PropertyName, n.getAttributes().getNamedItem(PropertyName.name()).getNodeValue());
  512. property.add(PropertyValue, n.getAttributes().getNamedItem(PropertyValue.name()).getNodeValue());
  513. props.add(property);
  514. }
  515. }
  516. return props;
  517. }
  518. protected void appendOtherParameter(Node node) {
  519. String nodeName = node.getNodeName();
  520. if (nodeName.equals("DuplicateProtection")) add(DuplicateProtection, Boolean.valueOf(getValue(node)));
  521. if (nodeName.equals("DuplicateTimer")) add(DuplicateTimer, getLongValue(node));
  522. if (nodeName.equals("DuplicateSize")) add(DuplicateSize, getIntValue(node));
  523. if (nodeName.equals("AcceptUndefinedPeer")) add(AcceptUndefinedPeer, Boolean.valueOf(getValue(node)));
  524. }
  525. protected void addExtensions(Node node) {
  526. NodeList c = node.getChildNodes();
  527. for (int i = 0; i < c.getLength(); i++) {
  528. String nodeName = c.item(i).getNodeName();
  529. if (nodeName.equals("MetaData")) { addInternalExtension(InternalMetaData, getValue(c.item(i))); }
  530. else if (nodeName.equals("MessageParser")) { addInternalExtension(InternalMessageParser, getValue(c.item(i))); }
  531. else if (nodeName.equals("ElementParser")) { addInternalExtension(InternalElementParser, getValue(c.item(i))); }
  532. else if (nodeName.equals("RouterEngine")) { addInternalExtension(InternalRouterEngine, getValue(c.item(i))); }
  533. else if (nodeName.equals("PeerController")) { addInternalExtension(InternalPeerController, getValue(c.item(i))); }
  534. else if (nodeName.equals("RealmController")) { addInternalExtension(InternalRealmController, getValue(c.item(i))); }
  535. else if (nodeName.equals("SessionFactory")) { addInternalExtension(InternalSessionFactory, getValue(c.item(i))); }
  536. else if (nodeName.equals("TransportFactory")) { addInternalExtension(InternalTransportFactory, getValue(c.item(i))); }
  537. else if (nodeName.equals("Connection")) { addInternalExtension(InternalConnectionClass, getValue(c.item(i))); }
  538. else if (nodeName.equals("NetworkGuard")) { addInternalExtension(InternalNetworkGuard, getValue(c.item(i))); }
  539. else if (nodeName.equals("PeerFsmFactory")) { addInternalExtension(InternalPeerFsmFactory, getValue(c.item(i))); }
  540. else if (nodeName.equals("StatisticFactory")) { addInternalExtension(InternalStatisticFactory, getValue(c.item(i))); }
  541. else if (nodeName.equals("ConcurrentFactory")) { addInternalExtension(InternalConcurrentFactory, getValue(c.item(i))); }
  542. else if (nodeName.equals("ConcurrentEntityFactory")) { addInternalExtension(InternalConcurrentEntityFactory, getValue(c.item(i))); }
  543. else if (nodeName.equals("StatisticProcessor")) { addInternalExtension(InternalStatisticProcessor, getValue(c.item(i))); }
  544. else if (nodeName.equals("NetWork")) { addInternalExtension(InternalNetWork, getValue(c.item(i))); }
  545. else if (nodeName.equals("SessionDatasource")) { addInternalExtension(InternalSessionDatasource, getValue(c.item(i))); }
  546. else if (nodeName.equals("TimerFacility")) { addInternalExtension(InternalTimerFacility, getValue(c.item(i))); }
  547. else if (nodeName.equals("AgentRedirect")) { addInternalExtension(InternalAgentRedirect, getValue(c.item(i))); }
  548. else if (nodeName.equals("AgentConfiguration")) { add(ExtensionPoint.InternalAgentConfiguration,getValue(c.item(i))); }
  549. else if (nodeName.equals("AgentProxy")) { addInternalExtension(InternalAgentProxy, getValue(c.item(i))); }
  550. else if (nodeName.equals("OverloadManager")) { addInternalExtension(InternalOverloadManager,getValue(c.item(i))); }
  551. else
  552. appendOtherExtension(c.item(i));
  553. }
  554. }
  555. protected void addInternalExtension(Ordinal ep, String value) {
  556. Configuration[] extensionConfs = this.getChildren(Parameters.Extensions.ordinal());
  557. AppConfiguration internalExtensions = (AppConfiguration) extensionConfs[ExtensionPoint.Internal.id()];
  558. internalExtensions.add(ep,value);
  559. }
  560. private void appendOtherExtension(Node item) {
  561. // Nothing to do here, so far
  562. }
  563. protected Long getLongValue(Node node) {
  564. return new Long(getValue(node));
  565. }
  566. protected Integer getIntValue(Node node) {
  567. return new Integer(getValue(node));
  568. }
  569. protected String getValue(Node node) {
  570. return node.getAttributes().getNamedItem("value").getNodeValue();
  571. }
  572. protected String getAttrValue(Node node, String name) {
  573. return node.getAttributes().getNamedItem(name).getNodeValue();
  574. }
  575. }