From: Andy J. (JIRA) <web...@jp...> - 2007-09-11 08:15:48
|
[ http://www.jpox.org/servlet/jira/browse/ENHANCER-91?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Andy Jefferson updated ENHANCER-91: ----------------------------------- Fix Version/s: 1.2.0-rc-1 (was: 1.2.0-beta-4) > Persistent class with methods writeObject and writeReplace should be modified by Enhancer an call jdoPreSerialize + add detachedState > ------------------------------------------------------------------------------------------------------------------------------------- > > Key: ENHANCER-91 > URL: http://www.jpox.org/servlet/jira/browse/ENHANCER-91 > Project: Enhancer > Issue Type: Bug > Components: JDO Enhancer : ASM, JDO Enhancer : BCEL > Affects Versions: 1.1.6, 1.2.0-beta-2 > Reporter: Erik Bengtson > Assigned To: Erik Bengtson > Fix For: 1.2.0-rc-1 > > > package org.jpox.samples.serialize; > import java.io.ByteArrayOutputStream; > import java.io.File; > import java.io.FileInputStream; > import java.io.FileOutputStream; > import java.io.IOException; > import java.io.ObjectInputStream; > import java.io.ObjectOutputStream; > import java.io.Serializable; > import java.util.BitSet; > import java.util.Date; > import javax.jdo.spi.Detachable; > import javax.jdo.spi.PersistenceCapable; > public class SerializeSample implements Serializable > { > private static final long serialVersionUID = 2765740961462495537L; > private String name; > > private long age; > > private Date birthdate; > private String zzzz; > private String zzzzzz; > > private transient String password; > private void writeObject(ObjectOutputStream stream) throws IOException { > //do jdoPreSerialize() here > try > { > stream.writeObject(getClass().getDeclaredField("jdoDetachedState").get(this)); > } > catch (Exception e) > { > } > stream.defaultWriteObject(); > } > private void readObject(ObjectInputStream stream) throws IOException, > ClassNotFoundException { > //do jdoPreSerialize() here > try > { > Object value = stream.readObject(); > getClass().getDeclaredField("jdoDetachedState").set(this,value); > } > catch (Exception e) > { > } > stream.defaultReadObject(); > } > /** > * @param args > */ > public static void main(String[] args) throws Exception > { > if( args.length < 1) > { > System.out.println("Must have one arg (out or in)."); > } > else if( args[0].equalsIgnoreCase("out")) > { > testOut(); > } > else if( args[0].equalsIgnoreCase("in")) > { > testIn(); > } > } > public static void testOut() throws Exception > { > if( !(Detachable.class.isAssignableFrom(SerializeSample.class))) > { > System.err.println("Expected a Detachable class"); > } > SerializeSample s = new SerializeSample(); > BitSet set = new BitSet(); > set.set(0); > set.set(1); > set.set(2); > set.set(3); > s.getClass().getDeclaredField("jdoDetachedState").set(s,new Object[]{set,set,set,set}); > s.name ="Erik"; > s.age = 10; > s.zzzz ="Sleeping"; > ByteArrayOutputStream buf = new ByteArrayOutputStream(); > File file =new File("test.out"); > file.createNewFile(); > ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream(file)); > o.writeObject(s); > o.close(); > } > public static void testIn() throws Exception > { > if( Detachable.class.isAssignableFrom(SerializeSample.class)) > { > System.out.println("Class is Detachable and detached state should be printed."); > } > else > { > System.out.println("Class is not Detachable."); > } > File file =new File("test.out"); > ObjectInputStream in = new ObjectInputStream(new FileInputStream(file)); > SerializeSample s = (SerializeSample) in.readObject(); > System.out.println(s.name); > System.out.println(s.age); > System.out.println(s.zzzz); > if( Detachable.class.isAssignableFrom(SerializeSample.class)) > { > System.out.println(s.getClass().getDeclaredField("jdoDetachedState").get(s)); > } > } > } -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://www.jpox.org/servlet/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira |