001: /* JFox, the OpenSource J2EE Application Server
002: *
003: * Copyright (C) 2002 huihoo.org
004: * Distributable under GNU LGPL license
005: * See the GNU Lesser General Public License for more details.
006: */
007:
008: package javax.management.relation;
009:
010: import java.util.Iterator;
011: import java.util.ArrayList;
012: import java.util.List;
013: import java.io.Serializable;
014: import javax.management.ObjectName;
015:
016: /**
017: * Represents an unresolved role: a role not retrieved from a relation due
018: * to a problem. It provides the role name, value (if problem when trying to
019: * set the role) and an integer defining the problem (constants defined in
020: * RoleStatus).
021: *
022: * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
023: */
024:
025: public class RoleUnresolved implements Serializable {
026:
027: // Role name
028: private String roleName = null;
029:
030: // Role value (ArrayList of ObjectName objects)
031: private List roleValue = null;
032:
033: // Problem type
034: private int roleStatus;
035:
036: /**
037: * Constructor
038: *
039: * @param roleName name of the role
040: * @param roleValue value of the role (if problem when setting the
041: * role)
042: * @param roleStatus type of problem (according to known problem types,
043: * listed as static final members).
044: *
045: * @exception IllegalArgumentException if null parameter or incorrect
046: * problem type
047: */
048: public RoleUnresolved(String roleName, List roleValue,
049: int roleStatus) throws IllegalArgumentException {
050: if (roleName == null)
051: throw new IllegalArgumentException(
052: "Invalid parameter: roleName can not be null");
053: setRoleName(roleName);
054: setRoleValue(roleValue);
055: setProblemType(roleStatus); // Can throw IllegalArgumentException
056: }
057:
058: /**
059: * Retrieves role name
060: */
061: public String getRoleName() {
062: return roleName;
063: }
064:
065: /**
066: * Retrieves role value
067: *
068: * @return an ArrayList of ObjectName objects, the one provided to be set
069: * in given role. Null if the unresolved role is returned for a read
070: * access.
071: */
072: public List getRoleValue() {
073: return roleValue;
074: }
075:
076: /**
077: * Retrieves problem type
078: *
079: * @return an integer corresponding to a problem, those being described as
080: * static final members of current class.
081: */
082: public int getProblemType() {
083: return roleStatus;
084: }
085:
086: /**
087: * Sets role name
088: *
089: * @exception IllegalArgumentException if null parameter
090: */
091: public void setRoleName(String roleName)
092: throws IllegalArgumentException {
093: if (roleName == null) {
094: throw new IllegalArgumentException(
095: "Invalid parameter: roleName can not be null");
096: }
097:
098: this .roleName = new String(roleName);
099: }
100:
101: /**
102: * Sets role value
103: *
104: * @param roleValue ArrayList of ObjectName objects for referenced
105: * MBeans not set in role.
106: */
107: public void setRoleValue(List roleValue) {
108: if (roleValue == null)
109: return;
110: this .roleValue = new ArrayList();
111: for (Iterator it = roleValue.iterator(); it.hasNext();) {
112: ObjectName objName = (ObjectName) (it.next());
113: this .roleValue.add(objName);
114: }
115: }
116:
117: /**
118: * Sets problem type
119: *
120: * @param roleStatus integer corresponding to a problem. Must be one of
121: * those described as static final members of current class.
122: *
123: * @exception IllegalArgumentException if incorrect problem type
124: */
125: public void setProblemType(int roleStatus)
126: throws IllegalArgumentException {
127: if (!(RoleStatus.isRoleStatus(roleStatus)))
128: throw new IllegalArgumentException(
129: "Incorrect problem type " + roleStatus);
130: this .roleStatus = roleStatus;
131: }
132:
133: /**
134: * Clone
135: *
136: * @return an independent clone
137: */
138: public Object clone() {
139: try {
140: return new RoleUnresolved(roleName, roleValue, roleStatus);
141: } catch (IllegalArgumentException exc) {
142: return null; // :)
143: }
144: }
145:
146: /**
147: * Prints a string describing the role
148: */
149: public String toString() {
150: StringBuffer result = new StringBuffer();
151: result.append("role name: " + roleName);
152: if (roleValue != null) {
153: result.append("; value: ");
154: for (Iterator it = roleValue.iterator(); it.hasNext();) {
155: ObjectName objName = (ObjectName) (it.next());
156: result.append(objName.toString());
157: if (it.hasNext())
158: result.append(", ");
159: }
160: }
161: result.append("; problem type: " + roleStatus);
162: return result.toString();
163: }
164: }
|