/*
 * JBoss, Home of Professional Open Source.
 * Copyright 2011, Red Hat, Inc., and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.jboss.as.controller.registry;

import org.jboss.as.controller.OperationHandler;

/**
 * Information about handling an attribute in a sub-model.
 *
 * @author Brian Stansberry
 */
public final class AttributeAccess {

    /**
     * The {@link AttributeAccess.AccessType}.
     *
     * <ul>
     *   <li>{@code READ_ONLY} defines a read-only attribute, which can be either {@code Storage.CONFIGURATION} or {@code Storage.RUNTIME}.</li>
     *   <li>{@code READ_WRITE} defines a read-write attribute, which can be either {@code Storage.CONFIGURATION} or {@code Storage.RUNTIME}.</li>
     *   <li>{@code METRIC} implies a read-only {@code Storage.RUNTIME} attribute.</li>
     * </ul>
     *
     */
    public static enum AccessType {
        READ_ONLY("read-only"),
        READ_WRITE("read-write"),
        METRIC("metric");

        private final String label;

        private AccessType(final String label) {
            this.label = label;
        }

        @Override
        public String toString() {
            return label;
        }
    }

    /**
     * The {@link AttributeAccess.Storage} indicates whether the attribute is
     * derived from the configuration or is a runtime attribute.
     */
    public static enum Storage {

        CONFIGURATION("configuration"),
        RUNTIME("runtime");

        private final String label;

        private Storage(final String label) {
            this.label = label;
        }

        @Override
        public String toString() {
            return label;
        }

    }

    private final AccessType access;
    private final Storage storage;
    private final OperationHandler readHandler;
    private final OperationHandler writeHandler;

    public AttributeAccess(final AccessType access, final Storage storage, final OperationHandler readHandler, final OperationHandler writeHandler) {
        assert access != null : "access is null";
        assert storage != null : "storage is null";
        this.access = access;
        this.readHandler = readHandler;
        this.writeHandler = writeHandler;
        this.storage = storage;
        if(access == AccessType.READ_WRITE && writeHandler == null) {
            throw new IllegalArgumentException("writeHandler is null");
        }
    }

    /**
     * Get the access type.
     *
     * @return the access type
     */
    public AccessType getAccessType() {
        return access;
    }

    /**
     * Get the storage type.
     *
     * @return the storage type
     */
    public Storage getStorageType() {
        return storage;
    }

    /**
     * Get the read handler.
     *
     * @return the read handler, <code>null</code> if not undefined
     */
    public OperationHandler getReadHandler() {
        return readHandler;
    }

    /**
     * Get the write handler.
     *
     * @return the write handler, <code>null</code> if not undefined.
     */
    public OperationHandler getWriteHandler() {
        return writeHandler;
    }

}

@@ -1264,54 +1264,55 @@
   * 
-The %7B@link AttributeAccess.AccessType%7D
+Indicates how an attributed is accessed
 .%0A     *
 %0A   
@@ -1311,61 +1311,59 @@
    *
+/
 %0A    
- * %3Cul%3E%0A  
+public static enum AccessType %7B%0A
    
-*
    
-%3Cli%3E%7B@code READ_ONLY%7D defines a
+  /** A
  rea
@@ -1460,56 +1460,57 @@
 IME%7D
-.%3C/li%3E
+ */
 %0A     
-*
    
-%3Cli%3E%7B@code READ_WRITE%7D defines a
+READ_ONLY(%22read-only%22),%0A        /** A
  rea
@@ -1608,52 +1608,59 @@
 IME%7D
-.%3C/li%3E
+ */
 %0A     
-*
    
-%3Cli%3E%7B@code METRIC%7D implies a
+READ_WRITE(%22read-write%22),%0A        /** A
  rea
@@ -1703,144 +1703,11 @@
 bute
-.%3C/li%3E%0A     * %3C/ul%3E%0A     *%0A     */%0A    public static enum AccessType %7B%0A        READ_ONLY(%22read-only%22),%0A        READ_WRITE(%22read-write%22),
+ */
 %0A   
@@ -1974,45 +1974,9 @@
   * 
-The %7B@link AttributeAccess.Storage%7D i
+I
 ndic
@@ -1988,19 +1988,18 @@
 whether 
-the
+an
  attribu
@@ -2003,23 +2003,16 @@
 ibute is
-%0A     *
  derived
@@ -2021,16 +2021,27 @@
 rom the 
+persistent 
 configur
@@ -2054,16 +2054,23 @@
 or is a 
+purely 
 runtime 
@@ -2125,48 +2125,368 @@
 e %7B%0A
-%0A        CONFIGURATION(%22configuration%22),
+        /**%0A         * An attribute whose value is stored in the persistent configuration.%0A         * The value may also be stored in runtime services.%0A         */%0A        CONFIGURATION(%22configuration%22),%0A        /**%0A         * An attribute whose value is only stored in runtime services, and%0A         * isn't stored in the persistent configuration.%0A         */
 %0A   

Improve AttributeAccess javadoc