PageRenderTime 59ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/clustering/jgroups/src/main/java/org/jboss/as/clustering/jgroups/subsystem/JGroupsDescriptions.java

#
Java | 245 lines | 172 code | 34 blank | 39 comment | 9 complexity | 70d76e735b022f02be3c738b7c636dff MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. /*
  2. * JBoss, Home of Professional Open Source.
  3. * Copyright 2011, 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.clustering.jgroups.subsystem;
  23. import static org.jboss.as.clustering.jgroups.subsystem.CommonAttributes.DEFAULT_STACK;
  24. import static org.jboss.as.clustering.jgroups.subsystem.CommonAttributes.VALUE;
  25. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.*;
  26. import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.VALUE_TYPE;
  27. import java.util.Locale;
  28. import java.util.ResourceBundle;
  29. import org.jboss.as.controller.AttributeDefinition;
  30. import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
  31. import org.jboss.dmr.ModelNode;
  32. import org.jboss.dmr.ModelType;
  33. /**
  34. * Access the resource bundle used to fetch local descriptions.
  35. * @author Paul Ferraro
  36. */
  37. public class JGroupsDescriptions {
  38. public static final String RESOURCE_NAME = JGroupsDescriptions.class.getPackage().getName() + ".LocalDescriptions";
  39. private JGroupsDescriptions() {
  40. // Hide
  41. }
  42. static ModelNode getSubsystemDescription(Locale locale) {
  43. ResourceBundle resources = getResources(locale);
  44. ModelNode subsystem = createDescription(resources, "jgroups");
  45. subsystem.get(ModelDescriptionConstants.HEAD_COMMENT_ALLOWED).set(true);
  46. subsystem.get(ModelDescriptionConstants.TAIL_COMMENT_ALLOWED).set(true);
  47. subsystem.get(ModelDescriptionConstants.NAMESPACE).set(Namespace.CURRENT.getUri());
  48. DEFAULT_STACK.addResourceAttributeDescription(resources, "jgroups", subsystem);
  49. // children of the root subsystem
  50. subsystem.get(CHILDREN, ModelKeys.STACK, DESCRIPTION).set(resources.getString("jgroups.stack"));
  51. subsystem.get(CHILDREN, ModelKeys.STACK, MIN_OCCURS).set(1);
  52. subsystem.get(CHILDREN, ModelKeys.STACK, MAX_OCCURS).set(Integer.MAX_VALUE);
  53. subsystem.get(CHILDREN, ModelKeys.STACK, MODEL_DESCRIPTION).setEmptyObject();
  54. return subsystem;
  55. }
  56. static ModelNode getSubsystemAddDescription(Locale locale) {
  57. ResourceBundle resources = getResources(locale);
  58. final ModelNode op = createOperationDescription(ADD, resources, "jgroups.add");
  59. DEFAULT_STACK.addOperationParameterDescription(resources, "jgroups", op);
  60. return op;
  61. }
  62. static ModelNode getSubsystemRemoveDescription(Locale locale) {
  63. ResourceBundle resources = getResources(locale);
  64. final ModelNode op = createOperationDescription(REMOVE, resources, "jgroups.remove");
  65. op.get(REPLY_PROPERTIES).setEmptyObject();
  66. op.get(REQUEST_PROPERTIES).setEmptyObject();
  67. return op;
  68. }
  69. static ModelNode getSubsystemDescribeDescription(Locale locale) {
  70. ResourceBundle resources = getResources(locale);
  71. final ModelNode op = createOperationDescription(DESCRIBE, resources, "jgroups.describe");
  72. op.get(REQUEST_PROPERTIES).setEmptyObject();
  73. op.get(REPLY_PROPERTIES, TYPE).set(ModelType.LIST);
  74. op.get(REPLY_PROPERTIES, VALUE_TYPE).set(ModelType.OBJECT);
  75. return op;
  76. }
  77. static ModelNode getProtocolStackDescription(Locale locale) {
  78. ResourceBundle resources = getResources(locale);
  79. final ModelNode stack = createDescription(resources, "jgroups.stack");
  80. // information about its child "transport=TRANSPORT"
  81. stack.get(CHILDREN, ModelKeys.TRANSPORT, DESCRIPTION).set(resources.getString("jgroups.stack.transport"));
  82. stack.get(CHILDREN, ModelKeys.TRANSPORT, MIN_OCCURS).set(0);
  83. stack.get(CHILDREN, ModelKeys.TRANSPORT, MAX_OCCURS).set(1);
  84. stack.get(CHILDREN, ModelKeys.TRANSPORT, ALLOWED).setEmptyList().add(ModelKeys.TRANSPORT_NAME);
  85. stack.get(CHILDREN, ModelKeys.TRANSPORT, MODEL_DESCRIPTION);
  86. // information about its child "protocol=*"
  87. stack.get(CHILDREN, ModelKeys.PROTOCOL, DESCRIPTION).set(resources.getString("jgroups.stack.protocol"));
  88. stack.get(CHILDREN, ModelKeys.PROTOCOL, MIN_OCCURS).set(0);
  89. stack.get(CHILDREN, ModelKeys.PROTOCOL, MAX_OCCURS).set(Integer.MAX_VALUE);
  90. stack.get(CHILDREN, ModelKeys.PROTOCOL, MODEL_DESCRIPTION);
  91. return stack ;
  92. }
  93. static ModelNode getProtocolStackAddDescription(Locale locale) {
  94. ResourceBundle resources = getResources(locale);
  95. final ModelNode op = createOperationDescription(ADD, resources, "jgroups.stack.add");
  96. // optional TRANSPORT and PROTOCOLS parameters (to permit configuring a stack from add())
  97. CommonAttributes.TRANSPORT.addOperationParameterDescription(resources, "jgroups.stack" , op);
  98. CommonAttributes.PROTOCOLS.addOperationParameterDescription(resources, "jgroups.stack" , op);
  99. return op;
  100. }
  101. static ModelNode getProtocolStackRemoveDescription(Locale locale) {
  102. ResourceBundle resources = getResources(locale);
  103. final ModelNode op = createOperationDescription(REMOVE, resources, "jgroups.stack.remove");
  104. op.get(REQUEST_PROPERTIES).setEmptyObject();
  105. return op;
  106. }
  107. // stack transport element
  108. static ModelNode getTransportDescription(Locale locale) {
  109. ResourceBundle resources = getResources(locale);
  110. final ModelNode transport = createDescription(resources, "jgroups.stack.transport");
  111. // attributes for adding a transport
  112. for (AttributeDefinition attr : CommonAttributes.TRANSPORT_ATTRIBUTES) {
  113. // don't add PROPERTIES to the resource - just its add operation
  114. if (attr.getName().equals(CommonAttributes.PROPERTIES.getName()))
  115. continue ;
  116. attr.addResourceAttributeDescription(resources, "jgroups.stack.transport", transport);
  117. }
  118. // information about its child "property=*"
  119. transport.get(CHILDREN, ModelKeys.PROPERTY, DESCRIPTION).set(resources.getString("jgroups.stack.transport.property"));
  120. transport.get(CHILDREN, ModelKeys.PROPERTY, MIN_OCCURS).set(0);
  121. transport.get(CHILDREN, ModelKeys.PROPERTY, MAX_OCCURS).set(Integer.MAX_VALUE);
  122. transport.get(CHILDREN, ModelKeys.PROPERTY, MODEL_DESCRIPTION);
  123. return transport ;
  124. }
  125. static ModelNode getTransportAddDescription(Locale locale) {
  126. ResourceBundle resources = getResources(locale);
  127. final ModelNode op = createOperationDescription(ADD, resources, "jgroups.stack.transport.add");
  128. for (AttributeDefinition attr : CommonAttributes.TRANSPORT_ATTRIBUTES) {
  129. attr.addOperationParameterDescription(resources, "jgroups.stack.transport", op);
  130. }
  131. return op;
  132. }
  133. static ModelNode getTransportRemoveDescription(Locale locale) {
  134. ResourceBundle resources = getResources(locale);
  135. final ModelNode op = createOperationDescription(REMOVE, resources, "jgroups.stack.transport.remove");
  136. op.get(REQUEST_PROPERTIES).setEmptyObject();
  137. return op;
  138. }
  139. // stack protocol element
  140. static ModelNode getProtocolDescription(Locale locale) {
  141. ResourceBundle resources = getResources(locale);
  142. final ModelNode protocol = createDescription(resources, "jgroups.stack.protocol");
  143. // attributes for adding a protocol
  144. for (AttributeDefinition attr : CommonAttributes.PROTOCOL_ATTRIBUTES) {
  145. // don't add PROPERTIES to the resource - just its add operation
  146. if (attr.getName().equals(CommonAttributes.PROPERTIES.getName()))
  147. continue ;
  148. attr.addResourceAttributeDescription(resources, "jgroups.stack.protocol", protocol);
  149. }
  150. // information about its child "property=*"
  151. protocol.get(CHILDREN, ModelKeys.PROPERTY, DESCRIPTION).set(resources.getString("jgroups.stack.protocol.property"));
  152. protocol.get(CHILDREN, ModelKeys.PROPERTY, MIN_OCCURS).set(0);
  153. protocol.get(CHILDREN, ModelKeys.PROPERTY, MAX_OCCURS).set(Integer.MAX_VALUE);
  154. protocol.get(CHILDREN, ModelKeys.PROPERTY, MODEL_DESCRIPTION);
  155. return protocol ;
  156. }
  157. static ModelNode getProtocolAddDescription(Locale locale) {
  158. ResourceBundle resources = getResources(locale);
  159. final ModelNode op = createOperationDescription(ModelKeys.ADD_PROTOCOL, resources, "jgroups.stack.protocol.add-protocol");
  160. for (AttributeDefinition attr : CommonAttributes.PROTOCOL_ATTRIBUTES) {
  161. attr.addOperationParameterDescription(resources, "jgroups.stack.protocol", op);
  162. }
  163. return op;
  164. }
  165. static ModelNode getProtocolRemoveDescription(Locale locale) {
  166. ResourceBundle resources = getResources(locale);
  167. final ModelNode op = createOperationDescription(ModelKeys.REMOVE_PROTOCOL, resources, "jgroups.stack.protocol.remove-protocol");
  168. CommonAttributes.TYPE.addOperationParameterDescription(resources, "jgroups.stack.protocol", op);
  169. return op;
  170. }
  171. // protocol property element
  172. static ModelNode getProtocolPropertyDescription(Locale locale) {
  173. ResourceBundle resources = getResources(locale);
  174. final ModelNode protocolProperty = createDescription(resources, "jgroups.stack.protocol.property");
  175. VALUE.addResourceAttributeDescription(resources, "jgroups.stack.protocol.property", protocolProperty);
  176. return protocolProperty ;
  177. }
  178. static ModelNode getProtocolPropertyAddDescription(Locale locale) {
  179. ResourceBundle resources = getResources(locale);
  180. final ModelNode op = createOperationDescription(ADD, resources, "jgroups.stack.protocol.property.add");
  181. VALUE.addOperationParameterDescription(resources, "jgroups.stack.protocol.property", op);
  182. return op;
  183. }
  184. static ModelNode getProtocolPropertyRemoveDescription(Locale locale) {
  185. ResourceBundle resources = getResources(locale);
  186. final ModelNode op = createOperationDescription(REMOVE, resources, "jgroups.stack.protocol.property.remove");
  187. op.get(REQUEST_PROPERTIES).setEmptyObject();
  188. return op;
  189. }
  190. static ModelNode getExportNativeConfigurationDescription(Locale locale) {
  191. ResourceBundle resources = getResources(locale);
  192. final ModelNode op = createOperationDescription(ModelKeys.EXPORT_NATIVE_CONFIGURATION, resources, "jgroups.stack.export-native-configuration");
  193. op.get(REQUEST_PROPERTIES).setEmptyObject();
  194. op.get(REPLY_PROPERTIES, TYPE).set(ModelType.STRING);
  195. return op;
  196. }
  197. private static ResourceBundle getResources(Locale locale) {
  198. return ResourceBundle.getBundle(RESOURCE_NAME, (locale == null) ? Locale.getDefault() : locale);
  199. }
  200. private static ModelNode createDescription(ResourceBundle resources, String key) {
  201. return createOperationDescription(null, resources, key);
  202. }
  203. private static ModelNode createOperationDescription(String operation, ResourceBundle resources, String key) {
  204. ModelNode description = new ModelNode();
  205. if (operation != null) {
  206. description.get(ModelDescriptionConstants.OPERATION_NAME).set(operation);
  207. }
  208. description.get(ModelDescriptionConstants.DESCRIPTION).set(resources.getString(key));
  209. return description;
  210. }
  211. }