001: /**
002: * The XMOJO Project 5
003: * Copyright © 2003 XMOJO.org. All rights reserved.
004:
005: * NO WARRANTY
006:
007: * BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
008: * THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
009: * OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
010: * PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
011: * OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
012: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
013: * TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE
014: * LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
015: * REPAIR OR CORRECTION.
016:
017: * IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL
018: * ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE
019: * THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
020: * GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
021: * USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF
022: * DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
023: * PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE),
024: * EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
025: * SUCH DAMAGES.
026: **/package javax.management.modelmbean;
027:
028: import java.lang.reflect.Constructor;
029: import java.io.ObjectInputStream;
030: import java.io.ObjectOutputStream;
031: import java.io.ObjectStreamField;
032: import java.io.IOException;
033:
034: import javax.management.Descriptor;
035: import javax.management.DescriptorAccess;
036: import javax.management.MBeanConstructorInfo;
037: import javax.management.MBeanParameterInfo;
038: import javax.management.IntrospectionException;
039:
040: /**
041: * The ModelMBeanConstructorInfo object describes a constructor of the
042: * ModelMBean. It is a subclass of MBeanConstructorInfo with the addition
043: * of an associated Descriptor and an implementation of the DescriptorAccess
044: * interface.
045: * <p>
046: * <p>
047: * <PRE>
048: * The fields in the descriptor are defined, but not limited to, the following: <P>
049: * name : operation name
050: * descriptorType : must be "operation"
051: * role : must be "constructor"
052: * displayName : human readable name of constructor
053: * class : class where method is defined (fully qualified)
054: * visibility : 1-4 where 1: always visible 4: rarely visible
055: * presentationString : xml formatted string to describe how to present operation
056: *</PRE>
057: * <p>PersistencePolicy and CurrencyTimeLimit fields are not valid for the
058: * constructor. The default constructo will have the name, descriptorType,
059: * and role fields.
060: */
061: public class ModelMBeanConstructorInfo extends MBeanConstructorInfo
062: implements DescriptorAccess, Cloneable {
063: Descriptor descriptor = new DescriptorSupport();
064:
065: private static final long serialVersionUID = 2675397548836767216L;
066:
067: private static final ObjectStreamField[] serialPersistentFields = {
068: new ObjectStreamField("consDescriptor",
069: DescriptorSupport.class),
070: new ObjectStreamField("currClass", java.lang.String.class) };
071:
072: /**
073: * Constructs a MBeanConstructorInfo object with a default descriptor.
074: *
075: * @param description The description of the constructor
076: *
077: * @param constructor object describing the MBean constructor.
078: */
079: public ModelMBeanConstructorInfo(String description,
080: Constructor constructor) {
081: super (description, constructor);
082: }
083:
084: /**
085: * Constructs a MBeanConstructorInfo object with the specified descriptor.
086: *
087: * @param description The description of the constructor
088: *
089: * @param constructor object describing the MBean constructor.
090: *
091: * @param descriptor An instance of Descriptor containing the appropriate
092: * metadata for this instance of the ModelMBeanConstructorInfo.
093: * If it is null or invalid then a default desriptor will be created.
094: */
095: public ModelMBeanConstructorInfo(String description,
096: Constructor constructor, Descriptor descriptor) {
097: super (description, constructor);
098: this .descriptor = descriptor;
099: }
100:
101: /**
102: * Constructs a MBeanConstructorInfo object with a default descriptor.
103: *
104: * @param name The name of the constructor
105: *
106: * @param description The description of the constructor
107: *
108: * @param signature MBeanParameterInfo object array describing the
109: * parameters of the constructor.
110: */
111: public ModelMBeanConstructorInfo(String name, String description,
112: MBeanParameterInfo[] signature) {
113: super (name, description, signature);
114: }
115:
116: /**
117: * Constructs a MBeanConstructorInfo object with a default descriptor.
118: *
119: * @param name The name of the constructor
120: *
121: * @param description The description of the constructor
122: *
123: * @param signature MBeanParameterInfo object array describing the
124: * parameters of the constructor.
125: *
126: * @param descriptor An instance of Descriptor containing the appropriate
127: * metadata for this instance of the ModelMBeanConstructorInfo.
128: * If it is null or invalid then a default desriptor will be created.
129: */
130: public ModelMBeanConstructorInfo(String name, String description,
131: MBeanParameterInfo[] signature, Descriptor descriptor) {
132: super (name, description, signature);
133: this .descriptor = descriptor;
134: }
135:
136: /**
137: * Constructs a duplicate copy ModelMBeanConstructorInfo.
138: * @return The duplicate copy of the object is returned.
139: */
140: public Object clone() {
141: Descriptor clonedDescr = null;
142:
143: if (descriptor != null)
144: clonedDescr = (Descriptor) descriptor.clone();
145:
146: return new ModelMBeanConstructorInfo(getName(),
147: getDescription(), getSignature(), clonedDescr);
148: }
149:
150: /**
151: * Returns the descriptor
152: *
153: * @return Descriptor associated with the ModelMBeanConstructorInfo object.
154: */
155: public Descriptor getDescriptor() {
156: return descriptor;
157: }
158:
159: /**
160: * Sets associated Descriptor of ModelMBeanConstructorInfo. If the new
161: * Descriptor is null, then the associated Descriptor reverts to a default
162: * descriptor. The Descriptor is validated before it is assigned. If the
163: * new Descriptor is invalid, then an IllegalArgumentException is thrown.
164: *
165: * @param inDescriptor replaces the Descriptor associated with
166: * the ModelMBeanConstructor.
167: *
168: * @throws IllegalArgumentException If the argument passsed in is illegal
169: * then this Exception will be thrown
170: */
171: public void setDescriptor(Descriptor inDescriptor) {
172: this .descriptor = inDescriptor;
173: }
174:
175: /**
176: * Returns a human readable version of the ModelMBeanConstructorInfo instance
177: */
178: public String toString() {
179: if (descriptor != null)
180: return (super .toString() + "\n Descriptor = " + descriptor
181: .toString());
182: else
183: return (super .toString() + "\n Descriptor = null");
184: }
185:
186: //--------------------------- Private methods ---------------------------//
187:
188: private void readObject(ObjectInputStream objectinputstream)
189: throws IOException, ClassNotFoundException {
190: ObjectInputStream.GetField getfield = objectinputstream
191: .readFields();
192:
193: try {
194: descriptor = (DescriptorSupport) getfield.get(
195: "consDescriptor", null);
196: } catch (Exception exception) {
197: }
198: }
199:
200: private void writeObject(ObjectOutputStream objectoutputstream)
201: throws IOException {
202: ObjectOutputStream.PutField putfield = objectoutputstream
203: .putFields();
204: putfield.put("consDescriptor", descriptor);
205: putfield.put("currClass", "ModelMBeanConstructorInfo");
206:
207: objectoutputstream.writeFields();
208: }
209: }
|