diff options
Diffstat (limited to 'javax/management')
30 files changed, 4158 insertions, 52 deletions
diff --git a/javax/management/BadAttributeValueExpException.java b/javax/management/BadAttributeValueExpException.java new file mode 100644 index 000000000..fbdf1deca --- /dev/null +++ b/javax/management/BadAttributeValueExpException.java @@ -0,0 +1,91 @@ +/* BadAttributeValueExpException.java -- Thrown by invalid query attributes. + 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; + +/** + * Thrown when the value of an a attribute passed to a query proves to + * be invalid. This exception is only used internally by the Java + * management API and is not exposed to user code. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class BadAttributeValueExpException + extends Exception +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -3105272988410493376L; + + /** + * The attribute value that caused the exception. + */ + private Object val; + + /** + * Constructs a new <code>BadAttributeValueExpException</code> + * using the specified object to represent the invalid value. + * + * @param val the inappropriate value. + */ + public BadAttributeValueExpException(Object val) + { + super(); + this.val = val; + } + + /** + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.BadAttributeValueExpException</code>) + * and the invalid value. + * + * @return a @link{java.lang.String} instance representing + * the instance in textual form. + */ + public String toString() + { + return getClass().getName() + + "[val=" + val + + "]"; + } + +} + diff --git a/javax/management/BadStringOperationException.java b/javax/management/BadStringOperationException.java new file mode 100644 index 000000000..8e5949ef7 --- /dev/null +++ b/javax/management/BadStringOperationException.java @@ -0,0 +1,92 @@ +/* BadStringOperationException.java -- Thrown by invalid query attributes. + 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; + +/** + * Thrown when a string-based operation passed to a query proves to + * be invalid. This exception is only used internally by the Java + * management API and is not exposed to user code. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class BadStringOperationException + extends Exception +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 7802201238441662100L; + + /** + * The operation that caused the exception. + */ + private String op; + + /** + * Constructs a new <code>BadStringOperationException</code> + * using the specified object to represent the invalid string + * operation. + * + * @param op the inappropriate string operation. + */ + public BadStringOperationException(String op) + { + super(); + this.op = op; + } + + /** + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.BadStringOperationException</code>) + * and the invalid string operation. + * + * @return a @link{java.lang.String} instance representing + * the instance in textual form. + */ + public String toString() + { + return getClass().getName() + + "[op=" + op + + "]"; + } + +} + diff --git a/javax/management/InstanceAlreadyExistsException.java b/javax/management/InstanceAlreadyExistsException.java new file mode 100644 index 000000000..c783208cb --- /dev/null +++ b/javax/management/InstanceAlreadyExistsException.java @@ -0,0 +1,76 @@ +/* InstanceAlreadyExistsException.java -- Thrown by invalid values. + 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; + +/** + * Thrown when an attempt to register a bean is made, and + * the bean is already registered. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class InstanceAlreadyExistsException + extends OperationsException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 8893743928912733931L; + + /** + * Constructs a new <code>InstanceAlreadyExistsException</code>. + */ + public InstanceAlreadyExistsException() + { + super(); + } + + /** + * Constructs a new <code>InstanceAlreadyExistsException</code> + * with the specified message. + * + * @param message the error message to give to the user. + */ + public InstanceAlreadyExistsException(String message) + { + super(message); + } + +} + diff --git a/javax/management/InstanceNotFoundException.java b/javax/management/InstanceNotFoundException.java new file mode 100644 index 000000000..4d209fc47 --- /dev/null +++ b/javax/management/InstanceNotFoundException.java @@ -0,0 +1,76 @@ +/* InstanceNotFoundException.java -- Thrown by invalid values. + 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; + +/** + * Thrown when an attempt to locate a bean is made, and + * the bean does not exist in the repository. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class InstanceNotFoundException + extends OperationsException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -882579438394773049L; + + /** + * Constructs a new <code>InstanceNotFoundException</code>. + */ + public InstanceNotFoundException() + { + super(); + } + + /** + * Constructs a new <code>InstanceNotFoundException</code> + * with the specified message. + * + * @param message the error message to give to the user. + */ + public InstanceNotFoundException(String message) + { + super(message); + } + +} + diff --git a/javax/management/InvalidApplicationException.java b/javax/management/InvalidApplicationException.java new file mode 100644 index 000000000..0bcf2d6cb --- /dev/null +++ b/javax/management/InvalidApplicationException.java @@ -0,0 +1,92 @@ +/* InvalidApplicationException.java -- Thrown by invalid query attributes. + 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; + +/** + * Thrown when a query or attribute is applied to a management bean + * which is of the wrong class. This exception is only used + * internally by the Java management API and is not exposed to user + * code. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class InvalidApplicationException + extends Exception +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -3048022274675537269L; + + /** + * The attribute value that caused the exception. + */ + private Object val; + + /** + * Constructs a new <code>InvalidApplicationException</code> + * using the specified object to represent the invalid value. + * + * @param val the inappropriate expression. + */ + public InvalidApplicationException(Object val) + { + super(); + this.val = val; + } + + /** + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.InvalidApplicationException</code>) + * and the invalid expression. + * + * @return a @link{java.lang.String} instance representing + * the instance in textual form. + */ + public String toString() + { + return getClass().getName() + + "[val=" + val + + "]"; + } + +} + diff --git a/javax/management/MBeanConstructorInfo.java b/javax/management/MBeanConstructorInfo.java index 832a3296d..9ddd432a8 100644 --- a/javax/management/MBeanConstructorInfo.java +++ b/javax/management/MBeanConstructorInfo.java @@ -89,10 +89,11 @@ public class MBeanConstructorInfo * Constructs a @link{MBeanConstructorInfo} with the specified * name, description and parameter information. A <code>null</code> * value for the parameter information is the same as passing in - * an empty array. + * an empty array. A copy of the parameter array is taken, so + * later changes have no effect. * * @param name the name of the constructor. - * @param desc a description of the attribute. + * @param desc a description of the constructor. * @param sig the signature of the constructor, as a series * of {@link MBeanParameterInfo} objects, one for * each parameter. @@ -104,7 +105,10 @@ public class MBeanConstructorInfo if (sig == null) signature = new MBeanParameterInfo[0]; else - signature = sig; + { + signature = new MBeanParameterInfo[sig.length]; + System.arraycopy(sig, 0, signature, 0, sig.length); + } } /** diff --git a/javax/management/MBeanFeatureInfo.java b/javax/management/MBeanFeatureInfo.java index 4f0243e18..74a030387 100644 --- a/javax/management/MBeanFeatureInfo.java +++ b/javax/management/MBeanFeatureInfo.java @@ -79,7 +79,7 @@ public class MBeanFeatureInfo /** * The <code>toString()</code> result of this instance. */ - protected transient String string; + transient String string; /** * Constructs a new {@link MBeanFeatureInfo} with the specified diff --git a/javax/management/MBeanInfo.java b/javax/management/MBeanInfo.java index e6f03f065..d30de0499 100644 --- a/javax/management/MBeanInfo.java +++ b/javax/management/MBeanInfo.java @@ -140,7 +140,8 @@ public class MBeanInfo * can be loaded by the MBean server or class loader; it merely * has to be a syntactically correct class name. Any of the * arrays may be <code>null</code>; this will be treated as if - * an empty array was supplied. + * an empty array was supplied. A copy of the arrays is + * taken, so later changes have no effect. * * @param name the name of the class this instance describes. * @param desc a description of the bean. @@ -162,19 +163,31 @@ public class MBeanInfo if (attribs == null) attributes = new MBeanAttributeInfo[0]; else - attributes = attribs; + { + attributes = new MBeanAttributeInfo[attribs.length]; + System.arraycopy(attribs, 0, attributes, 0, attribs.length); + } if (cons == null) constructors = new MBeanConstructorInfo[0]; else - constructors = cons; + { + constructors = new MBeanConstructorInfo[cons.length]; + System.arraycopy(cons, 0, constructors, 0, cons.length); + } if (ops == null) operations = new MBeanOperationInfo[0]; else - operations = ops; + { + operations = new MBeanOperationInfo[ops.length]; + System.arraycopy(ops, 0, operations, 0, ops.length); + } if (notifs == null) notifications = new MBeanNotificationInfo[0]; else - notifications = notifs; + { + notifications = new MBeanNotificationInfo[notifs.length]; + System.arraycopy(notifs, 0, notifications, 0, notifs.length); + } } /** diff --git a/javax/management/MBeanOperationInfo.java b/javax/management/MBeanOperationInfo.java index a2db8d1b0..2a78d19d9 100644 --- a/javax/management/MBeanOperationInfo.java +++ b/javax/management/MBeanOperationInfo.java @@ -140,7 +140,8 @@ public class MBeanOperationInfo * Constructs a @link{MBeanOperationInfo} with the specified name, * description, parameter information, return type and impact. A * <code>null</code> value for the parameter information is the same - * as passing in an empty array. + * as passing in an empty array. A copy of the parameter array is + * taken, so later changes have no effect. * * @param name the name of the constructor. * @param desc a description of the attribute. @@ -158,7 +159,10 @@ public class MBeanOperationInfo if (sig == null) signature = new MBeanParameterInfo[0]; else - signature = sig; + { + signature = new MBeanParameterInfo[sig.length]; + System.arraycopy(sig, 0, signature, 0, sig.length); + } this.type = type; this.impact = impact; } diff --git a/javax/management/MBeanRegistrationException.java b/javax/management/MBeanRegistrationException.java new file mode 100644 index 000000000..9f62b9aa0 --- /dev/null +++ b/javax/management/MBeanRegistrationException.java @@ -0,0 +1,84 @@ +/* MBeanRegistrationException.java -- A bean registration exception. + 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; + +/** + * Represents an arbitrary exception thrown during registration of a + * management bean. When registering a bean causes an exception to be + * thrown, the resulting exception is wrapped inside an {@link + * MBeanRegistrationException}. Calling {@link getTargetException()} + * will return the wrapped exception. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class MBeanRegistrationException + extends MBeanException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 4482382455277067805L; + + /** + * Constructs a new <code>MBeanRegistrationException</code> wrapping + * the specified exception. + * + * @param e the exception to be wrapped. + */ + public MBeanRegistrationException(Exception e) + { + super(e); + } + + /** + * Constructs a new <code>MBeanRegistrationException</code> wrapping + * the specified exception and using the supplied message. + * + * @param e the exception to be wrapped. + * @param message the error message to give to the user. + */ + public MBeanRegistrationException(Exception e, String message) + { + super(e, message); + } + + +} + diff --git a/javax/management/MalformedObjectNameException.java b/javax/management/MalformedObjectNameException.java new file mode 100644 index 000000000..e2f577490 --- /dev/null +++ b/javax/management/MalformedObjectNameException.java @@ -0,0 +1,76 @@ +/* MalformedObjectNameException.java -- Thrown by invalid values. + 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; + +/** + * Thrown when a string used as an {@link ObjectName} + * is invalid. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class MalformedObjectNameException + extends OperationsException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -572689714442915824L; + + /** + * Constructs a new <code>MalformedObjectNameException</code>. + */ + public MalformedObjectNameException() + { + super(); + } + + /** + * Constructs a new <code>MalformedObjectNameException</code> + * with the specified message. + * + * @param message the error message to give to the user. + */ + public MalformedObjectNameException(String message) + { + super(message); + } + +} + diff --git a/javax/management/RuntimeErrorException.java b/javax/management/RuntimeErrorException.java new file mode 100644 index 000000000..811dc40f2 --- /dev/null +++ b/javax/management/RuntimeErrorException.java @@ -0,0 +1,115 @@ +/* RuntimeErrorException.java -- A user-defined management error. + 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; + +/** + * Represents an arbitrary error thrown by a management + * bean. When a management bean executes code that causes + * an error to be thrown, the resulting error is + * wrapped inside an {@link RuntimeErrorException}. Calling + * {@link getTargetError()} will return the wrapped + * exception. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class RuntimeErrorException + extends JMRuntimeException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 704338937753949796L; + + /** + * The target error. + * + * @serial the target error. + */ + private Error error; + + /** + * Constructs a new <code>RuntimeErrorException</code> wrapping + * the specified error. + * + * @param e the error to be wrapped. + */ + public RuntimeErrorException(Error e) + { + super(); + error = e; + } + + /** + * Constructs a new <code>RuntimeErrorException</code> wrapping + * the specified error and using the supplied message. + * + * @param e the error to be wrapped. + * @param message the error message to give to the user. + */ + public RuntimeErrorException(Error e, String message) + { + super(message); + error = e; + } + + /** + * Returns the true cause of this error, the wrapped + * error. + * + * @return the wrapped error. + */ + public Throwable getCause() + { + return error; + } + + /** + * Returns the true cause of this error, the wrapped + * error. + * + * @return the wrapped error. + */ + public Error getTargetError() + { + return error; + } + +} + diff --git a/javax/management/RuntimeMBeanException.java b/javax/management/RuntimeMBeanException.java new file mode 100644 index 000000000..95225a80a --- /dev/null +++ b/javax/management/RuntimeMBeanException.java @@ -0,0 +1,114 @@ +/* RuntimeMBeanException.java -- A user-defined management exception. + 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; + +/** + * Represents an arbitrary runtime exception thrown by a management + * bean. When a management bean executes code that causes a runtime + * exception to be thrown, the resulting exception is wrapped inside a + * {@link RuntimeMBeanException}. Calling {@link + * getTargetException()} will return the wrapped exception. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class RuntimeMBeanException + extends JMRuntimeException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 5274912751982730171L; + + /** + * The target exception. + * + * @serial the target exception. + */ + private RuntimeException runtimeException; + + /** + * Constructs a new <code>RuntimeMBeanException</code> wrapping + * the specified exception. + * + * @param e the exception to be wrapped. + */ + public RuntimeMBeanException(RuntimeException e) + { + super(); + runtimeException = e; + } + + /** + * Constructs a new <code>RuntimeMBeanException</code> wrapping + * the specified exception and using the supplied message. + * + * @param e the exception to be wrapped. + * @param message the error message to give to the user. + */ + public RuntimeMBeanException(RuntimeException e, String message) + { + super(message); + runtimeException = e; + } + + /** + * Returns the true cause of this exception, the wrapped runtime + * exception. + * + * @return the wrapped exception. + */ + public Throwable getCause() + { + return runtimeException; + } + + /** + * Returns the true cause of this exception, the wrapped runtime + * exception. + * + * @return the wrapped exception. + */ + public RuntimeException getTargetException() + { + return runtimeException; + } + +} + diff --git a/javax/management/ServiceNotFoundException.java b/javax/management/ServiceNotFoundException.java new file mode 100644 index 000000000..602e1490d --- /dev/null +++ b/javax/management/ServiceNotFoundException.java @@ -0,0 +1,75 @@ +/* ServiceNotFoundException.java -- Thrown by invalid values. + 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; + +/** + * Thrown when a requested service is unsupported. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class ServiceNotFoundException + extends OperationsException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -3990675661956646827L; + + /** + * Constructs a new <code>ServiceNotFoundException</code>. + */ + public ServiceNotFoundException() + { + super(); + } + + /** + * Constructs a new <code>ServiceNotFoundException</code> + * with the specified message. + * + * @param message the error message to give to the user. + */ + public ServiceNotFoundException(String message) + { + super(message); + } + +} + diff --git a/javax/management/StandardMBean.java b/javax/management/StandardMBean.java index 736192ee2..16b6f0b66 100644 --- a/javax/management/StandardMBean.java +++ b/javax/management/StandardMBean.java @@ -205,17 +205,13 @@ public class StandardMBean Method getter; try { - getter = iface.getMethod("get" + - name.substring(0, 1).toUpperCase() + - name.substring(1), null); + getter = iface.getMethod("get" + name, null); } catch (NoSuchMethodException e) { try { - getter = iface.getMethod("is" + - name.substring(0, 1).toUpperCase() + - name.substring(1), null); + getter = iface.getMethod("is" + name, null); } catch (NoSuchMethodException ex) { @@ -564,11 +560,9 @@ public class StandardMBean Method[] amethods; String attrib; if (name.startsWith("is")) - attrib = name.substring(2,3).toLowerCase() - + name.substring(3); + attrib = name.substring(2); else - attrib = name.substring(3,4).toLowerCase() - + name.substring(4); + attrib = name.substring(3); if (attributes.containsKey(attrib)) amethods = (Method[]) attributes.get(attrib); else @@ -583,8 +577,7 @@ public class StandardMBean methods[a].getParameterTypes().length == 1) { Method[] amethods; - String attrib = name.substring(3,4).toLowerCase() - + name.substring(4); + String attrib = name.substring(3); if (attributes.containsKey(attrib)) amethods = (Method[]) attributes.get(attrib); else @@ -595,7 +588,8 @@ public class StandardMBean amethods[1] = methods[a]; } else - operations.add(new MBeanOperationInfo("", methods[a])); + operations.add(new MBeanOperationInfo(methods[a].getName(), + methods[a])); } List attribs = new ArrayList(attributes.size()); Iterator it = attributes.entrySet().iterator(); @@ -605,7 +599,8 @@ public class StandardMBean Method[] amethods = (Method[]) entry.getValue(); try { - attribs.add(new MBeanAttributeInfo((String) entry.getKey(), "", + attribs.add(new MBeanAttributeInfo((String) entry.getKey(), + (String) entry.getKey(), amethods[0], amethods[1])); } catch (IntrospectionException e) @@ -632,7 +627,8 @@ public class StandardMBean MBeanConstructorInfo[] cinfo = new MBeanConstructorInfo[cons.length]; for (int a = 0; a < cinfo.length; ++a) { - MBeanConstructorInfo oldInfo = new MBeanConstructorInfo("", cons[a]); + MBeanConstructorInfo oldInfo = new MBeanConstructorInfo(cons[a].getName(), + cons[a]); String desc = getDescription(oldInfo); MBeanParameterInfo[] params = oldInfo.getSignature(); MBeanParameterInfo[] pinfo = new MBeanParameterInfo[params.length]; @@ -665,8 +661,8 @@ public class StandardMBean oinfo[a] = new MBeanOperationInfo(oldInfo.getName(), desc, pinfo, oldInfo.getReturnType(), impact); } - info = new MBeanInfo(impl.getClass().getName(), "", ainfo, cinfo, - oinfo, null); + info = new MBeanInfo(impl.getClass().getName(), impl.getClass().getName(), + ainfo, cinfo, oinfo, null); String cname = getClassName(info); String desc = getDescription(info); info = new MBeanInfo(cname, desc, ainfo, cinfo, oinfo, null); @@ -679,7 +675,7 @@ public class StandardMBean * * @return the management interface. */ - public Class getMBeanInterface() + public final Class getMBeanInterface() { return iface; } diff --git a/javax/management/openmbean/InvalidOpenTypeException.java b/javax/management/openmbean/InvalidOpenTypeException.java new file mode 100644 index 000000000..9c9ff8cfa --- /dev/null +++ b/javax/management/openmbean/InvalidOpenTypeException.java @@ -0,0 +1,76 @@ +/* InvalidOpenTypeException.java -- Thrown by an invalid open type. + 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; + +/** + * Thrown when a open data value has an erroneous open + * type. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class InvalidOpenTypeException + extends IllegalArgumentException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -2837312755412327534L; + + /** + * Constructs a new <code>InvalidOpenTypeException</code>. + */ + public InvalidOpenTypeException() + { + super(); + } + + /** + * Constructs a new <code>InvalidOpenTypeException</code> + * with the specified message. + * + * @param message the error message to give to the user. + */ + public InvalidOpenTypeException(String message) + { + super(message); + } + +} + diff --git a/javax/management/openmbean/KeyAlreadyExistsException.java b/javax/management/openmbean/KeyAlreadyExistsException.java new file mode 100644 index 000000000..cc6bba636 --- /dev/null +++ b/javax/management/openmbean/KeyAlreadyExistsException.java @@ -0,0 +1,77 @@ +/* KeyAlreadyExistsException.java -- Thrown when a key clashes with another. + 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; + +/** + * Thrown when a key (a field name or row index) is passed to a method + * of the {@link CompositeData} or {@link TabularData} classes and it + * is found to already be in use. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class KeyAlreadyExistsException + extends IllegalArgumentException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 1845183636745282866L; + + /** + * Constructs a new <code>KeyAlreadyExistsException</code>. + */ + public KeyAlreadyExistsException() + { + super(); + } + + /** + * Constructs a new <code>KeyAlreadyExistsException</code> + * with the specified message. + * + * @param message the error message to give to the user. + */ + public KeyAlreadyExistsException(String message) + { + super(message); + } + +} + diff --git a/javax/management/openmbean/OpenMBeanAttributeInfo.java b/javax/management/openmbean/OpenMBeanAttributeInfo.java new file mode 100644 index 000000000..1b276fd19 --- /dev/null +++ b/javax/management/openmbean/OpenMBeanAttributeInfo.java @@ -0,0 +1,120 @@ +/* OpenMBeanAttributeInfo.java -- Open typed info about an attribute. + 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; + +/** + * Describes an attribute associated with an open management bean. + * This interface includes those methods specified by {@link + * javax.management.MBeanAttributeInfo}, so implementations should + * extend this class. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public interface OpenMBeanAttributeInfo + extends OpenMBeanParameterInfo +{ + + /** + * Compares this attribute with the supplied object. This returns + * true iff the object is an instance of {@link OpenMBeanAttributeInfo} + * with an equal name and open type, the same default, minimum, + * maximum and legal values and the same access properties + * ({@link #isIs()}, {@link #isReadable()}, {@link #isWritable()}). + * + * @param obj the object to compare. + * @return true if the object is a {@link OpenMBeanParameterInfo} + * instance, + * <code>name.equals(object.getName())</code>, + * <code>openType.equals(object.getOpenType())</code>, + * <code>defaultValue.equals(object.getDefaultValue())</code>, + * <code>minValue.equals(object.getMinValue())</code>, + * <code>maxValue.equals(object.getMaxValue())</code>, + * <code>legalValues.equals(object.getLegalValues())</code>, + * <code>is == object.isIs()</code>, + * <code>isRead == object.isReadable()</code>, + * and <code>isWrite == object.isWritable()</code>. + */ + boolean equals(Object obj); + + /** + * Returns the hashcode of the attribute information as the sum of + * the hashcodes of the name, open type, default value, maximum + * value, minimum value, the set of legal values and the access + * properties. + * + * @return the hashcode of the attribute information. + */ + int hashCode(); + + /** + * Returns true if the accessor method of this attribute + * is of the form <code>isXXX</code>. + * + * @return true if the accessor takes the form <code>isXXX</code>. + */ + boolean isIs(); + + /** + * Returns true if value of this attribute can be read. + * + * @return true if the value of the attribute can be read. + */ + boolean isReadable(); + + /** + * Returns true if the value of this attribute can be changed. + * + * @return true if the value of the attribute can be changed. + */ + boolean isWritable(); + + /** + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.openmbean.OpenMBeanAttributeInfo</code>) + * along with the name, open type, default, minimum, maximum + * and legal values of the parameter and the access permissions + * ({@link #isIs()}, {@link #isReadable()}, {@link #isWritable()}). + * + * @return a @link{java.lang.String} instance representing + * the instance in textual form. + */ + String toString(); + +} diff --git a/javax/management/openmbean/OpenMBeanAttributeInfoSupport.java b/javax/management/openmbean/OpenMBeanAttributeInfoSupport.java new file mode 100644 index 000000000..83e043640 --- /dev/null +++ b/javax/management/openmbean/OpenMBeanAttributeInfoSupport.java @@ -0,0 +1,546 @@ +/* OpenMBeanAttributeInfoSupport.java -- Open typed info about an attribute. + 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.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import javax.management.MBeanAttributeInfo; + +/** + * Describes an attribute of an open management bean. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class OpenMBeanAttributeInfoSupport + extends MBeanAttributeInfo + implements OpenMBeanAttributeInfo +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -4867215622149721849L; + + /** + * The open type of the attribute. + */ + private OpenType openType; + + /** + * The default value of the attribute (may be <code>null</code>). + */ + private Object defaultValue; + + /** + * The possible legal values of the attribute (may be <code>null</code>). + */ + private Set legalValues; + + /** + * The minimum value of the attribute (may be <code>null</code>). + */ + private Comparable minValue; + + /** + * The maximum value of the attribute (may be <code>null</code>). + */ + private Comparable maxValue; + + /** + * The hash code of this instance. + */ + private transient Integer hashCode; + + /** + * The <code>toString()</code> result of this instance. + */ + private transient String string; + + /** + * Constructs a new {@link OpenMBeanAttributeInfo} using the + * specified name, description, open type and access properties. + * The name, description and open type may not be <code>null</code> + * and the name and description may not be equal to the empty + * string. + * + * @param name the name of the attribute. + * @param desc a description of the attribute. + * @param type the open type of the attribute. + * @param isReadable true if the attribute's value can be read. + * @param isWritable true if the attribute's value can be changed. + * @param isIs true if the attribute uses an accessor of the form isXXX. + * @throws IllegalArgumentException if the name, description or + * open type are <code>null</code> + * or the name or description are + * the empty string. + */ + public OpenMBeanAttributeInfoSupport(String name, String desc, OpenType type, + boolean isReadable, boolean isWritable, + boolean isIs) + { + super(name, type == null ? null : type.getClassName(), desc, isReadable, + isWritable, isIs); + if (name == null) + throw new IllegalArgumentException("The name may not be null."); + if (desc == null) + throw new IllegalArgumentException("The description may not be null."); + if (type == null) + throw new IllegalArgumentException("The type may not be null."); + if (name.length() == 0) + throw new IllegalArgumentException("The name may not be the empty string."); + if (desc.length() == 0) + throw new IllegalArgumentException("The description may not be the " + + "empty string."); + } + + /** + * Constructs a new {@link OpenMBeanAttributeInfo} using the + * specified name, description, open type and default value. The + * name, description and open type cannot be <code>null</code> and + * the name and description may not be equal to the empty string. + * The default value may be <code>null</code>. If non-null, it must + * be a valid value of the given open type. Default values are not + * applicable to the open types, {@link ArrayType} and {@link + * TabularType}. + * + * @param name the name of the attribute. + * @param desc a description of the attribute. + * @param type the open type of the attribute. + * @param isReadable true if the attribute's value can be read. + * @param isWritable true if the attribute's value can be changed. + * @param isIs true if the attribute uses an accessor of the form isXXX. + * @param defaultValue the default value of the attribute. + * @throws IllegalArgumentException if the name, description or + * open type are <code>null</code> + * or the name or description are + * the empty string. + * @throws OpenDataException if <code>defaultValue<code> is non-null + * and is either not a value of the given + * open type or the open type is an instance + * of {@link ArrayType} or {@link TabularType}. + */ + public OpenMBeanAttributeInfoSupport(String name, String desc, OpenType type, + boolean isReadable, boolean isWritable, + boolean isIs, Object defaultValue) + throws OpenDataException + { + this(name, desc, type, isReadable, isWritable, isIs, defaultValue, null); + } + + /** + * <p> + * Constructs a new {@link OpenMBeanAttributeInfo} using the + * specified name, description, open type, access properties, + * default, maximum and minimum values. The name, description + * and open type cannot be <code>null</code> and the name and + * description may not be equal to the empty string. The + * default, maximum and minimum values may be <code>null</code>. + * The following conditions apply when the attributes mentioned + * are non-null: + * </p> + * <ul> + * <li>The values must be valid values for the given open type.</li> + * <li>Default values are not applicable to the open types, {@link + * ArrayType} and {@link TabularType}.</li> + * <li>The minimum value must be smaller than or equal to the maximum value + * (literally, <code>minValue.compareTo(maxValue) <= 0</code>.</li> + * <li>The minimum value must be smaller than or equal to the default value + * (literally, <code>minValue.compareTo(defaultValue) <= 0</code>.</li> + * <li>The default value must be smaller than or equal to the maximum value + * (literally, <code>defaultValue.compareTo(maxValue) <= 0</code>.</li> + * </ul> + * + * @param name the name of the attribute. + * @param desc a description of the attribute. + * @param type the open type of the attribute. + * @param isReadable true if the attribute's value can be read. + * @param isWritable true if the attribute's value can be changed. + * @param isIs true if the attribute uses an accessor of the form isXXX. + * @param defaultValue the default value of the attribute, or <code>null</code>. + * @param minimumValue the minimum value of the attribute, or <code>null</code>. + * @param maximumValue the maximum value of the attribute, or <code>null</code>. + * @throws IllegalArgumentException if the name, description or + * open type are <code>null</code> + * or the name or description are + * the empty string. + * @throws OpenDataException if any condition in the list above is broken. + */ + public OpenMBeanAttributeInfoSupport(String name, String desc, OpenType type, + boolean isReadable, boolean isWritable, + boolean isIs, Object defaultValue, + Comparable minimumValue, + Comparable maximumValue) + throws OpenDataException + { + this(name, desc, type, isReadable, isWritable, isIs); + if (defaultValue != null && !(type.isValue(defaultValue))) + throw new OpenDataException("The default value is not a member of the " + + "open type given."); + if (minimumValue != null && !(type.isValue(minimumValue))) + throw new OpenDataException("The minimum value is not a member of the " + + "open type given."); + if (maximumValue != null && !(type.isValue(maximumValue))) + throw new OpenDataException("The maximum value is not a member of the " + + "open type given."); + if (defaultValue != null && (type instanceof ArrayType || + type instanceof TabularType)) + throw new OpenDataException("Default values are not applicable for " + + "array or tabular types."); + if (minValue != null && maxValue != null + && minValue.compareTo(maxValue) > 0) + throw new OpenDataException("The minimum value is greater than the " + + "maximum."); + if (minValue != null && defaultValue != null + && minValue.compareTo(defaultValue) > 0) + throw new OpenDataException("The minimum value is greater than the " + + "default."); + if (defaultValue != null && maxValue != null + && maxValue.compareTo(defaultValue) < 0) + throw new OpenDataException("The default value is greater than the " + + "maximum."); + + openType = type; + this.defaultValue = defaultValue; + minValue = minimumValue; + maxValue = maximumValue; + } + + /** + * <p> + * Constructs a new {@link OpenMBeanAttributeInfo} using the + * specified name, description, open type, access properties, default + * value and set of legal values. The name, description and open type + * cannot be <code>null</code> and the name and description may not be + * equal to the empty string. The default, maximum and minimum values + * may be <code>null</code>. The following conditions apply when the + * attributes mentioned are non-null: + * </p> + * <ul> + * <li>The default value and each of the legal values must be a valid + * value for the given open type.</li> + * <li>Default and legal values are not applicable to the open types, {@link + * ArrayType} and {@link TabularType}.</li> + * <li>The default value is not in the set of legal values.</li> + * </ul> + * <p> + * The legal values are copied from the array into a unmodifiable set, + * so future modifications to the array have no effect. + * </p> + * + * @param name the name of the attribute. + * @param desc a description of the attribute. + * @param type the open type of the attribute. + * @param isReadable true if the attribute's value can be read. + * @param isWritable true if the attribute's value can be changed. + * @param isIs true if the attribute uses an accessor of the form isXXX. + * @param defaultValue the default value of the attribute, or <code>null</code>. + * @param legalValues the legal values of the attribute. May be + * <code>null</code> or an empty array. + * @throws IllegalArgumentException if the name, description or + * open type are <code>null</code> + * or the name or description are + * the empty string. + * @throws OpenDataException if any condition in the list above is broken. + */ + public OpenMBeanAttributeInfoSupport(String name, String desc, OpenType type, + boolean isReadable, boolean isWritable, + boolean isIs, Object defaultValue, + Object[] legalValues) + throws OpenDataException + { + this(name, desc, type, isReadable, isWritable, isIs); + if (defaultValue != null && !(type.isValue(defaultValue))) + throw new OpenDataException("The default value is not a member of the " + + "open type given."); + if (defaultValue != null && (type instanceof ArrayType || + type instanceof TabularType)) + throw new OpenDataException("Default values are not applicable for " + + "array or tabular types."); + if (legalValues != null && (type instanceof ArrayType || + type instanceof TabularType)) + throw new OpenDataException("Legal values are not applicable for " + + "array or tabular types."); + if (legalValues != null && legalValues.length > 0) + { + Set lv = new HashSet(legalValues.length); + for (int a = 0; a < legalValues.length; ++a) + { + if (legalValues[a] != null && + !(type.isValue(legalValues[a]))) + throw new OpenDataException("The legal value, " + + legalValues[a] + + "is not a member of the " + + "open type given."); + lv.add(legalValues[a]); + } + if (defaultValue != null && !(lv.contains(defaultValue))) + throw new OpenDataException("The default value is not in the set " + + "of legal values."); + this.legalValues = Collections.unmodifiableSet(lv); + } + openType = type; + this.defaultValue = defaultValue; + } + + /** + * Compares this attribute with the supplied object. This returns + * true iff the object is an instance of {@link OpenMBeanAttributeInfo} + * with an equal name and open type and the same default, minimum, + * maximum and legal values and the same access properties. + * + * @param obj the object to compare. + * @return true if the object is a {@link OpenMBeanAttributeInfo} + * instance, + * <code>name.equals(object.getName())</code>, + * <code>openType.equals(object.getOpenType())</code>, + * <code>isRead == object.isReadable()</code>, + * <code>isWrite == object.isWritable()</code>, + * <code>isIs == object.isIs()</code>, + * <code>defaultValue.equals(object.getDefaultValue())</code>, + * <code>minValue.equals(object.getMinValue())</code>, + * <code>maxValue.equals(object.getMaxValue())</code>, + * and <code>legalValues.equals(object.getLegalValues())</code>. + */ + public boolean equals(Object obj) + { + if (!(obj instanceof OpenMBeanAttributeInfo)) + return false; + OpenMBeanAttributeInfo o = (OpenMBeanAttributeInfo) obj; + return getName().equals(o.getName()) && + openType.equals(o.getOpenType()) && + isReadable() == o.isReadable() && + isWritable() == o.isWritable() && + isIs() == o.isIs() && + (defaultValue == null ? o.getDefaultValue() == null : + defaultValue.equals(o.getDefaultValue())) && + (minValue == null ? o.getMinValue() == null : + minValue.equals(o.getMinValue())) && + (maxValue == null ? o.getMaxValue() == null : + maxValue.equals(o.getMaxValue())) && + (legalValues == null ? o.getLegalValues() == null : + legalValues.equals(o.getLegalValues())); + } + + /** + * Returns the default value of this attribute, or <code>null</code> + * if there is no default value. + * + * @return the default value of the attribute, or <code>null</code> + * if there is no default. + */ + public Object getDefaultValue() + { + return defaultValue; + } + + /** + * Returns a {@link java.util.Set} enumerating the legal values + * of this attribute, or <code>null</code> if no such limited + * set exists for this attribute. + * + * @return a set of legal values, or <code>null</code> if no such + * set exists. + */ + public Set getLegalValues() + { + return legalValues; + } + + /** + * Returns the maximum value of this attribute, or <code>null</code> + * if there is no maximum. + * + * @return the maximum value, or <code>null</code> if none exists. + */ + public Comparable getMaxValue() + { + return maxValue; + } + + /** + * Returns the minimum value of this attribute, or <code>null</code> + * if there is no minimum. + * + * @return the minimum value, or <code>null</code> if none exists. + */ + public Comparable getMinValue() + { + return minValue; + } + + /** + * Returns the open type instance which represents the type of this + * attribute. + * + * @return the open type of this attribute. + */ + public OpenType getOpenType() + { + return openType; + } + + /** + * Returns true if this attribute has a default value + * (i.e. the value is non-null). + * + * @return true if this attribute has a default. + */ + public boolean hasDefaultValue() + { + return defaultValue != null; + } + + /** + * <p> + * Returns the hashcode of the attribute information as the sum of + * the hashcodes of the name, open type, default value, maximum + * value, minimum value and the set of legal values. + * </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 hashcode of the attribute information. + */ + public int hashCode() + { + if (hashCode == null) + hashCode = Integer.valueOf(getName().hashCode() + + openType.hashCode() + + Boolean.valueOf(isReadable()).hashCode() + + (2 * + Boolean.valueOf(isWritable()).hashCode()) + + (4 * Boolean.valueOf(isIs()).hashCode()) + + (defaultValue == null ? 0 : + defaultValue.hashCode()) + + (minValue == null ? 0 : + minValue.hashCode()) + + (maxValue == null ? 0 : + maxValue.hashCode()) + + (legalValues == null ? 0 : + legalValues.hashCode())); + return hashCode.intValue(); + } + + /** + * Returns true if there is a set of legal values for this + * attribute (i.e. the value is non-null). + * + * @return true if a set of legal values exists for this + * attribute. + */ + public boolean hasLegalValues() + { + return legalValues != null; + } + + /** + * Returns true if there is a maximum value for this attribute + * (i.e. the value is non-null). + * + * @return true if a maximum value exists for this attribute. + */ + public boolean hasMaxValue() + { + return maxValue != null; + } + + /** + * Returns true if there is a minimum value for this attribute. + * (i.e. the value is non-null). + * + * @return true if a minimum value exists for this attribute. + */ + public boolean hasMinValue() + { + return minValue != null; + } + + /** + * Returns true if the specified object is a valid value for + * this attribute. + * + * @param obj the object to test. + * @return true if <code>obj</code> is a valid value for this + * attribute. + */ + public boolean isValue(Object obj) + { + return openType.isValue(obj); + } + + /** + * <p> + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.openmbean.OpenMBeanAttributeInfo</code>) + * along with the name, open type, access properties, default, + * minimum, maximum and legal values of the attribute. + * </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=" + getName() + + ",openType=" + openType + + ",isReadable=" + isReadable() + + ",isWritable=" + isWritable() + + ",isIs=" + isIs() + + ",defaultValue=" + defaultValue + + ",minValue=" + minValue + + ",maxValue=" + maxValue + + ",legalValues=" + legalValues + + "]"; + return string; + } + +} diff --git a/javax/management/openmbean/OpenMBeanConstructorInfo.java b/javax/management/openmbean/OpenMBeanConstructorInfo.java new file mode 100644 index 000000000..34cef131f --- /dev/null +++ b/javax/management/openmbean/OpenMBeanConstructorInfo.java @@ -0,0 +1,112 @@ +/* OpenMBeanConstructorInfo.java -- Open typed info about a constructor. + 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 javax.management.MBeanParameterInfo; + +/** + * Describes a constructor for an open management bean. + * This interface includes those methods specified by {@link + * javax.management.MBeanConstructorInfo}, so implementations should + * extend this class. The {@link #getSignature()} method should + * return an array containing instances of {@link OpenMBeanParameterInfo}. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public interface OpenMBeanConstructorInfo +{ + + /** + * Compares this attribute with the supplied object. This returns + * true iff the object is an instance of {@link OpenMBeanConstructorInfo} + * with an equal name and signature. + * + * @param obj the object to compare. + * @return true if the object is a {@link OpenMBeanParameterInfo} + * instance, + * <code>name.equals(object.getName())</code>, + * and <code>signature.equals(object.getSignature())</code>. + */ + boolean equals(Object obj); + + /** + * Returns a description of this constructor. + * + * @return a human-readable description. + */ + String getDescription(); + + /** + * Returns the name of this constructor. + * + * @return the name of the constructor. + */ + String getName(); + + /** + * Returns the constructor's signature, in the form of + * information on each parameter. Each parameter is + * described by an instance of {@link OpenMBeanParameterInfo}. + * + * @return an array of {@link OpenMBeanParameterInfo} objects, + * describing the constructor parameters. + */ + MBeanParameterInfo[] getSignature(); + + /** + * Returns the hashcode of the constructor information as the sum of + * the hashcodes of the name and signature (calculated by + * <code>java.util.Arrays.asList(signature).hashCode()</code>). + * + * @return the hashcode of the constructor information. + */ + int hashCode(); + + /** + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.openmbean.OpenMBeanConstructorInfo</code>) + * along with the name and signature. + * + * @return a @link{java.lang.String} instance representing + * the instance in textual form. + */ + String toString(); + +} diff --git a/javax/management/openmbean/OpenMBeanConstructorInfoSupport.java b/javax/management/openmbean/OpenMBeanConstructorInfoSupport.java new file mode 100644 index 000000000..9dac01a59 --- /dev/null +++ b/javax/management/openmbean/OpenMBeanConstructorInfoSupport.java @@ -0,0 +1,174 @@ +/* OpenMBeanConstructorInfoSupport.java -- Open typed info about an constructor. + 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.util.Arrays; + +import javax.management.MBeanConstructorInfo; +import javax.management.MBeanParameterInfo; + +/** + * Describes a constructor for an open management bean. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class OpenMBeanConstructorInfoSupport + extends MBeanConstructorInfo + implements OpenMBeanConstructorInfo +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -4400441579007477003L; + + /** + * The hash code of this instance. + */ + private transient Integer hashCode; + + /** + * The <code>toString()</code> result of this instance. + */ + private transient String string; + + /** + * Constructs a @link{OpenMBeanConstructorInfo} with the specified + * name, description and parameter information. A <code>null</code> + * value for the parameter information is the same as passing in + * an empty array. Neither the name nor the description may be + * null or equal to the empty string. A copy of the parameter array + * is taken, so later changes have no effect. + * + * @param name the name of the constructor. + * @param desc a description of the constructor. + * @param sig the signature of the constructor, as a series + * of {@link MBeanParameterInfo} objects, one for + * each parameter. + * @throws IllegalArgumentException if the name or description is + * either <code>null</code> + * or the empty string. + * @throws ArrayStoreException if the members of the signature array + * are not assignable to + * {@link javax.management.MBeanParameterInfo} + */ + public OpenMBeanConstructorInfoSupport(String name, String desc, + OpenMBeanParameterInfo[] sig) + { + super(name, desc, (MBeanParameterInfo[]) sig); + if (name == null) + throw new IllegalArgumentException("The name may not be null."); + if (desc == null) + throw new IllegalArgumentException("The description may not be null."); + if (name.length() == 0) + throw new IllegalArgumentException("The name may not be the empty string."); + if (desc.length() == 0) + throw new IllegalArgumentException("The description may not be the " + + "empty string."); + } + + /** + * Compares this attribute with the supplied object. This returns + * true iff the object is an instance of {@link OpenMBeanConstructorInfo} + * with an equal name and signature. + * + * @param obj the object to compare. + * @return true if the object is a {@link OpenMBeanParameterInfo} + * instance, + * <code>name.equals(object.getName())</code>, + * and <code>signature.equals(object.getSignature())</code>. + */ + public boolean equals(Object obj) + { + if (!(obj instanceof OpenMBeanConstructorInfo)) + return false; + OpenMBeanConstructorInfo o = (OpenMBeanConstructorInfo) obj; + return getName().equals(o.getName()) && + getSignature().equals(o.getSignature()); + } + + /** + * <p> + * Returns the hashcode of the constructor information as the sum of + * the hashcodes of the name and signature (calculated by + * <code>java.util.Arrays.asList(signature).hashCode()</code>). + * </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 the hashcode of the constructor information. + */ + public int hashCode() + { + if (hashCode == null) + hashCode = Integer.valueOf(getName().hashCode() + + Arrays.asList(getSignature()).hashCode()); + return hashCode.intValue(); + } + + /** + * <p> + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.openmbean.OpenMBeanConstructorInfo</code>) + * along with the name and signature. + * </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=" + getName() + + ",signature=" + Arrays.toString(getSignature()) + + "]"; + return string; + } + +} diff --git a/javax/management/openmbean/OpenMBeanInfo.java b/javax/management/openmbean/OpenMBeanInfo.java new file mode 100644 index 000000000..5aa4df451 --- /dev/null +++ b/javax/management/openmbean/OpenMBeanInfo.java @@ -0,0 +1,154 @@ +/* OpenMBeanInfo.java -- Open typed info about a management bean. + 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 javax.management.MBeanAttributeInfo; +import javax.management.MBeanConstructorInfo; +import javax.management.MBeanNotificationInfo; +import javax.management.MBeanOperationInfo; + +/** + * Describes an open management bean. Open management beans are + * management beans where {@link + * javax.management.DynamicMBean#getMBeanInfo()} returns an + * implementation of this interface. This interface includes those + * methods specified by {@link javax.management.MBeanInfo}, + * so implementations should extend this class. Each method + * which returns an array of one of the <code>MBeanXXXInfo</code> + * classes should return an array containing instances + * of the equivalent open version (<code>OpenMBeanXXXInfo</code>). + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public interface OpenMBeanInfo +{ + + /** + * Compares this attribute with the supplied object. This returns + * true iff the object is an instance of {@link OpenMBeanInfo} + * with the same class name and equal instances of the info classes. + * + * @param obj the object to compare. + * @return true if the object is a {@link OpenMBeanInfo} + * instance, + * <code>className.equals(object.getClassName())</code> + * and each info class has an equal in the other object. + */ + boolean equals(Object obj); + + /** + * Returns descriptions of each of the attributes provided by this + * management bean. The elements should be implementations of the + * {@link OpenMBeanAttributeInfo} class. + * + * @return an array of {@link OpenMBeanAttributeInfo} objects, + * representing the attributes emitted by this + * management bean. + */ + MBeanAttributeInfo[] getAttributes(); + + /** + * Returns the class name of the management bean. + * + * @return the bean's class name. + */ + String getClassName(); + + /** + * Returns descriptions of each of the constructors provided by this + * management bean. The elements should be implementations of the + * {@link OpenMBeanConstructorInfo} class. + * + * @return an array of {@link OpenMBeanConstructorInfo} objects, + * representing the constructors emitted by this + * management bean. + */ + MBeanConstructorInfo[] getConstructors(); + + /** + * Returns a description of this operation. + * + * @return a human-readable description. + */ + String getDescription(); + + /** + * Returns descriptions of each of the notifications provided by this + * management bean. The elements should be implementations of the + * {@link OpenMBeanNotificationInfo} class. + * + * @return an array of {@link OpenMBeanNotificationInfo} objects, + * representing the notifications emitted by this + * management bean. + */ + MBeanNotificationInfo[] getNotifications(); + + /** + * Returns descriptions of each of the operations provided by this + * management bean. The elements should be implementations of the + * {@link OpenMBeanOperationInfo} class. + * + * @return an array of {@link OpenMBeanOperationInfo} objects, + * representing the operations emitted by this + * management bean. + */ + MBeanOperationInfo[] getOperations(); + + /** + * Returns the hashcode of the bean information as the sum of the + * hashcodes of the class name and each array (calculated using + * java.util.HashSet(<code>java.util.Arrays.asList(signature)).hashCode()</code>). + * + * @return the hashcode of the bean information. + */ + int hashCode(); + + /** + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.openmbean.OpenMBeanInfo</code>) + * along with the class name and textual representations + * of each array. + * + * @return a @link{java.lang.String} instance representing + * the instance in textual form. + */ + String toString(); + +} diff --git a/javax/management/openmbean/OpenMBeanInfoSupport.java b/javax/management/openmbean/OpenMBeanInfoSupport.java new file mode 100644 index 000000000..5f8d55b83 --- /dev/null +++ b/javax/management/openmbean/OpenMBeanInfoSupport.java @@ -0,0 +1,191 @@ +/* OpenMBeanInfoSupport.java -- Open typed info about a bean. + 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.util.Arrays; +import java.util.HashSet; + +import javax.management.MBeanInfo; +import javax.management.MBeanAttributeInfo; +import javax.management.MBeanConstructorInfo; +import javax.management.MBeanNotificationInfo; +import javax.management.MBeanOperationInfo; + +/** + * Describes an open management bean. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class OpenMBeanInfoSupport + extends MBeanInfo + implements OpenMBeanInfo +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 4349395935420511492L; + + /** + * The hash code of this instance. + */ + private transient Integer hashCode; + + /** + * The <code>toString()</code> result of this instance. + */ + private transient String string; + + /** + * Constructs a new {@link OpenMBeanInfo} using the supplied + * class name and description with the given attributes, + * operations, constructors and notifications. The class + * name does not have to actually specify a valid class that + * can be loaded by the MBean server or class loader; it merely + * has to be a syntactically correct class name. Any of the + * arrays may be <code>null</code>; this will be treated as if + * an empty array was supplied. A copy of the arrays is + * taken, so later changes have no effect. + * + * @param name the name of the class this instance describes. + * @param desc a description of the bean. + * @param attribs the attribute descriptions for the bean, + * or <code>null</code>. + * @param cons the constructor descriptions for the bean, + * or <code>null</code>. + * @param ops the operation descriptions for the bean, + * or <code>null</code>. + * @param notifs the notification descriptions for the bean, + * or <code>null</code>. + * @throws ArrayStoreException if a members of an array + * is not assignable to the equivalent + * <code>MBeanXXXInfo</code> class. + */ + public OpenMBeanInfoSupport(String name, String desc, + OpenMBeanAttributeInfo[] attribs, + OpenMBeanConstructorInfo[] cons, + OpenMBeanOperationInfo[] ops, + MBeanNotificationInfo[] notifs) + { + super(name, desc, (MBeanAttributeInfo[]) attribs, + (MBeanConstructorInfo[]) cons, + (MBeanOperationInfo[]) ops, + notifs); + } + + /** + * Compares this attribute with the supplied object. This returns + * true iff the object is an instance of {@link OpenMBeanInfo} + * with the same class name and equal instances of the info classes. + * + * @param obj the object to compare. + * @return true if the object is a {@link OpenMBeanInfo} + * instance, + * <code>className.equals(object.getClassName())</code> + * and each info class has an equal in the other object. + */ + public boolean equals(Object obj) + { + if (!(obj instanceof OpenMBeanInfo)) + return false; + OpenMBeanInfo o = (OpenMBeanInfo) obj; + return getClassName().equals(o.getClassName()) && + getAttributes().equals(o.getAttributes()) && + getConstructors().equals(o.getConstructors()) && + getNotifications().equals(o.getNotifications()) && + getOperations().equals(o.getOperations()); + } + + /** + * <p> + * Returns the hashcode of the bean information as the sum of the + * hashcodes of the class name and each array (calculated using + * java.util.HashSet(<code>java.util.Arrays.asList(signature)).hashCode()</code>). + * </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 the hashcode of the bean information. + */ + public int hashCode() + { + if (hashCode == null) + hashCode = + Integer.valueOf(getClassName().hashCode() + + new HashSet(Arrays.asList(getAttributes())).hashCode() + + new HashSet(Arrays.asList(getConstructors())).hashCode() + + new HashSet(Arrays.asList(getNotifications())).hashCode() + + new HashSet(Arrays.asList(getOperations())).hashCode()); + return hashCode.intValue(); + } + + /** + * <p> + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.openmbean.OpenMBeanInfo</code>) + * along with the class name and textual representations + * of each array. + * </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() + + "[className=" + getClassName() + + ",attributes=" + Arrays.toString(getAttributes()) + + ",constructors=" + Arrays.toString(getConstructors()) + + ",notifications=" + Arrays.toString(getNotifications()) + + ",operations=" + Arrays.toString(getOperations()) + + "]"; + return string; + } + +} diff --git a/javax/management/openmbean/OpenMBeanOperationInfo.java b/javax/management/openmbean/OpenMBeanOperationInfo.java new file mode 100644 index 000000000..8b61329d9 --- /dev/null +++ b/javax/management/openmbean/OpenMBeanOperationInfo.java @@ -0,0 +1,154 @@ +/* OpenMBeanOperationInfo.java -- Open typed info about a operation. + 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 javax.management.MBeanParameterInfo; + +/** + * Describes a operation for an open management bean. + * This interface includes those methods specified by {@link + * javax.management.MBeanOperationInfo}, so implementations should + * extend this class. The {@link #getSignature()} method should + * return an array containing instances of {@link OpenMBeanParameterInfo}. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public interface OpenMBeanOperationInfo +{ + + /** + * Compares this attribute with the supplied object. This returns + * true iff the object is an instance of {@link OpenMBeanOperationInfo} + * with an equal name, signature, open return type and impact. + * + * @param obj the object to compare. + * @return true if the object is a {@link OpenMBeanParameterInfo} + * instance, + * <code>name.equals(object.getName())</code>, + * <code>signature.equals(object.getSignature())</code>, + * <code>returnOpenType.equals(object.getReturnOpenType())</code>, + * and <code>impact == object.getImpact()</code>. + */ + boolean equals(Object obj); + + /** + * Returns a description of this operation. + * + * @return a human-readable description. + */ + String getDescription(); + + /** + * <p> + * Returns the impact of performing this operation. + * The value is equal to one of the following: + * </p> + * <ol> + * <li>{@link javax.management.MBeanOperationInfo#INFO} + * — the method just returns + * information (akin to an accessor).</li> + * <li>{@link javax.management.MBeanOperationInfo#ACTION} + * the method just alters the state of the bean, without + * returning a value (akin to a mutator).</li> + * <li>{@link javax.management.MBeanOperationInfo#ACTION_INFO} + * the method both makes state changes and returns a value.</li> + * <li>{@link javax.management.MBeanOperationInfo#UNKNOWN} + * the behaviour of the operation is unknown.</li> + * </ol> + * + * @return the impact of performing the operation. + */ + int getImpact(); + + /** + * Returns the name of this operation. + * + * @return the name of the operation. + */ + String getName(); + + /** + * Returns the open type instance which represents the type of the + * return value. + * + * @return the open type of the return value. + */ + OpenType getReturnOpenType(); + + /** + * Returns the return type of the operation, as the class + * name. This should be identical to + * <code>getReturnOpenType.getClassName()</code>. + * + * @return the return type. + */ + String getReturnType(); + + /** + * Returns the operation's signature, in the form of + * information on each parameter. Each parameter is + * described by an instance of {@link OpenMBeanParameterInfo}. + * + * @return an array of {@link OpenMBeanParameterInfo} objects, + * describing the operation parameters. + */ + MBeanParameterInfo[] getSignature(); + + /** + * Returns the hashcode of the operation information as the sum of + * the hashcodes of the name, open return type, impact and signature + * (calculated by + * <code>java.util.Arrays.asList(signature).hashCode()</code>). + * + * @return the hashcode of the operation information. + */ + int hashCode(); + + /** + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.openmbean.OpenMBeanOperationInfo</code>) + * along with the name, signature, open return type and impact. + * + * @return a @link{java.lang.String} instance representing + * the instance in textual form. + */ + String toString(); + +} diff --git a/javax/management/openmbean/OpenMBeanOperationInfoSupport.java b/javax/management/openmbean/OpenMBeanOperationInfoSupport.java new file mode 100644 index 000000000..07564897c --- /dev/null +++ b/javax/management/openmbean/OpenMBeanOperationInfoSupport.java @@ -0,0 +1,240 @@ +/* OpenMBeanOperationInfoSupport.java -- Open typed info about an operation. + 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.util.Arrays; + +import javax.management.MBeanOperationInfo; +import javax.management.MBeanParameterInfo; + +/** + * Describes a operation for an open management bean. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class OpenMBeanOperationInfoSupport + extends MBeanOperationInfo + implements OpenMBeanOperationInfo +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 4996859732565369366L; + + /** + * The open type representing the return value. + */ + private OpenType returnOpenType; + + /** + * The hash code of this instance. + */ + private transient Integer hashCode; + + /** + * The <code>toString()</code> result of this instance. + */ + private transient String string; + + /** + * Constructs a @link{OpenMBeanOperationInfo} with the specified name, + * description, parameter information, open return type and impact. A + * <code>null</code> value for the parameter information is the same + * as passing in an empty array. A copy of the parameter array is + * taken, so later changes have no effect. The name and the + * description may not be equal to the empty string, and neither + * the name, description nor the open return type may be + * <code>null</code>. The value of <code>impact</code> must be + * one of the four valid values + * ({@link javax.management.MBeanOperationInfo#INFO}, + * {@link javax.management.MBeanOperationInfo#ACTION}, + * {@link javax.management.MBeanOperationInfo#ACTION_INFO} and + * {@link javax.management.MBeanOperationInfo#UNKNOWN}). + * + * + * @param name the name of the constructor. + * @param desc a description of the attribute. + * @param sig the signature of the method, as a series + * of {@link MBeanParameterInfo} objects, one for + * each parameter. + * @param type the open return type of the method. + * @param impact the impact of performing the operation. + * @throws IllegalArgumentException if the name, description or + * open return type is <code>null</code>, + * the name or description are equal to + * the empty string, or the impact factor + * is not one of the values enumerated + * above. + * @throws ArrayStoreException if the members of the signature array + * are not assignable to + * {@link javax.management.MBeanParameterInfo} + */ + public OpenMBeanOperationInfoSupport(String name, String desc, + OpenMBeanParameterInfo[] sig, + OpenType type, int impact) + { + super(name, desc, (MBeanParameterInfo[]) sig, + type == null ? null : type.getClassName(), impact); + if (name == null) + throw new IllegalArgumentException("The name may not be null."); + if (desc == null) + throw new IllegalArgumentException("The description may not be null."); + if (type == null) + throw new IllegalArgumentException("The type may not be null."); + if (name.length() == 0) + throw new IllegalArgumentException("The name may not be the empty string."); + if (desc.length() == 0) + throw new IllegalArgumentException("The description may not be the " + + "empty string."); + if (impact != ACTION && impact != INFO && + impact != ACTION_INFO && impact != UNKNOWN) + throw new IllegalArgumentException("The impact factor is an invalid value."); + returnOpenType = type; + } + + /** + * Compares this attribute with the supplied object. This returns + * true iff the object is an instance of {@link OpenMBeanOperationInfo} + * with an equal name, signature, open return type and impact. + * + * @param obj the object to compare. + * @return true if the object is a {@link OpenMBeanParameterInfo} + * instance, + * <code>name.equals(object.getName())</code>, + * <code>signature.equals(object.getSignature())</code>, + * <code>returnOpenType.equals(object.getReturnOpenType())</code>, + * and <code>impact == object.getImpact()</code>. + */ + public boolean equals(Object obj) + { + if (!(obj instanceof OpenMBeanOperationInfo)) + return false; + OpenMBeanOperationInfo o = (OpenMBeanOperationInfo) obj; + return getName().equals(o.getName()) && + getSignature().equals(o.getSignature()) && + returnOpenType.equals(o.getReturnOpenType()) && + getImpact() == o.getImpact(); + } + + /** + * Returns the open type instance which represents the type of the + * return value. + * + * @return the open type of the return value. + */ + public OpenType getReturnOpenType() + { + return returnOpenType; + } + + /** + * <p> + * Returns the hashcode of the operation information as the sum of + * the hashcodes of the name, open return type, impact and signature + * (calculated by + * <code>java.util.Arrays.asList(signature).hashCode()</code>). + * </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 the hashcode of the operation information. + */ + public int hashCode() + { + if (hashCode == null) + hashCode = Integer.valueOf(getName().hashCode() + + returnOpenType.hashCode() + + Integer.valueOf(getImpact()).hashCode() + + Arrays.asList(getSignature()).hashCode()); + return hashCode.intValue(); + } + + /** + * <p> + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.openmbean.OpenMBeanOperationInfo</code>) + * along with the name, signature, open return type and impact. + * </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 impactString; + switch (getImpact()) + { + case INFO: + impactString = "INFO"; + break; + case ACTION: + impactString = "ACTION"; + break; + case ACTION_INFO: + impactString = "ACTION_INFO"; + break; + case UNKNOWN: + impactString = "UNKNOWN"; + break; + default: + impactString = "ERRONEOUS VALUE"; + } + string = getClass().getName() + + "[name=" + getName() + + ",signature=" + Arrays.toString(getSignature()) + + ",returnOpenType=" + returnOpenType + + ",impact=" + impactString + + "]"; + } + return string; + } + +} diff --git a/javax/management/openmbean/OpenMBeanParameterInfo.java b/javax/management/openmbean/OpenMBeanParameterInfo.java new file mode 100644 index 000000000..780e8ba11 --- /dev/null +++ b/javax/management/openmbean/OpenMBeanParameterInfo.java @@ -0,0 +1,190 @@ +/* OpenMBeanParameterInfo.java -- Open typed info about a parameter. + 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.util.Set; + +/** + * Describes the parameters of a constructor or operation associated + * with an open management bean. This interface includes those methods + * specified by {@link javax.management.MBeanParameterInfo}, so + * implementations should extend this class. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public interface OpenMBeanParameterInfo +{ + + /** + * Compares this parameter with the supplied object. This returns + * true iff the object is an instance of {@link OpenMBeanParameterInfo} + * with an equal name and open type and the same default, minimum, + * maximum and legal values. + * + * @param obj the object to compare. + * @return true if the object is a {@link OpenMBeanParameterInfo} + * instance, + * <code>name.equals(object.getName())</code>, + * <code>openType.equals(object.getOpenType())</code>, + * <code>defaultValue.equals(object.getDefaultValue())</code>, + * <code>minValue.equals(object.getMinValue())</code>, + * <code>maxValue.equals(object.getMaxValue())</code>, + * and <code>legalValues.equals(object.getLegalValues())</code>. + */ + boolean equals(Object obj); + + /** + * Returns the default value of this parameter, or <code>null</code> + * if there is no default value. + * + * @return the default value of the parameter, or <code>null</code> + * if there is no default. + */ + Object getDefaultValue(); + + /** + * Returns a description of this parameter. + * + * @return a human-readable description. + */ + String getDescription(); + + /** + * Returns a {@link java.util.Set} enumerating the legal values + * of this parameter, or <code>null</code> if no such limited + * set exists for this parameter. + * + * @return a set of legal values, or <code>null</code> if no such + * set exists. + */ + Set getLegalValues(); + + /** + * Returns the maximum value of this parameter, or <code>null</code> + * if there is no maximum. + * + * @return the maximum value, or <code>null</code> if none exists. + */ + Comparable getMaxValue(); + + /** + * Returns the minimum value of this parameter, or <code>null</code> + * if there is no minimum. + * + * @return the minimum value, or <code>null</code> if none exists. + */ + Comparable getMinValue(); + + /** + * Returns the name of this parameter. + * + * @return the name of the parameter. + */ + String getName(); + + /** + * Returns the open type instance which represents the type of this + * parameter. + * + * @return the open type of this parameter. + */ + OpenType getOpenType(); + + /** + * Returns true if this parameter has a default value. + * + * @return true if this parameter has a default. + */ + boolean hasDefaultValue(); + + /** + * Returns the hashcode of the parameter information as the sum of + * the hashcodes of the name, open type, default value, maximum + * value, minimum value and the set of legal values. + * + * @return the hashcode of the parameter information. + */ + int hashCode(); + + /** + * Returns true if there is a set of legal values for this + * parameter. + * + * @return true if a set of legal values exists for this + * parameter. + */ + boolean hasLegalValues(); + + /** + * Returns true if there is a maximum value for this parameter. + * + * @return true if a maximum value exists for this parameter. + */ + boolean hasMaxValue(); + + /** + * Returns true if there is a minimum value for this parameter. + * + * @return true if a minimum value exists for this parameter. + */ + boolean hasMinValue(); + + /** + * Returns true if the specified object is a valid value for + * this parameter. + * + * @param obj the object to test. + * @return true if <code>obj</code> is a valid value for this + * parameter. + */ + boolean isValue(Object obj); + + /** + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.openmbean.OpenMBeanParameterInfo</code>) + * along with the name, open type, default, minimum, maximum + * and legal values of the parameter. + * + * @return a @link{java.lang.String} instance representing + * the instance in textual form. + */ + String toString(); + +} diff --git a/javax/management/openmbean/OpenMBeanParameterInfoSupport.java b/javax/management/openmbean/OpenMBeanParameterInfoSupport.java new file mode 100644 index 000000000..af3bda6c7 --- /dev/null +++ b/javax/management/openmbean/OpenMBeanParameterInfoSupport.java @@ -0,0 +1,511 @@ +/* OpenMBeanParameterInfoSupport.java -- Open typed info about a parameter. + 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.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import javax.management.MBeanParameterInfo; + +/** + * Describes the parameters of a constructor or operation associated + * with an open management bean. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class OpenMBeanParameterInfoSupport + extends MBeanParameterInfo + implements OpenMBeanParameterInfo +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -7235016873758443122L; + + /** + * The open type of the parameter. + */ + private OpenType openType; + + /** + * The default value of the parameter (may be <code>null</code>). + */ + private Object defaultValue; + + /** + * The possible legal values of the parameter (may be <code>null</code>). + */ + private Set legalValues; + + /** + * The minimum value of the parameter (may be <code>null</code>). + */ + private Comparable minValue; + + /** + * The maximum value of the parameter (may be <code>null</code>). + */ + private Comparable maxValue; + + /** + * The hash code of this instance. + */ + private transient Integer hashCode; + + /** + * The <code>toString()</code> result of this instance. + */ + private transient String string; + + /** + * Constructs a new {@link OpenMBeanParameterInfo} using the specified + * name, description and open type. None of these values may be + * <code>null</code> and the name and description may not be equal + * to the empty string. + * + * @param name the name of the parameter. + * @param desc a description of the parameter. + * @param type the open type of the parameter. + * @throws IllegalArgumentException if the name, description or + * open type are <code>null</code> + * or the name or description are + * the empty string. + */ + public OpenMBeanParameterInfoSupport(String name, String desc, OpenType type) + { + super(name, type == null ? null : type.getClassName(), desc); + if (name == null) + throw new IllegalArgumentException("The name may not be null."); + if (desc == null) + throw new IllegalArgumentException("The description may not be null."); + if (type == null) + throw new IllegalArgumentException("The type may not be null."); + if (name.length() == 0) + throw new IllegalArgumentException("The name may not be the empty string."); + if (desc.length() == 0) + throw new IllegalArgumentException("The description may not be the " + + "empty string."); + openType = type; + } + + /** + * Constructs a new {@link OpenMBeanParameterInfo} using the + * specified name, description, open type and default value. The + * name, description and open type cannot be <code>null</code> and + * the name and description may not be equal to the empty string. + * The default value may be <code>null</code>. If non-null, it must + * be a valid value of the given open type. Default values are not + * applicable to the open types, {@link ArrayType} and {@link + * TabularType}. + * + * @param name the name of the parameter. + * @param desc a description of the parameter. + * @param type the open type of the parameter. + * @param defaultValue the default value of the parameter. + * @throws IllegalArgumentException if the name, description or + * open type are <code>null</code> + * or the name or description are + * the empty string. + * @throws OpenDataException if <code>defaultValue<code> is non-null + * and is either not a value of the given + * open type or the open type is an instance + * of {@link ArrayType} or {@link TabularType}. + */ + public OpenMBeanParameterInfoSupport(String name, String desc, OpenType type, + Object defaultValue) + throws OpenDataException + { + this(name, desc, type, defaultValue, null); + } + + /** + * <p> + * Constructs a new {@link OpenMBeanParameterInfo} using the + * specified name, description, open type, default, maximum and + * minimum values. The name, description and open type cannot be + * <code>null</code> and the name and description may not be equal + * to the empty string. The default, maximum and minimum values may + * be <code>null</code>. The following conditions apply when the + * parameters mentioned are non-null: + * </p> + * <ul> + * <li>The values must be valid values for the given open type.</li> + * <li>Default values are not applicable to the open types, {@link + * ArrayType} and {@link TabularType}.</li> + * <li>The minimum value must be smaller than or equal to the maximum value + * (literally, <code>minValue.compareTo(maxValue) <= 0</code>.</li> + * <li>The minimum value must be smaller than or equal to the default value + * (literally, <code>minValue.compareTo(defaultValue) <= 0</code>.</li> + * <li>The default value must be smaller than or equal to the maximum value + * (literally, <code>defaultValue.compareTo(maxValue) <= 0</code>.</li> + * </ul> + * + * @param name the name of the parameter. + * @param desc a description of the parameter. + * @param type the open type of the parameter. + * @param defaultValue the default value of the parameter, or <code>null</code>. + * @param minimumValue the minimum value of the parameter, or <code>null</code>. + * @param maximumValue the maximum value of the parameter, or <code>null</code>. + * @throws IllegalArgumentException if the name, description or + * open type are <code>null</code> + * or the name or description are + * the empty string. + * @throws OpenDataException if any condition in the list above is broken. + */ + public OpenMBeanParameterInfoSupport(String name, String desc, OpenType type, + Object defaultValue, Comparable minimumValue, + Comparable maximumValue) + throws OpenDataException + { + this(name, desc, type); + if (defaultValue != null && !(type.isValue(defaultValue))) + throw new OpenDataException("The default value is not a member of the " + + "open type given."); + if (minimumValue != null && !(type.isValue(minimumValue))) + throw new OpenDataException("The minimum value is not a member of the " + + "open type given."); + if (maximumValue != null && !(type.isValue(maximumValue))) + throw new OpenDataException("The maximum value is not a member of the " + + "open type given."); + if (defaultValue != null && (type instanceof ArrayType || + type instanceof TabularType)) + throw new OpenDataException("Default values are not applicable for " + + "array or tabular types."); + if (minValue != null && maxValue != null + && minValue.compareTo(maxValue) > 0) + throw new OpenDataException("The minimum value is greater than the " + + "maximum."); + if (minValue != null && defaultValue != null + && minValue.compareTo(defaultValue) > 0) + throw new OpenDataException("The minimum value is greater than the " + + "default."); + if (defaultValue != null && maxValue != null + && maxValue.compareTo(defaultValue) < 0) + throw new OpenDataException("The default value is greater than the " + + "maximum."); + + this.defaultValue = defaultValue; + minValue = minimumValue; + maxValue = maximumValue; + } + + /** + * <p> + * Constructs a new {@link OpenMBeanParameterInfo} using the + * specified name, description, open type, default value and + * set of legal values. The name, description and open type cannot be + * <code>null</code> and the name and description may not be equal + * to the empty string. The default, maximum and minimum values may + * be <code>null</code>. The following conditions apply when the + * parameters mentioned are non-null: + * </p> + * <ul> + * <li>The default value and each of the legal values must be a valid + * value for the given open type.</li> + * <li>Default and legal values are not applicable to the open types, {@link + * ArrayType} and {@link TabularType}.</li> + * <li>The default value is not in the set of legal values.</li> + * </ul> + * <p> + * The legal values are copied from the array into a unmodifiable set, + * so future modifications to the array have no effect. + * </p> + * + * @param name the name of the parameter. + * @param desc a description of the parameter. + * @param type the open type of the parameter. + * @param defaultValue the default value of the parameter, or <code>null</code>. + * @param legalValues the legal values of the parameter. May be + * <code>null</code> or an empty array. + * @throws IllegalArgumentException if the name, description or + * open type are <code>null</code> + * or the name or description are + * the empty string. + * @throws OpenDataException if any condition in the list above is broken. + */ + public OpenMBeanParameterInfoSupport(String name, String desc, OpenType type, + Object defaultValue, Object[] legalValues) + throws OpenDataException + { + this(name, desc, type); + if (defaultValue != null && !(type.isValue(defaultValue))) + throw new OpenDataException("The default value is not a member of the " + + "open type given."); + if (defaultValue != null && (type instanceof ArrayType || + type instanceof TabularType)) + throw new OpenDataException("Default values are not applicable for " + + "array or tabular types."); + if (legalValues != null && (type instanceof ArrayType || + type instanceof TabularType)) + throw new OpenDataException("Legal values are not applicable for " + + "array or tabular types."); + if (legalValues != null && legalValues.length > 0) + { + Set lv = new HashSet(legalValues.length); + for (int a = 0; a < legalValues.length; ++a) + { + if (legalValues[a] != null && + !(type.isValue(legalValues[a]))) + throw new OpenDataException("The legal value, " + + legalValues[a] + + "is not a member of the " + + "open type given."); + lv.add(legalValues[a]); + } + if (defaultValue != null && !(lv.contains(defaultValue))) + throw new OpenDataException("The default value is not in the set " + + "of legal values."); + this.legalValues = Collections.unmodifiableSet(lv); + } + this.defaultValue = defaultValue; + } + + /** + * Compares this parameter with the supplied object. This returns + * true iff the object is an instance of {@link OpenMBeanParameterInfo} + * with an equal name and open type and the same default, minimum, + * maximum and legal values. + * + * @param obj the object to compare. + * @return true if the object is a {@link OpenMBeanParameterInfo} + * instance, + * <code>name.equals(object.getName())</code>, + * <code>openType.equals(object.getOpenType())</code>, + * <code>defaultValue.equals(object.getDefaultValue())</code>, + * <code>minValue.equals(object.getMinValue())</code>, + * <code>maxValue.equals(object.getMaxValue())</code>, + * and <code>legalValues.equals(object.getLegalValues())</code>. + */ + public boolean equals(Object obj) + { + if (!(obj instanceof OpenMBeanParameterInfo)) + return false; + OpenMBeanParameterInfo o = (OpenMBeanParameterInfo) obj; + return getName().equals(o.getName()) && + openType.equals(o.getOpenType()) && + (defaultValue == null ? o.getDefaultValue() == null : + defaultValue.equals(o.getDefaultValue())) && + (minValue == null ? o.getMinValue() == null : + minValue.equals(o.getMinValue())) && + (maxValue == null ? o.getMaxValue() == null : + maxValue.equals(o.getMaxValue())) && + (legalValues == null ? o.getLegalValues() == null : + legalValues.equals(o.getLegalValues())); + } + + /** + * Returns the default value of this parameter, or <code>null</code> + * if there is no default value. + * + * @return the default value of the parameter, or <code>null</code> + * if there is no default. + */ + public Object getDefaultValue() + { + return defaultValue; + } + + /** + * Returns a {@link java.util.Set} enumerating the legal values + * of this parameter, or <code>null</code> if no such limited + * set exists for this parameter. + * + * @return a set of legal values, or <code>null</code> if no such + * set exists. + */ + public Set getLegalValues() + { + return legalValues; + } + + /** + * Returns the maximum value of this parameter, or <code>null</code> + * if there is no maximum. + * + * @return the maximum value, or <code>null</code> if none exists. + */ + public Comparable getMaxValue() + { + return maxValue; + } + + /** + * Returns the minimum value of this parameter, or <code>null</code> + * if there is no minimum. + * + * @return the minimum value, or <code>null</code> if none exists. + */ + public Comparable getMinValue() + { + return minValue; + } + + /** + * Returns the open type instance which represents the type of this + * parameter. + * + * @return the open type of this parameter. + */ + public OpenType getOpenType() + { + return openType; + } + + /** + * Returns true if this parameter has a default value + * (i.e. the value is non-null). + * + * @return true if this parameter has a default. + */ + public boolean hasDefaultValue() + { + return defaultValue != null; + } + + /** + * <p> + * Returns the hashcode of the parameter information as the sum of + * the hashcodes of the name, open type, default value, maximum + * value, minimum value and the set of legal values. + * </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 hashcode of the parameter information. + */ + public int hashCode() + { + if (hashCode == null) + hashCode = Integer.valueOf(getName().hashCode() + + openType.hashCode() + + (defaultValue == null ? 0 : + defaultValue.hashCode()) + + (minValue == null ? 0 : + minValue.hashCode()) + + (maxValue == null ? 0 : + maxValue.hashCode()) + + (legalValues == null ? 0 : + legalValues.hashCode())); + return hashCode.intValue(); + } + + /** + * Returns true if there is a set of legal values for this + * parameter (i.e. the value is non-null). + * + * @return true if a set of legal values exists for this + * parameter. + */ + public boolean hasLegalValues() + { + return legalValues != null; + } + + /** + * Returns true if there is a maximum value for this parameter + * (i.e. the value is non-null). + * + * @return true if a maximum value exists for this parameter. + */ + public boolean hasMaxValue() + { + return maxValue != null; + } + + /** + * Returns true if there is a minimum value for this parameter. + * (i.e. the value is non-null). + * + * @return true if a minimum value exists for this parameter. + */ + public boolean hasMinValue() + { + return minValue != null; + } + + /** + * Returns true if the specified object is a valid value for + * this parameter. + * + * @param obj the object to test. + * @return true if <code>obj</code> is a valid value for this + * parameter. + */ + public boolean isValue(Object obj) + { + return openType.isValue(obj); + } + + /** + * <p> + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.openmbean.OpenMBeanParameterInfo</code>) + * along with the name, open type, default, minimum, maximum + * and legal values of the parameter. + * </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=" + getName() + + ",openType=" + openType + + ",defaultValue=" + defaultValue + + ",minValue=" + minValue + + ",maxValue=" + maxValue + + ",legalValues=" + legalValues + + "]"; + return string; + } + +} diff --git a/javax/management/openmbean/SimpleType.java b/javax/management/openmbean/SimpleType.java index 3962909d4..39753f1c6 100644 --- a/javax/management/openmbean/SimpleType.java +++ b/javax/management/openmbean/SimpleType.java @@ -53,7 +53,7 @@ import java.io.ObjectStreamException; * @author Andrew John Hughes (gnu_andrew@member.fsf.org) * @since 1.5 */ -public class SimpleType +public final class SimpleType extends OpenType { diff --git a/javax/management/openmbean/TabularData.java b/javax/management/openmbean/TabularData.java index 17c8de981..7e57e0fd8 100644 --- a/javax/management/openmbean/TabularData.java +++ b/javax/management/openmbean/TabularData.java @@ -55,12 +55,14 @@ public interface TabularData /** * Calculates the index the specified {@link CompositeData} value * would have, if it was to be added to this {@link TabularData} - * instance. This method includes a check that the type of - * the given value is the same as the row type of this instance, - * but not a check for existing instances of the given value. - * The value must also not be <code>null</code>. Possible indices - * are returned by the {@link TabularType#getIndexNames()} method - * of this instance's tabular type. + * instance. This method includes a check that the type of the + * given value is the same as the row type of this instance, but not + * a check for existing instances of the given value. The value + * must also not be <code>null</code>. Possible indices are + * returned by the {@link TabularType#getIndexNames()} method of + * this instance's tabular type. The returned indices are the + * values of the fields in the supplied {@link CompositeData} + * instance that match the names given in the {@link TabularType}. * * @param val the {@link CompositeData} value whose index should * be calculated. @@ -106,7 +108,7 @@ public interface TabularData * Compares the specified object with this object for equality. * The object is judged equivalent if it is non-null, and also * an instance of {@link TabularData} with the same row type, - * and index to value mappings. The two compared instances may + * and {@link CompositeData} values. The two compared instances may * be equivalent even if they represent different implementations * of {@link TabularData}. * @@ -123,9 +125,9 @@ public interface TabularData * @return the matching {@link CompositeData} value, or * <code>null</code> if one does not exist. * @throws NullPointerException if the key is <code>null</code>. - * @throws InvalidOpenTypeException if the key does not match - * the {@link TabularType} of this - * instance. + * @throws InvalidKeyException if the key does not match + * the {@link TabularType} of this + * instance. */ CompositeData get(Object[] key); @@ -138,14 +140,12 @@ public interface TabularData TabularType getTabularType(); /** - * Returns the hash code of the composite data type. - * This is computed as the sum of the hash codes of the - * each index and its value, together with the hash - * code of the tabular type. These are the same elements - * of the type that are compared as part of the - * {@link #equals(java.lang.Object)} method, thus ensuring - * that the hashcode is compatible with the equality - * test. + * Returns the hash code of the composite data type. This is + * computed as the sum of the hash codes of each value, together + * with the hash code of the tabular type. These are the same + * elements of the type that are compared as part of the {@link + * #equals(java.lang.Object)} method, thus ensuring that the + * hashcode is compatible with the equality test. * * @return the hash code of this instance. */ @@ -196,15 +196,16 @@ public interface TabularData * values in the array, as well as from the existing values * in the table. The operation should be atomic; if one * value can not be added, then none of the values should - * be. + * be. If the array is <code>null</code> or empty, the + * method simply returns. * * @param vals the {@link CompositeData} values to add. - * @throws NullPointerException if <code>val</code> is + * @throws NullPointerException if a value from the array is * <code>null</code>. - * @throws InvalidOpenTypeException if the type of the + * @throws InvalidOpenTypeException if the type of a * given value does not * match the row type. - * @throws KeyAlreadyExistsException if the value has the + * @throws KeyAlreadyExistsException if a value has the * same calculated index * as an existing value or * of one of the other diff --git a/javax/management/openmbean/TabularDataSupport.java b/javax/management/openmbean/TabularDataSupport.java new file mode 100644 index 000000000..9dc8a0e97 --- /dev/null +++ b/javax/management/openmbean/TabularDataSupport.java @@ -0,0 +1,652 @@ +/* TabularDataSupport.java -- Tables of composite data structures. + 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.Serializable; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Provides an implementation of the {@link TabularData} + * interface using a {@link java.util.HashMap}. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class TabularDataSupport + implements TabularData, Serializable, Cloneable, Map +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 5720150593236309827L; + + /** + * Mapping of rows to column values. + * + * @serial the map of rows to column values. + */ + private Map dataMap; + + /** + * The tabular type which represents this tabular data instance. + * + * @serial the type information for this instance. + */ + private TabularType tabularType; + + /** + * Constructs a new empty {@link TabularDataSupport} with the + * specified type. The type may not be null. This constructor + * simply calls the other, with the default initial capacity of + * <code>101</code> and default load factor of <code>0.75</code>. + * + * @param type the tabular type of this tabular data instance. + * @throws IllegalArgumentException if <code>type</code> is + * <code>null</code>. + */ + public TabularDataSupport(TabularType type) + { + this(type, 101, 0.75f); + } + + /** + * Constructs a new empty {@link TabularDataSupport} with the + * specified type and the supplied initial capacity and load factor + * being used for the underlying {@link java.util.HashMap}. The + * type may not be null and the initial capacity and load factor + * must be positive. + * + * @param type the tabular type of this tabular data instance. + * @param cap the initial capacity of the underlying map. + * @param lf the load factor of the underlying map. + * @throws IllegalArgumentException if <code>type</code> is + * <code>null</code>, or + * <code>cap</code> or + * <code>lf</code> are + * negative. + */ + public TabularDataSupport(TabularType type, int cap, float lf) + { + if (type == null) + throw new IllegalArgumentException("The type may not be null."); + tabularType = type; + dataMap = new HashMap(cap, lf); + } + + /** + * Calculates the index the specified {@link CompositeData} value + * would have, if it was to be added to this {@link TabularData} + * instance. This method includes a check that the type of the + * given value is the same as the row type of this instance, but not + * a check for existing instances of the given value. The value + * must also not be <code>null</code>. Possible indices are + * selected by the {@link TabularType#getIndexNames()} method of + * this instance's tabular type. The returned indices are the + * values of the fields in the supplied {@link CompositeData} + * instance that match the names given in the {@link TabularType}. + * + * @param val the {@link CompositeData} value whose index should + * be calculated. + * @return the index the value would take on, if it were to be added. + * @throws NullPointerException if the value is <code>null</code>. + * @throws InvalidOpenTypeException if the value does not match the + * row type of this instance. + */ + public Object[] calculateIndex(CompositeData val) + { + if (!(val.getCompositeType().equals(tabularType.getRowType()))) + throw new InvalidOpenTypeException("The type of the given value " + + "does not match the row type " + + "of this instance."); + List indexNames = tabularType.getIndexNames(); + List matchingIndicies = new ArrayList(indexNames.size()); + Iterator it = indexNames.iterator(); + while (it.hasNext()) + { + String name = (String) it.next(); + matchingIndicies.add(val.get(name)); + } + return matchingIndicies.toArray(); + } + + /** + * Removes all {@link CompositeData} values from the table. + */ + public void clear() + { + dataMap.clear(); + } + + /** + * Returns a shallow clone of the information, as obtained by the + * {@link Object} implementation of {@link Object#clone()}. The map + * is also cloned, but it still references the same objects. + * + * @return a shallow clone of this {@link TabularDataSupport}. + */ + public Object clone() + { + TabularDataSupport clone = null; + try + { + clone = (TabularDataSupport) super.clone(); + clone.setMap((HashMap) ((HashMap) dataMap).clone()); + } + catch (CloneNotSupportedException e) + { + /* This won't happen as we implement Cloneable */ + } + return clone; + } + + /** + * Returns true iff this instance of the {@link TabularData} class + * contains a {@link CompositeData} value at the specified index. + * The method returns <code>false</code> if the given key can + * not be cast to an {@link java.lang.Object} array; otherwise + * it returns the result of {@link #containsKey(java.lang.Object[])}. + * + * + * @param key the key to test for. + * @return true if the key maps to a {@link CompositeData} value. + */ + public boolean containsKey(Object key) + { + if (key instanceof Object[]) + return containsKey((Object[]) key); + else + return false; + } + + /** + * Returns true iff this instance of the {@link TabularData} class + * contains a {@link CompositeData} value at the specified index. + * In any other circumstance, including if the given key + * is <code>null</code> or of the incorrect type, according to + * the {@link TabularType} of this instance, this method returns + * false. + * + * @param key the key to test for. + * @return true if the key maps to a {@link CompositeData} value. + */ + public boolean containsKey(Object[] key) + { + if (key == null) + return false; + if (!(isKeyValid(key))) + return false; + return dataMap.containsKey(key); + } + + /** + * Returns true iff this instance of the {@link TabularData} class + * contains the specified {@link CompositeData} value. If the given + * value is not an instance of {@link CompositeData}, this method + * simply returns false. + * + * @param val the value to test for. + * @return true if the value exists. + */ + public boolean containsValue(Object val) + { + if (val instanceof CompositeData) + return containsValue((CompositeData) val); + else + return false; + } + + /** + * Returns true iff this instance of the {@link TabularData} class + * contains the specified {@link CompositeData} value. + * In any other circumstance, including if the given value + * is <code>null</code> or of the incorrect type, according to + * the {@link TabularType} of this instance, this method returns + * false. + * + * @param val the value to test for. + * @return true if the value exists. + */ + public boolean containsValue(CompositeData val) + { + if (val == null) + return false; + if (!(val.getCompositeType().equals(tabularType.getRowType()))) + return false; + return dataMap.containsValue(val); + } + + /** + * <p> + * Returns a set view of the mappings in this Map. Each element in the + * set is a Map.Entry. The set is backed by the map, so that changes in + * one show up in the other. Modifications made while an iterator is + * in progress cause undefined behavior. If the set supports removal, + * these methods remove the underlying mapping from the map: + * <code>Iterator.remove</code>, <code>Set.remove</code>, + * <code>removeAll</code>, <code>retainAll</code>, and <code>clear</code>. + * Element addition, via <code>add</code> or <code>addAll</code>, is + * not supported via this set. + * </p> + * <p> + * <strong>Note</strong>: using the + * {@link java.util.Map.Entry#setValue(Object) will cause corruption of + * the index to row mappings. + * </p> + * + * @return the set view of all mapping entries + * @see java.util.Map.Entry + */ + public Set entrySet() + { + return dataMap.entrySet(); + } + + /** + * Compares the specified object with this object for equality. + * The object is judged equivalent if it is non-null, and also + * an instance of {@link TabularData} with the same row type, + * and {@link CompositeData} values. The two compared instances may + * be equivalent even if they represent different implementations + * of {@link TabularData}. + * + * @param obj the object to compare for equality. + * @return true if <code>obj</code> is equal to <code>this</code>. + */ + public boolean equals(Object obj) + { + if (!(obj instanceof TabularData)) + return false; + TabularData data = (TabularData) obj; + return tabularType.equals(data.getTabularType()) && + dataMap.values().equals(data.values()); + } + + /** + * Retrieves the value for the specified key by simply + * calling <code>get((Object[]) key)</code>. + * + * @param key the key whose value should be returned. + * @return the matching {@link CompositeData} value, or + * <code>null</code> if one does not exist. + * @throws NullPointerException if the key is <code>null</code>. + * @throws ClassCastException if the key is not an instance + * of <code>Object[]</code>. + * @throws InvalidKeyException if the key does not match + * the {@link TabularType} of this + * instance. + */ + public Object get(Object key) + { + return get((Object[]) key); + } + + /** + * Retrieves the {@link CompositeData} value for the specified + * key, or <code>null</code> if no such mapping exists. + * + * @param key the key whose value should be returned. + * @return the matching {@link CompositeData} value, or + * <code>null</code> if one does not exist. + * @throws NullPointerException if the key is <code>null</code>. + * @throws InvalidKeyException if the key does not match + * the {@link TabularType} of this + * instance. + */ + public CompositeData get(Object[] key) + { + if (!(isKeyValid(key))) + throw new InvalidKeyException("The key does not match the " + + "tabular type of this instance."); + return (CompositeData) dataMap.get(key); + } + + /** + * Returns the tabular type which corresponds to this instance + * of {@link TabularData}. + * + * @return the tabular type for this instance. + */ + public TabularType getTabularType() + { + return tabularType; + } + + /** + * Returns the hash code of the composite data type. This is + * computed as the sum of the hash codes of each value, together + * with the hash code of the tabular type. These are the same + * elements of the type that are compared as part of the {@link + * #equals(java.lang.Object)} method, thus ensuring that the + * hashcode is compatible with the equality test. + * + * @return the hash code of this instance. + */ + public int hashCode() + { + return tabularType.hashCode() + dataMap.values().hashCode(); + } + + /** + * Returns true if this {@link TabularData} instance + * contains no {@link CompositeData} values. + * + * @return true if the instance is devoid of rows. + */ + public boolean isEmpty() + { + return dataMap.isEmpty(); + } + + /** + * Returns true if the given key is valid for the + * @link{TabularType} of this instance. + * + * @return true if the key is valid. + * @throws NullPointerException if <code>key</code> + * is null. + */ + private boolean isKeyValid(Object[] key) + { + Iterator it = tabularType.getIndexNames().iterator(); + CompositeType rowType = tabularType.getRowType(); + for (int a = 0; it.hasNext(); ++a) + { + OpenType type = rowType.getType((String) it.next()); + if (!(type.isValue(key[a]))) + return false; + } + return true; + } + + /** + * Returns a set view of the keys in this Map. The set is backed by the + * map, so that changes in one show up in the other. Modifications made + * while an iterator is in progress cause undefined behavior. If the set + * supports removal, these methods remove the underlying mapping from + * the map: <code>Iterator.remove</code>, <code>Set.remove</code>, + * <code>removeAll</code>, <code>retainAll</code>, and <code>clear</code>. + * Element addition, via <code>add</code> or <code>addAll</code>, is + * not supported via this set. + * + * @return the set view of all keys + */ + public Set keySet() + { + return dataMap.keySet(); + } + + /** + * Adds the specified {@link CompositeData} value to the + * table. The value must be non-null, of the same type + * as the row type of this instance, and must not have + * the same index as an existing value. The index is + * calculated using the index names of the + * {@link TabularType} for this instance. + * + * @param val the {@link CompositeData} value to add. + * @throws NullPointerException if <code>val</code> is + * <code>null</code>. + * @throws InvalidOpenTypeException if the type of the + * given value does not + * match the row type. + * @throws KeyAlreadyExistsException if the value has the + * same calculated index + * as an existing value. + */ + public void put(CompositeData val) + { + Object[] key = calculateIndex(val); + if (dataMap.containsKey(key)) + throw new KeyAlreadyExistsException("A value with this index " + + "already exists."); + dataMap.put(key, val); + } + + /** + * Adds the specified {@link CompositeData} value to the + * table, ignoring the supplied key, by simply calling + * <code>put((CompositeData) val)</code>. + * + * @param key ignored. + * @param val the {@link CompositeData} value to add. + * @return the {@link CompositeData} value. + * @throws NullPointerException if <code>val</code> is + * <code>null</code>. + * @throws InvalidOpenTypeException if the type of the + * given value does not + * match the row type. + * @throws KeyAlreadyExistsException if the value has the + * same calculated index + * as an existing value. + */ + public Object put(Object key, Object val) + { + put((CompositeData) val); + return val; + } + + /** + * Adds each of the specified {@link CompositeData} values + * to the table. Each element of the array must meet the + * conditions given for the {@link #put(CompositeData)} + * method. In addition, the index of each value in the + * array must be distinct from the index of the other + * values in the array, as well as from the existing values + * in the table. The operation should be atomic; if one + * value can not be added, then none of the values should + * be. If the array is <code>null</code> or empty, the + * method simply returns. + * + * @param vals the {@link CompositeData} values to add. + * @throws NullPointerException if a value from the array is + * <code>null</code>. + * @throws InvalidOpenTypeException if the type of a + * given value does not + * match the row type. + * @throws KeyAlreadyExistsException if a value has the + * same calculated index + * as an existing value or + * of one of the other + * specified values. + */ + public void putAll(CompositeData[] vals) + { + if (vals == null || vals.length == 0) + return; + Map mapToAdd = new HashMap(vals.length); + for (int a = 0; a < vals.length; ++a) + { + Object[] key = calculateIndex(vals[a]); + if (dataMap.containsKey(key)) + throw new KeyAlreadyExistsException("Element " + a + ": A " + + "value with this index " + + "already exists."); + mapToAdd.put(key, vals[a]); + } + dataMap.putAll(mapToAdd); + } + + /** + * Converts each value from the specified map to a member of an + * array of {@link CompositeData} values and adds them using {@link + * #put(CompositeData[])}, if possible. As in {@link + * #put(Object,Object)}, the keys are simply ignored. This method + * is useful for adding the {@link CompositeData} values from a + * different {@link TabularData} instance, which uses the same + * {@link TabularType} but a different selection of index names, to + * this one. If the map is <code>null</code> or empty, the method + * simply returns. + * + * @param m the map to add. Only the values are used and must + * all be instances of {@link CompositeData}. + * @throws NullPointerException if a value from the map is + * <code>null</code>. + * @throws ClassCastException if a value from the map is not + * an instance of {@link CompositeData}. + * @throws InvalidOpenTypeException if the type of the + * given value does not + * match the row type. + * @throws KeyAlreadyExistsException if the value has the + * same calculated index + * as an existing value or + * of one of the other + * specified values. + */ + public void putAll(Map m) + { + if (m == null || m.size() == 0) + return; + Collection vals = m.values(); + CompositeData[] data = new CompositeData[vals.size()]; + Iterator it = vals.iterator(); + for (int a = 0; it.hasNext(); ++a) + { + data[a] = (CompositeData) it.next(); + } + putAll(data); + } + + /** + * Removes the value for the specified key by simply + * calling <code>remove((Object[]) key)</code>. + * + * @param key the key whose value should be removed. + * @return the removed value, or <code>null</code> if + * there is no value for the given key. + * @throws NullPointerException if the key is <code>null</code>. + * @throws ClassCastException if the key is not an instance + * of <code>Object[]</code>. + * @throws InvalidOpenTypeException if the key does not match + * the {@link TabularType} of this + * instance. + */ + public Object remove(Object key) + { + return remove((Object[]) key); + } + + /** + * Removes the {@link CompositeData} value located at the + * specified index. <code>null</code> is returned if the + * value does not exist. Otherwise, the removed value is + * returned. + * + * @param key the key of the value to remove. + * @return the removed value, or <code>null</code> if + * there is no value for the given key. + * @throws NullPointerException if the key is <code>null</code>. + * @throws InvalidOpenTypeException if the key does not match + * the {@link TabularType} of this + * instance. + */ + public CompositeData remove(Object[] key) + { + if (!(isKeyValid(key))) + throw new InvalidKeyException("The key does not match the " + + "tabular type of this instance."); + return (CompositeData) dataMap.remove(key); + } + + /** + * Package-private method to set the internal {@link java.util.Map} + * instance (used in cloning). + * + * @param map the new map used. + */ + void setMap(Map map) + { + dataMap = map; + } + + /** + * Returns the number of {@link CompositeData} values or rows + * in the table. + * + * @return the number of rows in the table. + */ + public int size() + { + return dataMap.size(); + } + + /** + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.openmbean.TabularDataSupport</code>) + * and the result of calling <code>toString()</code> on the + * tabular type and underlying hash map instance. + * + * @return a {@link java.lang.String} representation of the + * object. + */ + public String toString() + { + return getClass().getName() + + "[tabularType=" + tabularType + + ",dataMap=" + dataMap + + "]"; + } + + /** + * Returns a collection (or bag) view of the values in this Map. The + * collection is backed by the map, so that changes in one show up in + * the other. Modifications made while an iterator is in progress cause + * undefined behavior. If the collection supports removal, these methods + * remove the underlying mapping from the map: <code>Iterator.remove</code>, + * <code>Collection.remove</code>, <code>removeAll</code>, + * <code>retainAll</code>, and <code>clear</code>. Element addition, via + * <code>add</code> or <code>addAll</code>, is not supported via this + * collection. + * + * @return the collection view of all values + */ + public Collection values() + { + return dataMap.values(); + } + +} + |