/* * 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. *
It represents a relation type, providing role information for each role * expected to be supported in every relation of that type. * *
A relation type includes a relation type name and a list of * role infos (represented by RoleInfo objects). * *
A relation type has to be declared in the Relation Service: *
- either using the createRelationType() method, where a RelationTypeSupport * object will be created and kept in the Relation Service *
- 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. * *
The serialVersionUID of this class is - the same name has been used for two different roles
* - no role info provided
* - 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 List4611072955724144607L
.
*
* @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