View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  
19  package org.apache.commons.modeler;
20  
21  
22  import java.io.Serializable;
23  
24  import javax.management.Descriptor;
25  import javax.management.MBeanParameterInfo;
26  import javax.management.modelmbean.ModelMBeanConstructorInfo;
27  
28  
29  /***
30   * <p>Internal configuration information for a <code>Constructor</code>
31   * descriptor.</p>
32   *
33   * @author Craig R. McClanahan
34   * @version $Revision: 480402 $ $Date: 2006-11-29 04:43:23 +0000 (Wed, 29 Nov 2006) $
35   */
36  
37  public class ConstructorInfo extends FeatureInfo implements Serializable {
38      static final long serialVersionUID = -5735336213417238238L;
39  
40      // ----------------------------------------------------- Instance Variables
41  
42  
43      /***
44       * The <code>ModelMBeanConstructorInfo</code> object that corresponds
45       * to this <code>ConstructorInfo</code> instance.
46       */
47      transient ModelMBeanConstructorInfo info = null;
48      protected String displayName = null;
49      protected ParameterInfo parameters[] = new ParameterInfo[0];
50  
51  
52      // ------------------------------------------------------------- Properties
53  
54  
55      /***
56       * Override the <code>description</code> property setter.
57       *
58       * @param description The new description
59       */
60      public void setDescription(String description) {
61          super.setDescription(description);
62          this.info = null;
63      }
64  
65  
66      /***
67       * Override the <code>name</code> property setter.
68       *
69       * @param name The new name
70       */
71      public void setName(String name) {
72          super.setName(name);
73          this.info = null;
74      }
75  
76  
77      /***
78       * The display name of this attribute.
79       */
80      public String getDisplayName() {
81          return (this.displayName);
82      }
83  
84      public void setDisplayName(String displayName) {
85          this.displayName = displayName;
86      }
87  
88  
89      /***
90       * The set of parameters for this constructor.
91       */
92      public ParameterInfo[] getSignature() {
93          return (this.parameters);
94      }
95  
96  
97      // --------------------------------------------------------- Public Methods
98  
99  
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 }