From: <ls...@us...> - 2006-12-10 19:36:17
|
Revision: 2890 http://jnode.svn.sourceforge.net/jnode/?rev=2890&view=rev Author: lsantha Date: 2006-12-10 11:36:16 -0800 (Sun, 10 Dec 2006) Log Message: ----------- Classpath patches. Modified Paths: -------------- trunk/core/src/classpath/javax/javax/management/openmbean/OpenType.java Added Paths: ----------- trunk/core/src/classpath/javax/javax/management/BadBinaryOpValueExpException.java trunk/core/src/classpath/javax/javax/management/MBeanPermission.java trunk/core/src/classpath/javax/javax/management/MBeanRegistration.java trunk/core/src/classpath/javax/javax/management/MBeanServer.java trunk/core/src/classpath/javax/javax/management/MBeanServerBuilder.java trunk/core/src/classpath/javax/javax/management/MBeanServerConnection.java trunk/core/src/classpath/javax/javax/management/MBeanServerDelegate.java trunk/core/src/classpath/javax/javax/management/MBeanServerDelegateMBean.java trunk/core/src/classpath/javax/javax/management/MBeanServerFactory.java trunk/core/src/classpath/javax/javax/management/MBeanServerNotification.java trunk/core/src/classpath/javax/javax/management/MBeanTrustPermission.java trunk/core/src/classpath/javax/javax/management/ObjectInstance.java trunk/core/src/classpath/javax/javax/management/ObjectName.java trunk/core/src/classpath/javax/javax/management/QueryExp.java trunk/core/src/classpath/javax/javax/management/ValueExp.java trunk/core/src/classpath/javax/javax/management/loading/ trunk/core/src/classpath/javax/javax/management/loading/ClassLoaderRepository.java Added: trunk/core/src/classpath/javax/javax/management/BadBinaryOpValueExpException.java =================================================================== --- trunk/core/src/classpath/javax/javax/management/BadBinaryOpValueExpException.java (rev 0) +++ trunk/core/src/classpath/javax/javax/management/BadBinaryOpValueExpException.java 2006-12-10 19:36:16 UTC (rev 2890) @@ -0,0 +1,102 @@ +/* BadBinaryOpValueExpException.java -- Thrown by invalid query expressions. + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + +package javax.management; + +/** + * Thrown when the expression passed to a method for constructing a + * query proves to be invalid. This exception is only used internally + * by the Java management API and is not exposed to user code. + * + * @author Andrew John Hughes (gnu...@me...) + * @since 1.5 + */ +public class BadBinaryOpValueExpException + extends Exception +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = 5068475589449021227L; + + /** + * The value expression that caused the exception. + */ + private ValueExp exp; + + /** + * Constructs a new <code>BadBinaryOpValueExpException</code> + * using the specified expression to represent the invalid one. + * + * @param exp the inappropriate value expression. + */ + public BadBinaryOpValueExpException(ValueExp exp) + { + super(); + this.exp = exp; + } + + /** + * Returns the inappropriate value expression associated + * with this exception. + * + * @return the value expression. + */ + public ValueExp getExp() + { + return exp; + } + + /** + * Returns a textual representation of this instance. This + * is constructed using the class name + * (<code>javax.management.BadBinaryOpValueExpException</code>) + * and the invalid value expression. + * + * @return a @link{java.lang.String} instance representing + * the instance in textual form. + */ + public String toString() + { + return getClass().getName() + + "[exp=" + exp + + "]"; + } + +} + Added: trunk/core/src/classpath/javax/javax/management/MBeanPermission.java =================================================================== --- trunk/core/src/classpath/javax/javax/management/MBeanPermission.java (rev 0) +++ trunk/core/src/classpath/javax/javax/management/MBeanPermission.java 2006-12-10 19:36:16 UTC (rev 2890) @@ -0,0 +1,562 @@ +/* MBeanPermission.java -- Permissions controlling server access. + 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.security.Permission; + +import java.io.IOException; +import java.io.ObjectInputStream; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; +import java.util.TreeSet; + +/** + * <p> + * Represents the permissions required to perform + * operations using the {@link MBeanServer}. As with + * all {@link java.security.Permission} objects, an + * instance of this class either represents a permission + * already held or one that is required to access a + * particular service. In the case of {@link MBeanPermission}s, + * implication checks are made using an instance of this class + * when a user requests an operation from the server, and a + * {@link SecurityManager} is in place. + * </p> + * <p> + * An {@link MBeanPermission} consists of four elements, + * which all have to match for the permission to be implied. + * These are as follows: + * </p> + * <ol> + * <li><strong>The action</strong>. For a required permission, + * this is a single value. For a permission held by the user, + * this is a list of comma-separated actions (with spaces allowed), + * or <code>*</code> (representing all actions). {@link #getActions()} + * returns this value.</li> + * <li><strong>The class name</strong>. For a required permission, + * this is the class name of the bean being accessed, if any. If + * a bean isn't involved in this action, the value is <code>null</code>. + * For a permission held by the user, it has one of three values: + * <ol> + * <li>The empty string, implying any class.</li> + * <li><code>*</code>, also implying any class.</li> + * <li>A class name pattern, which may specify a single class + * (e.g. <code>java.lang.Object</code>) or a series of classes + * using the wildcard character <code>*</code> (e.g. + * <code>javax.swing.*</code>.)</li> + * </ol></li> + * <li><strong>The member</strong>. For a required permission, + * this is the member of the bean being accessed (an attribute + * or operation), if any. If a member of the bean isn't involved + * in this action, the value is <code>null</code>. + * For a permission held by the user, it has one of three values: + * <ol> + * <li>The empty string, implying any member.</li> + * <li><code>*</code>, also implying any member.</li> + * <li>The name of a member.</li> + * </ol></li> + * <li>The object name</strong>. For a required permission, + * this is the {@link ObjectName} of the bean being accessed, if + * any. If a bean isn't involved in this action, the value is + * <code>null</code>. The name may not be a pattern. + * For a permission held by the user, it may be the empty + * string (allowing everything) or an {@link ObjectName} + * pattern. + * </li></ol> + * {@link #getName()} returns the latter three of these as a + * single string: + * </p> + * <p><code>className#member[objectName]</code></p> + * <p> + * where <code>""</code> is disallowed, as, although any of + * the elements may be omitted, not all of them should be + * left out simultaneously. <code>"-"</code> is used to + * represent <code>null</code>. When this occurs in a + * required permission, anything may match it. When this + * forms part of a permission held by the user, it only + * matches another <code>null</code> value. + * </p> + * <p>The list of valid actions is as follows:</p> + * <ul> + * <li>addNotificationListener</li> + * <li>getAttribute</li> + * <li>getClassLoader</li> + * <li>getClassLoaderFor</li> + * <li>getClassLoaderRepository</li> + * <li>getDomains</li> + * <li>getMBeanInfo</li> + * <li>getObjectInstance</li> + * <li>instantiate</li> + * <li>invoke</li> + * <li>isInstanceOf</li> + * <li>queryMBeans</li> + * <li>queryNames</li> + * <li>registerMBean</li> + * <li>removeNotificationListener</li> + * <li>setAttribute</li> + * <li>unregisterMBean</li> + * </ul> + * + * @author Andrew John Hughes (gnu...@me...) + * @since 1.5 + */ +public class MBeanPermission + extends Permission +{ + + /** + * Compatible with JDK 1.5 + */ + private static final long serialVersionUID = -2416928705275160661L; + + /** + * The list of actions associated with this permission. + */ + private String actions; + + /** + * The list of actions as an ordered set. + */ + private transient Set actionSet; + + /** + * The set of valid actions. + */ + private static final Set validSet; + + /** + * Initialise the set of valid actions. + */ + static + { + validSet = new HashSet(); + validSet.add("addNotificationListener"); + validSet.add("getAttribute"); + validSet.add("getClassLoader"); + validSet.add("getClassLoaderFor"); + validSet.add("getClassLoaderRepository"); + validSet.add("getDomains"); + validSet.add("getMBeanInfo"); + validSet.add("getObjectInstance"); + validSet.add("instantiate"); + validSet.add("invoke"); + validSet.add("isInstanceOf"); + validSet.add("queryMBeans"); + validSet.add("queryNames"); + validSet.add("registerMBean"); + validSet.add("removeNotificationListener"); + validSet.add("setAttribute"); + validSet.add("unregisterMBean"); + } + + /** + * Constructs a new {@link MBeanPermission} with the specified name + * and actions. The name is of the form <code>className#member[objectName]</code>, + * where each element is optional, but a completely empty or <code>null</code> + * name is disallowed. Actions are specified as a comma-separated list + * and may also not be empty or <code>null</code>. + * + * @param name the name of the permission. + * @param actions the actions associated with this permission. + * @throws IllegalArgumentException if the name or actions are invalid. + */ + public MBeanPermission(String name, String actions) + { + super(name); + if (name == null || name.length() == 0) + throw new IllegalArgumentException("The supplied name was null or empty."); + if (actions == null || actions.length() == 0) + throw new IllegalArgumentException("The supplied action list was null or empty."); + this.actions = actions; + updateActionSet(); + } + + /** + * Constructs a new {@link MBeanPermission} with the specified class name, + * member, object name and actions. The name of the permission is created + * using the form <code>className#member[objectName]</code>, + * where each element is optional, but an empty or <code>null</code> + * name is disallowed. Actions are specified as a comma-separated list + * and may also not be empty or <code>null</code>. + * + * @param className the name of the class to which this permission applies, + * or either <code>null</code> or <code>"-"</code> for a + * value which may be implied by any class name, but not + * imply any class name itself. + * @param member the member of the class to which this permission applies, + * or either <code>null</code> or <code>"-"</code> for a + * value which may be implied by any member, but not + * imply any member itself. + * @param objectName the {@link ObjectName} to which this permission applies, + * or <code>null</code> for a value which may be implied by + * any object name, but not imply any object name itself. + * @param actions the actions associated with this permission. + */ + public MBeanPermission(String className, String member, + ObjectName name, String actions) + { + this((className == null ? "-" : className) + "#" + + (member == null ? "-" : member) + "[" + + (name == null ? "-" : name.toString()) + "]", actions); + } + + /** + * Returns true if the given object is also an {@link MBeanPermission} + * with the same name and actions. + * + * @param obj the object to test. + * @return true if the object is an {@link MBeanPermission} with + * the same name and actions. + */ + public boolean equals(Object obj) + { + if (obj instanceof MBeanPermission) + { + MBeanPermission p = (MBeanPermission) obj; + return (p.getName().equals(getName()) && + p.getActions().equals(actions)); + } + return false; + } + + /** + * Returns the list of actions in alphabetical order. + * + * @return the list of actions. + */ + public String getActions() + { + Iterator it = actionSet.iterator(); + StringBuilder builder = new StringBuilder(); + while (it.hasNext()) + { + builder.append(it.next()); + if (it.hasNext()) + builder.append(","); + } + return builder.toString(); + } + + /** + * Returns the hashcode of the permission as the sum + * of the hashcodes of the name and actions. + * + * @return the hashcode of the permission. + */ + public int hashCode() + { + return getName().hashCode() + actions.hashCode(); + } + + /** + * <p> + * Returns true if this permission implies the supplied permission. + * This happens if the following holds: + * </p> + * <ul> + * <li>The supplied permission is an {@link MBeanPermission}</li> + * <li>The supplied permission has either a <code>null</code> classname + * or its classname matches the classname of this permission. A + * classname of <code>"*"</code> for this permission always matches + * the classname of the supplied permission. Generally, <code>'*'</code> + * acts as a wildcard, so <code>".*"</code> matches <code>'.'</code> + * followed by anything.</li> + * <li>The supplied permission has either a <code>null</code> member + * or its member matches the member of this permission. A member of + * <code>"*"</code> for this permission always matches the member + * of the supplied permission.</li> + * <li>The supplied permission has either a <code>null</code> object name + * or its object name matches the object name of this permission. If the + * object name of this permission is a pattern, {@link ObjectName#apply(ObjectName)} + * may be used as well.</li> + * <li>The supplied permission's actions are a subset of the actions + * of this permission. If the <code>queryMBeans</code> action is presented, + * the <code>queryNames</code> action is implied.</li> + * </ul> + * + * @param p the permission to check that this permission implies. + * @return true if this permission implies <code>p</code>. + */ + public boolean implies(Permission p) + { + if (p instanceof MBeanPermission) + { + MBeanPermission mp = (MBeanPermission) p; + NameHolder pName = new NameHolder(mp.getName()); + NameHolder name = new NameHolder(getName()); + if (!(name.equals(pName))) + return false; + Iterator i = mp.getActionSet().iterator(); + while (i.hasNext()) + { + String nextAction = (String) i.next(); + boolean found = actions.contains(nextAction); + if (!found) + if (nextAction.equals("queryNames")) + found = actions.contains("queryMBeans"); + if (!found) + return false; + } + return true; + } + return false; + } + + /** + * Small helper class to handle deconstruction of the name. + * + * @author Andrew John Hughes (gnu...@me...) + */ + private class NameHolder + { + + /** + * The class name. + */ + private String className; + + /** + * The member. + */ + private String member; + + /** + * The object name. + */ + private ObjectName objectName; + + /** + * Constructs a broken-down name from a given name. + * + * @param name the name to break down. + */ + public NameHolder(String name) + { + String objectName = null; + int memberIndex = name.indexOf("#"); + int onIndex = name.indexOf("["); + if (onIndex == -1) + { + if (memberIndex == -1) + className = name; + else + { + className = name.substring(0, memberIndex); + member = name.substring(memberIndex + 1); + } + } + else + { + if (memberIndex == -1) + { + className = name.substring(0, onIndex); + objectName = name.substring(onIndex + 1, + name.length() - 1); + } + else + { + className = name.substring(0, memberIndex); + member = name.substring(memberIndex + 1, onIndex); + objectName = name.substring(onIndex + 1, + name.length() - 1); + } + } + if (className.equals("-")) + className = null; + if (member.equals("-")) + member = null; + if (objectName == null || objectName.equals("-")) + this.objectName = null; + else + try + { + this.objectName = new ObjectName(objectName); + } + catch (MalformedObjectNameException e) + { + throw (Error) + (new InternalError("Invalid object name.").initCause(e)); + } + } + + /** + * <p> + * Returns true if the supplied object is also a + * {@link NameHolder} and the following holds: + * </p> + * <ul> + * <li>The supplied classname is <code>null</code> or the two match. A + * classname of <code>"*"</code> for this holder always matches + * the classname of the supplied holder. Generally, <code>'*'</code> + * acts as a wildcard, so <code>".*"</code> matches <code>'.'</code> + * followed by anything.</li> + * <li>The supplied name holder has either a <code>null</code> member + * or its member matches the member of this name holder. A member of + * <code>"*"</code> for this name holder always matches the member + * of the supplied name holder.</li> + * <li>The supplied name holder has either a <code>null</code> object name + * or its object name matches the object name of this name holder. If the + * object name of this name holder is a pattern, + * {@link ObjectName#apply(ObjectName)} may be used as well.</li> + * </ul> + * + * @param obj the object to compare with this. + * @return true if the above holds. + */ + public boolean equals(Object obj) + { + if (obj instanceof NameHolder) + { + NameHolder nh = (NameHolder) obj; + boolean cn = false; + String ocn = nh.getClassName(); + if (ocn == null || className.equals("*")) + cn = true; + else + { + int wcIndex = className.indexOf("*"); + if (wcIndex != -1) + cn = ocn.startsWith(className.substring(0, wcIndex)); + else + cn = ocn.equals(className); + } + boolean m = false; + String om = nh.getMember(); + if (om == null || member.equals("*")) + m = true; + else + m = om.equals(member); + boolean on = false; + ObjectName oon = nh.getObjectName(); + if (oon == null) + on = true; + else if (objectName.isPattern()) + on = objectName.apply(oon); + else + on = oon.equals(objectName); + return (cn && m && on); + } + return false; + } + + /** + * Returns the class name. + */ + public String getClassName() + { + return className; + } + + /** + * Returns the member. + */ + public String getMember() + { + return member; + } + + /** + * Returns the object name. + */ + public ObjectName getObjectName() + { + return objectName; + } + } + + /** + * Returns the set of actions. + * + * @return the actions as an ordered set. + */ + Set getActionSet() + { + return actionSet; + } + + /** + * Updates the action set from the current value of + * the actions string. + */ + private void updateActionSet() + { + String[] actionsArray = actions.split(","); + actionSet = new TreeSet(); + for (int a = 0; a < actionsArray.length; ++a) + actionSet.add(actionsArray[a].trim()); + } + + /** + * Reads the object from a stream and ensures the incoming + * data is valid. + * + * @param in the input stream. + * @throws IOException if an I/O error occurs. + * @throws ClassNotFoundException if a class used by the object + * can not be found. + */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException + { + in.defaultReadObject(); + updateActionSet(); + checkActions(); + } + + /** + * Checks that the actions used in this permission + * are from the valid set. + * + * @throws IllegalArgumentException if the name or actions are invalid. + */ + private void checkActions() + { + Iterator it = actionSet.iterator(); + while (it.hasNext()) + { + String action = (String) it.next(); + if (!(validSet.contains(action))) + throw new IllegalArgumentException("Invalid action " + + action + " found."); + } + } + +} + Added: trunk/core/src/classpath/javax/javax/management/MBeanRegistration.java =================================================================== --- trunk/core/src/classpath/javax/javax/management/MBeanRegistration.java (rev 0) +++ trunk/core/src/classpath/javax/javax/management/MBeanRegistration.java 2006-12-10 19:36:16 UTC (rev 2890) @@ -0,0 +1,95 @@ +/* MBeanRegistration.java -- Interface for beans to hook into registration. + 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; + +/** + * Beans may implement this interface in order to perform + * operations immediately prior to or after their registration + * or deregistration. + * + * @author Andrew John Hughes (gnu...@me...) + * @since 1.5 + */ +public interface MBeanRegistration +{ + + /** + * This method is called following deregistration of the bean + * by the server. + */ + void postDeregister(); + + /** + * This method is called following both successful and unsuccessful + * attempts to register the bean. The supplied boolean value indicates + * the result of the attempt relative to this call. + * + * @param successful true if the registration was successful. + */ + void postRegister(Boolean successful); + + /** + * This method is called prior to de-registration, and may throw + * an exception. + * + * @throws Exception if something goes wrong during the bean's pre-deregistration + * operation. The server will re-throw this exception + * as an {@link MBeanRegistrationException}. + */ + void preDeregister() + throws Exception; + + /** + * This method is called prior to registration, with a reference to the + * server and {@link ObjectName} supplied to the server for registration. + * This method may be used to replace this name by one chosen by the bean. + * Such behaviour is expected if the supplied name is <code>null</code>, + * but may occur in all cases. The method may throw an exception, which + * will cause registration to be aborted. + * + * @param server the server with which the bean is being registered. + * @param name the name the server was supplied with for registration, + * which may be <code>null</code>. + * @throws Exception if something goes wrong during the bean's pre-registration + * operation. The server will re-throw this exception + * as an {@link MBeanRegistrationException}. + */ + ObjectName preRegister(MBeanServer server, ObjectName name) + throws Exception; + +} Added: trunk/core/src/classpath/javax/javax/management/MBeanServer.java =================================================================== --- trunk/core/src/classpath/javax/javax/management/MBeanServer.java (rev 0) +++ trunk/core/src/classpath/javax/javax/management/MBeanServer.java 2006-12-10 19:36:16 UTC (rev 2890) @@ -0,0 +1,1199 @@ +/* MBeanServer.java -- Represents a management server. + 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.ObjectInputStream; + +import java.util.Set; + +import javax.management.loading.ClassLoaderRepository; + +/** + * <p> + * This interface represents a server for management beans, + * providing facilities for the creation, registration and + * removal of such beans. This interface is central to the + * Java management architecture. Users do not usually implement + * this class. Instead, implementations of this class + * may be obtained using an {@link MBeanServerFactory}. + * </p> + * <p> + * Registering a bean with the server makes its attributes and + * operations accessible via the server. Only JMX compliant + * beans may be registered with the server. When a bean + * is registered or unregistered, an {@link MBeanServerNotification} + * is emitted by the server's {@link MBeanServerDelegate}. + * Listeners may be registered with this bean in order to + * obtain such notifications. It has the {@link ObjectName} + * <code>JMImplementation:type=MBeanServerDelegate</code>. + * </p> + * <p> + * Security checks are applied on the methods of the server, + * as detailed below, if it is obtained using the + * {@link MBeanServerFactory#createMBeanServer()} or + * {@link MBeanServerFactory#newMBeanServer()} methods and + * {@link System.getSecurityManager()} returns a non-<code>null</code> + * value. If a check fails, a {@link SecurityException} + * is thrown. Note than the class name used in the exception + * is that of the bean, and thus, as a result, an + * {@link InstanceNotFoundException} + * precludes these security checks, due to the class name + * that would be used in the exception being unavailable. + * </p> + * + * @author Andrew John Hughes (gnu...@me...) + * @since 1.5 + */ +public interface MBeanServer + extends MBeanServerConnection +{ + + /** + * Registers the supplied listener with the specified management + * bean. Notifications emitted by the management bean are forwarded + * to the listener via the server, which will convert any MBean + * references in the source to portable {@link ObjectName} + * instances. The notification is otherwise unchanged. + * + * @param name the name of the management bean with which the listener + * should be registered. + * @param listener the listener which will handle notifications from + * the bean. + * @param filter the filter to apply to incoming notifications, or + * <code>null</code> if no filtering should be applied. + * @param passback an object to be passed to the listener when a + * notification is emitted. + * @throws InstanceNotFoundException if the name of the management bean + * could not be resolved. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, name, + * "addNotificationListener")</code>}. + * @see #removeNotificationListener(ObjectName, NotificationListener) + * @see #removeNotificationListener(ObjectName, NotificationListener, + * NotificationFilter, Object) + * @see NotificationBroadcaster#addNotificationListener(NotificationListener, + * NotificationFilter, + * Object) + */ + void addNotificationListener(ObjectName name, NotificationListener listener, + NotificationFilter filter, Object passback) + throws InstanceNotFoundException; + + /** + * <p> + * Registers the supplied listener with the specified management + * bean. Notifications emitted by the management bean are forwarded + * to the listener via the server, which will convert any MBean + * references in the source to portable {@link ObjectName} + * instances. The notification is otherwise unchanged. + * </p> + * <p> + * The listener that receives notifications will be the one that is + * registered with the given name at the time this method is called. + * Even if it later unregisters and ceases to use that name, it will + * still receive notifications. + * </p> + * + * @param name the name of the management bean with which the listener + * should be registered. + * @param listener the name of the listener which will handle + * notifications from the bean. + * @param filter the filter to apply to incoming notifications, or + * <code>null</code> if no filtering should be applied. + * @param passback an object to be passed to the listener when a + * notification is emitted. + * @throws InstanceNotFoundException if the name of the management bean + * could not be resolved. + * @throws RuntimeOperationsException if the bean associated with the given + * object name is not a + * {@link NotificationListener}. This + * exception wraps an + * {@link IllegalArgumentException}. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, name, + * "addNotificationListener")</code>}. + * @see #removeNotificationListener(ObjectName, NotificationListener) + * @see #removeNotificationListener(ObjectName, NotificationListener, + * NotificationFilter, Object) + * @see NotificationBroadcaster#addNotificationListener(NotificationListener, + * NotificationFilter, + * Object) + */ + void addNotificationListener(ObjectName name, ObjectName listener, + NotificationFilter filter, Object passback) + throws InstanceNotFoundException; + + /** + * <p> + * Instantiates a new instance of the specified management bean + * using the default constructor and registers it with the server + * under the supplied name. The class is loaded using the + * {@link javax.management.loading.ClassLoaderRepository default + * loader repository} of the server. + * </p> + * <p> + * If the name supplied is <code>null</code>, then the bean is + * expected to implement the {@link MBeanRegistration} interface. + * The {@link MBeanRegistration#preRegister preRegister} method + * of this interface will be used to obtain the name in this case. + * </p> + * <p> + * This method is equivalent to calling {@link + * #createMBean(String, ObjectName, Object[], String[]) + * <code>createMBean(className, name, (Object[]) null, + * (String[]) null)</code>} with <code>null</code> parameters + * and signature. + * </p> + * + * @param className the class of the management bean, of which + * an instance should be created. + * @param name the name to register the new bean with. + * @return an {@link ObjectInstance} containing the {@link ObjectName} + * and Java class name of the created instance. + * @throws ReflectionException if an exception occurs in creating + * an instance of the bean. + * @throws InstanceAlreadyExistsException if a matching instance + * already exists. + * @throws MBeanRegistrationException if an exception occurs in + * calling the preRegister + * method. + * @throws MBeanException if the bean's constructor throws an exception. + * @throws NotCompliantMBeanException if the created bean is not + * compliant with the JMX specification. + * @throws RuntimeOperationsException if an {@link IllegalArgumentException} + * is thrown by the server due to a + * <code>null</code> class name or object + * name or if the object name is a pattern. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply the + * use of the <code>instantiate</code> + * and <code>registerMBean</code> methods. + * @see #createMBean(String, ObjectName, Object[], String[]) + */ + ObjectInstance createMBean(String className, ObjectName name) + throws ReflectionException, InstanceAlreadyExistsException, + MBeanRegistrationException, MBeanException, + NotCompliantMBeanException; + + /** + * <p> + * Instantiates a new instance of the specified management bean + * using the given constructor and registers it with the server + * under the supplied name. The class is loaded using the + * {@link javax.management.loading.ClassLoaderRepository default + * loader repository} of the server. + * </p> + * <p> + * If the name supplied is <code>null</code>, then the bean is + * expected to implement the {@link MBeanRegistration} interface. + * The {@link MBeanRegistration#preRegister preRegister} method + * of this interface will be used to obtain the name in this case. + * </p> + * + * @param className the class of the management bean, of which + * an instance should be created. + * @param name the name to register the new bean with. + * @param params the parameters for the bean's constructor. + * @param sig the signature of the constructor to use. + * @return an {@link ObjectInstance} containing the {@link ObjectName} + * and Java class name of the created instance. + * @throws ReflectionException if an exception occurs in creating + * an instance of the bean. + * @throws InstanceAlreadyExistsException if a matching instance + * already exists. + * @throws MBeanRegistrationException if an exception occurs in + * calling the preRegister + * method. + * @throws MBeanException if the bean's constructor throws an exception. + * @throws NotCompliantMBeanException if the created bean is not + * compliant with the JMX specification. + * @throws RuntimeOperationsException if an {@link IllegalArgumentException} + * is thrown by the server due to a + * <code>null</code> class name or object + * name or if the object name is a pattern. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply the + * use of the <code>instantiate</code> + * and <code>registerMBean</code> methods. + */ + ObjectInstance createMBean(String className, ObjectName name, + Object[] params, String[] sig) + throws ReflectionException, InstanceAlreadyExistsException, + MBeanRegistrationException, MBeanException, + NotCompliantMBeanException; + + /** + * <p> + * Instantiates a new instance of the specified management bean + * using the default constructor and registers it with the server + * under the supplied name. The class is loaded using the + * given class loader. If this argument is <code>null</code>, + * then the same class loader as was used to load the server + * is used. + * </p> + * <p> + * If the name supplied is <code>null</code>, then the bean is + * expected to implement the {@link MBeanRegistration} interface. + * The {@link MBeanRegistration#preRegister preRegister} method + * of this interface will be used to obtain the name in this case. + * </p> + * <p> + * This method is equivalent to calling {@link + * #createMBean(String, ObjectName, ObjectName, Object[], String) + * <code>createMBean(className, name, loaderName, (Object[]) null, + * (String) null)</code>} with <code>null</code> parameters + * and signature. + * </p> + * + * @param className the class of the management bean, of which + * an instance should be created. + * @param name the name to register the new bean with. + * @param loaderName the name of the class loader. + * @return an {@link ObjectInstance} containing the {@link ObjectName} + * and Java class name of the created instance. + * @throws ReflectionException if an exception occurs in creating + * an instance of the bean. + * @throws InstanceAlreadyExistsException if a matching instance + * already exists. + * @throws MBeanRegistrationException if an exception occurs in + * calling the preRegister + * method. + * @throws MBeanException if the bean's constructor throws an exception. + * @throws NotCompliantMBeanException if the created bean is not + * compliant with the JMX specification. + * @throws InstanceNotFoundException if the specified class loader is not + * registered with the server. + * @throws RuntimeOperationsException if an {@link IllegalArgumentException} + * is thrown by the server due to a + * <code>null</code> class name or object + * name or if the object name is a pattern. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply the + * use of the <code>instantiate</code> + * and <code>registerMBean</code> methods. + * @see #createMBean(String, ObjectName, ObjectName, Object[], String[]) + */ + ObjectInstance createMBean(String className, ObjectName name, + ObjectName loaderName) + throws ReflectionException, InstanceAlreadyExistsException, + MBeanRegistrationException, MBeanException, + NotCompliantMBeanException, InstanceNotFoundException; + + /** + * <p> + * Instantiates a new instance of the specified management bean + * using the given constructor and registers it with the server + * under the supplied name. The class is loaded using the + * given class loader. If this argument is <code>null</code>, + * then the same class loader as was used to load the server + * is used. + * </p> + * <p> + * If the name supplied is <code>null</code>, then the bean is + * expected to implement the {@link MBeanRegistration} interface. + * The {@link MBeanRegistration#preRegister preRegister} method + * of this interface will be used to obtain the name in this case. + * </p> + * + * @param className the class of the management bean, of which + * an instance should be created. + * @param name the name to register the new bean with. + * @param loaderName the name of the class loader. + * @param params the parameters for the bean's constructor. + * @param sig the signature of the constructor to use. + * @return an {@link ObjectInstance} containing the {@link ObjectName} + * and Java class name of the created instance. + * @throws ReflectionException if an exception occurs in creating + * an instance of the bean. + * @throws InstanceAlreadyExistsException if a matching instance + * already exists. + * @throws MBeanRegistrationException if an exception occurs in + * calling the preRegister + * method. + * @throws MBeanException if the bean's constructor throws an exception. + * @throws NotCompliantMBeanException if the created bean is not + * compliant with the JMX specification. + * @throws InstanceNotFoundException if the specified class loader is not + * registered with the server. + * @throws RuntimeOperationsException if an {@link IllegalArgumentException} + * is thrown by the server due to a + * <code>null</code> class name or object + * name or if the object name is a pattern. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply the + * use of the <code>instantiate</code> + * and <code>registerMBean</code> methods. + */ + ObjectInstance createMBean(String className, ObjectName name, + ObjectName loaderName, Object[] params, + String[] sig) + throws ReflectionException, InstanceAlreadyExistsException, + MBeanRegistrationException, MBeanException, + NotCompliantMBeanException, InstanceNotFoundException; + + /** + * Deserializes a byte array using the class loader of the specified + * management bean as its context. + * + * @param name the name of the bean whose class loader should be used. + * @param data the byte array to be deserialized. + * @return the deserialized object stream. + * @deprecated {@link #getClassLoaderFor(ObjectName)} should be used + * to obtain the class loader of the bean, which can then + * be used to perform deserialization in the user's code. + * @throws InstanceNotFoundException if the specified bean is not + * registered with the server. + * @throws OperationsException if any I/O error is thrown by the + * deserialization process. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, name, + * "getClassLoaderFor")</code> + */ + ObjectInputStream deserialize(ObjectName name, byte[] data) + throws InstanceNotFoundException, OperationsException; + + /** + * Deserializes a byte array using the same class loader for its context + * as was used to load the given class. This class loader is obtained by + * loading the specified class using the {@link + * javax.management.loading.ClassLoaderRepository Class Loader Repository} + * and then using the class loader of the resulting {@link Class} instance. + * + * @param name the name of the class which should be loaded to obtain the + * class loader. + * @param data the byte array to be deserialized. + * @return the deserialized object stream. + * @deprecated {@link #getClassLoaderRepository} should be used + * to obtain the class loading repository, which can then + * be used to obtain the {@link Class} instance and deserialize + * the array using its class loader. + * @throws OperationsException if any I/O error is thrown by the + * deserialization process. + * @throws ReflectionException if an error occurs in obtaining the + * {@link Class} instance. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(null, null, null, + * "getClassLoaderRepository")</code> + */ + ObjectInputStream deserialize(String name, byte[] data) + throws OperationsException, ReflectionException; + + /** + * Deserializes a byte array using the same class loader for its context + * as was used to load the given class. The name of the class loader to + * be used is supplied, and may be <code>null</code> if the server's + * class loader should be used instead. + * + * @param name the name of the class which should be loaded to obtain the + * class loader. + * @param loader the name of the class loader to use, or <code>null</code> + * if the class loader of the server should be used. + * @param data the byte array to be deserialized. + * @return the deserialized object stream. + * @deprecated {@link #getClassLoader(ObjectName} can be used to obtain + * the named class loader and deserialize the array. + * @throws InstanceNotFoundException if the specified class loader is not + * registered with the server. + * @throws OperationsException if any I/O error is thrown by the + * deserialization process. + * @throws ReflectionException if an error occurs in obtaining the + * {@link Class} instance. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, loader, + * "getClassLoader")</code> + */ + ObjectInputStream deserialize(String name, ObjectName loader, byte[] data) + throws InstanceNotFoundException, ReflectionException, + OperationsException; + + /** + * Returns the value of the supplied attribute from the specified + * management bean. + * + * @param bean the bean to retrieve the value from. + * @param name the name of the attribute to retrieve. + * @return the value of the attribute. + * @throws AttributeNotFoundException if the attribute could not be + * accessed from the bean. + * @throws MBeanException if the management bean's accessor throws + * an exception. + * @throws InstanceNotFoundException if the bean can not be found. + * @throws ReflectionException if an exception was thrown in trying + * to invoke the bean's accessor. + * @throws RuntimeOperationsException if an {@link IllegalArgumentException} + * is thrown by the server due to a + * <code>null</code> bean or attribute + * name. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, name, bean, + * "getAttribute")</code>}. + * @see DynamicMBean#getAttribute(String) + */ + Object getAttribute(ObjectName bean, String name) + throws MBeanException, AttributeNotFoundException, + InstanceNotFoundException, ReflectionException; + + /** + * Returns the values of the named attributes from the specified + * management bean. + * + * @param bean the bean to retrieve the value from. + * @param names the names of the attributes to retrieve. + * @return the values of the attributes. + * @throws InstanceNotFoundException if the bean can not be found. + * @throws ReflectionException if an exception was thrown in trying + * to invoke the bean's accessor. + * @throws RuntimeOperationsException if an {@link IllegalArgumentException} + * is thrown by the server due to a + * <code>null</code> bean or attribute + * name. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, bean, + * "getAttribute")</code>}. Additionally, + * for an attribute name, <code>n</code>, the + * caller's permission must imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, n, bean, + * "getAttribute")</code>} or that attribute will + * not be included. + * + * @see DynamicMBean#getAttributes(String[]) + */ + AttributeList getAttributes(ObjectName bean, String[] names) + throws InstanceNotFoundException, ReflectionException; + + /** + * Returns the specified class loader. If the specified value is + * <code>null</code>, then the class loader of the server will be + * returned. If <code>l</code> is the requested class loader, + * and <code>r</code> is the actual class loader returned, then + * either <code>l</code> and <code>r</code> will be identical, + * or they will at least return the same class from + * {@link ClassLoader#loadClass(String)} for any given string. + * They may not be identical due to one or the other + * being wrapped in another class loader (e.g. for security). + * + * @param name the name of the class loader to return. + * @return the class loader. + * @throws InstanceNotFoundException if the class loader can not + * be found. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, name, + * "getClassLoader")</code> + */ + ClassLoader getClassLoader(ObjectName name) + throws InstanceNotFoundException; + + /** + * Returns the class loader of the specified management bean. If + * <code>l</code> is the requested class loader, and <code>r</code> + * is the actual class loader returned, then either <code>l</code> + * and <code>r</code> will be identical, or they will at least + * return the same class from {@link ClassLoader#loadClass(String)} + * for any given string. They may not be identical due to one or + * the other being wrapped in another class loader (e.g. for + * security). + * + * @param name the name of the bean whose class loader should be + * returned. + * @return the class loader. + * @throws InstanceNotFoundException if the bean is not registered + * with the server. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(className, null, name, + * "getClassLoaderFor")</code> + */ + ClassLoader getClassLoaderFor(ObjectName name) + throws InstanceNotFoundException; + + /** + * Returns the class loader repository used by this server. + * + * @return the class loader repository. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(null, null, null, + * "getClassLoaderRepository")</code> + */ + ClassLoaderRepository getClassLoaderRepository(); + + /** + * Returns the default domain this server applies to beans that have + * no specified domain. + * + * @return the default domain. + */ + String getDefaultDomain(); + + /** + * Returns an array containing all the domains used by beans registered + * with this server. The ordering of the array is undefined. + * + * @return the list of domains. + * @throws SecurityException if a security manager exists and the + * caller's permissions don't imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(null, null, name, + * "getDomains")</code>}. Additionally, + * for an domain, <code>d</code>, the + * caller's permission must imply {@link + * MBeanPermission(String,String,ObjectName,String) + * <code>MBeanPermission(null, null, + * new ObjectName("d:x=x"), "getDomains")</code>} + * or that domain will not be included. Note + * that "x=x" is an arbitrary key-value pair + * provided to satisfy the constructor. + * @see ObjectName#getDomain() + */ + String[] getDomains(); + + /** + * Returns the number of manag... [truncated message content] |