/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*/
/**
* This class represents the meta data for ModelMBeans. Descriptors have been
* added on the meta data objects.
* <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 and operations
* exposed via the ModelMBeanInfo for the ModelMBean 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 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.
*
* MBeanException and RuntimeOperationsException must be thrown on every public
* method. This allows for wrapping exceptions from distributed
* communications (RMI, EJB, etc.)
*
* <p>The <b>serialVersionUID</b> of this class is
* <code>-1935722590756516193L</code>.
*
* @since 1.5
*/
@SuppressWarnings("serial")
// 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
//
// Serial version for new serial form
//
// Serializable fields in old serial form
{
};
//
// Serializable fields in new serial form
{
};
//
// Actual serial version and serial form
private static final long serialVersionUID;
/**
* @serialField modelMBeanDescriptor Descriptor The descriptor containing
* MBean wide policy
* @serialField modelMBeanAttributes ModelMBeanAttributeInfo[] The array of
* {@link ModelMBeanAttributeInfo} objects which
* have descriptors
* @serialField modelMBeanConstructors MBeanConstructorInfo[] The array of
* {@link ModelMBeanConstructorInfo} objects which
* have descriptors
* @serialField modelMBeanNotifications MBeanNotificationInfo[] The array of
* {@link ModelMBeanNotificationInfo} objects which
* have descriptors
* @serialField modelMBeanOperations MBeanOperationInfo[] The array of
* {@link ModelMBeanOperationInfo} objects which
* have descriptors
*/
private static boolean compat = false;
static {
try {
} catch (Exception e) {
// OK: No compat with 1.0
}
if (compat) {
} else {
}
}
//
// END Serialization compatibility stuff
/**
* @serial The descriptor containing MBean wide policy
*/
/* The following fields always have the same values as the
fields inherited from MBeanInfo and are retained only for
compatibility. By rewriting the serialization code we could
get rid of them.
These fields can't be final because they are assigned to by
readObject(). */
/**
* @serial The array of {@link ModelMBeanAttributeInfo} objects which
* have descriptors
*/
/**
* @serial The array of {@link ModelMBeanConstructorInfo} objects which
* have descriptors
*/
/**
* @serial The array of {@link ModelMBeanNotificationInfo} objects which
* have descriptors
*/
/**
* @serial The array of {@link ModelMBeanOperationInfo} objects which
* have descriptors
*/
/**
* Constructs a ModelMBeanInfoSupport which is a duplicate of the given
* ModelMBeanInfo. The returned object is a shallow copy of the given
* object. Neither the Descriptor nor the contained arrays
* ({@code ModelMBeanAttributeInfo[]} etc) are cloned. This method is
* chiefly of interest to modify the Descriptor of the returned instance
* via {@link #setDescriptor setDescriptor} without affecting the
* Descriptor of the original object.
*
* @param mbi the ModelMBeanInfo instance from which the ModelMBeanInfo
* being created is initialized.
*/
super(mbi.getClassName(),
mbi.getAttributes(),
mbi.getOperations(),
mbi.getNotifications());
try {
} catch (MBeanException mbe) {
ModelMBeanInfoSupport.class.getName(),
"ModelMBeanInfo(ModelMBeanInfo)",
"Could not get a valid modelMBeanDescriptor, " +
"setting a default Descriptor");
}
}
ModelMBeanInfoSupport.class.getName(),
"ModelMBeanInfo(ModelMBeanInfo)", "Exit");
}
}
/**
* Creates a ModelMBeanInfoSupport with the provided information,
* but the descriptor is a default.
* The default descriptor is: name=className, descriptorType="mbean",
* displayName=className, persistPolicy="never", log="F", visibility="1"
*
* @param className classname of the MBean
* @param description human readable description of the
* ModelMBean
* @param attributes array of ModelMBeanAttributeInfo objects
* which have descriptors
* @param constructors array of ModelMBeanConstructorInfo
* objects which have descriptors
* @param operations array of ModelMBeanOperationInfo objects
* which have descriptors
* @param notifications array of ModelMBeanNotificationInfo
* objects which have descriptors
*/
}
/**
* Creates a ModelMBeanInfoSupport with the provided information
* and the descriptor given in parameter.
*
* @param className classname of the MBean
* @param description human readable description of the
* ModelMBean
* @param attributes array of ModelMBeanAttributeInfo objects
* which have descriptors
* @param constructors array of ModelMBeanConstructorInfo
* objects which have descriptor
* @param operations array of ModelMBeanOperationInfo objects
* which have descriptor
* @param notifications array of ModelMBeanNotificationInfo
* objects which have descriptor
* @param mbeandescriptor descriptor to be used as the
* MBeanDescriptor containing MBean wide policy. If the
* descriptor is null, a default descriptor will be constructed.
* The default descriptor is:
* name=className, descriptorType="mbean", displayName=className,
* persistPolicy="never", log="F", visibility="1". If the descriptor
* does not contain all of these fields, the missing ones are
* added with these default values.
*
* @exception RuntimeOperationsException Wraps an
* IllegalArgumentException for invalid descriptor passed in
* parameter. (see {@link #getMBeanDescriptor
* getMBeanDescriptor} for the definition of a valid MBean
* descriptor.)
*/
super(className,
/* The values saved here are possibly null, but we
check this everywhere they are referenced. If at
some stage we replace null with an empty array
here, as we do in the superclass constructor
parameters, then we must also do this in
readObject(). */
ModelMBeanInfoSupport.class.getName(),
"ModelMBeanInfoSupport(String,String,ModelMBeanAttributeInfo[]," +
"ModelMBeanConstructorInfo[],ModelMBeanOperationInfo[]," +
"ModelMBeanNotificationInfo[],Descriptor)",
"Exit");
}
}
new ModelMBeanAttributeInfo[0];
new ModelMBeanConstructorInfo[0];
new ModelMBeanNotificationInfo[0];
new ModelMBeanOperationInfo[0];
// Java doc inherited from MOdelMBeanInfo interface
/**
* Returns a shallow clone of this instance. Neither the Descriptor nor
* the contained arrays ({@code ModelMBeanAttributeInfo[]} etc) are
* cloned. This method is chiefly of interest to modify the Descriptor
* of the clone via {@link #setDescriptor setDescriptor} without affecting
* the Descriptor of the original object.
*
* @return a shallow clone of this instance.
*/
return(new ModelMBeanInfoSupport(this));
}
throws MBeanException, RuntimeOperationsException {
ModelMBeanInfoSupport.class.getName(),
"getDescriptors(String)", "Entry");
}
inDescriptorType = "all";
}
// if no descriptors of that type, will return empty array
//
final Descriptor[] retList;
int numAttrs = 0;
for (int i=0; i < numAttrs; i++) {
retList[i] = (((ModelMBeanAttributeInfo)
attrList[i]).getDescriptor());
}
int numOpers = 0;
for (int i=0; i < numOpers; i++) {
retList[i] = (((ModelMBeanOperationInfo)
operList[i]).getDescriptor());
}
int numCons = 0;
for (int i=0; i < numCons; i++) {
retList[i] = (((ModelMBeanConstructorInfo)
consList[i]).getDescriptor());
}
int numNotifs = 0;
for (int i=0; i < numNotifs; i++) {
retList[i] = (((ModelMBeanNotificationInfo)
notifList[i]).getDescriptor());
}
int numAttrs = 0;
int numOpers = 0;
int numCons = 0;
int numNotifs = 0;
int j=0;
for (int i=0; i < numAttrs; i++) {
retList[j] = (((ModelMBeanAttributeInfo)
attrList[i]).getDescriptor());
j++;
}
for (int i=0; i < numCons; i++) {
retList[j] = (((ModelMBeanConstructorInfo)
consList[i]).getDescriptor());
j++;
}
for (int i=0; i < numOpers; i++) {
getDescriptor());
j++;
}
for (int i=0; i < numNotifs; i++) {
getDescriptor());
j++;
}
} else {
final IllegalArgumentException iae =
new IllegalArgumentException("Descriptor Type is invalid");
" the descriptors of the MBean";
}
ModelMBeanInfoSupport.class.getName(),
"getDescriptors(String)", "Exit");
}
return retList;
}
throws MBeanException, RuntimeOperationsException {
ModelMBeanInfoSupport.class.getName(),
"setDescriptors(Descriptor[])", "Entry");
}
if (inDescriptors==null) {
// throw RuntimeOperationsException - invalid descriptor
throw new RuntimeOperationsException(
new IllegalArgumentException("Descriptor list is invalid"),
"Exception occurred trying to set the descriptors " +
"of the MBeanInfo");
}
return;
}
}
ModelMBeanInfoSupport.class.getName(),
"setDescriptors(Descriptor[])", "Exit");
}
}
/**
* Returns a Descriptor requested by name.
*
* @param inDescriptorName The name of the descriptor.
*
* @return Descriptor containing a descriptor for the ModelMBean with the
* same name. If no descriptor is found, null is returned.
*
* @exception MBeanException Wraps a distributed communication Exception.
* @exception RuntimeOperationsException Wraps an IllegalArgumentException
* for null name.
*
* @see #setDescriptor
*/
throws MBeanException, RuntimeOperationsException {
ModelMBeanInfoSupport.class.getName(),
"getDescriptor(String)", "Entry");
}
}
throws MBeanException, RuntimeOperationsException {
if (inDescriptorName==null) {
// throw RuntimeOperationsException - invalid descriptor
throw new RuntimeOperationsException(
new IllegalArgumentException("Descriptor is invalid"),
"Exception occurred trying to set the descriptors of " +
"the MBeanInfo");
}
}
/* The logic here is a bit convoluted, because we are
dealing with two possible cases, depending on whether
inDescriptorType is null. If it's not null, then only
one of the following ifs will run, and it will either
return a descriptor or null. If inDescriptorType is
null, then all of the following ifs will run until one
of them finds a descriptor. */
return attr.getDescriptor();
if (inDescriptorType != null)
return null;
}
return oper.getDescriptor();
if (inDescriptorType != null)
return null;
}
return oper.getDescriptor();
if (inDescriptorType != null)
return null;
}
return notif.getDescriptor();
if (inDescriptorType != null)
return null;
}
if (inDescriptorType == null)
return null;
throw new RuntimeOperationsException(
new IllegalArgumentException("Descriptor Type is invalid"),
"Exception occurred trying to find the descriptors of the MBean");
}
throws MBeanException, RuntimeOperationsException {
"Exception occurred trying to set the descriptors of the MBean";
ModelMBeanInfoSupport.class.getName(),
"setDescriptor(Descriptor,String)", "Entry");
}
if (inDescriptor==null) {
inDescriptor = new DescriptorSupport();
}
if (inDescriptorType == null) {
ModelMBeanInfoSupport.class.getName(),
"setDescriptor(Descriptor,String)",
"descriptorType null in both String parameter and Descriptor, defaulting to "+ MMB);
}
}
if (inDescriptorName == null) {
ModelMBeanInfoSupport.class.getName(),
"setDescriptor(Descriptor,String)",
"descriptor name null, defaulting to "+ this.getClassName());
inDescriptorName = this.getClassName();
}
boolean found = false;
found = true;
int numAttrs = 0;
for (int i=0; i < numAttrs; i++) {
found = true;
.append("\t\n local: AttributeInfo descriptor is ")
.append("\t\n modelMBeanInfo: AttributeInfo descriptor is ")
ModelMBeanInfoSupport.class.getName(),
"setDescriptor(Descriptor,String)",
}
}
}
int numOpers = 0;
for (int i=0; i < numOpers; i++) {
found = true;
}
}
int numCons = 0;
for (int i=0; i < numCons; i++) {
found = true;
}
}
int numNotifs = 0;
for (int i=0; i < numNotifs; i++) {
found = true;
}
}
} else {
new IllegalArgumentException("Invalid descriptor type: " +
}
if (!found) {
new IllegalArgumentException("Descriptor name is invalid: " +
"type=" + inDescriptorType +
"; name=" + inDescriptorName);
}
ModelMBeanInfoSupport.class.getName(),
"setDescriptor(Descriptor,String)", "Exit");
}
}
throws MBeanException, RuntimeOperationsException {
ModelMBeanInfoSupport.class.getName(),
"getAttribute(String)", "Entry");
}
throw new RuntimeOperationsException(
new IllegalArgumentException("Attribute Name is null"),
"Exception occurred trying to get the " +
"ModelMBeanAttributeInfo of the MBean");
}
int numAttrs = 0;
.append("\t\n this.getAttributes() MBeanAttributeInfo Array ")
.append("\t\n this.modelMBeanAttributes MBeanAttributeInfo Array ")
ModelMBeanInfoSupport.class.getName(),
}
}
}
ModelMBeanInfoSupport.class.getName(),
"getAttribute(String)", "Exit");
}
return retInfo;
}
throws MBeanException, RuntimeOperationsException {
ModelMBeanInfoSupport.class.getName(),
"getOperation(String)", "Entry");
}
throw new RuntimeOperationsException(
new IllegalArgumentException("inName is null"),
"Exception occurred trying to get the " +
"ModelMBeanOperationInfo of the MBean");
}
int numOpers = 0;
}
}
ModelMBeanInfoSupport.class.getName(),
"getOperation(String)", "Exit");
}
return retInfo;
}
/**
* Returns the ModelMBeanConstructorInfo requested by name.
* If no ModelMBeanConstructorInfo exists for this name null is returned.
*
* @param inName the name of the constructor.
*
* @return the constructor info for the named constructor, or null
* if there is none.
*
* @exception MBeanException Wraps a distributed communication Exception.
* @exception RuntimeOperationsException Wraps an IllegalArgumentException
* for a null constructor name.
*/
throws MBeanException, RuntimeOperationsException {
ModelMBeanInfoSupport.class.getName(),
"getConstructor(String)", "Entry");
}
throw new RuntimeOperationsException(
new IllegalArgumentException("Constructor name is null"),
"Exception occurred trying to get the " +
"ModelMBeanConstructorInfo of the MBean");
}
int numCons = 0;
}
}
ModelMBeanInfoSupport.class.getName(),
"getConstructor(String)", "Exit");
}
return retInfo;
}
throws MBeanException, RuntimeOperationsException {
ModelMBeanInfoSupport.class.getName(),
"getNotification(String)", "Entry");
}
throw new RuntimeOperationsException(
new IllegalArgumentException("Notification name is null"),
"Exception occurred trying to get the " +
"ModelMBeanNotificationInfo of the MBean");
}
int numNotifs = 0;
}
}
ModelMBeanInfoSupport.class.getName(),
"getNotification(String)", "Exit");
}
return retInfo;
}
/* We override MBeanInfo.getDescriptor() to return our descriptor. */
/**
* @since 1.6
*/
return getMBeanDescriptorNoException();
}
return getMBeanDescriptorNoException();
}
ModelMBeanInfoSupport.class.getName(),
"getMBeanDescriptorNoException()", "Entry");
}
if (modelMBeanDescriptor == null)
ModelMBeanInfoSupport.class.getName(),
"getMBeanDescriptorNoException()",
"Exit, returning: " + modelMBeanDescriptor);
}
}
throws MBeanException, RuntimeOperationsException {
ModelMBeanInfoSupport.class.getName(),
"setMBeanDescriptor(Descriptor)", "Entry");
}
}
/**
* 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=className,name=className,descriptorType="mbean",
* persistPolicy="never", log="F", visibility="1"
*
* @param in Descriptor to be checked, or null which is equivalent to
* an empty Descriptor.
* @exception RuntimeOperationsException if Descriptor is invalid
*/
if (defaulted) {
clone = new DescriptorSupport();
} else {
}
//Setting defaults.
}
}
}
}
}
}
//Checking validity
"The isValid() method of the Descriptor object itself returned false,"+
}
"The Descriptor \"descriptorType\" field does not match the object described. " +
}
return clone;
}
/**
* Deserializes a {@link ModelMBeanInfoSupport} from an {@link ObjectInputStream}.
*/
throws IOException, ClassNotFoundException {
if (compat) {
// Read an object serialized in the old serial form
//
throw new NullPointerException("modelMBeanDescriptor");
}
throw new NullPointerException("mmbAttributes");
}
throw new NullPointerException("mmbConstructors");
}
throw new NullPointerException("mmbNotifications");
}
throw new NullPointerException("mmbOperations");
}
} else {
// Read an object serialized in the new serial form
//
}
}
/**
* Serializes a {@link ModelMBeanInfoSupport} to an {@link ObjectOutputStream}.
*/
throws IOException {
if (compat) {
// Serializes this instance in the old serial form
//
out.writeFields();
} else {
// Serializes this instance in the new serial form
//
}
}
}