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.Method;
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.MBeanOperationInfo;
037: import javax.management.MBeanParameterInfo;
038:
039: /**
040: * The ModelMBeanOperationInfo object describes a management operation
041: * of the ModelMBean. It is a subclass of MBeanOperationInfo with the
042: * addition of an associated Descriptor and an implementation of the
043: * DescriptorAccess interface.
044: * <P>
045: * <P>
046: * <PRE>
047: * The fields in the descriptor are defined, but not limited to, the following:
048: * name : operation name
049: * descriptorType : must be "operation"
050: * class : class where method is defined (fully qualified)
051: * role : getter, setter, operation, constructor
052: * targetObject : object on which to execute this method
053: * targetType : type of object reference for targetObject:
054: *
055: * ObjectReference|EJBHandle|IOR|RMIReference
056: * lastReturnedValue : cached value for operation
057: * currencyTimeLimit : how long cached value is valid
058: * lastReturnedTimeStamp : when cached value was set
059: * visibility : 1-4 where 1: always visible 4: rarely visible
060: * presentationString : xml formatted string to describe how to present operation
061: * </PRE>
062: * <P> The default descriptor will have name, descriptorType, and role fields set.
063: */
064:
065: public class ModelMBeanOperationInfo extends MBeanOperationInfo
066: implements DescriptorAccess {
067: Descriptor descriptor = new DescriptorSupport();
068:
069: private static final long serialVersionUID = 0x7e1dce2a56f1e767L;
070:
071: private static final ObjectStreamField[] serialPersistentFields = {
072: new ObjectStreamField("operationDescriptor",
073: DescriptorSupport.class),
074: new ObjectStreamField("currClass", java.lang.String.class) };
075:
076: /**
077: * Constructs a new ModelMBeanOperationInfo object with default descriptor
078: *
079: * @param method The java.lang.reflect.Method object describing the MBean operation.
080: *
081: * @param description A human readable description of the operation.
082: */
083: public ModelMBeanOperationInfo(String description, Method method) {
084: super (description, method);
085: }
086:
087: /**
088: * Constructs a new ModelMBeanOperationInfo object
089: * @param method The java.lang.reflect.Method object describing the MBean operation.
090: * @param description A human readable description of the operation.
091: * @param descriptor Descriptor containing the appropriate metadata for this
092: * instance of the MBeanNotificationInfo.If it is null or invalid then a default
093: * desriptor will be created.
094: */
095: public ModelMBeanOperationInfo(String description, Method method,
096: Descriptor descriptor) {
097: super (description, method);
098: this .descriptor = descriptor;
099: }
100:
101: /**
102: * Constructs a ModelMBeanOperationInfo object with a default descriptor.
103: *
104: * @param name The method name
105: *
106: * @param description A human readable description of the operation.
107: *
108: * @param signature The array of MBeanParameterInfo contains the parameters
109: * or arguments of the method
110: *
111: * @param type The return type of the method
112: *
113: * @param impact The impact of the method, will be anyone of the following
114: * INFO, ACTION, ACTION_INFO, UNKNOWN.
115: */
116: public ModelMBeanOperationInfo(String name, String description,
117: MBeanParameterInfo[] signature, String type, int impact) {
118: super (name, description, signature, type, impact);
119: }
120:
121: /**
122: * Constructs a ModelMBeanOperationInfo object escriptorth with
123: * the specified Descriptor.
124: *
125: * @param name The method name
126: *
127: * @param description A human readable description of the operation.
128: *
129: * @param signature The array of MBeanParameterInfo contains the parameters
130: * or arguments of the method
131: *
132: * @param type The return type of the method
133: *
134: * @param impact The impact of the method, will be anyone of the following
135: * INFO, ACTION, ACTION_INFO, UNKNOWN.
136: *
137: * @param descriptor Descriptor containing the appropriate metadata for
138: * this instance of the MBeanOperationInfo. If it is null or
139: * invalid then a default desriptor will be created.
140: */
141: public ModelMBeanOperationInfo(String name, String description,
142: MBeanParameterInfo[] signature, String type, int impact,
143: Descriptor descriptor) {
144: super (name, description, signature, type, impact);
145: this .descriptor = descriptor;
146: }
147:
148: /**
149: * Creates a ModelMBeanOperationInfo with the specified
150: * ModelMBeanOperationInfo object.
151: *
152: * @param inInfo ModelMBeanOperationInfo object
153: */
154: public ModelMBeanOperationInfo(ModelMBeanOperationInfo inInfo) {
155: super (inInfo.getName(), inInfo.getDescription(), inInfo
156: .getSignature(), inInfo.getReturnType(), inInfo
157: .getImpact());
158: if (inInfo.getDescriptor() != null)
159: this .descriptor = (Descriptor) inInfo.getDescriptor()
160: .clone();
161: }
162:
163: /**
164: * Creates a duplicate object of ModelMBeanOperationInfo
165: *
166: * @return Create and return a duplicate object of ModelMBeanOperationInfo
167: */
168: public Object clone() {
169: Descriptor clonedDescr = null;
170:
171: if (descriptor != null)
172: clonedDescr = (Descriptor) descriptor.clone();
173:
174: return new ModelMBeanOperationInfo(getName(), getDescription(),
175: getSignature(), getReturnType(), getImpact(),
176: clonedDescr);
177: }
178:
179: /**
180: * Gets the corresponding Descriptor of this ModelMBeanNotificationInfo
181: *
182: * @return This returns the Descriptor associated with
183: * this ModelMBeanNotificationInfo
184: */
185: public Descriptor getDescriptor() {
186: return descriptor;
187: }
188:
189: /**
190: * Sets the specified Descriptor to this ModelMBeanNotificationInfo.If the
191: * value is null then default Descriptor will be taken. The Descriptor is
192: * validated before it is assigned. If the new Descriptor is invalid, then
193: * an IllegalArgumentException is thrown.
194: *
195: * @param inDescriptor This replaces the Descriptor associated with the
196: * ModelMBeanNotification interface
197: *
198: * @throws IllegalArgumentException If the new Descriptor is invalid,
199: * then it will be thrown.
200: */
201: public void setDescriptor(Descriptor inDescriptor) {
202: this .descriptor = inDescriptor;
203: }
204:
205: /**
206: * Returns a human readable version of the ModelMBeanOperationInfo instance
207: *
208: * @return This returns human readable version of the
209: * ModelMBeanOperationInfo instance
210: */
211: public String toString() {
212: if (descriptor != null)
213: return (super .toString() + "\n Descriptor = " + descriptor
214: .toString());
215: else
216: return (super .toString() + "\n Descriptor = null");
217: }
218:
219: //--------------------------- Private methods ---------------------------//
220:
221: private void readObject(ObjectInputStream objectinputstream)
222: throws IOException, ClassNotFoundException {
223: ObjectInputStream.GetField getfield = objectinputstream
224: .readFields();
225:
226: try {
227: descriptor = (DescriptorSupport) getfield.get(
228: "operationDescriptor", null);
229: } catch (Exception exception) {
230: //throw new IOException(malformedobjectnameexception.toString());
231: }
232: }
233:
234: private void writeObject(ObjectOutputStream objectoutputstream)
235: throws IOException {
236: ObjectOutputStream.PutField putfield = objectoutputstream
237: .putFields();
238: putfield.put("operationDescriptor", descriptor);
239: putfield.put("currClass", "ModelMBeanOperationInfo");
240:
241: objectoutputstream.writeFields();
242: }
243: }
|