001: /**
002: * The XMOJO Project 5
003: * Copyright © 2003 XMOJO.org. All rights reserved.
004:
005: * NO WARRANTY
006:
007: * BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
008: * THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
009: * OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
010: * PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
011: * OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
012: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
013: * TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE
014: * LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
015: * REPAIR OR CORRECTION.
016:
017: * IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
018: * ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE
019: * THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
020: * GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
021: * USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF
022: * DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
023: * PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE),
024: * EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
025: * SUCH DAMAGES.
026: **/package javax.management.modelmbean;
027:
028: import java.io.ObjectInputStream;
029: import java.io.ObjectOutputStream;
030: import java.io.ObjectStreamField;
031: import java.io.IOException;
032:
033: import javax.management.Descriptor;
034: import javax.management.DescriptorAccess;
035: import javax.management.MBeanNotificationInfo;
036:
037: /**
038: * The ModelMBeanNotificationInfo object describes a notification emitted
039: * by a ModelMBean. It is a subclass of MBeanNotificationInfo with the
040: * addition of an associated Descriptor and an implementation of the
041: * Descriptor interface.
042: * <P>
043: * <P>
044: * <PRE>
045: * The fields in the descriptor are defined, but not limited to, the following: <P>
046: * name : notification name <P>
047: * descriptorType : must be "notification" <P>
048: * severity : 1-5 where 1: fatal 2: severe 3: error 4: warn 5: info <P>
049: * messageID : unique key for message text (to allow translation,analysis) <P>
050: * messageText : text of notification <P>
051: * log : T - log message F - do not log message <P>
052: * logfile : string fully qualified file name appropriate for operating system<P>
053: * visibility : 1-4 where 1: always visible 4: rarely visible <P>
054: * presentationString : xml formatted string to allow presentation of data <P>
055: * </PRE>
056: * <P> The default descriptor contains the name, descriptorType, and severity=5 fields.
057: */
058: public class ModelMBeanNotificationInfo extends MBeanNotificationInfo
059: implements DescriptorAccess, Cloneable {
060: Descriptor descriptor = new DescriptorSupport();
061:
062: static final long serialVersionUID = -5304849168906325029L;
063:
064: private static final ObjectStreamField[] serialPersistentFields = {
065: new ObjectStreamField("notificationDescriptor",
066: DescriptorSupport.class),
067: new ObjectStreamField("currClass", java.lang.String.class) };
068:
069: /**
070: * Constructs a ModelMBeanNotificationInfo object with a default descxriptor.
071: *
072: * @param notifTypes The notification type string
073: *
074: * @param name The Notification class name
075: *
076: * @param description The description about the notification
077: */
078: public ModelMBeanNotificationInfo(String[] notifTypes, String name,
079: String description) {
080: super (notifTypes, name, description);
081: this .descriptor = getDefaultDescriptor();
082: }
083:
084: /**
085: * Constructs a ModelMBeanNotificationInfo object
086: *
087: * @param notifTypes The notification type string
088: *
089: * @param name The Notification class name
090: *
091: * @param description The description about the notification
092: *
093: * @param descriptor Descriptor containing the appropriate metadata for
094: * this instance of the MBeanNotificationInfo. If it is null
095: * or invalid then a default desriptor will be created.
096: */
097: public ModelMBeanNotificationInfo(String[] notifTypes, String name,
098: String description, Descriptor descriptor) {
099: super (notifTypes, name, description);
100:
101: if (descriptor.isValid())
102: this .descriptor = descriptor;
103: else
104: this .descriptor = getDefaultDescriptor();
105: }
106:
107: /**
108: * Constructs a new ModelMBeanNotificationInfo object from this
109: * ModelMBeanNotfication Object.
110: *
111: * @param inInfo The duplicate ModelMBeanNotificationInfo object
112: */
113: public ModelMBeanNotificationInfo(ModelMBeanNotificationInfo inInfo) {
114: super (inInfo.getNotifTypes(), inInfo.getName(), inInfo
115: .getDescription());
116:
117: if (inInfo.getDescriptor() != null)
118: this .descriptor = (Descriptor) inInfo.getDescriptor()
119: .clone();
120: else
121: this .descriptor = getDefaultDescriptor();
122: }
123:
124: /**
125: * Creates a duplicate ModelMBeanNotificationInfo object
126: *
127: * @return A duplicate ModelMBeanNotificationInfo object
128: */
129: public Object clone() {
130: Descriptor clonedDescr = null;
131:
132: if (descriptor != null)
133: clonedDescr = (Descriptor) descriptor.clone();
134:
135: return new ModelMBeanNotificationInfo(getNotifTypes(),
136: getName(), getDescription(), clonedDescr);
137: }
138:
139: /**
140: * Gets the corresponding Descriptor of this ModelMBeanNotificationInfo
141: *
142: * @return This returns the Descriptor associated with
143: * this ModelMBeanNotificationInfo
144: */
145: public Descriptor getDescriptor() {
146: return descriptor;
147: }
148:
149: /**
150: * Sets the specified Descriptor to this ModelMBeanNotificationInfo.If the
151: * value is null then default Descriptor will be taken. The Descriptor
152: * is validated before it is assigned. If the new Descriptor is invalid,
153: * then an IllegalArgumentException is thrown.
154: *
155: * @param inDescriptor This replaces the Descriptor associated with the
156: * ModelMBeanNotification interface
157: *
158: * @throws IllegalArgumentException If the new Descriptor is invalid,
159: * then it will be thrown.
160: */
161: public void setDescriptor(Descriptor inDescriptor) {
162: if (inDescriptor == null) {
163: this .descriptor = getDefaultDescriptor();
164: } else {
165: if (inDescriptor.isValid())
166: this .descriptor = (Descriptor) inDescriptor.clone();
167: else
168: throw new IllegalArgumentException(
169: "Invalid descriptor received as parameter");
170: }
171: }
172:
173: /**
174: * Returns a human readable version of the ModelMBeanNotificationInfo instance
175: * @return Human readable version of the ModelMBeanNotificationInfo instance
176: */
177: public String toString() {
178: if (descriptor != null)
179: return (super .toString() + "\n Descriptor = " + descriptor
180: .toString());
181: else
182: return (super .toString() + "\n Descriptor = null");
183: }
184:
185: //--------------------------- Private methods ---------------------------//
186:
187: /**
188: * Creates default descriptor for notification as follows:
189: * descriptorType=notification, name=this.getName(),
190: * displayname=this.getName(),log=F,severity=5,visibility=1
191: */
192: private Descriptor getDefaultDescriptor() {
193: return new DescriptorSupport(new String[] {
194: "descriptorType=notification",
195: ("name=" + this .getName()),
196: ("displayName=" + this .getName()), "severity=5",
197: "log=F", "visibility=1" });
198: }
199:
200: private void readObject(ObjectInputStream objectinputstream)
201: throws IOException, ClassNotFoundException {
202: ObjectInputStream.GetField getfield = objectinputstream
203: .readFields();
204:
205: try {
206: descriptor = (DescriptorSupport) getfield.get(
207: "notificationDescriptor", null);
208: } catch (Exception exception) {
209: //throw new IOException(malformedobjectnameexception.toString());
210: }
211: }
212:
213: private void writeObject(ObjectOutputStream objectoutputstream)
214: throws IOException {
215: ObjectOutputStream.PutField putfield = objectoutputstream
216: .putFields();
217: putfield.put("notificationDescriptor", descriptor);
218: putfield.put("currClass", "ModelMBeanNotificationInfo");
219:
220: objectoutputstream.writeFields();
221: }
222: }
|