jdk/src/share/classes/javax/management/Impact.java
changeset 4159 9e3aae7675f1
parent 4158 0b4d21bc8b5c
parent 4156 acaa49a2768a
child 4160 bda0a85afcb7
equal deleted inserted replaced
4158:0b4d21bc8b5c 4159:9e3aae7675f1
     1 /*
       
     2  * Copyright 2007-2008 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 
       
    26 package javax.management;
       
    27 
       
    28 /**
       
    29  * <p>Defines the impact of an MBean operation, in particular whether it
       
    30  * has an effect on the MBean or simply returns information.  This enum
       
    31  * is used in the {@link ManagedOperation @ManagedOperation} annotation.
       
    32  * Its {@link #getCode()} method can be used to get an {@code int} suitable
       
    33  * for use as the {@code impact} parameter in an {@link MBeanOperationInfo}
       
    34  * constructor.</p>
       
    35  */
       
    36 public enum Impact {
       
    37     /**
       
    38      * The operation is read-like: it returns information but does not change
       
    39      * any state.
       
    40      * @see MBeanOperationInfo#INFO
       
    41      */
       
    42     INFO(MBeanOperationInfo.INFO),
       
    43 
       
    44     /**
       
    45      * The operation is write-like: it has an effect but does not return
       
    46      * any information from the MBean.
       
    47      * @see MBeanOperationInfo#ACTION
       
    48      */
       
    49     ACTION(MBeanOperationInfo.ACTION),
       
    50 
       
    51     /**
       
    52      * The operation is both read-like and write-like: it has an effect,
       
    53      * and it also returns information from the MBean.
       
    54      * @see MBeanOperationInfo#ACTION_INFO
       
    55      */
       
    56     ACTION_INFO(MBeanOperationInfo.ACTION_INFO),
       
    57 
       
    58     /**
       
    59      * The impact of the operation is unknown or cannot be expressed
       
    60      * using one of the other values.
       
    61      * @see MBeanOperationInfo#UNKNOWN
       
    62      */
       
    63     UNKNOWN(MBeanOperationInfo.UNKNOWN);
       
    64 
       
    65     private final int code;
       
    66 
       
    67     /**
       
    68      * An instance of this enumeration, with the corresponding {@code int}
       
    69      * code used by the {@link MBeanOperationInfo} constructors.
       
    70      *
       
    71      * @param code the code used by the {@code MBeanOperationInfo} constructors.
       
    72      */
       
    73     Impact(int code) {
       
    74         this.code = code;
       
    75     }
       
    76 
       
    77     /**
       
    78      * The equivalent {@code int} code used by the {@link MBeanOperationInfo}
       
    79      * constructors.
       
    80      * @return the {@code int} code.
       
    81      */
       
    82     public int getCode() {
       
    83         return code;
       
    84     }
       
    85 
       
    86     /**
       
    87      * Return the {@code Impact} value corresponding to the given {@code int}
       
    88      * code.  The {@code code} is the value that would be used in an
       
    89      * {@code MBeanOperationInfo} constructor.
       
    90      *
       
    91      * @param code the {@code int} code.
       
    92      *
       
    93      * @return an {@code Impact} value {@code x} such that
       
    94      * {@code code == x.}{@link #getCode()}, or {@code Impact.UNKNOWN}
       
    95      * if there is no such value.
       
    96      */
       
    97     public static Impact forCode(int code) {
       
    98         switch (code) {
       
    99             case MBeanOperationInfo.ACTION: return ACTION;
       
   100             case MBeanOperationInfo.INFO: return INFO;
       
   101             case MBeanOperationInfo.ACTION_INFO: return ACTION_INFO;
       
   102             default: return UNKNOWN;
       
   103         }
       
   104     }
       
   105 }