001: /* JFox, the OpenSource J2EE Application Server
002: *
003: * Copyright (C) 2002 huihoo.org
004: * Distributable under GNU LGPL license
005: * See the GNU Lesser General Public License for more details.
006: */
007:
008: package javax.management;
009:
010: import java.io.Serializable;
011: import java.lang.reflect.Constructor;
012:
013: /**
014: * Describes a constructor exposed by an MBean.
015: *
016: * @author <a href="mailto:young_yy@hotmail.org">Young Yang</a>
017: */
018:
019: public class MBeanConstructorInfo extends MBeanFeatureInfo implements
020: Serializable, Cloneable {
021:
022: /**
023: * The method.
024: */
025: private transient java.lang.reflect.Constructor constructor = null;
026:
027: /**
028: * The signature of the method, that is, the class names of the arguments.
029: */
030: private MBeanParameterInfo[] signature = null;
031:
032: /**
033: * Constructs an <CODE>MBeanConstructorInfo</CODE> object.
034: *
035: * @param description A human readable description of the operation.
036: * @param constructor The <CODE>java.lang.reflect.Constructor</CODE> object describing the MBean constructor.
037: */
038: public MBeanConstructorInfo(String description,
039: Constructor constructor) {
040: super (constructor.getName(), description);
041: this .constructor = constructor;
042: findMethodParameterTypes();
043: }
044:
045: /**
046: * Constructs an <CODE>MBeanConstructorInfo</CODE> object.
047: *
048: * @param name The name of the constructor.
049: * @param description A human readable description of the constructor.
050: * @param signature <CODE>MBeanParameterInfo</CODE> objects describing the parameters(arguments) of the constructor.
051: */
052: public MBeanConstructorInfo(String name, String description,
053: MBeanParameterInfo[] signature) {
054:
055: super (name, description);
056: this .signature = signature;
057: }
058:
059: /**
060: * Package-private duplicate constructor.
061: * <P>
062: * This must isolate the new object from any changes to the old object.
063: */
064:
065: MBeanConstructorInfo(MBeanConstructorInfo old) {
066: super (old.name, old.description);
067: signature = old.signature;
068: }
069:
070: /**
071: * Creates and returns a copy of this object.
072: */
073: public Object clone() {
074: return (new MBeanConstructorInfo(this ));
075: }
076:
077: /**
078: * Returns the signature of the method, that is, information on the operation's arguments.
079: */
080: public MBeanParameterInfo[] getSignature() {
081: if (signature != null) {
082: int len = signature.length;
083: MBeanParameterInfo[] res = new MBeanParameterInfo[len];
084: for (int i = 0; i < len; i++) {
085: res[i] = (MBeanParameterInfo) signature[i].clone();
086: }
087: return res;
088: } else {
089: return new MBeanParameterInfo[0];
090: }
091: }
092:
093: /**
094: * Sets the action signature and parameters.
095: * <P>
096: * All primitive type parameters (int, ..etc.) are converted to native type
097: * parameters (java.lang.Integer, ..etc.).
098: */
099: private void findMethodParameterTypes() {
100: String[] signatures = constructSignatures(constructor
101: .getParameterTypes());
102: if (signatures != null) {
103: int len = signatures.length;
104: signature = new MBeanParameterInfo[len];
105: for (int i = 0; i < len; i++) {
106: signature[i] = new MBeanParameterInfo("",
107: signatures[i], "");
108: }
109: }
110: }
111:
112: /**
113: * Converts the array of classes to an array of class signatures.
114: */
115: private String[] constructSignatures(Class[] classes) {
116: String signers[] = new String[classes.length];
117: for (int i = 0; i < classes.length; i++) {
118: signers[i] = classes[i].getName();
119: }
120: return signers;
121: }
122:
123: }
|