feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
1401
jdkSrc/jdk8/javax/management/modelmbean/DescriptorSupport.java
Normal file
1401
jdkSrc/jdk8/javax/management/modelmbean/DescriptorSupport.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,199 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @author IBM Corp.
|
||||
*
|
||||
* Copyright IBM Corp. 1999-2000. All rights reserved.
|
||||
*/
|
||||
|
||||
package javax.management.modelmbean;
|
||||
|
||||
import com.sun.jmx.mbeanserver.GetPropertyAction;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamField;
|
||||
import java.security.AccessController;
|
||||
|
||||
/**
|
||||
* Exception thrown when an invalid target object type is specified.
|
||||
*
|
||||
*
|
||||
* <p>The <b>serialVersionUID</b> of this class is <code>1190536278266811217L</code>.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
@SuppressWarnings("serial") // serialVersionUID not constant
|
||||
public class InvalidTargetObjectTypeException extends Exception
|
||||
{
|
||||
|
||||
// Serialization compatibility stuff:
|
||||
// Two serial forms are supported in this class. The selected form depends
|
||||
// on system property "jmx.serial.form":
|
||||
// - "1.0" for JMX 1.0
|
||||
// - any other value for JMX 1.1 and higher
|
||||
//
|
||||
// Serial version for old serial form
|
||||
private static final long oldSerialVersionUID = 3711724570458346634L;
|
||||
//
|
||||
// Serial version for new serial form
|
||||
private static final long newSerialVersionUID = 1190536278266811217L;
|
||||
//
|
||||
// Serializable fields in old serial form
|
||||
private static final ObjectStreamField[] oldSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("msgStr", String.class),
|
||||
new ObjectStreamField("relatedExcept", Exception.class)
|
||||
};
|
||||
//
|
||||
// Serializable fields in new serial form
|
||||
private static final ObjectStreamField[] newSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("exception", Exception.class)
|
||||
};
|
||||
//
|
||||
// Actual serial version and serial form
|
||||
private static final long serialVersionUID;
|
||||
/**
|
||||
* @serialField exception Exception Encapsulated {@link Exception}
|
||||
*/
|
||||
private static final ObjectStreamField[] serialPersistentFields;
|
||||
private static boolean compat = false;
|
||||
static {
|
||||
try {
|
||||
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
|
||||
String form = AccessController.doPrivileged(act);
|
||||
compat = (form != null && form.equals("1.0"));
|
||||
} catch (Exception e) {
|
||||
// OK: No compat with 1.0
|
||||
}
|
||||
if (compat) {
|
||||
serialPersistentFields = oldSerialPersistentFields;
|
||||
serialVersionUID = oldSerialVersionUID;
|
||||
} else {
|
||||
serialPersistentFields = newSerialPersistentFields;
|
||||
serialVersionUID = newSerialVersionUID;
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Serialization compatibility stuff
|
||||
|
||||
/**
|
||||
* @serial Encapsulated {@link Exception}
|
||||
*/
|
||||
Exception exception;
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public InvalidTargetObjectTypeException ()
|
||||
{
|
||||
super("InvalidTargetObjectTypeException: ");
|
||||
exception = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor from a string.
|
||||
*
|
||||
* @param s String value that will be incorporated in the message for
|
||||
* this exception.
|
||||
*/
|
||||
|
||||
public InvalidTargetObjectTypeException (String s)
|
||||
{
|
||||
super("InvalidTargetObjectTypeException: " + s);
|
||||
exception = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor taking an exception and a string.
|
||||
*
|
||||
* @param e Exception that we may have caught to reissue as an
|
||||
* InvalidTargetObjectTypeException. The message will be used, and we may want to
|
||||
* consider overriding the printStackTrace() methods to get data
|
||||
* pointing back to original throw stack.
|
||||
* @param s String value that will be incorporated in message for
|
||||
* this exception.
|
||||
*/
|
||||
|
||||
public InvalidTargetObjectTypeException (Exception e, String s)
|
||||
{
|
||||
super("InvalidTargetObjectTypeException: " +
|
||||
s +
|
||||
((e != null)?("\n\t triggered by:" + e.toString()):""));
|
||||
exception = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes an {@link InvalidTargetObjectTypeException} from an {@link ObjectInputStream}.
|
||||
*/
|
||||
private void readObject(ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException {
|
||||
if (compat)
|
||||
{
|
||||
// Read an object serialized in the old serial form
|
||||
//
|
||||
ObjectInputStream.GetField fields = in.readFields();
|
||||
exception = (Exception) fields.get("relatedExcept", null);
|
||||
if (fields.defaulted("relatedExcept"))
|
||||
{
|
||||
throw new NullPointerException("relatedExcept");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Read an object serialized in the new serial form
|
||||
//
|
||||
in.defaultReadObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serializes an {@link InvalidTargetObjectTypeException} to an {@link ObjectOutputStream}.
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream out)
|
||||
throws IOException {
|
||||
if (compat)
|
||||
{
|
||||
// Serializes this instance in the old serial form
|
||||
//
|
||||
ObjectOutputStream.PutField fields = out.putFields();
|
||||
fields.put("relatedExcept", exception);
|
||||
fields.put("msgStr", ((exception != null)?exception.getMessage():""));
|
||||
out.writeFields();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Serializes this instance in the new serial form
|
||||
//
|
||||
out.defaultWriteObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
123
jdkSrc/jdk8/javax/management/modelmbean/ModelMBean.java
Normal file
123
jdkSrc/jdk8/javax/management/modelmbean/ModelMBean.java
Normal file
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @author IBM Corp.
|
||||
*
|
||||
* Copyright IBM Corp. 1999-2000. All rights reserved.
|
||||
*/
|
||||
|
||||
package javax.management.modelmbean;
|
||||
|
||||
import javax.management.DynamicMBean;
|
||||
import javax.management.InstanceNotFoundException;
|
||||
import javax.management.MBeanException;
|
||||
import javax.management.PersistentMBean;
|
||||
import javax.management.RuntimeOperationsException;
|
||||
|
||||
/**
|
||||
* This interface must be implemented by the ModelMBeans. An implementation of this interface
|
||||
* must be shipped with every JMX Agent.
|
||||
* <P>
|
||||
* Java resources wishing to be manageable instantiate the ModelMBean using the MBeanServer's
|
||||
* createMBean method. The resource then sets the ModelMBeanInfo (with Descriptors) for the ModelMBean
|
||||
* instance. The attributes and operations exposed via the ModelMBeanInfo for the ModelMBean are accessible
|
||||
* from MBeans, connectors/adaptors like other MBeans. Through the ModelMBeanInfo Descriptors, values and methods in
|
||||
* the managed application can be defined and mapped to attributes and operations of the ModelMBean.
|
||||
* This mapping can be defined during development in an XML formatted file or dynamically and
|
||||
* programmatically at runtime.
|
||||
* <P>
|
||||
* Every ModelMBean which is instantiated in the MBeanServer becomes manageable:
|
||||
* its attributes and operations
|
||||
* become remotely accessible through the connectors/adaptors connected to that MBeanServer.
|
||||
* A Java object cannot be registered in the MBeanServer unless it is a JMX compliant MBean.
|
||||
* By instantiating a ModelMBean, resources are guaranteed that the MBean is valid.
|
||||
* <P>
|
||||
* MBeanException and RuntimeOperationsException must be thrown on every public method. This allows
|
||||
* for wrapping exceptions from distributed communications (RMI, EJB, etc.). These exceptions do
|
||||
* not have to be thrown by the implementation except in the scenarios described in the specification
|
||||
* and javadoc.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
|
||||
public interface ModelMBean extends
|
||||
DynamicMBean,
|
||||
PersistentMBean,
|
||||
ModelMBeanNotificationBroadcaster
|
||||
{
|
||||
|
||||
/**
|
||||
* Initializes a ModelMBean object using ModelMBeanInfo passed in.
|
||||
* This method makes it possible to set a customized ModelMBeanInfo on
|
||||
* the ModelMBean as long as it is not registered with the MBeanServer.
|
||||
* <br>
|
||||
* Once the ModelMBean's ModelMBeanInfo (with Descriptors) are
|
||||
* customized and set on the ModelMBean, the ModelMBean can be
|
||||
* registered with the MBeanServer.
|
||||
* <P>
|
||||
* If the ModelMBean is currently registered, this method throws
|
||||
* a {@link javax.management.RuntimeOperationsException} wrapping an
|
||||
* {@link IllegalStateException}
|
||||
*
|
||||
* @param inModelMBeanInfo The ModelMBeanInfo object to be used
|
||||
* by the ModelMBean.
|
||||
*
|
||||
* @exception MBeanException Wraps a distributed communication
|
||||
* Exception.
|
||||
* @exception RuntimeOperationsException
|
||||
* <ul><li>Wraps an {@link IllegalArgumentException} if
|
||||
* the MBeanInfo passed in parameter is null.</li>
|
||||
* <li>Wraps an {@link IllegalStateException} if the ModelMBean
|
||||
* is currently registered in the MBeanServer.</li>
|
||||
* </ul>
|
||||
*
|
||||
**/
|
||||
public void setModelMBeanInfo(ModelMBeanInfo inModelMBeanInfo)
|
||||
throws MBeanException, RuntimeOperationsException;
|
||||
|
||||
/**
|
||||
* Sets the instance handle of the object against which to
|
||||
* execute all methods in this ModelMBean management interface
|
||||
* (MBeanInfo and Descriptors).
|
||||
*
|
||||
* @param mr Object that is the managed resource
|
||||
* @param mr_type The type of reference for the managed resource. Can be: ObjectReference,
|
||||
* Handle, IOR, EJBHandle, RMIReference.
|
||||
* If the MBeanServer cannot process the mr_type passed in, an InvalidTargetTypeException
|
||||
* will be thrown.
|
||||
*
|
||||
*
|
||||
* @exception MBeanException The initializer of the object has thrown an exception.
|
||||
* @exception RuntimeOperationsException Wraps an IllegalArgumentException:
|
||||
* The managed resource type passed in parameter is null.
|
||||
* @exception InstanceNotFoundException The managed resource object could not be found
|
||||
* @exception InvalidTargetObjectTypeException The managed resource type cannot be processed by the
|
||||
* ModelMBean or JMX Agent.
|
||||
*/
|
||||
public void setManagedResource(Object mr, String mr_type)
|
||||
throws MBeanException, RuntimeOperationsException,
|
||||
InstanceNotFoundException, InvalidTargetObjectTypeException ;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,530 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @author IBM Corp.
|
||||
*
|
||||
* Copyright IBM Corp. 1999-2000. All rights reserved.
|
||||
*/
|
||||
|
||||
package javax.management.modelmbean;
|
||||
|
||||
import static com.sun.jmx.defaults.JmxProperties.MODELMBEAN_LOGGER;
|
||||
import com.sun.jmx.mbeanserver.GetPropertyAction;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamField;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.AccessController;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.management.Descriptor;
|
||||
import javax.management.DescriptorKey;
|
||||
import javax.management.DescriptorAccess;
|
||||
import javax.management.MBeanAttributeInfo;
|
||||
import javax.management.RuntimeOperationsException;
|
||||
|
||||
/**
|
||||
* <p>The ModelMBeanAttributeInfo object describes an attribute of the ModelMBean.
|
||||
* It is a subclass of MBeanAttributeInfo with the addition of an associated Descriptor
|
||||
* and an implementation of the DescriptorAccess interface.</p>
|
||||
*
|
||||
* <P id="descriptor">
|
||||
* The fields in the descriptor are defined, but not limited to, the following.
|
||||
* Note that when the Type in this table is Number, a String that is the decimal
|
||||
* representation of a Long can also be used.</P>
|
||||
*
|
||||
* <table border="1" cellpadding="5" summary="ModelMBeanAttributeInfo Fields">
|
||||
* <tr><th>Name</th><th>Type</th><th>Meaning</th></tr>
|
||||
* <tr><td>name</td><td>String</td>
|
||||
* <td>Attribute name.</td></tr>
|
||||
* <tr><td>descriptorType</td><td>String</td>
|
||||
* <td>Must be "attribute".</td></tr>
|
||||
* <tr id="value-field"><td>value</td><td>Object</td>
|
||||
* <td>Current (cached) value for attribute.</td></tr>
|
||||
* <tr><td>default</td><td>Object</td>
|
||||
* <td>Default value for attribute.</td></tr>
|
||||
* <tr><td>displayName</td><td>String</td>
|
||||
* <td>Name of attribute to be used in displays.</td></tr>
|
||||
* <tr><td>getMethod</td><td>String</td>
|
||||
* <td>Name of operation descriptor for get method.</td></tr>
|
||||
* <tr><td>setMethod</td><td>String</td>
|
||||
* <td>Name of operation descriptor for set method.</td></tr>
|
||||
* <tr><td>protocolMap</td><td>Descriptor</td>
|
||||
* <td>See the section "Protocol Map Support" in the JMX specification
|
||||
* document. Mappings must be appropriate for the attribute and entries
|
||||
* can be updated or augmented at runtime.</td></tr>
|
||||
* <tr><td>persistPolicy</td><td>String</td>
|
||||
* <td>One of: OnUpdate|OnTimer|NoMoreOftenThan|OnUnregister|Always|Never.
|
||||
* See the section "MBean Descriptor Fields" in the JMX specification
|
||||
* document.</td></tr>
|
||||
* <tr><td>persistPeriod</td><td>Number</td>
|
||||
* <td>Frequency of persist cycle in seconds. Used when persistPolicy is
|
||||
* "OnTimer" or "NoMoreOftenThan".</td></tr>
|
||||
* <tr><td>currencyTimeLimit</td><td>Number</td>
|
||||
* <td>How long <a href="#value=field">value</a> is valid: <0 never,
|
||||
* =0 always, >0 seconds.</td></tr>
|
||||
* <tr><td>lastUpdatedTimeStamp</td><td>Number</td>
|
||||
* <td>When <a href="#value-field">value</a> was set.</td></tr>
|
||||
* <tr><td>visibility</td><td>Number</td>
|
||||
* <td>1-4 where 1: always visible, 4: rarely visible.</td></tr>
|
||||
* <tr><td>presentationString</td><td>String</td>
|
||||
* <td>XML formatted string to allow presentation of data.</td></tr>
|
||||
* </table>
|
||||
*
|
||||
* <p>The default descriptor contains the name, descriptorType and displayName
|
||||
* fields. The default value of the name and displayName fields is the name of
|
||||
* the attribute.</p>
|
||||
*
|
||||
* <p><b>Note:</b> because of inconsistencies in previous versions of
|
||||
* this specification, it is recommended not to use negative or zero
|
||||
* values for <code>currencyTimeLimit</code>. To indicate that a
|
||||
* cached value is never valid, omit the
|
||||
* <code>currencyTimeLimit</code> field. To indicate that it is
|
||||
* always valid, use a very large number for this field.</p>
|
||||
*
|
||||
* <p>The <b>serialVersionUID</b> of this class is <code>6181543027787327345L</code>.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
|
||||
@SuppressWarnings("serial") // serialVersionUID is not constant
|
||||
public class ModelMBeanAttributeInfo
|
||||
extends MBeanAttributeInfo
|
||||
implements DescriptorAccess {
|
||||
|
||||
// Serialization compatibility stuff:
|
||||
// Two serial forms are supported in this class. The selected form depends
|
||||
// on system property "jmx.serial.form":
|
||||
// - "1.0" for JMX 1.0
|
||||
// - any other value for JMX 1.1 and higher
|
||||
//
|
||||
// Serial version for old serial form
|
||||
private static final long oldSerialVersionUID = 7098036920755973145L;
|
||||
//
|
||||
// Serial version for new serial form
|
||||
private static final long newSerialVersionUID = 6181543027787327345L;
|
||||
//
|
||||
// Serializable fields in old serial form
|
||||
private static final ObjectStreamField[] oldSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("attrDescriptor", Descriptor.class),
|
||||
new ObjectStreamField("currClass", String.class)
|
||||
};
|
||||
//
|
||||
// Serializable fields in new serial form
|
||||
private static final ObjectStreamField[] newSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("attrDescriptor", Descriptor.class)
|
||||
};
|
||||
//
|
||||
// Actual serial version and serial form
|
||||
private static final long serialVersionUID;
|
||||
/**
|
||||
* @serialField attrDescriptor Descriptor The {@link Descriptor}
|
||||
* containing the metadata corresponding to this attribute
|
||||
*/
|
||||
private static final ObjectStreamField[] serialPersistentFields;
|
||||
private static boolean compat = false;
|
||||
static {
|
||||
try {
|
||||
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
|
||||
String form = AccessController.doPrivileged(act);
|
||||
compat = (form != null && form.equals("1.0"));
|
||||
} catch (Exception e) {
|
||||
// OK: No compat with 1.0
|
||||
}
|
||||
if (compat) {
|
||||
serialPersistentFields = oldSerialPersistentFields;
|
||||
serialVersionUID = oldSerialVersionUID;
|
||||
} else {
|
||||
serialPersistentFields = newSerialPersistentFields;
|
||||
serialVersionUID = newSerialVersionUID;
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Serialization compatibility stuff
|
||||
|
||||
/**
|
||||
* @serial The {@link Descriptor} containing the metadata corresponding to
|
||||
* this attribute
|
||||
*/
|
||||
private Descriptor attrDescriptor = validDescriptor(null);
|
||||
|
||||
private final static String currClass = "ModelMBeanAttributeInfo";
|
||||
|
||||
/**
|
||||
* Constructs a ModelMBeanAttributeInfo object with a default
|
||||
* descriptor. The {@link Descriptor} of the constructed
|
||||
* object will include fields contributed by any annotations
|
||||
* on the {@code Method} objects that contain the {@link
|
||||
* DescriptorKey} meta-annotation.
|
||||
*
|
||||
* @param name The name of the attribute.
|
||||
* @param description A human readable description of the attribute. Optional.
|
||||
* @param getter The method used for reading the attribute value.
|
||||
* May be null if the property is write-only.
|
||||
* @param setter The method used for writing the attribute value.
|
||||
* May be null if the attribute is read-only.
|
||||
* @exception javax.management.IntrospectionException There is a consistency
|
||||
* problem in the definition of this attribute.
|
||||
*
|
||||
*/
|
||||
|
||||
public ModelMBeanAttributeInfo(String name,
|
||||
String description,
|
||||
Method getter,
|
||||
Method setter)
|
||||
throws javax.management.IntrospectionException {
|
||||
super(name, description, getter, setter);
|
||||
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanAttributeInfo.class.getName(),
|
||||
"ModelMBeanAttributeInfo(" +
|
||||
"String,String,Method,Method)",
|
||||
"Entry", name);
|
||||
}
|
||||
|
||||
attrDescriptor = validDescriptor(null);
|
||||
// put getter and setter methods in operations list
|
||||
// create default descriptor
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a ModelMBeanAttributeInfo object. The {@link
|
||||
* Descriptor} of the constructed object will include fields
|
||||
* contributed by any annotations on the {@code Method}
|
||||
* objects that contain the {@link DescriptorKey}
|
||||
* meta-annotation.
|
||||
*
|
||||
* @param name The name of the attribute.
|
||||
* @param description A human readable description of the attribute. Optional.
|
||||
* @param getter The method used for reading the attribute value.
|
||||
* May be null if the property is write-only.
|
||||
* @param setter The method used for writing the attribute value.
|
||||
* May be null if the attribute is read-only.
|
||||
* @param descriptor An instance of Descriptor containing the
|
||||
* appropriate metadata for this instance of the Attribute. If
|
||||
* it is null, then a default descriptor will be created. If
|
||||
* the descriptor does not contain the field "displayName" this field is added
|
||||
* in the descriptor with its default value.
|
||||
* @exception javax.management.IntrospectionException There is a consistency
|
||||
* problem in the definition of this attribute.
|
||||
* @exception RuntimeOperationsException Wraps an
|
||||
* IllegalArgumentException. The descriptor is invalid, or descriptor
|
||||
* field "name" is not equal to name parameter, or descriptor field
|
||||
* "descriptorType" is not equal to "attribute".
|
||||
*
|
||||
*/
|
||||
|
||||
public ModelMBeanAttributeInfo(String name,
|
||||
String description,
|
||||
Method getter,
|
||||
Method setter,
|
||||
Descriptor descriptor)
|
||||
throws javax.management.IntrospectionException {
|
||||
|
||||
super(name, description, getter, setter);
|
||||
// put getter and setter methods in operations list
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanAttributeInfo.class.getName(),
|
||||
"ModelMBeanAttributeInfo(" +
|
||||
"String,String,Method,Method,Descriptor)",
|
||||
"Entry", name);
|
||||
}
|
||||
attrDescriptor = validDescriptor(descriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a ModelMBeanAttributeInfo object with a default descriptor.
|
||||
*
|
||||
* @param name The name of the attribute
|
||||
* @param type The type or class name of the attribute
|
||||
* @param description A human readable description of the attribute.
|
||||
* @param isReadable True if the attribute has a getter method, false otherwise.
|
||||
* @param isWritable True if the attribute has a setter method, false otherwise.
|
||||
* @param isIs True if the attribute has an "is" getter, false otherwise.
|
||||
*
|
||||
*/
|
||||
public ModelMBeanAttributeInfo(String name,
|
||||
String type,
|
||||
String description,
|
||||
boolean isReadable,
|
||||
boolean isWritable,
|
||||
boolean isIs)
|
||||
{
|
||||
|
||||
super(name, type, description, isReadable, isWritable, isIs);
|
||||
// create default descriptor
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanAttributeInfo.class.getName(),
|
||||
"ModelMBeanAttributeInfo(" +
|
||||
"String,String,String,boolean,boolean,boolean)",
|
||||
"Entry", name);
|
||||
}
|
||||
attrDescriptor = validDescriptor(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a ModelMBeanAttributeInfo object.
|
||||
*
|
||||
* @param name The name of the attribute
|
||||
* @param type The type or class name of the attribute
|
||||
* @param description A human readable description of the attribute.
|
||||
* @param isReadable True if the attribute has a getter method, false otherwise.
|
||||
* @param isWritable True if the attribute has a setter method, false otherwise.
|
||||
* @param isIs True if the attribute has an "is" getter, false otherwise.
|
||||
* @param descriptor An instance of Descriptor containing the
|
||||
* appropriate metadata for this instance of the Attribute. If
|
||||
* it is null then a default descriptor will be created. If
|
||||
* the descriptor does not contain the field "displayName" this field
|
||||
* is added in the descriptor with its default value.
|
||||
* @exception RuntimeOperationsException Wraps an
|
||||
* IllegalArgumentException. The descriptor is invalid, or descriptor
|
||||
* field "name" is not equal to name parameter, or descriptor field
|
||||
* "descriptorType" is not equal to "attribute".
|
||||
*
|
||||
*/
|
||||
public ModelMBeanAttributeInfo(String name,
|
||||
String type,
|
||||
String description,
|
||||
boolean isReadable,
|
||||
boolean isWritable,
|
||||
boolean isIs,
|
||||
Descriptor descriptor)
|
||||
{
|
||||
super(name, type, description, isReadable, isWritable, isIs);
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanAttributeInfo.class.getName(),
|
||||
"ModelMBeanAttributeInfo(String,String,String," +
|
||||
"boolean,boolean,boolean,Descriptor)",
|
||||
"Entry", name);
|
||||
}
|
||||
attrDescriptor = validDescriptor(descriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ModelMBeanAttributeInfo object from this
|
||||
* ModelMBeanAttributeInfo Object. A default descriptor will
|
||||
* be created.
|
||||
*
|
||||
* @param inInfo the ModelMBeanAttributeInfo to be duplicated
|
||||
*/
|
||||
|
||||
public ModelMBeanAttributeInfo(ModelMBeanAttributeInfo inInfo)
|
||||
{
|
||||
super(inInfo.getName(),
|
||||
inInfo.getType(),
|
||||
inInfo.getDescription(),
|
||||
inInfo.isReadable(),
|
||||
inInfo.isWritable(),
|
||||
inInfo.isIs());
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanAttributeInfo.class.getName(),
|
||||
"ModelMBeanAttributeInfo(ModelMBeanAttributeInfo)",
|
||||
"Entry");
|
||||
}
|
||||
Descriptor newDesc = inInfo.getDescriptor();
|
||||
attrDescriptor = validDescriptor(newDesc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a copy of the associated Descriptor for the
|
||||
* ModelMBeanAttributeInfo.
|
||||
*
|
||||
* @return Descriptor associated with the
|
||||
* ModelMBeanAttributeInfo object.
|
||||
*
|
||||
* @see #setDescriptor
|
||||
*/
|
||||
|
||||
public Descriptor getDescriptor() {
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanAttributeInfo.class.getName(),
|
||||
"getDescriptor()", "Entry");
|
||||
}
|
||||
if (attrDescriptor == null) {
|
||||
attrDescriptor = validDescriptor(null);
|
||||
}
|
||||
return((Descriptor)attrDescriptor.clone());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets associated Descriptor (full replace) for the
|
||||
* ModelMBeanAttributeDescriptor. If the new Descriptor is
|
||||
* null, then the associated Descriptor reverts to a default
|
||||
* descriptor. The Descriptor is validated before it is
|
||||
* assigned. If the new Descriptor is invalid, then a
|
||||
* RuntimeOperationsException wrapping an
|
||||
* IllegalArgumentException is thrown.
|
||||
* @param inDescriptor replaces the Descriptor associated with the
|
||||
* ModelMBeanAttributeInfo
|
||||
*
|
||||
* @exception RuntimeOperationsException Wraps an
|
||||
* IllegalArgumentException for an invalid Descriptor
|
||||
*
|
||||
* @see #getDescriptor
|
||||
*/
|
||||
public void setDescriptor(Descriptor inDescriptor) {
|
||||
attrDescriptor = validDescriptor(inDescriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a new ModelMBeanAttributeInfo which is a duplicate of this ModelMBeanAttributeInfo.
|
||||
*
|
||||
* @exception RuntimeOperationsException for illegal value for
|
||||
* field Names or field Values. If the descriptor construction
|
||||
* fails for any reason, this exception will be thrown.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Object clone()
|
||||
{
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanAttributeInfo.class.getName(),
|
||||
"clone()", "Entry");
|
||||
}
|
||||
return(new ModelMBeanAttributeInfo(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a human-readable version of the
|
||||
* ModelMBeanAttributeInfo instance.
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return
|
||||
"ModelMBeanAttributeInfo: " + this.getName() +
|
||||
" ; Description: " + this.getDescription() +
|
||||
" ; Types: " + this.getType() +
|
||||
" ; isReadable: " + this.isReadable() +
|
||||
" ; isWritable: " + this.isWritable() +
|
||||
" ; Descriptor: " + this.getDescriptor();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clones the passed in Descriptor, sets default values, and checks for validity.
|
||||
* If the Descriptor is invalid (for instance by having the wrong "name"),
|
||||
* this indicates programming error and a RuntimeOperationsException will be thrown.
|
||||
*
|
||||
* The following fields will be defaulted if they are not already set:
|
||||
* displayName=this.getName(),name=this.getName(),descriptorType = "attribute"
|
||||
*
|
||||
* @param in Descriptor to be checked, or null which is equivalent to
|
||||
* an empty Descriptor.
|
||||
* @exception RuntimeOperationsException if Descriptor is invalid
|
||||
*/
|
||||
private Descriptor validDescriptor(final Descriptor in) throws RuntimeOperationsException {
|
||||
|
||||
Descriptor clone;
|
||||
boolean defaulted = (in == null);
|
||||
if (defaulted) {
|
||||
clone = new DescriptorSupport();
|
||||
MODELMBEAN_LOGGER.finer("Null Descriptor, creating new.");
|
||||
} else {
|
||||
clone = (Descriptor) in.clone();
|
||||
}
|
||||
|
||||
//Setting defaults.
|
||||
if (defaulted && clone.getFieldValue("name")==null) {
|
||||
clone.setField("name", this.getName());
|
||||
MODELMBEAN_LOGGER.finer("Defaulting Descriptor name to " + this.getName());
|
||||
}
|
||||
if (defaulted && clone.getFieldValue("descriptorType")==null) {
|
||||
clone.setField("descriptorType", "attribute");
|
||||
MODELMBEAN_LOGGER.finer("Defaulting descriptorType to \"attribute\"");
|
||||
}
|
||||
if (clone.getFieldValue("displayName") == null) {
|
||||
clone.setField("displayName",this.getName());
|
||||
MODELMBEAN_LOGGER.finer("Defaulting Descriptor displayName to " + this.getName());
|
||||
}
|
||||
|
||||
//Checking validity
|
||||
if (!clone.isValid()) {
|
||||
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
|
||||
"The isValid() method of the Descriptor object itself returned false,"+
|
||||
"one or more required fields are invalid. Descriptor:" + clone.toString());
|
||||
}
|
||||
if (!getName().equalsIgnoreCase((String)clone.getFieldValue("name"))) {
|
||||
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
|
||||
"The Descriptor \"name\" field does not match the object described. " +
|
||||
" Expected: "+ this.getName() + " , was: " + clone.getFieldValue("name"));
|
||||
}
|
||||
|
||||
if (!"attribute".equalsIgnoreCase((String)clone.getFieldValue("descriptorType"))) {
|
||||
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
|
||||
"The Descriptor \"descriptorType\" field does not match the object described. " +
|
||||
" Expected: \"attribute\" ," + " was: " + clone.getFieldValue("descriptorType"));
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes a {@link ModelMBeanAttributeInfo} from an {@link ObjectInputStream}.
|
||||
*/
|
||||
private void readObject(ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException {
|
||||
// New serial form ignores extra field "currClass"
|
||||
in.defaultReadObject();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serializes a {@link ModelMBeanAttributeInfo} to an {@link ObjectOutputStream}.
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream out)
|
||||
throws IOException {
|
||||
if (compat)
|
||||
{
|
||||
// Serializes this instance in the old serial form
|
||||
//
|
||||
ObjectOutputStream.PutField fields = out.putFields();
|
||||
fields.put("attrDescriptor", attrDescriptor);
|
||||
fields.put("currClass", currClass);
|
||||
out.writeFields();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Serializes this instance in the new serial form
|
||||
//
|
||||
out.defaultWriteObject();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,491 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @author IBM Corp.
|
||||
*
|
||||
* Copyright IBM Corp. 1999-2000. All rights reserved.
|
||||
*/
|
||||
|
||||
package javax.management.modelmbean;
|
||||
|
||||
import static com.sun.jmx.defaults.JmxProperties.MODELMBEAN_LOGGER;
|
||||
import com.sun.jmx.mbeanserver.GetPropertyAction;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamField;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.security.AccessController;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.management.Descriptor;
|
||||
import javax.management.DescriptorAccess;
|
||||
import javax.management.DescriptorKey;
|
||||
import javax.management.MBeanConstructorInfo;
|
||||
import javax.management.MBeanParameterInfo;
|
||||
import javax.management.RuntimeOperationsException;
|
||||
|
||||
/**
|
||||
* <p>The ModelMBeanConstructorInfo object describes a constructor of the ModelMBean.
|
||||
* It is a subclass of MBeanConstructorInfo with the addition of an associated Descriptor
|
||||
* and an implementation of the DescriptorAccess interface.</p>
|
||||
*
|
||||
* <P id="descriptor">
|
||||
* The fields in the descriptor are defined, but not limited to, the following.
|
||||
* Note that when the Type in this table is Number, a String that is the decimal
|
||||
* representation of a Long can also be used.</P>
|
||||
*
|
||||
* <table border="1" cellpadding="5" summary="ModelMBeanConstructorInfo Fields">
|
||||
* <tr><th>Name</th><th>Type</th><th>Meaning</th></tr>
|
||||
* <tr><td>name</td><td>String</td>
|
||||
* <td>Constructor name.</td></tr>
|
||||
* <tr><td>descriptorType</td><td>String</td>
|
||||
* <td>Must be "operation".</td></tr>
|
||||
* <tr><td>role</td><td>String</td>
|
||||
* <td>Must be "constructor".</td></tr>
|
||||
* <tr><td>displayName</td><td>String</td>
|
||||
* <td>Human readable name of constructor.</td></tr>
|
||||
* <tr><td>visibility</td><td>Number</td>
|
||||
* <td>1-4 where 1: always visible 4: rarely visible.</td></tr>
|
||||
* <tr><td>presentationString</td><td>String</td>
|
||||
* <td>XML formatted string to describe how to present operation</td></tr>
|
||||
* </table>
|
||||
*
|
||||
* <p>The {@code persistPolicy} and {@code currencyTimeLimit} fields
|
||||
* are meaningless for constructors, but are not considered invalid.</p>
|
||||
*
|
||||
* <p>The default descriptor will have the {@code name}, {@code
|
||||
* descriptorType}, {@code displayName} and {@code role} fields.
|
||||
*
|
||||
* <p>The <b>serialVersionUID</b> of this class is <code>3862947819818064362L</code>.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
|
||||
@SuppressWarnings("serial") // serialVersionUID is not constant
|
||||
public class ModelMBeanConstructorInfo
|
||||
extends MBeanConstructorInfo
|
||||
implements DescriptorAccess {
|
||||
|
||||
// Serialization compatibility stuff:
|
||||
// Two serial forms are supported in this class. The selected form depends
|
||||
// on system property "jmx.serial.form":
|
||||
// - "1.0" for JMX 1.0
|
||||
// - any other value for JMX 1.1 and higher
|
||||
//
|
||||
// Serial version for old serial form
|
||||
private static final long oldSerialVersionUID = -4440125391095574518L;
|
||||
//
|
||||
// Serial version for new serial form
|
||||
private static final long newSerialVersionUID = 3862947819818064362L;
|
||||
//
|
||||
// Serializable fields in old serial form
|
||||
private static final ObjectStreamField[] oldSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("consDescriptor", Descriptor.class),
|
||||
new ObjectStreamField("currClass", String.class)
|
||||
};
|
||||
//
|
||||
// Serializable fields in new serial form
|
||||
private static final ObjectStreamField[] newSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("consDescriptor", Descriptor.class)
|
||||
};
|
||||
//
|
||||
// Actual serial version and serial form
|
||||
private static final long serialVersionUID;
|
||||
/**
|
||||
* @serialField consDescriptor Descriptor The {@link Descriptor} containing the metadata for this instance
|
||||
*/
|
||||
private static final ObjectStreamField[] serialPersistentFields;
|
||||
private static boolean compat = false;
|
||||
static {
|
||||
try {
|
||||
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
|
||||
String form = AccessController.doPrivileged(act);
|
||||
compat = (form != null && form.equals("1.0"));
|
||||
} catch (Exception e) {
|
||||
// OK: No compat with 1.0
|
||||
}
|
||||
if (compat) {
|
||||
serialPersistentFields = oldSerialPersistentFields;
|
||||
serialVersionUID = oldSerialVersionUID;
|
||||
} else {
|
||||
serialPersistentFields = newSerialPersistentFields;
|
||||
serialVersionUID = newSerialVersionUID;
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Serialization compatibility stuff
|
||||
|
||||
/**
|
||||
* @serial The {@link Descriptor} containing the metadata for this instance
|
||||
*/
|
||||
private Descriptor consDescriptor = validDescriptor(null);
|
||||
|
||||
private final static String currClass = "ModelMBeanConstructorInfo";
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a ModelMBeanConstructorInfo object with a default
|
||||
* descriptor. The {@link Descriptor} of the constructed
|
||||
* object will include fields contributed by any annotations on
|
||||
* the {@code Constructor} object that contain the {@link
|
||||
* DescriptorKey} meta-annotation.
|
||||
*
|
||||
* @param description A human readable description of the constructor.
|
||||
* @param constructorMethod The java.lang.reflect.Constructor object
|
||||
* describing the MBean constructor.
|
||||
*/
|
||||
public ModelMBeanConstructorInfo(String description,
|
||||
Constructor<?> constructorMethod)
|
||||
{
|
||||
super(description, constructorMethod);
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanConstructorInfo.class.getName(),
|
||||
"ModelMBeanConstructorInfo(String,Constructor)",
|
||||
"Entry");
|
||||
}
|
||||
consDescriptor = validDescriptor(null);
|
||||
|
||||
// put getter and setter methods in constructors list
|
||||
// create default descriptor
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a ModelMBeanConstructorInfo object. The {@link
|
||||
* Descriptor} of the constructed object will include fields
|
||||
* contributed by any annotations on the {@code Constructor}
|
||||
* object that contain the {@link DescriptorKey}
|
||||
* meta-annotation.
|
||||
*
|
||||
* @param description A human readable description of the constructor.
|
||||
* @param constructorMethod The java.lang.reflect.Constructor object
|
||||
* describing the ModelMBean constructor.
|
||||
* @param descriptor An instance of Descriptor containing the
|
||||
* appropriate metadata for this instance of the
|
||||
* ModelMBeanConstructorInfo. If it is null, then a default
|
||||
* descriptor will be created. If the descriptor does not
|
||||
* contain the field "displayName" this field is added in the
|
||||
* descriptor with its default value.
|
||||
*
|
||||
* @exception RuntimeOperationsException Wraps an
|
||||
* IllegalArgumentException. The descriptor is invalid, or
|
||||
* descriptor field "name" is not equal to name
|
||||
* parameter, or descriptor field "descriptorType" is
|
||||
* not equal to "operation" or descriptor field "role" is
|
||||
* present but not equal to "constructor".
|
||||
*/
|
||||
|
||||
public ModelMBeanConstructorInfo(String description,
|
||||
Constructor<?> constructorMethod,
|
||||
Descriptor descriptor)
|
||||
{
|
||||
|
||||
super(description, constructorMethod);
|
||||
// put getter and setter methods in constructors list
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanConstructorInfo.class.getName(),
|
||||
"ModelMBeanConstructorInfo(" +
|
||||
"String,Constructor,Descriptor)", "Entry");
|
||||
}
|
||||
consDescriptor = validDescriptor(descriptor);
|
||||
}
|
||||
/**
|
||||
* Constructs a ModelMBeanConstructorInfo object with a default descriptor.
|
||||
*
|
||||
* @param name The name of the constructor.
|
||||
* @param description A human readable description of the constructor.
|
||||
* @param signature MBeanParameterInfo object array describing the parameters(arguments) of the constructor.
|
||||
*/
|
||||
|
||||
public ModelMBeanConstructorInfo(String name,
|
||||
String description,
|
||||
MBeanParameterInfo[] signature)
|
||||
{
|
||||
|
||||
super(name, description, signature);
|
||||
// create default descriptor
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanConstructorInfo.class.getName(),
|
||||
"ModelMBeanConstructorInfo(" +
|
||||
"String,String,MBeanParameterInfo[])", "Entry");
|
||||
}
|
||||
consDescriptor = validDescriptor(null);
|
||||
}
|
||||
/**
|
||||
* Constructs a ModelMBeanConstructorInfo object.
|
||||
*
|
||||
* @param name The name of the constructor.
|
||||
* @param description A human readable description of the constructor.
|
||||
* @param signature MBeanParameterInfo objects describing the parameters(arguments) of the constructor.
|
||||
* @param descriptor An instance of Descriptor containing the appropriate metadata
|
||||
* for this instance of the MBeanConstructorInfo. If it is null then a default descriptor will be created.
|
||||
* If the descriptor does not contain the field "displayName" this field
|
||||
* is added in the descriptor with its default value.
|
||||
*
|
||||
* @exception RuntimeOperationsException Wraps an
|
||||
* IllegalArgumentException. The descriptor is invalid, or
|
||||
* descriptor field "name" is not equal to name
|
||||
* parameter, or descriptor field "descriptorType" is
|
||||
* not equal to "operation" or descriptor field "role" is
|
||||
* present but not equal to "constructor".
|
||||
*/
|
||||
|
||||
public ModelMBeanConstructorInfo(String name,
|
||||
String description,
|
||||
MBeanParameterInfo[] signature,
|
||||
Descriptor descriptor)
|
||||
{
|
||||
super(name, description, signature);
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanConstructorInfo.class.getName(),
|
||||
"ModelMBeanConstructorInfo(" +
|
||||
"String,String,MBeanParameterInfo[],Descriptor)",
|
||||
"Entry");
|
||||
}
|
||||
consDescriptor = validDescriptor(descriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ModelMBeanConstructorInfo object from this ModelMBeanConstructor Object.
|
||||
*
|
||||
* @param old the ModelMBeanConstructorInfo to be duplicated
|
||||
*
|
||||
*/
|
||||
ModelMBeanConstructorInfo(ModelMBeanConstructorInfo old)
|
||||
{
|
||||
super(old.getName(), old.getDescription(), old.getSignature());
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanConstructorInfo.class.getName(),
|
||||
"ModelMBeanConstructorInfo(" +
|
||||
"ModelMBeanConstructorInfo)", "Entry");
|
||||
}
|
||||
consDescriptor = validDescriptor(consDescriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a new ModelMBeanConstructorInfo which is a duplicate of this ModelMBeanConstructorInfo.
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
public Object clone ()
|
||||
{
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanConstructorInfo.class.getName(),
|
||||
"clone()", "Entry");
|
||||
}
|
||||
return(new ModelMBeanConstructorInfo(this)) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the associated Descriptor.
|
||||
*
|
||||
* @return Descriptor associated with the
|
||||
* ModelMBeanConstructorInfo object.
|
||||
*
|
||||
* @see #setDescriptor
|
||||
*/
|
||||
|
||||
|
||||
@Override
|
||||
public Descriptor getDescriptor()
|
||||
{
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanConstructorInfo.class.getName(),
|
||||
"getDescriptor()", "Entry");
|
||||
}
|
||||
if (consDescriptor == null){
|
||||
consDescriptor = validDescriptor(null);
|
||||
}
|
||||
return((Descriptor)consDescriptor.clone());
|
||||
}
|
||||
/**
|
||||
* Sets associated Descriptor (full replace) of
|
||||
* ModelMBeanConstructorInfo. If the new Descriptor is null,
|
||||
* then the associated Descriptor reverts to a default
|
||||
* descriptor. The Descriptor is validated before it is
|
||||
* assigned. If the new Descriptor is invalid, then a
|
||||
* RuntimeOperationsException wrapping an
|
||||
* IllegalArgumentException is thrown.
|
||||
*
|
||||
* @param inDescriptor replaces the Descriptor associated with
|
||||
* the ModelMBeanConstructor. If the descriptor does not
|
||||
* contain all the following fields, the missing ones are added with
|
||||
* their default values: displayName, name, role, descriptorType.
|
||||
*
|
||||
* @exception RuntimeOperationsException Wraps an
|
||||
* IllegalArgumentException. The descriptor is invalid, or
|
||||
* descriptor field "name" is present but not equal to name
|
||||
* parameter, or descriptor field "descriptorType" is present
|
||||
* but not equal to "operation" or descriptor field "role" is
|
||||
* present but not equal to "constructor".
|
||||
*
|
||||
* @see #getDescriptor
|
||||
*/
|
||||
public void setDescriptor(Descriptor inDescriptor)
|
||||
{
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanConstructorInfo.class.getName(),
|
||||
"setDescriptor()", "Entry");
|
||||
}
|
||||
consDescriptor = validDescriptor(inDescriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string containing the entire contents of the ModelMBeanConstructorInfo in human readable form.
|
||||
*/
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanConstructorInfo.class.getName(),
|
||||
"toString()", "Entry");
|
||||
}
|
||||
String retStr =
|
||||
"ModelMBeanConstructorInfo: " + this.getName() +
|
||||
" ; Description: " + this.getDescription() +
|
||||
" ; Descriptor: " + this.getDescriptor() +
|
||||
" ; Signature: ";
|
||||
MBeanParameterInfo[] pTypes = this.getSignature();
|
||||
for (int i=0; i < pTypes.length; i++)
|
||||
{
|
||||
retStr = retStr.concat((pTypes[i]).getType() + ", ");
|
||||
}
|
||||
return retStr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clones the passed in Descriptor, sets default values, and checks for validity.
|
||||
* If the Descriptor is invalid (for instance by having the wrong "name"),
|
||||
* this indicates programming error and a RuntimeOperationsException will be thrown.
|
||||
*
|
||||
* The following fields will be defaulted if they are not already set:
|
||||
* displayName=this.getName(), name=this.getName(), descriptorType="operation",
|
||||
* role="constructor"
|
||||
*
|
||||
*
|
||||
* @param in Descriptor to be checked, or null which is equivalent to
|
||||
* an empty Descriptor.
|
||||
* @exception RuntimeOperationsException if Descriptor is invalid
|
||||
*/
|
||||
private Descriptor validDescriptor(final Descriptor in) throws RuntimeOperationsException {
|
||||
Descriptor clone;
|
||||
boolean defaulted = (in == null);
|
||||
if (defaulted) {
|
||||
clone = new DescriptorSupport();
|
||||
MODELMBEAN_LOGGER.finer("Null Descriptor, creating new.");
|
||||
} else {
|
||||
clone = (Descriptor) in.clone();
|
||||
}
|
||||
|
||||
//Setting defaults.
|
||||
if (defaulted && clone.getFieldValue("name")==null) {
|
||||
clone.setField("name", this.getName());
|
||||
MODELMBEAN_LOGGER.finer("Defaulting Descriptor name to " + this.getName());
|
||||
}
|
||||
if (defaulted && clone.getFieldValue("descriptorType")==null) {
|
||||
clone.setField("descriptorType", "operation");
|
||||
MODELMBEAN_LOGGER.finer("Defaulting descriptorType to \"operation\"");
|
||||
}
|
||||
if (clone.getFieldValue("displayName") == null) {
|
||||
clone.setField("displayName",this.getName());
|
||||
MODELMBEAN_LOGGER.finer("Defaulting Descriptor displayName to " + this.getName());
|
||||
}
|
||||
if (clone.getFieldValue("role") == null) {
|
||||
clone.setField("role","constructor");
|
||||
MODELMBEAN_LOGGER.finer("Defaulting Descriptor role field to \"constructor\"");
|
||||
}
|
||||
|
||||
//Checking validity
|
||||
if (!clone.isValid()) {
|
||||
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
|
||||
"The isValid() method of the Descriptor object itself returned false,"+
|
||||
"one or more required fields are invalid. Descriptor:" + clone.toString());
|
||||
}
|
||||
if (!getName().equalsIgnoreCase((String) clone.getFieldValue("name"))) {
|
||||
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
|
||||
"The Descriptor \"name\" field does not match the object described. " +
|
||||
" Expected: "+ this.getName() + " , was: " + clone.getFieldValue("name"));
|
||||
}
|
||||
if (!"operation".equalsIgnoreCase((String) clone.getFieldValue("descriptorType"))) {
|
||||
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
|
||||
"The Descriptor \"descriptorType\" field does not match the object described. " +
|
||||
" Expected: \"operation\" ," + " was: " + clone.getFieldValue("descriptorType"));
|
||||
}
|
||||
if (! ((String)clone.getFieldValue("role")).equalsIgnoreCase("constructor")) {
|
||||
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
|
||||
"The Descriptor \"role\" field does not match the object described. " +
|
||||
" Expected: \"constructor\" ," + " was: " + clone.getFieldValue("role"));
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a {@link ModelMBeanConstructorInfo} from an {@link ObjectInputStream}.
|
||||
*/
|
||||
private void readObject(ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException {
|
||||
// New serial form ignores extra field "currClass"
|
||||
in.defaultReadObject();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serializes a {@link ModelMBeanConstructorInfo} to an {@link ObjectOutputStream}.
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream out)
|
||||
throws IOException {
|
||||
if (compat)
|
||||
{
|
||||
// Serializes this instance in the old serial form
|
||||
//
|
||||
ObjectOutputStream.PutField fields = out.putFields();
|
||||
fields.put("consDescriptor", consDescriptor);
|
||||
fields.put("currClass", currClass);
|
||||
out.writeFields();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Serializes this instance in the new serial form
|
||||
//
|
||||
out.defaultWriteObject();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
370
jdkSrc/jdk8/javax/management/modelmbean/ModelMBeanInfo.java
Normal file
370
jdkSrc/jdk8/javax/management/modelmbean/ModelMBeanInfo.java
Normal file
@@ -0,0 +1,370 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @author IBM Corp.
|
||||
*
|
||||
* Copyright IBM Corp. 1999-2000. All rights reserved.
|
||||
*/
|
||||
|
||||
package javax.management.modelmbean;
|
||||
|
||||
import javax.management.Descriptor;
|
||||
import javax.management.MBeanAttributeInfo;
|
||||
import javax.management.MBeanConstructorInfo;
|
||||
import javax.management.RuntimeOperationsException;
|
||||
import javax.management.MBeanException;
|
||||
import javax.management.MBeanNotificationInfo;
|
||||
import javax.management.MBeanOperationInfo;
|
||||
|
||||
/**
|
||||
* This interface is implemented by the ModelMBeanInfo for every ModelMBean. An implementation of this interface
|
||||
* must be shipped with every JMX Agent.
|
||||
* <P>
|
||||
* Java resources wishing to be manageable instantiate the ModelMBean using the MBeanServer's
|
||||
* createMBean method. The resource then sets the ModelMBeanInfo and Descriptors for the ModelMBean
|
||||
* instance. The attributes, operations, and notifications exposed via the ModelMBeanInfo for the
|
||||
* ModelMBean comprise the management interface and are accessible
|
||||
* from MBeans, connectors/adaptors like other MBeans. Through the Descriptors, values and methods in
|
||||
* the managed application can be defined and mapped to attributes and operations of the ModelMBean.
|
||||
* This mapping can be defined during development in a file or dynamically and
|
||||
* programmatically at runtime.
|
||||
* <P>
|
||||
* Every ModelMBean which is instantiated in the MBeanServer becomes manageable:
|
||||
* its attributes, operations, and notifications
|
||||
* become remotely accessible through the connectors/adaptors connected to that MBeanServer.
|
||||
* A Java object cannot be registered in the MBeanServer unless it is a JMX compliant MBean.
|
||||
* By instantiating a ModelMBean, resources are guaranteed that the MBean is valid.
|
||||
*
|
||||
* MBeanException and RuntimeOperationsException must be thrown on every public method. This allows
|
||||
* for wrapping exceptions from distributed communications (RMI, EJB, etc.)
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
|
||||
public interface ModelMBeanInfo
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Returns a Descriptor array consisting of all
|
||||
* Descriptors for the ModelMBeanInfo of type inDescriptorType.
|
||||
*
|
||||
* @param inDescriptorType value of descriptorType field that must be set for the descriptor
|
||||
* to be returned. Must be "mbean", "attribute", "operation", "constructor" or "notification".
|
||||
* If it is null or empty then all types will be returned.
|
||||
*
|
||||
* @return Descriptor array containing all descriptors for the ModelMBean if type inDescriptorType.
|
||||
*
|
||||
* @exception MBeanException Wraps a distributed communication Exception.
|
||||
* @exception RuntimeOperationsException Wraps an IllegalArgumentException when the descriptorType in parameter is
|
||||
* not one of: "mbean", "attribute", "operation", "constructor", "notification", empty or null.
|
||||
*
|
||||
* @see #setDescriptors
|
||||
*/
|
||||
public Descriptor[] getDescriptors(String inDescriptorType)
|
||||
throws MBeanException, RuntimeOperationsException;
|
||||
|
||||
/**
|
||||
* Adds or replaces descriptors in the ModelMBeanInfo.
|
||||
*
|
||||
* @param inDescriptors The descriptors to be set in the ModelMBeanInfo. Null
|
||||
* elements of the list will be ignored. All descriptors must have name and descriptorType fields.
|
||||
*
|
||||
* @exception RuntimeOperationsException Wraps an IllegalArgumentException for a null or invalid descriptor.
|
||||
* @exception MBeanException Wraps a distributed communication Exception.
|
||||
*
|
||||
* @see #getDescriptors
|
||||
*/
|
||||
public void setDescriptors(Descriptor[] inDescriptors)
|
||||
throws MBeanException, RuntimeOperationsException;
|
||||
|
||||
/**
|
||||
* Returns a Descriptor requested by name and descriptorType.
|
||||
*
|
||||
* @param inDescriptorName The name of the descriptor.
|
||||
* @param inDescriptorType The type of the descriptor being
|
||||
* requested. If this is null or empty then all types are
|
||||
* searched. Valid types are 'mbean', 'attribute', 'constructor'
|
||||
* 'operation', and 'notification'. This value will be equal to
|
||||
* the 'descriptorType' field in the descriptor that is returned.
|
||||
*
|
||||
* @return Descriptor containing the descriptor for the ModelMBean
|
||||
* with the same name and descriptorType. If no descriptor is
|
||||
* found, null is returned.
|
||||
*
|
||||
* @exception MBeanException Wraps a distributed communication Exception.
|
||||
* @exception RuntimeOperationsException Wraps an IllegalArgumentException for a null descriptor name or null or invalid type.
|
||||
* The type must be "mbean","attribute", "constructor", "operation", or "notification".
|
||||
*
|
||||
* @see #setDescriptor
|
||||
*/
|
||||
|
||||
public Descriptor getDescriptor(String inDescriptorName, String inDescriptorType)
|
||||
throws MBeanException, RuntimeOperationsException;
|
||||
|
||||
/**
|
||||
* Sets descriptors in the info array of type inDescriptorType
|
||||
* for the ModelMBean. The setDescriptor method of the
|
||||
* corresponding ModelMBean*Info will be called to set the
|
||||
* specified descriptor.
|
||||
*
|
||||
* @param inDescriptor The descriptor to be set in the
|
||||
* ModelMBean. It must NOT be null. All descriptors must have
|
||||
* name and descriptorType fields.
|
||||
* @param inDescriptorType The type of the descriptor being
|
||||
* set. If this is null then the descriptorType field in the
|
||||
* descriptor is used. If specified this value must be set in
|
||||
* the descriptorType field in the descriptor. Must be
|
||||
* "mbean","attribute", "constructor", "operation", or
|
||||
* "notification".
|
||||
*
|
||||
* @exception RuntimeOperationsException Wraps an
|
||||
* IllegalArgumentException for illegal or null arguments or
|
||||
* if the name field of the descriptor is not found in the
|
||||
* corresponding MBeanAttributeInfo or MBeanConstructorInfo or
|
||||
* MBeanNotificationInfo or MBeanOperationInfo.
|
||||
* @exception MBeanException Wraps a distributed communication
|
||||
* Exception.
|
||||
*
|
||||
* @see #getDescriptor
|
||||
*/
|
||||
|
||||
public void setDescriptor(Descriptor inDescriptor, String inDescriptorType)
|
||||
throws MBeanException, RuntimeOperationsException;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Returns the ModelMBean's descriptor which contains MBean wide
|
||||
* policies. This descriptor contains metadata about the MBean and default
|
||||
* policies for persistence and caching.</p>
|
||||
*
|
||||
* <P id="descriptor">
|
||||
* The fields in the descriptor are defined, but not limited to, the
|
||||
* following. Note that when the Type in this table is Number, a String
|
||||
* that is the decimal representation of a Long can also be used.</P>
|
||||
*
|
||||
* <table border="1" cellpadding="5" summary="ModelMBean Fields">
|
||||
* <tr><th>Name</th><th>Type</th><th>Meaning</th></tr>
|
||||
* <tr><td>name</td><td>String</td>
|
||||
* <td>MBean name.</td></tr>
|
||||
* <tr><td>descriptorType</td><td>String</td>
|
||||
* <td>Must be "mbean".</td></tr>
|
||||
* <tr><td>displayName</td><td>String</td>
|
||||
* <td>Name of MBean to be used in displays.</td></tr>
|
||||
* <tr><td>persistPolicy</td><td>String</td>
|
||||
* <td>One of: OnUpdate|OnTimer|NoMoreOftenThan|OnUnregister|Always|Never.
|
||||
* See the section "MBean Descriptor Fields" in the JMX specification
|
||||
* document.</td></tr>
|
||||
* <tr><td>persistLocation</td><td>String</td>
|
||||
* <td>The fully qualified directory name where the MBean should be
|
||||
* persisted (if appropriate).</td></tr>
|
||||
* <tr><td>persistFile</td><td>String</td>
|
||||
* <td>File name into which the MBean should be persisted.</td></tr>
|
||||
* <tr><td>persistPeriod</td><td>Number</td>
|
||||
* <td>Frequency of persist cycle in seconds, for OnTime and
|
||||
* NoMoreOftenThan PersistPolicy</td></tr>
|
||||
* <tr><td>currencyTimeLimit</td><td>Number</td>
|
||||
* <td>How long cached value is valid: <0 never, =0 always,
|
||||
* >0 seconds.</td></tr>
|
||||
* <tr><td>log</td><td>String</td>
|
||||
* <td>t: log all notifications, f: log no notifications.</td></tr>
|
||||
* <tr><td>logfile</td><td>String</td>
|
||||
* <td>Fully qualified filename to log events to.</td></tr>
|
||||
* <tr><td>visibility</td><td>Number</td>
|
||||
* <td>1-4 where 1: always visible 4: rarely visible.</td></tr>
|
||||
* <tr><td>export</td><td>String</td>
|
||||
* <td>Name to be used to export/expose this MBean so that it is
|
||||
* findable by other JMX Agents.</td></tr>
|
||||
* <tr><td>presentationString</td><td>String</td>
|
||||
* <td>XML formatted string to allow presentation of data to be
|
||||
* associated with the MBean.</td></tr>
|
||||
* </table>
|
||||
*
|
||||
* <P>
|
||||
* The default descriptor is: name=className,descriptorType="mbean", displayName=className,
|
||||
* persistPolicy="never",log="F",visibility="1"
|
||||
* If the descriptor does not contain all these fields, they will be added with these default values.
|
||||
*
|
||||
* <p><b>Note:</b> because of inconsistencies in previous versions of
|
||||
* this specification, it is recommended not to use negative or zero
|
||||
* values for <code>currencyTimeLimit</code>. To indicate that a
|
||||
* cached value is never valid, omit the
|
||||
* <code>currencyTimeLimit</code> field. To indicate that it is
|
||||
* always valid, use a very large number for this field.</p>
|
||||
*
|
||||
* @return the MBean descriptor.
|
||||
*
|
||||
* @exception MBeanException Wraps a distributed communication
|
||||
* Exception.
|
||||
*
|
||||
* @exception RuntimeOperationsException a {@link
|
||||
* RuntimeException} occurred while getting the descriptor.
|
||||
*
|
||||
* @see #setMBeanDescriptor
|
||||
*/
|
||||
public Descriptor getMBeanDescriptor()
|
||||
throws MBeanException, RuntimeOperationsException;
|
||||
|
||||
/**
|
||||
* Sets the ModelMBean's descriptor. This descriptor contains default, MBean wide
|
||||
* metadata about the MBean and default policies for persistence and caching. This operation
|
||||
* does a complete replacement of the descriptor, no merging is done. If the descriptor to
|
||||
* set to is null then the default descriptor will be created.
|
||||
* The default descriptor is: name=className,descriptorType="mbean", displayName=className,
|
||||
* persistPolicy="never",log="F",visibility="1"
|
||||
* If the descriptor does not contain all these fields, they will be added with these default values.
|
||||
*
|
||||
* See {@link #getMBeanDescriptor getMBeanDescriptor} method javadoc for description of valid field names.
|
||||
*
|
||||
* @param inDescriptor the descriptor to set.
|
||||
*
|
||||
* @exception MBeanException Wraps a distributed communication Exception.
|
||||
* @exception RuntimeOperationsException Wraps an IllegalArgumentException for invalid descriptor.
|
||||
*
|
||||
*
|
||||
* @see #getMBeanDescriptor
|
||||
*/
|
||||
|
||||
public void setMBeanDescriptor(Descriptor inDescriptor)
|
||||
throws MBeanException, RuntimeOperationsException;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a ModelMBeanAttributeInfo requested by name.
|
||||
*
|
||||
* @param inName The name of the ModelMBeanAttributeInfo to get.
|
||||
* If no ModelMBeanAttributeInfo exists for this name null is returned.
|
||||
*
|
||||
* @return the attribute info for the named attribute, or null
|
||||
* if there is none.
|
||||
*
|
||||
* @exception MBeanException Wraps a distributed communication
|
||||
* Exception.
|
||||
* @exception RuntimeOperationsException Wraps an
|
||||
* IllegalArgumentException for a null attribute name.
|
||||
*
|
||||
*/
|
||||
|
||||
public ModelMBeanAttributeInfo getAttribute(String inName)
|
||||
throws MBeanException, RuntimeOperationsException;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a ModelMBeanOperationInfo requested by name.
|
||||
*
|
||||
* @param inName The name of the ModelMBeanOperationInfo to get.
|
||||
* If no ModelMBeanOperationInfo exists for this name null is returned.
|
||||
*
|
||||
* @return the operation info for the named operation, or null
|
||||
* if there is none.
|
||||
*
|
||||
* @exception MBeanException Wraps a distributed communication Exception.
|
||||
* @exception RuntimeOperationsException Wraps an IllegalArgumentException for a null operation name.
|
||||
*
|
||||
*/
|
||||
|
||||
public ModelMBeanOperationInfo getOperation(String inName)
|
||||
throws MBeanException, RuntimeOperationsException;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a ModelMBeanNotificationInfo requested by name.
|
||||
*
|
||||
* @param inName The name of the ModelMBeanNotificationInfo to get.
|
||||
* If no ModelMBeanNotificationInfo exists for this name null is returned.
|
||||
*
|
||||
* @return the info for the named notification, or null if there
|
||||
* is none.
|
||||
*
|
||||
* @exception MBeanException Wraps a distributed communication Exception.
|
||||
* @exception RuntimeOperationsException Wraps an IllegalArgumentException for a null notification name.
|
||||
*
|
||||
*/
|
||||
public ModelMBeanNotificationInfo getNotification(String inName)
|
||||
throws MBeanException, RuntimeOperationsException;
|
||||
|
||||
/**
|
||||
* Creates and returns a copy of this object.
|
||||
*/
|
||||
public java.lang.Object clone();
|
||||
|
||||
/**
|
||||
* Returns the list of attributes exposed for management.
|
||||
* Each attribute is described by an <CODE>MBeanAttributeInfo</CODE> object.
|
||||
*
|
||||
* @return An array of <CODE>MBeanAttributeInfo</CODE> objects.
|
||||
*/
|
||||
public MBeanAttributeInfo[] getAttributes();
|
||||
|
||||
/**
|
||||
* Returns the name of the Java class of the MBean described by
|
||||
* this <CODE>MBeanInfo</CODE>.
|
||||
*
|
||||
* @return the Java class name.
|
||||
*/
|
||||
public java.lang.String getClassName();
|
||||
|
||||
/**
|
||||
* Returns the list of the public constructors of the MBean.
|
||||
* Each constructor is described by an <CODE>MBeanConstructorInfo</CODE> object.
|
||||
*
|
||||
* @return An array of <CODE>MBeanConstructorInfo</CODE> objects.
|
||||
*/
|
||||
public MBeanConstructorInfo[] getConstructors();
|
||||
|
||||
/**
|
||||
* Returns a human readable description of the MBean.
|
||||
*
|
||||
* @return the description.
|
||||
*/
|
||||
public java.lang.String getDescription();
|
||||
|
||||
/**
|
||||
* Returns the list of the notifications emitted by the MBean.
|
||||
* Each notification is described by an <CODE>MBeanNotificationInfo</CODE> object.
|
||||
* <P>
|
||||
* In addition to any notification specified by the application,
|
||||
* a ModelMBean may always send also two additional notifications:
|
||||
* <UL>
|
||||
* <LI> One with descriptor name "GENERIC" and displayName "jmx.modelmbean.generic"
|
||||
* <LI> Second is a standard attribute change notification
|
||||
* with descriptor name "ATTRIBUTE_CHANGE" and displayName "jmx.attribute.change"
|
||||
* </UL>
|
||||
* Thus any implementation of ModelMBeanInfo should always add those two notifications
|
||||
* in addition to those specified by the application.
|
||||
*
|
||||
* @return An array of <CODE>MBeanNotificationInfo</CODE> objects.
|
||||
*/
|
||||
public MBeanNotificationInfo[] getNotifications();
|
||||
|
||||
/**
|
||||
* Returns the list of operations of the MBean.
|
||||
* Each operation is described by an <CODE>MBeanOperationInfo</CODE> object.
|
||||
*
|
||||
* @return An array of <CODE>MBeanOperationInfo</CODE> objects.
|
||||
*/
|
||||
public MBeanOperationInfo[] getOperations();
|
||||
|
||||
}
|
||||
1067
jdkSrc/jdk8/javax/management/modelmbean/ModelMBeanInfoSupport.java
Normal file
1067
jdkSrc/jdk8/javax/management/modelmbean/ModelMBeanInfoSupport.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,192 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @author IBM Corp.
|
||||
*
|
||||
* Copyright IBM Corp. 1999-2000. All rights reserved.
|
||||
*/
|
||||
|
||||
package javax.management.modelmbean;
|
||||
|
||||
import javax.management.Attribute;
|
||||
import javax.management.AttributeChangeNotification;
|
||||
import javax.management.ListenerNotFoundException;
|
||||
import javax.management.MBeanException;
|
||||
import javax.management.Notification;
|
||||
import javax.management.NotificationBroadcaster;
|
||||
import javax.management.NotificationListener;
|
||||
import javax.management.RuntimeOperationsException;
|
||||
|
||||
/**
|
||||
* This interface must be implemented by the ModelMBeans. An implementation of this interface
|
||||
* must be shipped with every JMX Agent.
|
||||
* <P>
|
||||
* Java resources wishing to be manageable instantiate the ModelMBean using the MBeanServer's
|
||||
* createMBean method. The resource then sets the ModelMBeanInfo (with Descriptors) for the ModelMBean
|
||||
* instance. The attributes and operations exposed via the ModelMBeanInfo for the ModelMBean are accessible
|
||||
* from MBeans, connectors/adaptors like other MBeans. Through the ModelMBeanInfo Descriptors, values and methods in
|
||||
* the managed application can be defined and mapped to attributes and operations of the ModelMBean.
|
||||
* This mapping can be defined during development in an XML formatted file or dynamically and
|
||||
* programmatically at runtime.
|
||||
* <P>
|
||||
* Every ModelMBean which is instantiated in the MBeanServer becomes manageable:
|
||||
* its attributes and operations
|
||||
* become remotely accessible through the connectors/adaptors connected to that MBeanServer.
|
||||
* A Java object cannot be registered in the MBeanServer unless it is a JMX compliant MBean.
|
||||
* By instantiating a ModelMBean, resources are guaranteed that the MBean is valid.
|
||||
* <P>
|
||||
* MBeanException and RuntimeOperationsException must be thrown on every public method. This allows
|
||||
* for wrapping exceptions from distributed communications (RMI, EJB, etc.). These exceptions do
|
||||
* not have to be thrown by the implementation except in the scenarios described in the specification
|
||||
* and javadoc.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
|
||||
public interface ModelMBeanNotificationBroadcaster extends NotificationBroadcaster
|
||||
{
|
||||
|
||||
/**
|
||||
* Sends a Notification which is passed in to the registered
|
||||
* Notification listeners on the ModelMBean as a
|
||||
* jmx.modelmbean.generic notification.
|
||||
*
|
||||
* @param ntfyObj The notification which is to be passed to
|
||||
* the 'handleNotification' method of the listener object.
|
||||
*
|
||||
* @exception MBeanException Wraps a distributed communication Exception.
|
||||
* @exception RuntimeOperationsException Wraps an IllegalArgumentException:
|
||||
* The Notification object passed in parameter is null.
|
||||
*
|
||||
*/
|
||||
|
||||
public void sendNotification(Notification ntfyObj)
|
||||
throws MBeanException, RuntimeOperationsException;
|
||||
|
||||
/**
|
||||
* Sends a Notification which contains the text string that is passed in
|
||||
* to the registered Notification listeners on the ModelMBean.
|
||||
*
|
||||
* @param ntfyText The text which is to be passed in the Notification to the 'handleNotification'
|
||||
* method of the listener object.
|
||||
* the constructed Notification will be:
|
||||
* type "jmx.modelmbean.generic"
|
||||
* source this ModelMBean instance
|
||||
* sequence 1
|
||||
*
|
||||
*
|
||||
* @exception MBeanException Wraps a distributed communication Exception.
|
||||
* @exception RuntimeOperationsException Wraps an IllegalArgumentException:
|
||||
* The Notification text string passed in parameter is null.
|
||||
*
|
||||
*/
|
||||
public void sendNotification(String ntfyText)
|
||||
throws MBeanException, RuntimeOperationsException;
|
||||
|
||||
/**
|
||||
* Sends an attributeChangeNotification which is passed in to
|
||||
* the registered attributeChangeNotification listeners on the
|
||||
* ModelMBean.
|
||||
*
|
||||
* @param notification The notification which is to be passed
|
||||
* to the 'handleNotification' method of the listener object.
|
||||
*
|
||||
* @exception MBeanException Wraps a distributed communication Exception.
|
||||
* @exception RuntimeOperationsException Wraps an IllegalArgumentException: The AttributeChangeNotification object passed in parameter is null.
|
||||
*
|
||||
*/
|
||||
public void sendAttributeChangeNotification(AttributeChangeNotification notification)
|
||||
throws MBeanException, RuntimeOperationsException;
|
||||
|
||||
|
||||
/**
|
||||
* Sends an attributeChangeNotification which contains the old value and new value for the
|
||||
* attribute to the registered AttributeChangeNotification listeners on the ModelMBean.
|
||||
* <P>
|
||||
* @param oldValue The original value for the Attribute
|
||||
* @param newValue The current value for the Attribute
|
||||
* <PRE>
|
||||
* The constructed attributeChangeNotification will be:
|
||||
* type "jmx.attribute.change"
|
||||
* source this ModelMBean instance
|
||||
* sequence 1
|
||||
* attributeName oldValue.getName()
|
||||
* attributeType oldValue's class
|
||||
* attributeOldValue oldValue.getValue()
|
||||
* attributeNewValue newValue.getValue()
|
||||
* </PRE>
|
||||
*
|
||||
* @exception MBeanException Wraps a distributed communication Exception.
|
||||
* @exception RuntimeOperationsException Wraps an IllegalArgumentException: An Attribute object passed in parameter is null
|
||||
* or the names of the two Attribute objects in parameter are not the same.
|
||||
*/
|
||||
public void sendAttributeChangeNotification(Attribute oldValue, Attribute newValue)
|
||||
throws MBeanException, RuntimeOperationsException;
|
||||
|
||||
|
||||
/**
|
||||
* Registers an object which implements the NotificationListener interface as a listener. This
|
||||
* object's 'handleNotification()' method will be invoked when any attributeChangeNotification is issued through
|
||||
* or by the ModelMBean. This does not include other Notifications. They must be registered
|
||||
* for independently. An AttributeChangeNotification will be generated for this attributeName.
|
||||
*
|
||||
* @param listener The listener object which will handles notifications emitted by the registered MBean.
|
||||
* @param attributeName The name of the ModelMBean attribute for which to receive change notifications.
|
||||
* If null, then all attribute changes will cause an attributeChangeNotification to be issued.
|
||||
* @param handback The context to be sent to the listener with the notification when a notification is emitted.
|
||||
*
|
||||
* @exception IllegalArgumentException The listener cannot be null.
|
||||
* @exception MBeanException Wraps a distributed communication Exception.
|
||||
* @exception RuntimeOperationsException Wraps an IllegalArgumentException The attribute name passed in parameter does not exist.
|
||||
*
|
||||
* @see #removeAttributeChangeNotificationListener
|
||||
*/
|
||||
public void addAttributeChangeNotificationListener(NotificationListener listener,
|
||||
String attributeName,
|
||||
Object handback)
|
||||
throws MBeanException, RuntimeOperationsException, IllegalArgumentException;
|
||||
|
||||
|
||||
/**
|
||||
* Removes a listener for attributeChangeNotifications from the RequiredModelMBean.
|
||||
*
|
||||
* @param listener The listener name which was handling notifications emitted by the registered MBean.
|
||||
* This method will remove all information related to this listener.
|
||||
* @param attributeName The attribute for which the listener no longer wants to receive attributeChangeNotifications.
|
||||
* If null the listener will be removed for all attributeChangeNotifications.
|
||||
*
|
||||
* @exception ListenerNotFoundException The listener is not registered in the MBean or is null.
|
||||
* @exception MBeanException Wraps a distributed communication Exception.
|
||||
* @exception RuntimeOperationsException Wraps an IllegalArgumentException If the inAttributeName parameter does not
|
||||
* correspond to an attribute name.
|
||||
*
|
||||
* @see #addAttributeChangeNotificationListener
|
||||
*/
|
||||
|
||||
public void removeAttributeChangeNotificationListener(NotificationListener listener,
|
||||
String attributeName)
|
||||
throws MBeanException, RuntimeOperationsException, ListenerNotFoundException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,420 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @author IBM Corp.
|
||||
*
|
||||
* Copyright IBM Corp. 1999-2000. All rights reserved.
|
||||
*/
|
||||
|
||||
package javax.management.modelmbean;
|
||||
|
||||
import static com.sun.jmx.defaults.JmxProperties.MODELMBEAN_LOGGER;
|
||||
import com.sun.jmx.mbeanserver.GetPropertyAction;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamField;
|
||||
import java.security.AccessController;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.management.Descriptor;
|
||||
import javax.management.DescriptorAccess;
|
||||
import javax.management.MBeanNotificationInfo;
|
||||
import javax.management.RuntimeOperationsException;
|
||||
|
||||
/**
|
||||
* <p>The ModelMBeanNotificationInfo object describes a notification emitted
|
||||
* by a ModelMBean.
|
||||
* It is a subclass of MBeanNotificationInfo with the addition of an
|
||||
* associated Descriptor and an implementation of the Descriptor interface.</p>
|
||||
*
|
||||
* <P id="descriptor">
|
||||
* The fields in the descriptor are defined, but not limited to, the following.
|
||||
* Note that when the Type in this table is Number, a String that is the decimal
|
||||
* representation of a Long can also be used.</P>
|
||||
*
|
||||
* <table border="1" cellpadding="5" summary="ModelMBeanNotificationInfo Fields">
|
||||
* <tr><th>Name</th><th>Type</th><th>Meaning</th></tr>
|
||||
* <tr><td>name</td><td>String</td>
|
||||
* <td>Notification name.</td></tr>
|
||||
* <tr><td>descriptorType</td><td>String</td>
|
||||
* <td>Must be "notification".</td></tr>
|
||||
* <tr><td>severity</td><td>Number</td>
|
||||
* <td>0-6 where 0: unknown; 1: non-recoverable;
|
||||
* 2: critical, failure; 3: major, severe;
|
||||
* 4: minor, marginal, error; 5: warning;
|
||||
* 6: normal, cleared, informative</td></tr>
|
||||
* <tr><td>messageID</td><td>String</td>
|
||||
* <td>Unique key for message text (to allow translation, analysis).</td></tr>
|
||||
* <tr><td>messageText</td><td>String</td>
|
||||
* <td>Text of notification.</td></tr>
|
||||
* <tr><td>log</td><td>String</td>
|
||||
* <td>T - log message, F - do not log message.</td></tr>
|
||||
* <tr><td>logfile</td><td>String</td>
|
||||
* <td>fully qualified file name appropriate for operating system.</td></tr>
|
||||
* <tr><td>visibility</td><td>Number</td>
|
||||
* <td>1-4 where 1: always visible 4: rarely visible.</td></tr>
|
||||
* <tr><td>presentationString</td><td>String</td>
|
||||
* <td>XML formatted string to allow presentation of data.</td></tr>
|
||||
* </table>
|
||||
*
|
||||
* <p>The default descriptor contains the name, descriptorType,
|
||||
* displayName and severity(=6) fields. The default value of the name
|
||||
* and displayName fields is the name of the Notification class (as
|
||||
* specified by the <code>name</code> parameter of the
|
||||
* ModelMBeanNotificationInfo constructor).</p>
|
||||
*
|
||||
* <p>The <b>serialVersionUID</b> of this class is <code>-7445681389570207141L</code>.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
|
||||
@SuppressWarnings("serial") // serialVersionUID is not constant
|
||||
public class ModelMBeanNotificationInfo
|
||||
extends MBeanNotificationInfo
|
||||
implements DescriptorAccess {
|
||||
|
||||
// Serialization compatibility stuff:
|
||||
// Two serial forms are supported in this class. The selected form
|
||||
// depends on system property "jmx.serial.form":
|
||||
// - "1.0" for JMX 1.0
|
||||
// - any other value for JMX 1.1 and higher
|
||||
//
|
||||
// Serial version for old serial form
|
||||
private static final long oldSerialVersionUID = -5211564525059047097L;
|
||||
//
|
||||
// Serial version for new serial form
|
||||
private static final long newSerialVersionUID = -7445681389570207141L;
|
||||
//
|
||||
// Serializable fields in old serial form
|
||||
private static final ObjectStreamField[] oldSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("notificationDescriptor", Descriptor.class),
|
||||
new ObjectStreamField("currClass", String.class)
|
||||
};
|
||||
//
|
||||
// Serializable fields in new serial form
|
||||
private static final ObjectStreamField[] newSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("notificationDescriptor", Descriptor.class)
|
||||
};
|
||||
//
|
||||
// Actual serial version and serial form
|
||||
private static final long serialVersionUID;
|
||||
/**
|
||||
* @serialField notificationDescriptor Descriptor The descriptor
|
||||
* containing the appropriate metadata for this instance
|
||||
*/
|
||||
private static final ObjectStreamField[] serialPersistentFields;
|
||||
private static boolean compat = false;
|
||||
static {
|
||||
try {
|
||||
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
|
||||
String form = AccessController.doPrivileged(act);
|
||||
compat = (form != null && form.equals("1.0"));
|
||||
} catch (Exception e) {
|
||||
// OK: No compat with 1.0
|
||||
}
|
||||
if (compat) {
|
||||
serialPersistentFields = oldSerialPersistentFields;
|
||||
serialVersionUID = oldSerialVersionUID;
|
||||
} else {
|
||||
serialPersistentFields = newSerialPersistentFields;
|
||||
serialVersionUID = newSerialVersionUID;
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Serialization compatibility stuff
|
||||
|
||||
/**
|
||||
* @serial The descriptor containing the appropriate metadata for
|
||||
* this instance
|
||||
*/
|
||||
private Descriptor notificationDescriptor;
|
||||
|
||||
private static final String currClass = "ModelMBeanNotificationInfo";
|
||||
|
||||
/**
|
||||
* Constructs a ModelMBeanNotificationInfo object with a default
|
||||
* descriptor.
|
||||
*
|
||||
* @param notifTypes The array of strings (in dot notation) containing
|
||||
* the notification types that may be emitted.
|
||||
* @param name The name of the Notification class.
|
||||
* @param description A human readable description of the
|
||||
* Notification. Optional.
|
||||
**/
|
||||
public ModelMBeanNotificationInfo(String[] notifTypes,
|
||||
String name,
|
||||
String description) {
|
||||
this(notifTypes,name,description,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a ModelMBeanNotificationInfo object.
|
||||
*
|
||||
* @param notifTypes The array of strings (in dot notation)
|
||||
* containing the notification types that may be emitted.
|
||||
* @param name The name of the Notification class.
|
||||
* @param description A human readable description of the Notification.
|
||||
* Optional.
|
||||
* @param descriptor An instance of Descriptor containing the
|
||||
* appropriate metadata for this instance of the
|
||||
* MBeanNotificationInfo. If it is null a default descriptor
|
||||
* will be created. If the descriptor does not contain the
|
||||
* fields "displayName" or "severity",
|
||||
* the missing ones are added with their default values.
|
||||
*
|
||||
* @exception RuntimeOperationsException Wraps an
|
||||
* {@link IllegalArgumentException}. The descriptor is invalid, or
|
||||
* descriptor field "name" is not equal to parameter name, or
|
||||
* descriptor field "descriptorType" is not equal to "notification".
|
||||
*
|
||||
**/
|
||||
public ModelMBeanNotificationInfo(String[] notifTypes,
|
||||
String name,
|
||||
String description,
|
||||
Descriptor descriptor) {
|
||||
super(notifTypes, name, description);
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanNotificationInfo.class.getName(),
|
||||
"ModelMBeanNotificationInfo", "Entry");
|
||||
}
|
||||
notificationDescriptor = validDescriptor(descriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ModelMBeanNotificationInfo object from this
|
||||
* ModelMBeanNotfication Object.
|
||||
*
|
||||
* @param inInfo the ModelMBeanNotificationInfo to be duplicated
|
||||
*
|
||||
**/
|
||||
public ModelMBeanNotificationInfo(ModelMBeanNotificationInfo inInfo) {
|
||||
this(inInfo.getNotifTypes(),
|
||||
inInfo.getName(),
|
||||
inInfo.getDescription(),inInfo.getDescriptor());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a new ModelMBeanNotificationInfo which is a
|
||||
* duplicate of this ModelMBeanNotificationInfo.
|
||||
**/
|
||||
public Object clone () {
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanNotificationInfo.class.getName(),
|
||||
"clone()", "Entry");
|
||||
}
|
||||
return(new ModelMBeanNotificationInfo(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the associated Descriptor for the
|
||||
* ModelMBeanNotificationInfo.
|
||||
*
|
||||
* @return Descriptor associated with the
|
||||
* ModelMBeanNotificationInfo object.
|
||||
*
|
||||
* @see #setDescriptor
|
||||
**/
|
||||
public Descriptor getDescriptor() {
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanNotificationInfo.class.getName(),
|
||||
"getDescriptor()", "Entry");
|
||||
}
|
||||
|
||||
if (notificationDescriptor == null) {
|
||||
// Dead code. Should never happen.
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanNotificationInfo.class.getName(),
|
||||
"getDescriptor()", "Descriptor value is null, " +
|
||||
"setting descriptor to default values");
|
||||
}
|
||||
notificationDescriptor = validDescriptor(null);
|
||||
}
|
||||
|
||||
return((Descriptor)notificationDescriptor.clone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets associated Descriptor (full replace) for the
|
||||
* ModelMBeanNotificationInfo If the new Descriptor is null,
|
||||
* then the associated Descriptor reverts to a default
|
||||
* descriptor. The Descriptor is validated before it is
|
||||
* assigned. If the new Descriptor is invalid, then a
|
||||
* RuntimeOperationsException wrapping an
|
||||
* IllegalArgumentException is thrown.
|
||||
*
|
||||
* @param inDescriptor replaces the Descriptor associated with the
|
||||
* ModelMBeanNotification interface
|
||||
*
|
||||
* @exception RuntimeOperationsException Wraps an
|
||||
* {@link IllegalArgumentException} for invalid Descriptor.
|
||||
*
|
||||
* @see #getDescriptor
|
||||
**/
|
||||
public void setDescriptor(Descriptor inDescriptor) {
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanNotificationInfo.class.getName(),
|
||||
"setDescriptor(Descriptor)", "Entry");
|
||||
}
|
||||
notificationDescriptor = validDescriptor(inDescriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a human readable string containing
|
||||
* ModelMBeanNotificationInfo.
|
||||
*
|
||||
* @return a string describing this object.
|
||||
**/
|
||||
public String toString() {
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanNotificationInfo.class.getName(),
|
||||
"toString()", "Entry");
|
||||
}
|
||||
|
||||
final StringBuilder retStr = new StringBuilder();
|
||||
|
||||
retStr.append("ModelMBeanNotificationInfo: ")
|
||||
.append(this.getName());
|
||||
|
||||
retStr.append(" ; Description: ")
|
||||
.append(this.getDescription());
|
||||
|
||||
retStr.append(" ; Descriptor: ")
|
||||
.append(this.getDescriptor());
|
||||
|
||||
retStr.append(" ; Types: ");
|
||||
String[] nTypes = this.getNotifTypes();
|
||||
for (int i=0; i < nTypes.length; i++) {
|
||||
if (i > 0) retStr.append(", ");
|
||||
retStr.append(nTypes[i]);
|
||||
}
|
||||
return retStr.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clones the passed in Descriptor, sets default values, and checks for validity.
|
||||
* If the Descriptor is invalid (for instance by having the wrong "name"),
|
||||
* this indicates programming error and a RuntimeOperationsException will be thrown.
|
||||
*
|
||||
* The following fields will be defaulted if they are not already set:
|
||||
* descriptorType="notification",displayName=this.getName(),
|
||||
* name=this.getName(),severity="6"
|
||||
*
|
||||
*
|
||||
* @param in Descriptor to be checked, or null which is equivalent to an
|
||||
* empty Descriptor.
|
||||
* @exception RuntimeOperationsException if Descriptor is invalid
|
||||
*/
|
||||
private Descriptor validDescriptor(final Descriptor in) throws RuntimeOperationsException {
|
||||
Descriptor clone;
|
||||
boolean defaulted = (in == null);
|
||||
if (defaulted) {
|
||||
clone = new DescriptorSupport();
|
||||
MODELMBEAN_LOGGER.finer("Null Descriptor, creating new.");
|
||||
} else {
|
||||
clone = (Descriptor) in.clone();
|
||||
}
|
||||
|
||||
//Setting defaults.
|
||||
if (defaulted && clone.getFieldValue("name")==null) {
|
||||
clone.setField("name", this.getName());
|
||||
MODELMBEAN_LOGGER.finer("Defaulting Descriptor name to " + this.getName());
|
||||
}
|
||||
if (defaulted && clone.getFieldValue("descriptorType")==null) {
|
||||
clone.setField("descriptorType", "notification");
|
||||
MODELMBEAN_LOGGER.finer("Defaulting descriptorType to \"notification\"");
|
||||
}
|
||||
if (clone.getFieldValue("displayName") == null) {
|
||||
clone.setField("displayName",this.getName());
|
||||
MODELMBEAN_LOGGER.finer("Defaulting Descriptor displayName to " + this.getName());
|
||||
}
|
||||
if (clone.getFieldValue("severity") == null) {
|
||||
clone.setField("severity", "6");
|
||||
MODELMBEAN_LOGGER.finer("Defaulting Descriptor severity field to 6");
|
||||
}
|
||||
|
||||
//Checking validity
|
||||
if (!clone.isValid()) {
|
||||
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
|
||||
"The isValid() method of the Descriptor object itself returned false,"+
|
||||
"one or more required fields are invalid. Descriptor:" + clone.toString());
|
||||
}
|
||||
if (!getName().equalsIgnoreCase((String) clone.getFieldValue("name"))) {
|
||||
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
|
||||
"The Descriptor \"name\" field does not match the object described. " +
|
||||
" Expected: "+ this.getName() + " , was: " + clone.getFieldValue("name"));
|
||||
}
|
||||
if (!"notification".equalsIgnoreCase((String) clone.getFieldValue("descriptorType"))) {
|
||||
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
|
||||
"The Descriptor \"descriptorType\" field does not match the object described. " +
|
||||
" Expected: \"notification\" ," + " was: " + clone.getFieldValue("descriptorType"));
|
||||
}
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes a {@link ModelMBeanNotificationInfo} from an
|
||||
* {@link ObjectInputStream}.
|
||||
**/
|
||||
private void readObject(ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException {
|
||||
// New serial form ignores extra field "currClass"
|
||||
in.defaultReadObject();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serializes a {@link ModelMBeanNotificationInfo} to an
|
||||
* {@link ObjectOutputStream}.
|
||||
**/
|
||||
private void writeObject(ObjectOutputStream out)
|
||||
throws IOException {
|
||||
if (compat) {
|
||||
// Serializes this instance in the old serial form
|
||||
//
|
||||
ObjectOutputStream.PutField fields = out.putFields();
|
||||
fields.put("notificationDescriptor", notificationDescriptor);
|
||||
fields.put("currClass", currClass);
|
||||
out.writeFields();
|
||||
} else {
|
||||
// Serializes this instance in the new serial form
|
||||
//
|
||||
out.defaultWriteObject();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,542 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @author IBM Corp.
|
||||
*
|
||||
* Copyright IBM Corp. 1999-2000. All rights reserved.
|
||||
*/
|
||||
|
||||
package javax.management.modelmbean;
|
||||
|
||||
import static com.sun.jmx.defaults.JmxProperties.MODELMBEAN_LOGGER;
|
||||
import com.sun.jmx.mbeanserver.GetPropertyAction;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamField;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.AccessController;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.management.Descriptor;
|
||||
import javax.management.DescriptorAccess;
|
||||
import javax.management.DescriptorKey;
|
||||
import javax.management.MBeanOperationInfo;
|
||||
import javax.management.MBeanParameterInfo;
|
||||
import javax.management.RuntimeOperationsException;
|
||||
|
||||
/**
|
||||
* <p>The ModelMBeanOperationInfo object describes a management operation of
|
||||
* the ModelMBean. It is a subclass of MBeanOperationInfo with the addition
|
||||
* of an associated Descriptor and an implementation of the DescriptorAccess
|
||||
* interface.</p>
|
||||
*
|
||||
* <P id="descriptor">
|
||||
* The fields in the descriptor are defined, but not limited to, the following.
|
||||
* Note that when the Type in this table is Number, a String that is the decimal
|
||||
* representation of a Long can also be used.</P>
|
||||
*
|
||||
* <table border="1" cellpadding="5" summary="ModelMBeanOperationInfo Fields">
|
||||
* <tr><th>Name</th><th>Type</th><th>Meaning</th></tr>
|
||||
* <tr><td>name</td><td>String</td>
|
||||
* <td>Operation name.</td></tr>
|
||||
* <tr><td>descriptorType</td><td>String</td>
|
||||
* <td>Must be "operation".</td></tr>
|
||||
* <tr><td>class</td><td>String</td>
|
||||
* <td>Class where method is defined (fully qualified).</td></tr>
|
||||
* <tr><td>role</td><td>String</td>
|
||||
* <td>Must be "operation", "getter", or "setter".</td></tr>
|
||||
* <tr><td>targetObject</td><td>Object</td>
|
||||
* <td>Object on which to execute this method.</td></tr>
|
||||
* <tr><td>targetType</td><td>String</td>
|
||||
* <td>type of object reference for targetObject. Can be:
|
||||
* ObjectReference | Handle | EJBHandle | IOR | RMIReference.</td></tr>
|
||||
* <tr><td>value</td><td>Object</td>
|
||||
* <td>Cached value for operation.</td></tr>
|
||||
* <tr><td>displayName</td><td>String</td>
|
||||
* <td>Human readable display name of the operation.</td>
|
||||
* <tr><td>currencyTimeLimit</td><td>Number</td>
|
||||
* <td>How long cached value is valid.</td></tr>
|
||||
* <tr><td>lastUpdatedTimeStamp</td><td>Number</td>
|
||||
* <td>When cached value was set.</td></tr>
|
||||
* <tr><td>visibility</td><td>Number</td>
|
||||
* <td>1-4 where 1: always visible 4: rarely visible.</td></tr>
|
||||
* <tr><td>presentationString</td><td>String</td>
|
||||
* <td>XML formatted string to describe how to present operation</td></tr>
|
||||
* </table>
|
||||
*
|
||||
* <p>The default descriptor will have name, descriptorType, displayName and
|
||||
* role fields set. The default value of the name and displayName fields is
|
||||
* the operation name.</p>
|
||||
*
|
||||
* <p><b>Note:</b> because of inconsistencies in previous versions of
|
||||
* this specification, it is recommended not to use negative or zero
|
||||
* values for <code>currencyTimeLimit</code>. To indicate that a
|
||||
* cached value is never valid, omit the
|
||||
* <code>currencyTimeLimit</code> field. To indicate that it is
|
||||
* always valid, use a very large number for this field.</p>
|
||||
*
|
||||
* <p>The <b>serialVersionUID</b> of this class is <code>6532732096650090465L</code>.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
|
||||
@SuppressWarnings("serial") // serialVersionUID is not constant
|
||||
public class ModelMBeanOperationInfo extends MBeanOperationInfo
|
||||
implements DescriptorAccess
|
||||
{
|
||||
|
||||
// Serialization compatibility stuff:
|
||||
// Two serial forms are supported in this class. The selected form depends
|
||||
// on system property "jmx.serial.form":
|
||||
// - "1.0" for JMX 1.0
|
||||
// - any other value for JMX 1.1 and higher
|
||||
//
|
||||
// Serial version for old serial form
|
||||
private static final long oldSerialVersionUID = 9087646304346171239L;
|
||||
//
|
||||
// Serial version for new serial form
|
||||
private static final long newSerialVersionUID = 6532732096650090465L;
|
||||
//
|
||||
// Serializable fields in old serial form
|
||||
private static final ObjectStreamField[] oldSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("operationDescriptor", Descriptor.class),
|
||||
new ObjectStreamField("currClass", String.class)
|
||||
};
|
||||
//
|
||||
// Serializable fields in new serial form
|
||||
private static final ObjectStreamField[] newSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("operationDescriptor", Descriptor.class)
|
||||
};
|
||||
//
|
||||
// Actual serial version and serial form
|
||||
private static final long serialVersionUID;
|
||||
/**
|
||||
* @serialField operationDescriptor Descriptor The descriptor
|
||||
* containing the appropriate metadata for this instance
|
||||
*/
|
||||
private static final ObjectStreamField[] serialPersistentFields;
|
||||
private static boolean compat = false;
|
||||
static {
|
||||
try {
|
||||
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
|
||||
String form = AccessController.doPrivileged(act);
|
||||
compat = (form != null && form.equals("1.0"));
|
||||
} catch (Exception e) {
|
||||
// OK: No compat with 1.0
|
||||
}
|
||||
if (compat) {
|
||||
serialPersistentFields = oldSerialPersistentFields;
|
||||
serialVersionUID = oldSerialVersionUID;
|
||||
} else {
|
||||
serialPersistentFields = newSerialPersistentFields;
|
||||
serialVersionUID = newSerialVersionUID;
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Serialization compatibility stuff
|
||||
|
||||
/**
|
||||
* @serial The descriptor containing the appropriate metadata for this instance
|
||||
*/
|
||||
private Descriptor operationDescriptor = validDescriptor(null);
|
||||
|
||||
private static final String currClass = "ModelMBeanOperationInfo";
|
||||
|
||||
/**
|
||||
* Constructs a ModelMBeanOperationInfo object with a default
|
||||
* descriptor. The {@link Descriptor} of the constructed
|
||||
* object will include fields contributed by any annotations
|
||||
* on the {@code Method} object that contain the {@link
|
||||
* DescriptorKey} meta-annotation.
|
||||
*
|
||||
* @param operationMethod The java.lang.reflect.Method object
|
||||
* describing the MBean operation.
|
||||
* @param description A human readable description of the operation.
|
||||
*/
|
||||
|
||||
public ModelMBeanOperationInfo(String description,
|
||||
Method operationMethod)
|
||||
{
|
||||
super(description, operationMethod);
|
||||
// create default descriptor
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanOperationInfo.class.getName(),
|
||||
"ModelMBeanOperationInfo(String,Method)",
|
||||
"Entry");
|
||||
}
|
||||
operationDescriptor = validDescriptor(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a ModelMBeanOperationInfo object. The {@link
|
||||
* Descriptor} of the constructed object will include fields
|
||||
* contributed by any annotations on the {@code Method} object
|
||||
* that contain the {@link DescriptorKey} meta-annotation.
|
||||
*
|
||||
* @param operationMethod The java.lang.reflect.Method object
|
||||
* describing the MBean operation.
|
||||
* @param description A human readable description of the
|
||||
* operation.
|
||||
* @param descriptor An instance of Descriptor containing the
|
||||
* appropriate metadata for this instance of the
|
||||
* ModelMBeanOperationInfo. If it is null a default
|
||||
* descriptor will be created. If the descriptor does not
|
||||
* contain the fields
|
||||
* "displayName" or "role", the missing ones are added with
|
||||
* their default values.
|
||||
*
|
||||
* @exception RuntimeOperationsException Wraps an
|
||||
* IllegalArgumentException. The descriptor is invalid; or
|
||||
* descriptor field "name" is not equal to
|
||||
* operation name; or descriptor field "DescriptorType" is
|
||||
* not equal to "operation"; or descriptor
|
||||
* optional field "role" is present but not equal to "operation",
|
||||
* "getter", or "setter".
|
||||
*
|
||||
*/
|
||||
|
||||
public ModelMBeanOperationInfo(String description,
|
||||
Method operationMethod,
|
||||
Descriptor descriptor)
|
||||
{
|
||||
|
||||
super(description, operationMethod);
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanOperationInfo.class.getName(),
|
||||
"ModelMBeanOperationInfo(String,Method,Descriptor)",
|
||||
"Entry");
|
||||
}
|
||||
operationDescriptor = validDescriptor(descriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a ModelMBeanOperationInfo object with a default descriptor.
|
||||
*
|
||||
* @param name The name of the method.
|
||||
* @param description A human readable description of the operation.
|
||||
* @param signature MBeanParameterInfo objects describing the
|
||||
* parameters(arguments) of the method.
|
||||
* @param type The type of the method's return value.
|
||||
* @param impact The impact of the method, one of INFO, ACTION,
|
||||
* ACTION_INFO, UNKNOWN.
|
||||
*/
|
||||
|
||||
public ModelMBeanOperationInfo(String name,
|
||||
String description,
|
||||
MBeanParameterInfo[] signature,
|
||||
String type,
|
||||
int impact)
|
||||
{
|
||||
|
||||
super(name, description, signature, type, impact);
|
||||
// create default descriptor
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanOperationInfo.class.getName(),
|
||||
"ModelMBeanOperationInfo(" +
|
||||
"String,String,MBeanParameterInfo[],String,int)",
|
||||
"Entry");
|
||||
}
|
||||
operationDescriptor = validDescriptor(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a ModelMBeanOperationInfo object.
|
||||
*
|
||||
* @param name The name of the method.
|
||||
* @param description A human readable description of the operation.
|
||||
* @param signature MBeanParameterInfo objects describing the
|
||||
* parameters(arguments) of the method.
|
||||
* @param type The type of the method's return value.
|
||||
* @param impact The impact of the method, one of INFO, ACTION,
|
||||
* ACTION_INFO, UNKNOWN.
|
||||
* @param descriptor An instance of Descriptor containing the
|
||||
* appropriate metadata for this instance of the
|
||||
* MBeanOperationInfo. If it is null then a default descriptor
|
||||
* will be created. If the descriptor does not contain
|
||||
* fields "displayName" or "role",
|
||||
* the missing ones are added with their default values.
|
||||
*
|
||||
* @exception RuntimeOperationsException Wraps an
|
||||
* IllegalArgumentException. The descriptor is invalid; or
|
||||
* descriptor field "name" is not equal to
|
||||
* operation name; or descriptor field "DescriptorType" is
|
||||
* not equal to "operation"; or descriptor optional
|
||||
* field "role" is present but not equal to "operation", "getter", or
|
||||
* "setter".
|
||||
*/
|
||||
|
||||
public ModelMBeanOperationInfo(String name,
|
||||
String description,
|
||||
MBeanParameterInfo[] signature,
|
||||
String type,
|
||||
int impact,
|
||||
Descriptor descriptor)
|
||||
{
|
||||
super(name, description, signature, type, impact);
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanOperationInfo.class.getName(),
|
||||
"ModelMBeanOperationInfo(String,String," +
|
||||
"MBeanParameterInfo[],String,int,Descriptor)",
|
||||
"Entry");
|
||||
}
|
||||
operationDescriptor = validDescriptor(descriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new ModelMBeanOperationInfo object from this
|
||||
* ModelMBeanOperation Object.
|
||||
*
|
||||
* @param inInfo the ModelMBeanOperationInfo to be duplicated
|
||||
*
|
||||
*/
|
||||
|
||||
public ModelMBeanOperationInfo(ModelMBeanOperationInfo inInfo)
|
||||
{
|
||||
super(inInfo.getName(),
|
||||
inInfo.getDescription(),
|
||||
inInfo.getSignature(),
|
||||
inInfo.getReturnType(),
|
||||
inInfo.getImpact());
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanOperationInfo.class.getName(),
|
||||
"ModelMBeanOperationInfo(ModelMBeanOperationInfo)",
|
||||
"Entry");
|
||||
}
|
||||
Descriptor newDesc = inInfo.getDescriptor();
|
||||
operationDescriptor = validDescriptor(newDesc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a new ModelMBeanOperationInfo which is a
|
||||
* duplicate of this ModelMBeanOperationInfo.
|
||||
*
|
||||
*/
|
||||
|
||||
public Object clone ()
|
||||
{
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanOperationInfo.class.getName(),
|
||||
"clone()", "Entry");
|
||||
}
|
||||
return(new ModelMBeanOperationInfo(this)) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a copy of the associated Descriptor of the
|
||||
* ModelMBeanOperationInfo.
|
||||
*
|
||||
* @return Descriptor associated with the
|
||||
* ModelMBeanOperationInfo object.
|
||||
*
|
||||
* @see #setDescriptor
|
||||
*/
|
||||
|
||||
public Descriptor getDescriptor()
|
||||
{
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanOperationInfo.class.getName(),
|
||||
"getDescriptor()", "Entry");
|
||||
}
|
||||
if (operationDescriptor == null) {
|
||||
operationDescriptor = validDescriptor(null);
|
||||
}
|
||||
|
||||
return((Descriptor) operationDescriptor.clone());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets associated Descriptor (full replace) for the
|
||||
* ModelMBeanOperationInfo If the new Descriptor is null, then
|
||||
* the associated Descriptor reverts to a default descriptor.
|
||||
* The Descriptor is validated before it is assigned. If the
|
||||
* new Descriptor is invalid, then a
|
||||
* RuntimeOperationsException wrapping an
|
||||
* IllegalArgumentException is thrown.
|
||||
*
|
||||
* @param inDescriptor replaces the Descriptor associated with the
|
||||
* ModelMBeanOperation.
|
||||
*
|
||||
* @exception RuntimeOperationsException Wraps an
|
||||
* IllegalArgumentException for invalid Descriptor.
|
||||
*
|
||||
* @see #getDescriptor
|
||||
*/
|
||||
public void setDescriptor(Descriptor inDescriptor)
|
||||
{
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanOperationInfo.class.getName(),
|
||||
"setDescriptor(Descriptor)", "Entry");
|
||||
}
|
||||
operationDescriptor = validDescriptor(inDescriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string containing the entire contents of the
|
||||
* ModelMBeanOperationInfo in human readable form.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
|
||||
MODELMBEAN_LOGGER.logp(Level.FINER,
|
||||
ModelMBeanOperationInfo.class.getName(),
|
||||
"toString()", "Entry");
|
||||
}
|
||||
String retStr =
|
||||
"ModelMBeanOperationInfo: " + this.getName() +
|
||||
" ; Description: " + this.getDescription() +
|
||||
" ; Descriptor: " + this.getDescriptor() +
|
||||
" ; ReturnType: " + this.getReturnType() +
|
||||
" ; Signature: ";
|
||||
MBeanParameterInfo[] pTypes = this.getSignature();
|
||||
for (int i=0; i < pTypes.length; i++)
|
||||
{
|
||||
retStr = retStr.concat((pTypes[i]).getType() + ", ");
|
||||
}
|
||||
return retStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones the passed in Descriptor, sets default values, and checks for validity.
|
||||
* If the Descriptor is invalid (for instance by having the wrong "name"),
|
||||
* this indicates programming error and a RuntimeOperationsException will be thrown.
|
||||
*
|
||||
* The following fields will be defaulted if they are not already set:
|
||||
* displayName=this.getName(),name=this.getName(),
|
||||
* descriptorType="operation", role="operation"
|
||||
*
|
||||
*
|
||||
* @param in Descriptor to be checked, or null which is equivalent to
|
||||
* an empty Descriptor.
|
||||
* @exception RuntimeOperationsException if Descriptor is invalid
|
||||
*/
|
||||
private Descriptor validDescriptor(final Descriptor in)
|
||||
throws RuntimeOperationsException {
|
||||
Descriptor clone;
|
||||
boolean defaulted = (in == null);
|
||||
if (defaulted) {
|
||||
clone = new DescriptorSupport();
|
||||
MODELMBEAN_LOGGER.finer("Null Descriptor, creating new.");
|
||||
} else {
|
||||
clone = (Descriptor) in.clone();
|
||||
}
|
||||
|
||||
//Setting defaults.
|
||||
if (defaulted && clone.getFieldValue("name")==null) {
|
||||
clone.setField("name", this.getName());
|
||||
MODELMBEAN_LOGGER.finer("Defaulting Descriptor name to " + this.getName());
|
||||
}
|
||||
if (defaulted && clone.getFieldValue("descriptorType")==null) {
|
||||
clone.setField("descriptorType", "operation");
|
||||
MODELMBEAN_LOGGER.finer("Defaulting descriptorType to \"operation\"");
|
||||
}
|
||||
if (clone.getFieldValue("displayName") == null) {
|
||||
clone.setField("displayName",this.getName());
|
||||
MODELMBEAN_LOGGER.finer("Defaulting Descriptor displayName to " + this.getName());
|
||||
}
|
||||
if (clone.getFieldValue("role") == null) {
|
||||
clone.setField("role","operation");
|
||||
MODELMBEAN_LOGGER.finer("Defaulting Descriptor role field to \"operation\"");
|
||||
}
|
||||
|
||||
//Checking validity
|
||||
if (!clone.isValid()) {
|
||||
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
|
||||
"The isValid() method of the Descriptor object itself returned false,"+
|
||||
"one or more required fields are invalid. Descriptor:" + clone.toString());
|
||||
}
|
||||
if (!getName().equalsIgnoreCase((String) clone.getFieldValue("name"))) {
|
||||
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
|
||||
"The Descriptor \"name\" field does not match the object described. " +
|
||||
" Expected: "+ this.getName() + " , was: " + clone.getFieldValue("name"));
|
||||
}
|
||||
if (!"operation".equalsIgnoreCase((String) clone.getFieldValue("descriptorType"))) {
|
||||
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
|
||||
"The Descriptor \"descriptorType\" field does not match the object described. " +
|
||||
" Expected: \"operation\" ," + " was: " + clone.getFieldValue("descriptorType"));
|
||||
}
|
||||
final String role = (String)clone.getFieldValue("role");
|
||||
if (!(role.equalsIgnoreCase("operation") ||
|
||||
role.equalsIgnoreCase("setter") ||
|
||||
role.equalsIgnoreCase("getter"))) {
|
||||
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
|
||||
"The Descriptor \"role\" field does not match the object described. " +
|
||||
" Expected: \"operation\", \"setter\", or \"getter\" ," + " was: " + clone.getFieldValue("role"));
|
||||
}
|
||||
final Object targetValue = clone.getFieldValue("targetType");
|
||||
if (targetValue != null) {
|
||||
if (!(targetValue instanceof java.lang.String)) {
|
||||
throw new RuntimeOperationsException(new IllegalArgumentException("Invalid Descriptor argument"),
|
||||
"The Descriptor field \"targetValue\" is invalid class. " +
|
||||
" Expected: java.lang.String, " + " was: " + targetValue.getClass().getName());
|
||||
}
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a {@link ModelMBeanOperationInfo} from an {@link ObjectInputStream}.
|
||||
*/
|
||||
private void readObject(ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException {
|
||||
// New serial form ignores extra field "currClass"
|
||||
in.defaultReadObject();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serializes a {@link ModelMBeanOperationInfo} to an {@link ObjectOutputStream}.
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream out)
|
||||
throws IOException {
|
||||
if (compat)
|
||||
{
|
||||
// Serializes this instance in the old serial form
|
||||
//
|
||||
ObjectOutputStream.PutField fields = out.putFields();
|
||||
fields.put("operationDescriptor", operationDescriptor);
|
||||
fields.put("currClass", currClass);
|
||||
out.writeFields();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Serializes this instance in the new serial form
|
||||
//
|
||||
out.defaultWriteObject();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
3007
jdkSrc/jdk8/javax/management/modelmbean/RequiredModelMBean.java
Normal file
3007
jdkSrc/jdk8/javax/management/modelmbean/RequiredModelMBean.java
Normal file
File diff suppressed because it is too large
Load Diff
158
jdkSrc/jdk8/javax/management/modelmbean/XMLParseException.java
Normal file
158
jdkSrc/jdk8/javax/management/modelmbean/XMLParseException.java
Normal file
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @author IBM Corp.
|
||||
*
|
||||
* Copyright IBM Corp. 1999-2000. All rights reserved.
|
||||
*/
|
||||
|
||||
|
||||
package javax.management.modelmbean;
|
||||
|
||||
import com.sun.jmx.mbeanserver.GetPropertyAction;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamField;
|
||||
import java.security.AccessController;
|
||||
|
||||
/**
|
||||
* This exception is thrown when an XML formatted string is being parsed into ModelMBean objects
|
||||
* or when XML formatted strings are being created from ModelMBean objects.
|
||||
*
|
||||
* It is also used to wrapper exceptions from XML parsers that may be used.
|
||||
*
|
||||
* <p>The <b>serialVersionUID</b> of this class is <code>3176664577895105181L</code>.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
@SuppressWarnings("serial") // serialVersionUID not constant
|
||||
public class XMLParseException
|
||||
extends Exception
|
||||
{
|
||||
// Serialization compatibility stuff:
|
||||
// Two serial forms are supported in this class. The selected form depends
|
||||
// on system property "jmx.serial.form":
|
||||
// - "1.0" for JMX 1.0
|
||||
// - any other value for JMX 1.1 and higher
|
||||
//
|
||||
// Serial version for old serial form
|
||||
private static final long oldSerialVersionUID = -7780049316655891976L;
|
||||
//
|
||||
// Serial version for new serial form
|
||||
private static final long newSerialVersionUID = 3176664577895105181L;
|
||||
//
|
||||
// Serializable fields in old serial form
|
||||
private static final ObjectStreamField[] oldSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("msgStr", String.class)
|
||||
};
|
||||
//
|
||||
// Serializable fields in new serial form
|
||||
private static final ObjectStreamField[] newSerialPersistentFields = { };
|
||||
//
|
||||
// Actual serial version and serial form
|
||||
private static final long serialVersionUID;
|
||||
private static final ObjectStreamField[] serialPersistentFields;
|
||||
private static boolean compat = false;
|
||||
static {
|
||||
try {
|
||||
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
|
||||
String form = AccessController.doPrivileged(act);
|
||||
compat = (form != null && form.equals("1.0"));
|
||||
} catch (Exception e) {
|
||||
// OK: No compat with 1.0
|
||||
}
|
||||
if (compat) {
|
||||
serialPersistentFields = oldSerialPersistentFields;
|
||||
serialVersionUID = oldSerialVersionUID;
|
||||
} else {
|
||||
serialPersistentFields = newSerialPersistentFields;
|
||||
serialVersionUID = newSerialVersionUID;
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Serialization compatibility stuff
|
||||
|
||||
/**
|
||||
* Default constructor .
|
||||
*/
|
||||
public XMLParseException ()
|
||||
{
|
||||
super("XML Parse Exception.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor taking a string.
|
||||
*
|
||||
* @param s the detail message.
|
||||
*/
|
||||
public XMLParseException (String s)
|
||||
{
|
||||
super("XML Parse Exception: " + s);
|
||||
}
|
||||
/**
|
||||
* Constructor taking a string and an exception.
|
||||
*
|
||||
* @param e the nested exception.
|
||||
* @param s the detail message.
|
||||
*/
|
||||
public XMLParseException (Exception e, String s)
|
||||
{
|
||||
super("XML Parse Exception: " + s + ":" + e.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes an {@link XMLParseException} from an {@link ObjectInputStream}.
|
||||
*/
|
||||
private void readObject(ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException {
|
||||
// New serial form ignores extra field "msgStr"
|
||||
in.defaultReadObject();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serializes an {@link XMLParseException} to an {@link ObjectOutputStream}.
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream out)
|
||||
throws IOException {
|
||||
if (compat)
|
||||
{
|
||||
// Serializes this instance in the old serial form
|
||||
//
|
||||
ObjectOutputStream.PutField fields = out.putFields();
|
||||
fields.put("msgStr", getMessage());
|
||||
out.writeFields();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Serializes this instance in the new serial form
|
||||
//
|
||||
out.defaultWriteObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user