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    
019    package org.apache.commons.modeler;
020    
021    
022    import java.io.Serializable;
023    
024    import javax.management.Descriptor;
025    import javax.management.modelmbean.ModelMBeanNotificationInfo;
026    
027    
028    /**
029     * <p>Internal configuration information for a <code>Notification</code>
030     * descriptor.</p>
031     *
032     * @author Craig R. McClanahan
033     * @version $Revision: 480402 $ $Date: 2006-11-29 05:43:23 +0100 (Wed, 29 Nov 2006) $
034     */
035    
036    public class NotificationInfo extends FeatureInfo implements Serializable {
037        static final long serialVersionUID = -6319885418912650856L;
038    
039        // ----------------------------------------------------- Instance Variables
040    
041    
042        /**
043         * The <code>ModelMBeanNotificationInfo</code> object that corresponds
044         * to this <code>NotificationInfo</code> instance.
045         */
046        transient ModelMBeanNotificationInfo info = null;
047        protected String notifTypes[] = new String[0];
048    
049        // ------------------------------------------------------------- Properties
050    
051    
052        /**
053         * Override the <code>description</code> property setter.
054         *
055         * @param description The new description
056         */
057        public void setDescription(String description) {
058            super.setDescription(description);
059            this.info = null;
060        }
061    
062    
063        /**
064         * Override the <code>name</code> property setter.
065         *
066         * @param name The new name
067         */
068        public void setName(String name) {
069            super.setName(name);
070            this.info = null;
071        }
072    
073    
074        /**
075         * The set of notification types for this MBean.
076         */
077        public String[] getNotifTypes() {
078            return (this.notifTypes);
079        }
080    
081    
082        // --------------------------------------------------------- Public Methods
083    
084    
085        /**
086         * Add a new notification type to the set managed by an MBean.
087         *
088         * @param notifType The new notification type
089         */
090        public void addNotifType(String notifType) {
091    
092            synchronized (notifTypes) {
093                String results[] = new String[notifTypes.length + 1];
094                System.arraycopy(notifTypes, 0, results, 0, notifTypes.length);
095                results[notifTypes.length] = notifType;
096                notifTypes = results;
097                this.info = null;
098            }
099    
100        }
101    
102    
103        /**
104         * Create and return a <code>ModelMBeanNotificationInfo</code> object that
105         * corresponds to the attribute described by this instance.
106         */
107        public ModelMBeanNotificationInfo createNotificationInfo() {
108    
109            // Return our cached information (if any)
110            if (info != null)
111                return (info);
112    
113            // Create and return a new information object
114            info = new ModelMBeanNotificationInfo
115                (getNotifTypes(), getName(), getDescription());
116            Descriptor descriptor = info.getDescriptor();
117            addFields(descriptor);
118            info.setDescriptor(descriptor);
119            return (info);
120    
121        }
122    
123    
124        /**
125         * Return a string representation of this notification descriptor.
126         */
127        public String toString() {
128    
129            StringBuffer sb = new StringBuffer("NotificationInfo[");
130            sb.append("name=");
131            sb.append(name);
132            sb.append(", description=");
133            sb.append(description);
134            sb.append(", notifTypes=");
135            sb.append(notifTypes.length);
136            sb.append("]");
137            return (sb.toString());
138    
139        }
140    
141    
142    }