* ObjectName Serialized Form
@ 2007-04-04 18:27 Andrew Haley
0 siblings, 0 replies; only message in thread
From: Andrew Haley @ 2007-04-04 18:27 UTC (permalink / raw)
To: classpath-patches, java-patches
Another patch for JBoss.
Andrew.
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.
Index: ObjectName.java
===================================================================
--- ObjectName.java (revision 123473)
+++ ObjectName.java (working copy)
@@ -45,6 +45,11 @@
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,32 @@
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<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;
/**
* Constructs an {@link ObjectName} instance from the given string,
@@ -145,12 +152,23 @@
{
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
@@ -199,6 +217,7 @@
throws MalformedObjectNameException
{
this.domain = domain;
+ properties = new TreeMap<String,String>();
properties.put(key, value);
checkComponents();
}
@@ -221,6 +240,7 @@
throws MalformedObjectNameException
{
this.domain = domain;
+ this.properties = new TreeMap<String,String>();
this.properties.putAll(properties);
checkComponents();
}
@@ -741,6 +761,46 @@
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 ('"', '?',
--
Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, UK
Registered in England and Wales No. 3798903
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-04-04 18:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-04 18:27 ObjectName Serialized Form Andrew Haley
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).