diff options
author | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2007-04-06 15:45:08 +0000 |
---|---|---|
committer | Andrew John Hughes <gnu_andrew@member.fsf.org> | 2007-04-06 15:45:08 +0000 |
commit | 9d89ebaf763178447aa4e44480ff16d396284a3b (patch) | |
tree | 05070417509eacad680fc043f346fac6a9349cd3 | |
parent | 3b83ec75c64f601e7b0fa183ca2a97004d2f7981 (diff) | |
download | classpath-9d89ebaf763178447aa4e44480ff16d396284a3b.tar.gz |
2007-04-06 Andrew John Hughes <gnu_andrew@member.fsf.org>
* gnu/javax/management/Translator.java:
(getTypeName(type)): Move type name creation to its own method.
* javax/management/ObjectName.java:
(WILDCARD): Added.
2007-04-04 Andrew Haley <aph@redhat.com>
* javax/management/ObjectName.java:
(serialVersionUID): Declare.
Make all fields transient.
(parse): Break out from constructor.
(writeObject, readObject): New methods.
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | gnu/javax/management/Translator.java | 52 | ||||
-rw-r--r-- | javax/management/ObjectName.java | 102 |
3 files changed, 159 insertions, 10 deletions
@@ -1,3 +1,18 @@ +2007-04-06 Andrew John Hughes <gnu_andrew@member.fsf.org> + + * gnu/javax/management/Translator.java: + (getTypeName(type)): Move type name creation to its own method. + * javax/management/ObjectName.java: + (WILDCARD): Added. + +2007-04-04 Andrew Haley <aph@redhat.com> + + * javax/management/ObjectName.java: + (serialVersionUID): Declare. + Make all fields transient. + (parse): Break out from constructor. + (writeObject, readObject): New methods. + 2007-04-05 Francis Kung <fkung@redhat.com> * include/Makefile.am: Remove old entry. diff --git a/gnu/javax/management/Translator.java b/gnu/javax/management/Translator.java index 163fdd4fd..69191d43f 100644 --- a/gnu/javax/management/Translator.java +++ b/gnu/javax/management/Translator.java @@ -127,11 +127,7 @@ public final class Translator celems[a] = fromJava(elems[a], elems[a].getClass()); return makeArraySpecific(celems); } - String tName = null; - if (type instanceof Class) - tName = ((Class<?>) type).getName(); - else - tName = type.toString(); + String tName = getTypeName(type); if (jtype instanceof List || jtype instanceof Set || jtype instanceof SortedSet) { @@ -499,4 +495,50 @@ public final class Translator return Translator.translate(c.getName()).getOpenType(); } + /** + * <p> + * Returns the type name according to the rules described + * in {@link javax.management.MXBean}. Namely, for a type, + * {@code T}, {@code typename(T)} is computed as follows: + * </p> + * <ul> + * <li>If T is non-generic and not an array, then the value + * of {@link java.lang.Class#getName()} is returned.</li> + * <li>If T is an array type, {@code{E[]}, then the type name + * is {@code typename(E)} followed by an occurrence + * of {@code '[]'} for each dimension.</li> + * <li>If T is a generic or parameterized type, the type name + * is composed of {@code typename(P)}, where {@code P} is the + * parameterized type name, followed by {@code '<'}, the resulting + * list of type names of the parameters after applying {@code typename} + * to each, separated by commas, and {@code '>'}.</li> + * </ul> + * + * @param type the type to return the type name of. + * @return the type name computed according to the rules above. + */ + private static final String getTypeName(Type type) + { + if (type instanceof Class) + { + Class<?> c = (Class<?>) type; + if (c.isArray()) + { + StringBuilder b = + new StringBuilder(c.getComponentType().getName()); + String normName = c.getName(); + for (int a = 0; a < normName.length(); ++a) + { + if (normName.charAt(a) == '[') + b.append("[]"); + else + break; + } + return b.toString(); + } + return c.getName(); + } + return type.toString(); + } + } diff --git a/javax/management/ObjectName.java b/javax/management/ObjectName.java index 04fa33a82..00a2a2875 100644 --- a/javax/management/ObjectName.java +++ b/javax/management/ObjectName.java @@ -45,6 +45,11 @@ import java.util.Iterator; import java.util.Map; import java.util.TreeMap; +import java.io.IOException; +import java.io.InvalidObjectException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + /** * <p> * An {@link ObjectName} instance represents the name of a management @@ -97,30 +102,56 @@ public class ObjectName implements Serializable, QueryExp { + private static final long serialVersionUID = 1081892073854801359L; + + /** + * The wildcard {@link ObjectName} {@code "*:*"} + * + * @since 1.6 + */ + public static final ObjectName WILDCARD; + /** * The domain of the name. */ - private String domain; + private transient String domain; /** * The properties, as key-value pairs. */ - private TreeMap<String,String> properties = new TreeMap<String,String>(); + private transient TreeMap<String,String> properties; /** * The properties as a string (stored for ordering). */ - private String propertyListString; + private transient String propertyListString; /** * True if this object name is a property pattern. */ - private boolean propertyPattern; + private transient boolean propertyPattern; /** * The management server associated with this object name. */ - private MBeanServer server; + private transient MBeanServer server; + + /** + * Static initializer to set up the wildcard. + */ + static + { + try + { + WILDCARD = new ObjectName(""); + } + catch (MalformedObjectNameException e) + { + throw (InternalError) (new InternalError("A problem occurred " + + "initializing the ObjectName " + + "wildcard.").initCause(e)); + } + } /** * Constructs an {@link ObjectName} instance from the given string, @@ -145,12 +176,22 @@ public class ObjectName { if (name.length() == 0) name = "*:*"; + parse(name); + } + /** + * Parse the name in the same form as the constructor. Used by + * readObject(). + */ + private void parse(String name) + throws MalformedObjectNameException + { int domainSep = name.indexOf(':'); if (domainSep == -1) throw new MalformedObjectNameException("No domain separator was found."); domain = name.substring(0, domainSep); String rest = name.substring(domainSep + 1); + properties = new TreeMap<String,String>(); if (rest.equals("*")) propertyPattern = true; else @@ -202,6 +243,7 @@ public class ObjectName throws MalformedObjectNameException { this.domain = domain; + properties = new TreeMap<String,String>(); properties.put(key, value); checkComponents(); } @@ -224,6 +266,7 @@ public class ObjectName throws MalformedObjectNameException { this.domain = domain; + this.properties = new TreeMap<String,String>(); this.properties.putAll(properties); checkComponents(); } @@ -744,6 +787,55 @@ public class ObjectName return getCanonicalName(); } + + /** + * Serialize this {@link ObjectName}. The serialized + * form is the same as the string parsed by the constructor. + * + * @param out the output stream to write to. + * @throws IOException if an I/O error occurs. + */ + private void writeObject(ObjectOutputStream out) + throws IOException + { + out.defaultWriteObject(); + StringBuffer buffer = new StringBuffer(getDomain()); + buffer.append(':'); + String properties = getKeyPropertyListString(); + buffer.append(properties); + if (isPropertyPattern()) + { + if (properties.length() == 0) + buffer.append("*"); + else + buffer.append(",*"); + } + out.writeObject(buffer.toString()); + } + + /** + * Reads the serialized form, which is that used + * by the constructor. + * + * @param in the input stream to read from. + * @throws IOException if an I/O error occurs. + */ + private void readObject(ObjectInputStream in) + throws IOException, ClassNotFoundException + { + in.defaultReadObject(); + String objectName = (String)in.readObject(); + try + { + parse(objectName); + } + catch (MalformedObjectNameException x) + { + throw new InvalidObjectException(x.toString()); + } + } + + /** * Unquotes the supplied string. The quotation marks are removed as * are the backslashes preceding the escaped characters ('"', '?', |