src/java.management/share/classes/javax/management/relation/RoleUnresolved.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 25859 jdk/src/java.management/share/classes/javax/management/relation/RoleUnresolved.java@3317bb8137f4
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
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: 1639
diff changeset
     2
 * Copyright (c) 2000, 2008, 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: 1639
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: 1639
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: 1639
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
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
import static com.sun.jmx.mbeanserver.Util.cast;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Represents an unresolved role: a role not retrieved from a relation due
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * to a problem. It provides the role name, value (if problem when trying to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * set the role) and an integer defining the problem (constants defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * RoleStatus).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p>The <b>serialVersionUID</b> of this class is <code>-48350262537070138L</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
@SuppressWarnings("serial")  // serialVersionUID not constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
public class RoleUnresolved implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // Serialization compatibility stuff:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    // Two serial forms are supported in this class. The selected form depends
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    // on system property "jmx.serial.form":
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    //  - "1.0" for JMX 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    //  - any other value for JMX 1.1 and higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // Serial version for old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    private static final long oldSerialVersionUID = -9026457686611660144L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // Serial version for new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private static final long newSerialVersionUID = -48350262537070138L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    // Serializable fields in old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private static final ObjectStreamField[] oldSerialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
      new ObjectStreamField("myRoleName", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
      new ObjectStreamField("myRoleValue", ArrayList.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
      new ObjectStreamField("myPbType", int.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    // Serializable fields in new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static final ObjectStreamField[] newSerialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
      new ObjectStreamField("roleName", String.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
      new ObjectStreamField("roleValue", List.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
      new ObjectStreamField("problemType", int.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // Actual serial version and serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private static final long serialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /** @serialField roleName String Role name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *  @serialField roleValue List Role value ({@link List} of {@link ObjectName} objects)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *  @serialField problemType int Problem type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private static final ObjectStreamField[] serialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private static boolean compat = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            String form = AccessController.doPrivileged(act);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            compat = (form != null && form.equals("1.0"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            // OK : Too bad, no compat with 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (compat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            serialPersistentFields = oldSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            serialVersionUID = oldSerialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            serialPersistentFields = newSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            serialVersionUID = newSerialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    // END Serialization compatibility stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    // Private members
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
     * @serial Role name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private String roleName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @serial Role value ({@link List} of {@link ObjectName} objects)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    private List<ObjectName> roleValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @serial Problem type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    private int problemType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    // Constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @param name  name of the role
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param value  value of the role (if problem when setting the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * role)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param pbType  type of problem (according to known problem types,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * listed as static final members).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @exception IllegalArgumentException  if null parameter or incorrect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * problem type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public RoleUnresolved(String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                          List<ObjectName> value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                          int pbType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        setRoleName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        setRoleValue(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        // Can throw IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        setProblemType(pbType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    // Accessors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Retrieves role name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @return the role name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @see #setRoleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public String getRoleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        return roleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Retrieves role value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @return an ArrayList of ObjectName objects, the one provided to be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * in given role. Null if the unresolved role is returned for a read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * access.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @see #setRoleValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public List<ObjectName> getRoleValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        return roleValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Retrieves problem type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @return an integer corresponding to a problem, those being described as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * static final members of current class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @see #setProblemType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public int getProblemType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return problemType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Sets role name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @param name the new role name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @see #getRoleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public void setRoleName(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        roleName = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Sets role value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @param value  List of ObjectName objects for referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * MBeans not set in role.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @see #getRoleValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public void setRoleValue(List<ObjectName> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            roleValue = new ArrayList<ObjectName>(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            roleValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Sets problem type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @param pbType  integer corresponding to a problem. Must be one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * those described as static final members of current class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @exception IllegalArgumentException  if incorrect problem type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @see #getProblemType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public void setProblemType(int pbType)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        if (!(RoleStatus.isRoleStatus(pbType))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            String excMsg = "Incorrect problem type.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        problemType = pbType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * Clone this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @return an independent clone.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            return new RoleUnresolved(roleName, roleValue, problemType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        } catch (IllegalArgumentException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            return null; // :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * Return a string describing this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @return a description of this RoleUnresolved object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        StringBuilder result = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        result.append("role name: " + roleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (roleValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            result.append("; value: ");
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   288
            for (Iterator<ObjectName> objNameIter = roleValue.iterator();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                 objNameIter.hasNext();) {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   290
                ObjectName currObjName = objNameIter.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                result.append(currObjName.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                if (objNameIter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                    result.append(", ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        result.append("; problem type: " + problemType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        return result.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Deserializes a {@link RoleUnresolved} from an {@link ObjectInputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    private void readObject(ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
      if (compat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        // Read an object serialized in the old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        ObjectInputStream.GetField fields = in.readFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        roleName = (String) fields.get("myRoleName", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if (fields.defaulted("myRoleName"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
          throw new NullPointerException("myRoleName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        roleValue = cast(fields.get("myRoleValue", null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        if (fields.defaulted("myRoleValue"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
          throw new NullPointerException("myRoleValue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        problemType = fields.get("myPbType", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        if (fields.defaulted("myPbType"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
          throw new NullPointerException("myPbType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        // Read an object serialized in the new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        in.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * Serializes a {@link RoleUnresolved} to an {@link ObjectOutputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    private void writeObject(ObjectOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
      if (compat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        // Serializes this instance in the old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        ObjectOutputStream.PutField fields = out.putFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        fields.put("myRoleName", roleName);
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   347
        fields.put("myRoleValue", roleValue);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        fields.put("myPbType", problemType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        out.writeFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        // Serializes this instance in the new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        out.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
}