diff options
author | Mark Wielaard <mark@gcc.gnu.org> | 2006-08-14 23:12:35 +0000 |
---|---|---|
committer | Mark Wielaard <mark@gcc.gnu.org> | 2006-08-14 23:12:35 +0000 |
commit | ac1ed908de999523efc36f38e69bca1aadfe0808 (patch) | |
tree | 97037d2c09c8384d80531f67ec36a01205df6bdb /libjava/classpath/javax/management | |
parent | abab460491408e05ea93fb85e1975296a87df504 (diff) | |
download | gcc-ac1ed908de999523efc36f38e69bca1aadfe0808.zip gcc-ac1ed908de999523efc36f38e69bca1aadfe0808.tar.gz gcc-ac1ed908de999523efc36f38e69bca1aadfe0808.tar.bz2 |
Imported GNU Classpath 0.92
2006-08-14 Mark Wielaard <mark@klomp.org>
Imported GNU Classpath 0.92
* HACKING: Add more importing hints. Update automake version
requirement.
* configure.ac (gconf-peer): New enable AC argument.
Add --disable-gconf-peer and --enable-default-preferences-peer
to classpath configure when gconf is disabled.
* scripts/makemake.tcl: Set gnu/java/util/prefs/gconf and
gnu/java/awt/dnd/peer/gtk to bc. Classify
gnu/java/security/Configuration.java as generated source file.
* gnu/java/lang/management/VMGarbageCollectorMXBeanImpl.java,
gnu/java/lang/management/VMMemoryPoolMXBeanImpl.java,
gnu/java/lang/management/VMClassLoadingMXBeanImpl.java,
gnu/java/lang/management/VMRuntimeMXBeanImpl.java,
gnu/java/lang/management/VMMemoryManagerMXBeanImpl.java,
gnu/java/lang/management/VMThreadMXBeanImpl.java,
gnu/java/lang/management/VMMemoryMXBeanImpl.java,
gnu/java/lang/management/VMCompilationMXBeanImpl.java: New VM stub
classes.
* java/lang/management/VMManagementFactory.java: Likewise.
* java/net/VMURLConnection.java: Likewise.
* gnu/java/nio/VMChannel.java: Likewise.
* java/lang/Thread.java (getState): Add stub implementation.
* java/lang/Class.java (isEnum): Likewise.
* java/lang/Class.h (isEnum): Likewise.
* gnu/awt/xlib/XToolkit.java (getClasspathTextLayoutPeer): Removed.
* javax/naming/spi/NamingManager.java: New override for StackWalker
functionality.
* configure, sources.am, Makefile.in, gcj/Makefile.in,
include/Makefile.in, testsuite/Makefile.in: Regenerated.
From-SVN: r116139
Diffstat (limited to 'libjava/classpath/javax/management')
38 files changed, 7216 insertions, 0 deletions
diff --git a/libjava/classpath/javax/management/Attribute.java b/libjava/classpath/javax/management/Attribute.java index 5c4a65e..ece9495 100644 --- a/libjava/classpath/javax/management/Attribute.java +++ b/libjava/classpath/javax/management/Attribute.java @@ -51,6 +51,11 @@ public class Attribute implements Serializable { /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 2484220110589082382L; + + /** * The attribute name. */ final String m_name; diff --git a/libjava/classpath/javax/management/AttributeList.java b/libjava/classpath/javax/management/AttributeList.java new file mode 100644 index 0000000..6823df3 --- /dev/null +++ b/libjava/classpath/javax/management/AttributeList.java @@ -0,0 +1,220 @@ +/* AttributeList.java -- A list of MBean 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; + +import java.util.ArrayList; + +/** + * Represents a list of MBean {@link Attribute}s, with their + * names and values. This is implemented as an + * {@link java.util.ArrayList} extension, with additional + * methods typed to only allow the addition of {@link Attribute}s. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class AttributeList + extends ArrayList +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -4077085769279709076L; + + /** + * Constructs an empty list with an initial capacity of ten. + * + * @see java.util.ArrayList#ArrayList() + */ + public AttributeList() + { + super(); + } + + /** + * Constructs an {@link AttributeList} using the contents + * of an existing list. The initial capacity is 110% of the + * size of the specified list. + * + * @param list the list to use to fill this list. + * @see java.util.ArrayList#ArrayList(java.util.Collection) + */ + public AttributeList(AttributeList list) + { + super(list); + } + + /** + * Constructs an empty list with the specified initial capacity. + * + * @param capacity the initial capacity of the list. + * @see java.util.ArrayList#ArrayList(int) + */ + public AttributeList(int capacity) + { + super(capacity); + } + + /** + * Adds the specified {@link Attribute} to the end of the list. + * + * @param attribute the attribute to add. + * @see java.util.Arraylist#add(Object) + */ + public void add(Attribute attribute) + { + super.add(attribute); + } + + /** + * <p> + * Adds the specified {@link Attribute} at the supplied index. + * Any attribute already at that index is moved up one place + * in the list to the position <code>(index + 1)</code>. + * Likewise, the attribute at <code>(index + 1)</code> is + * also moved up one place, continuing until the final + * attribute in the list moves to a new position, increasing + * the size of the list. + * </p> + * <p> + * If the index is invalid (i.e. it is smaller than zero, or + * greater than the current size of the list), a + * @link{RuntimeOperationsException} is thrown, which wraps + * the @link{IndexOutOfBoundsException} from the underlying + * array list. + * </p> + * + * @param index the index at which to place the new attribute. + * @param attribute the new attribute to add. + * @throws RuntimeOperationsException if <code>index < 0</code> + * or <code>index > size()</code> + * @see java.util.ArrayList#add(int, Object) + */ + public void add(int index, Attribute attribute) + { + try + { + super.add(index, attribute); + } + catch (IndexOutOfBoundsException e) + { + throw new RuntimeOperationsException(e, "Invalid index."); + } + } + + /** + * Adds all the {@link Attribute}s from the supplied list + * to the end of this list, in the order they are returned + * by the list's {@link java.util.Iterator}. + * + * @param list the list of attributes to add. + * @return true if the list changed. + * @see java.util.ArrayList#addAll(Collection) + */ + public boolean addAll(AttributeList list) + { + return super.addAll(list); + } + + /** + * <p> + * Adds all the {@link Attribute}s from the supplied list + * to this list, at the specified index. The attributes + * are added in the order they are returned by the + * list's {@link java.util.Iterator}. Any attribute already + * at that index is moved up one place in the list to the + * position <code>(index + list.size())</code>. + * Likewise, the attribute at <code>(index + list.size())</code> + * is also moved up one place, continuing until the final + * attribute in the original list. + * </p> + * <p> + * If the index is invalid (i.e. it is smaller than zero, or + * greater than the current size of the list), a + * @link{RuntimeOperationsException} is thrown, which wraps + * the @link{IndexOutOfBoundsException} from the underlying + * array list. + * </p> + * + * @param index the index at which to place the new attribute. + * @param list the list of attributes to add. + * @return true if the list changed. + * @throws RuntimeOperationsException if <code>index < 0</code> + * or <code>index > size()</code> + * @see java.util.ArrayList#addAll(int, Collection) + */ + public boolean addAll(int index, AttributeList list) + { + try + { + return super.addAll(index, list); + } + catch (IndexOutOfBoundsException e) + { + throw new RuntimeOperationsException(e, "Invalid index."); + } + } + + /** + * Replaces the attribute at the specified index with the one + * supplied. If the index is invalid (i.e. it is smaller than + * zero, or greater than the current size of the list), a + * @link{RuntimeOperationsException} is thrown, which wraps + * the @link{IndexOutOfBoundsException} from the underlying + * array list. + * + * @param index the index at which to place the new attribute. + * @param attribute the new attribute to add. + * @throws RuntimeOperationsException if <code>index < 0</code> + * or <code>index > size()</code> + * @see java.util.ArrayList#set(int, Object) + */ + public void set(int index, Attribute attribute) + { + try + { + super.set(index, attribute); + } + catch (IndexOutOfBoundsException e) + { + throw new RuntimeOperationsException(e, "Invalid index."); + } + } + +} diff --git a/libjava/classpath/javax/management/AttributeNotFoundException.java b/libjava/classpath/javax/management/AttributeNotFoundException.java new file mode 100644 index 0000000..2c6c698 --- /dev/null +++ b/libjava/classpath/javax/management/AttributeNotFoundException.java @@ -0,0 +1,71 @@ +/* AttributeNotFoundException.java -- Thrown by unknown 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 attribute is requested but can not be + * found. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class AttributeNotFoundException + extends OperationsException +{ + + /** + * Constructs a new <code>AttributeNotFoundException</code>. + */ + public AttributeNotFoundException() + { + super(); + } + + /** + * Constructs a new <code>AttributeNotFoundException</code> + * with the specified message. + * + * @param message the error message to give to the user. + */ + public AttributeNotFoundException(String message) + { + super(message); + } + +} + diff --git a/libjava/classpath/javax/management/DynamicMBean.java b/libjava/classpath/javax/management/DynamicMBean.java new file mode 100644 index 0000000..80ea72c --- /dev/null +++ b/libjava/classpath/javax/management/DynamicMBean.java @@ -0,0 +1,162 @@ +/* DynamicMBean.java -- A management bean with a dynamic interface. + 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 a management bean that provides a + * dynamic interface. Users of a {@link DynamicMBean} + * may retrieve information about its attributes at + * runtime and use this information to dynamically + * obtain the corresponding values of these attributes. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public interface DynamicMBean +{ + + /** + * Obtains the value of the specified attribute of the + * management bean. The management bean should perform + * a lookup for the named attribute, and return its value + * by calling the appropriate getter method, if possible. + * + * @param name the name of the attribute to retrieve. + * @return the value of the specified attribute. + * @throws AttributeNotFoundException if the name does not + * correspond to an attribute + * of the bean. + * @throws MBeanException if retrieving the attribute causes + * the bean to throw an exception (which + * becomes the cause of this exception). + * @throws ReflectionException if an exception occurred in trying + * to use the reflection interface + * to lookup the attribute. The + * thrown exception is the cause of + * this exception. + * @see #setAttribute(String) + */ + Object getAttribute(String name) + throws AttributeNotFoundException, MBeanException, + ReflectionException; + + /** + * Obtains the values of each of the specified attributes + * of the management bean. The returned list includes + * those attributes that were retrieved and their + * corresponding values. + * + * @param names the names of the attributes to retrieve. + * @return a list of the retrieved attributes. + * @see #setAttributes(AttributeList) + */ + AttributeList getAttributes(String[] names); + + /** + * Returns an information object which lists the attributes + * and actions associated with the management bean. + * + * @return a description of the management bean, including + * all exposed attributes and actions. + */ + MBeanInfo getMBeanInfo(); + + /** + * Invokes the specified action on the management bean using + * the supplied parameters. The signature of the action is + * specified by a {@link String} array, which lists the classes + * corresponding to each parameter. The class loader used to + * load these classes is the same as that used for loading the + * management bean itself. + * + * @param name the name of the action to invoke. + * @param params the parameters used to call the action. + * @param signature the signature of the action. + * @return the return value of the action. + * @throws MBeanException if the action throws an exception. The + * thrown exception is the cause of this + * exception. + * @throws ReflectionException if an exception occurred in trying + * to use the reflection interface + * to invoke the action. The + * thrown exception is the cause of + * this exception. + */ + Object invoke(String name, Object[] params, String[] signature) + throws MBeanException, ReflectionException; + + /** + * Sets the value of the specified attribute of the + * management bean. The management bean should perform + * a lookup for the named attribute, and sets its value + * using the associated setter method, if possible. + * + * @param attribute the attribute to set. + * @throws AttributeNotFoundException if the attribute does not + * correspond to an attribute + * of the bean. + * @throws InvalidAttributeValueException if the value is invalid + * for this particular + * attribute of the bean. + * @throws MBeanException if setting the attribute causes + * the bean to throw an exception (which + * becomes the cause of this exception). + * @throws ReflectionException if an exception occurred in trying + * to use the reflection interface + * to lookup the attribute. The + * thrown exception is the cause of + * this exception. + * @see #getAttribute(String) + */ + void setAttribute(Attribute attribute) + throws AttributeNotFoundException, InvalidAttributeValueException, + MBeanException, ReflectionException; + + /** + * Sets the value of each of the specified attributes + * to that supplied by the {@link Attribute} object. + * The returned list contains the attributes that were + * set and their new values. + * + * @param attributes the attributes to set. + * @return a list of the changed attributes. + * @see #getAttributes(AttributeList) + */ + AttributeList setAttributes(AttributeList attributes); + +} diff --git a/libjava/classpath/javax/management/IntrospectionException.java b/libjava/classpath/javax/management/IntrospectionException.java new file mode 100644 index 0000000..3b9d4b1 --- /dev/null +++ b/libjava/classpath/javax/management/IntrospectionException.java @@ -0,0 +1,78 @@ +/* IntrospectionException.java -- Thrown by bean introspection methods. + 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; + +/** + * A general for all exceptions thrown during introspection + * operations on management beans. For example, such an + * exception may be thrown while constructing one of + * the <code>MBeanXXXInfo</code> classes. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class IntrospectionException + extends OperationsException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 1054516935875481725L; + + /** + * Constructs a new <code>IntrospectionException</code>. + */ + public IntrospectionException() + { + super(); + } + + /** + * Constructs a new <code>IntrospectionException</code> + * with the specified message. + * + * @param message the error message to give to the user. + */ + public IntrospectionException(String message) + { + super(message); + } + +} + diff --git a/libjava/classpath/javax/management/InvalidAttributeValueException.java b/libjava/classpath/javax/management/InvalidAttributeValueException.java new file mode 100644 index 0000000..f766eda --- /dev/null +++ b/libjava/classpath/javax/management/InvalidAttributeValueException.java @@ -0,0 +1,71 @@ +/* InvalidAttributeValueException.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 value is given for an attribute which + * is invalid. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class InvalidAttributeValueException + extends OperationsException +{ + + /** + * Constructs a new <code>InvalidAttributeValueException</code>. + */ + public InvalidAttributeValueException() + { + super(); + } + + /** + * Constructs a new <code>InvalidAttributeValueException</code> + * with the specified message. + * + * @param message the error message to give to the user. + */ + public InvalidAttributeValueException(String message) + { + super(message); + } + +} + diff --git a/libjava/classpath/javax/management/JMException.java b/libjava/classpath/javax/management/JMException.java new file mode 100644 index 0000000..d057025 --- /dev/null +++ b/libjava/classpath/javax/management/JMException.java @@ -0,0 +1,71 @@ +/* JMException.java -- Thrown by the management classes. + 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; + +/** + * A general superclass for all non-runtime management + * exceptions. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class JMException + extends Exception +{ + + /** + * Constructs a new <code>JMException</code>. + */ + public JMException() + { + super(); + } + + /** + * Constructs a new <code>JMException</code> + * with the specified message. + * + * @param message the error message to give to the user. + */ + public JMException(String message) + { + super(message); + } + +} + diff --git a/libjava/classpath/javax/management/JMRuntimeException.java b/libjava/classpath/javax/management/JMRuntimeException.java new file mode 100644 index 0000000..ba14a19 --- /dev/null +++ b/libjava/classpath/javax/management/JMRuntimeException.java @@ -0,0 +1,71 @@ +/* JMRuntimeException.java -- Thrown by the management classes. + 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; + +/** + * A general superclass for all runtime management + * exceptions. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class JMRuntimeException + extends RuntimeException +{ + + /** + * Constructs a new <code>JMRuntimeException</code>. + */ + public JMRuntimeException() + { + super(); + } + + /** + * Constructs a new <code>JMRuntimeException</code> + * with the specified message. + * + * @param message the error message to give to the user. + */ + public JMRuntimeException(String message) + { + super(message); + } + +} + diff --git a/libjava/classpath/javax/management/ListenerNotFoundException.java b/libjava/classpath/javax/management/ListenerNotFoundException.java new file mode 100644 index 0000000..ea3cb74 --- /dev/null +++ b/libjava/classpath/javax/management/ListenerNotFoundException.java @@ -0,0 +1,75 @@ +/* ListenerNotFoundException.java -- Thrown when a listener does not exist. + 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 listener does not exist. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class ListenerNotFoundException + extends OperationsException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -7242605822448519061L; + + /** + * Constructs a new <code>ListenerNotFoundException</code>. + */ + public ListenerNotFoundException() + { + super(); + } + + /** + * Constructs a new <code>ListenerNotFoundException</code> + * with the specified message. + * + * @param message the error message to give to the user. + */ + public ListenerNotFoundException(String message) + { + super(message); + } + +} + diff --git a/libjava/classpath/javax/management/MBeanAttributeInfo.java b/libjava/classpath/javax/management/MBeanAttributeInfo.java new file mode 100644 index 0000000..bded7e4 --- /dev/null +++ b/libjava/classpath/javax/management/MBeanAttributeInfo.java @@ -0,0 +1,301 @@ +/* MBeanAttributeInfo.java -- Information about an attribute of 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; + +import java.lang.reflect.Method; + +/** + * Describes the attributes of a management bean. + * The information in this class is immutable as standard. + * Of course, subclasses may change this, but this + * behaviour is not recommended. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class MBeanAttributeInfo + extends MBeanFeatureInfo + implements Cloneable +{ + + /** + * The type of the attribute. + * + * @serial the attribute type. + */ + private String attributeType; + + /** + * True if the attribute's value can be changed. + * + * @serial true if the value can be changed. + */ + private boolean isWrite; + + /** + * True if the attribute's value can be read. + * + * @serial true if the value can be read. + */ + private boolean isRead; + + /** + * True if the attribute is a boolean and thus + * has a isXXX accessor rather than a getXXX accessor. + * + * @serial true if the attribute has an isXXX accessor. + */ + private boolean is; + + /** + * Constructs a new {@link MBeanAttributeInfo} using the specified + * name and description, with the given accessor and mutator + * methods. A <code>null</code> value for the accessor method + * indicates that the value can not be read. A <code>null</code> + * value for the mutator method indicates that the value can not be + * changed. + * + * @param name the name of the attribute. + * @param desc a description of the attribute. + * @param getter the accessor method, or <code>null</code> if the value + * can not be read. + * @param setter the mutator method, or <code>null</code> if the value + * can not be changed. + * @throws IntrospectionException if both the accessor and mutator method + * are <code>null</code>. + */ + public MBeanAttributeInfo(String name, String desc, + Method getter, Method setter) + throws IntrospectionException + { + super(name, desc); + if (getter == null && setter == null) + throw new IntrospectionException("Both the getter and setter methods can " + + "not be null."); + if (getter == null) + { + attributeType = setter.getParameterTypes()[0].getName(); + isRead = false; + is = false; + } + else + { + attributeType = getter.getReturnType().getName(); + isRead = true; + is = getter.getName().startsWith("is"); + } + if (setter != null) + isWrite = true; + } + + /** + * Constructs a new {@link MBeanAttributeInfo} using the specified + * name, description and type with the given settings for the accessor + * and mutator methods. + * + * @param name the name of the attribute. + * @param type the type of the attribute, in the form of its class name. + * @param desc a description 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 attribute is both unreadable + * and unwritable. + */ + public MBeanAttributeInfo(String name, String type, String desc, + boolean isReadable, boolean isWritable, + boolean isIs) + { + super(name, desc); + if (!isReadable && !isWritable) + throw new IllegalArgumentException("The attribute can not be both " + + "unreadable and unwritable."); + attributeType = type; + isRead = isReadable; + isWrite = isWritable; + is = isIs; + } + + /** + * Returns a clone of this instance. The clone is created + * using just the method provided by {@link java.lang.Object}. + * Thus, the clone is just a shallow clone as returned by + * that method, and does not contain any deeper cloning based + * on the subject of this class. + * + * @return a clone of this instance. + * @see java.lang.Cloneable + */ + public Object clone() + { + try + { + return super.clone(); + } + catch (CloneNotSupportedException e) + { + /* This shouldn't happen; we implement Cloneable */ + throw new IllegalStateException("clone() called on " + + "non-cloneable object."); + } + } + + /** + * Compares this feature with the supplied object. This + * returns true iff the object is an instance of + * {@link MBeanAttributeInfo}, {@link Object#equals()} + * returns true for a comparison of both the name and + * description of this attribute with that of the specified + * object (performed by the superclass), and the type and + * boolean flags of the two instances are equal. + * + * @param obj the object to compare. + * @return true if the object is a {@link MBeanAttributeInfo} + * instance, + * <code>name.equals(object.getName())</code>, + * <code>description.equals(object.getDescription())</code>, + * <code>attributeType.equals(object.getType())</code>, + * <code>isRead == object.isReadable()</code>, + * <code>isWrite == object.isWritable()</code>, + * <code>is == object.isIs()</code> + */ + public boolean equals(Object obj) + { + if (!(obj instanceof MBeanAttributeInfo)) + return false; + if (!(super.equals(obj))) + return false; + MBeanAttributeInfo o = (MBeanAttributeInfo) obj; + return (attributeType.equals(o.getType()) && + isRead == o.isReadable() && + isWrite == o.isWritable() && + is == o.isIs()); + } + + /** + * Returns the type of this attribute, in the form of its class name. + * + * @return the type of this attribute. + */ + public String getType() + { + return attributeType; + } + + /** + * Returns the hashcode of the attribute information as the sum of + * the hashcode of the superclass, the hashcode of the type, + * the hashcode of {@link #isReadable()}, twice the hashcode + * of {@link #isWritable()} and four times the hashcode + * of {@link #isIs()}. + * + * @return the hashcode of the attribute information. + */ + public int hashCode() + { + return super.hashCode() + attributeType.hashCode() + + Boolean.valueOf(isRead).hashCode() + + (2 * Boolean.valueOf(isWrite).hashCode()) + + (4 * Boolean.valueOf(is).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>. + */ + public boolean isIs() + { + return is; + } + + /** + * Returns true if value of this attribute can be read. + * + * @return true if the value of the attribute can be read. + */ + public boolean isReadable() + { + return isRead; + } + + /** + * Returns true if the value of this attribute can be changed. + * + * @return true if the value of the attribute can be changed. + */ + public boolean isWritable() + { + return isWrite; + } + + /** + * <p> + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.MBeanAttributeInfo</code>), + * the name, description and type of the attribute and the + * current settings of the {@link #isReadable()}, + * {@link #isWritable()} and {@link #isIs()} properties. + * </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) + { + super.toString(); + string = string.substring(0, string.length() - 1) + + ",type=" + attributeType + + ",isReadable=" + (isRead ? "yes" : "no") + + ",isWritable=" + (isWrite ? "yes" : "no") + + ",isIs=" + (is ? "yes" : "no") + + "]"; + } + return string; + } + +} diff --git a/libjava/classpath/javax/management/MBeanConstructorInfo.java b/libjava/classpath/javax/management/MBeanConstructorInfo.java new file mode 100644 index 0000000..832a3296 --- /dev/null +++ b/libjava/classpath/javax/management/MBeanConstructorInfo.java @@ -0,0 +1,228 @@ +/* MBeanConstructorInfo.java -- Information about a bean's 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; + +import java.lang.reflect.Constructor; + +import java.util.Arrays; + +/** + * Describes the constructors of a management bean. + * The information in this class is immutable as standard. + * Of course, subclasses may change this, but this + * behaviour is not recommended. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class MBeanConstructorInfo + extends MBeanFeatureInfo + implements Cloneable +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 4433990064191844427L; + + /** + * The signature of the constructor i.e. the argument types. + */ + private MBeanParameterInfo[] signature; + + /** + * Constructs a @link{MBeanConstructorInfo} with the specified + * description using the given constructor. Each parameter is + * described merely by its type; the name and description are + * <code>null</code>. + * + * @param desc a description of the attribute. + * @param cons the constructor. + */ + public MBeanConstructorInfo(String desc, Constructor cons) + { + super(cons.getName(), desc); + Class[] paramTypes = cons.getParameterTypes(); + signature = new MBeanParameterInfo[paramTypes.length]; + for (int a = 0; a < paramTypes.length; ++a) + signature[a] = new MBeanParameterInfo(null, + paramTypes[a].getName(), + null); + } + + /** + * 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. + * + * @param name the name of the constructor. + * @param desc a description of the attribute. + * @param sig the signature of the constructor, as a series + * of {@link MBeanParameterInfo} objects, one for + * each parameter. + */ + public MBeanConstructorInfo(String name, String desc, + MBeanParameterInfo[] sig) + { + super(name, desc); + if (sig == null) + signature = new MBeanParameterInfo[0]; + else + signature = sig; + } + + /** + * Returns a clone of this instance. The clone is created + * using just the method provided by {@link java.lang.Object}. + * Thus, the clone is just a shallow clone as returned by + * that method, and does not contain any deeper cloning based + * on the subject of this class. + * + * @return a clone of this instance. + * @see java.lang.Cloneable + */ + public Object clone() + { + try + { + return super.clone(); + } + catch (CloneNotSupportedException e) + { + /* This shouldn't happen; we implement Cloneable */ + throw new IllegalStateException("clone() called on " + + "non-cloneable object."); + } + } + + /** + * Compares this feature with the supplied object. This returns + * true iff the object is an instance of {@link + * MBeanConstructorInfo}, {@link Object#equals()} returns true for a + * comparison of both the name and description of this notification + * with that of the specified object (performed by the superclass), + * and the two signature arrays contain the same elements in the + * same order (but one may be longer than the other). + * + * @param obj the object to compare. + * @return true if the object is a {@link MBeanConstructorInfo} + * instance, + * <code>name.equals(object.getName())</code>, + * <code>description.equals(object.getDescription())</code> + * and the corresponding elements of the signature arrays are + * equal. + */ + public boolean equals(Object obj) + { + if (!(obj instanceof MBeanConstructorInfo)) + return false; + if (!(super.equals(obj))) + return false; + MBeanConstructorInfo o = (MBeanConstructorInfo) obj; + MBeanParameterInfo[] sig = o.getSignature(); + for (int a = 0; a < signature.length; ++a) + { + if (a == sig.length) + return true; + if (!(signature[a].equals(sig[a]))) + return false; + } + return true; + } + + /** + * Returns the constructor's signature, in the form of + * information on each parameter. Each parameter is + * described by an instance of {@link MBeanParameterInfo}. + * The returned array is a shallow copy of the array used + * by this instance, so changing which elements are stored + * in the array won't affect the array used by this, but + * changing the actual elements will affect the ones used + * here. + * + * @return an array of {@link MBeanParameterInfo} objects, + * describing the constructor parameters. + */ + public MBeanParameterInfo[] getSignature() + { + return (MBeanParameterInfo[]) signature.clone(); + } + + /** + * Returns the hashcode of the constructor information as the sum + * of the hashcode of the superclass and the hashcode of the parameter + * array. + * + * @return the hashcode of the constructor information. + */ + public int hashCode() + { + return super.hashCode() + Arrays.hashCode(signature); + } + + /** + * <p> + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.MBeanConstructorInfo</code>), + * the name and description of the constructor and the + * contents of the array of parameters. + * </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) + { + super.toString(); + string = string.substring(0, string.length() - 1) + + ",signature=" + Arrays.toString(signature) + + "]"; + } + return string; + } + +} diff --git a/libjava/classpath/javax/management/MBeanException.java b/libjava/classpath/javax/management/MBeanException.java new file mode 100644 index 0000000..f082275 --- /dev/null +++ b/libjava/classpath/javax/management/MBeanException.java @@ -0,0 +1,118 @@ +/* MBeanException.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 exception thrown by a management + * bean. When a management bean executes code that causes + * an exception to be thrown, the resulting exception is + * wrapped inside an {@link MBeanException}. Calling + * {@link getTargetException()} will return the wrapped + * exception. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class MBeanException + extends JMException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 4066342430588744142L; + + /* Sun re-implemented causality -- don't know why, but + serialization demands we do too... */ + + /** + * The target exception. + * + * @serial the target exception. + */ + private Exception exception; + + /** + * Constructs a new <code>MBeanException</code> wrapping + * the specified exception. + * + * @param e the exception to be wrapped. + */ + public MBeanException(Exception e) + { + super(); + exception = e; + } + + /** + * Constructs a new <code>MBeanException</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 MBeanException(Exception e, String message) + { + super(message); + exception = e; + } + + /** + * Returns the true cause of this exception, the wrapped + * exception. + * + * @return the wrapped exception. + */ + public Throwable getCause() + { + return exception; + } + + /** + * Returns the true cause of this exception, the wrapped + * exception. + * + * @return the wrapped exception. + */ + public Exception getTargetException() + { + return exception; + } + +} + diff --git a/libjava/classpath/javax/management/MBeanFeatureInfo.java b/libjava/classpath/javax/management/MBeanFeatureInfo.java new file mode 100644 index 0000000..4f0243e --- /dev/null +++ b/libjava/classpath/javax/management/MBeanFeatureInfo.java @@ -0,0 +1,186 @@ +/* MBeanFeatureInfo.java -- Information about a bean feature. + 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; + +import java.io.Serializable; + +/** + * A general superclass for the description of features + * of management beans. This allows the user to access + * the feature dynamically, without knowing the details + * beforehand. The information is immutable as standard. + * Of course, subclasses may change this, but this + * behaviour is not recommended. + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class MBeanFeatureInfo + implements Serializable +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 3952882688968447265L; + + /** + * A description of the feature in human-readable form. + * Subclasses should access this via the {@link #getDescription()} + * function rather than using the value directly. + * + * @serial a description of the feature. + */ + protected String description; + + /** + * The name of the feature. Subclasses should access this + * via the {@link #getName()} function rather than using the + * value directly. + * + * @serial the name of the feature. + */ + protected String name; + + /** + * The <code>toString()</code> result of this instance. + */ + protected transient String string; + + /** + * Constructs a new {@link MBeanFeatureInfo} with the specified + * name and description. + * + * @param name the name of the management bean feature. + * @param description the description of the feature. + */ + public MBeanFeatureInfo(String name, String description) + { + this.name = name; + this.description = description; + } + + /** + * Compares this feature with the supplied object. This + * returns true iff the object is an instance of + * {@link MBeanFeatureInfo} and {@link Object#equals()} + * returns true for a comparison of both the name and + * description of this feature with that of the specified + * object. + * + * @param obj the object to compare. + * @return true if the object is a {@link MBeanFeatureInfo} + * instance, + * <code>name.equals(object.getName())</code> and + * <code>description.equals(object.getDescription</code>. + */ + public boolean equals(Object obj) + { + if (obj instanceof MBeanFeatureInfo) + { + MBeanFeatureInfo o = (MBeanFeatureInfo) obj; + return ((name == null ? + o.getName() == null : + name.equals(o.getName())) && + (description == null ? + o.getDescription() == null : + description.equals(o.getDescription()))); + } + else + return false; + } + + /** + * Returns a description of this feature. + * + * @return a human-readable description. + */ + public String getDescription() + { + return description; + } + + /** + * Returns the name of this feature. + * + * @return the name of the feature. + */ + public String getName() + { + return name; + } + + /** + * Returns the hashcode of the feature as + * the sum of the hashcodes of its name + * and description. + * + * @return the hashcode of this feature. + */ + public int hashCode() + { + return (name == null ? -1 : name.hashCode()) + + (description == null ? -1 : description.hashCode()); + } + + /** + * <p> + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.MBeanFeatureInfo</code>) and + * the name and description of the feature. + * </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=" + name + + ",desc=" + description + + "]"; + return string; + } + +} diff --git a/libjava/classpath/javax/management/MBeanInfo.java b/libjava/classpath/javax/management/MBeanInfo.java new file mode 100644 index 0000000..e6f03f0 --- /dev/null +++ b/libjava/classpath/javax/management/MBeanInfo.java @@ -0,0 +1,397 @@ +/* MBeanInfo.java -- Information 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; + +import java.io.Serializable; + +import java.util.Arrays; + +/** + * <p> + * Describes the interface of a management bean. This allows + * the user to access the bean dynamically, without knowing + * the details of any of its attributes, operations, + * constructors or notifications beforehand. The information + * is immutable as standard. Of course, subclasses may change + * this, but this behaviour is not recommended. + * </p> + * <p> + * The contents of this class, for standard management beans, + * are dynamically compiled using reflection. + * {@link #getClassName()} and {@link #getConstructors()} + * return the name of the class and its constructors, respectively. + * This is much the same as could be obtained by reflection on the + * bean. {@link #getAttributes()} and {@link #getOperations()}, + * however, do something more in splitting the methods of the + * class into two sets. Those of the form, <code>getXXX</code>, + * <code>setXXX</code> and <code>isXXX</code> are taken to be + * the accessors and mutators of a series of attributes, with + * <code>XXX</code> being the attribute name. These are returned + * by {@link getAttributes()} and the {@link Attribute} class can + * be used to manipulate them. The remaining methods are classified + * as operations and returned by {@link getOperations()}. + * </p> + * <p> + * Beans can also broadcast notifications. If the bean provides this + * facility, by implementing the {@link NotificationBroadcaster} + * interface, then an array of {@link MBeanNotificationInfo} objects + * may be obtained from {@link #getNotifications()}, which describe + * the notifications emitted. + * </p> + * <p> + * Model management beans and open management beans also supply an + * instance of this class, as part of implementing the + * {@link DynamicMBean#getMBeanInfo()} method of {@link DynamicMBean}. + * </p> + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class MBeanInfo + implements Cloneable, Serializable +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -6451021435135161911L; + + /** + * A description of the bean. + * + * @serial The bean's description. + */ + private String description; + + /** + * The class name of the management bean. + * + * @serial The bean's class name. + */ + private String className; + + /** + * Descriptions of the attributes provided by the bean. + */ + private MBeanAttributeInfo[] attributes; + + /** + * Descriptions of the operations provided by the bean. + */ + private MBeanOperationInfo[] operations; + + /** + * Descriptions of the bean's constructors. + */ + private MBeanConstructorInfo[] constructors; + + /** + * Descriptions of the notifications emitted by the bean. + * + * @serial The bean's notifications. + */ + private MBeanNotificationInfo[] notifications; + + /** + * The <code>toString()</code> result of this instance. + */ + private transient String string; + + /** + * Constructs a new {@link MBeanInfo} 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. + * + * @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>. + */ + public MBeanInfo(String name, String desc, MBeanAttributeInfo[] attribs, + MBeanConstructorInfo[] cons, MBeanOperationInfo[] ops, + MBeanNotificationInfo[] notifs) + { + className = name; + description = desc; + if (attribs == null) + attributes = new MBeanAttributeInfo[0]; + else + attributes = attribs; + if (cons == null) + constructors = new MBeanConstructorInfo[0]; + else + constructors = cons; + if (ops == null) + operations = new MBeanOperationInfo[0]; + else + operations = ops; + if (notifs == null) + notifications = new MBeanNotificationInfo[0]; + else + notifications = notifs; + } + + /** + * Returns a shallow clone of the information. This is + * simply a new copy of each string and a clone + * of each array, which still references the same objects, + * as obtained by the {@link Object} implementation of + * {@link Object#clone()}. As the fields can not be + * changed, this method is only really of interest to + * subclasses which may add new mutable fields or make + * the existing ones mutable. + * + * @return a shallow clone of this {@link MBeanInfo}. + */ + public Object clone() + { + MBeanInfo clone = null; + try + { + clone = (MBeanInfo) super.clone(); + } + catch (CloneNotSupportedException e) + { + /* This won't happen as we implement Cloneable */ + } + return clone; + } + + /** + * Compares this feature with the supplied object. This returns + * true iff the object is an instance of {@link MBeanInfo} and + * {@link Object#equals()} returns true for a comparison of the + * class name and description, and the arrays each contain the same + * elements in the same order (but one may be longer than the + * other). + * + * @param obj the object to compare. + * @return true if the object is a {@link MBeanInfo} + * instance, + * <code>className.equals(object.getClassName())</code>, + * <code>description.equals(object.getDescription())</code> + * and the corresponding elements of the arrays are + * equal. + */ + public boolean equals(Object obj) + { + if (!(obj instanceof MBeanInfo)) + return false; + if (!(super.equals(obj))) + return false; + MBeanInfo o = (MBeanInfo) obj; + MBeanAttributeInfo[] attr = o.getAttributes(); + for (int a = 0; a < attributes.length; ++a) + { + if (a == attr.length) + return true; + if (!(attributes[a].equals(attr[a]))) + return false; + } + MBeanConstructorInfo[] cons = o.getConstructors(); + for (int a = 0; a < constructors.length; ++a) + { + if (a == cons.length) + return true; + if (!(constructors[a].equals(cons[a]))) + return false; + } + MBeanOperationInfo[] ops = o.getOperations(); + for (int a = 0; a < operations.length; ++a) + { + if (a == ops.length) + return true; + if (!(operations[a].equals(ops[a]))) + return false; + } + MBeanNotificationInfo[] notifs = o.getNotifications(); + for (int a = 0; a < notifications.length; ++a) + { + if (a == notifs.length) + return true; + if (!(notifications[a].equals(notifs[a]))) + return false; + } + return (className.equals(o.getClassName()) && + description.equals(o.getDescription())); + } + + /** + * Returns descriptions of each of the attributes provided + * by this management bean. The returned value is a shallow + * copy of the attribute array maintained by this instance. + * Hence, changing the elements of the returned array will not + * affect the attribute array, and the elements (instances + * of the {@link MBeanAttributeInfo} class) are immutable. + * + * @return an array of {@link MBeanAttributeInfo} objects, + * representing the attributes emitted by this + * management bean. + */ + public MBeanAttributeInfo[] getAttributes() + { + return (MBeanAttributeInfo[]) attributes.clone(); + } + + /** + * Returns the class name of the management bean. + * + * @return the bean's class name. + */ + public String getClassName() + { + return className; + } + + /** + * Returns descriptions of each of the constructors provided + * by this management bean. The returned value is a shallow + * copy of the constructor array maintained by this instance. + * Hence, changing the elements of the returned array will not + * affect the constructor array, and the elements (instances + * of the {@link MBeanConstructorInfo} class) are immutable. + * + * @return an array of {@link MBeanConstructorInfo} objects, + * representing the constructors emitted by this + * management bean. + */ + public MBeanConstructorInfo[] getConstructors() + { + return (MBeanConstructorInfo[]) constructors.clone(); + } + + /** + * Returns a description of the management bean. + * + * @return the bean's description. + */ + public String getDescription() + { + return description; + } + + /** + * Returns descriptions of each of the notifications emitted + * by this management bean. The returned value is a shallow + * copy of the notification array maintained by this instance. + * Hence, changing the elements of the returned array will not + * affect the notification array, and the elements (instances + * of the {@link MBeanNotificationInfo} class) are immutable. + * + * @return an array of {@link MBeanNotificationInfo} objects, + * representing the notifications emitted by this + * management bean. + */ + public MBeanNotificationInfo[] getNotifications() + { + return (MBeanNotificationInfo[]) notifications.clone(); + } + + /** + * Returns descriptions of each of the operations provided + * by this management bean. The returned value is a shallow + * copy of the operation array maintained by this instance. + * Hence, changing the elements of the returned array will not + * affect the operation array, and the elements (instances + * of the {@link MBeanOperationInfo} class) are immutable. + * + * @return an array of {@link MBeanOperationInfo} objects, + * representing the operations emitted by this + * management bean. + */ + public MBeanOperationInfo[] getOperations() + { + return (MBeanOperationInfo[]) operations.clone(); + } + + /** + * Returns the hashcode of the information as the sum of the + * hashcode of the classname, description and each array. + * + * @return the hashcode of the information. + */ + public int hashCode() + { + return className.hashCode() + description.hashCode() + + Arrays.hashCode(attributes) + Arrays.hashCode(constructors) + + Arrays.hashCode(operations) + Arrays.hashCode(notifications); + } + + /** + * <p> + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.MBeanInfo</code>), + * the name and description of the bean and the contents + * of the four arrays. + * </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=" + className + + ",desc=" + description + + ",attributes=" + Arrays.toString(attributes) + + ",constructors=" + Arrays.toString(constructors) + + ",operations=" + Arrays.toString(operations) + + ",notifications=" + Arrays.toString(notifications) + + "]"; + return string; + } + +} diff --git a/libjava/classpath/javax/management/MBeanNotificationInfo.java b/libjava/classpath/javax/management/MBeanNotificationInfo.java new file mode 100644 index 0000000..ba4077e --- /dev/null +++ b/libjava/classpath/javax/management/MBeanNotificationInfo.java @@ -0,0 +1,227 @@ +/* MBeanNotificationInfo.java -- Information about a bean's notification. + 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; + +import java.util.Arrays; + +/** + * <p> + * Describes the notifications emitted by a management bean. + * An instance of this class is specific to notifications + * involving a particular type of object. A new instance + * should be created for each Java class used for notifications, + * and the Java class name forms the name of the instance. + * Each instance lists a number of notification types; these + * are not types in the sense of different Java classes, but + * instead form the names of notifications following the same + * syntax as Java property and package names. + * </p> + * <p> + * For instance, a management bean may emit two notifications + * containing {@link java.lang.String} objects. Both would be described + * using one instance of this class, with a member of the array + * returned by {@link #getNotifTypes()} for each one. If another + * notification containing a {@link java.util.Date} object were to + * be added, this would require a new instance of this class. + * </p> + * <p> + * The information in this class is immutable as standard. + * Of course, subclasses may change this, but this + * behaviour is not recommended. + * </p> + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class MBeanNotificationInfo + extends MBeanFeatureInfo + implements Cloneable +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -3888371564530107064L; + + /** + * The types of notification described by this instance. + * + * @serial the types of notification. + */ + private String[] types; + + /** + * Constructs a new {@link MBeanNotificationInfo} with the + * specified name, description and notification types. The + * notification types array may be <code>null</code> or of + * zero length, in order to indicate the absence of any types. + * + * @param types an array of {@link java.lang.String} objects, + * containing the names of the notifications emitted + * of this Java type. The names use the dot notation + * familiar from Java property and package names. + * @param name the name of the Java class the notifications described + * by this object are instances of. + * @param description a description of the data. + * @throws IllegalArgumentException for some reason... + */ + public MBeanNotificationInfo(String[] types, String name, + String description) + { + super(name, description); + this.types = types; + } + + /** + * Returns a clone of this instance. The clone is created + * using just the method provided by {@link java.lang.Object}. + * Thus, the clone is just a shallow clone as returned by + * that method, and does not contain any deeper cloning based + * on the subject of this class. + * + * @return a clone of this instance. + * @see java.lang.Cloneable + */ + public Object clone() + { + try + { + return super.clone(); + } + catch (CloneNotSupportedException e) + { + /* This shouldn't happen; we implement Cloneable */ + throw new IllegalStateException("clone() called on " + + "non-cloneable object."); + } + } + + /** + * Compares this feature with the supplied object. This returns + * true iff the object is an instance of {@link + * MBeanNotificationInfo}, {@link Object#equals()} returns true for + * a comparison of both the name and description of this + * notification with that of the specified object, and the two + * notification type arrays contain the same elements in the same + * order (but one may be longer than the other). + * + * @param obj the object to compare. + * @return true if the object is a {@link MBeanNotificationInfo} + * instance, + * <code>name.equals(object.getName())</code>, + * <code>description.equals(object.getDescription())</code> + * and the corresponding elements of the type arrays are + * equal. + */ + public boolean equals(Object obj) + { + if (obj instanceof MBeanNotificationInfo) + { + if (!(super.equals(obj))) + return false; + MBeanNotificationInfo o = (MBeanNotificationInfo) obj; + String[] oTypes = o.getNotifTypes(); + for (int a = 0; a < types.length; ++a) + { + if (a == oTypes.length) + return true; + if (!(types[a].equals(oTypes[a]))) + return false; + } + return true; + } + else + return false; + } + + /** + * Returns the notification types that the management bean may emit. + * The notification types are strings using the dot notation + * familiar from Java property and package names. Changing the + * returned array does not affect the values retained by this + * instance. + * + * @return the notification types. + */ + public String[] getNotifTypes() + { + return types; + } + + /** + * Returns the hashcode of the notification information as the sum + * of the hashcode of the superclass and the hashcode of the types + * array. + * + * @return the hashcode of the notification information. + */ + public int hashCode() + { + return super.hashCode() + Arrays.hashCode(types); + } + + /** + * <p> + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.MBeanNotificationInfo</code>), + * the name and description of the notification and the + * contents of the array of types. + * </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) + { + super.toString(); + string = string.substring(0, string.length() - 1) + + ",types=" + Arrays.toString(types) + + "]"; + } + return string; + } + +} diff --git a/libjava/classpath/javax/management/MBeanOperationInfo.java b/libjava/classpath/javax/management/MBeanOperationInfo.java new file mode 100644 index 0000000..a2db8d1b --- /dev/null +++ b/libjava/classpath/javax/management/MBeanOperationInfo.java @@ -0,0 +1,344 @@ +/* MBeanOperationInfo.java -- Information about a bean's operations. + 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; + +import java.lang.reflect.Method; + +import java.util.Arrays; + +/** + * Describes the operations of a management bean. + * The information in this class is immutable as standard. + * Of course, subclasses may change this, but this + * behaviour is not recommended. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class MBeanOperationInfo + extends MBeanFeatureInfo + implements Cloneable +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -6178860474881375330L; + + /** + * Used to signify that the operation merely provides information + * (akin to an accessor). + */ + public static final int INFO = 0; + + /** + * Used to signify that the operation makes some change to the + * state of the bean (akin to a mutator). + */ + public static final int ACTION = 1; + + /** + * Used to signify that the operation makes some state change + * to the bean and also returns information. + */ + public static final int ACTION_INFO = 2; + + /** + * Used to signify that the behaviour of the operation is + * unknown. + */ + public static final int UNKNOWN = 3; + + /** + * The return type of the method, in the form of its class name. + */ + private String type; + + /** + * The signature of the constructor i.e. the argument types. + */ + private MBeanParameterInfo[] signature; + + /** + * The impact of the method, as one of {@link #INFO}, {@link #ACTION}, + * {@link #ACTION_INFO} and {@link #UNKNOWN}. + */ + private int impact; + + /** + * Constructs a @link{MBeanOperationInfo} with the specified + * description using the given method. Each parameter is + * described merely by its type; the name and description are + * <code>null</code>. The return type and impact of the + * method are determined from the {@link Method} instance. + * + * @param desc a description of the attribute. + * @param method the method. + */ + public MBeanOperationInfo(String desc, Method method) + { + super(method.getName(), desc); + Class[] paramTypes = method.getParameterTypes(); + signature = new MBeanParameterInfo[paramTypes.length]; + for (int a = 0; a < paramTypes.length; ++a) + signature[a] = new MBeanParameterInfo(null, + paramTypes[a].getName(), + null); + type = method.getReturnType().getName(); + if (method.getReturnType() == Void.TYPE) + { + if (paramTypes.length == 0) + impact = UNKNOWN; + else + impact = ACTION; + } + else + { + if (paramTypes.length == 0) + impact = INFO; + else + impact = ACTION_INFO; + } + } + + /** + * 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. + * + * @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 return type of the method, as the class name. + * @param impact the impact of performing the operation. + */ + public MBeanOperationInfo(String name, String desc, + MBeanParameterInfo[] sig, String type, + int impact) + { + super(name, desc); + if (sig == null) + signature = new MBeanParameterInfo[0]; + else + signature = sig; + this.type = type; + this.impact = impact; + } + + /** + * Returns a clone of this instance. The clone is created + * using just the method provided by {@link java.lang.Object}. + * Thus, the clone is just a shallow clone as returned by + * that method, and does not contain any deeper cloning based + * on the subject of this class. + * + * @return a clone of this instance. + * @see java.lang.Cloneable + */ + public Object clone() + { + try + { + return super.clone(); + } + catch (CloneNotSupportedException e) + { + /* This shouldn't happen; we implement Cloneable */ + throw new IllegalStateException("clone() called on " + + "non-cloneable object."); + } + } + + /** + * Compares this feature with the supplied object. This returns + * true iff the object is an instance of {@link + * MBeanConstructorInfo}, {@link Object#equals()} returns true for a + * comparison of both the name and description of this notification + * with that of the specified object (performed by the superclass), + * the return type and impact are equal and the two signature arrays + * contain the same elements in the same order (but one may be + * longer than the other). + * + * @param obj the object to compare. + * @return true if the object is a {@link MBeanOperationInfo} + * instance, + * <code>name.equals(object.getName())</code>, + * <code>description.equals(object.getDescription())</code>, + * <code>type.equals(object.getReturnType())</code>, + * <code>impact == object.getImpact()</code>, + * and the corresponding elements of the signature arrays are + * equal. + */ + public boolean equals(Object obj) + { + if (!(obj instanceof MBeanOperationInfo)) + return false; + if (!(super.equals(obj))) + return false; + MBeanOperationInfo o = (MBeanOperationInfo) obj; + MBeanParameterInfo[] sig = o.getSignature(); + for (int a = 0; a < signature.length; ++a) + { + if (a == sig.length) + return true; + if (!(signature[a].equals(sig[a]))) + return false; + } + return (type.equals(o.getReturnType()) && + impact == o.getImpact()); + } + + /** + * <p> + * Returns the impact of performing this operation. + * The value is equal to one of the following: + * </p> + * <ol> + * <li>{@link #INFO} — the method just returns + * information (akin to an accessor).</li> + * <li>{@link #ACTION} — the method just alters + * the state of the bean, without returning a value + * (akin to a mutator).</li> + * <li>{@link #ACTION_INFO} — the method both makes + * state changes and returns a value.</li> + * <li>{@link #UNKNOWN} — the behaviour of the operation + * is unknown.</li> + * </ol> + * + * @return the impact of performing the operation. + */ + public int getImpact() + { + return impact; + } + + /** + * Returns the return type of the operation, as the class + * name. + * + * @return the return type. + */ + public String getReturnType() + { + return type; + } + + /** + * Returns the operation's signature, in the form of + * information on each parameter. Each parameter is + * described by an instance of {@link MBeanParameterInfo}. + * The returned array is a shallow copy of the array used + * by this instance, so changing which elements are stored + * in the array won't affect the array used by this, but + * changing the actual elements will affect the ones used + * here. + * + * @return an array of {@link MBeanParameterInfo} objects, + * describing the operation parameters. + */ + public MBeanParameterInfo[] getSignature() + { + return (MBeanParameterInfo[]) signature.clone(); + } + + /** + * Returns the hashcode of the operation information as the sum of + * the hashcode of the superclass, the parameter array, the return + * type and the impact factor. + * + * @return the hashcode of the operation information. + */ + public int hashCode() + { + return super.hashCode() + Arrays.hashCode(signature) + + type.hashCode() + Integer.valueOf(impact).hashCode(); + } + + /** + * <p> + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.MBeanOperationInfo</code>), + * the name, description, return type and impact of the + * operation and the contents of the array of parameters. + * </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 (impact) + { + 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"; + } + super.toString(); + string = string.substring(0, string.length() - 1) + + ",returnType=" + type + + ",impact=" + impactString + + ",signature=" + Arrays.toString(signature) + + "]"; + } + return string; + } + +} diff --git a/libjava/classpath/javax/management/MBeanParameterInfo.java b/libjava/classpath/javax/management/MBeanParameterInfo.java new file mode 100644 index 0000000..ee6ef99 --- /dev/null +++ b/libjava/classpath/javax/management/MBeanParameterInfo.java @@ -0,0 +1,176 @@ +/* MBeanParameterInfo.java -- Information about an operation's parameters. + 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; + +/** + * Describes the parameters of a constructor or operation associated + * with a management bean. The information in this class is immutable + * as standard. Of course, subclasses may change this, but this + * behaviour is not recommended. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class MBeanParameterInfo + extends MBeanFeatureInfo + implements Cloneable +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 7432616882776782338L; + + /** + * The type of the parameter, represented by the class name. + */ + private String type; + + /** + * Constructs a new {@link MBeanParameterInfo} using the specified + * name, description and type. + * + * @param name the name of the attribute. + * @param type the type of the attribute, in the form of its class name. + * @param desc a description of the attribute. + */ + public MBeanParameterInfo(String name, String type, String desc) + { + super(name, desc); + this.type = type; + } + + /** + * Returns a clone of this instance. The clone is created + * using just the method provided by {@link java.lang.Object}. + * Thus, the clone is just a shallow clone as returned by + * that method, and does not contain any deeper cloning based + * on the subject of this class. + * + * @return a clone of this instance. + * @see java.lang.Cloneable + */ + public Object clone() + { + try + { + return super.clone(); + } + catch (CloneNotSupportedException e) + { + /* This shouldn't happen; we implement Cloneable */ + throw new IllegalStateException("clone() called on " + + "non-cloneable object."); + } + } + + /** + * Compares this feature with the supplied object. This returns + * true iff the object is an instance of {@link MBeanParameterInfo}, + * {@link Object#equals()} returns true for a comparison of both the + * name and description of this parameter with that of the specified + * object (performed by the superclass), and the type of the two + * instances is equal. + * + * @param obj the object to compare. + * @return true if the object is a {@link MBeanParameterInfo} + * instance, + * <code>name.equals(object.getName())</code>, + * <code>description.equals(object.getDescription())</code>, + * and <code>type.equals(object.getType())</code>. + */ + public boolean equals(Object obj) + { + if (!(obj instanceof MBeanParameterInfo)) + return false; + if (!(super.equals(obj))) + return false; + MBeanParameterInfo o = (MBeanParameterInfo) obj; + return type.equals(o.getType()); + } + + /** + * Returns the type of this attribute, in the form of its class name. + * + * @return the type of this attribute. + */ + public String getType() + { + return type; + } + + /** + * Returns the hashcode of the parameter information as the sum of + * the hashcode of the superclass and the hashcode of the type. + * + * @return the hashcode of the parameter information. + */ + public int hashCode() + { + return super.hashCode() + type.hashCode(); + } + + /** + * <p> + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.MBeanParameterInfo</code>) along + * with the name, description and type 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) + { + super.toString(); + string = string.substring(0, string.length() - 1) + + ",type=" + type + + "]"; + } + return string; + } + +} diff --git a/libjava/classpath/javax/management/NotCompliantMBeanException.java b/libjava/classpath/javax/management/NotCompliantMBeanException.java new file mode 100644 index 0000000..f2252f2 --- /dev/null +++ b/libjava/classpath/javax/management/NotCompliantMBeanException.java @@ -0,0 +1,78 @@ +/* NotCompliantMBeanException.java -- Thrown due to a non-compliant 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; + +/** + * Thrown when a management bean is passed to a method + * (e.g. to an MBean server to be registered) and it + * fails to comply with the specifications for such + * a bean. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class NotCompliantMBeanException + extends OperationsException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 5175579583207963577L; + + /** + * Constructs a new <code>NotCompliantMBeanException</code>. + */ + public NotCompliantMBeanException() + { + super(); + } + + /** + * Constructs a new <code>NotCompliantMBeanException</code> + * with the specified message. + * + * @param message the error message to give to the user. + */ + public NotCompliantMBeanException(String message) + { + super(message); + } + +} + diff --git a/libjava/classpath/javax/management/Notification.java b/libjava/classpath/javax/management/Notification.java new file mode 100644 index 0000000..52c11de --- /dev/null +++ b/libjava/classpath/javax/management/Notification.java @@ -0,0 +1,314 @@ +/* Notification.java -- A notification emitted by 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; + +import java.util.Date; +import java.util.EventObject; + +/** + * <p> + * A notification message that may be emitted by a bean. + * Notifications have both a message and a type, so individual + * notifications can be grouped by type. They also incorporate + * sequencing, so that the recipient can order the delivered + * messages correctly (there is no guarantee that they will + * be delivered in order). + * </p> + * <p> + * Notifications also include a reference to the source of + * the notification. The source bean is represented either + * by an {@link ObjectName} or by a direct reference to the + * bean. The former is preferable, and notifications emitted + * via a {@link MBeanServer} will automatically have the source + * transformed into an {@link ObjectName}. + * </p> + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class Notification + extends EventObject +{ + + /** + * The notification message. + * + * @serial the notification message. + */ + private String message; + + /** + * The notification's sequence number, relative to the notifications + * emitted by the bean. + * + * @serial the notification sequence number. + */ + private long sequenceNumber; + + /** + * The source of the notification. This is redeclared in order to + * replace the <code>source</code> variable in {@link java.util.EventObject} + * with a non-transient version. + * + * @serial the notification source. + */ + protected Object source; + + /** + * The time the notification was generated. + * + * @serial the notification timestamp. + */ + private long timeStamp; + + /** + * The type of notification sent. This utilises the same style + * as Java property and package names. For example, + * <code>gnu.gcj.compiler</code> may be one type of notifications. + * + * @serial the notification type. + */ + private String type; + + /** + * The user data associated with the notification. This includes + * any additional data which should be transmitted with the notification, + * but can't be achieved using the {@link java.lang.String} format + * of the <code>message</code>. + * + * @serial the notification user data. + */ + private Object userData; + + /** + * Creates a new {@link Notification} object with the specified type, + * source and sequence number. The timestamp is created using the + * current date and time. + * + * @param type the type of the notification. + * @param source the source of the notification. + * @param sequenceNumber the sequence number of the notifcation. + */ + public Notification(String type, Object source, long sequenceNumber) + { + this(type, source, sequenceNumber, new Date().getTime()); + } + + /** + * Creates a new {@link Notification} object with the specified type, + * source, sequence number and timestamp. + * + * @param type the type of the notification. + * @param source the source of the notification. + * @param sequenceNumber the sequence number of the notifcation. + * @param timeStamp the time the notification was emitted. + */ + public Notification(String type, Object source, long sequenceNumber, + long timeStamp) + { + this(type, source, sequenceNumber, timeStamp, null); + } + + /** + * Creates a new {@link Notification} object with the specified type, + * source, sequence number, timestamp and message. + * + * @param type the type of the notification. + * @param source the source of the notification. + * @param sequenceNumber the sequence number of the notifcation. + * @param timeStamp the time the notification was emitted. + * @param message the message contained in the notification. + */ + public Notification(String type, Object source, long sequenceNumber, + long timeStamp, String message) + { + super(source); + this.type = type; + this.sequenceNumber = sequenceNumber; + this.timeStamp = timeStamp; + this.message = message; + } + + /** + * Creates a new {@link Notification} object with the specified type, + * source, sequence number and message. The timestamp is created using + * the current date and time. + * + * @param type the type of the notification. + * @param source the source of the notification. + * @param sequenceNumber the sequence number of the notifcation. + * @param message the message contained in the notification. + */ + public Notification(String type, Object source, long sequenceNumber, + String message) + { + this(type, source, sequenceNumber, new Date().getTime(), message); + } + + /** + * Returns the message contained in this notification. The message + * is in {@link java.lang.String} form, and is thus intended for + * display to the end-user. Data transferred as part of the notification + * which shouldn't be displayed is included in the <code>userData</code> + * field. + * + * @return the notification message. + * @see #getUserData() + * @see #setUserData(java.lang.Object) + */ + public String getMessage() + { + return message; + } + + /** + * Returns the sequence number of this notification. This + * can be used to determine the order in which notifications + * were emitted by the broadcasting bean. + * + * @return the sequence number. + * @see #setSequenceNumber(long) + */ + public long getSequenceNumber() + { + return sequenceNumber; + } + + /** + * Returns the date and time at which this notification was + * emitted. + * + * @return the notification timestamp. + * @see #setTimeStamp(long) + */ + public long getTimeStamp() + { + return timeStamp; + } + + /** + * Returns the type of this notification. Types take the same + * form as Java package and property names. + * + * @return the type of the notification. + */ + public String getType() + { + return type; + } + + /** + * Returns the additional user data associated with the notification. + * This is used to attach additional non-textual information to the + * notification. + * + * @return the user data associated with the notification. + * @see #setUserData(java.lang.Object) + */ + public Object getUserData() + { + return userData; + } + + /** + * Sets the sequence number to the value specified. + * + * @param sequenceNumber the new sequence number. + * @see #getSequenceNumber() + */ + public void setSequenceNumber(long sequenceNumber) + { + this.sequenceNumber = sequenceNumber; + } + + /** + * Sets the source of this notification to the value + * specified. + * + * @param source the new source of the notification. + * @see java.util.EventSource#getSource() + */ + public void setSource(Object source) + { + this.source = source; + } + + /** + * Sets the date and time at which this notification + * was emitted. + * + * @param timeStamp the new time stamp of the notification. + * @see #getTimeStamp() + */ + public void setTimeStamp(long timeStamp) + { + this.timeStamp = timeStamp; + } + + /** + * Sets the additional user data associated with the notification + * to the specified value. This is used to attach additional + * non-textual information to the notification. + * + * @param userData the new user data associated with the notification. + * @see #getUserData() + */ + public void setUserData(Object userData) + { + this.userData = userData; + } + + /** + * A textual representation of the notification. + * + * @return the notification in {@link java.lang.String} form. + */ + public String toString() + { + return getClass().getName() + + "[message=" + message + + ", sequenceNumber=" + sequenceNumber + + ", source=" + source + + ", timeStamp=" + timeStamp + + ", type=" + type + + ", userData=" + userData + + "]"; + } + +} + diff --git a/libjava/classpath/javax/management/NotificationBroadcaster.java b/libjava/classpath/javax/management/NotificationBroadcaster.java new file mode 100644 index 0000000..139d842 --- /dev/null +++ b/libjava/classpath/javax/management/NotificationBroadcaster.java @@ -0,0 +1,112 @@ +/* NotificationBroadcaster.java -- Interface for broadcasters. + 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; + +/** + * <p> + * Represents a bean that can emit notifications when + * events occur. Other beans can use this interface + * to add themselves to the list of recipients of such + * notifications. + * </p> + * <p> + * <strong>Note</strong>: New classes should use + * {@link NotificationEmitter}, a subinterface of this, + * in preference to using this interface directly. + * </p> + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public interface NotificationBroadcaster +{ + + /** + * Registers the specified listener as a new recipient of + * notifications from this bean. If non-null, the filter + * argument will be used to select which notifications are + * delivered. The supplied object will also be passed to + * the recipient with each notification. This should not + * be modified by the broadcaster, but instead should be + * passed unmodified to the listener. + * + * @param listener the new listener, who will receive + * notifications from this broadcasting bean. + * @param filter a filter to determine which notifications are + * delivered to the listener, or <code>null</code> + * if no filtering is required. + * @param passback an object to be passed to the listener with + * each notification. + * @throws IllegalArgumentException if <code>listener</code> is + * <code>null</code>. + * @see #removeNotificationListener(NotificationListener) + */ + void addNotificationListener(NotificationListener listener, + NotificationFilter filter, + Object passback) + throws IllegalArgumentException; + + /** + * Returns an array describing the notifications this + * bean may send to its registered listeners. Ideally, this + * array should be complete, but in some cases, this may + * not be possible. However, be aware that some listeners + * may expect this to be so. + * + * @return the array of possible notifications. + */ + MBeanNotificationInfo[] getNotificationInfo(); + + /** + * Removes the specified listener from the list of recipients + * of notifications from this bean. This includes all combinations + * of filters and passback objects registered for this listener. + * For more specific removal of listeners, see the subinterface + * {@link NotificationEmitter}. + * + * @param listener the listener to remove. + * @throws ListenerNotFoundException if the specified listener + * is not registered with this bean. + * @see #addNotificationListener(NotificationListener, NotificationFilter, + * java.lang.Object) + */ + void removeNotificationListener(NotificationListener listener) + throws ListenerNotFoundException; + +} + diff --git a/libjava/classpath/javax/management/NotificationEmitter.java b/libjava/classpath/javax/management/NotificationEmitter.java new file mode 100644 index 0000000..002e2fe --- /dev/null +++ b/libjava/classpath/javax/management/NotificationEmitter.java @@ -0,0 +1,76 @@ +/* NotificationEmitter.java -- Refined interface for broadcasters. + 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 a bean that can emit notifications when + * events occur. Other beans can use this interface + * to add themselves to the list of recipients of such + * notifications. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public interface NotificationEmitter + extends NotificationBroadcaster +{ + + /** + * Removes the specified listener from the list of recipients + * of notifications from this bean. Only the first instance with + * the supplied filter and passback object is removed. + * <code>null</code> is used as a valid value for these parameters, + * rather than as a way to remove all registration instances for + * the specified listener; for this behaviour instead, see the details + * of the same method in {@link NotificationBroadcaster}. + * + * @param listener the listener to remove. + * @param filter the filter of the listener to remove. + * @param passback the passback object of the listener to remove. + * @throws ListenerNotFoundException if the specified listener + * is not registered with this bean. + * @see #addNotificationListener(NotificationListener, NotificationFilter, + * java.lang.Object) + */ + void removeNotificationListener(NotificationListener listener, + NotificationFilter filter, + Object passback) + throws ListenerNotFoundException; + +} + diff --git a/libjava/classpath/javax/management/NotificationFilter.java b/libjava/classpath/javax/management/NotificationFilter.java new file mode 100644 index 0000000..a8e41c9 --- /dev/null +++ b/libjava/classpath/javax/management/NotificationFilter.java @@ -0,0 +1,66 @@ +/* NotificationFilter.java -- Interface for notification filters. + 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; + +import java.io.Serializable; + +/** + * Represents a object that acts as a filter for notifications. + * Implementations of this class are used to determine which + * notifications should be passed to a receiving bean, and which + * should not. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public interface NotificationFilter + extends Serializable +{ + + /** + * Returns true if the specified notification should be passed + * on to the listener. + * + * @param notification the notification being delivered. + * @return true if the notification should be passed to the + * listener, false otherwise. + */ + boolean isNotificationEnabled(Notification notification); + +} + diff --git a/libjava/classpath/javax/management/NotificationListener.java b/libjava/classpath/javax/management/NotificationListener.java new file mode 100644 index 0000000..69b08ee --- /dev/null +++ b/libjava/classpath/javax/management/NotificationListener.java @@ -0,0 +1,70 @@ +/* NotificationListener.java -- Interface for receivers of notifications. + 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; + +import java.util.EventListener; + +/** + * Represents a object that can receive notifications from + * a bean. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public interface NotificationListener + extends EventListener +{ + + /** + * Invoked by the notifying bean when a notification is to + * be delivered to the recipient. As the transmission of + * notifications takes place sequentially, implementors of + * this method should avoid performing lengthy operations, + * as the notifying bean will stall until the method is + * complete. + * + * @param notification the notification from the bean. + * @param passback the object that was passed to the notifying + * bean as part of the registration process. + * @see NotificationBroadcaster#addListener(NotificationListener, + * NotificationFilter, Object) + */ + void handleNotification(Notification notification, Object passback); + +} + diff --git a/libjava/classpath/javax/management/OperationsException.java b/libjava/classpath/javax/management/OperationsException.java new file mode 100644 index 0000000..cbd90d6 --- /dev/null +++ b/libjava/classpath/javax/management/OperationsException.java @@ -0,0 +1,76 @@ +/* OperationsException.java -- Thrown by management operations. + 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; + +/** + * A general superclass for all exceptions thrown by + * operations on management beans. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class OperationsException + extends JMException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -4967597595580536216L; + + /** + * Constructs a new <code>OperationsException</code>. + */ + public OperationsException() + { + super(); + } + + /** + * Constructs a new <code>OperationsException</code> + * with the specified message. + * + * @param message the error message to give to the user. + */ + public OperationsException(String message) + { + super(message); + } + +} + diff --git a/libjava/classpath/javax/management/ReflectionException.java b/libjava/classpath/javax/management/ReflectionException.java new file mode 100644 index 0000000..0f19b5b --- /dev/null +++ b/libjava/classpath/javax/management/ReflectionException.java @@ -0,0 +1,118 @@ +/* ReflectionException.java -- A reflection-based 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 one of the reflection exceptions thrown by a + * management bean. When a management bean tries to perform + * a lookup using the reflection API and encounters an exception, + * it gets wrapped inside an {@link ReflectionException}. + * Calling {@link getTargetException()} will return the wrapped + * exception. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class ReflectionException + extends JMException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 9170809325636915553L; + + /* Sun re-implemented causality -- don't know why, but + serialization demands we do too... */ + + /** + * The target exception. + * + * @serial the target exception. + */ + private Exception exception; + + /** + * Constructs a new <code>ReflectionException</code> wrapping + * the specified exception. + * + * @param e the exception to be wrapped. + */ + public ReflectionException(Exception e) + { + super(); + exception = e; + } + + /** + * Constructs a new <code>ReflectionException</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 ReflectionException(Exception e, String message) + { + super(message); + exception = e; + } + + /** + * Returns the true cause of this exception, the wrapped + * exception. + * + * @return the wrapped exception. + */ + public Throwable getCause() + { + return exception; + } + + /** + * Returns the true cause of this exception, the wrapped + * exception. + * + * @return the wrapped exception. + */ + public Exception getTargetException() + { + return exception; + } + +} + diff --git a/libjava/classpath/javax/management/RuntimeOperationsException.java b/libjava/classpath/javax/management/RuntimeOperationsException.java new file mode 100644 index 0000000..8a830a5 --- /dev/null +++ b/libjava/classpath/javax/management/RuntimeOperationsException.java @@ -0,0 +1,121 @@ +/* RuntimeOperationsException.java -- A wrapped run-time 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 a runtime exception thrown by a management + * bean operation. When a management bean executes code + * that causes a runtime exception to be thrown, the + * resulting exception is wrapped inside an + * {@link RuntimeOperationsException}. Calling + * {@link getTargetException()} will return the wrapped + * exception. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class RuntimeOperationsException + extends JMRuntimeException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -8408923047489133588L; + + /* Sun re-implemented causality -- don't know why, but + serialization demands we do too... */ + + /** + * The target exception. + * + * @serial the target exception. + */ + private RuntimeException runtimeException; + + /** + * Constructs a new <code>RuntimeOperationsException</code> + * wrapping the specified exception. + * + * @param e the exception to be wrapped. + */ + public RuntimeOperationsException(RuntimeException e) + { + super(); + runtimeException = e; + } + + /** + * Constructs a new <code>RuntimeOperationsException</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 RuntimeOperationsException(RuntimeException e, + String message) + { + super(message); + runtimeException = e; + } + + /** + * Returns the true cause of this exception, the wrapped + * exception. + * + * @return the wrapped exception. + */ + public Throwable getCause() + { + return runtimeException; + } + + /** + * Returns the true cause of this exception, the wrapped + * exception. + * + * @return the wrapped exception. + */ + public RuntimeException getTargetException() + { + return runtimeException; + } + +} + diff --git a/libjava/classpath/javax/management/StandardMBean.java b/libjava/classpath/javax/management/StandardMBean.java new file mode 100644 index 0000000..736192e --- /dev/null +++ b/libjava/classpath/javax/management/StandardMBean.java @@ -0,0 +1,925 @@ +/* StandardMBean.java -- A standard reflection-based 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; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * Provides a dynamic management bean by using reflection on an + * interface and an implementing class. By default, a bean instance + * is paired up with its interface based on specific naming + * conventions (if the implementation is called X, the interface must + * be XMBean). Using this class removes the need to use a specific + * naming system to match up the two. Instead, an instance of this + * bean is created either via explicit construction or subclassing, + * and this provides access to the attributes, constructors and + * operations of the implementation via reflection. Various hooks are + * provided in order to allow customization of this process. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class StandardMBean + implements DynamicMBean +{ + + /** + * The interface for this bean. + */ + private Class iface; + + /** + * The implementation of the interface. + */ + private Object impl; + + /** + * Cached bean information. + */ + private MBeanInfo info; + + /** + * Constructs a new {@link StandardMBean} using the specified + * interface and <code>this</code> as the instance. This should + * be used to create an instance via subclassing. + * + * @param iface the interface this bean implements, or <code>null</code> + * if the interface should be determined using the naming + * convention (class X has interface XMBean). + * @throws NotCompliantMBeanException if this class doesn't implement + * the interface or a method appears + * in the interface that doesn't comply + * with the naming conventions. + */ + protected StandardMBean(Class iface) + throws NotCompliantMBeanException + { + if (iface == null) + { + String className = getClass().getName(); + try + { + iface = Class.forName(className + "MBean"); + } + catch (ClassNotFoundException e) + { + throw (NotCompliantMBeanException) + (new NotCompliantMBeanException("An interface for the class " + + className + " was not found.").initCause(e)); + } + } + if (!(iface.isInstance(this))) + throw new NotCompliantMBeanException("The instance, " + impl + + ", is not an instance of " + iface); + impl = this; + this.iface = iface; + } + + /** + * Constructs a new {@link StandardMBean} using the specified + * interface and the supplied instance as the implementation. + * + * @param impl the implementation. + * @param iface the interface the bean implements, or <code>null</code> + * if the interface should be determined using the naming + * convention (class X has interface XMBean). + * @throws IllegalArgumentException if <code>impl</code> is <code>null</code>. + * @throws NotCompliantMBeanException if <code>impl</code> doesn't implement + * the interface or a method appears + * in the interface that doesn't comply + * with the naming conventions. + */ + public StandardMBean(Object impl, Class iface) + throws NotCompliantMBeanException + { + if (impl == null) + throw new IllegalArgumentException("The specified implementation is null."); + if (iface == null) + { + String className = impl.getClass().getName(); + try + { + iface = Class.forName(className + "MBean"); + } + catch (ClassNotFoundException e) + { + throw (NotCompliantMBeanException) + (new NotCompliantMBeanException("An interface for the class " + + className + " was not found.").initCause(e)); + } + } + if (!(iface.isInstance(impl))) + throw new NotCompliantMBeanException("The instance, " + impl + + ", is not an instance of " + iface); + this.impl = impl; + this.iface = iface; + } + + /** + * Caches the {@link MBeanInfo} instance for this object. This is a + * customization hook, so that subclasses can choose the caching policy + * used. The default implementation caches the value in the instance + * itself. Subclasses may override this so as to not cache the data + * at all, or so as to use a cache shared between multiple beans. + * + * @param info the {@link MBeanInfo} instance to cache, or <code>null</code> + * if there is no new value to cache. When the value is not + * <code>null</code>, the cache should replace the current value + * with the value supplied here. + * @see #getCachedMBeanInfo() + */ + protected void cacheMBeanInfo(MBeanInfo info) + { + if (info != null) + this.info = info; + } + + /** + * Obtains the value of the specified attribute of the + * management bean. The management bean should perform + * a lookup for the named attribute, and return its value + * by calling the appropriate getter method, if possible. + * + * @param name the name of the attribute to retrieve. + * @return the value of the specified attribute. + * @throws AttributeNotFoundException if the name does not + * correspond to an attribute + * of the bean. + * @throws MBeanException if retrieving the attribute causes + * the bean to throw an exception (which + * becomes the cause of this exception). + * @throws ReflectionException if an exception occurred in trying + * to use the reflection interface + * to lookup the attribute. The + * thrown exception is the cause of + * this exception. + * @see #setAttribute(String) + */ + public Object getAttribute(String name) + throws AttributeNotFoundException, MBeanException, + ReflectionException + { + Method getter; + try + { + getter = iface.getMethod("get" + + name.substring(0, 1).toUpperCase() + + name.substring(1), null); + } + catch (NoSuchMethodException e) + { + try + { + getter = iface.getMethod("is" + + name.substring(0, 1).toUpperCase() + + name.substring(1), null); + } + catch (NoSuchMethodException ex) + { + throw ((AttributeNotFoundException) + new AttributeNotFoundException("The attribute, " + name + + ", was not found.").initCause(ex)); + } + } + Object result; + try + { + result = getter.invoke(impl, null); + } + catch (IllegalAccessException e) + { + throw new ReflectionException(e, "Failed to retrieve " + name); + } + catch (IllegalArgumentException e) + { + throw new ReflectionException(e, "Failed to retrieve " + name); + } + catch (InvocationTargetException e) + { + throw new MBeanException((Exception) e.getCause(), + "The getter of " + name + + " threw an exception"); + } + return result; + } + + /** + * Obtains the values of each of the specified attributes + * of the management bean. The returned list includes + * those attributes that were retrieved and their + * corresponding values. + * + * @param names the names of the attributes to retrieve. + * @return a list of the retrieved attributes. + * @see #setAttributes(AttributeList) + */ + public AttributeList getAttributes(String[] names) + { + AttributeList list = new AttributeList(names.length); + for (int a = 0; a < names.length; ++a) + { + try + { + Object value = getAttribute(names[a]); + list.add(new Attribute(names[a], value)); + } + catch (AttributeNotFoundException e) + { + /* Ignored */ + } + catch (ReflectionException e) + { + /* Ignored */ + } + catch (MBeanException e) + { + /* Ignored */ + } + } + return list; + } + + /** + * Returns the cached {@link MBeanInfo} instance for this object. This is a + * customization hook, so that subclasses can choose the caching policy + * used. The default implementation caches the value in the instance + * itself, and returns this value on calls to this method. + * + * @return the cached {@link MBeanInfo} instance, or <code>null</code> + * if no value is cached. + * @see #cacheMBeanInfo(javax.management.MBeanInfo) + */ + protected MBeanInfo getCachedMBeanInfo() + { + return info; + } + + /** + * Returns the class name that will be used in the {@link MBeanInfo} + * instance. This is a customization hook, so that subclasses can + * provide a custom class name. By default, this returns the class + * name from the supplied {@link MBeanInfo} instance. + * + * @param info the {@link MBeanInfo} instance constructed via + * reflection. + * @return the class name to use in the instance. + */ + protected String getClassName(MBeanInfo info) + { + return info.getClassName(); + } + + /** + * Returns information on the constructors that will be used in + * the {@link MBeanInfo} instance. This is a customization hook, + * so that subclasses can provide their own information on the + * bean's constructors, if necessary. By default, this method + * returns <code>null</code> unless the implementation supplied + * is either <code>null</code> or <code>this</code>. This default + * implementation prevents the use of + * {@link MBeanServer#createMBean} in cases where the bean is + * not created as a subclass of {@link StandardMBean}. + * + * @param constructors the constructor information created via + * reflection. + * @param impl the implementation, or <code>null</code> if this + * should be ignored. + * @return the constructor information to use. + */ + protected MBeanConstructorInfo[] getConstructors(MBeanConstructorInfo[] + constructors, Object impl) + { + if (impl == null || impl == this) + return constructors; + return null; + } + + /** + * Returns the description of the attribute that will be used in + * the supplied {@link MBeanAttributeInfo} instance. This is a + * customization hook, so that subclasses can provide a custom + * description. By default, this calls + * {@link #getDescription(MBeanFeatureInfo)} with the supplied + * {@link MBeanAttributeInfo} instance. + * + * @param info the {@link MBeanAttributeInfo} instance constructed + * via reflection. + * @return the description to use in the instance. + */ + protected String getDescription(MBeanAttributeInfo info) + { + return getDescription((MBeanFeatureInfo) info); + } + + /** + * Returns the description of the constructor that will be used in + * the supplied {@link MBeanConstructorInfo} instance. This is a + * customization hook, so that subclasses can provide a custom + * description. By default, this calls + * {@link #getDescription(MBeanFeatureInfo)} with the supplied + * {@link MBeanConstructorInfo} instance. + * + * @param info the {@link MBeanConstructorInfo} instance constructed + * via reflection. + * @return the description to use in the instance. + */ + protected String getDescription(MBeanConstructorInfo info) + { + return getDescription((MBeanFeatureInfo) info); + } + + /** + * Returns the description of the nth parameter of the constructor + * that will be used in the supplied {@link MBeanParameterInfo} + * instance. This is a customization hook, so that subclasses + * can provide a custom description. By default, this calls + * <code>param.getDescription()</code>. + * + * @param info the {@link MBeanConstructorInfo} instance constructed + * via reflection. + * @param param the {@link MBeanParameterInfo} instance constructed + * via reflection. + * @param n the number of the parameter, in order to link it to the + * information on the constructor. + * @return the description to use in the instance. + */ + protected String getDescription(MBeanConstructorInfo info, + MBeanParameterInfo param, int n) + { + return param.getDescription(); + } + + /** + * Returns the description of the supplied feature that + * will be used in the supplied {@link MBeanFeatureInfo} + * instance. This is a customization hook, so that subclasses + * can provide a custom description. By default, this calls + * <code>info.getDescription()</code>. This method is also called + * by default for the more specific description methods for attributes, + * constructors and operations. + * + * @param info the {@link MBeanFeatureInfo} instance constructed + * via reflection. + * @return the description to use in the instance. + */ + protected String getDescription(MBeanFeatureInfo info) + { + return info.getDescription(); + } + + /** + * Returns the description of the bean that will be used in the + * supplied {@link MBeanInfo} instance. This is a customization + * hook, so that subclasses can provide a custom description. By + * default, this calls <code>info.getDescription()</code>. + * + * @param info the {@link MBeanInfo} instance constructed + * via reflection. + * @return the description to use in the instance. + */ + protected String getDescription(MBeanInfo info) + { + return info.getDescription(); + } + + /** + * Returns the description of the operation that will be used in + * the supplied {@link MBeanOperationInfo} instance. This is a + * customization hook, so that subclasses can provide a custom + * description. By default, this calls + * {@link #getDescription(MBeanFeatureInfo)} with the supplied + * {@link MBeanOperationInfo} instance. + * + * @param info the {@link MBeanOperationInfo} instance constructed + * via reflection. + * @return the description to use in the instance. + */ + protected String getDescription(MBeanOperationInfo info) + { + return getDescription((MBeanFeatureInfo) info); + } + + /** + * Returns the description of the nth parameter of the operation + * that will be used in the supplied {@link MBeanParameterInfo} + * instance. This is a customization hook, so that subclasses + * can provide a custom description. By default, this calls + * <code>param.getDescription()</code>. + * + * @param info the {@link MBeanOperationInfo} instance constructed + * via reflection. + * @param param the {@link MBeanParameterInfo} instance constructed + * via reflection. + * @param n the number of the parameter, in order to link it to the + * information on the operation. + * @return the description to use in the instance. + */ + protected String getDescription(MBeanOperationInfo info, + MBeanParameterInfo param, int n) + { + return param.getDescription(); + } + + /** + * Returns the impact of the operation that will be used in the + * supplied {@link MBeanOperationInfo} instance. This is a + * customization hook, so that subclasses can provide a custom + * impact flag. By default, this returns + * <code>info.getImpact()</code>. + * + * @param info the {@link MBeanOperationInfo} instance constructed + * via reflection. + * @return the impact flag to use in the instance. + */ + protected int getImpact(MBeanOperationInfo info) + { + return info.getImpact(); + } + + /** + * Returns the instance that implements this bean. + * + * @return the implementation. + */ + public Object getImplementation() + { + return impl; + } + + /** + * Returns the class of the instance that implements this bean. + * + * @return the implementation class. + */ + public Class getImplementationClass() + { + return impl.getClass(); + } + + /** + * <p> + * Returns an information object which lists the attributes + * and actions associated with the management bean. This + * implementation proceeds as follows: + * </p> + * <ol> + * <li>{@link #getCachedMBeanInfo()} is called to obtain + * the cached instance. If this returns a non-null value, + * this value is returned.</li> + * <li>If there is no cached value, then the method proceeds + * to create one. During this process, the customization hooks + * detailed in this class are called to allow the values used + * to be overrided: + * <ul> + * <li>For each attribute, + * {@link #getDescription(MBeanAttributeInfo)} is called.</li> + * <li>For each constructor, + * {@link #getDescription(MBeanConstructorInfo)} is called, + * along with {@link #getDescription(MBeanConstructorInfo, + * MBeanParameterInfo, int)} and + * {@link #getParameterName(MBeanConstructorInfo, + * MBeanParameterInfo, int)} for each parameter.</li> + * <li>The constructors may be replaced as a whole by + * a call to + * {@link #getConstructors(MBeanConstructorInfo[], Object)}.</li> + * <li>For each operation, + * {@link #getDescription(MBeanOperationInfo)} and + * {@link #getImpact(MBeanOperationInfo)} are called, + * along with {@link #getDescription(MBeanOperationInfo, + * MBeanParameterInfo, int)} and + * {@link #getParameterName(MBeanOperationInfo, + * MBeanParameterInfo, int)} for each parameter.</li> + * <li>{@link #getClassName(MBeanInfo)} and + * {@link #getDescription(MBeanInfo)} are called to customise + * the basic information about the class.</li> + * </ul> + * </li> + * <li>Finally, {@link #cacheMBeanInfo(MBeanInfo)} is called + * with the created instance before it is returned.</li> + * </ol> + * + * @return a description of the management bean, including + * all exposed attributes and actions. + */ + public MBeanInfo getMBeanInfo() + { + MBeanInfo info = getCachedMBeanInfo(); + if (info != null) + return info; + Method[] methods = iface.getMethods(); + Map attributes = new HashMap(); + List operations = new ArrayList(); + for (int a = 0; a < methods.length; ++a) + { + String name = methods[a].getName(); + if (((name.startsWith("get") && + methods[a].getReturnType() != Void.TYPE) || + (name.startsWith("is") && + methods[a].getReturnType() == Boolean.TYPE)) && + methods[a].getParameterTypes().length == 0) + { + Method[] amethods; + String attrib; + if (name.startsWith("is")) + attrib = name.substring(2,3).toLowerCase() + + name.substring(3); + else + attrib = name.substring(3,4).toLowerCase() + + name.substring(4); + if (attributes.containsKey(attrib)) + amethods = (Method[]) attributes.get(attrib); + else + { + amethods = new Method[2]; + attributes.put(attrib, amethods); + } + amethods[0] = methods[a]; + } + else if (name.startsWith("set") && + methods[a].getReturnType() == Void.TYPE && + methods[a].getParameterTypes().length == 1) + { + Method[] amethods; + String attrib = name.substring(3,4).toLowerCase() + + name.substring(4); + if (attributes.containsKey(attrib)) + amethods = (Method[]) attributes.get(attrib); + else + { + amethods = new Method[2]; + attributes.put(attrib, amethods); + } + amethods[1] = methods[a]; + } + else + operations.add(new MBeanOperationInfo("", methods[a])); + } + List attribs = new ArrayList(attributes.size()); + Iterator it = attributes.entrySet().iterator(); + while (it.hasNext()) + { + Map.Entry entry = (Map.Entry) it.next(); + Method[] amethods = (Method[]) entry.getValue(); + try + { + attribs.add(new MBeanAttributeInfo((String) entry.getKey(), "", + amethods[0], amethods[1])); + } + catch (IntrospectionException e) + { + /* Shouldn't happen; both shouldn't be null */ + throw new IllegalStateException("The two methods passed to " + + "the MBeanAttributeInfo " + + "constructor for " + entry + + "were null.", e); + } + } + MBeanAttributeInfo[] ainfo = new MBeanAttributeInfo[attribs.size()]; + for (int a = 0; a < ainfo.length; ++a) + { + MBeanAttributeInfo oldInfo = (MBeanAttributeInfo) attribs.get(a); + String desc = getDescription(oldInfo); + ainfo[a] = new MBeanAttributeInfo(oldInfo.getName(), + oldInfo.getType(), desc, + oldInfo.isReadable(), + oldInfo.isWritable(), + oldInfo.isIs()); + } + Constructor[] cons = impl.getClass().getConstructors(); + MBeanConstructorInfo[] cinfo = new MBeanConstructorInfo[cons.length]; + for (int a = 0; a < cinfo.length; ++a) + { + MBeanConstructorInfo oldInfo = new MBeanConstructorInfo("", cons[a]); + String desc = getDescription(oldInfo); + MBeanParameterInfo[] params = oldInfo.getSignature(); + MBeanParameterInfo[] pinfo = new MBeanParameterInfo[params.length]; + for (int b = 0; b < pinfo.length; ++b) + { + String pdesc = getDescription(oldInfo, params[b], b); + String pname = getParameterName(oldInfo, params[b], b); + pinfo[b] = new MBeanParameterInfo(pname, params[b].getType(), + pdesc); + } + cinfo[a] = new MBeanConstructorInfo(oldInfo.getName(), desc, + pinfo); + } + cinfo = getConstructors(cinfo, impl); + MBeanOperationInfo[] oinfo = new MBeanOperationInfo[operations.size()]; + for (int a = 0; a < oinfo.length; ++a) + { + MBeanOperationInfo oldInfo = (MBeanOperationInfo) operations.get(a); + String desc = getDescription(oldInfo); + int impact = getImpact(oldInfo); + MBeanParameterInfo[] params = oldInfo.getSignature(); + MBeanParameterInfo[] pinfo = new MBeanParameterInfo[params.length]; + for (int b = 0; b < pinfo.length; ++b) + { + String pdesc = getDescription(oldInfo, params[b], b); + String pname = getParameterName(oldInfo, params[b], b); + pinfo[b] = new MBeanParameterInfo(pname, params[b].getType(), + pdesc); + } + oinfo[a] = new MBeanOperationInfo(oldInfo.getName(), desc, pinfo, + oldInfo.getReturnType(), impact); + } + info = new MBeanInfo(impl.getClass().getName(), "", ainfo, cinfo, + oinfo, null); + String cname = getClassName(info); + String desc = getDescription(info); + info = new MBeanInfo(cname, desc, ainfo, cinfo, oinfo, null); + cacheMBeanInfo(info); + return info; + } + + /** + * Returns the interface for this management bean. + * + * @return the management interface. + */ + public Class getMBeanInterface() + { + return iface; + } + + /** + * Returns the name of the nth parameter of the constructor + * that will be used in the supplied {@link MBeanParameterInfo} + * instance. This is a customization hook, so that subclasses + * can provide a custom name. By default, this calls + * <code>param.getName()</code>. + * + * @param info the {@link MBeanConstructorInfo} instance constructed + * via reflection. + * @param param the {@link MBeanParameterInfo} instance constructed + * via reflection. + * @param n the number of the parameter, in order to link it to the + * information on the constructor. + * @return the name to use in the instance. + */ + protected String getParameterName(MBeanConstructorInfo info, + MBeanParameterInfo param, int n) + { + return param.getName(); + } + + /** + * Returns the name of the nth parameter of the operation + * that will be used in the supplied {@link MBeanParameterInfo} + * instance. This is a customization hook, so that subclasses + * can provide a custom name. By default, this calls + * <code>param.getName()</code>. + * + * @param info the {@link MBeanOperationInfo} instance constructed + * via reflection. + * @param param the {@link MBeanParameterInfo} instance constructed + * via reflection. + * @param n the number of the parameter, in order to link it to the + * information on the operation. + * @return the name to use in the instance. + */ + protected String getParameterName(MBeanOperationInfo info, + MBeanParameterInfo param, int n) + { + return param.getName(); + } + + /** + * Invokes the specified action on the management bean using + * the supplied parameters. The signature of the action is + * specified by a {@link String} array, which lists the classes + * corresponding to each parameter. The class loader used to + * load these classes is the same as that used for loading the + * management bean itself. + * + * @param name the name of the action to invoke. + * @param params the parameters used to call the action. + * @param signature the signature of the action. + * @return the return value of the action. + * @throws MBeanException if the action throws an exception. The + * thrown exception is the cause of this + * exception. + * @throws ReflectionException if an exception occurred in trying + * to use the reflection interface + * to invoke the action. The + * thrown exception is the cause of + * this exception. + */ + public Object invoke(String name, Object[] params, String[] signature) + throws MBeanException, ReflectionException + { + Class[] sigTypes = new Class[signature.length]; + ClassLoader loader = getClass().getClassLoader(); + for (int a = 0; a < signature.length; ++a) + try + { + sigTypes[a] = Class.forName(signature[a], true, loader); + } + catch (ClassNotFoundException e) + { + throw new ReflectionException(e, "The class, " + signature[a] + + ", in the method signature " + + "could not be loaded."); + } + Method method; + try + { + method = iface.getMethod(name, sigTypes); + } + catch (NoSuchMethodException e) + { + throw new ReflectionException(e, "The method, " + name + + ", could not be found."); + } + Object result; + try + { + result = method.invoke(impl, params); + } + catch (IllegalAccessException e) + { + throw new ReflectionException(e, "Failed to call " + name); + } + catch (IllegalArgumentException e) + { + throw new ReflectionException(e, "Failed to call " + name); + } + catch (InvocationTargetException e) + { + throw new MBeanException((Exception) e.getCause(), "The method " + + name + " threw an exception"); + } + return result; + } + + /** + * Sets the value of the specified attribute of the + * management bean. The management bean should perform + * a lookup for the named attribute, and sets its value + * using the associated setter method, if possible. + * + * @param attribute the attribute to set. + * @throws AttributeNotFoundException if the attribute does not + * correspond to an attribute + * of the bean. + * @throws InvalidAttributeValueException if the value is invalid + * for this particular + * attribute of the bean. + * @throws MBeanException if setting the attribute causes + * the bean to throw an exception (which + * becomes the cause of this exception). + * @throws ReflectionException if an exception occurred in trying + * to use the reflection interface + * to lookup the attribute. The + * thrown exception is the cause of + * this exception. + * @see #getAttribute(String) + */ + public void setAttribute(Attribute attribute) + throws AttributeNotFoundException, InvalidAttributeValueException, + MBeanException, ReflectionException + { + Method setter; + String name = attribute.getName(); + try + { + setter = iface.getMethod("set" + + name.substring(0, 1).toUpperCase() + + name.substring(1), null); + } + catch (NoSuchMethodException e) + { + throw ((AttributeNotFoundException) + new AttributeNotFoundException("The attribute, " + name + + ", was not found.").initCause(e)); + } + try + { + setter.invoke(impl, new Object[] { attribute.getValue() }); + } + catch (IllegalAccessException e) + { + throw new ReflectionException(e, "Failed to set " + name); + } + catch (IllegalArgumentException e) + { + throw ((InvalidAttributeValueException) + new InvalidAttributeValueException(attribute.getValue() + + " is an invalid value for " + + name).initCause(e)); + } + catch (InvocationTargetException e) + { + throw new MBeanException((Exception) e.getCause(), "The getter of " + + name + " threw an exception"); + } + } + + /** + * Sets the value of each of the specified attributes + * to that supplied by the {@link Attribute} object. + * The returned list contains the attributes that were + * set and their new values. + * + * @param attributes the attributes to set. + * @return a list of the changed attributes. + * @see #getAttributes(AttributeList) + */ + public AttributeList setAttributes(AttributeList attributes) + { + AttributeList list = new AttributeList(attributes.size()); + Iterator it = attributes.iterator(); + while (it.hasNext()) + { + try + { + Attribute attrib = (Attribute) it.next(); + setAttribute(attrib); + list.add(attrib); + } + catch (AttributeNotFoundException e) + { + /* Ignored */ + } + catch (InvalidAttributeValueException e) + { + /* Ignored */ + } + catch (ReflectionException e) + { + /* Ignored */ + } + catch (MBeanException e) + { + /* Ignored */ + } + } + return list; + } + + /** + * Replaces the implementation of the interface used by this + * instance with the one specified. The new implementation + * must be non-null and implement the interface specified on + * construction of this instance. + * + * @throws IllegalArgumentException if <code>impl</code> is <code>null</code>. + * @throws NotCompliantMBeanException if <code>impl</code> doesn't implement + * the interface or a method appears + * in the interface that doesn't comply + * with the naming conventions. + */ + public void setImplementation(Object impl) + throws NotCompliantMBeanException + { + if (impl == null) + throw new IllegalArgumentException("The specified implementation is null."); + if (!(iface.isInstance(impl))) + throw new NotCompliantMBeanException("The instance, " + impl + + ", is not an instance of " + iface); + this.impl = impl; + } + +} diff --git a/libjava/classpath/javax/management/openmbean/ArrayType.java b/libjava/classpath/javax/management/openmbean/ArrayType.java new file mode 100644 index 0000000..d2fc398 --- /dev/null +++ b/libjava/classpath/javax/management/openmbean/ArrayType.java @@ -0,0 +1,313 @@ +/* ArrayType.java -- Open type descriptor for an array. + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.management.openmbean; + +import java.lang.reflect.Array; + +import java.util.Arrays; + +/** + * The open type descriptor for arrays of open data values. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class ArrayType + extends OpenType +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 720504429830309770L; + + /** + * The number of dimensions arrays of this type has. + */ + private int dimension; + + /** + * The element type of arrays of this type. + */ + private OpenType elementType; + + /** + * The hash code of this instance. + */ + private transient Integer hashCode; + + /** + * The <code>toString()</code> result of this instance. + */ + private transient String string; + + /** + * Returns the class name of the array, given the element + * class name and its dimensions. + * + * @param className the name of the class used by the + * array's elements. + * @param dim the dimensions of the array. + * @return the array's class name. + */ + private static String getArrayClassName(String className, int dim) + { + char[] brackets = new char[dim]; + Arrays.fill(brackets, '['); + return String.valueOf(brackets) + "L" + className; + } + + /** + * <p> + * Constructs a new {@link ArrayType} instance for an array of the + * specified type with the supplied number of dimensions. The attributes + * used by the superclass, {@link OpenType}, are automatically defined, + * based on these values. Both the class name and type name are set + * to the value returned by the {@link java.lang.Class#getName()} of + * the array's class (i.e. the element type, preceded by n instances of + * '[' and an 'L', where n is the number of dimensions the array has). + * The description is based upon the template <code>n-dimension array + * of e</code>, where n is the number of dimensions of the array, and + * e is the element type. The class name of the actual elements is + * obtainable by calling {@link OpenType#getClassName()} on the result + * of {@link #getElementOpenType()}. + * </p> + * <p> + * As an example, the array type returned by + * <code>new ArrayType(6, SimpleType.INTEGER)</code> has the following + * values: + * </p> + * <table> + * <th><td>Attribute</td><td>Value</td></th> + * <tr><td>Class Name</td><td><code>[[[[[[Ljava.lang.Integer;</code> + * </td></tr> + * <tr><td>Type Name</td><td><code>[[[[[[Ljava.lang.Integer;</code> + * </td></tr> + * <tr><td>Description</td><td><code>6-dimension array of + * java.lang.Integer</code></td></tr> + * <tr><td>Element Type Class Name</td><td><code>java.lang.Integer</code> + * </td></tr> + * </table> + * <p> + * The dimensions of the array must be equal to or greater than 1. The + * element type must be an instance of {@link SimpleType}, + * {@link CompositeType} or {@link TabularType}. + * </p> + * + * @param dim the dimensions of the array. + * @param elementType the type of the elements of the array. + * @throws IllegalArgumentException if <code>dim</code> is less than 1. + * @throws OpenDataException if the element type is not an instance of either + * {@link SimpleType}, {@link CompositeType} + * or {@link TabularType}. + */ + public ArrayType(int dim, OpenType elementType) + throws OpenDataException + { + super(getArrayClassName(elementType.getClassName(), dim), + getArrayClassName(elementType.getClassName(), dim), + dim + "-dimension array of " + elementType.getClassName()); + if (dim < 1) + throw new IllegalArgumentException("Dimensions must be greater " + + "than or equal to 1."); + if (!(elementType instanceof SimpleType || + elementType instanceof CompositeType || + elementType instanceof TabularType)) + throw new OpenDataException("The element type must be a simple " + + "type, a composite type or a tabular " + + "type."); + dimension = dim; + this.elementType = elementType; + } + + /** + * <p> + * Compares this array type with another object + * for equality. The objects are judged to be equal if: + * </p> + * <ul> + * <li><code>obj</code> is not null.</li> + * <li><code>obj</code> is an instance of + * {@link ArrayType}.</li> + * <li>The dimensions are equal.</li> + * <li>The element types are equal.</li> + * </ul> + * + * @param obj the object to compare with. + * @return true if the conditions above hold. + */ + public boolean equals(Object obj) + { + if (!(obj instanceof ArrayType)) + return false; + ArrayType atype = (ArrayType) obj; + return (atype.getDimension() == dimension && + atype.getElementOpenType().equals(elementType)); + } + + /** + * Returns the number of dimensions used by arrays + * of this type. + * + * @return the number of dimensions. + */ + public int getDimension() + { + return dimension; + } + + /** + * Returns the open type descriptor which describes + * the type of the elements of this array type. + * + * @return the type of the elements. + */ + public OpenType getElementOpenType() + { + return elementType; + } + + /** + * <p> + * Returns the hash code of the array type. + * This is computed as the sum of the hash code of the + * element type together with the number of dimensions + * the array has. These are the same elements + * of the type that are compared as part of the + * {@link #equals(java.lang.Object)} method, thus ensuring + * that the hashcode is compatible with the equality + * test. + * </p> + * <p> + * As instances of this class are immutable, the hash code + * is computed just once for each instance and reused + * throughout its life. + * </p> + * + * @return the hash code of this instance. + */ + public int hashCode() + { + if (hashCode == null) + hashCode = Integer.valueOf(dimension + elementType.hashCode()); + return hashCode.intValue(); + } + + /** + * <p> + * Returns true if the specified object is a member of this + * array type. The object is judged to be so if it is + * non-null, an array and one of the following two conditions + * holds: + * </p> + * <ul> + * <li>This {@link ArrayType} instance has a {@link SimpleType} + * as its element type. Thus, the object must have the same + * class name as that returned by {@link SimpleType#getClassName()} + * for this class.</li> + * <li>This {@link ArrayType} instance has a {@link CompositeType} + * or a {@link TabularType} as its element type. Thus, the object + * must be assignable to such an array, and have elements which + * are either null or valid values for the element type.</li> + * </ul> + * + * @param obj the object to test for membership. + * @return true if the object is a member of this type. + */ + public boolean isValue(Object obj) + { + if (obj == null) + return false; + Class objClass = obj.getClass(); + if (!(objClass.isArray())) + return false; + if (elementType instanceof SimpleType) + return getClassName().equals(objClass.getName()); + Class elementClass = null; + try + { + elementClass = Class.forName(getClassName()); + } + catch (ClassNotFoundException e) + { + throw new IllegalStateException("The array type's element " + + "class could not be found.", e); + } + if (!(elementClass.isAssignableFrom(objClass))) + return false; + for (int a = 0; a < Array.getLength(obj); ++a) + { + Object elem = Array.get(obj, a); + if (elem != null && + (!(elementType.isValue(elem)))) + return false; + } + return true; + } + + /** + * <p> + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.openmbean.ArrayType</code>) + * and each element of the instance which is relevant to + * the definition of {@link equals(java.lang.Object)} and + * {@link hashCode()} (i.e. the type name, the number of + * dimensions and the element type). + * </p> + * <p> + * As instances of this class are immutable, the return value + * is computed just once for each instance and reused + * throughout its life. + * </p> + * + * @return a @link{java.lang.String} instance representing + * the instance in textual form. + */ + public String toString() + { + if (string == null) + string = getClass().getName() + + "[name=" + getTypeName() + + ", dimension=" + dimension + + ", elementType=" + elementType + + "]"; + return string; + } + +} diff --git a/libjava/classpath/javax/management/openmbean/CompositeData.java b/libjava/classpath/javax/management/openmbean/CompositeData.java new file mode 100644 index 0000000..08f0dc2 --- /dev/null +++ b/libjava/classpath/javax/management/openmbean/CompositeData.java @@ -0,0 +1,154 @@ +/* CompositeData.java -- A composite data structure. + 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.Collection; + +/** + * Provides an interface to a composite data structure, + * in order to aid interoperability. The composite data + * structure is represented by mapping field names to + * values. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public interface CompositeData +{ + + /** + * Returns true if this {@link CompositeData} instance contains + * the specified key. This method always returns false for + * an input key equal to <code>null</code> or the empty string. + * + * @param key the key to find in the structure. + * @return true if the key exists. + */ + boolean containsKey(String key); + + /** + * Returns true if this {@link CompositeData} instance has + * a value equal to that supplied. + * + * @param value the value to look for. + * @return true if the value exists. + */ + boolean containsValue(Object value); + + /** + * 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 CompositeData} with the same name-value + * mappings and types. The two compared instances may be + * equivalent even if they represent different implementations of + * {@link CompositeData}. + * + * @param obj the object to compare for equality. + * @return true if <code>obj</code> is equal to <code>this</code>. + */ + boolean equals(Object obj); + + /** + * Retrieves the value for the specified key. + * + * @param key the key whose value should be returned. + * @return the matching value. + * @throws IllegalArgumentException if the key is <code>null</code> + * or the empty string. + * @throws InvalidKeyException if the key does not exist. + */ + Object get(String key); + + /** + * Returns the appropriate value for each key in the given array, + * using the same ordering. + * + * @param keys the keys whose values should be returned. + * @return the matching values. + * @throws IllegalArgumentException if one of the keys is + * <code>null</code> or the + * empty string. + * @throws InvalidKeyException if one of the keys does not exist. + */ + Object[] getAll(String[] keys); + + /** + * Returns the composite type which corresponds to this instance + * of {@link CompositeData}. + * + * @return the composite type for this instance. + */ + CompositeType getCompositeType(); + + /** + * Returns the hash code of this instance. The hash code is + * computed as the sum of the hash codes of all the values plus + * the hash code of the composite type. As equality comparisons + * take place using this same information, this ensures that + * the property, <code>e1.equals(e2)</code> implies + * <code>e1.hashCode() == e2.hashCode(), holds for any pair + * of instances, <code>e1</code> and <code>e2</code>. + * + * @return the hash code of this {@link CompositeData}. + * @see Object#equals(Object) + */ + int hashCode(); + + /** + * Returns a textual representation of this instance. The + * exact format is left up to the implementation, but it + * should contain the name of the implementing class, + * the name of the type and a mapping of the form + * <code>key=value</code> for each pair of key and value. + * + * @return a {@link java.lang.String} representation of the + * object. + */ + String toString(); + + /** + * Returns a read-only collection of the values associated with + * this instance. The values are sorted using the lexicographic + * ordering of the corresponding keys. + * + * @return the values of this instance. + */ + Collection values(); + +} + diff --git a/libjava/classpath/javax/management/openmbean/CompositeDataSupport.java b/libjava/classpath/javax/management/openmbean/CompositeDataSupport.java new file mode 100644 index 0000000..5d5adb7 --- /dev/null +++ b/libjava/classpath/javax/management/openmbean/CompositeDataSupport.java @@ -0,0 +1,349 @@ +/* CompositeData.java -- A composite data structure implementation. + 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.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.SortedMap; +import java.util.TreeMap; + +/** + * Provides an implementation of the {@link CompositeData} + * interface. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class CompositeDataSupport + implements CompositeData, Serializable +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 8003518976613702244L; + + /** + * Mapping of field names to values. + * + * @serial the map of field names to values. + */ + private SortedMap contents; + + /** + * The composite type which represents this composite data instance. + * + * @serial the type information for this instance. + */ + private CompositeType compositeType; + + /** + * Constructs a new {@link CompositeDataSupport} instance with the + * specified type using field names and values from the supplied map. + * The keys of the map become the field names, while the values + * become the values of each respective field. This constructor simply + * calls the other constructor, with the two arrays formed using the + * keys and values of this map, respectively. Thus, the input parameters + * given should conform to the same requirements given there (i.e. no + * null values or empty strings). + * + * @param type the composite type of this composite data structure. + * @param items a mapping of field names to values. This should match + * the mappings given by the type (i.e. for each mapping + * in the type, there should be a corresponding field name + * with a value of the correct type). + * @throws IllegalArgumentException if the type, the map or any of the keys + * or values in the map are <code>null</code>, + * or if any key from the map is an empty + * string. + * @throws OpenDataException if a mismatch occurs between the map and the + * field name/type specification given by the + * {@link CompositeType} instance. This may be + * due to the two having a different size, a + * mismatch between keys or an incorrectly typed + * value. + * @throws ArrayStoreException if one of the keys is not a + * {@link java.lang.String} (thus calling a failure + * in converting the keys to an array of strings). + */ + public CompositeDataSupport(CompositeType type, Map items) + throws OpenDataException + { + this(type, + (String[]) items.keySet().toArray(new String[items.size()]), + items.values().toArray()); + } + + /** + * Constructs a new {@link CompositeDataSupport} instance with the + * specified type using the supplied arrays of field names and + * values. Neither the type, the two arrays or any elements of the + * arrays may be <code>null</code>. The {@link java.lang.String}s + * within the <code>names</code> array must be non-empty. The + * arrays must match in size and order, as each element of the + * <code>names</code> array is matched against the corresponding + * value in the <code>values</code> array. Internally, the two are + * stored in a map, lexographically ordered using the field names. + * The data given should also conform to the description of the + * instance given by the {@link CompositeType} instance supplied. + * + * @param type the composite type of this composite data structure. + * @param names the field names. + * @param values the corresponding values of the fields. + * @throws IllegalArgumentException if the type, the arrays or any of the keys + * or values in the arrays are <code>null</code>, + * or if any key from <code>names</code> is + * an empty string. This also occurs if the + * arrays differ in length. + * @throws OpenDataException if a mismatch occurs between the arrays and the + * field name/type specification given by the + * {@link CompositeType} instance. This may be + * due to a differing number of field names, a + * mismatch between names or an incorrectly typed + * value. + */ + public CompositeDataSupport(CompositeType type, String[] names, Object[] values) + throws OpenDataException + { + if (type == null) + throw new IllegalArgumentException("The given composite type is null."); + compositeType = type; + if (names == null) + throw new IllegalArgumentException("The names array is null."); + if (values == null) + throw new IllegalArgumentException("The values array is null."); + if (names.length != values.length) + throw new IllegalArgumentException("The sizes of the arrays differ."); + Set typeKeys = type.keySet(); + if (typeKeys.size() != names.length) + throw new OpenDataException("The number of field names does not match " + + "the type description."); + contents = new TreeMap(); + for (int a = 0; a < names.length; ++a) + { + if (names[a] == null) + throw new IllegalArgumentException("Element " + a + " of the names " + + "array is null."); + if (names[a].length() == 0) + throw new IllegalArgumentException("Element " + a + " of the names " + + "array is an empty string."); + if (values[a] == null) + throw new IllegalArgumentException("Element " + a + " of the values " + + "array is null."); + if (!(typeKeys.contains(names[a]))) + throw new OpenDataException("The name, " + names[a] + ", is not a " + + "field in the given type description."); + if (!(type.getType(names[a]).isValue(values[a]))) + throw new OpenDataException("The value, " + values[a] + ", is not a " + + "valid value for the " + names[a] + " field."); + contents.put(names[a], values[a]); + } + } + + /** + * Returns true if this {@link CompositeData} instance contains + * the specified key. This method always returns false for + * an input key equal to <code>null</code> or the empty string. + * + * @param key the key to find in the structure. + * @return true if the key exists. + */ + public boolean containsKey(String key) + { + if (key == null || key.length() == 0) + return false; + else + return contents.containsKey(key); + } + + /** + * Returns true if this {@link CompositeData} instance has + * a value equal to that supplied. + * + * @param value the value to look for. + * @return true if the value exists. + */ + public boolean containsValue(Object value) + { + return contents.containsValue(value); + } + + + /** + * 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 CompositeData} with the same name-value + * mappings and types. The two compared instances may be + * equivalent even if they represent different implementations of + * {@link CompositeData}. + * + * @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 CompositeData)) + return false; + CompositeData data = (CompositeData) obj; + if (!(data.getCompositeType().equals(compositeType))) + return false; + Iterator it = contents.keySet().iterator(); + while (it.hasNext()) + { + String key = (String) it.next(); + if (!(data.containsKey(key))) + return false; + if (!(data.get(key).equals(contents.get(key)))) + return false; + } + return true; + } + + /** + * Retrieves the value for the specified key. + * + * @param key the key whose value should be returned. + * @return the matching value. + * @throws IllegalArgumentException if the key is <code>null</code> + * or the empty string. + * @throws InvalidKeyException if the key does not exist. + */ + public Object get(String key) + { + if (key == null) + throw new IllegalArgumentException("The supplied key is null."); + if (key.length() == 0) + throw new IllegalArgumentException("The supplied key is the empty string."); + if (!(contents.containsKey(key))) + throw new InvalidKeyException("The supplied key does not exist."); + return contents.get(key); + } + + /** + * Returns the appropriate value for each key in the given array, + * using the same ordering. + * + * @param keys the keys whose values should be returned. + * @return the matching values. + * @throws IllegalArgumentException if one of the keys is + * <code>null</code> or the + * empty string. + * @throws InvalidKeyException if one of the keys does not exist. + */ + public Object[] getAll(String[] keys) + { + Object[] values = new Object[keys.length]; + for (int a = 0; a < keys.length; ++a) + values[a] = get(keys[a]); + return values; + } + + + /** + * Returns the composite type which corresponds to this instance + * of {@link CompositeData}. + * + * @return the composite type for this instance. + */ + public CompositeType getCompositeType() + { + return compositeType; + } + + /** + * Returns the hash code of this instance. The hash code is + * computed as the sum of the hash codes of all the values plus + * the hash code of the composite type. As equality comparisons + * take place using this same information, this should ensure that + * the property, <code>e1.equals(e2)</code> implies + * <code>e1.hashCode() == e2.hashCode(), holds for any pair + * of instances, <code>e1</code> and <code>e2</code>. However, + * this relies on the other instance implementing the + * <code>hashCode</code> method correctly, if it is not an + * instance of {@link CompositeDataSupport}. + * + * @return the hash code of this {@link CompositeData}. + * @see Object#equals(Object) + */ + public int hashCode() + { + int code = compositeType.hashCode(); + Iterator it = values().iterator(); + while (it.hasNext()) + code += it.next().hashCode(); + return code; + } + + + /** + * Returns a textual representation of this instance. The + * exact format is left up to the implementation, but it + * should contain the name of the implementing class, + * the name of the type and a mapping of the form + * <code>key=value</code> for each pair of key and value. + * + * @return a {@link java.lang.String} representation of the + * object. + */ + public String toString() + { + return getClass().getName() + + "[compositeType=" + compositeType + + ",contents=" + contents + + "]"; + } + + /** + * Returns a read-only collection of the values associated with + * this instance. The values are sorted using the lexicographic + * ordering of the corresponding keys. + * + * @return the values of this instance. + */ + public Collection values() + { + return Collections.unmodifiableCollection(contents.values()); + } + +} + diff --git a/libjava/classpath/javax/management/openmbean/CompositeType.java b/libjava/classpath/javax/management/openmbean/CompositeType.java new file mode 100644 index 0000000..0ae5a4e --- /dev/null +++ b/libjava/classpath/javax/management/openmbean/CompositeType.java @@ -0,0 +1,324 @@ +/* CompositeType.java -- Type descriptor for CompositeData instances. + 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.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +/** + * The open type descriptor for instances of the + * {@link CompositeData} class. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class CompositeType + extends OpenType +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -5366242454346948798L; + + /** + * A map of item names to their descriptions. + */ + private TreeMap nameToDescription; + + /** + * A map of item names to their types. + */ + private TreeMap nameToType; + + /** + * The hash code of this instance. + */ + private transient Integer hashCode; + + /** + * The <code>toString()</code> result of this instance. + */ + private transient String string; + + /** + * <p> + * Constructs a new {@link CompositeType} instance for the given + * type name with the specified field names, descriptions and types. + * All parameters, and the elements of the array parameters, must be + * non-null and {@link java.lang.String} values must be something other + * than the empty string. The arrays must be non-empty, and be of + * equal size. + * </p> + * <p> + * The result of <code>CompositeData.class.getName()</code> is adopted + * as the class name (see {@link OpenType}) and changes to the array + * elements following construction of the {@link CompositeType} instance + * will <strong>not</strong> affect the values used by the instance. + * The field names are sorted in to ascending alphanumeric order internally, + * and so ordering can not be used to differentiate between two instances. + * </p> + * + * @param name the name of this composite type. + * @param desc a description of this composite type. + * @param names the names of each field within the composite type. + * @param descs the descriptions of each field within the composite type. + * @param types the types of each field within the composite type. + * @throws IllegalArgumentException if any validity constraint listed above + * is broken. + * @throws OpenDataException if duplicate item names are provided. Item names + * are case-sensitive, but whitespace is removed + * before comparison. + */ + public CompositeType(String name, String desc, String[] names, + String[] descs, OpenType[] types) + throws OpenDataException + { + super(CompositeData.class.getName(), name, desc); + if (names.length == 0 + || names.length != descs.length + || names.length != types.length) + throw new IllegalArgumentException("Arrays must be non-empty " + + "and of equal size."); + nameToDescription = new TreeMap(); + for (int a = 0; a < names.length; ++a) + { + if (names[a] == null) + throw new IllegalArgumentException("Name " + a + " is null."); + if (descs[a] == null) + throw new IllegalArgumentException("Description " + a + + " is null."); + String fieldName = names[a].trim(); + if (fieldName.length() == 0) + throw new IllegalArgumentException("Name " + a + " is " + + "the empty string."); + if (descs[a].length() == 0) + throw new IllegalArgumentException("Description " + a + " is " + + "the empty string."); + if (nameToDescription.containsKey(fieldName)) + throw new OpenDataException(fieldName + " appears more " + + "than once."); + nameToDescription.put(fieldName, descs[a]); + } + nameToType = new TreeMap(); + for (int a = 0; a < names.length; ++a) + nameToType.put(names[a].trim(), types[a]); + } + + /** + * Returns true if this composite data type has a field + * with the given name. + * + * @param name the name of the field to check for. + * @return true if a field of that name exists. + */ + public boolean containsKey(String name) + { + return nameToDescription.containsKey(name); + } + + /** + * <p> + * Compares this composite data type with another object + * for equality. The objects are judged to be equal if: + * </p> + * <ul> + * <li><code>obj</code> is not null.</li> + * <li><code>obj</code> is an instance of + * {@link CompositeType}.</li> + * <li>The type names are equal.</li> + * <li>The fields and their types match.</li> + * </ul> + * + * @param obj the object to compare with. + * @return true if the conditions above hold. + */ + public boolean equals(Object obj) + { + if (!(obj instanceof CompositeType)) + return false; + CompositeType ctype = (CompositeType) obj; + if (!(ctype.getTypeName().equals(getTypeName()))) + return false; + Set keys = keySet(); + if (!(ctype.keySet().equals(keys))) + return false; + Iterator it = keys.iterator(); + while (it.hasNext()) + { + String key = (String) it.next(); + if (!(ctype.getType(key).equals(getType(key)))) + return false; + } + return true; + } + + /** + * Returns the description for the given field name, + * or <code>null</code> if the field name does not + * exist within this composite data type. + * + * @param name the name of the field whose description + * should be returned. + * @return the description, or <code>null</code> if the + * field doesn't exist. + */ + public String getDescription(String name) + { + return (String) nameToDescription.get(name); + } + + /** + * Returns the type for the given field name, + * or <code>null</code> if the field name does not + * exist within this composite data type. + * + * @param name the name of the field whose type + * should be returned. + * @return the type, or <code>null</code> if the + * field doesn't exist. + */ + public OpenType getType(String name) + { + return (OpenType) nameToType.get(name); + } + + /** + * <p> + * Returns the hash code of the composite data type. + * This is computed as the sum of the hash codes of + * each field name and its type, together with the hash + * code of the type name. 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. + * </p> + * <p> + * As instances of this class are immutable, the hash code + * is computed just once for each instance and reused + * throughout its life. + * </p> + * + * @return the hash code of this instance. + */ + public int hashCode() + { + if (hashCode == null) + { + int elementTotal = 0; + Iterator it = nameToType.entrySet().iterator(); + while (it.hasNext()) + { + Map.Entry entry = (Map.Entry) it.next(); + elementTotal += (entry.getKey().hashCode() + + entry.getValue().hashCode()); + } + hashCode = Integer.valueOf(elementTotal + + getTypeName().hashCode()); + } + return hashCode.intValue(); + } + + /** + * Returns true if the specified object is a member of this + * composite type. The object is judged to be so if it is + * an instance of {@link CompositeData} with an equivalent + * type, according to the definition of + * {@link #equals(java.lang.Object)} for {@link CompositeType}. + * + * @param obj the object to test for membership. + * @return true if the object is a member of this type. + */ + public boolean isValue(Object obj) + { + if (obj instanceof CompositeData) + { + CompositeData data = (CompositeData) obj; + return equals(data.getCompositeType()); + } + return false; + } + + /** + * Returns an unmodifiable {@link java.util.Set}-based + * view of the field names that form part of this + * {@link CompositeType} instance. The names are stored + * in ascending alphanumeric order. + * + * @return a unmodifiable set containing the field + * name {@link java.lang.String}s. + */ + public Set keySet() + { + return Collections.unmodifiableSet(nameToDescription.keySet()); + } + + /** + * <p> + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.openmbean.CompositeType</code>) + * and each element of the instance which is relevant to + * the definition of {@link equals(java.lang.Object)} and + * {@link hashCode()} (i.e. the type name, and the name + * and type of each field). + * </p> + * <p> + * As instances of this class are immutable, the return value + * is computed just once for each instance and reused + * throughout its life. + * </p> + * + * @return a @link{java.lang.String} instance representing + * the instance in textual form. + */ + public String toString() + { + if (string == null) + string = getClass().getName() + + "[name=" + getTypeName() + + ", fields=" + nameToType + + "]"; + return string; + } + +} diff --git a/libjava/classpath/javax/management/openmbean/InvalidKeyException.java b/libjava/classpath/javax/management/openmbean/InvalidKeyException.java new file mode 100644 index 0000000..5f0cf76 --- /dev/null +++ b/libjava/classpath/javax/management/openmbean/InvalidKeyException.java @@ -0,0 +1,77 @@ +/* InvalidKeyException.java -- Thrown by an invalid composite/tabular key. + 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 an invalid key (a field name or row index) is + * passed to a method of the {@link CompositeData} or + * {@link TabularData} classes. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class InvalidKeyException + extends IllegalArgumentException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 4224269443946322062L; + + /** + * Constructs a new <code>InvalidKeyException</code>. + */ + public InvalidKeyException() + { + super(); + } + + /** + * Constructs a new <code>InvalidKeyException</code> + * with the specified message. + * + * @param message the error message to give to the user. + */ + public InvalidKeyException(String message) + { + super(message); + } + +} + diff --git a/libjava/classpath/javax/management/openmbean/OpenDataException.java b/libjava/classpath/javax/management/openmbean/OpenDataException.java new file mode 100644 index 0000000..a476cc1 --- /dev/null +++ b/libjava/classpath/javax/management/openmbean/OpenDataException.java @@ -0,0 +1,79 @@ +/* OpenDataException.java -- Thrown by invalid open bean data. + 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.JMException; + +/** + * Thrown when an instance of one of the open types, open + * data objects or open metadata information objects could + * not be created due to invalid construction parameters. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class OpenDataException + extends JMException +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 8346311255433349870L; + + /** + * Constructs a new <code>OpenDataException</code>. + */ + public OpenDataException() + { + super(); + } + + /** + * Constructs a new <code>OpenDataException</code> + * with the specified message. + * + * @param message the error message to give to the user. + */ + public OpenDataException(String message) + { + super(message); + } + +} + diff --git a/libjava/classpath/javax/management/openmbean/OpenType.java b/libjava/classpath/javax/management/openmbean/OpenType.java new file mode 100644 index 0000000..b08c40c --- /dev/null +++ b/libjava/classpath/javax/management/openmbean/OpenType.java @@ -0,0 +1,230 @@ +/* OpenType.java -- Superclass of all open types. + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.management.openmbean; + +import java.io.Serializable; + +/** + * The superclass of all open types, which describe the + * applicable data values for open MBeans. An open type + * is defined by its name and description, and the name + * of the Java class it maps to. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public abstract class OpenType + implements Serializable +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -9195195325186646468L; + + /** + * The name of the Java class this type represents. + */ + private String className; + + /** + * The name of this type. + */ + private String typeName; + + /** + * A description of this type. + */ + private String description; + + /** + * An array which defines the set of Java types which can be + * used as open types. Note that each type is also available + * in array form, possibly with multiple dimensions. + */ + public static final String[] ALLOWED_CLASSNAMES = { + "java.lang.Void", + "java.lang.Boolean", + "java.lang.Character", + "java.lang.Byte", + "java.lang.Short", + "java.lang.Integer", + "java.lang.Long", + "java.lang.Float", + "java.lang.Double", + "java.lang.String", + "java.math.BigDecimal", + "java.math.BigInteger", + "java.util.Date", + "javax.management.ObjectName", + CompositeData.class.getName(), + TabularData.class.getName() + }; + + /** + * Constructs a new {@link OpenType} for the specified class + * with the given name and description. The name of the class + * must be taken from the list of {@link ALLOWED_CLASSNAMES}. + * Arrays are implictly included in this, and follow the usual + * syntax of {@link java.lang.Class#getName()} with the name + * preceded by n instances of '[' (where n is the number of + * dimensions) and an L. The name and description can not be + * <code>null</code> or the empty string. + * + * @param className the name of the Java class this type + * represents. + * @param name the name of the type. + * @param desc the description of the type. + * @throws IllegalArgumentException if either of <code>name</code> + * or <code>desc</code> are + * <code>null</code> or the empty + * string. + * @throws OpenDataException if the class name does not reference + * a listed class (from @{link ALLOWED_CLASSNAMES}) + */ + protected OpenType(String className, String name, String desc) + throws OpenDataException + { + if (name == null || name.equals("")) + throw new IllegalArgumentException("The name can not be null " + + "or the empty string."); + if (desc == null || desc.equals("")) + throw new IllegalArgumentException("The description can not " + + "be null or the empty string."); + String testString; + if (className.startsWith("[")) + testString = className.substring(className.indexOf("L") + 1); + else + testString = className; + boolean openTypeFound = false; + for (int a = 0; a < ALLOWED_CLASSNAMES.length; ++a) + if (ALLOWED_CLASSNAMES[a].equals(className)) + openTypeFound = true; + if (!openTypeFound) + throw new OpenDataException("The class name does not specify " + + "a valid open type."); + this.className = className; + typeName = name; + description = desc; + } + + /** + * Performs an equality test on this object and the one specified. + * + * @param obj the object to test against this one. + * @return true if the two objects are equivalent. + * @see java.lang.Object#hashCode() + */ + public abstract boolean equals(Object obj); + + /** + * Returns the name of the Java class this type represents. This must + * be one of the {@link ALLOWED_CLASSNAMES} or an array of one of them. + * The specification of arrays follows the standard set by + * {@link java.lang.Class#getName()} i.e. the name is the class name + * preceded by n instances of '[' and an 'L', where n is number of + * dimensions used by the array. + * + * @return the class name. + */ + public String getClassName() + { + return className; + } + + /** + * Returns a description of this open type. + * + * @return the description. + */ + public String getDescription() + { + return description; + } + + /** + * Returns the name of this open type. + * + * @return the type name. + */ + public String getTypeName() + { + return typeName; + } + + /** + * Returns a hash code for this open type. The hash code + * should be consistent with the {@link equals()} method. + * Thus, it should continue to return the same value while + * the values used by the {@link equals()} method remain + * the same, and should return different hash codes for + * objects which are judged to be different using the + * {@link equals()} method. + * + * @return the hash code of this instance. + */ + public abstract int hashCode(); + + /** + * Returns true if this open type represents an array type. + * + * @return true if this open type represents an array type. + */ + public boolean isArray() + { + return className.startsWith("["); + } + + /** + * Returns true if the specified object is a member of this + * type. + * + * @param obj the object to test for membership. + * @return true if the object is a member of this type. + */ + public abstract boolean isValue(Object obj); + + /** + * Returns a textual representation of this type. + * + * @return a {@link java.lang.String} representation of this + * type. + */ + public abstract String toString(); + +} diff --git a/libjava/classpath/javax/management/openmbean/SimpleType.java b/libjava/classpath/javax/management/openmbean/SimpleType.java new file mode 100644 index 0000000..3962909 --- /dev/null +++ b/libjava/classpath/javax/management/openmbean/SimpleType.java @@ -0,0 +1,342 @@ +/* SimpleType.java -- Open type descriptor for the base types. + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.management.openmbean; + +import java.io.InvalidObjectException; +import java.io.ObjectStreamException; + +/** + * The open type descriptor for data values that are members + * of one of the simple types (such as an integer or a string). + * The other open types ({@link ArrayType}, {@link CompositeType}, + * {@link TabularType}) are constructed from one or more of these + * types. The simple types are formed from a small subset of + * basic Java types. As a result, the valid instances of this + * class are predefined, and no constructor is given for creating + * new instances. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class SimpleType + extends OpenType +{ + + /** + * The {@link SimpleType} representation of + * <code>java.math.BigDecimal</code>. + */ + public static final SimpleType BIGDECIMAL; + + /** + * The {@link SimpleType} representation of + * <code>java.math.BigInteger</code>. + */ + public static final SimpleType BIGINTEGER; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Boolean</code>. + */ + public static final SimpleType BOOLEAN; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Byte</code>. + */ + public static final SimpleType BYTE; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Character</code>. + */ + public static final SimpleType CHARACTER; + + /** + * The {@link SimpleType} representation of + * <code>java.util.Date</code>. + */ + public static final SimpleType DATE; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Double</code>. + */ + public static final SimpleType DOUBLE; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Float</code>. + */ + public static final SimpleType FLOAT; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Integer</code>. + */ + public static final SimpleType INTEGER; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Long</code>. + */ + public static final SimpleType LONG; + + /** + * The {@link SimpleType} representation of + * <code>javax.management.ObjectName</code>. + */ + public static final SimpleType OBJECTNAME; + + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Short</code>. + */ + public static final SimpleType SHORT; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.String</code>. + */ + public static final SimpleType STRING; + + /** + * The {@link SimpleType} representation of + * <code>java.lang.Void</code>. + */ + public static final SimpleType VOID; + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 2215577471957694503L; + + /** + * The hash code of this instance. + */ + private transient Integer hashCode; + + /** + * The <code>toString()</code> result of this instance. + */ + private transient String string; + + /** + * Static construction of the {@link SimpleType} instances. + */ + static + { + try + { + BIGDECIMAL = new SimpleType("java.math.BigDecimal"); + BIGINTEGER = new SimpleType("java.math.BigInteger"); + BOOLEAN = new SimpleType("java.lang.Boolean"); + BYTE = new SimpleType("java.lang.Byte"); + CHARACTER = new SimpleType("java.lang.Character"); + DATE = new SimpleType("java.util.Date"); + DOUBLE = new SimpleType("java.lang.Double"); + FLOAT = new SimpleType("java.lang.Float"); + INTEGER = new SimpleType("java.lang.Integer"); + LONG = new SimpleType("java.lang.Long"); + OBJECTNAME = new SimpleType("javax.management.ObjectName"); + SHORT = new SimpleType("java.lang.Short"); + STRING = new SimpleType("java.lang.String"); + VOID = new SimpleType("java.lang.Void"); + } + catch (OpenDataException e) + { + /* In normal circumstances, this shouldn't be possible. */ + throw new IllegalStateException("A invalid class name " + + "was passed to the SimpleType " + + "constructor."); + } + } + + /** + * Constructs a new {@link SimpleType} instance for the given + * class name. The class name is also used as the type name + * and description of the {@link OpenType} instance. + * + * @param name the name of the class this instance should + * represent. + * @throws OpenDataException if somehow the constructor of the + * superclass is passed an invalid + * class name. + */ + private SimpleType(String name) + throws OpenDataException + { + super(name, name, name); + } + + /** + * <p> + * Compares this simple data type with another object + * for equality. The objects are judged to be equal if: + * </p> + * <ul> + * <li><code>obj</code> is not null.</li> + * <li><code>obj</code> is an instance of + * {@link SimpleType}.</li> + * <li>The class names are equal.</li> + * </ul> + * + * @param obj the object to compare with. + * @return true if the conditions above hold. + */ + public boolean equals(Object obj) + { + if (!(obj instanceof SimpleType)) + return false; + SimpleType sType = (SimpleType) obj; + return sType.getClassName().equals(getClassName()); + } + + /** + * <p> + * Returns the hash code of the simple data type. + * This is simply the hash code of the class name, + * which is the same element of the type compared + * as part of the + * {@link #equals(java.lang.Object)} method, thus ensuring + * that the hashcode is compatible with the equality + * test. + * </p> + * <p> + * As instances of this class are immutable, the hash code + * is computed just once for each instance and reused + * throughout its life. + * </p> + * + * @return the hash code of this instance. + */ + public int hashCode() + { + if (hashCode == null) + hashCode = Integer.valueOf(getClassName().hashCode()); + return hashCode.intValue(); + } + + /** + * Returns true if the specified object is a member of this + * simple type. The object is judged to be so if it is + * non-null and its class name is the same as that returned + * by {@link SimpleType#getClassName()}. + * + * @param obj the object to test for membership. + * @return true if the object is a member of this type. + */ + public boolean isValue(Object obj) + { + if (obj == null) + return false; + return obj.getClass().getName().equals(getClassName()); + } + + /** + * Replaces instances of this class read from an + * {@link java.io.ObjectInputStream} with one of the predefined + * values. This ensures that each existing instance of + * this class is one of these unique instances. + * + * @return the replacement object. + * @throws ObjectStreamException if the object can not be + * resolved. + */ + public Object readResolve() + throws ObjectStreamException + { + if (equals(BIGDECIMAL)) + return BIGDECIMAL; + if (equals(BIGINTEGER)) + return BIGINTEGER; + if (equals(BOOLEAN)) + return BOOLEAN; + if (equals(BYTE)) + return BYTE; + if (equals(CHARACTER)) + return CHARACTER; + if (equals(DATE)) + return DATE; + if (equals(DOUBLE)) + return DOUBLE; + if (equals(FLOAT)) + return FLOAT; + if (equals(INTEGER)) + return INTEGER; + if (equals(LONG)) + return LONG; + if (equals(OBJECTNAME)) + return OBJECTNAME; + if (equals(SHORT)) + return SHORT; + if (equals(STRING)) + return STRING; + if (equals(VOID)) + return VOID; + throw new InvalidObjectException("Invalid simple type instance " + + "deserialized."); + } + + /** + * <p> + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.openmbean.SimpleType</code>) + * and the name of the class the type represents. + * </p> + * <p> + * As instances of this class are immutable, the return value + * is computed just once for each instance and reused + * throughout its life. + * </p> + * + * @return a @link{java.lang.String} instance representing + * the instance in textual form. + */ + public String toString() + { + if (string == null) + string = getClass().getName() + + "[name=" + getClassName() + + "]"; + return string; + } + +} diff --git a/libjava/classpath/javax/management/openmbean/TabularData.java b/libjava/classpath/javax/management/openmbean/TabularData.java new file mode 100644 index 0000000..17c8de9 --- /dev/null +++ b/libjava/classpath/javax/management/openmbean/TabularData.java @@ -0,0 +1,258 @@ +/* TabularData.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.util.Collection; +import java.util.Set; + +/** + * Provides an interface to a specific type of composite + * data structure, where keys (the columns) map to the + * {@link CompositeData} objects that form the rows of + * the table. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +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. + * + * @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. + */ + Object[] calculateIndex(CompositeData val); + + /** + * Removes all {@link CompositeData} values from the table. + */ + void clear(); + + /** + * 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. + */ + boolean containsKey(Object[] key); + + /** + * 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. + */ + boolean containsValue(CompositeData val); + + /** + * 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 + * 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>. + */ + boolean equals(Object obj); + + /** + * 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 InvalidOpenTypeException if the key does not match + * the {@link TabularType} of this + * instance. + */ + CompositeData get(Object[] key); + + /** + * Returns the tabular type which corresponds to this instance + * of {@link TabularData}. + * + * @return the tabular type for this instance. + */ + 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. + * + * @return the hash code of this instance. + */ + int hashCode(); + + /** + * Returns true if this {@link TabularData} instance + * contains no {@link CompositeData} values. + * + * @return true if the instance is devoid of rows. + */ + boolean isEmpty(); + + /** + * Returns a {@link java.util.Set} view of the keys or + * indices of this {@link TabularData} instance. + * + * @return a set containing the keys of this instance. + */ + Set 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. + */ + void put(CompositeData 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. + * + * @param vals the {@link CompositeData} values 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 or + * of one of the other + * specified values. + */ + void putAll(CompositeData[] vals); + + /** + * 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. + */ + CompositeData remove(Object[] key); + + /** + * Returns the number of {@link CompositeData} values or rows + * in the table. + * + * @return the number of rows in the table. + */ + int size(); + + /** + * Returns a textual representation of this instance. The + * exact format is left up to the implementation, but it + * should contain the name of the implementing class and + * the tabular type. + * + * @return a {@link java.lang.String} representation of the + * object. + */ + String toString(); + + /** + * Returns the values associated with this instance. + * + * @return the values of this instance. + */ + Collection values(); + +} + diff --git a/libjava/classpath/javax/management/openmbean/TabularType.java b/libjava/classpath/javax/management/openmbean/TabularType.java new file mode 100644 index 0000000..c38f5ea --- /dev/null +++ b/libjava/classpath/javax/management/openmbean/TabularType.java @@ -0,0 +1,269 @@ +/* TabularType.java -- Type descriptor for TabularData instances. + 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.Collections; +import java.util.Iterator; +import java.util.List; + +/** + * The open type descriptor for instances of the + * {@link TabularData} class. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +public class TabularType + extends OpenType +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 6554071860220659261L; + + /** + * The composite type used by the rows of the table. + */ + private CompositeType rowType; + + /** + * The list of index names, which form the columns of the table. + * They are retained in the order given by the user, and is + * unmodifiable. + */ + private List indexNames; + + /** + * The hash code of this instance. + */ + private transient Integer hashCode; + + /** + * The <code>toString()</code> result of this instance. + */ + private transient String string; + + /** + * <p> + * Constructs a new {@link TabularType} instance for the given + * type name, description, row type and index names. All parameters + * (including the individual elements of the array of index names) + * must be non-null and those that are of type {@link java.lang.String} + * must be non-empty. The array of index names must also be non-empty. + * </p> + * <p> + * The result of <code>TabularData.class.getName()</code> is adopted + * as the class name (see {@link OpenType}). The ordering of the array + * elements is relevant in determining the indicies of the values in the + * table, and thus in the use of the + * {@link TabularData#get(java.lang.Object[])} and + * {@link TabularData#remove(java.lang.Object[])} methods of the + * {@link TabularData} class. + * </p> + * + * @param name the name of this tabular type. + * @param desc a description of this tabular type. + * @param rowType the type of the rows of the table. + * @param indexNames the names used to index the rows within the table. + * @throws IllegalArgumentException if any validity constraint listed above + * is broken. + * @throws OpenDataException if an index name does not match a corresponding + * name in the given row type. + */ + public TabularType(String name, String desc, CompositeType rowType, + String[] indexNames) + throws OpenDataException + { + super(TabularData.class.getName(), name, desc); + if (rowType == null) + throw new IllegalArgumentException("A null row type was given."); + for (int a = 0; a < indexNames.length; ++a) + { + if (indexNames[a] == null) + throw new IllegalArgumentException("Name " + a + + " is null."); + if (indexNames[a].length() == 0) + throw new IllegalArgumentException("Name " + a + + " is the empty string."); + if (!(rowType.containsKey(indexNames[a]))) + throw new OpenDataException("No matching key for " + + indexNames[a] + " was found in " + + "the supplied row type."); + } + this.rowType = rowType; + this.indexNames = Collections.unmodifiableList(Arrays.asList(indexNames)); + } + + /** + * <p> + * Compares this tabular data type with another object + * for equality. The objects are judged to be equal if: + * </p> + * <ul> + * <li><code>obj</code> is not null.</li> + * <li><code>obj</code> is an instance of + * {@link TabularType}.</li> + * <li>The type names are equal.</li> + * <li>The row types are equal.</li> + * <li>The index names are equal and in the same order.</li> + * </ul> + * + * @param obj the object to compare with. + * @return true if the conditions above hold. + */ + public boolean equals(Object obj) + { + if (!(obj instanceof TabularType)) + return false; + TabularType ttype = (TabularType) obj; + return (ttype.getTypeName().equals(getTypeName()) + && (ttype.getRowType().equals(getRowType())) + && (ttype.getIndexNames().equals(getIndexNames()))); + } + + /** + * Returns an unmodifiable list containing the index names. + * The ordering of these names is used to determine the indicies + * of the {@link CompositeData} values, and is retained from that + * used in the call to this object's constructor. + * + * @return an unmodifiable list of the index names used by this + * tabular data structure. + */ + public List getIndexNames() + { + return indexNames; + } + + /** + * Returns the type of the rows used by this tabular data structure. + * + * @return the row type. + */ + public CompositeType getRowType() + { + return rowType; + } + + /** + * <p> + * Returns the hash code of the tabular data type. + * This is computed as the sum of the hash codes of the + * index names together with the hash code of the type + * name and row 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. + * </p> + * <p> + * As instances of this class are immutable, the hash code + * is computed just once for each instance and reused + * throughout its life. + * </p> + * + * @return the hash code of this instance. + */ + public int hashCode() + { + if (hashCode == null) + { + int elementTotal = 0; + Iterator it = indexNames.iterator(); + while (it.hasNext()) + elementTotal += it.next().hashCode(); + hashCode = Integer.valueOf(elementTotal + + getTypeName().hashCode() + + rowType.hashCode()); + } + return hashCode.intValue(); + } + + /** + * Returns true if the specified object is a member of this + * tabular type. The object is judged to be so if it is + * an instance of {@link TabularData} with an equivalent + * type, according to the definition of + * {@link #equals(java.lang.Object)} for {@link TabularType}. + * + * @param obj the object to test for membership. + * @return true if the object is a member of this type. + */ + public boolean isValue(Object obj) + { + if (obj instanceof TabularData) + { + TabularData data = (TabularData) obj; + return equals(data.getTabularType()); + } + return false; + } + + /** + * <p> + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.openmbean.TabularType</code>) + * and each element of the instance which is relevant to + * the definition of {@link equals(java.lang.Object)} and + * {@link hashCode()} (i.e. the type name, the row type + * and the index names). + * </p> + * <p> + * As instances of this class are immutable, the return value + * is computed just once for each instance and reused + * throughout its life. + * </p> + * + * @return a @link{java.lang.String} instance representing + * the instance in textual form. + */ + public String toString() + { + if (string == null) + string = getClass().getName() + + "[name=" + getTypeName() + + ", rowType=" + rowType + + ", indexNames=" + indexNames + + "]"; + return string; + } + +} diff --git a/libjava/classpath/javax/management/openmbean/package.html b/libjava/classpath/javax/management/openmbean/package.html new file mode 100644 index 0000000..d915007 --- /dev/null +++ b/libjava/classpath/javax/management/openmbean/package.html @@ -0,0 +1,64 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<!-- package.html - describes classes in java.lang.management package. + 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. --> + +<html> +<head><title>GNU Classpath - javax.management.openmbean</title></head> + +<body> + +<p> +Provides the data types and descriptor classes for the +<emph>Open MBean</emph>s. Open MBeans are provided in +order to aid interoperability with non-Java management +systems. Unlike normal MBeans, which make use of any +Java data type, Open MBeans use a restricted set of types +which can then be mapped over remote connections, including +to non-Java systems. +</p> +<p> +Normal MBeans are described using an instance of +{@link javax.management.MBeanInfo} with appropriate representations +of the attributes, constructors and operators associated with +the bean. Open MBeans are described in the same way, but by +using subtypes of these entities, which type the bean data using +instances of {@link javax.management.openmbean.OpenType}. Open +types differ from Java types, and are explicitly specified in order +to obtain interoperability with other systems. +</p> +</body> +</html> |