[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] Patch: RFA: QName serialization
From: |
Tom Tromey |
Subject: |
[cp-patches] Patch: RFA: QName serialization |
Date: |
19 Sep 2005 12:11:31 -0600 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 |
This updates QName to be Serializable as required by 1.5.
As part of this, I changed the qName field to be computed lazily, so
that it would work properly with serialization without requiring a
readObject method.
Any comments? Is this ok? This isn't really my area so I didn't want
to simply commit this change.
Tom
2005-09-19 Tom Tromey <address@hidden>
* javax/xml/namespace/QName.java: Now Serializable.
(serialVersionUID): New field.
(qName, hashCode): Now transient.
(QName): Don't compute qName here.
(equals): Now final.
(hashCode): Simplified.
(toString): Compute qName here.
Index: javax/xml/namespace/QName.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/xml/namespace/QName.java,v
retrieving revision 1.7
diff -u -r1.7 QName.java
--- javax/xml/namespace/QName.java 5 Sep 2005 12:37:38 -0000 1.7
+++ javax/xml/namespace/QName.java 19 Sep 2005 18:10:01 -0000
@@ -1,5 +1,5 @@
/* QName.java - An XML qualified name.
- Copyright (C) 2004 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,6 +38,8 @@
package javax.xml.namespace;
+import java.io.Serializable;
+
import javax.xml.XMLConstants;
/**
@@ -47,14 +49,15 @@
* @author <a href='mailto:address@hidden'>Chris Burdess</a>
* @since 1.3
*/
-public class QName
+public class QName implements Serializable
{
+ private static final long serialVersionUID = 4418622981026545151L;
private final String namespaceURI;
private final String localPart;
private final String prefix;
- private final String qName;
- int hashCode = -1;
+ private transient String qName;
+ transient int hashCode = -1;
public QName(String namespaceURI, String localPart)
{
@@ -78,21 +81,6 @@
this.namespaceURI = namespaceURI;
this.localPart = localPart;
this.prefix = prefix;
-
- StringBuffer buf = new StringBuffer();
- if (namespaceURI.length() > 0)
- {
- buf.append('{');
- buf.append(namespaceURI);
- buf.append('}');
- }
- if (prefix.length() > 0)
- {
- buf.append(prefix);
- buf.append(':');
- }
- buf.append(localPart);
- qName = buf.toString();
}
public QName(String localPart)
@@ -115,7 +103,7 @@
return prefix;
}
- public boolean equals(Object obj)
+ public final boolean equals(Object obj)
{
if (obj instanceof QName)
{
@@ -129,19 +117,29 @@
public final int hashCode()
{
if (hashCode == -1)
- {
- StringBuffer buf = new StringBuffer();
- buf.append('{');
- buf.append(namespaceURI);
- buf.append('}');
- buf.append(localPart);
- hashCode = buf.toString().hashCode();
- }
+ hashCode = localPart.hashCode() ^ namespaceURI.hashCode();
return hashCode;
}
- public String toString()
+ public synchronized String toString()
{
+ if (qName == null)
+ {
+ StringBuffer buf = new StringBuffer();
+ if (namespaceURI.length() > 0)
+ {
+ buf.append('{');
+ buf.append(namespaceURI);
+ buf.append('}');
+ }
+ if (prefix.length() > 0)
+ {
+ buf.append(prefix);
+ buf.append(':');
+ }
+ buf.append(localPart);
+ qName = buf.toString();
+ }
return qName;
}
- [cp-patches] Patch: RFA: QName serialization,
Tom Tromey <=