This patch adds the missing from(CompositeData) methods to the two java.lang.management classes, along with two further classes these changes depend on.
Changelog:
2006-07-09 Andrew John Hughes <[EMAIL PROTECTED]>
* java/lang/management/MemoryUsage.java:
(from(javax.management.openmbean.CompositeData)):
Implemented.
* java/lang/management/ThreadInfo.java:
Changed to use open types throughout for the state.
(ThreadInfo(long,String,String,long,long,String,
long,String,long,long,boolean,StackTraceElement[])):
New constructor.
(checkAttribute(javax.management.openmbean.CompositeType,
String, javax.management.openmbean.OpenType)): New method.
(from(javax.management.openmbean.CompositeData)):
Implemented.
(getLockName()): Fixed to use new variable.
(getLockOwnerId()): Likewise.
(getLockOwnerName()): Likewise.
(getThreadId()): Likewise.
(getThreadName()): Likewise.
(getThreadState()): Likewise.
(toString()): Refactored to use new variables.
* javax/management/openmbean/ArrayType.java:
New file.
* javax/management/openmbean/CompositeType.java:
Variables should be transient, not volatile.
* javax/management/openmbean/OpenDataException.java:
(serialVersionUID): Added.
* javax/management/openmbean/SimpleType.java:
New file.
* javax/management/openmbean/TabularType.java
Variables should be transient, not volatile.
--
Andrew :-)
Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
public class gcj extends Freedom implements Java { ... }
Index: java/lang/management/MemoryUsage.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/management/MemoryUsage.java,v
retrieving revision 1.2
diff -u -3 -p -u -r1.2 MemoryUsage.java
--- java/lang/management/MemoryUsage.java 2 Jul 2006 20:57:29 -0000
1.2
+++ java/lang/management/MemoryUsage.java 9 Jul 2006 19:55:20 -0000
@@ -37,6 +37,9 @@ exception statement from your version. *
package java.lang.management;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.SimpleType;
/**
* <p>
* Retains information on the usage of a particular memory
@@ -146,6 +149,48 @@ public class MemoryUsage
}
/**
+ * <p>
+ * Returns a [EMAIL PROTECTED] MemoryUsage} instance using the values
+ * given in the supplied
+ * [EMAIL PROTECTED] javax.management.openmbean.CompositeData} object.
+ * The composite data instance should contain the following
+ * attributes:
+ * </p>
+ * <ul>
+ * <li>init</li>
+ * <li>used</li>
+ * <li>committed</li>
+ * <li>max</li>
+ * </ul>
+ * <p>
+ * All should have the type, <code>java.lang.Long</code>.
+ * </p>
+ *
+ * @param data the composite data structure to take values from.
+ * @return a new instance containing the values from the
+ * composite data structure, or <code>null</code>
+ * if the data structure was also <code>null</code>.
+ * @throws IllegalArgumentException if the composite data structure
+ * does not match the structure
+ * outlined above, or the values
+ * are invalid.
+ */
+ public static MemoryUsage from(CompositeData data)
+ {
+ if (data == null)
+ return null;
+ CompositeType type = data.getCompositeType();
+ ThreadInfo.checkAttribute(type, "init", SimpleType.LONG);
+ ThreadInfo.checkAttribute(type, "used", SimpleType.LONG);
+ ThreadInfo.checkAttribute(type, "committed", SimpleType.LONG);
+ ThreadInfo.checkAttribute(type, "max", SimpleType.LONG);
+ return new MemoryUsage(((Long) data.get("init")).longValue(),
+ ((Long) data.get("used")).longValue(),
+ ((Long) data.get("committed")).longValue(),
+ ((Long) data.get("max")).longValue());
+ }
+
+ /**
* Returns the amount of memory committed for use by this
* memory pool (in bytes). This amount is guaranteed to
* be available, unlike the maximum.
Index: java/lang/management/ThreadInfo.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/management/ThreadInfo.java,v
retrieving revision 1.3
diff -u -3 -p -u -r1.3 ThreadInfo.java
--- java/lang/management/ThreadInfo.java 2 Jul 2006 17:29:10 -0000
1.3
+++ java/lang/management/ThreadInfo.java 9 Jul 2006 19:55:20 -0000
@@ -37,6 +37,13 @@ exception statement from your version. *
package java.lang.management;
+import javax.management.openmbean.ArrayType;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenDataException;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+
/**
* <p>
* A class which maintains information about a particular
@@ -83,9 +90,19 @@ public class ThreadInfo
{
/**
- * The thread which this instance concerns.
+ * The id of the thread which this instance concerns.
+ */
+ private long threadId;
+
+ /**
+ * The name of the thread which this instance concerns.
+ */
+ private String threadName;
+
+ /**
+ * The state of the thread which this instance concerns.
*/
- private Thread thread;
+ private String threadState;
/**
* The number of times the thread has been blocked.
@@ -100,17 +117,24 @@ public class ThreadInfo
private long blockedTime;
/**
- * The monitor lock on which this thread is blocked
- * (if any).
+ * The name of the monitor lock on which this thread
+ * is blocked (if any).
*/
- private Object lock;
+ private String lockName;
/**
- * The thread which owns the monitor lock on which this
- * thread is blocked, or <code>null</code> if there is
- * no owner.
+ * The id of the thread which owns the monitor lock on
+ * which this thread is blocked, or <code>-1</code>
+ * if there is no owner.
*/
- private Thread lockOwner;
+ private long lockOwnerId;
+
+ /**
+ * The name of the thread which owns the monitor lock on
+ * which this thread is blocked, or <code>null</code>
+ * if there is no owner.
+ */
+ private String lockOwnerName;
/**
* The number of times the thread has been in a waiting
@@ -176,11 +200,60 @@ public class ThreadInfo
long waitedTime, boolean isInNative, boolean isSuspended,
StackTraceElement[] trace)
{
- this.thread = thread;
+ this(thread.getId(), thread.getName(), thread.getState(), blockedCount,
+ blockedTime, lock.getClass().getName() + "@" +
+ Integer.toHexString(System.identityHashCode(lock)), lockOwner.getId(),
+ lockOwner.getName(), waitedCount, waitedTime, isInNative, isSuspended,
+ trace);
+ }
+
+ /**
+ * Constructs a new [EMAIL PROTECTED] ThreadInfo} corresponding
+ * to the thread details specified.
+ *
+ * @param threadId the id of the thread on which this
+ * new instance will be based.
+ * @param threadName the name of the thread on which
+ * this new instance will be based.
+ * @param threadState the state of the thread on which
+ * this new instance will be based.
+ * @param blockedCount the number of times the thread
+ * has been blocked.
+ * @param blockedTime the accumulated number of milliseconds
+ * the specified thread has been blocked
+ * (only used with contention monitoring enabled)
+ * @param lockName the name of the monitor lock the thread is waiting for
+ * (only used if blocked)
+ * @param lockOwnerId the id of the thread which owns the monitor
+ * lock, or <code>-1</code> if it doesn't have an owner
+ * (only used if blocked)
+ * @param lockOwnerName the name of the thread which owns the monitor
+ * lock, or <code>null</code> if it doesn't have an
+ * owner (only used if blocked)
+ * @param waitedCount the number of times the thread has been in a
+ * waiting state.
+ * @param waitedTime the accumulated number of milliseconds the
+ * specified thread has been waiting
+ * (only used with contention monitoring enabled)
+ * @param isInNative true if the thread is in a native method.
+ * @param isSuspended true if the thread is suspended.
+ * @param trace the stack trace of the thread to a pre-determined
+ * depth (see VMThreadMXBeanImpl)
+ */
+ private ThreadInfo(long threadId, String threadName, String threadState,
+ long blockedCount, long blockedTime, String lockName,
+ long lockOwnerId, String lockOwnerName, long waitedCount,
+ long waitedTime, boolean isInNative, boolean isSuspended,
+ StackTraceElement[] trace)
+ {
+ this.threadId = threadId;
+ this.threadName = threadName;
+ this.threadState = threadState;
this.blockedCount = blockedCount;
this.blockedTime = blockedTime;
- this.lock = lock;
- this.lockOwner = lockOwner;
+ this.lockName = lockName;
+ this.lockOwnerId = lockOwnerId;
+ this.lockOwnerName = lockOwnerName;
this.waitedCount = waitedCount;
this.waitedTime = waitedTime;
this.isInNative = isInNative;
@@ -189,6 +262,145 @@ public class ThreadInfo
}
/**
+ * Checks for an attribute in a [EMAIL PROTECTED] CompositeData} structure
+ * with the correct type.
+ *
+ * @param ctype the composite data type to check.
+ * @param name the name of the attribute.
+ * @param type the type to check for.
+ * @throws IllegalArgumentException if the attribute is absent
+ * or of the wrong type.
+ */
+ static void checkAttribute(CompositeType ctype, String name,
+ OpenType type)
+ throws IllegalArgumentException
+ {
+ OpenType foundType = ctype.getType(name);
+ if (foundType == null)
+ throw new IllegalArgumentException("Could not find a field named " +
+ name);
+ if (!(foundType.equals(type)))
+ throw new IllegalArgumentException("Field " + name + " is not of " +
+ "type " + type.getClassName());
+ }
+
+ /**
+ * <p>
+ * Returns a [EMAIL PROTECTED] ThreadInfo} instance using the values
+ * given in the supplied
+ * [EMAIL PROTECTED] javax.management.openmbean.CompositeData} object.
+ * The composite data instance should contain the following
+ * attributes with the specified types:
+ * </p>
+ * <table>
+ * <th><td>Name</td><td>Type</td></th>
+ * <tr><td>threadId</td><td>java.lang.Long</td></tr>
+ * <tr><td>threadName</td><td>java.lang.String</td></tr>
+ * <tr><td>threadState</td><td>java.lang.String</td></tr>
+ * <tr><td>suspended</td><td>java.lang.Boolean</td></tr>
+ * <tr><td>inNative</td><td>java.lang.Boolean</td></tr>
+ * <tr><td>blockedCount</td><td>java.lang.Long</td></tr>
+ * <tr><td>blockedTime</td><td>java.lang.Long</td></tr>
+ * <tr><td>waitedCount</td><td>java.lang.Long</td></tr>
+ * <tr><td>waitedTime</td><td>java.lang.Long</td></tr>
+ * <tr><td>lockName</td><td>java.lang.String</td></tr>
+ * <tr><td>lockOwnerId</td><td>java.lang.Long</td></tr>
+ * <tr><td>lockOwnerName</td><td>java.lang.String</td></tr>
+ * <tr><td>stackTrace</td><td>javax.management.openmbean.CompositeData[]
+ * </td></tr>
+ * </table>
+ * <p>
+ * The stack trace is further described as:
+ * </p>
+ * <table>
+ * <th><td>Name</td><td>Type</td></th>
+ * <tr><td>className</td><td>java.lang.String</td></tr>
+ * <tr><td>methodName</td><td>java.lang.String</td></tr>
+ * <tr><td>fileName</td><td>java.lang.String</td></tr>
+ * <tr><td>lineNumber</td><td>java.lang.Integer</td></tr>
+ * <tr><td>nativeMethod</td><td>java.lang.Boolean</td></tr>
+ * </table>
+ *
+ * @param data the composite data structure to take values from.
+ * @return a new instance containing the values from the
+ * composite data structure, or <code>null</code>
+ * if the data structure was also <code>null</code>.
+ * @throws IllegalArgumentException if the composite data structure
+ * does not match the structure
+ * outlined above.
+ */
+ public static ThreadInfo from(CompositeData data)
+ {
+ if (data == null)
+ return null;
+ CompositeType type = data.getCompositeType();
+ checkAttribute(type, "threadId", SimpleType.LONG);
+ checkAttribute(type, "threadName", SimpleType.STRING);
+ checkAttribute(type, "threadState", SimpleType.STRING);
+ checkAttribute(type, "suspended", SimpleType.BOOLEAN);
+ checkAttribute(type, "inNative", SimpleType.BOOLEAN);
+ checkAttribute(type, "blockedCount", SimpleType.LONG);
+ checkAttribute(type, "blockedTime", SimpleType.LONG);
+ checkAttribute(type, "waitedCount", SimpleType.LONG);
+ checkAttribute(type, "waitedTime", SimpleType.LONG);
+ checkAttribute(type, "lockName", SimpleType.STRING);
+ checkAttribute(type, "lockOwnerId", SimpleType.LONG);
+ checkAttribute(type, "lockOwnerName", SimpleType.STRING);
+ try
+ {
+ CompositeType seType =
+ new CompositeType(StackTraceElement.class.getName(),
+ "An element of a stack trace",
+ new String[] { "className", "methodName",
+ "fileName", "lineNumber",
+ "nativeMethod"
+ },
+ new String[] { "Name of the class",
+ "Name of the method",
+ "Name of the source code file",
+ "Line number",
+ "True if this is a native method"
+ },
+ new OpenType[] {
+ SimpleType.STRING, SimpleType.STRING,
+ SimpleType.STRING, SimpleType.INTEGER,
+ SimpleType.BOOLEAN
+ });
+ checkAttribute(type, "stackTrace", new ArrayType(1, seType));
+ }
+ catch (OpenDataException e)
+ {
+ throw new IllegalStateException("Something went wrong in creating " +
+ "the composite data type for the " +
+ "stack trace element.", e);
+ }
+ CompositeData[] dTraces = (CompositeData[]) data.get("stackTrace");
+ StackTraceElement[] traces = new StackTraceElement[dTraces.length];
+ for (int a = 0; a < dTraces.length; ++a)
+ /* FIXME: We can't use the boolean as there is no available
+ constructor. */
+ traces[a] =
+ new StackTraceElement((String) dTraces[a].get("className"),
+ (String) dTraces[a].get("methodName"),
+ (String) dTraces[a].get("fileName"),
+ ((Integer)
+ dTraces[a].get("lineNumber")).intValue());
+ return new ThreadInfo(((Long) data.get("threadId")).longValue(),
+ (String) data.get("threadName"),
+ (String) data.get("threadState"),
+ ((Long) data.get("blockedCount")).longValue(),
+ ((Long) data.get("blockedTime")).longValue(),
+ (String) data.get("lockName"),
+ ((Long) data.get("lockOwnerId")).longValue(),
+ (String) data.get("lockOwnerName"),
+ ((Long) data.get("waitedCount")).longValue(),
+ ((Long) data.get("waitedTime")).longValue(),
+ ((Boolean) data.get("inNative")).booleanValue(),
+ ((Boolean) data.get("suspended")).booleanValue(),
+ traces);
+ }
+
+ /**
* Returns the number of times this thread has been
* in the [EMAIL PROTECTED] java.lang.Thread.State#BLOCKED} state.
* A thread enters this state when it is waiting to
@@ -272,10 +484,9 @@ public class ThreadInfo
*/
public String getLockName()
{
- if (thread.getState().equals("BLOCKED"))
+ if (threadState.equals("BLOCKED"))
return null;
- return lock.getClass().getName() + "@" +
- Integer.toHexString(System.identityHashCode(lock));
+ return lockName;
}
/**
@@ -291,11 +502,9 @@ public class ThreadInfo
*/
public long getLockOwnerId()
{
- if (thread.getState().equals("BLOCKED"))
- return -1;
- if (lockOwner == null)
+ if (threadState.equals("BLOCKED"))
return -1;
- return lockOwner.getId();
+ return lockOwnerId;
}
/**
@@ -311,11 +520,9 @@ public class ThreadInfo
*/
public String getLockOwnerName()
{
- if (thread.getState().equals("BLOCKED"))
- return null;
- if (lockOwner == null)
+ if (threadState.equals("BLOCKED"))
return null;
- return lockOwner.getName();
+ return lockOwnerName;
}
/**
@@ -350,7 +557,7 @@ public class ThreadInfo
*/
public long getThreadId()
{
- return thread.getId();
+ return threadId;
}
/**
@@ -361,7 +568,7 @@ public class ThreadInfo
*/
public String getThreadName()
{
- return thread.getName();
+ return threadName;
}
/**
@@ -372,7 +579,7 @@ public class ThreadInfo
*/
public String getThreadState()
{
- return thread.getState();
+ return threadState;
}
/**
@@ -480,17 +687,17 @@ public class ThreadInfo
*/
public String toString()
{
- String state = thread.getState();
return getClass().getName() +
- "[id=" + thread.getId() +
- ", name=" + thread.getName() +
- ", state=" + state +
+ "[id=" + threadId +
+ ", name=" + threadName +
+ ", state=" + threadState +
", blockedCount=" + blockedCount +
", waitedCount=" + waitedCount +
", isInNative=" + isInNative +
", isSuspended=" + isSuspended +
- (state.equals("BLOCKED") ? ", lock=" + lock +
- ", lockOwner=" + lockOwner : "") +
+ (threadState.equals("BLOCKED") ?
+ ", lockOwnerId=" + lockOwnerId +
+ ", lockOwnerName=" + lockOwnerName : "") +
"]";
}
Index: javax/management/openmbean/ArrayType.java
===================================================================
RCS file: javax/management/openmbean/ArrayType.java
diff -N javax/management/openmbean/ArrayType.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ javax/management/openmbean/ArrayType.java 9 Jul 2006 19:55:20 -0000
@@ -0,0 +1,313 @@
+/* ArrayType.java -- Open type descriptor for an array.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath 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 for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.management.openmbean;
+
+import java.lang.reflect.Array;
+
+import java.util.Arrays;
+
+/**
+ * The open type descriptor for arrays of open data values.
+ *
+ * @author Andrew John Hughes ([EMAIL PROTECTED])
+ * @since 1.5
+ */
+public class ArrayType
+ extends OpenType
+{
+
+ /**
+ * Compatible with JDK 1.5
+ */
+ private static final long serialVersionUID = 720504429830309770L;
+
+ /**
+ * The number of dimensions arrays of this type has.
+ */
+ private int dimension;
+
+ /**
+ * The element type of arrays of this type.
+ */
+ private OpenType elementType;
+
+ /**
+ * The hash code of this instance.
+ */
+ private transient Integer hashCode;
+
+ /**
+ * The <code>toString()</code> result of this instance.
+ */
+ private transient String string;
+
+ /**
+ * Returns the class name of the array, given the element
+ * class name and its dimensions.
+ *
+ * @param className the name of the class used by the
+ * array's elements.
+ * @param dim the dimensions of the array.
+ * @return the array's class name.
+ */
+ private static String getArrayClassName(String className, int dim)
+ {
+ char[] brackets = new char[dim];
+ Arrays.fill(brackets, '[');
+ return String.valueOf(brackets) + "L" + className;
+ }
+
+ /**
+ * <p>
+ * Constructs a new [EMAIL PROTECTED] ArrayType} instance for an array of the
+ * specified type with the supplied number of dimensions. The attributes
+ * used by the superclass, [EMAIL PROTECTED] OpenType}, are automatically
defined,
+ * based on these values. Both the class name and type name are set
+ * to the value returned by the [EMAIL PROTECTED] java.lang.Class#getName()}
of
+ * the array's class (i.e. the element type, preceded by n instances of
+ * '[' and an 'L', where n is the number of dimensions the array has).
+ * The description is based upon the template <code>n-dimension array
+ * of e</code>, where n is the number of dimensions of the array, and
+ * e is the element type. The class name of the actual elements is
+ * obtainable by calling [EMAIL PROTECTED] OpenType#getClassName()} on the
result
+ * of [EMAIL PROTECTED] #getElementOpenType()}.
+ * </p>
+ * <p>
+ * As an example, the array type returned by
+ * <code>new ArrayType(6, SimpleType.INTEGER)</code> has the following
+ * values:
+ * </p>
+ * <table>
+ * <th><td>Attribute</td><td>Value</td></th>
+ * <tr><td>Class Name</td><td><code>[[[[[[Ljava.lang.Integer;</code>
+ * </td></tr>
+ * <tr><td>Type Name</td><td><code>[[[[[[Ljava.lang.Integer;</code>
+ * </td></tr>
+ * <tr><td>Description</td><td><code>6-dimension array of
+ * java.lang.Integer</code></td></tr>
+ * <tr><td>Element Type Class Name</td><td><code>java.lang.Integer</code>
+ * </td></tr>
+ * </table>
+ * <p>
+ * The dimensions of the array must be equal to or greater than 1. The
+ * element type must be an instance of [EMAIL PROTECTED] SimpleType},
+ * [EMAIL PROTECTED] CompositeType} or [EMAIL PROTECTED] TabularType}.
+ * </p>
+ *
+ * @param dim the dimensions of the array.
+ * @param elementType the type of the elements of the array.
+ * @throws IllegalArgumentException if <code>dim</code> is less than 1.
+ * @throws OpenDataException if the element type is not an instance of either
+ * [EMAIL PROTECTED] SimpleType}, [EMAIL
PROTECTED] CompositeType}
+ * or [EMAIL PROTECTED] TabularType}.
+ */
+ public ArrayType(int dim, OpenType elementType)
+ throws OpenDataException
+ {
+ super(getArrayClassName(elementType.getClassName(), dim),
+ getArrayClassName(elementType.getClassName(), dim),
+ dim + "-dimension array of " + elementType.getClassName());
+ if (dim < 1)
+ throw new IllegalArgumentException("Dimensions must be greater " +
+ "than or equal to 1.");
+ if (!(elementType instanceof SimpleType ||
+ elementType instanceof CompositeType ||
+ elementType instanceof TabularType))
+ throw new OpenDataException("The element type must be a simple " +
+ "type, a composite type or a tabular " +
+ "type.");
+ dimension = dim;
+ this.elementType = elementType;
+ }
+
+ /**
+ * <p>
+ * Compares this array type with another object
+ * for equality. The objects are judged to be equal if:
+ * </p>
+ * <ul>
+ * <li><code>obj</code> is not null.</li>
+ * <li><code>obj</code> is an instance of
+ * [EMAIL PROTECTED] ArrayType}.</li>
+ * <li>The dimensions are equal.</li>
+ * <li>The element types are equal.</li>
+ * </ul>
+ *
+ * @param obj the object to compare with.
+ * @return true if the conditions above hold.
+ */
+ public boolean equals(Object obj)
+ {
+ if (!(obj instanceof ArrayType))
+ return false;
+ ArrayType atype = (ArrayType) obj;
+ return (atype.getDimension() == dimension &&
+ atype.getElementOpenType().equals(elementType));
+ }
+
+ /**
+ * Returns the number of dimensions used by arrays
+ * of this type.
+ *
+ * @return the number of dimensions.
+ */
+ public int getDimension()
+ {
+ return dimension;
+ }
+
+ /**
+ * Returns the open type descriptor which describes
+ * the type of the elements of this array type.
+ *
+ * @return the type of the elements.
+ */
+ public OpenType getElementOpenType()
+ {
+ return elementType;
+ }
+
+ /**
+ * <p>
+ * Returns the hash code of the array type.
+ * This is computed as the sum of the hash code of the
+ * element type together with the number of dimensions
+ * the array has. These are the same elements
+ * of the type that are compared as part of the
+ * [EMAIL PROTECTED] #equals(java.lang.Object)} method, thus ensuring
+ * that the hashcode is compatible with the equality
+ * test.
+ * </p>
+ * <p>
+ * As instances of this class are immutable, the hash code
+ * is computed just once for each instance and reused
+ * throughout its life.
+ * </p>
+ *
+ * @return the hash code of this instance.
+ */
+ public int hashCode()
+ {
+ if (hashCode == null)
+ hashCode = Integer.valueOf(dimension + elementType.hashCode());
+ return hashCode.intValue();
+ }
+
+ /**
+ * <p>
+ * Returns true if the specified object is a member of this
+ * array type. The object is judged to be so if it is
+ * non-null, an array and one of the following two conditions
+ * holds:
+ * </p>
+ * <ul>
+ * <li>This [EMAIL PROTECTED] ArrayType} instance has a [EMAIL PROTECTED]
SimpleType}
+ * as its element type. Thus, the object must have the same
+ * class name as that returned by [EMAIL PROTECTED]
SimpleType#getClassName()}
+ * for this class.</li>
+ * <li>This [EMAIL PROTECTED] ArrayType} instance has a [EMAIL PROTECTED]
CompositeType}
+ * or a [EMAIL PROTECTED] TabularType} as its element type. Thus, the object
+ * must be assignable to such an array, and have elements which
+ * are either null or valid values for the element type.</li>
+ * </ul>
+ *
+ * @param obj the object to test for membership.
+ * @return true if the object is a member of this type.
+ */
+ public boolean isValue(Object obj)
+ {
+ if (obj == null)
+ return false;
+ Class objClass = obj.getClass();
+ if (!(objClass.isArray()))
+ return false;
+ if (elementType instanceof SimpleType)
+ return getClassName().equals(objClass.getName());
+ Class elementClass = null;
+ try
+ {
+ elementClass = Class.forName(getClassName());
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new IllegalStateException("The array type's element " +
+ "class could not be found.", e);
+ }
+ if (!(elementClass.isAssignableFrom(objClass)))
+ return false;
+ for (int a = 0; a < Array.getLength(obj); ++a)
+ {
+ Object elem = Array.get(obj, a);
+ if (elem != null &&
+ (!(elementType.isValue(elem))))
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * <p>
+ * Returns a textual representation of this instance. This
+ * is constructed using the class name
+ * (<code>javax.management.openmbean.ArrayType</code>)
+ * and each element of the instance which is relevant to
+ * the definition of [EMAIL PROTECTED] equals(java.lang.Object)} and
+ * [EMAIL PROTECTED] hashCode()} (i.e. the type name, the number of
+ * dimensions and the element type).
+ * </p>
+ * <p>
+ * As instances of this class are immutable, the return value
+ * is computed just once for each instance and reused
+ * throughout its life.
+ * </p>
+ *
+ * @return a @link{java.lang.String} instance representing
+ * the instance in textual form.
+ */
+ public String toString()
+ {
+ if (string == null)
+ string = getClass().getName()
+ + "[name=" + getTypeName()
+ + ", dimension=" + dimension
+ + ", elementType=" + elementType
+ + "]";
+ return string;
+ }
+
+}
Index: javax/management/openmbean/CompositeType.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/management/openmbean/CompositeType.java,v
retrieving revision 1.1
diff -u -3 -p -u -r1.1 CompositeType.java
--- javax/management/openmbean/CompositeType.java 9 Jul 2006 13:56:22
-0000 1.1
+++ javax/management/openmbean/CompositeType.java 9 Jul 2006 19:55:20
-0000
@@ -72,12 +72,12 @@ public class CompositeType
/**
* The hash code of this instance.
*/
- private volatile Integer hashCode;
+ private transient Integer hashCode;
/**
* The <code>toString()</code> result of this instance.
*/
- private volatile String string;
+ private transient String string;
/**
* <p>
Index: javax/management/openmbean/OpenDataException.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/management/openmbean/OpenDataException.java,v
retrieving revision 1.1
diff -u -3 -p -u -r1.1 OpenDataException.java
--- javax/management/openmbean/OpenDataException.java 9 Jul 2006 13:56:22
-0000 1.1
+++ javax/management/openmbean/OpenDataException.java 9 Jul 2006 19:55:20
-0000
@@ -52,6 +52,11 @@ public class OpenDataException
{
/**
+ * Compatible with JDK 1.5
+ */
+ private static final long serialVersionUID = 8346311255433349870L;
+
+ /**
* Constructs a new <code>OpenDataException</code>.
*/
public OpenDataException()
Index: javax/management/openmbean/SimpleType.java
===================================================================
RCS file: javax/management/openmbean/SimpleType.java
diff -N javax/management/openmbean/SimpleType.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ javax/management/openmbean/SimpleType.java 9 Jul 2006 19:55:24 -0000
@@ -0,0 +1,342 @@
+/* SimpleType.java -- Open type descriptor for the base types.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath 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 for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package javax.management.openmbean;
+
+import java.io.InvalidObjectException;
+import java.io.ObjectStreamException;
+
+/**
+ * The open type descriptor for data values that are members
+ * of one of the simple types (such as an integer or a string).
+ * The other open types ([EMAIL PROTECTED] ArrayType}, [EMAIL PROTECTED]
CompositeType},
+ * [EMAIL PROTECTED] TabularType}) are constructed from one or more of these
+ * types. The simple types are formed from a small subset of
+ * basic Java types. As a result, the valid instances of this
+ * class are predefined, and no constructor is given for creating
+ * new instances.
+ *
+ * @author Andrew John Hughes ([EMAIL PROTECTED])
+ * @since 1.5
+ */
+public class SimpleType
+ extends OpenType
+{
+
+ /**
+ * The [EMAIL PROTECTED] SimpleType} representation of
+ * <code>java.math.BigDecimal</code>.
+ */
+ public static final SimpleType BIGDECIMAL;
+
+ /**
+ * The [EMAIL PROTECTED] SimpleType} representation of
+ * <code>java.math.BigInteger</code>.
+ */
+ public static final SimpleType BIGINTEGER;
+
+ /**
+ * The [EMAIL PROTECTED] SimpleType} representation of
+ * <code>java.lang.Boolean</code>.
+ */
+ public static final SimpleType BOOLEAN;
+
+ /**
+ * The [EMAIL PROTECTED] SimpleType} representation of
+ * <code>java.lang.Byte</code>.
+ */
+ public static final SimpleType BYTE;
+
+ /**
+ * The [EMAIL PROTECTED] SimpleType} representation of
+ * <code>java.lang.Character</code>.
+ */
+ public static final SimpleType CHARACTER;
+
+ /**
+ * The [EMAIL PROTECTED] SimpleType} representation of
+ * <code>java.util.Date</code>.
+ */
+ public static final SimpleType DATE;
+
+ /**
+ * The [EMAIL PROTECTED] SimpleType} representation of
+ * <code>java.lang.Double</code>.
+ */
+ public static final SimpleType DOUBLE;
+
+ /**
+ * The [EMAIL PROTECTED] SimpleType} representation of
+ * <code>java.lang.Float</code>.
+ */
+ public static final SimpleType FLOAT;
+
+ /**
+ * The [EMAIL PROTECTED] SimpleType} representation of
+ * <code>java.lang.Integer</code>.
+ */
+ public static final SimpleType INTEGER;
+
+ /**
+ * The [EMAIL PROTECTED] SimpleType} representation of
+ * <code>java.lang.Long</code>.
+ */
+ public static final SimpleType LONG;
+
+ /**
+ * The [EMAIL PROTECTED] SimpleType} representation of
+ * <code>javax.management.ObjectName</code>.
+ */
+ public static final SimpleType OBJECTNAME;
+
+
+ /**
+ * The [EMAIL PROTECTED] SimpleType} representation of
+ * <code>java.lang.Short</code>.
+ */
+ public static final SimpleType SHORT;
+
+ /**
+ * The [EMAIL PROTECTED] SimpleType} representation of
+ * <code>java.lang.String</code>.
+ */
+ public static final SimpleType STRING;
+
+ /**
+ * The [EMAIL PROTECTED] SimpleType} representation of
+ * <code>java.lang.Void</code>.
+ */
+ public static final SimpleType VOID;
+
+ /**
+ * Compatible with JDK 1.5
+ */
+ private static final long serialVersionUID = 2215577471957694503L;
+
+ /**
+ * The hash code of this instance.
+ */
+ private transient Integer hashCode;
+
+ /**
+ * The <code>toString()</code> result of this instance.
+ */
+ private transient String string;
+
+ /**
+ * Static construction of the [EMAIL PROTECTED] SimpleType} instances.
+ */
+ static
+ {
+ try
+ {
+ BIGDECIMAL = new SimpleType("java.math.BigDecimal");
+ BIGINTEGER = new SimpleType("java.math.BigInteger");
+ BOOLEAN = new SimpleType("java.lang.Boolean");
+ BYTE = new SimpleType("java.lang.Byte");
+ CHARACTER = new SimpleType("java.lang.Character");
+ DATE = new SimpleType("java.util.Date");
+ DOUBLE = new SimpleType("java.lang.Double");
+ FLOAT = new SimpleType("java.lang.Float");
+ INTEGER = new SimpleType("java.lang.Integer");
+ LONG = new SimpleType("java.lang.Long");
+ OBJECTNAME = new SimpleType("javax.management.ObjectName");
+ SHORT = new SimpleType("java.lang.Short");
+ STRING = new SimpleType("java.lang.String");
+ VOID = new SimpleType("java.lang.Void");
+ }
+ catch (OpenDataException e)
+ {
+ /* In normal circumstances, this shouldn't be possible. */
+ throw new IllegalStateException("A invalid class name " +
+ "was passed to the SimpleType " +
+ "constructor.");
+ }
+ }
+
+ /**
+ * Constructs a new [EMAIL PROTECTED] SimpleType} instance for the given
+ * class name. The class name is also used as the type name
+ * and description of the [EMAIL PROTECTED] OpenType} instance.
+ *
+ * @param name the name of the class this instance should
+ * represent.
+ * @throws OpenDataException if somehow the constructor of the
+ * superclass is passed an invalid
+ * class name.
+ */
+ private SimpleType(String name)
+ throws OpenDataException
+ {
+ super(name, name, name);
+ }
+
+ /**
+ * <p>
+ * Compares this simple data type with another object
+ * for equality. The objects are judged to be equal if:
+ * </p>
+ * <ul>
+ * <li><code>obj</code> is not null.</li>
+ * <li><code>obj</code> is an instance of
+ * [EMAIL PROTECTED] SimpleType}.</li>
+ * <li>The class names are equal.</li>
+ * </ul>
+ *
+ * @param obj the object to compare with.
+ * @return true if the conditions above hold.
+ */
+ public boolean equals(Object obj)
+ {
+ if (!(obj instanceof SimpleType))
+ return false;
+ SimpleType sType = (SimpleType) obj;
+ return sType.getClassName().equals(getClassName());
+ }
+
+ /**
+ * <p>
+ * Returns the hash code of the simple data type.
+ * This is simply the hash code of the class name,
+ * which is the same element of the type compared
+ * as part of the
+ * [EMAIL PROTECTED] #equals(java.lang.Object)} method, thus ensuring
+ * that the hashcode is compatible with the equality
+ * test.
+ * </p>
+ * <p>
+ * As instances of this class are immutable, the hash code
+ * is computed just once for each instance and reused
+ * throughout its life.
+ * </p>
+ *
+ * @return the hash code of this instance.
+ */
+ public int hashCode()
+ {
+ if (hashCode == null)
+ hashCode = Integer.valueOf(getClassName().hashCode());
+ return hashCode.intValue();
+ }
+
+ /**
+ * Returns true if the specified object is a member of this
+ * simple type. The object is judged to be so if it is
+ * non-null and its class name is the same as that returned
+ * by [EMAIL PROTECTED] SimpleType#getClassName()}.
+ *
+ * @param obj the object to test for membership.
+ * @return true if the object is a member of this type.
+ */
+ public boolean isValue(Object obj)
+ {
+ if (obj == null)
+ return false;
+ return obj.getClass().getName().equals(getClassName());
+ }
+
+ /**
+ * Replaces instances of this class read from an
+ * [EMAIL PROTECTED] java.io.ObjectInputStream} with one of the predefined
+ * values. This ensures that each existing instance of
+ * this class is one of these unique instances.
+ *
+ * @return the replacement object.
+ * @throws ObjectStreamException if the object can not be
+ * resolved.
+ */
+ public Object readResolve()
+ throws ObjectStreamException
+ {
+ if (equals(BIGDECIMAL))
+ return BIGDECIMAL;
+ if (equals(BIGINTEGER))
+ return BIGINTEGER;
+ if (equals(BOOLEAN))
+ return BOOLEAN;
+ if (equals(BYTE))
+ return BYTE;
+ if (equals(CHARACTER))
+ return CHARACTER;
+ if (equals(DATE))
+ return DATE;
+ if (equals(DOUBLE))
+ return DOUBLE;
+ if (equals(FLOAT))
+ return FLOAT;
+ if (equals(INTEGER))
+ return INTEGER;
+ if (equals(LONG))
+ return LONG;
+ if (equals(OBJECTNAME))
+ return OBJECTNAME;
+ if (equals(SHORT))
+ return SHORT;
+ if (equals(STRING))
+ return STRING;
+ if (equals(VOID))
+ return VOID;
+ throw new InvalidObjectException("Invalid simple type instance " +
+ "deserialized.");
+ }
+
+ /**
+ * <p>
+ * Returns a textual representation of this instance. This
+ * is constructed using the class name
+ * (<code>javax.management.openmbean.SimpleType</code>)
+ * and the name of the class the type represents.
+ * </p>
+ * <p>
+ * As instances of this class are immutable, the return value
+ * is computed just once for each instance and reused
+ * throughout its life.
+ * </p>
+ *
+ * @return a @link{java.lang.String} instance representing
+ * the instance in textual form.
+ */
+ public String toString()
+ {
+ if (string == null)
+ string = getClass().getName()
+ + "[name=" + getClassName()
+ + "]";
+ return string;
+ }
+
+}
Index: javax/management/openmbean/TabularType.java
===================================================================
RCS file:
/cvsroot/classpath/classpath/javax/management/openmbean/TabularType.java,v
retrieving revision 1.1
diff -u -3 -p -u -r1.1 TabularType.java
--- javax/management/openmbean/TabularType.java 9 Jul 2006 13:56:22 -0000
1.1
+++ javax/management/openmbean/TabularType.java 9 Jul 2006 19:55:24 -0000
@@ -73,12 +73,12 @@ public class TabularType
/**
* The hash code of this instance.
*/
- private volatile Integer hashCode;
+ private transient Integer hashCode;
/**
* The <code>toString()</code> result of this instance.
*/
- private volatile String string;
+ private transient String string;
/**
* <p>
@@ -131,7 +131,7 @@ public class TabularType
this.indexNames = Collections.unmodifiableList(Arrays.asList(indexNames));
}
- /**
+ /**
* <p>
* Compares this tabular data type with another object
* for equality. The objects are judged to be equal if:
signature.asc
Description: Digital signature
