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