001: /**
002: * Copyright (C) The MX4J Contributors.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the MX4J License version 1.0.
006: * See the terms of the MX4J License in the documentation provided with this software.
007: */package javax.management.relation;
008:
009: import java.util.ArrayList;
010: import java.util.Collections;
011: import java.util.List;
012: import javax.management.Notification;
013: import javax.management.ObjectName;
014:
015: /**
016: * @version $Revision: 1.9 $
017: */
018: public class RelationNotification extends Notification {
019: private static final long serialVersionUID = -6871117877523310399L;
020:
021: public static final String RELATION_BASIC_CREATION = "jmx.relation.creation.basic";
022: public static final String RELATION_MBEAN_CREATION = "jmx.relation.creation.mbean";
023: public static final String RELATION_BASIC_REMOVAL = "jmx.relation.removal.basic";
024: public static final String RELATION_MBEAN_REMOVAL = "jmx.relation.removal.mbean";
025: public static final String RELATION_BASIC_UPDATE = "jmx.relation.update.basic";
026: public static final String RELATION_MBEAN_UPDATE = "jmx.relation.update.mbean";
027:
028: private String relationId;
029: private String relationTypeName;
030: private String roleName;
031: private ObjectName relationObjName;
032: private List unregisterMBeanList;
033: private List oldRoleValue;
034: private List newRoleValue;
035:
036: /**
037: * Constructor used when creating or removing a relation
038: */
039: public RelationNotification(String createRemoveType, Object source,
040: long sequenceNumber, long timestamp, String message,
041: String relationId, String relationTypeName,
042: ObjectName relationObjectName, List unregisteredMBeanList)
043: throws IllegalArgumentException {
044: super (createRemoveType, source, sequenceNumber, timestamp,
045: message);
046: // checks if the type is one of Creation or removal of an MBean or a Relation
047: checkCreateRemoveType(createRemoveType);
048: this .relationId = relationId;
049: this .relationTypeName = relationTypeName;
050: this .relationObjName = relationObjectName;
051: setUnregisterMBeanList(unregisteredMBeanList);
052: }
053:
054: /**
055: * Constructor used when updating a Relation
056: */
057: public RelationNotification(String updateType, Object source,
058: long sequenceNumber, long timestamp, String message,
059: String relationId, String relationTypeName,
060: ObjectName relationObjectName, String roleName,
061: List newRoleValues, List oldRoleValues)
062: throws IllegalArgumentException {
063: super (updateType, source, sequenceNumber, timestamp, message);
064: // checks for an MBean or relation update
065: checkUpdateType(updateType);
066: this .relationId = relationId;
067: this .relationTypeName = relationTypeName;
068: this .relationObjName = relationObjectName;
069: this .roleName = roleName;
070: setOldRoleValues(oldRoleValues);
071: setNewRoleValues(newRoleValues);
072: }
073:
074: private void setOldRoleValues(List list) {
075: if (list != null) {
076: if (oldRoleValue == null) {
077: oldRoleValue = new ArrayList();
078: }
079: oldRoleValue.clear();
080: oldRoleValue.addAll(list);
081: }
082: }
083:
084: private void setNewRoleValues(List list) {
085: if (list != null) {
086: if (newRoleValue == null) {
087: newRoleValue = new ArrayList();
088: }
089: newRoleValue.clear();
090: newRoleValue.addAll(list);
091: }
092: }
093:
094: private void setUnregisterMBeanList(List list) {
095: if (list != null) {
096: if (unregisterMBeanList == null) {
097: unregisterMBeanList = new ArrayList();
098: }
099: unregisterMBeanList.clear();
100: unregisterMBeanList.addAll(list);
101: }
102: }
103:
104: public String getRelationId() {
105: return relationId;
106: }
107:
108: public String getRelationTypeName() {
109: return relationTypeName;
110: }
111:
112: public ObjectName getObjectName() {
113: return relationObjName;
114: }
115:
116: public List getMBeansToUnregister() {
117: if (unregisterMBeanList != null) {
118: // Cannot clone, since I'm not sure which type of list the data member is.
119: return new ArrayList(unregisterMBeanList);
120: } else {
121: return Collections.EMPTY_LIST;
122: }
123: }
124:
125: public List getNewRoleValue() {
126: if (newRoleValue != null) {
127: // Cannot clone, since I'm not sure which type of list the data member is.
128: return new ArrayList(newRoleValue);
129: } else {
130: return Collections.EMPTY_LIST;
131: }
132: }
133:
134: public List getOldRoleValue() {
135: if (oldRoleValue != null) {
136: // Cannot clone, since I'm not sure which type of list the data member is.
137: return new ArrayList(oldRoleValue);
138: } else {
139: return Collections.EMPTY_LIST;
140: }
141: }
142:
143: public String getRoleName() {
144: return roleName;
145: }
146:
147: private void checkCreateRemoveType(String type)
148: throws IllegalArgumentException {
149: if (!(type.equals(RelationNotification.RELATION_BASIC_CREATION))
150: && (!(type
151: .equals(RelationNotification.RELATION_MBEAN_CREATION)))
152: && (!(type
153: .equals(RelationNotification.RELATION_BASIC_REMOVAL)))
154: && (!(type
155: .equals(RelationNotification.RELATION_MBEAN_REMOVAL)))) {
156: throw new IllegalArgumentException(
157: "Notification type is not recognized must be one of create or remove");
158: }
159: }
160:
161: private void checkUpdateType(String type)
162: throws IllegalArgumentException {
163: if (!(type.equals(RelationNotification.RELATION_BASIC_UPDATE))
164: && (!(type
165: .equals(RelationNotification.RELATION_MBEAN_UPDATE)))) {
166: throw new IllegalArgumentException(
167: "Notification type is not recognized must be one of update");
168: }
169: }
170: }
|