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.MBeanParameterInfo;
026    import javax.management.modelmbean.ModelMBeanConstructorInfo;
027    
028    
029    /**
030     * <p>Internal configuration information for a <code>Constructor</code>
031     * descriptor.</p>
032     *
033     * @author Craig R. McClanahan
034     * @version $Revision: 480402 $ $Date: 2006-11-29 05:43:23 +0100 (Wed, 29 Nov 2006) $
035     */
036    
037    public class ConstructorInfo extends FeatureInfo implements Serializable {
038        static final long serialVersionUID = -5735336213417238238L;
039    
040        // ----------------------------------------------------- Instance Variables
041    
042    
043        /**
044         * The <code>ModelMBeanConstructorInfo</code> object that corresponds
045         * to this <code>ConstructorInfo</code> instance.
046         */
047        transient ModelMBeanConstructorInfo info = null;
048        protected String displayName = null;
049        protected ParameterInfo parameters[] = new ParameterInfo[0];
050    
051    
052        // ------------------------------------------------------------- Properties
053    
054    
055        /**
056         * Override the <code>description</code> property setter.
057         *
058         * @param description The new description
059         */
060        public void setDescription(String description) {
061            super.setDescription(description);
062            this.info = null;
063        }
064    
065    
066        /**
067         * Override the <code>name</code> property setter.
068         *
069         * @param name The new name
070         */
071        public void setName(String name) {
072            super.setName(name);
073            this.info = null;
074        }
075    
076    
077        /**
078         * The display name of this attribute.
079         */
080        public String getDisplayName() {
081            return (this.displayName);
082        }
083    
084        public void setDisplayName(String displayName) {
085            this.displayName = displayName;
086        }
087    
088    
089        /**
090         * The set of parameters for this constructor.
091         */
092        public ParameterInfo[] getSignature() {
093            return (this.parameters);
094        }
095    
096    
097        // --------------------------------------------------------- Public Methods
098    
099    
100        /**
101         * Add a new parameter to the set of parameters for this constructor.
102         *
103         * @param parameter The new parameter descriptor
104         */
105        public void addParameter(ParameterInfo parameter) {
106    
107            synchronized (parameters) {
108                ParameterInfo results[] = new ParameterInfo[parameters.length + 1];
109                System.arraycopy(parameters, 0, results, 0, parameters.length);
110                results[parameters.length] = parameter;
111                parameters = results;
112                this.info = null;
113            }
114    
115        }
116    
117    
118        /**
119         * Create and return a <code>ModelMBeanConstructorInfo</code> object that
120         * corresponds to the attribute described by this instance.
121         */
122        public ModelMBeanConstructorInfo createConstructorInfo() {
123    
124            // Return our cached information (if any)
125            if (info != null)
126                return (info);
127    
128            // Create and return a new information object
129            ParameterInfo params[] = getSignature();
130            MBeanParameterInfo parameters[] =
131                new MBeanParameterInfo[params.length];
132            for (int i = 0; i < params.length; i++)
133                parameters[i] = params[i].createParameterInfo();
134            info = new ModelMBeanConstructorInfo
135                (getName(), getDescription(), parameters);
136            Descriptor descriptor = info.getDescriptor();
137            descriptor.removeField("class");
138            if (getDisplayName() != null)
139                descriptor.setField("displayName", getDisplayName());
140            addFields(descriptor);
141            info.setDescriptor(descriptor);
142            return (info);
143    
144        }
145    
146    
147        /**
148         * Return a string representation of this constructor descriptor.
149         */
150        public String toString() {
151    
152            StringBuffer sb = new StringBuffer("ConstructorInfo[");
153            sb.append("name=");
154            sb.append(name);
155            sb.append(", description=");
156            sb.append(description);
157            sb.append(", parameters=");
158            sb.append(parameters.length);
159            sb.append("]");
160            return (sb.toString());
161    
162        }
163    
164    
165    }