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