View Javadoc

1   /*
2    * Copyright 1999-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  
18  package org.apache.commons.modeler;
19  
20  
21  import java.io.Serializable;
22  
23  import javax.management.Descriptor;
24  import javax.management.MBeanParameterInfo;
25  import javax.management.modelmbean.ModelMBeanConstructorInfo;
26  
27  
28  /***
29   * <p>Internal configuration information for a <code>Constructor</code>
30   * descriptor.</p>
31   *
32   * @author Craig R. McClanahan
33   * @version $Revision: 155428 $ $Date: 2005-02-26 08:12:25 -0500 (Sat, 26 Feb 2005) $
34   */
35  
36  public class ConstructorInfo extends FeatureInfo implements Serializable {
37      static final long serialVersionUID = -5735336213417238238L;
38  
39      // ----------------------------------------------------- Instance Variables
40  
41  
42      /***
43       * The <code>ModelMBeanConstructorInfo</code> object that corresponds
44       * to this <code>ConstructorInfo</code> instance.
45       */
46      transient ModelMBeanConstructorInfo info = null;
47      protected String displayName = null;
48      protected ParameterInfo parameters[] = new ParameterInfo[0];
49  
50  
51      // ------------------------------------------------------------- Properties
52  
53  
54      /***
55       * Override the <code>description</code> property setter.
56       *
57       * @param description The new description
58       */
59      public void setDescription(String description) {
60          super.setDescription(description);
61          this.info = null;
62      }
63  
64  
65      /***
66       * Override the <code>name</code> property setter.
67       *
68       * @param name The new name
69       */
70      public void setName(String name) {
71          super.setName(name);
72          this.info = null;
73      }
74  
75  
76      /***
77       * The display name of this attribute.
78       */
79      public String getDisplayName() {
80          return (this.displayName);
81      }
82  
83      public void setDisplayName(String displayName) {
84          this.displayName = displayName;
85      }
86  
87  
88      /***
89       * The set of parameters for this constructor.
90       */
91      public ParameterInfo[] getSignature() {
92          return (this.parameters);
93      }
94  
95  
96      // --------------------------------------------------------- Public Methods
97  
98  
99      /***
100      * Add a new parameter to the set of parameters for this constructor.
101      *
102      * @param parameter The new parameter descriptor
103      */
104     public void addParameter(ParameterInfo parameter) {
105 
106         synchronized (parameters) {
107             ParameterInfo results[] = new ParameterInfo[parameters.length + 1];
108             System.arraycopy(parameters, 0, results, 0, parameters.length);
109             results[parameters.length] = parameter;
110             parameters = results;
111             this.info = null;
112         }
113 
114     }
115 
116 
117     /***
118      * Create and return a <code>ModelMBeanConstructorInfo</code> object that
119      * corresponds to the attribute described by this instance.
120      */
121     public ModelMBeanConstructorInfo createConstructorInfo() {
122 
123         // Return our cached information (if any)
124         if (info != null)
125             return (info);
126 
127         // Create and return a new information object
128         ParameterInfo params[] = getSignature();
129         MBeanParameterInfo parameters[] =
130             new MBeanParameterInfo[params.length];
131         for (int i = 0; i < params.length; i++)
132             parameters[i] = params[i].createParameterInfo();
133         info = new ModelMBeanConstructorInfo
134             (getName(), getDescription(), parameters);
135         Descriptor descriptor = info.getDescriptor();
136         descriptor.removeField("class");
137         if (getDisplayName() != null)
138             descriptor.setField("displayName", getDisplayName());
139         addFields(descriptor);
140         info.setDescriptor(descriptor);
141         return (info);
142 
143     }
144 
145 
146     /***
147      * Return a string representation of this constructor descriptor.
148      */
149     public String toString() {
150 
151         StringBuffer sb = new StringBuffer("ConstructorInfo[");
152         sb.append("name=");
153         sb.append(name);
154         sb.append(", description=");
155         sb.append(description);
156         sb.append(", parameters=");
157         sb.append(parameters.length);
158         sb.append("]");
159         return (sb.toString());
160 
161     }
162 
163 
164 }