From 2f69f684f3367f585a0f73e4308dc2449295a076 Mon Sep 17 00:00:00 2001 From: Andrew Haley Date: Mon, 16 Apr 2007 13:46:54 +0000 Subject: TaggedComponentHelper.java (read): Use read_octet_array(), not read(). 2007-04-16 Andrew Haley * org/omg/IOP/TaggedComponentHelper.java (read): Use read_octet_array(), not read(). (write): Use write_octet_array(), not write(). * org/omg/PortableServer/Servant.java (_get_delegate): Throw if no delegate has been set. * javax/management/ObjectName.java serialVersionUID: Declare. Make all fields transient. (parse): Break out from constructor. (writeObject, readObject): New methods. From-SVN: r123864 --- libjava/classpath/javax/management/ObjectName.java | 70 ++++++++++++++++++++-- 1 file changed, 65 insertions(+), 5 deletions(-) (limited to 'libjava/classpath/javax/management/ObjectName.java') diff --git a/libjava/classpath/javax/management/ObjectName.java b/libjava/classpath/javax/management/ObjectName.java index 6042054..0ddfb8e 100644 --- a/libjava/classpath/javax/management/ObjectName.java +++ b/libjava/classpath/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; + /** *

* An {@link ObjectName} instance represents the name of a management @@ -97,30 +102,32 @@ public class ObjectName implements Serializable, QueryExp { + private static final long serialVersionUID = 1081892073854801359L; + /** * The domain of the name. */ - private String domain; + private transient String domain; /** * The properties, as key-value pairs. */ - private TreeMap properties = new TreeMap(); + private transient TreeMap 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; /** * Constructs an {@link ObjectName} instance from the given string, @@ -145,12 +152,23 @@ 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(); if (rest.equals("*")) propertyPattern = true; else @@ -199,6 +217,7 @@ public class ObjectName throws MalformedObjectNameException { this.domain = domain; + properties = new TreeMap(); properties.put(key, value); checkComponents(); } @@ -221,6 +240,7 @@ public class ObjectName throws MalformedObjectNameException { this.domain = domain; + this.properties = new TreeMap(); this.properties.putAll(properties); checkComponents(); } @@ -741,6 +761,46 @@ public class ObjectName return getCanonicalName(); } + + /** + * Serialization methods. The serialized form is the same as the + * string parsed by the constructor. + */ + + 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()); + } + + 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 ('"', '?', -- cgit v1.1