PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/jboss-as-7.1.1.Final/ejb3/src/main/java/org/jboss/as/ejb3/subsystem/CacheFactoryResourceDefinition.java

#
Java | 136 lines | 79 code | 16 blank | 41 comment | 4 complexity | d38a501338dc1bb4dfc02a5ca25f4a1d 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.ejb3.subsystem;
  23. import java.util.Locale;
  24. import java.util.ResourceBundle;
  25. import javax.xml.stream.XMLStreamException;
  26. import javax.xml.stream.XMLStreamWriter;
  27. import org.jboss.as.controller.AttributeDefinition;
  28. import org.jboss.as.controller.ListAttributeDefinition;
  29. import org.jboss.as.controller.PathElement;
  30. import org.jboss.as.controller.ReloadRequiredWriteAttributeHandler;
  31. import org.jboss.as.controller.SimpleAttributeDefinition;
  32. import org.jboss.as.controller.SimpleAttributeDefinitionBuilder;
  33. import org.jboss.as.controller.SimpleResourceDefinition;
  34. import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
  35. import org.jboss.as.controller.descriptions.ResourceDescriptionResolver;
  36. import org.jboss.as.controller.operations.validation.StringLengthValidator;
  37. import org.jboss.as.controller.registry.AttributeAccess;
  38. import org.jboss.as.controller.registry.ManagementResourceRegistration;
  39. import org.jboss.as.controller.registry.OperationEntry;
  40. import org.jboss.dmr.ModelNode;
  41. import org.jboss.dmr.ModelType;
  42. /**
  43. * @author Paul Ferraro
  44. */
  45. public class CacheFactoryResourceDefinition extends SimpleResourceDefinition {
  46. public static final ListAttributeDefinition ALIASES = new StringListAttributeDefinition(EJB3SubsystemModel.ALIASES, EJB3SubsystemXMLAttribute.ALIASES.getLocalName(), true);
  47. public static final SimpleAttributeDefinition PASSIVATION_STORE =
  48. new SimpleAttributeDefinitionBuilder(EJB3SubsystemModel.PASSIVATION_STORE, ModelType.STRING, true)
  49. .setXmlName(EJB3SubsystemXMLAttribute.PASSIVATION_STORE_REF.getLocalName())
  50. .setAllowExpression(true)
  51. .setFlags(AttributeAccess.Flag.RESTART_NONE)
  52. .build();
  53. private static final AttributeDefinition[] ATTRIBUTES = new AttributeDefinition[] { ALIASES, PASSIVATION_STORE };
  54. private static final CacheFactoryAdd ADD_HANDLER = new CacheFactoryAdd(ATTRIBUTES);
  55. private static final CacheFactoryRemove REMOVE_HANDLER = new CacheFactoryRemove(ADD_HANDLER);
  56. public static final CacheFactoryResourceDefinition INSTANCE = new CacheFactoryResourceDefinition();
  57. private CacheFactoryResourceDefinition() {
  58. super(PathElement.pathElement(EJB3SubsystemModel.CACHE),
  59. EJB3Extension.getResourceDescriptionResolver(EJB3SubsystemModel.CACHE),
  60. ADD_HANDLER, REMOVE_HANDLER,
  61. OperationEntry.Flag.RESTART_NONE, OperationEntry.Flag.RESTART_RESOURCE_SERVICES);
  62. }
  63. @Override
  64. public void registerAttributes(ManagementResourceRegistration resourceRegistration) {
  65. ReloadRequiredWriteAttributeHandler handler = new ReloadRequiredWriteAttributeHandler(ATTRIBUTES);
  66. for (AttributeDefinition attribute: ATTRIBUTES) {
  67. resourceRegistration.registerReadWriteAttribute(attribute, null, handler);
  68. }
  69. }
  70. private static class StringListAttributeDefinition extends ListAttributeDefinition {
  71. /** {@inheritDoc} */
  72. StringListAttributeDefinition(String name, String xmlName, boolean allowNull) {
  73. super(name, xmlName, allowNull, 0, Integer.MAX_VALUE, new StringLengthValidator(1));
  74. }
  75. /**
  76. * {@inheritDoc}
  77. * @see org.jboss.as.controller.ListAttributeDefinition#addValueTypeDescription(org.jboss.dmr.ModelNode, java.util.ResourceBundle)
  78. */
  79. @Override
  80. protected void addValueTypeDescription(ModelNode node, ResourceBundle bundle) {
  81. this.setValueType(node);
  82. }
  83. /**
  84. * {@inheritDoc}
  85. * @see org.jboss.as.controller.ListAttributeDefinition#addAttributeValueTypeDescription(org.jboss.dmr.ModelNode, org.jboss.as.controller.descriptions.ResourceDescriptionResolver, java.util.Locale, java.util.ResourceBundle)
  86. */
  87. @Override
  88. protected void addAttributeValueTypeDescription(ModelNode node, ResourceDescriptionResolver resolver, Locale locale, ResourceBundle bundle) {
  89. this.setValueType(node);
  90. }
  91. /**
  92. * {@inheritDoc}
  93. * @see org.jboss.as.controller.ListAttributeDefinition#addOperationParameterValueTypeDescription(org.jboss.dmr.ModelNode, java.lang.String, org.jboss.as.controller.descriptions.ResourceDescriptionResolver, java.util.Locale, java.util.ResourceBundle)
  94. */
  95. @Override
  96. protected void addOperationParameterValueTypeDescription(ModelNode node, String operationName, ResourceDescriptionResolver resolver, Locale locale, ResourceBundle bundle) {
  97. this.setValueType(node);
  98. }
  99. private void setValueType(ModelNode node) {
  100. node.get(ModelDescriptionConstants.VALUE_TYPE).set(ModelType.STRING);
  101. }
  102. /**
  103. * {@inheritDoc}
  104. * @see org.jboss.as.controller.AttributeDefinition#marshallAsElement(org.jboss.dmr.ModelNode, javax.xml.stream.XMLStreamWriter)
  105. */
  106. @Override
  107. public void marshallAsElement(ModelNode model, XMLStreamWriter writer) throws XMLStreamException {
  108. if (model.hasDefined(this.getName())) {
  109. StringBuilder builder = new StringBuilder();
  110. for (ModelNode alias: model.get(this.getName()).asList()) {
  111. if (builder.length() > 0) {
  112. builder.append(' ');
  113. }
  114. builder.append(alias.asString());
  115. }
  116. writer.writeAttribute(this.getXmlName(), builder.toString());
  117. }
  118. }
  119. }
  120. }