001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.commons.modeler;
019:
020: import java.io.Serializable;
021:
022: import javax.management.Descriptor;
023: import javax.management.modelmbean.ModelMBeanNotificationInfo;
024:
025: /**
026: * <p>Internal configuration information for a <code>Notification</code>
027: * descriptor.</p>
028: *
029: * @author Craig R. McClanahan
030: * @version $Revision: 480402 $ $Date: 2006-11-29 04:43:23 +0000 (Wed, 29 Nov 2006) $
031: */
032:
033: public class NotificationInfo extends FeatureInfo implements
034: Serializable {
035: static final long serialVersionUID = -6319885418912650856L;
036:
037: // ----------------------------------------------------- Instance Variables
038:
039: /**
040: * The <code>ModelMBeanNotificationInfo</code> object that corresponds
041: * to this <code>NotificationInfo</code> instance.
042: */
043: transient ModelMBeanNotificationInfo info = null;
044: protected String notifTypes[] = new String[0];
045:
046: // ------------------------------------------------------------- Properties
047:
048: /**
049: * Override the <code>description</code> property setter.
050: *
051: * @param description The new description
052: */
053: public void setDescription(String description) {
054: super .setDescription(description);
055: this .info = null;
056: }
057:
058: /**
059: * Override the <code>name</code> property setter.
060: *
061: * @param name The new name
062: */
063: public void setName(String name) {
064: super .setName(name);
065: this .info = null;
066: }
067:
068: /**
069: * The set of notification types for this MBean.
070: */
071: public String[] getNotifTypes() {
072: return (this .notifTypes);
073: }
074:
075: // --------------------------------------------------------- Public Methods
076:
077: /**
078: * Add a new notification type to the set managed by an MBean.
079: *
080: * @param notifType The new notification type
081: */
082: public void addNotifType(String notifType) {
083:
084: synchronized (notifTypes) {
085: String results[] = new String[notifTypes.length + 1];
086: System.arraycopy(notifTypes, 0, results, 0,
087: notifTypes.length);
088: results[notifTypes.length] = notifType;
089: notifTypes = results;
090: this .info = null;
091: }
092:
093: }
094:
095: /**
096: * Create and return a <code>ModelMBeanNotificationInfo</code> object that
097: * corresponds to the attribute described by this instance.
098: */
099: public ModelMBeanNotificationInfo createNotificationInfo() {
100:
101: // Return our cached information (if any)
102: if (info != null)
103: return (info);
104:
105: // Create and return a new information object
106: info = new ModelMBeanNotificationInfo(getNotifTypes(),
107: getName(), getDescription());
108: Descriptor descriptor = info.getDescriptor();
109: addFields(descriptor);
110: info.setDescriptor(descriptor);
111: return (info);
112:
113: }
114:
115: /**
116: * Return a string representation of this notification descriptor.
117: */
118: public String toString() {
119:
120: StringBuffer sb = new StringBuffer("NotificationInfo[");
121: sb.append("name=");
122: sb.append(name);
123: sb.append(", description=");
124: sb.append(description);
125: sb.append(", notifTypes=");
126: sb.append(notifTypes.length);
127: sb.append("]");
128: return (sb.toString());
129:
130: }
131:
132: }
|