01: /**
02: * Copyright (C) The MX4J Contributors.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the MX4J License version 1.0.
06: * See the terms of the MX4J License in the documentation provided with this software.
07: */package javax.management.relation;
08:
09: import java.io.Serializable;
10: import java.util.ArrayList;
11: import java.util.Iterator;
12: import java.util.List;
13: import javax.management.ObjectName;
14:
15: /**
16: * @version $Revision: 1.10 $
17: */
18: public class RoleUnresolved implements Serializable {
19: private static final long serialVersionUID = -48350262537070138L;
20:
21: private String roleName;
22: private List roleValue;
23: private int problemType;
24:
25: public RoleUnresolved(String roleName, List roleValues,
26: int problemType) throws IllegalArgumentException {
27: setRoleName(roleName);
28: setRoleValue(roleValues);
29: setProblemType(problemType);
30: }
31:
32: public int getProblemType() {
33: return problemType;
34: }
35:
36: public String getRoleName() {
37: return roleName;
38: }
39:
40: public List getRoleValue() {
41: // During serialization I can get any type of List
42: return roleValue == null ? null : new ArrayList(roleValue);
43: }
44:
45: public void setRoleName(String name) {
46: if (name == null)
47: throw new IllegalArgumentException(
48: "Role Name cannot be null");
49: roleName = name;
50: }
51:
52: public void setRoleValue(List list) {
53: if (list != null) {
54: if (roleValue == null) {
55: roleValue = new ArrayList();
56: }
57: roleValue.clear();
58: roleValue.addAll(list);
59: } else {
60: roleValue = null;
61: }
62: }
63:
64: public void setProblemType(int type) {
65: if (!(RoleStatus.isRoleStatus(type))) {
66: throw new IllegalArgumentException("Problem Type unknown");
67: }
68: problemType = type;
69: }
70:
71: public Object clone() {
72: // NB we do not (and cannot) implement Cloneable so we do our own copy
73: return new RoleUnresolved(roleName, roleValue, problemType);
74: }
75:
76: public String toString() {
77: StringBuffer roleBuff = new StringBuffer();
78: roleBuff.append("Role Name: ").append(roleName);
79: if (roleValue != null) {
80: roleBuff.append("\nRole Values:");
81: for (Iterator i = roleValue.iterator(); i.hasNext();) {
82: ObjectName objectName = (ObjectName) i.next();
83: roleBuff.append(objectName);
84: if (i.hasNext()) {
85: roleBuff.append(", ");
86: }
87: }
88: }
89: roleBuff.append("\nProblem Type:");
90: roleBuff.append(problemType);
91: return roleBuff.toString();
92: }
93: }
|