CVS: Tapestry/framework/src/net/sf/tapestry/record SerializableCopier.java,NONE,1.1.2.1 IValuePersister.java,1.1.2.1,1.1.2.2 IValueCopier.java,1.1.2.1,1.1.2.2 PageRecorder.java,1.9.2.1,1.9.2.2 DefaultValuePersister.java,1.1.2.2,1.1.2.3
Howard Lewis Ship <[email protected]>
| Newsgroups | gmane.comp.java.tapestry.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/record
In directory sc8-pr-cvs1:/tmp/cvs-serv10129/framework/src/net/sf/tapestry/record
Modified Files:
Tag: hship-2-3
IValuePersister.java IValueCopier.java PageRecorder.java
DefaultValuePersister.java
Added Files:
Tag: hship-2-3
SerializableCopier.java
Log Message:
Add ability to store copies of Serializable objects (by serializing/deserialing them).
--- NEW FILE: SerializableCopier.java ---
package net.sf.tapestry.record;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import net.sf.tapestry.IResourceResolver;
import net.sf.tapestry.util.io.ResolvingObjectInputStream;
/**
* Copies a {@link java.io.Serializable} object by making a copy of it,
* using serialization.
*
* @author Howard Lewis Ship
* @version $Id: SerializableCopier.java,v 1.1.2.1 2003/01/02 03:13:49 hship Exp $
* @since 2.4
*
**/
public class SerializableCopier implements IValueCopier
{
private static final Log LOG = LogFactory.getLog(SerializableCopier.class);
private IResourceResolver _resolver;
public SerializableCopier(IResourceResolver resolver)
{
_resolver = resolver;
}
public Object makeCopyOfValue(Object value) throws PageRecorderSerializationException
{
try
{
byte[] bytes = serialize(value);
return deserialize(bytes);
}
catch (IOException ex)
{
throw new PageRecorderSerializationException(ex);
}
}
private byte[] serialize(Object object) throws IOException
{
boolean debug = LOG.isDebugEnabled();
if (debug)
LOG.debug("Serializing " + object);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(object);
oos.close();
byte[] result = bos.toByteArray();
if (debug)
LOG.debug("Serialized to " + result.length + " bytes");
return result;
}
private Object deserialize(byte[] bytes) throws IOException
{
boolean debug = LOG.isDebugEnabled();
if (debug)
LOG.debug("Deserializing " + bytes.length + " bytes");
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ResolvingObjectInputStream(_resolver, bis);
Object result;
try
{
result = ois.readObject();
}
catch (ClassNotFoundException ex)
{
throw new IOException(ex.getMessage());
}
ois.close();
if (debug)
LOG.debug("Deserialized as " + result);
return result;
}
}
Index: IValuePersister.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/record/Attic/IValuePersister.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** IValuePersister.java 30 Dec 2002 03:04:55 -0000 1.1.2.1
--- IValuePersister.java 2 Jan 2003 03:13:50 -0000 1.1.2.2
***************
*** 1,4 ****
--- 1,6 ----
package net.sf.tapestry.record;
+ import net.sf.tapestry.IRequestCycle;
+
/**
* Responsible for persisting values on behalf of a {@link net.sf.tapestry.IPageRecorder}.
***************
*** 19,22 ****
--- 21,32 ----
public interface IValuePersister
{
+ /**
+ * Invoked just after an instance is instantiated, to allow it
+ * to complete its initialization.
+ *
+ **/
+
+ public void initialize(IRequestCycle cycle);
+
/**
* Converts an active value (used by the application) to
Index: IValueCopier.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/record/Attic/IValueCopier.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** IValueCopier.java 30 Dec 2002 03:04:55 -0000 1.1.2.1
--- IValueCopier.java 2 Jan 2003 03:13:50 -0000 1.1.2.2
***************
*** 17,20 ****
**/
! public Object makeCopyOfValue(Object value);
}
--- 17,21 ----
**/
! public Object makeCopyOfValue(Object value)
! throws PageRecorderSerializationException;
}
Index: PageRecorder.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/record/PageRecorder.java,v
retrieving revision 1.9.2.1
retrieving revision 1.9.2.2
diff -C2 -d -r1.9.2.1 -r1.9.2.2
*** PageRecorder.java 30 Dec 2002 03:04:55 -0000 1.9.2.1
--- PageRecorder.java 2 Jan 2003 03:13:50 -0000 1.9.2.2
***************
*** 262,265 ****
--- 262,267 ----
_persister = new DefaultValuePersister();
+ _persister.initialize(cycle);
+
context.setAttribute(name, _persister);
}
Index: DefaultValuePersister.java
===================================================================
RCS file: /cvsroot/tapestry/Tapestry/framework/src/net/sf/tapestry/record/Attic/DefaultValuePersister.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -d -r1.1.2.2 -r1.1.2.3
*** DefaultValuePersister.java 31 Dec 2002 12:22:58 -0000 1.1.2.2
--- DefaultValuePersister.java 2 Jan 2003 03:13:50 -0000 1.1.2.3
***************
*** 1,4 ****
--- 1,5 ----
package net.sf.tapestry.record;
+ import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.Date;
***************
*** 11,14 ****
--- 12,16 ----
import net.sf.tapestry.ApplicationRuntimeException;
+ import net.sf.tapestry.IRequestCycle;
import net.sf.tapestry.Tapestry;
import net.sf.tapestry.util.AdaptorRegistry;
***************
*** 28,38 ****
private AdaptorRegistry _registry = new AdaptorRegistry();
- public DefaultValuePersister()
- {
- registerValueCopiers();
- }
/**
! * Invoked from {@link #registerValueCopiers()} to register the copier
* for a particular class.
*
--- 30,36 ----
private AdaptorRegistry _registry = new AdaptorRegistry();
/**
! * Invoked from {@link #initialize(IRequestCycle)} to register the copier
* for a particular class.
*
***************
*** 77,84 ****
* <p>
* An instance of {@link ArrayCopier} for <code>Object[]</code>.
*
**/
! protected void registerValueCopiers()
{
IValueCopier immutable = new ImmutableValueCopier();
--- 75,85 ----
* <p>
* An instance of {@link ArrayCopier} for <code>Object[]</code>.
+ *
+ * <p>
+ * An instance of {@link SerializableCopier} for {@link java.io.Serializable}.
*
**/
! public void initialize(IRequestCycle cycle)
{
IValueCopier immutable = new ImmutableValueCopier();
***************
*** 99,105 ****
--- 100,109 ----
registerValueCopier(Object[].class, new ArrayCopier());
+
+ registerValueCopier(Serializable.class, new SerializableCopier(cycle.getEngine().getResourceResolver()));
}
protected Object copy(Object value)
+ throws PageRecorderSerializationException
{
IValueCopier copier = getCopier(value);
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf