Hi, this patch fixes all incompatibilities with serialization in the javax.print namespace. If I haven't forgot something all is now conformant to the JDK classes serialized form.
2006-02-23 Wolfgang Baer <[EMAIL PROTECTED]> * javax/print/attribute/standard/MediaSize.java: (media): Field renamed to mediaName for serialization. (MediaSize): Adapted to new fieldname. (getMediaSizeName): Likewise. * javax/print/attribute/HashAttributeSet.java: (interfaceName): Field renamed to myInterface for serialization. (HashAttributeSet): Adapted to the new fieldname. (add): Likewise. (addAll): Likewise. (addInternal): Likewise. (attributeMap): Made transient. (readObject): New serialization method. (writeObject): Likewise. * javax/print/attribute/AttributeSetUtilities.java: (SynchronizedAttributeSet.set): Field renamed to attrset for serialization. (SynchronizedAttributeSet.add): Adapted to the new fieldname. (SynchronizedAttributeSet.addAll): Likewise. (SynchronizedAttributeSet.clear): Likewise. (SynchronizedAttributeSet.containsKey): Likewise. (SynchronizedAttributeSet.containsValue): Likewise. (SynchronizedAttributeSet.equals): Likewise. (SynchronizedAttributeSet.get): Likewise. (SynchronizedAttributeSet.hashCode): Likewise. (SynchronizedAttributeSet.isEmpty): Likewise. (SynchronizedAttributeSet.remove): Likewise. (SynchronizedAttributeSet.size): Likewise. (SynchronizedAttributeSet.toArray): Likewise. (UnmodifiableAttributeSet.set): Field renamed to attrset for serialization. (UnmodifiableAttributeSet.add): Adapted to the new fieldname. (UnmodifiableAttributeSet.addAll): Likewise. (UnmodifiableAttributeSet.clear): Likewise. (UnmodifiableAttributeSet.containsKey): Likewise. (UnmodifiableAttributeSet.containsValue): Likewise. (UnmodifiableAttributeSet.equals): Likewise. (UnmodifiableAttributeSet.get): Likewise. (UnmodifiableAttributeSet.hashCode): Likewise. (UnmodifiableAttributeSet.isEmpty): Likewise. (UnmodifiableAttributeSet.remove): Likewise. (UnmodifiableAttributeSet.size): Likewise. (UnmodifiableAttributeSet.toArray): Likewise. * javax/print/attribute/standard/MediaPrintableArea.java: (width): Field renamed to w for serialization. (height): Field renamed to h for serialization. (MediaPrintableArea): Adapted to the new fieldnames. (MediaPrintableArea): Likewise. (equals): Likewise. (hashCode): Likewise. (getHeight): Likewise. (getWidth): Likewise. Wolfgang
Index: javax/print/attribute/HashAttributeSet.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/print/attribute/HashAttributeSet.java,v retrieving revision 1.5 diff -u -r1.5 HashAttributeSet.java --- javax/print/attribute/HashAttributeSet.java 14 Nov 2005 20:56:59 -0000 1.5 +++ javax/print/attribute/HashAttributeSet.java 23 Feb 2006 18:18:32 -0000 @@ -37,6 +37,9 @@ package javax.print.attribute; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.HashMap; import java.util.Iterator; @@ -49,8 +52,8 @@ { private static final long serialVersionUID = 5311560590283707917L; - private Class interfaceName; - private HashMap attributeMap = new HashMap(); + private Class myInterface; + private transient HashMap attributeMap = new HashMap(); /** * Creates an empty <code>HashAttributeSet</code> object. @@ -112,7 +115,7 @@ if (interfaceName == null) throw new NullPointerException("interfaceName may not be null"); - this.interfaceName = interfaceName; + myInterface = interfaceName; } /** @@ -192,7 +195,7 @@ */ public boolean add(Attribute attribute) { - return addInternal(attribute, interfaceName); + return addInternal(attribute, myInterface); } private boolean addInternal(Attribute attribute, Class interfaceName) @@ -201,7 +204,7 @@ throw new NullPointerException("attribute may not be null"); AttributeSetUtilities.verifyAttributeCategory(interfaceName, - this.interfaceName); + myInterface); Object old = attributeMap.put (attribute.getCategory(), AttributeSetUtilities.verifyAttributeValue @@ -220,7 +223,7 @@ */ public boolean addAll(AttributeSet attributes) { - return addAllInternal(attributes, interfaceName); + return addAllInternal(attributes, myInterface); } private boolean addAllInternal(AttributeSet attributes, Class interfaceName) @@ -393,4 +396,24 @@ return array; } + + // Implemented as specified in serialized form + private void readObject(ObjectInputStream s) + throws ClassNotFoundException, IOException + { + myInterface = (Class) s.readObject(); + int size = s.readInt(); + attributeMap = new HashMap(size); + for (int i=0; i < size; i++) + add((Attribute) s.readObject()); + } + + private void writeObject(ObjectOutputStream s) throws IOException + { + s.writeObject(myInterface); + s.writeInt(size()); + Iterator it = attributeMap.values().iterator(); + while (it.hasNext()) + s.writeObject(it.next()); + } } Index: javax/print/attribute/AttributeSetUtilities.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/print/attribute/AttributeSetUtilities.java,v retrieving revision 1.5 diff -u -r1.5 AttributeSetUtilities.java --- javax/print/attribute/AttributeSetUtilities.java 14 Nov 2005 22:11:44 -0000 1.5 +++ javax/print/attribute/AttributeSetUtilities.java 23 Feb 2006 18:18:33 -0000 @@ -78,14 +78,14 @@ private static class UnmodifiableAttributeSet implements AttributeSet, Serializable { - private AttributeSet set; + private AttributeSet attrset; public UnmodifiableAttributeSet(AttributeSet attributeSet) { if (attributeSet == null) throw new NullPointerException("attributeSet may not be null"); - this.set = attributeSet; + this.attrset = attributeSet; } public boolean add(Attribute attribute) @@ -105,32 +105,32 @@ public boolean containsKey(Class category) { - return set.containsKey(category); + return attrset.containsKey(category); } public boolean containsValue(Attribute attribute) { - return set.containsValue(attribute); + return attrset.containsValue(attribute); } public boolean equals(Object obj) { - return set.equals(obj); + return attrset.equals(obj); } public Attribute get(Class interfaceName) { - return set.get(interfaceName); + return attrset.get(interfaceName); } public int hashCode() { - return set.hashCode(); + return attrset.hashCode(); } public boolean isEmpty() { - return set.isEmpty(); + return attrset.isEmpty(); } public boolean remove(Class category) @@ -145,12 +145,12 @@ public int size() { - return set.size(); + return attrset.size(); } public Attribute[] toArray() { - return set.toArray(); + return attrset.toArray(); } } @@ -197,79 +197,79 @@ private static class SynchronizedAttributeSet implements AttributeSet, Serializable { - private AttributeSet set; + private AttributeSet attrset; public SynchronizedAttributeSet(AttributeSet attributeSet) { if (attributeSet == null) throw new NullPointerException("attributeSet may not be null"); - this.set = attributeSet; + attrset = attributeSet; } public synchronized boolean add(Attribute attribute) { - return set.add(attribute); + return attrset.add(attribute); } public synchronized boolean addAll(AttributeSet attributes) { - return set.addAll(attributes); + return attrset.addAll(attributes); } public synchronized void clear() { - set.clear(); + attrset.clear(); } public synchronized boolean containsKey(Class category) { - return set.containsKey(category); + return attrset.containsKey(category); } public synchronized boolean containsValue(Attribute attribute) { - return set.containsValue(attribute); + return attrset.containsValue(attribute); } public synchronized boolean equals(Object obj) { - return set.equals(obj); + return attrset.equals(obj); } public synchronized Attribute get(Class interfaceName) { - return set.get(interfaceName); + return attrset.get(interfaceName); } public synchronized int hashCode() { - return set.hashCode(); + return attrset.hashCode(); } public synchronized boolean isEmpty() { - return set.isEmpty(); + return attrset.isEmpty(); } public synchronized boolean remove(Class category) { - return set.remove(category); + return attrset.remove(category); } public synchronized boolean remove(Attribute attribute) { - return set.remove(attribute); + return attrset.remove(attribute); } public synchronized int size() { - return set.size(); + return attrset.size(); } public synchronized Attribute[] toArray() { - return set.toArray(); + return attrset.toArray(); } } Index: javax/print/attribute/standard/MediaSize.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/print/attribute/standard/MediaSize.java,v retrieving revision 1.7 diff -u -r1.7 MediaSize.java --- javax/print/attribute/standard/MediaSize.java 6 Feb 2006 11:11:00 -0000 1.7 +++ javax/print/attribute/standard/MediaSize.java 23 Feb 2006 18:18:33 -0000 @@ -87,7 +87,7 @@ tmp = MediaSize.Other.EXECUTIVE; } - private MediaSizeName media; + private MediaSizeName mediaName; /** * Creates a <code>MediaSize</code> object. The created object will be added @@ -128,7 +128,7 @@ public MediaSize(float x, float y, int units, MediaSizeName media) { super(x, y, units); - this.media = media; + mediaName = media; mediaCache.add(this); } @@ -171,7 +171,7 @@ public MediaSize(int x, int y, int units, MediaSizeName media) { super(x, y, units); - this.media = media; + mediaName = media; mediaCache.add(this); } @@ -273,7 +273,7 @@ */ public MediaSizeName getMediaSizeName() { - return media; + return mediaName; } /** Index: javax/print/attribute/standard/MediaPrintableArea.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/print/attribute/standard/MediaPrintableArea.java,v retrieving revision 1.3 diff -u -r1.3 MediaPrintableArea.java --- javax/print/attribute/standard/MediaPrintableArea.java 19 Dec 2005 11:18:48 -0000 1.3 +++ javax/print/attribute/standard/MediaPrintableArea.java 23 Feb 2006 18:18:33 -0000 @@ -95,9 +95,9 @@ /** y in micrometers. */ private int y; /** width in micrometers. */ - private int width; + private int w; /** height in micrometers. */ - private int height; + private int h; /** * Creates a new <code>MediaPrintableArea</code> object with the given @@ -119,8 +119,8 @@ this.x = (int) (x * units + 0.5f); this.y = (int) (y * units + 0.5f); - this.width = (int) (w * units + 0.5f); - this.height = (int) (h * units + 0.5f); + this.w = (int) (w * units + 0.5f); + this.h = (int) (h * units + 0.5f); } /** @@ -143,8 +143,8 @@ this.x = x * units; this.y = y * units; - this.width = w * units; - this.height = h * units; + this.w = w * units; + this.h = h * units; } /** @@ -180,7 +180,7 @@ if (units < 1) throw new IllegalArgumentException("units may not be less than 1"); - return height / ((float)units); + return h / ((float)units); } /** @@ -196,7 +196,7 @@ if (units < 1) throw new IllegalArgumentException("units may not be less than 1"); - return width / ((float)units); + return w / ((float)units); } /** @@ -248,7 +248,7 @@ MediaPrintableArea tmp = (MediaPrintableArea) obj; return (x == tmp.getX(1) && y == tmp.getY(1) - && width == tmp.getWidth(1) && height == tmp.getHeight(1)); + && w == tmp.getWidth(1) && h == tmp.getHeight(1)); } /** @@ -270,7 +270,7 @@ */ public int hashCode() { - return x ^ y + width ^ height; + return x ^ y + w ^ h; } /**