src/java.management/share/classes/javax/management/relation/RoleInfo.java
author dholmes
Mon, 18 Nov 2019 23:41:06 -0500
changeset 59132 189f47d990b5
parent 47216 71c04702a3d5
permissions -rw-r--r--
8215355: Object monitor deadlock with no threads holding the monitor (using jemalloc 5.1) Reviewed-by: rehn, stuefe, dcubed, sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.management.relation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.jmx.mbeanserver.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.ObjectStreamField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.management.NotCompliantMBeanException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * A RoleInfo object summarises a role in a relation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
    45
 * <p>The <b>serialVersionUID</b> of this class is {@code 2504952983494636987L}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
@SuppressWarnings("serial")  // serialVersionUID not constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
public class RoleInfo implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    // Serialization compatibility stuff:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    // Two serial forms are supported in this class. The selected form depends
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    // on system property "jmx.serial.form":
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    //  - "1.0" for JMX 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    //  - any other value for JMX 1.1 and higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // Serial version for old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private static final long oldSerialVersionUID = 7227256952085334351L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    // Serial version for new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private static final long newSerialVersionUID = 2504952983494636987L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // Serializable fields in old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private static final ObjectStreamField[] oldSerialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
      new ObjectStreamField("myName", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
      new ObjectStreamField("myIsReadableFlg", boolean.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
      new ObjectStreamField("myIsWritableFlg", boolean.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
      new ObjectStreamField("myDescription", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
      new ObjectStreamField("myMinDegree", int.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
      new ObjectStreamField("myMaxDegree", int.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
      new ObjectStreamField("myRefMBeanClassName", String.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // Serializable fields in new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static final ObjectStreamField[] newSerialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
      new ObjectStreamField("name", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
      new ObjectStreamField("isReadable", boolean.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
      new ObjectStreamField("isWritable", boolean.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
      new ObjectStreamField("description", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
      new ObjectStreamField("minDegree", int.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
      new ObjectStreamField("maxDegree", int.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
      new ObjectStreamField("referencedMBeanClassName", String.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    // Actual serial version and serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static final long serialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @serialField name String Role name
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
    92
     * @serialField isReadable boolean Read access mode: {@code true} if role is readable
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
    93
     * @serialField isWritable boolean Write access mode: {@code true} if role is writable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @serialField description String Role description
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @serialField minDegree int Minimum degree (i.e. minimum number of referenced MBeans in corresponding role)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @serialField maxDegree int Maximum degree (i.e. maximum number of referenced MBeans in corresponding role)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @serialField referencedMBeanClassName String Name of class of MBean(s) expected to be referenced in corresponding role
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private static final ObjectStreamField[] serialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private static boolean compat = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            String form = AccessController.doPrivileged(act);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            compat = (form != null && form.equals("1.0"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            // OK : Too bad, no compat with 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if (compat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            serialPersistentFields = oldSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            serialVersionUID = oldSerialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            serialPersistentFields = newSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            serialVersionUID = newSerialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    // END Serialization compatibility stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    // Public constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * To specify an unlimited cardinality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public static final int ROLE_CARDINALITY_INFINITY = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    // Private members
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @serial Role name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    private String name = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   139
     * @serial Read access mode: {@code true} if role is readable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private boolean isReadable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   144
     * @serial Write access mode: {@code true} if role is writable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    private boolean isWritable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @serial Role description
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private String description = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @serial Minimum degree (i.e. minimum number of referenced MBeans in corresponding role)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    private int minDegree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @serial Maximum degree (i.e. maximum number of referenced MBeans in corresponding role)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    private int maxDegree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @serial Name of class of MBean(s) expected to be referenced in corresponding role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    private String referencedMBeanClassName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    // Constructors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param roleName  name of the role.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param mbeanClassName  name of the class of MBean(s) expected to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * be referenced in corresponding role.  If an MBean <em>M</em> is in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * this role, then the MBean server must return true for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * {@link MBeanServer#isInstanceOf isInstanceOf(M, mbeanClassName)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param read  flag to indicate if the corresponding role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * can be read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @param write  flag to indicate if the corresponding role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * can be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @param min  minimum degree for role, i.e. minimum number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * MBeans to provide in corresponding role
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   186
     * Must be less than or equal to {@code max}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * (ROLE_CARDINALITY_INFINITY for unlimited)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @param max  maximum degree for role, i.e. maximum number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * MBeans to provide in corresponding role
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   190
     * Must be greater than or equal to {@code min}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * (ROLE_CARDINALITY_INFINITY for unlimited)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param descr  description of the role (can be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @exception InvalidRoleInfoException  if the minimum degree is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * greater than the maximum degree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @exception ClassNotFoundException As of JMX 1.2, this exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * can no longer be thrown.  It is retained in the declaration of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * this class for compatibility with existing code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @exception NotCompliantMBeanException  if the class mbeanClassName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * is not a MBean class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public RoleInfo(String roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    String mbeanClassName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    boolean read,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    boolean write,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    int min,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    int max,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                    String descr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
           InvalidRoleInfoException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
           ClassNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
           NotCompliantMBeanException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        init(roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
             mbeanClassName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
             read,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
             write,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
             min,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
             max,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
             descr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @param roleName  name of the role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @param mbeanClassName  name of the class of MBean(s) expected to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * be referenced in corresponding role.  If an MBean <em>M</em> is in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * this role, then the MBean server must return true for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * {@link MBeanServer#isInstanceOf isInstanceOf(M, mbeanClassName)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param read  flag to indicate if the corresponding role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * can be read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @param write  flag to indicate if the corresponding role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * can be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * <P>Minimum and maximum degrees defaulted to 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * <P>Description of role defaulted to null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @exception ClassNotFoundException As of JMX 1.2, this exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * can no longer be thrown.  It is retained in the declaration of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * this class for compatibility with existing code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @exception NotCompliantMBeanException As of JMX 1.2, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * exception can no longer be thrown.  It is retained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * declaration of this class for compatibility with existing code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public RoleInfo(String roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    String mbeanClassName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    boolean read,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    boolean write)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
           ClassNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
           NotCompliantMBeanException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            init(roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                 mbeanClassName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                 read,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                 write,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                 null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        } catch (InvalidRoleInfoException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            // OK : Can never happen as the minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            //      degree equals the maximum degree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @param roleName  name of the role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @param mbeanClassName  name of the class of MBean(s) expected to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * be referenced in corresponding role.  If an MBean <em>M</em> is in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * this role, then the MBean server must return true for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * {@link MBeanServer#isInstanceOf isInstanceOf(M, mbeanClassName)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * <P>IsReadable and IsWritable defaulted to true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * <P>Minimum and maximum degrees defaulted to 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * <P>Description of role defaulted to null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @exception ClassNotFoundException As of JMX 1.2, this exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * can no longer be thrown.  It is retained in the declaration of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * this class for compatibility with existing code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @exception NotCompliantMBeanException As of JMX 1.2, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * exception can no longer be thrown.  It is retained in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * declaration of this class for compatibility with existing code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public RoleInfo(String roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                    String mbeanClassName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
           ClassNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
           NotCompliantMBeanException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            init(roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                 mbeanClassName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                 true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                 true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                 null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        } catch (InvalidRoleInfoException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            // OK : Can never happen as the minimum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            //      degree equals the maximum degree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Copy constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   319
     * @param roleInfo the {@code RoleInfo} instance to be copied.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    public RoleInfo(RoleInfo roleInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        if (roleInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            // Revisit [cebro] Localize message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            init(roleInfo.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                 roleInfo.getRefMBeanClassName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                 roleInfo.isReadable(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                 roleInfo.isWritable(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                 roleInfo.getMinDegree(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                 roleInfo.getMaxDegree(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                 roleInfo.getDescription());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        } catch (InvalidRoleInfoException exc3) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            // OK : Can never happen as the minimum degree and the maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            //      degree were already checked at the time the roleInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            //      instance was created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    // Accessors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * Returns the name of the role.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @return the name of the role.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * Returns read access mode for the role (true if it is readable).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @return true if the role is readable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    public boolean isReadable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        return isReadable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * Returns write access mode for the role (true if it is writable).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @return true if the role is writable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public boolean isWritable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        return isWritable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * Returns description text for the role.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @return the description of the role.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    public String getDescription() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        return description;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * Returns minimum degree for corresponding role reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @return the minimum degree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public int getMinDegree() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return minDegree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * Returns maximum degree for corresponding role reference.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @return the maximum degree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    public int getMaxDegree() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        return maxDegree;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * <p>Returns name of type of MBean expected to be referenced in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * corresponding role.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @return the name of the referenced type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    public String getRefMBeanClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        return referencedMBeanClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   416
     * Returns true if the {@code value} parameter is greater than or equal to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * the expected minimum degree, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @param value  the value to be checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @return true if greater than or equal to minimum degree, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public boolean checkMinDegree(int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        if (value >= ROLE_CARDINALITY_INFINITY &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            (minDegree == ROLE_CARDINALITY_INFINITY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
             || value >= minDegree)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /**
32034
05676cfd40b5 8133040: docs: replace <tt> tags (obsolete in html5) for java.management
avstepan
parents: 25859
diff changeset
   434
     * Returns true if the {@code value} parameter is lower than or equal to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * the expected maximum degree, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @param value  the value to be checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @return true if lower than or equal to maximum degree, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    public boolean checkMaxDegree(int value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        if (value >= ROLE_CARDINALITY_INFINITY &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            (maxDegree == ROLE_CARDINALITY_INFINITY ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
             (value != ROLE_CARDINALITY_INFINITY &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
              value <= maxDegree))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * Returns a string describing the role info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * @return a description of the role info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        StringBuilder result = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        result.append("role info name: " + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        result.append("; isReadable: " + isReadable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        result.append("; isWritable: " + isWritable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        result.append("; description: " + description);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        result.append("; minimum degree: " + minDegree);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        result.append("; maximum degree: " + maxDegree);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        result.append("; MBean class: " + referencedMBeanClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        return result.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    // Misc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    // Initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    private void init(String roleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                      String mbeanClassName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                      boolean read,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                      boolean write,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                      int min,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                      int max,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                      String descr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            throws IllegalArgumentException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                   InvalidRoleInfoException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        if (roleName == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            mbeanClassName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            // Revisit [cebro] Localize message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        name = roleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        isReadable = read;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        isWritable = write;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        if (descr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            description = descr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        boolean invalidRoleInfoFlg = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        StringBuilder excMsgStrB = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        if (max != ROLE_CARDINALITY_INFINITY &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            (min == ROLE_CARDINALITY_INFINITY ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
             min > max)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            // Revisit [cebro] Localize message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            excMsgStrB.append("Minimum degree ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            excMsgStrB.append(min);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            excMsgStrB.append(" is greater than maximum degree ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            excMsgStrB.append(max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            invalidRoleInfoFlg = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        } else if (min < ROLE_CARDINALITY_INFINITY ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                   max < ROLE_CARDINALITY_INFINITY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            // Revisit [cebro] Localize message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            excMsgStrB.append("Minimum or maximum degree has an illegal value, must be [0, ROLE_CARDINALITY_INFINITY].");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            invalidRoleInfoFlg = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        if (invalidRoleInfoFlg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            throw new InvalidRoleInfoException(excMsgStrB.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        minDegree = min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        maxDegree = max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        referencedMBeanClassName = mbeanClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * Deserializes a {@link RoleInfo} from an {@link ObjectInputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    private void readObject(ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
      if (compat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        // Read an object serialized in the old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        ObjectInputStream.GetField fields = in.readFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        name = (String) fields.get("myName", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        if (fields.defaulted("myName"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
          throw new NullPointerException("myName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        isReadable = fields.get("myIsReadableFlg", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (fields.defaulted("myIsReadableFlg"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
          throw new NullPointerException("myIsReadableFlg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        isWritable = fields.get("myIsWritableFlg", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        if (fields.defaulted("myIsWritableFlg"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
          throw new NullPointerException("myIsWritableFlg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        description = (String) fields.get("myDescription", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        if (fields.defaulted("myDescription"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
          throw new NullPointerException("myDescription");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        minDegree = fields.get("myMinDegree", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        if (fields.defaulted("myMinDegree"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
          throw new NullPointerException("myMinDegree");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        maxDegree = fields.get("myMaxDegree", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        if (fields.defaulted("myMaxDegree"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
          throw new NullPointerException("myMaxDegree");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        referencedMBeanClassName = (String) fields.get("myRefMBeanClassName", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        if (fields.defaulted("myRefMBeanClassName"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
          throw new NullPointerException("myRefMBeanClassName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        // Read an object serialized in the new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        in.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * Serializes a {@link RoleInfo} to an {@link ObjectOutputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    private void writeObject(ObjectOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
      if (compat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        // Serializes this instance in the old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        ObjectOutputStream.PutField fields = out.putFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        fields.put("myName", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        fields.put("myIsReadableFlg", isReadable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        fields.put("myIsWritableFlg", isWritable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        fields.put("myDescription", description);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        fields.put("myMinDegree", minDegree);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        fields.put("myMaxDegree", maxDegree);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        fields.put("myRefMBeanClassName", referencedMBeanClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        out.writeFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        // Serializes this instance in the new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        out.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
}