feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
/**
|
||||
* This exception is raised when relation id provided for a relation is already
|
||||
* used.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class InvalidRelationIdException extends RelationException {
|
||||
|
||||
/* Serial version */
|
||||
private static final long serialVersionUID = -7115040321202754171L;
|
||||
|
||||
/**
|
||||
* Default constructor, no message put in exception.
|
||||
*/
|
||||
public InvalidRelationIdException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given message put in exception.
|
||||
*
|
||||
* @param message the detail message.
|
||||
*/
|
||||
public InvalidRelationIdException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
/**
|
||||
* This exception is raised when an invalid Relation Service is provided.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class InvalidRelationServiceException extends RelationException {
|
||||
|
||||
/* Serial version */
|
||||
private static final long serialVersionUID = 3400722103759507559L;
|
||||
|
||||
/**
|
||||
* Default constructor, no message put in exception.
|
||||
*/
|
||||
public InvalidRelationServiceException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given message put in exception.
|
||||
*
|
||||
* @param message the detail message.
|
||||
*/
|
||||
public InvalidRelationServiceException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
/**
|
||||
* Invalid relation type.
|
||||
* This exception is raised when, in a relation type, there is already a
|
||||
* relation type with that name, or the same name has been used for two
|
||||
* different role infos, or no role info provided, or one null role info
|
||||
* provided.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class InvalidRelationTypeException extends RelationException {
|
||||
|
||||
/* Serial version */
|
||||
private static final long serialVersionUID = 3007446608299169961L;
|
||||
|
||||
/**
|
||||
* Default constructor, no message put in exception.
|
||||
*/
|
||||
public InvalidRelationTypeException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given message put in exception.
|
||||
*
|
||||
* @param message the detail message.
|
||||
*/
|
||||
public InvalidRelationTypeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
/**
|
||||
* This exception is raised when, in a role info, its minimum degree is greater
|
||||
* than its maximum degree.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class InvalidRoleInfoException extends RelationException {
|
||||
|
||||
/* Serial version */
|
||||
private static final long serialVersionUID = 7517834705158932074L;
|
||||
|
||||
/**
|
||||
* Default constructor, no message put in exception.
|
||||
*/
|
||||
public InvalidRoleInfoException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given message put in exception.
|
||||
*
|
||||
* @param message the detail message.
|
||||
*/
|
||||
public InvalidRoleInfoException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
/**
|
||||
* Role value is invalid.
|
||||
* This exception is raised when, in a role, the number of referenced MBeans
|
||||
* in given value is less than expected minimum degree, or the number of
|
||||
* referenced MBeans in provided value exceeds expected maximum degree, or
|
||||
* one referenced MBean in the value is not an Object of the MBean
|
||||
* class expected for that role, or an MBean provided for that role does not
|
||||
* exist.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class InvalidRoleValueException extends RelationException {
|
||||
|
||||
/* Serial version */
|
||||
private static final long serialVersionUID = -2066091747301983721L;
|
||||
|
||||
/**
|
||||
* Default constructor, no message put in exception.
|
||||
*/
|
||||
public InvalidRoleValueException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given message put in exception.
|
||||
*
|
||||
* @param message the detail message.
|
||||
*/
|
||||
public InvalidRoleValueException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,478 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
import static com.sun.jmx.mbeanserver.Util.cast;
|
||||
import static com.sun.jmx.defaults.JmxProperties.RELATION_LOGGER;
|
||||
import com.sun.jmx.mbeanserver.GetPropertyAction;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamField;
|
||||
import java.security.AccessController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.management.MBeanServerNotification;
|
||||
|
||||
import javax.management.Notification;
|
||||
import javax.management.NotificationFilterSupport;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Filter for {@link MBeanServerNotification}.
|
||||
* This filter filters MBeanServerNotification notifications by
|
||||
* selecting the ObjectNames of interest and the operations (registration,
|
||||
* unregistration, both) of interest (corresponding to notification
|
||||
* types).
|
||||
*
|
||||
* <p>The <b>serialVersionUID</b> of this class is <code>2605900539589789736L</code>.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
@SuppressWarnings("serial") // serialVersionUID must be constant
|
||||
public class MBeanServerNotificationFilter extends NotificationFilterSupport {
|
||||
|
||||
// Serialization compatibility stuff:
|
||||
// Two serial forms are supported in this class. The selected form depends
|
||||
// on system property "jmx.serial.form":
|
||||
// - "1.0" for JMX 1.0
|
||||
// - any other value for JMX 1.1 and higher
|
||||
//
|
||||
// Serial version for old serial form
|
||||
private static final long oldSerialVersionUID = 6001782699077323605L;
|
||||
//
|
||||
// Serial version for new serial form
|
||||
private static final long newSerialVersionUID = 2605900539589789736L;
|
||||
//
|
||||
// Serializable fields in old serial form
|
||||
private static final ObjectStreamField[] oldSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("mySelectObjNameList", Vector.class),
|
||||
new ObjectStreamField("myDeselectObjNameList", Vector.class)
|
||||
};
|
||||
//
|
||||
// Serializable fields in new serial form
|
||||
private static final ObjectStreamField[] newSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("selectedNames", List.class),
|
||||
new ObjectStreamField("deselectedNames", List.class)
|
||||
};
|
||||
//
|
||||
// Actual serial version and serial form
|
||||
private static final long serialVersionUID;
|
||||
/**
|
||||
* @serialField selectedNames List List of {@link ObjectName}s of interest
|
||||
* <ul>
|
||||
* <li><code>null</code> means that all {@link ObjectName}s are implicitly selected
|
||||
* (check for explicit deselections)</li>
|
||||
* <li>Empty vector means that no {@link ObjectName} is explicitly selected</li>
|
||||
* </ul>
|
||||
* @serialField deselectedNames List List of {@link ObjectName}s with no interest
|
||||
* <ul>
|
||||
* <li><code>null</code> means that all {@link ObjectName}s are implicitly deselected
|
||||
* (check for explicit selections))</li>
|
||||
* <li>Empty vector means that no {@link ObjectName} is explicitly deselected</li>
|
||||
* </ul>
|
||||
*/
|
||||
private static final ObjectStreamField[] serialPersistentFields;
|
||||
private static boolean compat = false;
|
||||
static {
|
||||
try {
|
||||
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
|
||||
String form = AccessController.doPrivileged(act);
|
||||
compat = (form != null && form.equals("1.0"));
|
||||
} catch (Exception e) {
|
||||
// OK : Too bad, no compat with 1.0
|
||||
}
|
||||
if (compat) {
|
||||
serialPersistentFields = oldSerialPersistentFields;
|
||||
serialVersionUID = oldSerialVersionUID;
|
||||
} else {
|
||||
serialPersistentFields = newSerialPersistentFields;
|
||||
serialVersionUID = newSerialVersionUID;
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Serialization compatibility stuff
|
||||
|
||||
//
|
||||
// Private members
|
||||
//
|
||||
|
||||
/**
|
||||
* @serial List of {@link ObjectName}s of interest
|
||||
* <ul>
|
||||
* <li><code>null</code> means that all {@link ObjectName}s are implicitly selected
|
||||
* (check for explicit deselections)</li>
|
||||
* <li>Empty vector means that no {@link ObjectName} is explicitly selected</li>
|
||||
* </ul>
|
||||
*/
|
||||
private List<ObjectName> selectedNames = new Vector<ObjectName>();
|
||||
|
||||
/**
|
||||
* @serial List of {@link ObjectName}s with no interest
|
||||
* <ul>
|
||||
* <li><code>null</code> means that all {@link ObjectName}s are implicitly deselected
|
||||
* (check for explicit selections))</li>
|
||||
* <li>Empty vector means that no {@link ObjectName} is explicitly deselected</li>
|
||||
* </ul>
|
||||
*/
|
||||
private List<ObjectName> deselectedNames = null;
|
||||
|
||||
//
|
||||
// Constructor
|
||||
//
|
||||
|
||||
/**
|
||||
* Creates a filter selecting all MBeanServerNotification notifications for
|
||||
* all ObjectNames.
|
||||
*/
|
||||
public MBeanServerNotificationFilter() {
|
||||
|
||||
super();
|
||||
RELATION_LOGGER.entering(MBeanServerNotificationFilter.class.getName(),
|
||||
"MBeanServerNotificationFilter");
|
||||
|
||||
enableType(MBeanServerNotification.REGISTRATION_NOTIFICATION);
|
||||
enableType(MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
|
||||
|
||||
RELATION_LOGGER.exiting(MBeanServerNotificationFilter.class.getName(),
|
||||
"MBeanServerNotificationFilter");
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Accessors
|
||||
//
|
||||
|
||||
/**
|
||||
* Disables any MBeanServerNotification (all ObjectNames are
|
||||
* deselected).
|
||||
*/
|
||||
public synchronized void disableAllObjectNames() {
|
||||
|
||||
RELATION_LOGGER.entering(MBeanServerNotificationFilter.class.getName(),
|
||||
"disableAllObjectNames");
|
||||
|
||||
selectedNames = new Vector<ObjectName>();
|
||||
deselectedNames = null;
|
||||
|
||||
RELATION_LOGGER.exiting(MBeanServerNotificationFilter.class.getName(),
|
||||
"disableAllObjectNames");
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables MBeanServerNotifications concerning given ObjectName.
|
||||
*
|
||||
* @param objectName ObjectName no longer of interest
|
||||
*
|
||||
* @exception IllegalArgumentException if the given ObjectName is null
|
||||
*/
|
||||
public synchronized void disableObjectName(ObjectName objectName)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
if (objectName == null) {
|
||||
String excMsg = "Invalid parameter.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
RELATION_LOGGER.entering(MBeanServerNotificationFilter.class.getName(),
|
||||
"disableObjectName", objectName);
|
||||
|
||||
// Removes from selected ObjectNames, if present
|
||||
if (selectedNames != null) {
|
||||
if (selectedNames.size() != 0) {
|
||||
selectedNames.remove(objectName);
|
||||
}
|
||||
}
|
||||
|
||||
// Adds it in deselected ObjectNames
|
||||
if (deselectedNames != null) {
|
||||
// If all are deselected, no need to do anything :)
|
||||
if (!(deselectedNames.contains(objectName))) {
|
||||
// ObjectName was not already deselected
|
||||
deselectedNames.add(objectName);
|
||||
}
|
||||
}
|
||||
|
||||
RELATION_LOGGER.exiting(MBeanServerNotificationFilter.class.getName(),
|
||||
"disableObjectName");
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables all MBeanServerNotifications (all ObjectNames are selected).
|
||||
*/
|
||||
public synchronized void enableAllObjectNames() {
|
||||
|
||||
RELATION_LOGGER.entering(MBeanServerNotificationFilter.class.getName(),
|
||||
"enableAllObjectNames");
|
||||
|
||||
selectedNames = null;
|
||||
deselectedNames = new Vector<ObjectName>();
|
||||
|
||||
RELATION_LOGGER.exiting(MBeanServerNotificationFilter.class.getName(),
|
||||
"enableAllObjectNames");
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables MBeanServerNotifications concerning given ObjectName.
|
||||
*
|
||||
* @param objectName ObjectName of interest
|
||||
*
|
||||
* @exception IllegalArgumentException if the given ObjectName is null
|
||||
*/
|
||||
public synchronized void enableObjectName(ObjectName objectName)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
if (objectName == null) {
|
||||
String excMsg = "Invalid parameter.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
RELATION_LOGGER.entering(MBeanServerNotificationFilter.class.getName(),
|
||||
"enableObjectName", objectName);
|
||||
|
||||
// Removes from deselected ObjectNames, if present
|
||||
if (deselectedNames != null) {
|
||||
if (deselectedNames.size() != 0) {
|
||||
deselectedNames.remove(objectName);
|
||||
}
|
||||
}
|
||||
|
||||
// Adds it in selected ObjectNames
|
||||
if (selectedNames != null) {
|
||||
// If all are selected, no need to do anything :)
|
||||
if (!(selectedNames.contains(objectName))) {
|
||||
// ObjectName was not already selected
|
||||
selectedNames.add(objectName);
|
||||
}
|
||||
}
|
||||
|
||||
RELATION_LOGGER.exiting(MBeanServerNotificationFilter.class.getName(),
|
||||
"enableObjectName");
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the ObjectNames enabled.
|
||||
*
|
||||
* @return Vector of ObjectNames:
|
||||
* <P>- null means all ObjectNames are implicitly selected, except the
|
||||
* ObjectNames explicitly deselected
|
||||
* <P>- empty means all ObjectNames are deselected, i.e. no ObjectName
|
||||
* selected.
|
||||
*/
|
||||
public synchronized Vector<ObjectName> getEnabledObjectNames() {
|
||||
if (selectedNames != null) {
|
||||
return new Vector<ObjectName>(selectedNames);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the ObjectNames disabled.
|
||||
*
|
||||
* @return Vector of ObjectNames:
|
||||
* <P>- null means all ObjectNames are implicitly deselected, except the
|
||||
* ObjectNames explicitly selected
|
||||
* <P>- empty means all ObjectNames are selected, i.e. no ObjectName
|
||||
* deselected.
|
||||
*/
|
||||
public synchronized Vector<ObjectName> getDisabledObjectNames() {
|
||||
if (deselectedNames != null) {
|
||||
return new Vector<ObjectName>(deselectedNames);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// NotificationFilter interface
|
||||
//
|
||||
|
||||
/**
|
||||
* Invoked before sending the specified notification to the listener.
|
||||
* <P>If:
|
||||
* <P>- the ObjectName of the concerned MBean is selected (explicitly OR
|
||||
* (implicitly and not explicitly deselected))
|
||||
* <P>AND
|
||||
* <P>- the type of the operation (registration or unregistration) is
|
||||
* selected
|
||||
* <P>then the notification is sent to the listener.
|
||||
*
|
||||
* @param notif The notification to be sent.
|
||||
*
|
||||
* @return true if the notification has to be sent to the listener, false
|
||||
* otherwise.
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
*/
|
||||
public synchronized boolean isNotificationEnabled(Notification notif)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
if (notif == null) {
|
||||
String excMsg = "Invalid parameter.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
RELATION_LOGGER.entering(MBeanServerNotificationFilter.class.getName(),
|
||||
"isNotificationEnabled", notif);
|
||||
|
||||
// Checks the type first
|
||||
String ntfType = notif.getType();
|
||||
Vector<String> enabledTypes = getEnabledTypes();
|
||||
if (!(enabledTypes.contains(ntfType))) {
|
||||
RELATION_LOGGER.logp(Level.FINER,
|
||||
MBeanServerNotificationFilter.class.getName(),
|
||||
"isNotificationEnabled",
|
||||
"Type not selected, exiting");
|
||||
return false;
|
||||
}
|
||||
|
||||
// We have a MBeanServerNotification: downcasts it
|
||||
MBeanServerNotification mbsNtf = (MBeanServerNotification)notif;
|
||||
|
||||
// Checks the ObjectName
|
||||
ObjectName objName = mbsNtf.getMBeanName();
|
||||
// Is it selected?
|
||||
boolean isSelectedFlg = false;
|
||||
if (selectedNames != null) {
|
||||
// Not all are implicitly selected:
|
||||
// checks for explicit selection
|
||||
if (selectedNames.size() == 0) {
|
||||
// All are explicitly not selected
|
||||
RELATION_LOGGER.logp(Level.FINER,
|
||||
MBeanServerNotificationFilter.class.getName(),
|
||||
"isNotificationEnabled",
|
||||
"No ObjectNames selected, exiting");
|
||||
return false;
|
||||
}
|
||||
|
||||
isSelectedFlg = selectedNames.contains(objName);
|
||||
if (!isSelectedFlg) {
|
||||
// Not in the explicit selected list
|
||||
RELATION_LOGGER.logp(Level.FINER,
|
||||
MBeanServerNotificationFilter.class.getName(),
|
||||
"isNotificationEnabled",
|
||||
"ObjectName not in selected list, exiting");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isSelectedFlg) {
|
||||
// Not explicitly selected: is it deselected?
|
||||
|
||||
if (deselectedNames == null) {
|
||||
// All are implicitly deselected and it is not explicitly
|
||||
// selected
|
||||
RELATION_LOGGER.logp(Level.FINER,
|
||||
MBeanServerNotificationFilter.class.getName(),
|
||||
"isNotificationEnabled",
|
||||
"ObjectName not selected, and all " +
|
||||
"names deselected, exiting");
|
||||
return false;
|
||||
|
||||
} else if (deselectedNames.contains(objName)) {
|
||||
// Explicitly deselected
|
||||
RELATION_LOGGER.logp(Level.FINER,
|
||||
MBeanServerNotificationFilter.class.getName(),
|
||||
"isNotificationEnabled",
|
||||
"ObjectName explicitly not selected, exiting");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
RELATION_LOGGER.logp(Level.FINER,
|
||||
MBeanServerNotificationFilter.class.getName(),
|
||||
"isNotificationEnabled",
|
||||
"ObjectName selected, exiting");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes an {@link MBeanServerNotificationFilter} from an {@link ObjectInputStream}.
|
||||
*/
|
||||
private void readObject(ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException {
|
||||
if (compat)
|
||||
{
|
||||
// Read an object serialized in the old serial form
|
||||
//
|
||||
ObjectInputStream.GetField fields = in.readFields();
|
||||
selectedNames = cast(fields.get("mySelectObjNameList", null));
|
||||
if (fields.defaulted("mySelectObjNameList"))
|
||||
{
|
||||
throw new NullPointerException("mySelectObjNameList");
|
||||
}
|
||||
deselectedNames = cast(fields.get("myDeselectObjNameList", null));
|
||||
if (fields.defaulted("myDeselectObjNameList"))
|
||||
{
|
||||
throw new NullPointerException("myDeselectObjNameList");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Read an object serialized in the new serial form
|
||||
//
|
||||
in.defaultReadObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serializes an {@link MBeanServerNotificationFilter} to an {@link ObjectOutputStream}.
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream out)
|
||||
throws IOException {
|
||||
if (compat)
|
||||
{
|
||||
// Serializes this instance in the old serial form
|
||||
//
|
||||
ObjectOutputStream.PutField fields = out.putFields();
|
||||
fields.put("mySelectObjNameList", selectedNames);
|
||||
fields.put("myDeselectObjNameList", deselectedNames);
|
||||
out.writeFields();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Serializes this instance in the new serial form
|
||||
//
|
||||
out.defaultWriteObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
264
jdkSrc/jdk8/javax/management/relation/Relation.java
Normal file
264
jdkSrc/jdk8/javax/management/relation/Relation.java
Normal file
@@ -0,0 +1,264 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.management.ObjectName;
|
||||
|
||||
/**
|
||||
* This interface has to be implemented by any MBean class expected to
|
||||
* represent a relation managed using the Relation Service.
|
||||
* <P>Simple relations, i.e. having only roles, no properties or methods, can
|
||||
* be created directly by the Relation Service (represented as RelationSupport
|
||||
* objects, internally handled by the Relation Service).
|
||||
* <P>If the user wants to represent more complex relations, involving
|
||||
* properties and/or methods, he has to provide his own class implementing the
|
||||
* Relation interface. This can be achieved either by inheriting from
|
||||
* RelationSupport class, or by implementing the interface (fully or delegation to
|
||||
* a RelationSupport object member).
|
||||
* <P>Specifying such user relation class is to introduce properties and/or
|
||||
* methods. Those have to be exposed for remote management. So this means that
|
||||
* any user relation class must be a MBean class.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public interface Relation {
|
||||
|
||||
/**
|
||||
* Retrieves role value for given role name.
|
||||
* <P>Checks if the role exists and is readable according to the relation
|
||||
* type.
|
||||
*
|
||||
* @param roleName name of role
|
||||
*
|
||||
* @return the ArrayList of ObjectName objects being the role value
|
||||
*
|
||||
* @exception IllegalArgumentException if null role name
|
||||
* @exception RoleNotFoundException if:
|
||||
* <P>- there is no role with given name
|
||||
* <P>- the role is not readable.
|
||||
* @exception RelationServiceNotRegisteredException if the Relation
|
||||
* Service is not registered in the MBean Server
|
||||
*
|
||||
* @see #setRole
|
||||
*/
|
||||
public List<ObjectName> getRole(String roleName)
|
||||
throws IllegalArgumentException,
|
||||
RoleNotFoundException,
|
||||
RelationServiceNotRegisteredException;
|
||||
|
||||
/**
|
||||
* Retrieves values of roles with given names.
|
||||
* <P>Checks for each role if it exists and is readable according to the
|
||||
* relation type.
|
||||
*
|
||||
* @param roleNameArray array of names of roles to be retrieved
|
||||
*
|
||||
* @return a RoleResult object, including a RoleList (for roles
|
||||
* successfully retrieved) and a RoleUnresolvedList (for roles not
|
||||
* retrieved).
|
||||
*
|
||||
* @exception IllegalArgumentException if null role name
|
||||
* @exception RelationServiceNotRegisteredException if the Relation
|
||||
* Service is not registered in the MBean Server
|
||||
*
|
||||
* @see #setRoles
|
||||
*/
|
||||
public RoleResult getRoles(String[] roleNameArray)
|
||||
throws IllegalArgumentException,
|
||||
RelationServiceNotRegisteredException;
|
||||
|
||||
/**
|
||||
* Returns the number of MBeans currently referenced in the given role.
|
||||
*
|
||||
* @param roleName name of role
|
||||
*
|
||||
* @return the number of currently referenced MBeans in that role
|
||||
*
|
||||
* @exception IllegalArgumentException if null role name
|
||||
* @exception RoleNotFoundException if there is no role with given name
|
||||
*/
|
||||
public Integer getRoleCardinality(String roleName)
|
||||
throws IllegalArgumentException,
|
||||
RoleNotFoundException;
|
||||
|
||||
/**
|
||||
* Returns all roles present in the relation.
|
||||
*
|
||||
* @return a RoleResult object, including a RoleList (for roles
|
||||
* successfully retrieved) and a RoleUnresolvedList (for roles not
|
||||
* readable).
|
||||
*
|
||||
* @exception RelationServiceNotRegisteredException if the Relation
|
||||
* Service is not registered in the MBean Server
|
||||
*/
|
||||
public RoleResult getAllRoles()
|
||||
throws RelationServiceNotRegisteredException;
|
||||
|
||||
/**
|
||||
* Returns all roles in the relation without checking read mode.
|
||||
*
|
||||
* @return a RoleList.
|
||||
*/
|
||||
public RoleList retrieveAllRoles();
|
||||
|
||||
/**
|
||||
* Sets the given role.
|
||||
* <P>Will check the role according to its corresponding role definition
|
||||
* provided in relation's relation type
|
||||
* <P>Will send a notification (RelationNotification with type
|
||||
* RELATION_BASIC_UPDATE or RELATION_MBEAN_UPDATE, depending if the
|
||||
* relation is a MBean or not).
|
||||
*
|
||||
* @param role role to be set (name and new value)
|
||||
*
|
||||
* @exception IllegalArgumentException if null role
|
||||
* @exception RoleNotFoundException if there is no role with the supplied
|
||||
* role's name or if the role is not writable (no test on the write access
|
||||
* mode performed when initializing the role)
|
||||
* @exception InvalidRoleValueException if value provided for
|
||||
* role is not valid, i.e.:
|
||||
* <P>- the number of referenced MBeans in given value is less than
|
||||
* expected minimum degree
|
||||
* <P>- the number of referenced MBeans in provided value exceeds expected
|
||||
* maximum degree
|
||||
* <P>- one referenced MBean in the value is not an Object of the MBean
|
||||
* class expected for that role
|
||||
* <P>- a MBean provided for that role does not exist.
|
||||
* @exception RelationServiceNotRegisteredException if the Relation
|
||||
* Service is not registered in the MBean Server
|
||||
* @exception RelationTypeNotFoundException if the relation type has not
|
||||
* been declared in the Relation Service.
|
||||
* @exception RelationNotFoundException if the relation has not been
|
||||
* added in the Relation Service.
|
||||
*
|
||||
* @see #getRole
|
||||
*/
|
||||
public void setRole(Role role)
|
||||
throws IllegalArgumentException,
|
||||
RoleNotFoundException,
|
||||
RelationTypeNotFoundException,
|
||||
InvalidRoleValueException,
|
||||
RelationServiceNotRegisteredException,
|
||||
RelationNotFoundException;
|
||||
|
||||
/**
|
||||
* Sets the given roles.
|
||||
* <P>Will check the role according to its corresponding role definition
|
||||
* provided in relation's relation type
|
||||
* <P>Will send one notification (RelationNotification with type
|
||||
* RELATION_BASIC_UPDATE or RELATION_MBEAN_UPDATE, depending if the
|
||||
* relation is a MBean or not) per updated role.
|
||||
*
|
||||
* @param roleList list of roles to be set
|
||||
*
|
||||
* @return a RoleResult object, including a RoleList (for roles
|
||||
* successfully set) and a RoleUnresolvedList (for roles not
|
||||
* set).
|
||||
*
|
||||
* @exception IllegalArgumentException if null role list
|
||||
* @exception RelationServiceNotRegisteredException if the Relation
|
||||
* Service is not registered in the MBean Server
|
||||
* @exception RelationTypeNotFoundException if the relation type has not
|
||||
* been declared in the Relation Service.
|
||||
* @exception RelationNotFoundException if the relation MBean has not been
|
||||
* added in the Relation Service.
|
||||
*
|
||||
* @see #getRoles
|
||||
*/
|
||||
public RoleResult setRoles(RoleList roleList)
|
||||
throws IllegalArgumentException,
|
||||
RelationServiceNotRegisteredException,
|
||||
RelationTypeNotFoundException,
|
||||
RelationNotFoundException;
|
||||
|
||||
/**
|
||||
* Callback used by the Relation Service when a MBean referenced in a role
|
||||
* is unregistered.
|
||||
* <P>The Relation Service will call this method to let the relation
|
||||
* take action to reflect the impact of such unregistration.
|
||||
* <P>BEWARE. the user is not expected to call this method.
|
||||
* <P>Current implementation is to set the role with its current value
|
||||
* (list of ObjectNames of referenced MBeans) without the unregistered
|
||||
* one.
|
||||
*
|
||||
* @param objectName ObjectName of unregistered MBean
|
||||
* @param roleName name of role where the MBean is referenced
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RoleNotFoundException if role does not exist in the
|
||||
* relation or is not writable
|
||||
* @exception InvalidRoleValueException if role value does not conform to
|
||||
* the associated role info (this will never happen when called from the
|
||||
* Relation Service)
|
||||
* @exception RelationServiceNotRegisteredException if the Relation
|
||||
* Service is not registered in the MBean Server
|
||||
* @exception RelationTypeNotFoundException if the relation type has not
|
||||
* been declared in the Relation Service.
|
||||
* @exception RelationNotFoundException if this method is called for a
|
||||
* relation MBean not added in the Relation Service.
|
||||
*/
|
||||
public void handleMBeanUnregistration(ObjectName objectName,
|
||||
String roleName)
|
||||
throws IllegalArgumentException,
|
||||
RoleNotFoundException,
|
||||
InvalidRoleValueException,
|
||||
RelationServiceNotRegisteredException,
|
||||
RelationTypeNotFoundException,
|
||||
RelationNotFoundException;
|
||||
|
||||
/**
|
||||
* Retrieves MBeans referenced in the various roles of the relation.
|
||||
*
|
||||
* @return a HashMap mapping:
|
||||
* <P> ObjectName {@literal ->} ArrayList of String (role names)
|
||||
*/
|
||||
public Map<ObjectName,List<String>> getReferencedMBeans();
|
||||
|
||||
/**
|
||||
* Returns name of associated relation type.
|
||||
*
|
||||
* @return the name of the relation type.
|
||||
*/
|
||||
public String getRelationTypeName();
|
||||
|
||||
/**
|
||||
* Returns ObjectName of the Relation Service handling the relation.
|
||||
*
|
||||
* @return the ObjectName of the Relation Service.
|
||||
*/
|
||||
public ObjectName getRelationServiceName();
|
||||
|
||||
/**
|
||||
* Returns relation identifier (used to uniquely identify the relation
|
||||
* inside the Relation Service).
|
||||
*
|
||||
* @return the relation id.
|
||||
*/
|
||||
public String getRelationId();
|
||||
}
|
||||
56
jdkSrc/jdk8/javax/management/relation/RelationException.java
Normal file
56
jdkSrc/jdk8/javax/management/relation/RelationException.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
import javax.management.JMException;
|
||||
|
||||
/**
|
||||
* This class is the superclass of any exception which can be raised during
|
||||
* relation management.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class RelationException extends JMException {
|
||||
|
||||
/* Serial version */
|
||||
private static final long serialVersionUID = 5434016005679159613L;
|
||||
|
||||
/**
|
||||
* Default constructor, no message put in exception.
|
||||
*/
|
||||
public RelationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given message put in exception.
|
||||
*
|
||||
* @param message the detail message.
|
||||
*/
|
||||
public RelationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
/**
|
||||
* This exception is raised when there is no relation for a given relation id
|
||||
* in a Relation Service.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class RelationNotFoundException extends RelationException {
|
||||
|
||||
/* Serial version */
|
||||
private static final long serialVersionUID = -3793951411158559116L;
|
||||
|
||||
/**
|
||||
* Default constructor, no message put in exception.
|
||||
*/
|
||||
public RelationNotFoundException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given message put in exception.
|
||||
*
|
||||
* @param message the detail message.
|
||||
*/
|
||||
public RelationNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
615
jdkSrc/jdk8/javax/management/relation/RelationNotification.java
Normal file
615
jdkSrc/jdk8/javax/management/relation/RelationNotification.java
Normal file
@@ -0,0 +1,615 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
import javax.management.Notification;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import java.io.InvalidObjectException;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamField;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sun.jmx.mbeanserver.GetPropertyAction;
|
||||
import static com.sun.jmx.mbeanserver.Util.cast;
|
||||
|
||||
/**
|
||||
* A notification of a change in the Relation Service.
|
||||
* A RelationNotification notification is sent when a relation is created via
|
||||
* the Relation Service, or an MBean is added as a relation in the Relation
|
||||
* Service, or a role is updated in a relation, or a relation is removed from
|
||||
* the Relation Service.
|
||||
*
|
||||
* <p>The <b>serialVersionUID</b> of this class is <code>-6871117877523310399L</code>.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
@SuppressWarnings("serial") // serialVersionUID not constant
|
||||
public class RelationNotification extends Notification {
|
||||
|
||||
// Serialization compatibility stuff:
|
||||
// Two serial forms are supported in this class. The selected form depends
|
||||
// on system property "jmx.serial.form":
|
||||
// - "1.0" for JMX 1.0
|
||||
// - any other value for JMX 1.1 and higher
|
||||
//
|
||||
// Serial version for old serial form
|
||||
private static final long oldSerialVersionUID = -2126464566505527147L;
|
||||
//
|
||||
// Serial version for new serial form
|
||||
private static final long newSerialVersionUID = -6871117877523310399L;
|
||||
//
|
||||
// Serializable fields in old serial form
|
||||
private static final ObjectStreamField[] oldSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("myNewRoleValue", ArrayList.class),
|
||||
new ObjectStreamField("myOldRoleValue", ArrayList.class),
|
||||
new ObjectStreamField("myRelId", String.class),
|
||||
new ObjectStreamField("myRelObjName", ObjectName.class),
|
||||
new ObjectStreamField("myRelTypeName", String.class),
|
||||
new ObjectStreamField("myRoleName", String.class),
|
||||
new ObjectStreamField("myUnregMBeanList", ArrayList.class)
|
||||
};
|
||||
//
|
||||
// Serializable fields in new serial form
|
||||
private static final ObjectStreamField[] newSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("newRoleValue", List.class),
|
||||
new ObjectStreamField("oldRoleValue", List.class),
|
||||
new ObjectStreamField("relationId", String.class),
|
||||
new ObjectStreamField("relationObjName", ObjectName.class),
|
||||
new ObjectStreamField("relationTypeName", String.class),
|
||||
new ObjectStreamField("roleName", String.class),
|
||||
new ObjectStreamField("unregisterMBeanList", List.class)
|
||||
};
|
||||
//
|
||||
// Actual serial version and serial form
|
||||
private static final long serialVersionUID;
|
||||
/**
|
||||
* @serialField relationId String Relation identifier of
|
||||
* created/removed/updated relation
|
||||
* @serialField relationTypeName String Relation type name of
|
||||
* created/removed/updated relation
|
||||
* @serialField relationObjName ObjectName {@link ObjectName} of
|
||||
* the relation MBean of created/removed/updated relation (only if
|
||||
* the relation is represented by an MBean)
|
||||
* @serialField unregisterMBeanList List List of {@link
|
||||
* ObjectName}s of referenced MBeans to be unregistered due to
|
||||
* relation removal
|
||||
* @serialField roleName String Name of updated role (only for role update)
|
||||
* @serialField oldRoleValue List Old role value ({@link
|
||||
* ArrayList} of {@link ObjectName}s) (only for role update)
|
||||
* @serialField newRoleValue List New role value ({@link
|
||||
* ArrayList} of {@link ObjectName}s) (only for role update)
|
||||
*/
|
||||
private static final ObjectStreamField[] serialPersistentFields;
|
||||
private static boolean compat = false;
|
||||
static {
|
||||
try {
|
||||
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
|
||||
String form = AccessController.doPrivileged(act);
|
||||
compat = (form != null && form.equals("1.0"));
|
||||
} catch (Exception e) {
|
||||
// OK : Too bad, no compat with 1.0
|
||||
}
|
||||
if (compat) {
|
||||
serialPersistentFields = oldSerialPersistentFields;
|
||||
serialVersionUID = oldSerialVersionUID;
|
||||
} else {
|
||||
serialPersistentFields = newSerialPersistentFields;
|
||||
serialVersionUID = newSerialVersionUID;
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Serialization compatibility stuff
|
||||
|
||||
//
|
||||
// Notification types
|
||||
//
|
||||
|
||||
/**
|
||||
* Type for the creation of an internal relation.
|
||||
*/
|
||||
public static final String RELATION_BASIC_CREATION = "jmx.relation.creation.basic";
|
||||
/**
|
||||
* Type for the relation MBean added into the Relation Service.
|
||||
*/
|
||||
public static final String RELATION_MBEAN_CREATION = "jmx.relation.creation.mbean";
|
||||
/**
|
||||
* Type for an update of an internal relation.
|
||||
*/
|
||||
public static final String RELATION_BASIC_UPDATE = "jmx.relation.update.basic";
|
||||
/**
|
||||
* Type for the update of a relation MBean.
|
||||
*/
|
||||
public static final String RELATION_MBEAN_UPDATE = "jmx.relation.update.mbean";
|
||||
/**
|
||||
* Type for the removal from the Relation Service of an internal relation.
|
||||
*/
|
||||
public static final String RELATION_BASIC_REMOVAL = "jmx.relation.removal.basic";
|
||||
/**
|
||||
* Type for the removal from the Relation Service of a relation MBean.
|
||||
*/
|
||||
public static final String RELATION_MBEAN_REMOVAL = "jmx.relation.removal.mbean";
|
||||
|
||||
//
|
||||
// Private members
|
||||
//
|
||||
|
||||
/**
|
||||
* @serial Relation identifier of created/removed/updated relation
|
||||
*/
|
||||
private String relationId = null;
|
||||
|
||||
/**
|
||||
* @serial Relation type name of created/removed/updated relation
|
||||
*/
|
||||
private String relationTypeName = null;
|
||||
|
||||
/**
|
||||
* @serial {@link ObjectName} of the relation MBean of created/removed/updated relation
|
||||
* (only if the relation is represented by an MBean)
|
||||
*/
|
||||
private ObjectName relationObjName = null;
|
||||
|
||||
/**
|
||||
* @serial List of {@link ObjectName}s of referenced MBeans to be unregistered due to
|
||||
* relation removal
|
||||
*/
|
||||
private List<ObjectName> unregisterMBeanList = null;
|
||||
|
||||
/**
|
||||
* @serial Name of updated role (only for role update)
|
||||
*/
|
||||
private String roleName = null;
|
||||
|
||||
/**
|
||||
* @serial Old role value ({@link ArrayList} of {@link ObjectName}s) (only for role update)
|
||||
*/
|
||||
private List<ObjectName> oldRoleValue = null;
|
||||
|
||||
/**
|
||||
* @serial New role value ({@link ArrayList} of {@link ObjectName}s) (only for role update)
|
||||
*/
|
||||
private List<ObjectName> newRoleValue = null;
|
||||
|
||||
//
|
||||
// Constructors
|
||||
//
|
||||
|
||||
/**
|
||||
* Creates a notification for either a relation creation (RelationSupport
|
||||
* object created internally in the Relation Service, or an MBean added as a
|
||||
* relation) or for a relation removal from the Relation Service.
|
||||
*
|
||||
* @param notifType type of the notification; either:
|
||||
* <P>- RELATION_BASIC_CREATION
|
||||
* <P>- RELATION_MBEAN_CREATION
|
||||
* <P>- RELATION_BASIC_REMOVAL
|
||||
* <P>- RELATION_MBEAN_REMOVAL
|
||||
* @param sourceObj source object, sending the notification. This is either
|
||||
* an ObjectName or a RelationService object. In the latter case it must be
|
||||
* the MBean emitting the notification; the MBean Server will rewrite the
|
||||
* source to be the ObjectName under which that MBean is registered.
|
||||
* @param sequence sequence number to identify the notification
|
||||
* @param timeStamp time stamp
|
||||
* @param message human-readable message describing the notification
|
||||
* @param id relation id identifying the relation in the Relation
|
||||
* Service
|
||||
* @param typeName name of the relation type
|
||||
* @param objectName ObjectName of the relation object if it is an MBean
|
||||
* (null for relations internally handled by the Relation Service)
|
||||
* @param unregMBeanList list of ObjectNames of referenced MBeans
|
||||
* expected to be unregistered due to relation removal (only for removal,
|
||||
* due to CIM qualifiers, can be null)
|
||||
*
|
||||
* @exception IllegalArgumentException if:
|
||||
* <P>- no value for the notification type
|
||||
* <P>- the notification type is not RELATION_BASIC_CREATION,
|
||||
* RELATION_MBEAN_CREATION, RELATION_BASIC_REMOVAL or
|
||||
* RELATION_MBEAN_REMOVAL
|
||||
* <P>- no source object
|
||||
* <P>- the source object is not a Relation Service
|
||||
* <P>- no relation id
|
||||
* <P>- no relation type name
|
||||
*/
|
||||
public RelationNotification(String notifType,
|
||||
Object sourceObj,
|
||||
long sequence,
|
||||
long timeStamp,
|
||||
String message,
|
||||
String id,
|
||||
String typeName,
|
||||
ObjectName objectName,
|
||||
List<ObjectName> unregMBeanList)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
super(notifType, sourceObj, sequence, timeStamp, message);
|
||||
|
||||
if (!isValidBasicStrict(notifType,sourceObj,id,typeName) || !isValidCreate(notifType)) {
|
||||
throw new IllegalArgumentException("Invalid parameter.");
|
||||
}
|
||||
|
||||
relationId = id;
|
||||
relationTypeName = typeName;
|
||||
relationObjName = safeGetObjectName(objectName);
|
||||
unregisterMBeanList = safeGetObjectNameList(unregMBeanList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a notification for a role update in a relation.
|
||||
*
|
||||
* @param notifType type of the notification; either:
|
||||
* <P>- RELATION_BASIC_UPDATE
|
||||
* <P>- RELATION_MBEAN_UPDATE
|
||||
* @param sourceObj source object, sending the notification. This is either
|
||||
* an ObjectName or a RelationService object. In the latter case it must be
|
||||
* the MBean emitting the notification; the MBean Server will rewrite the
|
||||
* source to be the ObjectName under which that MBean is registered.
|
||||
* @param sequence sequence number to identify the notification
|
||||
* @param timeStamp time stamp
|
||||
* @param message human-readable message describing the notification
|
||||
* @param id relation id identifying the relation in the Relation
|
||||
* Service
|
||||
* @param typeName name of the relation type
|
||||
* @param objectName ObjectName of the relation object if it is an MBean
|
||||
* (null for relations internally handled by the Relation Service)
|
||||
* @param name name of the updated role
|
||||
* @param newValue new role value (List of ObjectName objects)
|
||||
* @param oldValue old role value (List of ObjectName objects)
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
*/
|
||||
public RelationNotification(String notifType,
|
||||
Object sourceObj,
|
||||
long sequence,
|
||||
long timeStamp,
|
||||
String message,
|
||||
String id,
|
||||
String typeName,
|
||||
ObjectName objectName,
|
||||
String name,
|
||||
List<ObjectName> newValue,
|
||||
List<ObjectName> oldValue
|
||||
)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
super(notifType, sourceObj, sequence, timeStamp, message);
|
||||
|
||||
if (!isValidBasicStrict(notifType,sourceObj,id,typeName) || !isValidUpdate(notifType,name,newValue,oldValue)) {
|
||||
throw new IllegalArgumentException("Invalid parameter.");
|
||||
}
|
||||
|
||||
relationId = id;
|
||||
relationTypeName = typeName;
|
||||
relationObjName = safeGetObjectName(objectName);
|
||||
|
||||
roleName = name;
|
||||
oldRoleValue = safeGetObjectNameList(oldValue);
|
||||
newRoleValue = safeGetObjectNameList(newValue);
|
||||
}
|
||||
|
||||
//
|
||||
// Accessors
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns the relation identifier of created/removed/updated relation.
|
||||
*
|
||||
* @return the relation id.
|
||||
*/
|
||||
public String getRelationId() {
|
||||
return relationId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the relation type name of created/removed/updated relation.
|
||||
*
|
||||
* @return the relation type name.
|
||||
*/
|
||||
public String getRelationTypeName() {
|
||||
return relationTypeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ObjectName of the
|
||||
* created/removed/updated relation.
|
||||
*
|
||||
* @return the ObjectName if the relation is an MBean, otherwise null.
|
||||
*/
|
||||
public ObjectName getObjectName() {
|
||||
return relationObjName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of ObjectNames of MBeans expected to be unregistered
|
||||
* due to a relation removal (only for relation removal).
|
||||
*
|
||||
* @return a {@link List} of {@link ObjectName}.
|
||||
*/
|
||||
public List<ObjectName> getMBeansToUnregister() {
|
||||
List<ObjectName> result;
|
||||
if (unregisterMBeanList != null) {
|
||||
result = new ArrayList<ObjectName>(unregisterMBeanList);
|
||||
} else {
|
||||
result = Collections.emptyList();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns name of updated role of updated relation (only for role update).
|
||||
*
|
||||
* @return the name of the updated role.
|
||||
*/
|
||||
public String getRoleName() {
|
||||
String result = null;
|
||||
if (roleName != null) {
|
||||
result = roleName;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns old value of updated role (only for role update).
|
||||
*
|
||||
* @return the old value of the updated role.
|
||||
*/
|
||||
public List<ObjectName> getOldRoleValue() {
|
||||
List<ObjectName> result;
|
||||
if (oldRoleValue != null) {
|
||||
result = new ArrayList<ObjectName>(oldRoleValue);
|
||||
} else {
|
||||
result = Collections.emptyList();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new value of updated role (only for role update).
|
||||
*
|
||||
* @return the new value of the updated role.
|
||||
*/
|
||||
public List<ObjectName> getNewRoleValue() {
|
||||
List<ObjectName> result;
|
||||
if (newRoleValue != null) {
|
||||
result = new ArrayList<ObjectName>(newRoleValue);
|
||||
} else {
|
||||
result = Collections.emptyList();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Misc
|
||||
//
|
||||
|
||||
// Initializes members
|
||||
//
|
||||
// -param notifKind 1 for creation/removal, 2 for update
|
||||
// -param notifType type of the notification; either:
|
||||
// - RELATION_BASIC_UPDATE
|
||||
// - RELATION_MBEAN_UPDATE
|
||||
// for an update, or:
|
||||
// - RELATION_BASIC_CREATION
|
||||
// - RELATION_MBEAN_CREATION
|
||||
// - RELATION_BASIC_REMOVAL
|
||||
// - RELATION_MBEAN_REMOVAL
|
||||
// for a creation or removal
|
||||
// -param sourceObj source object, sending the notification. Will always
|
||||
// be a RelationService object.
|
||||
// -param sequence sequence number to identify the notification
|
||||
// -param timeStamp time stamp
|
||||
// -param message human-readable message describing the notification
|
||||
// -param id relation id identifying the relation in the Relation
|
||||
// Service
|
||||
// -param typeName name of the relation type
|
||||
// -param objectName ObjectName of the relation object if it is an MBean
|
||||
// (null for relations internally handled by the Relation Service)
|
||||
// -param unregMBeanList list of ObjectNames of MBeans expected to be
|
||||
// removed due to relation removal
|
||||
// -param name name of the updated role
|
||||
// -param newValue new value (List of ObjectName objects)
|
||||
// -param oldValue old value (List of ObjectName objects)
|
||||
//
|
||||
// -exception IllegalArgumentException if:
|
||||
// - no value for the notification type
|
||||
// - incorrect notification type
|
||||
// - no source object
|
||||
// - the source object is not a Relation Service
|
||||
// - no relation id
|
||||
// - no relation type name
|
||||
// - no role name (for role update)
|
||||
// - no role old value (for role update)
|
||||
// - no role new value (for role update)
|
||||
|
||||
// Despite the fact, that validation in constructor of RelationNotification prohibit
|
||||
// creation of the class instance with null sourceObj its possible to set it to null later
|
||||
// by public setSource() method.
|
||||
// So we should relax validation rules to preserve serialization behavior compatibility.
|
||||
|
||||
private boolean isValidBasicStrict(String notifType, Object sourceObj, String id, String typeName){
|
||||
if (sourceObj == null) {
|
||||
return false;
|
||||
}
|
||||
return isValidBasic(notifType,sourceObj,id,typeName);
|
||||
}
|
||||
|
||||
private boolean isValidBasic(String notifType, Object sourceObj, String id, String typeName){
|
||||
if (notifType == null || id == null || typeName == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sourceObj != null && (
|
||||
!(sourceObj instanceof RelationService) &&
|
||||
!(sourceObj instanceof ObjectName))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isValidCreate(String notifType) {
|
||||
String[] validTypes= {RelationNotification.RELATION_BASIC_CREATION,
|
||||
RelationNotification.RELATION_MBEAN_CREATION,
|
||||
RelationNotification.RELATION_BASIC_REMOVAL,
|
||||
RelationNotification.RELATION_MBEAN_REMOVAL};
|
||||
|
||||
Set<String> ctSet = new HashSet<String>(Arrays.asList(validTypes));
|
||||
return ctSet.contains(notifType);
|
||||
}
|
||||
|
||||
private boolean isValidUpdate(String notifType, String name,
|
||||
List<ObjectName> newValue, List<ObjectName> oldValue) {
|
||||
|
||||
if (!(notifType.equals(RelationNotification.RELATION_BASIC_UPDATE)) &&
|
||||
!(notifType.equals(RelationNotification.RELATION_MBEAN_UPDATE))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (name == null || oldValue == null || newValue == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private ArrayList<ObjectName> safeGetObjectNameList(List<ObjectName> src){
|
||||
ArrayList<ObjectName> dest = null;
|
||||
if (src != null) {
|
||||
dest = new ArrayList<ObjectName>();
|
||||
for (ObjectName item : src) {
|
||||
// NPE thrown if we attempt to add null object
|
||||
dest.add(ObjectName.getInstance(item));
|
||||
}
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
private ObjectName safeGetObjectName(ObjectName src){
|
||||
ObjectName dest = null;
|
||||
if (src != null) {
|
||||
dest = ObjectName.getInstance(src);
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a {@link RelationNotification} from an {@link ObjectInputStream}.
|
||||
*/
|
||||
private void readObject(ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException {
|
||||
|
||||
String tmpRelationId, tmpRelationTypeName, tmpRoleName;
|
||||
|
||||
ObjectName tmpRelationObjName;
|
||||
List<ObjectName> tmpNewRoleValue, tmpOldRoleValue, tmpUnregMBeanList;
|
||||
|
||||
ObjectInputStream.GetField fields = in.readFields();
|
||||
|
||||
if (compat) {
|
||||
tmpRelationId = (String)fields.get("myRelId", null);
|
||||
tmpRelationTypeName = (String)fields.get("myRelTypeName", null);
|
||||
tmpRoleName = (String)fields.get("myRoleName", null);
|
||||
|
||||
tmpRelationObjName = (ObjectName)fields.get("myRelObjName", null);
|
||||
tmpNewRoleValue = cast(fields.get("myNewRoleValue", null));
|
||||
tmpOldRoleValue = cast(fields.get("myOldRoleValue", null));
|
||||
tmpUnregMBeanList = cast(fields.get("myUnregMBeanList", null));
|
||||
}
|
||||
else {
|
||||
tmpRelationId = (String)fields.get("relationId", null);
|
||||
tmpRelationTypeName = (String)fields.get("relationTypeName", null);
|
||||
tmpRoleName = (String)fields.get("roleName", null);
|
||||
|
||||
tmpRelationObjName = (ObjectName)fields.get("relationObjName", null);
|
||||
tmpNewRoleValue = cast(fields.get("newRoleValue", null));
|
||||
tmpOldRoleValue = cast(fields.get("oldRoleValue", null));
|
||||
tmpUnregMBeanList = cast(fields.get("unregisterMBeanList", null));
|
||||
}
|
||||
|
||||
// Validate fields we just read, throw InvalidObjectException
|
||||
// if something goes wrong
|
||||
|
||||
String notifType = super.getType();
|
||||
if (!isValidBasic(notifType,super.getSource(),tmpRelationId,tmpRelationTypeName) ||
|
||||
(!isValidCreate(notifType) &&
|
||||
!isValidUpdate(notifType,tmpRoleName,tmpNewRoleValue,tmpOldRoleValue))) {
|
||||
|
||||
super.setSource(null);
|
||||
throw new InvalidObjectException("Invalid object read");
|
||||
}
|
||||
|
||||
// assign deserialized vaules to object fields
|
||||
relationObjName = safeGetObjectName(tmpRelationObjName);
|
||||
newRoleValue = safeGetObjectNameList(tmpNewRoleValue);
|
||||
oldRoleValue = safeGetObjectNameList(tmpOldRoleValue);
|
||||
unregisterMBeanList = safeGetObjectNameList(tmpUnregMBeanList);
|
||||
|
||||
relationId = tmpRelationId;
|
||||
relationTypeName = tmpRelationTypeName;
|
||||
roleName = tmpRoleName;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serializes a {@link RelationNotification} to an {@link ObjectOutputStream}.
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream out)
|
||||
throws IOException {
|
||||
if (compat)
|
||||
{
|
||||
// Serializes this instance in the old serial form
|
||||
//
|
||||
ObjectOutputStream.PutField fields = out.putFields();
|
||||
fields.put("myNewRoleValue", newRoleValue);
|
||||
fields.put("myOldRoleValue", oldRoleValue);
|
||||
fields.put("myRelId", relationId);
|
||||
fields.put("myRelObjName", relationObjName);
|
||||
fields.put("myRelTypeName", relationTypeName);
|
||||
fields.put("myRoleName",roleName);
|
||||
fields.put("myUnregMBeanList", unregisterMBeanList);
|
||||
out.writeFields();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Serializes this instance in the new serial form
|
||||
//
|
||||
out.defaultWriteObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
3789
jdkSrc/jdk8/javax/management/relation/RelationService.java
Normal file
3789
jdkSrc/jdk8/javax/management/relation/RelationService.java
Normal file
File diff suppressed because it is too large
Load Diff
798
jdkSrc/jdk8/javax/management/relation/RelationServiceMBean.java
Normal file
798
jdkSrc/jdk8/javax/management/relation/RelationServiceMBean.java
Normal file
@@ -0,0 +1,798 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
import javax.management.ObjectName;
|
||||
import javax.management.InstanceNotFoundException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The Relation Service is in charge of creating and deleting relation types
|
||||
* and relations, of handling the consistency and of providing query
|
||||
* mechanisms.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public interface RelationServiceMBean {
|
||||
|
||||
/**
|
||||
* Checks if the Relation Service is active.
|
||||
* Current condition is that the Relation Service must be registered in the
|
||||
* MBean Server
|
||||
*
|
||||
* @exception RelationServiceNotRegisteredException if it is not
|
||||
* registered
|
||||
*/
|
||||
public void isActive()
|
||||
throws RelationServiceNotRegisteredException;
|
||||
|
||||
//
|
||||
// Accessors
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns the flag to indicate if when a notification is received for the
|
||||
* unregistration of an MBean referenced in a relation, if an immediate
|
||||
* "purge" of the relations (look for the relations no longer valid)
|
||||
* has to be performed, or if that will be performed only when the
|
||||
* purgeRelations method is explicitly called.
|
||||
* <P>true is immediate purge.
|
||||
*
|
||||
* @return true if purges are immediate.
|
||||
*
|
||||
* @see #setPurgeFlag
|
||||
*/
|
||||
public boolean getPurgeFlag();
|
||||
|
||||
/**
|
||||
* Sets the flag to indicate if when a notification is received for the
|
||||
* unregistration of an MBean referenced in a relation, if an immediate
|
||||
* "purge" of the relations (look for the relations no longer valid)
|
||||
* has to be performed, or if that will be performed only when the
|
||||
* purgeRelations method is explicitly called.
|
||||
* <P>true is immediate purge.
|
||||
*
|
||||
* @param purgeFlag flag
|
||||
*
|
||||
* @see #getPurgeFlag
|
||||
*/
|
||||
public void setPurgeFlag(boolean purgeFlag);
|
||||
|
||||
//
|
||||
// Relation type handling
|
||||
//
|
||||
|
||||
/**
|
||||
* Creates a relation type (RelationTypeSupport object) with given
|
||||
* role infos (provided by the RoleInfo objects), and adds it in the
|
||||
* Relation Service.
|
||||
*
|
||||
* @param relationTypeName name of the relation type
|
||||
* @param roleInfoArray array of role infos
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception InvalidRelationTypeException If:
|
||||
* <P>- there is already a relation type with that name
|
||||
* <P>- the same name has been used for two different role infos
|
||||
* <P>- no role info provided
|
||||
* <P>- one null role info provided
|
||||
*/
|
||||
public void createRelationType(String relationTypeName,
|
||||
RoleInfo[] roleInfoArray)
|
||||
throws IllegalArgumentException,
|
||||
InvalidRelationTypeException;
|
||||
|
||||
/**
|
||||
* Adds given object as a relation type. The object is expected to
|
||||
* implement the RelationType interface.
|
||||
*
|
||||
* @param relationTypeObj relation type object (implementing the
|
||||
* RelationType interface)
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter or if
|
||||
* {@link RelationType#getRelationTypeName
|
||||
* relationTypeObj.getRelationTypeName()} returns null.
|
||||
* @exception InvalidRelationTypeException if there is already a relation
|
||||
* type with that name
|
||||
*/
|
||||
public void addRelationType(RelationType relationTypeObj)
|
||||
throws IllegalArgumentException,
|
||||
InvalidRelationTypeException;
|
||||
|
||||
/**
|
||||
* Retrieves names of all known relation types.
|
||||
*
|
||||
* @return ArrayList of relation type names (Strings)
|
||||
*/
|
||||
public List<String> getAllRelationTypeNames();
|
||||
|
||||
/**
|
||||
* Retrieves list of role infos (RoleInfo objects) of a given relation
|
||||
* type.
|
||||
*
|
||||
* @param relationTypeName name of relation type
|
||||
*
|
||||
* @return ArrayList of RoleInfo.
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationTypeNotFoundException if there is no relation type
|
||||
* with that name.
|
||||
*/
|
||||
public List<RoleInfo> getRoleInfos(String relationTypeName)
|
||||
throws IllegalArgumentException,
|
||||
RelationTypeNotFoundException;
|
||||
|
||||
/**
|
||||
* Retrieves role info for given role of a given relation type.
|
||||
*
|
||||
* @param relationTypeName name of relation type
|
||||
* @param roleInfoName name of role
|
||||
*
|
||||
* @return RoleInfo object.
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationTypeNotFoundException if the relation type is not
|
||||
* known in the Relation Service
|
||||
* @exception RoleInfoNotFoundException if the role is not part of the
|
||||
* relation type.
|
||||
*/
|
||||
public RoleInfo getRoleInfo(String relationTypeName,
|
||||
String roleInfoName)
|
||||
throws IllegalArgumentException,
|
||||
RelationTypeNotFoundException,
|
||||
RoleInfoNotFoundException;
|
||||
|
||||
/**
|
||||
* Removes given relation type from Relation Service.
|
||||
* <P>The relation objects of that type will be removed from the
|
||||
* Relation Service.
|
||||
*
|
||||
* @param relationTypeName name of the relation type to be removed
|
||||
*
|
||||
* @exception RelationServiceNotRegisteredException if the Relation
|
||||
* Service is not registered in the MBean Server
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationTypeNotFoundException If there is no relation type
|
||||
* with that name
|
||||
*/
|
||||
public void removeRelationType(String relationTypeName)
|
||||
throws RelationServiceNotRegisteredException,
|
||||
IllegalArgumentException,
|
||||
RelationTypeNotFoundException;
|
||||
|
||||
//
|
||||
// Relation handling
|
||||
//
|
||||
|
||||
/**
|
||||
* Creates a simple relation (represented by a RelationSupport object) of
|
||||
* given relation type, and adds it in the Relation Service.
|
||||
* <P>Roles are initialized according to the role list provided in
|
||||
* parameter. The ones not initialized in this way are set to an empty
|
||||
* ArrayList of ObjectNames.
|
||||
* <P>A RelationNotification, with type RELATION_BASIC_CREATION, is sent.
|
||||
*
|
||||
* @param relationId relation identifier, to identify uniquely the relation
|
||||
* inside the Relation Service
|
||||
* @param relationTypeName name of the relation type (has to be created
|
||||
* in the Relation Service)
|
||||
* @param roleList role list to initialize roles of the relation (can
|
||||
* be null).
|
||||
*
|
||||
* @exception RelationServiceNotRegisteredException if the Relation
|
||||
* Service is not registered in the MBean Server
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RoleNotFoundException if a value is provided for a role
|
||||
* that does not exist in the relation type
|
||||
* @exception InvalidRelationIdException if relation id already used
|
||||
* @exception RelationTypeNotFoundException if relation type not known in
|
||||
* Relation Service
|
||||
* @exception InvalidRoleValueException if:
|
||||
* <P>- the same role name is used for two different roles
|
||||
* <P>- the number of referenced MBeans in given value is less than
|
||||
* expected minimum degree
|
||||
* <P>- the number of referenced MBeans in provided value exceeds expected
|
||||
* maximum degree
|
||||
* <P>- one referenced MBean in the value is not an Object of the MBean
|
||||
* class expected for that role
|
||||
* <P>- an MBean provided for that role does not exist
|
||||
*/
|
||||
public void createRelation(String relationId,
|
||||
String relationTypeName,
|
||||
RoleList roleList)
|
||||
throws RelationServiceNotRegisteredException,
|
||||
IllegalArgumentException,
|
||||
RoleNotFoundException,
|
||||
InvalidRelationIdException,
|
||||
RelationTypeNotFoundException,
|
||||
InvalidRoleValueException;
|
||||
|
||||
/**
|
||||
* Adds an MBean created by the user (and registered by him in the MBean
|
||||
* Server) as a relation in the Relation Service.
|
||||
* <P>To be added as a relation, the MBean must conform to the
|
||||
* following:
|
||||
* <P>- implement the Relation interface
|
||||
* <P>- have for RelationService ObjectName the ObjectName of current
|
||||
* Relation Service
|
||||
* <P>- have a relation id that is unique and unused in current Relation Service
|
||||
* <P>- have for relation type a relation type created in the Relation
|
||||
* Service
|
||||
* <P>- have roles conforming to the role info provided in the relation
|
||||
* type.
|
||||
*
|
||||
* @param relationObjectName ObjectName of the relation MBean to be added.
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationServiceNotRegisteredException if the Relation
|
||||
* Service is not registered in the MBean Server
|
||||
* @exception NoSuchMethodException If the MBean does not implement the
|
||||
* Relation interface
|
||||
* @exception InvalidRelationIdException if:
|
||||
* <P>- no relation identifier in MBean
|
||||
* <P>- the relation identifier is already used in the Relation Service
|
||||
* @exception InstanceNotFoundException if the MBean for given ObjectName
|
||||
* has not been registered
|
||||
* @exception InvalidRelationServiceException if:
|
||||
* <P>- no Relation Service name in MBean
|
||||
* <P>- the Relation Service name in the MBean is not the one of the
|
||||
* current Relation Service
|
||||
* @exception RelationTypeNotFoundException if:
|
||||
* <P>- no relation type name in MBean
|
||||
* <P>- the relation type name in MBean does not correspond to a relation
|
||||
* type created in the Relation Service
|
||||
* @exception InvalidRoleValueException if:
|
||||
* <P>- the number of referenced MBeans in a role is less than
|
||||
* expected minimum degree
|
||||
* <P>- the number of referenced MBeans in a role exceeds expected
|
||||
* maximum degree
|
||||
* <P>- one referenced MBean in the value is not an Object of the MBean
|
||||
* class expected for that role
|
||||
* <P>- an MBean provided for a role does not exist
|
||||
* @exception RoleNotFoundException if a value is provided for a role
|
||||
* that does not exist in the relation type
|
||||
*/
|
||||
public void addRelation(ObjectName relationObjectName)
|
||||
throws IllegalArgumentException,
|
||||
RelationServiceNotRegisteredException,
|
||||
NoSuchMethodException,
|
||||
InvalidRelationIdException,
|
||||
InstanceNotFoundException,
|
||||
InvalidRelationServiceException,
|
||||
RelationTypeNotFoundException,
|
||||
RoleNotFoundException,
|
||||
InvalidRoleValueException;
|
||||
|
||||
/**
|
||||
* If the relation is represented by an MBean (created by the user and
|
||||
* added as a relation in the Relation Service), returns the ObjectName of
|
||||
* the MBean.
|
||||
*
|
||||
* @param relationId relation id identifying the relation
|
||||
*
|
||||
* @return ObjectName of the corresponding relation MBean, or null if
|
||||
* the relation is not an MBean.
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationNotFoundException there is no relation associated
|
||||
* to that id
|
||||
*/
|
||||
public ObjectName isRelationMBean(String relationId)
|
||||
throws IllegalArgumentException,
|
||||
RelationNotFoundException;
|
||||
|
||||
/**
|
||||
* Returns the relation id associated to the given ObjectName if the
|
||||
* MBean has been added as a relation in the Relation Service.
|
||||
*
|
||||
* @param objectName ObjectName of supposed relation
|
||||
*
|
||||
* @return relation id (String) or null (if the ObjectName is not a
|
||||
* relation handled by the Relation Service)
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
*/
|
||||
public String isRelation(ObjectName objectName)
|
||||
throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Checks if there is a relation identified in Relation Service with given
|
||||
* relation id.
|
||||
*
|
||||
* @param relationId relation id identifying the relation
|
||||
*
|
||||
* @return boolean: true if there is a relation, false else
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
*/
|
||||
public Boolean hasRelation(String relationId)
|
||||
throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Returns all the relation ids for all the relations handled by the
|
||||
* Relation Service.
|
||||
*
|
||||
* @return ArrayList of String
|
||||
*/
|
||||
public List<String> getAllRelationIds();
|
||||
|
||||
/**
|
||||
* Checks if given Role can be read in a relation of the given type.
|
||||
*
|
||||
* @param roleName name of role to be checked
|
||||
* @param relationTypeName name of the relation type
|
||||
*
|
||||
* @return an Integer wrapping an integer corresponding to possible
|
||||
* problems represented as constants in RoleUnresolved:
|
||||
* <P>- 0 if role can be read
|
||||
* <P>- integer corresponding to RoleStatus.NO_ROLE_WITH_NAME
|
||||
* <P>- integer corresponding to RoleStatus.ROLE_NOT_READABLE
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationTypeNotFoundException if the relation type is not
|
||||
* known in the Relation Service
|
||||
*/
|
||||
public Integer checkRoleReading(String roleName,
|
||||
String relationTypeName)
|
||||
throws IllegalArgumentException,
|
||||
RelationTypeNotFoundException;
|
||||
|
||||
/**
|
||||
* Checks if given Role can be set in a relation of given type.
|
||||
*
|
||||
* @param role role to be checked
|
||||
* @param relationTypeName name of relation type
|
||||
* @param initFlag flag to specify that the checking is done for the
|
||||
* initialization of a role, write access shall not be verified.
|
||||
*
|
||||
* @return an Integer wrapping an integer corresponding to possible
|
||||
* problems represented as constants in RoleUnresolved:
|
||||
* <P>- 0 if role can be set
|
||||
* <P>- integer corresponding to RoleStatus.NO_ROLE_WITH_NAME
|
||||
* <P>- integer for RoleStatus.ROLE_NOT_WRITABLE
|
||||
* <P>- integer for RoleStatus.LESS_THAN_MIN_ROLE_DEGREE
|
||||
* <P>- integer for RoleStatus.MORE_THAN_MAX_ROLE_DEGREE
|
||||
* <P>- integer for RoleStatus.REF_MBEAN_OF_INCORRECT_CLASS
|
||||
* <P>- integer for RoleStatus.REF_MBEAN_NOT_REGISTERED
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationTypeNotFoundException if unknown relation type
|
||||
*/
|
||||
public Integer checkRoleWriting(Role role,
|
||||
String relationTypeName,
|
||||
Boolean initFlag)
|
||||
throws IllegalArgumentException,
|
||||
RelationTypeNotFoundException;
|
||||
|
||||
/**
|
||||
* Sends a notification (RelationNotification) for a relation creation.
|
||||
* The notification type is:
|
||||
* <P>- RelationNotification.RELATION_BASIC_CREATION if the relation is an
|
||||
* object internal to the Relation Service
|
||||
* <P>- RelationNotification.RELATION_MBEAN_CREATION if the relation is a
|
||||
* MBean added as a relation.
|
||||
* <P>The source object is the Relation Service itself.
|
||||
* <P>It is called in Relation Service createRelation() and
|
||||
* addRelation() methods.
|
||||
*
|
||||
* @param relationId relation identifier of the updated relation
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationNotFoundException if there is no relation for given
|
||||
* relation id
|
||||
*/
|
||||
public void sendRelationCreationNotification(String relationId)
|
||||
throws IllegalArgumentException,
|
||||
RelationNotFoundException;
|
||||
|
||||
/**
|
||||
* Sends a notification (RelationNotification) for a role update in the
|
||||
* given relation. The notification type is:
|
||||
* <P>- RelationNotification.RELATION_BASIC_UPDATE if the relation is an
|
||||
* object internal to the Relation Service
|
||||
* <P>- RelationNotification.RELATION_MBEAN_UPDATE if the relation is a
|
||||
* MBean added as a relation.
|
||||
* <P>The source object is the Relation Service itself.
|
||||
* <P>It is called in relation MBean setRole() (for given role) and
|
||||
* setRoles() (for each role) methods (implementation provided in
|
||||
* RelationSupport class).
|
||||
* <P>It is also called in Relation Service setRole() (for given role) and
|
||||
* setRoles() (for each role) methods.
|
||||
*
|
||||
* @param relationId relation identifier of the updated relation
|
||||
* @param newRole new role (name and new value)
|
||||
* @param oldRoleValue old role value (List of ObjectName objects)
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationNotFoundException if there is no relation for given
|
||||
* relation id
|
||||
*/
|
||||
public void sendRoleUpdateNotification(String relationId,
|
||||
Role newRole,
|
||||
List<ObjectName> oldRoleValue)
|
||||
throws IllegalArgumentException,
|
||||
RelationNotFoundException;
|
||||
|
||||
/**
|
||||
* Sends a notification (RelationNotification) for a relation removal.
|
||||
* The notification type is:
|
||||
* <P>- RelationNotification.RELATION_BASIC_REMOVAL if the relation is an
|
||||
* object internal to the Relation Service
|
||||
* <P>- RelationNotification.RELATION_MBEAN_REMOVAL if the relation is a
|
||||
* MBean added as a relation.
|
||||
* <P>The source object is the Relation Service itself.
|
||||
* <P>It is called in Relation Service removeRelation() method.
|
||||
*
|
||||
* @param relationId relation identifier of the updated relation
|
||||
* @param unregMBeanList List of ObjectNames of MBeans expected
|
||||
* to be unregistered due to relation removal (can be null)
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationNotFoundException if there is no relation for given
|
||||
* relation id
|
||||
*/
|
||||
public void sendRelationRemovalNotification(String relationId,
|
||||
List<ObjectName> unregMBeanList)
|
||||
throws IllegalArgumentException,
|
||||
RelationNotFoundException;
|
||||
|
||||
/**
|
||||
* Handles update of the Relation Service role map for the update of given
|
||||
* role in given relation.
|
||||
* <P>It is called in relation MBean setRole() (for given role) and
|
||||
* setRoles() (for each role) methods (implementation provided in
|
||||
* RelationSupport class).
|
||||
* <P>It is also called in Relation Service setRole() (for given role) and
|
||||
* setRoles() (for each role) methods.
|
||||
* <P>To allow the Relation Service to maintain the consistency (in case
|
||||
* of MBean unregistration) and to be able to perform queries, this method
|
||||
* must be called when a role is updated.
|
||||
*
|
||||
* @param relationId relation identifier of the updated relation
|
||||
* @param newRole new role (name and new value)
|
||||
* @param oldRoleValue old role value (List of ObjectName objects)
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationServiceNotRegisteredException if the Relation
|
||||
* Service is not registered in the MBean Server
|
||||
* @exception RelationNotFoundException if no relation for given id.
|
||||
*/
|
||||
public void updateRoleMap(String relationId,
|
||||
Role newRole,
|
||||
List<ObjectName> oldRoleValue)
|
||||
throws IllegalArgumentException,
|
||||
RelationServiceNotRegisteredException,
|
||||
RelationNotFoundException;
|
||||
|
||||
/**
|
||||
* Removes given relation from the Relation Service.
|
||||
* <P>A RelationNotification notification is sent, its type being:
|
||||
* <P>- RelationNotification.RELATION_BASIC_REMOVAL if the relation was
|
||||
* only internal to the Relation Service
|
||||
* <P>- RelationNotification.RELATION_MBEAN_REMOVAL if the relation is
|
||||
* registered as an MBean.
|
||||
* <P>For MBeans referenced in such relation, nothing will be done,
|
||||
*
|
||||
* @param relationId relation id of the relation to be removed
|
||||
*
|
||||
* @exception RelationServiceNotRegisteredException if the Relation
|
||||
* Service is not registered in the MBean Server
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationNotFoundException if no relation corresponding to
|
||||
* given relation id
|
||||
*/
|
||||
public void removeRelation(String relationId)
|
||||
throws RelationServiceNotRegisteredException,
|
||||
IllegalArgumentException,
|
||||
RelationNotFoundException;
|
||||
|
||||
/**
|
||||
* Purges the relations.
|
||||
*
|
||||
* <P>Depending on the purgeFlag value, this method is either called
|
||||
* automatically when a notification is received for the unregistration of
|
||||
* an MBean referenced in a relation (if the flag is set to true), or not
|
||||
* (if the flag is set to false).
|
||||
* <P>In that case it is up to the user to call it to maintain the
|
||||
* consistency of the relations. To be kept in mind that if an MBean is
|
||||
* unregistered and the purge not done immediately, if the ObjectName is
|
||||
* reused and assigned to another MBean referenced in a relation, calling
|
||||
* manually this purgeRelations() method will cause trouble, as will
|
||||
* consider the ObjectName as corresponding to the unregistered MBean, not
|
||||
* seeing the new one.
|
||||
*
|
||||
* <P>The behavior depends on the cardinality of the role where the
|
||||
* unregistered MBean is referenced:
|
||||
* <P>- if removing one MBean reference in the role makes its number of
|
||||
* references less than the minimum degree, the relation has to be removed.
|
||||
* <P>- if the remaining number of references after removing the MBean
|
||||
* reference is still in the cardinality range, keep the relation and
|
||||
* update it calling its handleMBeanUnregistration() callback.
|
||||
*
|
||||
* @exception RelationServiceNotRegisteredException if the Relation
|
||||
* Service is not registered in the MBean Server.
|
||||
*/
|
||||
public void purgeRelations()
|
||||
throws RelationServiceNotRegisteredException;
|
||||
|
||||
/**
|
||||
* Retrieves the relations where a given MBean is referenced.
|
||||
* <P>This corresponds to the CIM "References" and "ReferenceNames"
|
||||
* operations.
|
||||
*
|
||||
* @param mbeanName ObjectName of MBean
|
||||
* @param relationTypeName can be null; if specified, only the relations
|
||||
* of that type will be considered in the search. Else all relation types
|
||||
* are considered.
|
||||
* @param roleName can be null; if specified, only the relations
|
||||
* where the MBean is referenced in that role will be returned. Else all
|
||||
* roles are considered.
|
||||
*
|
||||
* @return an HashMap, where the keys are the relation ids of the relations
|
||||
* where the MBean is referenced, and the value is, for each key,
|
||||
* an ArrayList of role names (as an MBean can be referenced in several
|
||||
* roles in the same relation).
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
*/
|
||||
public Map<String,List<String>>
|
||||
findReferencingRelations(ObjectName mbeanName,
|
||||
String relationTypeName,
|
||||
String roleName)
|
||||
throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Retrieves the MBeans associated to given one in a relation.
|
||||
* <P>This corresponds to CIM Associators and AssociatorNames operations.
|
||||
*
|
||||
* @param mbeanName ObjectName of MBean
|
||||
* @param relationTypeName can be null; if specified, only the relations
|
||||
* of that type will be considered in the search. Else all
|
||||
* relation types are considered.
|
||||
* @param roleName can be null; if specified, only the relations
|
||||
* where the MBean is referenced in that role will be considered. Else all
|
||||
* roles are considered.
|
||||
*
|
||||
* @return an HashMap, where the keys are the ObjectNames of the MBeans
|
||||
* associated to given MBean, and the value is, for each key, an ArrayList
|
||||
* of the relation ids of the relations where the key MBean is
|
||||
* associated to given one (as they can be associated in several different
|
||||
* relations).
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
*/
|
||||
public Map<ObjectName,List<String>>
|
||||
findAssociatedMBeans(ObjectName mbeanName,
|
||||
String relationTypeName,
|
||||
String roleName)
|
||||
throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Returns the relation ids for relations of the given type.
|
||||
*
|
||||
* @param relationTypeName relation type name
|
||||
*
|
||||
* @return an ArrayList of relation ids.
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationTypeNotFoundException if there is no relation type
|
||||
* with that name.
|
||||
*/
|
||||
public List<String> findRelationsOfType(String relationTypeName)
|
||||
throws IllegalArgumentException,
|
||||
RelationTypeNotFoundException;
|
||||
|
||||
/**
|
||||
* Retrieves role value for given role name in given relation.
|
||||
*
|
||||
* @param relationId relation id
|
||||
* @param roleName name of role
|
||||
*
|
||||
* @return the ArrayList of ObjectName objects being the role value
|
||||
*
|
||||
* @exception RelationServiceNotRegisteredException if the Relation
|
||||
* Service is not registered
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationNotFoundException if no relation with given id
|
||||
* @exception RoleNotFoundException if:
|
||||
* <P>- there is no role with given name
|
||||
* <P>or
|
||||
* <P>- the role is not readable.
|
||||
*
|
||||
* @see #setRole
|
||||
*/
|
||||
public List<ObjectName> getRole(String relationId,
|
||||
String roleName)
|
||||
throws RelationServiceNotRegisteredException,
|
||||
IllegalArgumentException,
|
||||
RelationNotFoundException,
|
||||
RoleNotFoundException;
|
||||
|
||||
/**
|
||||
* Retrieves values of roles with given names in given relation.
|
||||
*
|
||||
* @param relationId relation id
|
||||
* @param roleNameArray array of names of roles to be retrieved
|
||||
*
|
||||
* @return a RoleResult object, including a RoleList (for roles
|
||||
* successfully retrieved) and a RoleUnresolvedList (for roles not
|
||||
* retrieved).
|
||||
*
|
||||
* @exception RelationServiceNotRegisteredException if the Relation
|
||||
* Service is not registered in the MBean Server
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationNotFoundException if no relation with given id
|
||||
*
|
||||
* @see #setRoles
|
||||
*/
|
||||
public RoleResult getRoles(String relationId,
|
||||
String[] roleNameArray)
|
||||
throws RelationServiceNotRegisteredException,
|
||||
IllegalArgumentException,
|
||||
RelationNotFoundException;
|
||||
|
||||
/**
|
||||
* Returns all roles present in the relation.
|
||||
*
|
||||
* @param relationId relation id
|
||||
*
|
||||
* @return a RoleResult object, including a RoleList (for roles
|
||||
* successfully retrieved) and a RoleUnresolvedList (for roles not
|
||||
* readable).
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationNotFoundException if no relation for given id
|
||||
* @exception RelationServiceNotRegisteredException if the Relation
|
||||
* Service is not registered in the MBean Server
|
||||
*/
|
||||
public RoleResult getAllRoles(String relationId)
|
||||
throws IllegalArgumentException,
|
||||
RelationNotFoundException,
|
||||
RelationServiceNotRegisteredException;
|
||||
|
||||
/**
|
||||
* Retrieves the number of MBeans currently referenced in the
|
||||
* given role.
|
||||
*
|
||||
* @param relationId relation id
|
||||
* @param roleName name of role
|
||||
*
|
||||
* @return the number of currently referenced MBeans in that role
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationNotFoundException if no relation with given id
|
||||
* @exception RoleNotFoundException if there is no role with given name
|
||||
*/
|
||||
public Integer getRoleCardinality(String relationId,
|
||||
String roleName)
|
||||
throws IllegalArgumentException,
|
||||
RelationNotFoundException,
|
||||
RoleNotFoundException;
|
||||
|
||||
/**
|
||||
* Sets the given role in given relation.
|
||||
* <P>Will check the role according to its corresponding role definition
|
||||
* provided in relation's relation type
|
||||
* <P>The Relation Service will keep track of the change to keep the
|
||||
* consistency of relations by handling referenced MBean deregistrations.
|
||||
*
|
||||
* @param relationId relation id
|
||||
* @param role role to be set (name and new value)
|
||||
*
|
||||
* @exception RelationServiceNotRegisteredException if the Relation
|
||||
* Service is not registered in the MBean Server
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationNotFoundException if no relation with given id
|
||||
* @exception RoleNotFoundException if:
|
||||
* <P>- internal relation
|
||||
* <P>and
|
||||
* <P>- the role does not exist or is not writable
|
||||
* @exception InvalidRoleValueException if internal relation and value
|
||||
* provided for role is not valid:
|
||||
* <P>- the number of referenced MBeans in given value is less than
|
||||
* expected minimum degree
|
||||
* <P>or
|
||||
* <P>- the number of referenced MBeans in provided value exceeds expected
|
||||
* maximum degree
|
||||
* <P>or
|
||||
* <P>- one referenced MBean in the value is not an Object of the MBean
|
||||
* class expected for that role
|
||||
* <P>or
|
||||
* <P>- an MBean provided for that role does not exist
|
||||
* @exception RelationTypeNotFoundException if unknown relation type
|
||||
*
|
||||
* @see #getRole
|
||||
*/
|
||||
public void setRole(String relationId,
|
||||
Role role)
|
||||
throws RelationServiceNotRegisteredException,
|
||||
IllegalArgumentException,
|
||||
RelationNotFoundException,
|
||||
RoleNotFoundException,
|
||||
InvalidRoleValueException,
|
||||
RelationTypeNotFoundException;
|
||||
|
||||
/**
|
||||
* Sets the given roles in given relation.
|
||||
* <P>Will check the role according to its corresponding role definition
|
||||
* provided in relation's relation type
|
||||
* <P>The Relation Service keeps track of the changes to keep the
|
||||
* consistency of relations by handling referenced MBean deregistrations.
|
||||
*
|
||||
* @param relationId relation id
|
||||
* @param roleList list of roles to be set
|
||||
*
|
||||
* @return a RoleResult object, including a RoleList (for roles
|
||||
* successfully set) and a RoleUnresolvedList (for roles not
|
||||
* set).
|
||||
*
|
||||
* @exception RelationServiceNotRegisteredException if the Relation
|
||||
* Service is not registered in the MBean Server
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationNotFoundException if no relation with given id
|
||||
*
|
||||
* @see #getRoles
|
||||
*/
|
||||
public RoleResult setRoles(String relationId,
|
||||
RoleList roleList)
|
||||
throws RelationServiceNotRegisteredException,
|
||||
IllegalArgumentException,
|
||||
RelationNotFoundException;
|
||||
|
||||
/**
|
||||
* Retrieves MBeans referenced in the various roles of the relation.
|
||||
*
|
||||
* @param relationId relation id
|
||||
*
|
||||
* @return a HashMap mapping:
|
||||
* <P> ObjectName {@literal ->} ArrayList of String (role
|
||||
* names)
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationNotFoundException if no relation for given
|
||||
* relation id
|
||||
*/
|
||||
public Map<ObjectName,List<String>> getReferencedMBeans(String relationId)
|
||||
throws IllegalArgumentException,
|
||||
RelationNotFoundException;
|
||||
|
||||
/**
|
||||
* Returns name of associated relation type for given relation.
|
||||
*
|
||||
* @param relationId relation id
|
||||
*
|
||||
* @return the name of the associated relation type.
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RelationNotFoundException if no relation for given
|
||||
* relation id
|
||||
*/
|
||||
public String getRelationTypeName(String relationId)
|
||||
throws IllegalArgumentException,
|
||||
RelationNotFoundException;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
/**
|
||||
* This exception is raised when an access is done to the Relation Service and
|
||||
* that one is not registered.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class RelationServiceNotRegisteredException extends RelationException {
|
||||
|
||||
/* Serial version */
|
||||
private static final long serialVersionUID = 8454744887157122910L;
|
||||
|
||||
/**
|
||||
* Default constructor, no message put in exception.
|
||||
*/
|
||||
public RelationServiceNotRegisteredException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given message put in exception.
|
||||
*
|
||||
* @param message the detail message.
|
||||
*/
|
||||
public RelationServiceNotRegisteredException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
1731
jdkSrc/jdk8/javax/management/relation/RelationSupport.java
Normal file
1731
jdkSrc/jdk8/javax/management/relation/RelationSupport.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
/**
|
||||
* A RelationSupport object is used internally by the Relation Service to
|
||||
* represent simple relations (only roles, no properties or methods), with an
|
||||
* unlimited number of roles, of any relation type. As internal representation,
|
||||
* it is not exposed to the user.
|
||||
* <P>RelationSupport class conforms to the design patterns of standard MBean. So
|
||||
* the user can decide to instantiate a RelationSupport object himself as
|
||||
* a MBean (as it follows the MBean design patterns), to register it in the
|
||||
* MBean Server, and then to add it in the Relation Service.
|
||||
* <P>The user can also, when creating his own MBean relation class, have it
|
||||
* extending RelationSupport, to retrieve the implementations of required
|
||||
* interfaces (see below).
|
||||
* <P>It is also possible to have in a user relation MBean class a member
|
||||
* being a RelationSupport object, and to implement the required interfaces by
|
||||
* delegating all to this member.
|
||||
* <P> RelationSupport implements the Relation interface (to be handled by the
|
||||
* Relation Service).
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public interface RelationSupportMBean
|
||||
extends Relation {
|
||||
|
||||
/**
|
||||
* Returns an internal flag specifying if the object is still handled by
|
||||
* the Relation Service.
|
||||
*
|
||||
* @return a Boolean equal to {@link Boolean#TRUE} if the object
|
||||
* is still handled by the Relation Service and {@link
|
||||
* Boolean#FALSE} otherwise.
|
||||
*/
|
||||
public Boolean isInRelationService();
|
||||
|
||||
/**
|
||||
* <p>Specifies whether this relation is handled by the Relation
|
||||
* Service.</p>
|
||||
* <P>BEWARE, this method has to be exposed as the Relation Service will
|
||||
* access the relation through its management interface. It is RECOMMENDED
|
||||
* NOT to use this method. Using it does not affect the registration of the
|
||||
* relation object in the Relation Service, but will provide wrong
|
||||
* information about it!
|
||||
*
|
||||
* @param flag whether the relation is handled by the Relation Service.
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
*/
|
||||
public void setRelationServiceManagementFlag(Boolean flag)
|
||||
throws IllegalArgumentException;
|
||||
}
|
||||
75
jdkSrc/jdk8/javax/management/relation/RelationType.java
Normal file
75
jdkSrc/jdk8/javax/management/relation/RelationType.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
import java.util.ArrayList; // for Javadoc
|
||||
import java.util.List;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* The RelationType interface has to be implemented by any class expected to
|
||||
* represent a relation type.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public interface RelationType extends Serializable {
|
||||
|
||||
//
|
||||
// Accessors
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns the relation type name.
|
||||
*
|
||||
* @return the relation type name.
|
||||
*/
|
||||
public String getRelationTypeName();
|
||||
|
||||
/**
|
||||
* Returns the list of role definitions (ArrayList of RoleInfo objects).
|
||||
*
|
||||
* @return an {@link ArrayList} of {@link RoleInfo}.
|
||||
*/
|
||||
public List<RoleInfo> getRoleInfos();
|
||||
|
||||
/**
|
||||
* Returns the role info (RoleInfo object) for the given role info name
|
||||
* (null if not found).
|
||||
*
|
||||
* @param roleInfoName role info name
|
||||
*
|
||||
* @return RoleInfo object providing role definition
|
||||
* does not exist
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RoleInfoNotFoundException if no role info with that name in
|
||||
* relation type.
|
||||
*/
|
||||
public RoleInfo getRoleInfo(String roleInfoName)
|
||||
throws IllegalArgumentException,
|
||||
RoleInfoNotFoundException;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
/**
|
||||
* This exception is raised when there is no relation type with given name in
|
||||
* Relation Service.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class RelationTypeNotFoundException extends RelationException {
|
||||
|
||||
/* Serial version */
|
||||
private static final long serialVersionUID = 1274155316284300752L;
|
||||
|
||||
/**
|
||||
* Default constructor, no message put in exception.
|
||||
*/
|
||||
public RelationTypeNotFoundException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given message put in exception.
|
||||
*
|
||||
* @param message the detail message.
|
||||
*/
|
||||
public RelationTypeNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
486
jdkSrc/jdk8/javax/management/relation/RelationTypeSupport.java
Normal file
486
jdkSrc/jdk8/javax/management/relation/RelationTypeSupport.java
Normal file
@@ -0,0 +1,486 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
import static com.sun.jmx.defaults.JmxProperties.RELATION_LOGGER;
|
||||
import static com.sun.jmx.mbeanserver.Util.cast;
|
||||
import com.sun.jmx.mbeanserver.GetPropertyAction;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamField;
|
||||
|
||||
import java.security.AccessController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A RelationTypeSupport object implements the RelationType interface.
|
||||
* <P>It represents a relation type, providing role information for each role
|
||||
* expected to be supported in every relation of that type.
|
||||
*
|
||||
* <P>A relation type includes a relation type name and a list of
|
||||
* role infos (represented by RoleInfo objects).
|
||||
*
|
||||
* <P>A relation type has to be declared in the Relation Service:
|
||||
* <P>- either using the createRelationType() method, where a RelationTypeSupport
|
||||
* object will be created and kept in the Relation Service
|
||||
* <P>- either using the addRelationType() method where the user has to create
|
||||
* an object implementing the RelationType interface, and this object will be
|
||||
* used as representing a relation type in the Relation Service.
|
||||
*
|
||||
* <p>The <b>serialVersionUID</b> of this class is <code>4611072955724144607L</code>.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
@SuppressWarnings("serial") // serialVersionUID not constant
|
||||
public class RelationTypeSupport implements RelationType {
|
||||
|
||||
// Serialization compatibility stuff:
|
||||
// Two serial forms are supported in this class. The selected form depends
|
||||
// on system property "jmx.serial.form":
|
||||
// - "1.0" for JMX 1.0
|
||||
// - any other value for JMX 1.1 and higher
|
||||
//
|
||||
// Serial version for old serial form
|
||||
private static final long oldSerialVersionUID = -8179019472410837190L;
|
||||
//
|
||||
// Serial version for new serial form
|
||||
private static final long newSerialVersionUID = 4611072955724144607L;
|
||||
//
|
||||
// Serializable fields in old serial form
|
||||
private static final ObjectStreamField[] oldSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("myTypeName", String.class),
|
||||
new ObjectStreamField("myRoleName2InfoMap", HashMap.class),
|
||||
new ObjectStreamField("myIsInRelServFlg", boolean.class)
|
||||
};
|
||||
//
|
||||
// Serializable fields in new serial form
|
||||
private static final ObjectStreamField[] newSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("typeName", String.class),
|
||||
new ObjectStreamField("roleName2InfoMap", Map.class),
|
||||
new ObjectStreamField("isInRelationService", boolean.class)
|
||||
};
|
||||
//
|
||||
// Actual serial version and serial form
|
||||
private static final long serialVersionUID;
|
||||
/**
|
||||
* @serialField typeName String Relation type name
|
||||
* @serialField roleName2InfoMap Map {@link Map} holding the mapping:
|
||||
* <role name ({@link String})> -> <role info ({@link RoleInfo} object)>
|
||||
* @serialField isInRelationService boolean Flag specifying whether the relation type has been declared in the
|
||||
* Relation Service (so can no longer be updated)
|
||||
*/
|
||||
private static final ObjectStreamField[] serialPersistentFields;
|
||||
private static boolean compat = false;
|
||||
static {
|
||||
try {
|
||||
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
|
||||
String form = AccessController.doPrivileged(act);
|
||||
compat = (form != null && form.equals("1.0"));
|
||||
} catch (Exception e) {
|
||||
// OK : Too bad, no compat with 1.0
|
||||
}
|
||||
if (compat) {
|
||||
serialPersistentFields = oldSerialPersistentFields;
|
||||
serialVersionUID = oldSerialVersionUID;
|
||||
} else {
|
||||
serialPersistentFields = newSerialPersistentFields;
|
||||
serialVersionUID = newSerialVersionUID;
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Serialization compatibility stuff
|
||||
|
||||
//
|
||||
// Private members
|
||||
//
|
||||
|
||||
/**
|
||||
* @serial Relation type name
|
||||
*/
|
||||
private String typeName = null;
|
||||
|
||||
/**
|
||||
* @serial {@link Map} holding the mapping:
|
||||
* <role name ({@link String})> -> <role info ({@link RoleInfo} object)>
|
||||
*/
|
||||
private Map<String,RoleInfo> roleName2InfoMap =
|
||||
new HashMap<String,RoleInfo>();
|
||||
|
||||
/**
|
||||
* @serial Flag specifying whether the relation type has been declared in the
|
||||
* Relation Service (so can no longer be updated)
|
||||
*/
|
||||
private boolean isInRelationService = false;
|
||||
|
||||
//
|
||||
// Constructors
|
||||
//
|
||||
|
||||
/**
|
||||
* Constructor where all role definitions are dynamically created and
|
||||
* passed as parameter.
|
||||
*
|
||||
* @param relationTypeName Name of relation type
|
||||
* @param roleInfoArray List of role definitions (RoleInfo objects)
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception InvalidRelationTypeException if:
|
||||
* <P>- the same name has been used for two different roles
|
||||
* <P>- no role info provided
|
||||
* <P>- one null role info provided
|
||||
*/
|
||||
public RelationTypeSupport(String relationTypeName,
|
||||
RoleInfo[] roleInfoArray)
|
||||
throws IllegalArgumentException,
|
||||
InvalidRelationTypeException {
|
||||
|
||||
if (relationTypeName == null || roleInfoArray == null) {
|
||||
String excMsg = "Invalid parameter.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
RELATION_LOGGER.entering(RelationTypeSupport.class.getName(),
|
||||
"RelationTypeSupport", relationTypeName);
|
||||
|
||||
// Can throw InvalidRelationTypeException, ClassNotFoundException
|
||||
// and NotCompliantMBeanException
|
||||
initMembers(relationTypeName, roleInfoArray);
|
||||
|
||||
RELATION_LOGGER.exiting(RelationTypeSupport.class.getName(),
|
||||
"RelationTypeSupport");
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor to be used for subclasses.
|
||||
*
|
||||
* @param relationTypeName Name of relation type.
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter.
|
||||
*/
|
||||
protected RelationTypeSupport(String relationTypeName)
|
||||
{
|
||||
if (relationTypeName == null) {
|
||||
String excMsg = "Invalid parameter.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
RELATION_LOGGER.entering(RelationTypeSupport.class.getName(),
|
||||
"RelationTypeSupport", relationTypeName);
|
||||
|
||||
typeName = relationTypeName;
|
||||
|
||||
RELATION_LOGGER.exiting(RelationTypeSupport.class.getName(),
|
||||
"RelationTypeSupport");
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Accessors
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns the relation type name.
|
||||
*
|
||||
* @return the relation type name.
|
||||
*/
|
||||
public String getRelationTypeName() {
|
||||
return typeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of role definitions (ArrayList of RoleInfo objects).
|
||||
*/
|
||||
public List<RoleInfo> getRoleInfos() {
|
||||
return new ArrayList<RoleInfo>(roleName2InfoMap.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the role info (RoleInfo object) for the given role info name
|
||||
* (null if not found).
|
||||
*
|
||||
* @param roleInfoName role info name
|
||||
*
|
||||
* @return RoleInfo object providing role definition
|
||||
* does not exist
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception RoleInfoNotFoundException if no role info with that name in
|
||||
* relation type.
|
||||
*/
|
||||
public RoleInfo getRoleInfo(String roleInfoName)
|
||||
throws IllegalArgumentException,
|
||||
RoleInfoNotFoundException {
|
||||
|
||||
if (roleInfoName == null) {
|
||||
String excMsg = "Invalid parameter.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
RELATION_LOGGER.entering(RelationTypeSupport.class.getName(),
|
||||
"getRoleInfo", roleInfoName);
|
||||
|
||||
// No null RoleInfo allowed, so use get()
|
||||
RoleInfo result = roleName2InfoMap.get(roleInfoName);
|
||||
|
||||
if (result == null) {
|
||||
StringBuilder excMsgStrB = new StringBuilder();
|
||||
String excMsg = "No role info for role ";
|
||||
excMsgStrB.append(excMsg);
|
||||
excMsgStrB.append(roleInfoName);
|
||||
throw new RoleInfoNotFoundException(excMsgStrB.toString());
|
||||
}
|
||||
|
||||
RELATION_LOGGER.exiting(RelationTypeSupport.class.getName(),
|
||||
"getRoleInfo");
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Misc
|
||||
//
|
||||
|
||||
/**
|
||||
* Add a role info.
|
||||
* This method of course should not be used after the creation of the
|
||||
* relation type, because updating it would invalidate that the relations
|
||||
* created associated to that type still conform to it.
|
||||
* Can throw a RuntimeException if trying to update a relation type
|
||||
* declared in the Relation Service.
|
||||
*
|
||||
* @param roleInfo role info to be added.
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter.
|
||||
* @exception InvalidRelationTypeException if there is already a role
|
||||
* info in current relation type with the same name.
|
||||
*/
|
||||
protected void addRoleInfo(RoleInfo roleInfo)
|
||||
throws IllegalArgumentException,
|
||||
InvalidRelationTypeException {
|
||||
|
||||
if (roleInfo == null) {
|
||||
String excMsg = "Invalid parameter.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
RELATION_LOGGER.entering(RelationTypeSupport.class.getName(),
|
||||
"addRoleInfo", roleInfo);
|
||||
|
||||
if (isInRelationService) {
|
||||
// Trying to update a declared relation type
|
||||
String excMsg = "Relation type cannot be updated as it is declared in the Relation Service.";
|
||||
throw new RuntimeException(excMsg);
|
||||
}
|
||||
|
||||
String roleName = roleInfo.getName();
|
||||
|
||||
// Checks if the role info has already been described
|
||||
if (roleName2InfoMap.containsKey(roleName)) {
|
||||
StringBuilder excMsgStrB = new StringBuilder();
|
||||
String excMsg = "Two role infos provided for role ";
|
||||
excMsgStrB.append(excMsg);
|
||||
excMsgStrB.append(roleName);
|
||||
throw new InvalidRelationTypeException(excMsgStrB.toString());
|
||||
}
|
||||
|
||||
roleName2InfoMap.put(roleName, new RoleInfo(roleInfo));
|
||||
|
||||
RELATION_LOGGER.exiting(RelationTypeSupport.class.getName(),
|
||||
"addRoleInfo");
|
||||
return;
|
||||
}
|
||||
|
||||
// Sets the internal flag to specify that the relation type has been
|
||||
// declared in the Relation Service
|
||||
void setRelationServiceFlag(boolean flag) {
|
||||
isInRelationService = flag;
|
||||
return;
|
||||
}
|
||||
|
||||
// Initializes the members, i.e. type name and role info list.
|
||||
//
|
||||
// -param relationTypeName Name of relation type
|
||||
// -param roleInfoArray List of role definitions (RoleInfo objects)
|
||||
//
|
||||
// -exception IllegalArgumentException if null parameter
|
||||
// -exception InvalidRelationTypeException If:
|
||||
// - the same name has been used for two different roles
|
||||
// - no role info provided
|
||||
// - one null role info provided
|
||||
private void initMembers(String relationTypeName,
|
||||
RoleInfo[] roleInfoArray)
|
||||
throws IllegalArgumentException,
|
||||
InvalidRelationTypeException {
|
||||
|
||||
if (relationTypeName == null || roleInfoArray == null) {
|
||||
String excMsg = "Invalid parameter.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
RELATION_LOGGER.entering(RelationTypeSupport.class.getName(),
|
||||
"initMembers", relationTypeName);
|
||||
|
||||
typeName = relationTypeName;
|
||||
|
||||
// Verifies role infos before setting them
|
||||
// Can throw InvalidRelationTypeException
|
||||
checkRoleInfos(roleInfoArray);
|
||||
|
||||
for (int i = 0; i < roleInfoArray.length; i++) {
|
||||
RoleInfo currRoleInfo = roleInfoArray[i];
|
||||
roleName2InfoMap.put(currRoleInfo.getName(),
|
||||
new RoleInfo(currRoleInfo));
|
||||
}
|
||||
|
||||
RELATION_LOGGER.exiting(RelationTypeSupport.class.getName(),
|
||||
"initMembers");
|
||||
return;
|
||||
}
|
||||
|
||||
// Checks the given RoleInfo array to verify that:
|
||||
// - the array is not empty
|
||||
// - it does not contain a null element
|
||||
// - a given role name is used only for one RoleInfo
|
||||
//
|
||||
// -param roleInfoArray array to be checked
|
||||
//
|
||||
// -exception IllegalArgumentException
|
||||
// -exception InvalidRelationTypeException If:
|
||||
// - the same name has been used for two different roles
|
||||
// - no role info provided
|
||||
// - one null role info provided
|
||||
static void checkRoleInfos(RoleInfo[] roleInfoArray)
|
||||
throws IllegalArgumentException,
|
||||
InvalidRelationTypeException {
|
||||
|
||||
if (roleInfoArray == null) {
|
||||
String excMsg = "Invalid parameter.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
if (roleInfoArray.length == 0) {
|
||||
// No role info provided
|
||||
String excMsg = "No role info provided.";
|
||||
throw new InvalidRelationTypeException(excMsg);
|
||||
}
|
||||
|
||||
|
||||
Set<String> roleNames = new HashSet<String>();
|
||||
|
||||
for (int i = 0; i < roleInfoArray.length; i++) {
|
||||
RoleInfo currRoleInfo = roleInfoArray[i];
|
||||
|
||||
if (currRoleInfo == null) {
|
||||
String excMsg = "Null role info provided.";
|
||||
throw new InvalidRelationTypeException(excMsg);
|
||||
}
|
||||
|
||||
String roleName = currRoleInfo.getName();
|
||||
|
||||
// Checks if the role info has already been described
|
||||
if (roleNames.contains(roleName)) {
|
||||
StringBuilder excMsgStrB = new StringBuilder();
|
||||
String excMsg = "Two role infos provided for role ";
|
||||
excMsgStrB.append(excMsg);
|
||||
excMsgStrB.append(roleName);
|
||||
throw new InvalidRelationTypeException(excMsgStrB.toString());
|
||||
}
|
||||
roleNames.add(roleName);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Deserializes a {@link RelationTypeSupport} from an {@link ObjectInputStream}.
|
||||
*/
|
||||
private void readObject(ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException {
|
||||
if (compat)
|
||||
{
|
||||
// Read an object serialized in the old serial form
|
||||
//
|
||||
ObjectInputStream.GetField fields = in.readFields();
|
||||
typeName = (String) fields.get("myTypeName", null);
|
||||
if (fields.defaulted("myTypeName"))
|
||||
{
|
||||
throw new NullPointerException("myTypeName");
|
||||
}
|
||||
roleName2InfoMap = cast(fields.get("myRoleName2InfoMap", null));
|
||||
if (fields.defaulted("myRoleName2InfoMap"))
|
||||
{
|
||||
throw new NullPointerException("myRoleName2InfoMap");
|
||||
}
|
||||
isInRelationService = fields.get("myIsInRelServFlg", false);
|
||||
if (fields.defaulted("myIsInRelServFlg"))
|
||||
{
|
||||
throw new NullPointerException("myIsInRelServFlg");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Read an object serialized in the new serial form
|
||||
//
|
||||
in.defaultReadObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serializes a {@link RelationTypeSupport} to an {@link ObjectOutputStream}.
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream out)
|
||||
throws IOException {
|
||||
if (compat)
|
||||
{
|
||||
// Serializes this instance in the old serial form
|
||||
//
|
||||
ObjectOutputStream.PutField fields = out.putFields();
|
||||
fields.put("myTypeName", typeName);
|
||||
fields.put("myRoleName2InfoMap", roleName2InfoMap);
|
||||
fields.put("myIsInRelServFlg", isInRelationService);
|
||||
out.writeFields();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Serializes this instance in the new serial form
|
||||
//
|
||||
out.defaultWriteObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
338
jdkSrc/jdk8/javax/management/relation/Role.java
Normal file
338
jdkSrc/jdk8/javax/management/relation/Role.java
Normal file
@@ -0,0 +1,338 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
import static com.sun.jmx.mbeanserver.Util.cast;
|
||||
import com.sun.jmx.mbeanserver.GetPropertyAction;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamField;
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.security.AccessController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.management.ObjectName;
|
||||
|
||||
/**
|
||||
* Represents a role: includes a role name and referenced MBeans (via their
|
||||
* ObjectNames). The role value is always represented as an ArrayList
|
||||
* collection (of ObjectNames) to homogenize the access.
|
||||
*
|
||||
* <p>The <b>serialVersionUID</b> of this class is <code>-279985518429862552L</code>.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
@SuppressWarnings("serial") // serialVersionUID not constant
|
||||
public class Role implements Serializable {
|
||||
|
||||
// Serialization compatibility stuff:
|
||||
// Two serial forms are supported in this class. The selected form depends
|
||||
// on system property "jmx.serial.form":
|
||||
// - "1.0" for JMX 1.0
|
||||
// - any other value for JMX 1.1 and higher
|
||||
//
|
||||
// Serial version for old serial form
|
||||
private static final long oldSerialVersionUID = -1959486389343113026L;
|
||||
//
|
||||
// Serial version for new serial form
|
||||
private static final long newSerialVersionUID = -279985518429862552L;
|
||||
//
|
||||
// Serializable fields in old serial form
|
||||
private static final ObjectStreamField[] oldSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("myName", String.class),
|
||||
new ObjectStreamField("myObjNameList", ArrayList.class)
|
||||
};
|
||||
//
|
||||
// Serializable fields in new serial form
|
||||
private static final ObjectStreamField[] newSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("name", String.class),
|
||||
new ObjectStreamField("objectNameList", List.class)
|
||||
};
|
||||
//
|
||||
// Actual serial version and serial form
|
||||
private static final long serialVersionUID;
|
||||
/**
|
||||
* @serialField name String Role name
|
||||
* @serialField objectNameList List {@link List} of {@link ObjectName}s of referenced MBeans
|
||||
*/
|
||||
private static final ObjectStreamField[] serialPersistentFields;
|
||||
private static boolean compat = false;
|
||||
static {
|
||||
try {
|
||||
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
|
||||
String form = AccessController.doPrivileged(act);
|
||||
compat = (form != null && form.equals("1.0"));
|
||||
} catch (Exception e) {
|
||||
// OK : Too bad, no compat with 1.0
|
||||
}
|
||||
if (compat) {
|
||||
serialPersistentFields = oldSerialPersistentFields;
|
||||
serialVersionUID = oldSerialVersionUID;
|
||||
} else {
|
||||
serialPersistentFields = newSerialPersistentFields;
|
||||
serialVersionUID = newSerialVersionUID;
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Serialization compatibility stuff
|
||||
|
||||
//
|
||||
// Private members
|
||||
//
|
||||
|
||||
/**
|
||||
* @serial Role name
|
||||
*/
|
||||
private String name = null;
|
||||
|
||||
/**
|
||||
* @serial {@link List} of {@link ObjectName}s of referenced MBeans
|
||||
*/
|
||||
private List<ObjectName> objectNameList = new ArrayList<ObjectName>();
|
||||
|
||||
//
|
||||
// Constructors
|
||||
//
|
||||
|
||||
/**
|
||||
* <p>Make a new Role object.
|
||||
* No check is made that the ObjectNames in the role value exist in
|
||||
* an MBean server. That check will be made when the role is set
|
||||
* in a relation.
|
||||
*
|
||||
* @param roleName role name
|
||||
* @param roleValue role value (List of ObjectName objects)
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
*/
|
||||
public Role(String roleName,
|
||||
List<ObjectName> roleValue)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
if (roleName == null || roleValue == null) {
|
||||
String excMsg = "Invalid parameter";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
setRoleName(roleName);
|
||||
setRoleValue(roleValue);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Accessors
|
||||
//
|
||||
|
||||
/**
|
||||
* Retrieves role name.
|
||||
*
|
||||
* @return the role name.
|
||||
*
|
||||
* @see #setRoleName
|
||||
*/
|
||||
public String getRoleName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves role value.
|
||||
*
|
||||
* @return ArrayList of ObjectName objects for referenced MBeans.
|
||||
*
|
||||
* @see #setRoleValue
|
||||
*/
|
||||
public List<ObjectName> getRoleValue() {
|
||||
return objectNameList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets role name.
|
||||
*
|
||||
* @param roleName role name
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
*
|
||||
* @see #getRoleName
|
||||
*/
|
||||
public void setRoleName(String roleName)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
if (roleName == null) {
|
||||
String excMsg = "Invalid parameter.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
name = roleName;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets role value.
|
||||
*
|
||||
* @param roleValue List of ObjectName objects for referenced
|
||||
* MBeans.
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
*
|
||||
* @see #getRoleValue
|
||||
*/
|
||||
public void setRoleValue(List<ObjectName> roleValue)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
if (roleValue == null) {
|
||||
String excMsg = "Invalid parameter.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
objectNameList = new ArrayList<ObjectName>(roleValue);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string describing the role.
|
||||
*
|
||||
* @return the description of the role.
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("role name: " + name + "; role value: ");
|
||||
for (Iterator<ObjectName> objNameIter = objectNameList.iterator();
|
||||
objNameIter.hasNext();) {
|
||||
ObjectName currObjName = objNameIter.next();
|
||||
result.append(currObjName.toString());
|
||||
if (objNameIter.hasNext()) {
|
||||
result.append(", ");
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
//
|
||||
// Misc
|
||||
//
|
||||
|
||||
/**
|
||||
* Clone the role object.
|
||||
*
|
||||
* @return a Role that is an independent copy of the current Role object.
|
||||
*/
|
||||
public Object clone() {
|
||||
|
||||
try {
|
||||
return new Role(name, objectNameList);
|
||||
} catch (IllegalArgumentException exc) {
|
||||
return null; // can't happen
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string for the given role value.
|
||||
*
|
||||
* @param roleValue List of ObjectName objects
|
||||
*
|
||||
* @return A String consisting of the ObjectNames separated by
|
||||
* newlines (\n).
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
*/
|
||||
public static String roleValueToString(List<ObjectName> roleValue)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
if (roleValue == null) {
|
||||
String excMsg = "Invalid parameter";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (ObjectName currObjName : roleValue) {
|
||||
if (result.length() > 0)
|
||||
result.append("\n");
|
||||
result.append(currObjName.toString());
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a {@link Role} from an {@link ObjectInputStream}.
|
||||
*/
|
||||
private void readObject(ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException {
|
||||
if (compat)
|
||||
{
|
||||
// Read an object serialized in the old serial form
|
||||
//
|
||||
ObjectInputStream.GetField fields = in.readFields();
|
||||
name = (String) fields.get("myName", null);
|
||||
if (fields.defaulted("myName"))
|
||||
{
|
||||
throw new NullPointerException("myName");
|
||||
}
|
||||
objectNameList = cast(fields.get("myObjNameList", null));
|
||||
if (fields.defaulted("myObjNameList"))
|
||||
{
|
||||
throw new NullPointerException("myObjNameList");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Read an object serialized in the new serial form
|
||||
//
|
||||
in.defaultReadObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serializes a {@link Role} to an {@link ObjectOutputStream}.
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream out)
|
||||
throws IOException {
|
||||
if (compat)
|
||||
{
|
||||
// Serializes this instance in the old serial form
|
||||
//
|
||||
ObjectOutputStream.PutField fields = out.putFields();
|
||||
fields.put("myName", name);
|
||||
fields.put("myObjNameList", objectNameList);
|
||||
out.writeFields();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Serializes this instance in the new serial form
|
||||
//
|
||||
out.defaultWriteObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
609
jdkSrc/jdk8/javax/management/relation/RoleInfo.java
Normal file
609
jdkSrc/jdk8/javax/management/relation/RoleInfo.java
Normal file
@@ -0,0 +1,609 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
|
||||
import com.sun.jmx.mbeanserver.GetPropertyAction;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamField;
|
||||
import java.io.Serializable;
|
||||
import java.security.AccessController;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
|
||||
import javax.management.NotCompliantMBeanException;
|
||||
|
||||
/**
|
||||
* A RoleInfo object summarises a role in a relation type.
|
||||
*
|
||||
* <p>The <b>serialVersionUID</b> of this class is <code>2504952983494636987L</code>.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
@SuppressWarnings("serial") // serialVersionUID not constant
|
||||
public class RoleInfo implements Serializable {
|
||||
|
||||
// Serialization compatibility stuff:
|
||||
// Two serial forms are supported in this class. The selected form depends
|
||||
// on system property "jmx.serial.form":
|
||||
// - "1.0" for JMX 1.0
|
||||
// - any other value for JMX 1.1 and higher
|
||||
//
|
||||
// Serial version for old serial form
|
||||
private static final long oldSerialVersionUID = 7227256952085334351L;
|
||||
//
|
||||
// Serial version for new serial form
|
||||
private static final long newSerialVersionUID = 2504952983494636987L;
|
||||
//
|
||||
// Serializable fields in old serial form
|
||||
private static final ObjectStreamField[] oldSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("myName", String.class),
|
||||
new ObjectStreamField("myIsReadableFlg", boolean.class),
|
||||
new ObjectStreamField("myIsWritableFlg", boolean.class),
|
||||
new ObjectStreamField("myDescription", String.class),
|
||||
new ObjectStreamField("myMinDegree", int.class),
|
||||
new ObjectStreamField("myMaxDegree", int.class),
|
||||
new ObjectStreamField("myRefMBeanClassName", String.class)
|
||||
};
|
||||
//
|
||||
// Serializable fields in new serial form
|
||||
private static final ObjectStreamField[] newSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("name", String.class),
|
||||
new ObjectStreamField("isReadable", boolean.class),
|
||||
new ObjectStreamField("isWritable", boolean.class),
|
||||
new ObjectStreamField("description", String.class),
|
||||
new ObjectStreamField("minDegree", int.class),
|
||||
new ObjectStreamField("maxDegree", int.class),
|
||||
new ObjectStreamField("referencedMBeanClassName", String.class)
|
||||
};
|
||||
//
|
||||
// Actual serial version and serial form
|
||||
private static final long serialVersionUID;
|
||||
/**
|
||||
* @serialField name String Role name
|
||||
* @serialField isReadable boolean Read access mode: <code>true</code> if role is readable
|
||||
* @serialField isWritable boolean Write access mode: <code>true</code> if role is writable
|
||||
* @serialField description String Role description
|
||||
* @serialField minDegree int Minimum degree (i.e. minimum number of referenced MBeans in corresponding role)
|
||||
* @serialField maxDegree int Maximum degree (i.e. maximum number of referenced MBeans in corresponding role)
|
||||
* @serialField referencedMBeanClassName String Name of class of MBean(s) expected to be referenced in corresponding role
|
||||
*/
|
||||
private static final ObjectStreamField[] serialPersistentFields;
|
||||
private static boolean compat = false;
|
||||
static {
|
||||
try {
|
||||
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
|
||||
String form = AccessController.doPrivileged(act);
|
||||
compat = (form != null && form.equals("1.0"));
|
||||
} catch (Exception e) {
|
||||
// OK : Too bad, no compat with 1.0
|
||||
}
|
||||
if (compat) {
|
||||
serialPersistentFields = oldSerialPersistentFields;
|
||||
serialVersionUID = oldSerialVersionUID;
|
||||
} else {
|
||||
serialPersistentFields = newSerialPersistentFields;
|
||||
serialVersionUID = newSerialVersionUID;
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Serialization compatibility stuff
|
||||
|
||||
//
|
||||
// Public constants
|
||||
//
|
||||
|
||||
/**
|
||||
* To specify an unlimited cardinality.
|
||||
*/
|
||||
public static final int ROLE_CARDINALITY_INFINITY = -1;
|
||||
|
||||
//
|
||||
// Private members
|
||||
//
|
||||
|
||||
/**
|
||||
* @serial Role name
|
||||
*/
|
||||
private String name = null;
|
||||
|
||||
/**
|
||||
* @serial Read access mode: <code>true</code> if role is readable
|
||||
*/
|
||||
private boolean isReadable;
|
||||
|
||||
/**
|
||||
* @serial Write access mode: <code>true</code> if role is writable
|
||||
*/
|
||||
private boolean isWritable;
|
||||
|
||||
/**
|
||||
* @serial Role description
|
||||
*/
|
||||
private String description = null;
|
||||
|
||||
/**
|
||||
* @serial Minimum degree (i.e. minimum number of referenced MBeans in corresponding role)
|
||||
*/
|
||||
private int minDegree;
|
||||
|
||||
/**
|
||||
* @serial Maximum degree (i.e. maximum number of referenced MBeans in corresponding role)
|
||||
*/
|
||||
private int maxDegree;
|
||||
|
||||
/**
|
||||
* @serial Name of class of MBean(s) expected to be referenced in corresponding role
|
||||
*/
|
||||
private String referencedMBeanClassName = null;
|
||||
|
||||
//
|
||||
// Constructors
|
||||
//
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param roleName name of the role.
|
||||
* @param mbeanClassName name of the class of MBean(s) expected to
|
||||
* be referenced in corresponding role. If an MBean <em>M</em> is in
|
||||
* this role, then the MBean server must return true for
|
||||
* {@link MBeanServer#isInstanceOf isInstanceOf(M, mbeanClassName)}.
|
||||
* @param read flag to indicate if the corresponding role
|
||||
* can be read
|
||||
* @param write flag to indicate if the corresponding role
|
||||
* can be set
|
||||
* @param min minimum degree for role, i.e. minimum number of
|
||||
* MBeans to provide in corresponding role
|
||||
* Must be less than or equal to <tt>max</tt>.
|
||||
* (ROLE_CARDINALITY_INFINITY for unlimited)
|
||||
* @param max maximum degree for role, i.e. maximum number of
|
||||
* MBeans to provide in corresponding role
|
||||
* Must be greater than or equal to <tt>min</tt>
|
||||
* (ROLE_CARDINALITY_INFINITY for unlimited)
|
||||
* @param descr description of the role (can be null)
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception InvalidRoleInfoException if the minimum degree is
|
||||
* greater than the maximum degree.
|
||||
* @exception ClassNotFoundException As of JMX 1.2, this exception
|
||||
* can no longer be thrown. It is retained in the declaration of
|
||||
* this class for compatibility with existing code.
|
||||
* @exception NotCompliantMBeanException if the class mbeanClassName
|
||||
* is not a MBean class.
|
||||
*/
|
||||
public RoleInfo(String roleName,
|
||||
String mbeanClassName,
|
||||
boolean read,
|
||||
boolean write,
|
||||
int min,
|
||||
int max,
|
||||
String descr)
|
||||
throws IllegalArgumentException,
|
||||
InvalidRoleInfoException,
|
||||
ClassNotFoundException,
|
||||
NotCompliantMBeanException {
|
||||
|
||||
init(roleName,
|
||||
mbeanClassName,
|
||||
read,
|
||||
write,
|
||||
min,
|
||||
max,
|
||||
descr);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param roleName name of the role
|
||||
* @param mbeanClassName name of the class of MBean(s) expected to
|
||||
* be referenced in corresponding role. If an MBean <em>M</em> is in
|
||||
* this role, then the MBean server must return true for
|
||||
* {@link MBeanServer#isInstanceOf isInstanceOf(M, mbeanClassName)}.
|
||||
* @param read flag to indicate if the corresponding role
|
||||
* can be read
|
||||
* @param write flag to indicate if the corresponding role
|
||||
* can be set
|
||||
*
|
||||
* <P>Minimum and maximum degrees defaulted to 1.
|
||||
* <P>Description of role defaulted to null.
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception ClassNotFoundException As of JMX 1.2, this exception
|
||||
* can no longer be thrown. It is retained in the declaration of
|
||||
* this class for compatibility with existing code.
|
||||
* @exception NotCompliantMBeanException As of JMX 1.2, this
|
||||
* exception can no longer be thrown. It is retained in the
|
||||
* declaration of this class for compatibility with existing code.
|
||||
*/
|
||||
public RoleInfo(String roleName,
|
||||
String mbeanClassName,
|
||||
boolean read,
|
||||
boolean write)
|
||||
throws IllegalArgumentException,
|
||||
ClassNotFoundException,
|
||||
NotCompliantMBeanException {
|
||||
|
||||
try {
|
||||
init(roleName,
|
||||
mbeanClassName,
|
||||
read,
|
||||
write,
|
||||
1,
|
||||
1,
|
||||
null);
|
||||
} catch (InvalidRoleInfoException exc) {
|
||||
// OK : Can never happen as the minimum
|
||||
// degree equals the maximum degree.
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param roleName name of the role
|
||||
* @param mbeanClassName name of the class of MBean(s) expected to
|
||||
* be referenced in corresponding role. If an MBean <em>M</em> is in
|
||||
* this role, then the MBean server must return true for
|
||||
* {@link MBeanServer#isInstanceOf isInstanceOf(M, mbeanClassName)}.
|
||||
*
|
||||
* <P>IsReadable and IsWritable defaulted to true.
|
||||
* <P>Minimum and maximum degrees defaulted to 1.
|
||||
* <P>Description of role defaulted to null.
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
* @exception ClassNotFoundException As of JMX 1.2, this exception
|
||||
* can no longer be thrown. It is retained in the declaration of
|
||||
* this class for compatibility with existing code.
|
||||
* @exception NotCompliantMBeanException As of JMX 1.2, this
|
||||
* exception can no longer be thrown. It is retained in the
|
||||
* declaration of this class for compatibility with existing code.
|
||||
*/
|
||||
public RoleInfo(String roleName,
|
||||
String mbeanClassName)
|
||||
throws IllegalArgumentException,
|
||||
ClassNotFoundException,
|
||||
NotCompliantMBeanException {
|
||||
|
||||
try {
|
||||
init(roleName,
|
||||
mbeanClassName,
|
||||
true,
|
||||
true,
|
||||
1,
|
||||
1,
|
||||
null);
|
||||
} catch (InvalidRoleInfoException exc) {
|
||||
// OK : Can never happen as the minimum
|
||||
// degree equals the maximum degree.
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param roleInfo the <tt>RoleInfo</tt> instance to be copied.
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
*/
|
||||
public RoleInfo(RoleInfo roleInfo)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
if (roleInfo == null) {
|
||||
// Revisit [cebro] Localize message
|
||||
String excMsg = "Invalid parameter.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
try {
|
||||
init(roleInfo.getName(),
|
||||
roleInfo.getRefMBeanClassName(),
|
||||
roleInfo.isReadable(),
|
||||
roleInfo.isWritable(),
|
||||
roleInfo.getMinDegree(),
|
||||
roleInfo.getMaxDegree(),
|
||||
roleInfo.getDescription());
|
||||
} catch (InvalidRoleInfoException exc3) {
|
||||
// OK : Can never happen as the minimum degree and the maximum
|
||||
// degree were already checked at the time the roleInfo
|
||||
// instance was created.
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Accessors
|
||||
//
|
||||
|
||||
/**
|
||||
* Returns the name of the role.
|
||||
*
|
||||
* @return the name of the role.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns read access mode for the role (true if it is readable).
|
||||
*
|
||||
* @return true if the role is readable.
|
||||
*/
|
||||
public boolean isReadable() {
|
||||
return isReadable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns write access mode for the role (true if it is writable).
|
||||
*
|
||||
* @return true if the role is writable.
|
||||
*/
|
||||
public boolean isWritable() {
|
||||
return isWritable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description text for the role.
|
||||
*
|
||||
* @return the description of the role.
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum degree for corresponding role reference.
|
||||
*
|
||||
* @return the minimum degree.
|
||||
*/
|
||||
public int getMinDegree() {
|
||||
return minDegree;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns maximum degree for corresponding role reference.
|
||||
*
|
||||
* @return the maximum degree.
|
||||
*/
|
||||
public int getMaxDegree() {
|
||||
return maxDegree;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Returns name of type of MBean expected to be referenced in
|
||||
* corresponding role.</p>
|
||||
*
|
||||
* @return the name of the referenced type.
|
||||
*/
|
||||
public String getRefMBeanClassName() {
|
||||
return referencedMBeanClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the <tt>value</tt> parameter is greater than or equal to
|
||||
* the expected minimum degree, false otherwise.
|
||||
*
|
||||
* @param value the value to be checked
|
||||
*
|
||||
* @return true if greater than or equal to minimum degree, false otherwise.
|
||||
*/
|
||||
public boolean checkMinDegree(int value) {
|
||||
if (value >= ROLE_CARDINALITY_INFINITY &&
|
||||
(minDegree == ROLE_CARDINALITY_INFINITY
|
||||
|| value >= minDegree)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the <tt>value</tt> parameter is lower than or equal to
|
||||
* the expected maximum degree, false otherwise.
|
||||
*
|
||||
* @param value the value to be checked
|
||||
*
|
||||
* @return true if lower than or equal to maximum degree, false otherwise.
|
||||
*/
|
||||
public boolean checkMaxDegree(int value) {
|
||||
if (value >= ROLE_CARDINALITY_INFINITY &&
|
||||
(maxDegree == ROLE_CARDINALITY_INFINITY ||
|
||||
(value != ROLE_CARDINALITY_INFINITY &&
|
||||
value <= maxDegree))) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string describing the role info.
|
||||
*
|
||||
* @return a description of the role info.
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("role info name: " + name);
|
||||
result.append("; isReadable: " + isReadable);
|
||||
result.append("; isWritable: " + isWritable);
|
||||
result.append("; description: " + description);
|
||||
result.append("; minimum degree: " + minDegree);
|
||||
result.append("; maximum degree: " + maxDegree);
|
||||
result.append("; MBean class: " + referencedMBeanClassName);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
//
|
||||
// Misc
|
||||
//
|
||||
|
||||
// Initialization
|
||||
private void init(String roleName,
|
||||
String mbeanClassName,
|
||||
boolean read,
|
||||
boolean write,
|
||||
int min,
|
||||
int max,
|
||||
String descr)
|
||||
throws IllegalArgumentException,
|
||||
InvalidRoleInfoException {
|
||||
|
||||
if (roleName == null ||
|
||||
mbeanClassName == null) {
|
||||
// Revisit [cebro] Localize message
|
||||
String excMsg = "Invalid parameter.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
name = roleName;
|
||||
isReadable = read;
|
||||
isWritable = write;
|
||||
if (descr != null) {
|
||||
description = descr;
|
||||
}
|
||||
|
||||
boolean invalidRoleInfoFlg = false;
|
||||
StringBuilder excMsgStrB = new StringBuilder();
|
||||
if (max != ROLE_CARDINALITY_INFINITY &&
|
||||
(min == ROLE_CARDINALITY_INFINITY ||
|
||||
min > max)) {
|
||||
// Revisit [cebro] Localize message
|
||||
excMsgStrB.append("Minimum degree ");
|
||||
excMsgStrB.append(min);
|
||||
excMsgStrB.append(" is greater than maximum degree ");
|
||||
excMsgStrB.append(max);
|
||||
invalidRoleInfoFlg = true;
|
||||
|
||||
} else if (min < ROLE_CARDINALITY_INFINITY ||
|
||||
max < ROLE_CARDINALITY_INFINITY) {
|
||||
// Revisit [cebro] Localize message
|
||||
excMsgStrB.append("Minimum or maximum degree has an illegal value, must be [0, ROLE_CARDINALITY_INFINITY].");
|
||||
invalidRoleInfoFlg = true;
|
||||
}
|
||||
if (invalidRoleInfoFlg) {
|
||||
throw new InvalidRoleInfoException(excMsgStrB.toString());
|
||||
}
|
||||
minDegree = min;
|
||||
maxDegree = max;
|
||||
|
||||
referencedMBeanClassName = mbeanClassName;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a {@link RoleInfo} from an {@link ObjectInputStream}.
|
||||
*/
|
||||
private void readObject(ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException {
|
||||
if (compat)
|
||||
{
|
||||
// Read an object serialized in the old serial form
|
||||
//
|
||||
ObjectInputStream.GetField fields = in.readFields();
|
||||
name = (String) fields.get("myName", null);
|
||||
if (fields.defaulted("myName"))
|
||||
{
|
||||
throw new NullPointerException("myName");
|
||||
}
|
||||
isReadable = fields.get("myIsReadableFlg", false);
|
||||
if (fields.defaulted("myIsReadableFlg"))
|
||||
{
|
||||
throw new NullPointerException("myIsReadableFlg");
|
||||
}
|
||||
isWritable = fields.get("myIsWritableFlg", false);
|
||||
if (fields.defaulted("myIsWritableFlg"))
|
||||
{
|
||||
throw new NullPointerException("myIsWritableFlg");
|
||||
}
|
||||
description = (String) fields.get("myDescription", null);
|
||||
if (fields.defaulted("myDescription"))
|
||||
{
|
||||
throw new NullPointerException("myDescription");
|
||||
}
|
||||
minDegree = fields.get("myMinDegree", 0);
|
||||
if (fields.defaulted("myMinDegree"))
|
||||
{
|
||||
throw new NullPointerException("myMinDegree");
|
||||
}
|
||||
maxDegree = fields.get("myMaxDegree", 0);
|
||||
if (fields.defaulted("myMaxDegree"))
|
||||
{
|
||||
throw new NullPointerException("myMaxDegree");
|
||||
}
|
||||
referencedMBeanClassName = (String) fields.get("myRefMBeanClassName", null);
|
||||
if (fields.defaulted("myRefMBeanClassName"))
|
||||
{
|
||||
throw new NullPointerException("myRefMBeanClassName");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Read an object serialized in the new serial form
|
||||
//
|
||||
in.defaultReadObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serializes a {@link RoleInfo} to an {@link ObjectOutputStream}.
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream out)
|
||||
throws IOException {
|
||||
if (compat)
|
||||
{
|
||||
// Serializes this instance in the old serial form
|
||||
//
|
||||
ObjectOutputStream.PutField fields = out.putFields();
|
||||
fields.put("myName", name);
|
||||
fields.put("myIsReadableFlg", isReadable);
|
||||
fields.put("myIsWritableFlg", isWritable);
|
||||
fields.put("myDescription", description);
|
||||
fields.put("myMinDegree", minDegree);
|
||||
fields.put("myMaxDegree", maxDegree);
|
||||
fields.put("myRefMBeanClassName", referencedMBeanClassName);
|
||||
out.writeFields();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Serializes this instance in the new serial form
|
||||
//
|
||||
out.defaultWriteObject();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
/**
|
||||
* This exception is raised when there is no role info with given name in a
|
||||
* given relation type.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class RoleInfoNotFoundException extends RelationException {
|
||||
|
||||
/* Serial version */
|
||||
private static final long serialVersionUID = 4394092234999959939L;
|
||||
|
||||
/**
|
||||
* Default constructor, no message put in exception.
|
||||
*/
|
||||
public RoleInfoNotFoundException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given message put in exception.
|
||||
*
|
||||
* @param message the detail message.
|
||||
*/
|
||||
public RoleInfoNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
373
jdkSrc/jdk8/javax/management/relation/RoleList.java
Normal file
373
jdkSrc/jdk8/javax/management/relation/RoleList.java
Normal file
@@ -0,0 +1,373 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
import com.sun.jmx.mbeanserver.Util;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A RoleList represents a list of roles (Role objects). It is used as
|
||||
* parameter when creating a relation, and when trying to set several roles in
|
||||
* a relation (via 'setRoles()' method). It is returned as part of a
|
||||
* RoleResult, to provide roles successfully retrieved.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
/* We cannot extend ArrayList<Role> because our legacy
|
||||
add(Role) method would then override add(E) in ArrayList<E>,
|
||||
and our return value is void whereas ArrayList.add(E)'s is boolean.
|
||||
Likewise for set(int,Role). Grrr. We cannot use covariance
|
||||
to override the most important methods and have them return
|
||||
Role, either, because that would break subclasses that
|
||||
override those methods in turn (using the original return type
|
||||
of Object). Finally, we cannot implement Iterable<Role>
|
||||
so you could write
|
||||
for (Role r : roleList)
|
||||
because ArrayList<> implements Iterable<> and the same class cannot
|
||||
implement two versions of a generic interface. Instead we provide
|
||||
the asList() method so you can write
|
||||
for (Role r : roleList.asList())
|
||||
*/
|
||||
public class RoleList extends ArrayList<Object> {
|
||||
|
||||
private transient boolean typeSafe;
|
||||
private transient boolean tainted;
|
||||
|
||||
/* Serial version */
|
||||
private static final long serialVersionUID = 5568344346499649313L;
|
||||
|
||||
//
|
||||
// Constructors
|
||||
//
|
||||
|
||||
/**
|
||||
* Constructs an empty RoleList.
|
||||
*/
|
||||
public RoleList() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an empty RoleList with the initial capacity
|
||||
* specified.
|
||||
*
|
||||
* @param initialCapacity initial capacity
|
||||
*/
|
||||
public RoleList(int initialCapacity) {
|
||||
super(initialCapacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@code RoleList} containing the elements of the
|
||||
* {@code List} specified, in the order in which they are returned by
|
||||
* the {@code List}'s iterator. The {@code RoleList} instance has
|
||||
* an initial capacity of 110% of the size of the {@code List}
|
||||
* specified.
|
||||
*
|
||||
* @param list the {@code List} that defines the initial contents of
|
||||
* the new {@code RoleList}.
|
||||
*
|
||||
* @exception IllegalArgumentException if the {@code list} parameter
|
||||
* is {@code null} or if the {@code list} parameter contains any
|
||||
* non-Role objects.
|
||||
*
|
||||
* @see ArrayList#ArrayList(java.util.Collection)
|
||||
*/
|
||||
public RoleList(List<Role> list) throws IllegalArgumentException {
|
||||
// Check for null parameter
|
||||
//
|
||||
if (list == null)
|
||||
throw new IllegalArgumentException("Null parameter");
|
||||
|
||||
// Check for non-Role objects
|
||||
//
|
||||
checkTypeSafe(list);
|
||||
|
||||
// Build the List<Role>
|
||||
//
|
||||
super.addAll(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a view of this list as a {@code List<Role>}.
|
||||
* Changes to the returned value are reflected by changes
|
||||
* to the original {@code RoleList} and vice versa.
|
||||
*
|
||||
* @return a {@code List<Role>} whose contents
|
||||
* reflect the contents of this {@code RoleList}.
|
||||
*
|
||||
* <p>If this method has ever been called on a given
|
||||
* {@code RoleList} instance, a subsequent attempt to add
|
||||
* an object to that instance which is not a {@code Role}
|
||||
* will fail with an {@code IllegalArgumentException}. For compatibility
|
||||
* reasons, a {@code RoleList} on which this method has never
|
||||
* been called does allow objects other than {@code Role}s to
|
||||
* be added.</p>
|
||||
*
|
||||
* @throws IllegalArgumentException if this {@code RoleList} contains
|
||||
* an element that is not a {@code Role}.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Role> asList() {
|
||||
if (!typeSafe) {
|
||||
if (tainted)
|
||||
checkTypeSafe(this);
|
||||
typeSafe = true;
|
||||
}
|
||||
return Util.cast(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Accessors
|
||||
//
|
||||
|
||||
/**
|
||||
* Adds the Role specified as the last element of the list.
|
||||
*
|
||||
* @param role the role to be added.
|
||||
*
|
||||
* @exception IllegalArgumentException if the role is null.
|
||||
*/
|
||||
public void add(Role role)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
if (role == null) {
|
||||
String excMsg = "Invalid parameter";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
super.add(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the role specified as an element at the position specified.
|
||||
* Elements with an index greater than or equal to the current position are
|
||||
* shifted up.
|
||||
*
|
||||
* @param index The position in the list where the new Role
|
||||
* object is to be inserted.
|
||||
* @param role The Role object to be inserted.
|
||||
*
|
||||
* @exception IllegalArgumentException if the role is null.
|
||||
* @exception IndexOutOfBoundsException if accessing with an index
|
||||
* outside of the list.
|
||||
*/
|
||||
public void add(int index,
|
||||
Role role)
|
||||
throws IllegalArgumentException,
|
||||
IndexOutOfBoundsException {
|
||||
|
||||
if (role == null) {
|
||||
String excMsg = "Invalid parameter";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
super.add(index, role);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the element at the position specified to be the role
|
||||
* specified.
|
||||
* The previous element at that position is discarded.
|
||||
*
|
||||
* @param index The position specified.
|
||||
* @param role The value to which the role element should be set.
|
||||
*
|
||||
* @exception IllegalArgumentException if the role is null.
|
||||
* @exception IndexOutOfBoundsException if accessing with an index
|
||||
* outside of the list.
|
||||
*/
|
||||
public void set(int index,
|
||||
Role role)
|
||||
throws IllegalArgumentException,
|
||||
IndexOutOfBoundsException {
|
||||
|
||||
if (role == null) {
|
||||
// Revisit [cebro] Localize message
|
||||
String excMsg = "Invalid parameter.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
super.set(index, role);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all the elements in the RoleList specified to the end
|
||||
* of the list, in the order in which they are returned by the Iterator of
|
||||
* the RoleList specified.
|
||||
*
|
||||
* @param roleList Elements to be inserted into the list (can be null)
|
||||
*
|
||||
* @return true if this list changed as a result of the call.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException if accessing with an index
|
||||
* outside of the list.
|
||||
*
|
||||
* @see ArrayList#addAll(Collection)
|
||||
*/
|
||||
public boolean addAll(RoleList roleList)
|
||||
throws IndexOutOfBoundsException {
|
||||
|
||||
if (roleList == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (super.addAll(roleList));
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts all of the elements in the RoleList specified into this
|
||||
* list, starting at the specified position, in the order in which they are
|
||||
* returned by the Iterator of the RoleList specified.
|
||||
*
|
||||
* @param index Position at which to insert the first element from the
|
||||
* RoleList specified.
|
||||
* @param roleList Elements to be inserted into the list.
|
||||
*
|
||||
* @return true if this list changed as a result of the call.
|
||||
*
|
||||
* @exception IllegalArgumentException if the role is null.
|
||||
* @exception IndexOutOfBoundsException if accessing with an index
|
||||
* outside of the list.
|
||||
*
|
||||
* @see ArrayList#addAll(int, Collection)
|
||||
*/
|
||||
public boolean addAll(int index,
|
||||
RoleList roleList)
|
||||
throws IllegalArgumentException,
|
||||
IndexOutOfBoundsException {
|
||||
|
||||
if (roleList == null) {
|
||||
// Revisit [cebro] Localize message
|
||||
String excMsg = "Invalid parameter.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
return (super.addAll(index, roleList));
|
||||
}
|
||||
|
||||
/*
|
||||
* Override all of the methods from ArrayList<Object> that might add
|
||||
* a non-Role to the List, and disallow that if asList has ever
|
||||
* been called on this instance.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean add(Object o) {
|
||||
if (!tainted)
|
||||
tainted = isTainted(o);
|
||||
if (typeSafe)
|
||||
checkTypeSafe(o);
|
||||
return super.add(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, Object element) {
|
||||
if (!tainted)
|
||||
tainted = isTainted(element);
|
||||
if (typeSafe)
|
||||
checkTypeSafe(element);
|
||||
super.add(index, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<?> c) {
|
||||
if (!tainted)
|
||||
tainted = isTainted(c);
|
||||
if (typeSafe)
|
||||
checkTypeSafe(c);
|
||||
return super.addAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, Collection<?> c) {
|
||||
if (!tainted)
|
||||
tainted = isTainted(c);
|
||||
if (typeSafe)
|
||||
checkTypeSafe(c);
|
||||
return super.addAll(index, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object set(int index, Object element) {
|
||||
if (!tainted)
|
||||
tainted = isTainted(element);
|
||||
if (typeSafe)
|
||||
checkTypeSafe(element);
|
||||
return super.set(index, element);
|
||||
}
|
||||
|
||||
/**
|
||||
* IllegalArgumentException if o is a non-Role object.
|
||||
*/
|
||||
private static void checkTypeSafe(Object o) {
|
||||
try {
|
||||
o = (Role) o;
|
||||
} catch (ClassCastException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* IllegalArgumentException if c contains any non-Role objects.
|
||||
*/
|
||||
private static void checkTypeSafe(Collection<?> c) {
|
||||
try {
|
||||
Role r;
|
||||
for (Object o : c)
|
||||
r = (Role) o;
|
||||
} catch (ClassCastException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if o is a non-Role object.
|
||||
*/
|
||||
private static boolean isTainted(Object o) {
|
||||
try {
|
||||
checkTypeSafe(o);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if c contains any non-Role objects.
|
||||
*/
|
||||
private static boolean isTainted(Collection<?> c) {
|
||||
try {
|
||||
checkTypeSafe(c);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
/**
|
||||
* This exception is raised when a role in a relation does not exist, or is not
|
||||
* readable, or is not settable.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class RoleNotFoundException extends RelationException {
|
||||
|
||||
/* Serial version */
|
||||
private static final long serialVersionUID = -2986406101364031481L;
|
||||
|
||||
/**
|
||||
* Default constructor, no message put in exception.
|
||||
*/
|
||||
public RoleNotFoundException() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor with given message put in exception.
|
||||
*
|
||||
* @param message the detail message.
|
||||
*/
|
||||
public RoleNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
261
jdkSrc/jdk8/javax/management/relation/RoleResult.java
Normal file
261
jdkSrc/jdk8/javax/management/relation/RoleResult.java
Normal file
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
|
||||
import com.sun.jmx.mbeanserver.GetPropertyAction;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamField;
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* Represents the result of a multiple access to several roles of a relation
|
||||
* (either for reading or writing).
|
||||
*
|
||||
* <p>The <b>serialVersionUID</b> of this class is <code>-6304063118040985512L</code>.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class RoleResult implements Serializable {
|
||||
|
||||
// Serialization compatibility stuff:
|
||||
// Two serial forms are supported in this class. The selected form depends
|
||||
// on system property "jmx.serial.form":
|
||||
// - "1.0" for JMX 1.0
|
||||
// - any other value for JMX 1.1 and higher
|
||||
//
|
||||
// Serial version for old serial form
|
||||
private static final long oldSerialVersionUID = 3786616013762091099L;
|
||||
//
|
||||
// Serial version for new serial form
|
||||
private static final long newSerialVersionUID = -6304063118040985512L;
|
||||
//
|
||||
// Serializable fields in old serial form
|
||||
private static final ObjectStreamField[] oldSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("myRoleList", RoleList.class),
|
||||
new ObjectStreamField("myRoleUnresList", RoleUnresolvedList.class)
|
||||
};
|
||||
//
|
||||
// Serializable fields in new serial form
|
||||
private static final ObjectStreamField[] newSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("roleList", RoleList.class),
|
||||
new ObjectStreamField("unresolvedRoleList", RoleUnresolvedList.class)
|
||||
};
|
||||
//
|
||||
// Actual serial version and serial form
|
||||
private static final long serialVersionUID;
|
||||
/**
|
||||
* @serialField roleList RoleList List of roles successfully accessed
|
||||
* @serialField unresolvedRoleList RoleUnresolvedList List of roles unsuccessfully accessed
|
||||
*/
|
||||
private static final ObjectStreamField[] serialPersistentFields;
|
||||
private static boolean compat = false;
|
||||
static {
|
||||
try {
|
||||
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
|
||||
String form = AccessController.doPrivileged(act);
|
||||
compat = (form != null && form.equals("1.0"));
|
||||
} catch (Exception e) {
|
||||
// OK : Too bad, no compat with 1.0
|
||||
}
|
||||
if (compat) {
|
||||
serialPersistentFields = oldSerialPersistentFields;
|
||||
serialVersionUID = oldSerialVersionUID;
|
||||
} else {
|
||||
serialPersistentFields = newSerialPersistentFields;
|
||||
serialVersionUID = newSerialVersionUID;
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Serialization compatibility stuff
|
||||
|
||||
//
|
||||
// Private members
|
||||
//
|
||||
|
||||
/**
|
||||
* @serial List of roles successfully accessed
|
||||
*/
|
||||
private RoleList roleList = null;
|
||||
|
||||
/**
|
||||
* @serial List of roles unsuccessfully accessed
|
||||
*/
|
||||
private RoleUnresolvedList unresolvedRoleList = null;
|
||||
|
||||
//
|
||||
// Constructor
|
||||
//
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param list list of roles successfully accessed.
|
||||
* @param unresolvedList list of roles not accessed (with problem
|
||||
* descriptions).
|
||||
*/
|
||||
public RoleResult(RoleList list,
|
||||
RoleUnresolvedList unresolvedList) {
|
||||
|
||||
setRoles(list);
|
||||
setRolesUnresolved(unresolvedList);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Accessors
|
||||
//
|
||||
|
||||
/**
|
||||
* Retrieves list of roles successfully accessed.
|
||||
*
|
||||
* @return a RoleList
|
||||
*
|
||||
* @see #setRoles
|
||||
*/
|
||||
public RoleList getRoles() {
|
||||
return roleList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves list of roles unsuccessfully accessed.
|
||||
*
|
||||
* @return a RoleUnresolvedList.
|
||||
*
|
||||
* @see #setRolesUnresolved
|
||||
*/
|
||||
public RoleUnresolvedList getRolesUnresolved() {
|
||||
return unresolvedRoleList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets list of roles successfully accessed.
|
||||
*
|
||||
* @param list list of roles successfully accessed
|
||||
*
|
||||
* @see #getRoles
|
||||
*/
|
||||
public void setRoles(RoleList list) {
|
||||
if (list != null) {
|
||||
|
||||
roleList = new RoleList();
|
||||
|
||||
for (Iterator<?> roleIter = list.iterator();
|
||||
roleIter.hasNext();) {
|
||||
Role currRole = (Role)(roleIter.next());
|
||||
roleList.add((Role)(currRole.clone()));
|
||||
}
|
||||
} else {
|
||||
roleList = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets list of roles unsuccessfully accessed.
|
||||
*
|
||||
* @param unresolvedList list of roles unsuccessfully accessed
|
||||
*
|
||||
* @see #getRolesUnresolved
|
||||
*/
|
||||
public void setRolesUnresolved(RoleUnresolvedList unresolvedList) {
|
||||
if (unresolvedList != null) {
|
||||
|
||||
unresolvedRoleList = new RoleUnresolvedList();
|
||||
|
||||
for (Iterator<?> roleUnresIter = unresolvedList.iterator();
|
||||
roleUnresIter.hasNext();) {
|
||||
RoleUnresolved currRoleUnres =
|
||||
(RoleUnresolved)(roleUnresIter.next());
|
||||
unresolvedRoleList.add((RoleUnresolved)(currRoleUnres.clone()));
|
||||
}
|
||||
} else {
|
||||
unresolvedRoleList = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a {@link RoleResult} from an {@link ObjectInputStream}.
|
||||
*/
|
||||
private void readObject(ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException {
|
||||
if (compat)
|
||||
{
|
||||
// Read an object serialized in the old serial form
|
||||
//
|
||||
ObjectInputStream.GetField fields = in.readFields();
|
||||
roleList = (RoleList) fields.get("myRoleList", null);
|
||||
if (fields.defaulted("myRoleList"))
|
||||
{
|
||||
throw new NullPointerException("myRoleList");
|
||||
}
|
||||
unresolvedRoleList = (RoleUnresolvedList) fields.get("myRoleUnresList", null);
|
||||
if (fields.defaulted("myRoleUnresList"))
|
||||
{
|
||||
throw new NullPointerException("myRoleUnresList");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Read an object serialized in the new serial form
|
||||
//
|
||||
in.defaultReadObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serializes a {@link RoleResult} to an {@link ObjectOutputStream}.
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream out)
|
||||
throws IOException {
|
||||
if (compat)
|
||||
{
|
||||
// Serializes this instance in the old serial form
|
||||
//
|
||||
ObjectOutputStream.PutField fields = out.putFields();
|
||||
fields.put("myRoleList", roleList);
|
||||
fields.put("myRoleUnresList", unresolvedRoleList);
|
||||
out.writeFields();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Serializes this instance in the new serial form
|
||||
//
|
||||
out.defaultWriteObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
93
jdkSrc/jdk8/javax/management/relation/RoleStatus.java
Normal file
93
jdkSrc/jdk8/javax/management/relation/RoleStatus.java
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
/**
|
||||
* This class describes the various problems which can be encountered when
|
||||
* accessing a role.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public class RoleStatus {
|
||||
|
||||
//
|
||||
// Possible problems
|
||||
//
|
||||
|
||||
/**
|
||||
* Problem type when trying to access an unknown role.
|
||||
*/
|
||||
public static final int NO_ROLE_WITH_NAME = 1;
|
||||
/**
|
||||
* Problem type when trying to read a non-readable attribute.
|
||||
*/
|
||||
public static final int ROLE_NOT_READABLE = 2;
|
||||
/**
|
||||
* Problem type when trying to update a non-writable attribute.
|
||||
*/
|
||||
public static final int ROLE_NOT_WRITABLE = 3;
|
||||
/**
|
||||
* Problem type when trying to set a role value with less ObjectNames than
|
||||
* the minimum expected cardinality.
|
||||
*/
|
||||
public static final int LESS_THAN_MIN_ROLE_DEGREE = 4;
|
||||
/**
|
||||
* Problem type when trying to set a role value with more ObjectNames than
|
||||
* the maximum expected cardinality.
|
||||
*/
|
||||
public static final int MORE_THAN_MAX_ROLE_DEGREE = 5;
|
||||
/**
|
||||
* Problem type when trying to set a role value including the ObjectName of
|
||||
* a MBean not of the class expected for that role.
|
||||
*/
|
||||
public static final int REF_MBEAN_OF_INCORRECT_CLASS = 6;
|
||||
/**
|
||||
* Problem type when trying to set a role value including the ObjectName of
|
||||
* a MBean not registered in the MBean Server.
|
||||
*/
|
||||
public static final int REF_MBEAN_NOT_REGISTERED = 7;
|
||||
|
||||
/**
|
||||
* Returns true if given value corresponds to a known role status, false
|
||||
* otherwise.
|
||||
*
|
||||
* @param status a status code.
|
||||
*
|
||||
* @return true if this value is a known role status.
|
||||
*/
|
||||
public static boolean isRoleStatus(int status) {
|
||||
if (status != NO_ROLE_WITH_NAME &&
|
||||
status != ROLE_NOT_READABLE &&
|
||||
status != ROLE_NOT_WRITABLE &&
|
||||
status != LESS_THAN_MIN_ROLE_DEGREE &&
|
||||
status != MORE_THAN_MAX_ROLE_DEGREE &&
|
||||
status != REF_MBEAN_OF_INCORRECT_CLASS &&
|
||||
status != REF_MBEAN_NOT_REGISTERED) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
358
jdkSrc/jdk8/javax/management/relation/RoleUnresolved.java
Normal file
358
jdkSrc/jdk8/javax/management/relation/RoleUnresolved.java
Normal file
@@ -0,0 +1,358 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
import static com.sun.jmx.mbeanserver.Util.cast;
|
||||
import com.sun.jmx.mbeanserver.GetPropertyAction;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.ObjectStreamField;
|
||||
import java.io.Serializable;
|
||||
|
||||
import java.security.AccessController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.management.ObjectName;
|
||||
|
||||
/**
|
||||
* Represents an unresolved role: a role not retrieved from a relation due
|
||||
* to a problem. It provides the role name, value (if problem when trying to
|
||||
* set the role) and an integer defining the problem (constants defined in
|
||||
* RoleStatus).
|
||||
*
|
||||
* <p>The <b>serialVersionUID</b> of this class is <code>-48350262537070138L</code>.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
@SuppressWarnings("serial") // serialVersionUID not constant
|
||||
public class RoleUnresolved implements Serializable {
|
||||
|
||||
// Serialization compatibility stuff:
|
||||
// Two serial forms are supported in this class. The selected form depends
|
||||
// on system property "jmx.serial.form":
|
||||
// - "1.0" for JMX 1.0
|
||||
// - any other value for JMX 1.1 and higher
|
||||
//
|
||||
// Serial version for old serial form
|
||||
private static final long oldSerialVersionUID = -9026457686611660144L;
|
||||
//
|
||||
// Serial version for new serial form
|
||||
private static final long newSerialVersionUID = -48350262537070138L;
|
||||
//
|
||||
// Serializable fields in old serial form
|
||||
private static final ObjectStreamField[] oldSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("myRoleName", String.class),
|
||||
new ObjectStreamField("myRoleValue", ArrayList.class),
|
||||
new ObjectStreamField("myPbType", int.class)
|
||||
};
|
||||
//
|
||||
// Serializable fields in new serial form
|
||||
private static final ObjectStreamField[] newSerialPersistentFields =
|
||||
{
|
||||
new ObjectStreamField("roleName", String.class),
|
||||
new ObjectStreamField("roleValue", List.class),
|
||||
new ObjectStreamField("problemType", int.class)
|
||||
};
|
||||
//
|
||||
// Actual serial version and serial form
|
||||
private static final long serialVersionUID;
|
||||
/** @serialField roleName String Role name
|
||||
* @serialField roleValue List Role value ({@link List} of {@link ObjectName} objects)
|
||||
* @serialField problemType int Problem type
|
||||
*/
|
||||
private static final ObjectStreamField[] serialPersistentFields;
|
||||
private static boolean compat = false;
|
||||
static {
|
||||
try {
|
||||
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
|
||||
String form = AccessController.doPrivileged(act);
|
||||
compat = (form != null && form.equals("1.0"));
|
||||
} catch (Exception e) {
|
||||
// OK : Too bad, no compat with 1.0
|
||||
}
|
||||
if (compat) {
|
||||
serialPersistentFields = oldSerialPersistentFields;
|
||||
serialVersionUID = oldSerialVersionUID;
|
||||
} else {
|
||||
serialPersistentFields = newSerialPersistentFields;
|
||||
serialVersionUID = newSerialVersionUID;
|
||||
}
|
||||
}
|
||||
//
|
||||
// END Serialization compatibility stuff
|
||||
|
||||
//
|
||||
// Private members
|
||||
//
|
||||
|
||||
/**
|
||||
* @serial Role name
|
||||
*/
|
||||
private String roleName = null;
|
||||
|
||||
/**
|
||||
* @serial Role value ({@link List} of {@link ObjectName} objects)
|
||||
*/
|
||||
private List<ObjectName> roleValue = null;
|
||||
|
||||
/**
|
||||
* @serial Problem type
|
||||
*/
|
||||
private int problemType;
|
||||
|
||||
//
|
||||
// Constructor
|
||||
//
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param name name of the role
|
||||
* @param value value of the role (if problem when setting the
|
||||
* role)
|
||||
* @param pbType type of problem (according to known problem types,
|
||||
* listed as static final members).
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter or incorrect
|
||||
* problem type
|
||||
*/
|
||||
public RoleUnresolved(String name,
|
||||
List<ObjectName> value,
|
||||
int pbType)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
if (name == null) {
|
||||
String excMsg = "Invalid parameter.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
setRoleName(name);
|
||||
setRoleValue(value);
|
||||
// Can throw IllegalArgumentException
|
||||
setProblemType(pbType);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Accessors
|
||||
//
|
||||
|
||||
/**
|
||||
* Retrieves role name.
|
||||
*
|
||||
* @return the role name.
|
||||
*
|
||||
* @see #setRoleName
|
||||
*/
|
||||
public String getRoleName() {
|
||||
return roleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves role value.
|
||||
*
|
||||
* @return an ArrayList of ObjectName objects, the one provided to be set
|
||||
* in given role. Null if the unresolved role is returned for a read
|
||||
* access.
|
||||
*
|
||||
* @see #setRoleValue
|
||||
*/
|
||||
public List<ObjectName> getRoleValue() {
|
||||
return roleValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves problem type.
|
||||
*
|
||||
* @return an integer corresponding to a problem, those being described as
|
||||
* static final members of current class.
|
||||
*
|
||||
* @see #setProblemType
|
||||
*/
|
||||
public int getProblemType() {
|
||||
return problemType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets role name.
|
||||
*
|
||||
* @param name the new role name.
|
||||
*
|
||||
* @exception IllegalArgumentException if null parameter
|
||||
*
|
||||
* @see #getRoleName
|
||||
*/
|
||||
public void setRoleName(String name)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
if (name == null) {
|
||||
String excMsg = "Invalid parameter.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
roleName = name;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets role value.
|
||||
*
|
||||
* @param value List of ObjectName objects for referenced
|
||||
* MBeans not set in role.
|
||||
*
|
||||
* @see #getRoleValue
|
||||
*/
|
||||
public void setRoleValue(List<ObjectName> value) {
|
||||
|
||||
if (value != null) {
|
||||
roleValue = new ArrayList<ObjectName>(value);
|
||||
} else {
|
||||
roleValue = null;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets problem type.
|
||||
*
|
||||
* @param pbType integer corresponding to a problem. Must be one of
|
||||
* those described as static final members of current class.
|
||||
*
|
||||
* @exception IllegalArgumentException if incorrect problem type
|
||||
*
|
||||
* @see #getProblemType
|
||||
*/
|
||||
public void setProblemType(int pbType)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
if (!(RoleStatus.isRoleStatus(pbType))) {
|
||||
String excMsg = "Incorrect problem type.";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
problemType = pbType;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone this object.
|
||||
*
|
||||
* @return an independent clone.
|
||||
*/
|
||||
public Object clone() {
|
||||
try {
|
||||
return new RoleUnresolved(roleName, roleValue, problemType);
|
||||
} catch (IllegalArgumentException exc) {
|
||||
return null; // :)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string describing this object.
|
||||
*
|
||||
* @return a description of this RoleUnresolved object.
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("role name: " + roleName);
|
||||
if (roleValue != null) {
|
||||
result.append("; value: ");
|
||||
for (Iterator<ObjectName> objNameIter = roleValue.iterator();
|
||||
objNameIter.hasNext();) {
|
||||
ObjectName currObjName = objNameIter.next();
|
||||
result.append(currObjName.toString());
|
||||
if (objNameIter.hasNext()) {
|
||||
result.append(", ");
|
||||
}
|
||||
}
|
||||
}
|
||||
result.append("; problem type: " + problemType);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a {@link RoleUnresolved} from an {@link ObjectInputStream}.
|
||||
*/
|
||||
private void readObject(ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException {
|
||||
if (compat)
|
||||
{
|
||||
// Read an object serialized in the old serial form
|
||||
//
|
||||
ObjectInputStream.GetField fields = in.readFields();
|
||||
roleName = (String) fields.get("myRoleName", null);
|
||||
if (fields.defaulted("myRoleName"))
|
||||
{
|
||||
throw new NullPointerException("myRoleName");
|
||||
}
|
||||
roleValue = cast(fields.get("myRoleValue", null));
|
||||
if (fields.defaulted("myRoleValue"))
|
||||
{
|
||||
throw new NullPointerException("myRoleValue");
|
||||
}
|
||||
problemType = fields.get("myPbType", 0);
|
||||
if (fields.defaulted("myPbType"))
|
||||
{
|
||||
throw new NullPointerException("myPbType");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Read an object serialized in the new serial form
|
||||
//
|
||||
in.defaultReadObject();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Serializes a {@link RoleUnresolved} to an {@link ObjectOutputStream}.
|
||||
*/
|
||||
private void writeObject(ObjectOutputStream out)
|
||||
throws IOException {
|
||||
if (compat)
|
||||
{
|
||||
// Serializes this instance in the old serial form
|
||||
//
|
||||
ObjectOutputStream.PutField fields = out.putFields();
|
||||
fields.put("myRoleName", roleName);
|
||||
fields.put("myRoleValue", roleValue);
|
||||
fields.put("myPbType", problemType);
|
||||
out.writeFields();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Serializes this instance in the new serial form
|
||||
//
|
||||
out.defaultWriteObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
370
jdkSrc/jdk8/javax/management/relation/RoleUnresolvedList.java
Normal file
370
jdkSrc/jdk8/javax/management/relation/RoleUnresolvedList.java
Normal file
@@ -0,0 +1,370 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package javax.management.relation;
|
||||
|
||||
import com.sun.jmx.mbeanserver.Util;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A RoleUnresolvedList represents a list of RoleUnresolved objects,
|
||||
* representing roles not retrieved from a relation due to a problem
|
||||
* encountered when trying to access (read or write) the roles.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
/* We cannot extend ArrayList<RoleUnresolved> because our legacy
|
||||
add(RoleUnresolved) method would then override add(E) in ArrayList<E>,
|
||||
and our return value is void whereas ArrayList.add(E)'s is boolean.
|
||||
Likewise for set(int,RoleUnresolved). Grrr. We cannot use covariance
|
||||
to override the most important methods and have them return
|
||||
RoleUnresolved, either, because that would break subclasses that
|
||||
override those methods in turn (using the original return type
|
||||
of Object). Finally, we cannot implement Iterable<RoleUnresolved>
|
||||
so you could write
|
||||
for (RoleUnresolved r : roleUnresolvedList)
|
||||
because ArrayList<> implements Iterable<> and the same class cannot
|
||||
implement two versions of a generic interface. Instead we provide
|
||||
the asList() method so you can write
|
||||
for (RoleUnresolved r : roleUnresolvedList.asList())
|
||||
*/
|
||||
public class RoleUnresolvedList extends ArrayList<Object> {
|
||||
|
||||
private transient boolean typeSafe;
|
||||
private transient boolean tainted;
|
||||
|
||||
/* Serial version */
|
||||
private static final long serialVersionUID = 4054902803091433324L;
|
||||
|
||||
//
|
||||
// Constructors
|
||||
//
|
||||
|
||||
/**
|
||||
* Constructs an empty RoleUnresolvedList.
|
||||
*/
|
||||
public RoleUnresolvedList() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an empty RoleUnresolvedList with the initial capacity
|
||||
* specified.
|
||||
*
|
||||
* @param initialCapacity initial capacity
|
||||
*/
|
||||
public RoleUnresolvedList(int initialCapacity) {
|
||||
super(initialCapacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a {@code RoleUnresolvedList} containing the elements of the
|
||||
* {@code List} specified, in the order in which they are returned by
|
||||
* the {@code List}'s iterator. The {@code RoleUnresolvedList} instance has
|
||||
* an initial capacity of 110% of the size of the {@code List}
|
||||
* specified.
|
||||
*
|
||||
* @param list the {@code List} that defines the initial contents of
|
||||
* the new {@code RoleUnresolvedList}.
|
||||
*
|
||||
* @exception IllegalArgumentException if the {@code list} parameter
|
||||
* is {@code null} or if the {@code list} parameter contains any
|
||||
* non-RoleUnresolved objects.
|
||||
*
|
||||
* @see ArrayList#ArrayList(java.util.Collection)
|
||||
*/
|
||||
public RoleUnresolvedList(List<RoleUnresolved> list)
|
||||
throws IllegalArgumentException {
|
||||
// Check for null parameter
|
||||
//
|
||||
if (list == null)
|
||||
throw new IllegalArgumentException("Null parameter");
|
||||
|
||||
// Check for non-RoleUnresolved objects
|
||||
//
|
||||
checkTypeSafe(list);
|
||||
|
||||
// Build the List<RoleUnresolved>
|
||||
//
|
||||
super.addAll(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a view of this list as a {@code List<RoleUnresolved>}.
|
||||
* Changes to the returned value are reflected by changes
|
||||
* to the original {@code RoleUnresolvedList} and vice versa.
|
||||
*
|
||||
* @return a {@code List<RoleUnresolved>} whose contents
|
||||
* reflect the contents of this {@code RoleUnresolvedList}.
|
||||
*
|
||||
* <p>If this method has ever been called on a given
|
||||
* {@code RoleUnresolvedList} instance, a subsequent attempt to add
|
||||
* an object to that instance which is not a {@code RoleUnresolved}
|
||||
* will fail with an {@code IllegalArgumentException}. For compatibility
|
||||
* reasons, a {@code RoleUnresolvedList} on which this method has never
|
||||
* been called does allow objects other than {@code RoleUnresolved}s to
|
||||
* be added.</p>
|
||||
*
|
||||
* @throws IllegalArgumentException if this {@code RoleUnresolvedList}
|
||||
* contains an element that is not a {@code RoleUnresolved}.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<RoleUnresolved> asList() {
|
||||
if (!typeSafe) {
|
||||
if (tainted)
|
||||
checkTypeSafe(this);
|
||||
typeSafe = true;
|
||||
}
|
||||
return Util.cast(this);
|
||||
}
|
||||
|
||||
//
|
||||
// Accessors
|
||||
//
|
||||
|
||||
/**
|
||||
* Adds the RoleUnresolved specified as the last element of the list.
|
||||
*
|
||||
* @param role - the unresolved role to be added.
|
||||
*
|
||||
* @exception IllegalArgumentException if the unresolved role is null.
|
||||
*/
|
||||
public void add(RoleUnresolved role)
|
||||
throws IllegalArgumentException {
|
||||
|
||||
if (role == null) {
|
||||
String excMsg = "Invalid parameter";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
super.add(role);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the unresolved role specified as an element at the position
|
||||
* specified.
|
||||
* Elements with an index greater than or equal to the current position are
|
||||
* shifted up.
|
||||
*
|
||||
* @param index - The position in the list where the new
|
||||
* RoleUnresolved object is to be inserted.
|
||||
* @param role - The RoleUnresolved object to be inserted.
|
||||
*
|
||||
* @exception IllegalArgumentException if the unresolved role is null.
|
||||
* @exception IndexOutOfBoundsException if index is out of range
|
||||
* (<code>index < 0 || index > size()</code>).
|
||||
*/
|
||||
public void add(int index,
|
||||
RoleUnresolved role)
|
||||
throws IllegalArgumentException,
|
||||
IndexOutOfBoundsException {
|
||||
|
||||
if (role == null) {
|
||||
String excMsg = "Invalid parameter";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
super.add(index, role);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the element at the position specified to be the unresolved role
|
||||
* specified.
|
||||
* The previous element at that position is discarded.
|
||||
*
|
||||
* @param index - The position specified.
|
||||
* @param role - The value to which the unresolved role element
|
||||
* should be set.
|
||||
*
|
||||
* @exception IllegalArgumentException if the unresolved role is null.
|
||||
* @exception IndexOutOfBoundsException if index is out of range
|
||||
* (<code>index < 0 || index >= size()</code>).
|
||||
*/
|
||||
public void set(int index,
|
||||
RoleUnresolved role)
|
||||
throws IllegalArgumentException,
|
||||
IndexOutOfBoundsException {
|
||||
|
||||
if (role == null) {
|
||||
String excMsg = "Invalid parameter";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
super.set(index, role);
|
||||
}
|
||||
|
||||
/**
|
||||
* Appends all the elements in the RoleUnresolvedList specified to the end
|
||||
* of the list, in the order in which they are returned by the Iterator of
|
||||
* the RoleUnresolvedList specified.
|
||||
*
|
||||
* @param roleList - Elements to be inserted into the list
|
||||
* (can be null).
|
||||
*
|
||||
* @return true if this list changed as a result of the call.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException if accessing with an index
|
||||
* outside of the list.
|
||||
*/
|
||||
public boolean addAll(RoleUnresolvedList roleList)
|
||||
throws IndexOutOfBoundsException {
|
||||
|
||||
if (roleList == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (super.addAll(roleList));
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts all of the elements in the RoleUnresolvedList specified into
|
||||
* this list, starting at the specified position, in the order in which
|
||||
* they are returned by the Iterator of the RoleUnresolvedList specified.
|
||||
*
|
||||
* @param index - Position at which to insert the first element from the
|
||||
* RoleUnresolvedList specified.
|
||||
* @param roleList - Elements to be inserted into the list.
|
||||
*
|
||||
* @return true if this list changed as a result of the call.
|
||||
*
|
||||
* @exception IllegalArgumentException if the role is null.
|
||||
* @exception IndexOutOfBoundsException if index is out of range
|
||||
* (<code>index < 0 || index > size()</code>).
|
||||
*/
|
||||
public boolean addAll(int index,
|
||||
RoleUnresolvedList roleList)
|
||||
throws IllegalArgumentException,
|
||||
IndexOutOfBoundsException {
|
||||
|
||||
if (roleList == null) {
|
||||
String excMsg = "Invalid parameter";
|
||||
throw new IllegalArgumentException(excMsg);
|
||||
}
|
||||
|
||||
return (super.addAll(index, roleList));
|
||||
}
|
||||
|
||||
/*
|
||||
* Override all of the methods from ArrayList<Object> that might add
|
||||
* a non-RoleUnresolved to the List, and disallow that if asList has
|
||||
* ever been called on this instance.
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean add(Object o) {
|
||||
if (!tainted)
|
||||
tainted = isTainted(o);
|
||||
if (typeSafe)
|
||||
checkTypeSafe(o);
|
||||
return super.add(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(int index, Object element) {
|
||||
if (!tainted)
|
||||
tainted = isTainted(element);
|
||||
if (typeSafe)
|
||||
checkTypeSafe(element);
|
||||
super.add(index, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<?> c) {
|
||||
if (!tainted)
|
||||
tainted = isTainted(c);
|
||||
if (typeSafe)
|
||||
checkTypeSafe(c);
|
||||
return super.addAll(c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(int index, Collection<?> c) {
|
||||
if (!tainted)
|
||||
tainted = isTainted(c);
|
||||
if (typeSafe)
|
||||
checkTypeSafe(c);
|
||||
return super.addAll(index, c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object set(int index, Object element) {
|
||||
if (!tainted)
|
||||
tainted = isTainted(element);
|
||||
if (typeSafe)
|
||||
checkTypeSafe(element);
|
||||
return super.set(index, element);
|
||||
}
|
||||
|
||||
/**
|
||||
* IllegalArgumentException if o is a non-RoleUnresolved object.
|
||||
*/
|
||||
private static void checkTypeSafe(Object o) {
|
||||
try {
|
||||
o = (RoleUnresolved) o;
|
||||
} catch (ClassCastException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* IllegalArgumentException if c contains any non-RoleUnresolved objects.
|
||||
*/
|
||||
private static void checkTypeSafe(Collection<?> c) {
|
||||
try {
|
||||
RoleUnresolved r;
|
||||
for (Object o : c)
|
||||
r = (RoleUnresolved) o;
|
||||
} catch (ClassCastException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if o is a non-RoleUnresolved object.
|
||||
*/
|
||||
private static boolean isTainted(Object o) {
|
||||
try {
|
||||
checkTypeSafe(o);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if c contains any non-RoleUnresolved objects.
|
||||
*/
|
||||
private static boolean isTainted(Collection<?> c) {
|
||||
try {
|
||||
checkTypeSafe(c);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user