PageRenderTime 44ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/modcluster/src/main/java/org/jboss/as/modcluster/ModClusterSubsystemXMLReader_1_0.java

http://github.com/jbossas/jboss-as
Java | 294 lines | 244 code | 21 blank | 29 comment | 28 complexity | 69d19a5923c884277b02cc444d0c9445 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2012, Red Hat, Inc., and individual contributors
  4. * as indicated by the @author tags. See the copyright.txt file in the
  5. * distribution for a 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.jboss.as.modcluster;
  23. import org.jboss.as.controller.PathAddress;
  24. import org.jboss.as.controller.PathElement;
  25. import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
  26. import org.jboss.as.controller.operations.common.Util;
  27. import org.jboss.as.controller.parsing.ParseUtils;
  28. import org.jboss.dmr.ModelNode;
  29. import org.jboss.dmr.Property;
  30. import org.jboss.staxmapper.XMLElementReader;
  31. import org.jboss.staxmapper.XMLExtendedStreamReader;
  32. import javax.xml.stream.XMLStreamException;
  33. import java.util.List;
  34. import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
  35. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
  36. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
  37. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
  38. import static org.jboss.as.controller.parsing.ParseUtils.requireNoNamespaceAttribute;
  39. import static org.jboss.as.controller.parsing.ParseUtils.unexpectedAttribute;
  40. import static org.jboss.as.controller.parsing.ParseUtils.unexpectedElement;
  41. public class ModClusterSubsystemXMLReader_1_0 implements XMLElementReader<List<ModelNode>> {
  42. /**
  43. * {@inheritDoc}
  44. */
  45. @Override
  46. public void readElement(XMLExtendedStreamReader reader, List<ModelNode> list) throws XMLStreamException {
  47. ParseUtils.requireNoAttributes(reader);
  48. PathAddress address = PathAddress.pathAddress(ModClusterExtension.SUBSYSTEM_PATH);
  49. final ModelNode subsystem = new ModelNode();
  50. subsystem.get(OP).set(ADD);
  51. subsystem.get(OP_ADDR).set(address.toModelNode());
  52. list.add(subsystem);
  53. // Reads it
  54. while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
  55. final Element element = Element.forName(reader.getLocalName());
  56. switch (element) {
  57. case MOD_CLUSTER_CONFIG:
  58. parseModClusterConfig(reader, list, address);
  59. break;
  60. default: {
  61. throw unexpectedElement(reader);
  62. }
  63. }
  64. }
  65. }
  66. void parseModClusterConfig(XMLExtendedStreamReader reader, List<ModelNode> list, PathAddress parent) throws XMLStreamException {
  67. PathAddress address = parent.append(ModClusterExtension.CONFIGURATION_PATH);
  68. final ModelNode config = Util.createAddOperation(address);
  69. list.add(config);
  70. // Parse the attributes.
  71. parsePropConf(reader, config);
  72. // Parse the elements
  73. while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
  74. final Element element = Element.forName(reader.getLocalName());
  75. switch (element) {
  76. case SIMPLE_LOAD_PROVIDER:
  77. parseSimpleLoadProvider(reader, config);
  78. break;
  79. case DYNAMIC_LOAD_PROVIDER:
  80. parseDynamicLoadProvider(reader, list, address);
  81. break;
  82. case SSL:
  83. parseSSL(reader, list, address);
  84. break;
  85. default:
  86. throw unexpectedElement(reader);
  87. }
  88. }
  89. }
  90. void parsePropConf(XMLExtendedStreamReader reader, ModelNode conf) throws XMLStreamException {
  91. final int count = reader.getAttributeCount();
  92. for (int i = 0; i < count; i++) {
  93. requireNoNamespaceAttribute(reader, i);
  94. final String value = reader.getAttributeValue(i);
  95. final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
  96. switch (attribute) {
  97. case ADVERTISE_SOCKET:
  98. case PROXY_LIST:
  99. case PROXY_URL:
  100. case ADVERTISE:
  101. case ADVERTISE_SECURITY_KEY:
  102. case EXCLUDED_CONTEXTS:
  103. case AUTO_ENABLE_CONTEXTS:
  104. case STOP_CONTEXT_TIMEOUT:
  105. case SOCKET_TIMEOUT:
  106. case STICKY_SESSION:
  107. case STICKY_SESSION_REMOVE:
  108. case STICKY_SESSION_FORCE:
  109. case WORKER_TIMEOUT:
  110. case MAX_ATTEMPTS:
  111. case FLUSH_PACKETS:
  112. case FLUSH_WAIT:
  113. case PING:
  114. case SMAX:
  115. case TTL:
  116. case NODE_TIMEOUT:
  117. case BALANCER:
  118. ModClusterConfigResourceDefinition.ATTRIBUTES_BY_NAME.get(attribute.getLocalName()).parseAndSetParameter(value, conf, reader);
  119. break;
  120. case DOMAIN:
  121. ModClusterConfigResourceDefinition.LOAD_BALANCING_GROUP.parseAndSetParameter(value, conf, reader);
  122. break;
  123. default:
  124. throw unexpectedAttribute(reader, i);
  125. }
  126. }
  127. // This is a required attribute - so set it to something reasonable
  128. ModClusterConfigResourceDefinition.CONNECTOR.parseAndSetParameter("ajp", conf, reader);
  129. }
  130. void parseSSL(XMLExtendedStreamReader reader, List<ModelNode> list, PathAddress parent) throws XMLStreamException {
  131. PathAddress address = parent.append(ModClusterExtension.SSL_CONFIGURATION_PATH);
  132. final ModelNode ssl = Util.createAddOperation(address);
  133. list.add(ssl);
  134. final int count = reader.getAttributeCount();
  135. for (int i = 0; i < count; i++) {
  136. requireNoNamespaceAttribute(reader, i);
  137. final String value = reader.getAttributeValue(i);
  138. final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
  139. switch (attribute) {
  140. case KEY_ALIAS:
  141. case PASSWORD:
  142. case CERTIFICATE_KEY_FILE:
  143. case CIPHER_SUITE:
  144. case PROTOCOL:
  145. case CA_CERTIFICATE_FILE:
  146. case CA_REVOCATION_URL:
  147. ModClusterSSLResourceDefinition.ATTRIBUTES_BY_NAME.get(attribute.getLocalName()).parseAndSetParameter(value, ssl, reader);
  148. break;
  149. default:
  150. throw unexpectedAttribute(reader, i);
  151. }
  152. }
  153. ParseUtils.requireNoContent(reader);
  154. }
  155. void parseSimpleLoadProvider(XMLExtendedStreamReader reader, ModelNode operation) throws XMLStreamException {
  156. final int count = reader.getAttributeCount();
  157. for (int i = 0; i < count; i++) {
  158. requireNoNamespaceAttribute(reader, i);
  159. final String value = reader.getAttributeValue(i);
  160. final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
  161. switch (attribute) {
  162. case FACTOR:
  163. ModClusterConfigResourceDefinition.SIMPLE_LOAD_PROVIDER.parseAndSetParameter(value, operation, reader);
  164. break;
  165. default:
  166. throw unexpectedAttribute(reader, i);
  167. }
  168. }
  169. ParseUtils.requireNoContent(reader);
  170. }
  171. void parseDynamicLoadProvider(XMLExtendedStreamReader reader, List<ModelNode> list, PathAddress parent) throws XMLStreamException {
  172. PathAddress address = parent.append(ModClusterExtension.DYNAMIC_LOAD_PROVIDER);
  173. final ModelNode load = Util.createAddOperation(address);
  174. final int count = reader.getAttributeCount();
  175. for (int i = 0; i < count; i++) {
  176. requireNoNamespaceAttribute(reader, i);
  177. final String value = reader.getAttributeValue(i);
  178. final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
  179. switch (attribute) {
  180. case HISTORY:
  181. DynamicLoadProviderDefinition.HISTORY.parseAndSetParameter(value, load, reader);
  182. break;
  183. case DECAY:
  184. DynamicLoadProviderDefinition.DECAY.parseAndSetParameter(value, load, reader);
  185. break;
  186. default:
  187. throw unexpectedAttribute(reader, i);
  188. }
  189. }
  190. list.add(load);
  191. while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
  192. // read the load-metric and the custom-load-metric
  193. final Element element = Element.forName(reader.getLocalName());
  194. switch (element) {
  195. case LOAD_METRIC:
  196. parseLoadMetric(reader, list, address);
  197. break;
  198. case CUSTOM_LOAD_METRIC:
  199. parseCustomLoadMetric(reader, list, address);
  200. break;
  201. default:
  202. throw unexpectedElement(reader);
  203. }
  204. }
  205. }
  206. void parseLoadMetric(XMLExtendedStreamReader reader, List<ModelNode> list, PathAddress address) throws XMLStreamException {
  207. final ModelNode metric = new ModelNode();
  208. final int count = reader.getAttributeCount();
  209. for (int i = 0; i < count; i++) {
  210. requireNoNamespaceAttribute(reader, i);
  211. final String value = reader.getAttributeValue(i);
  212. final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
  213. switch (attribute) {
  214. case TYPE:
  215. LoadMetricDefinition.TYPE.parseAndSetParameter(value, metric, reader);
  216. break;
  217. case CAPACITY:
  218. LoadMetricDefinition.CAPACITY.parseAndSetParameter(value, metric, reader);
  219. break;
  220. case WEIGHT:
  221. LoadMetricDefinition.WEIGHT.parseAndSetParameter(value, metric, reader);
  222. break;
  223. default:
  224. throw unexpectedAttribute(reader, i);
  225. }
  226. }
  227. PathElement pe = PathElement.pathElement(ModClusterExtension.LOAD_METRIC.getKey(), metric.get(CommonAttributes.TYPE).asString());
  228. metric.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
  229. metric.get(ModelDescriptionConstants.OP_ADDR).set(address.append(pe).toModelNode());
  230. readProperties(reader, metric);
  231. list.add(metric);
  232. }
  233. static void readProperties(XMLExtendedStreamReader reader, ModelNode metric) throws XMLStreamException {
  234. while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
  235. final Element element = Element.forName(reader.getLocalName());
  236. switch (element) {
  237. case PROPERTY:
  238. final Property property = ParseUtils.readProperty(reader);
  239. metric.get(CommonAttributes.PROPERTY).get(property.getName()).set(property.getValue());
  240. break;
  241. default:
  242. throw unexpectedElement(reader);
  243. }
  244. }
  245. }
  246. void parseCustomLoadMetric(XMLExtendedStreamReader reader, List<ModelNode> list, PathAddress address) throws XMLStreamException {
  247. final ModelNode customMetric = new ModelNode();
  248. final int count = reader.getAttributeCount();
  249. for (int i = 0; i < count; i++) {
  250. requireNoNamespaceAttribute(reader, i);
  251. final String value = reader.getAttributeValue(i);
  252. final Attribute attribute = Attribute.forName(reader.getAttributeLocalName(i));
  253. switch (attribute) {
  254. case CAPACITY:
  255. LoadMetricDefinition.CAPACITY.parseAndSetParameter(value, customMetric, reader);
  256. break;
  257. case WEIGHT:
  258. LoadMetricDefinition.WEIGHT.parseAndSetParameter(value, customMetric, reader);
  259. break;
  260. case CLASS:
  261. CustomLoadMetricDefinition.CLASS.parseAndSetParameter(value, customMetric, reader);
  262. break;
  263. default:
  264. throw unexpectedAttribute(reader, i);
  265. }
  266. }
  267. PathElement pe = PathElement.pathElement(ModClusterExtension.CUSTOM_LOAD_METRIC.getKey(), customMetric.get(CommonAttributes.CLASS).asString());
  268. customMetric.get(ModelDescriptionConstants.OP).set(ModelDescriptionConstants.ADD);
  269. customMetric.get(ModelDescriptionConstants.OP_ADDR).set(address.append(pe).toModelNode());
  270. readProperties(reader, customMetric);
  271. list.add(customMetric);
  272. }
  273. }