jsr344-experts@javaserverfaces-spec-public.java.net

[jsr344-experts] Re: [1144-ResourceWrapperExternalizable] PROPOSAL

From: Ken Finnigan <kfinniga_at_redhat.com>
Date: Tue, 13 Nov 2012 10:39:35 -0500 (EST)

After looking at the implementation implications for what I've proposed, I think some changes to the proposed solution are in order.

As getWrapped() returns a Resource, we need to make Resource implement Externalizable instead of ResourceWrapper.

This change would result in the following methods on Resource being added:

public void writeExternal(ObjectOutput out) throws IOException {

out.writeObject(resourceName);
out.writeObject(libraryName);
out.writeObject(contentType);
}

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {

resourceName = (String) in.readObject();
libraryName = (String) in.readObject();
contentType = (String) in.readObject();
}

Which would change the implementation of ResourceImpl by removing Externalizable from implements and modifying those methods to be:

public void writeExternal(ObjectOutput out) throws IOException {

super.writeExternal(out);
out.writeLong(initialTime);
out.writeLong(maxAge);

}

public void readExternal(ObjectInput in)
throws IOException, ClassNotFoundException {

super.readExternal(in);
initialTime = in.readLong();
maxAge = in.readLong();
}

Then ResourceWrapper would declare readExternal() and writeExternal() as abstract, like getWrapped().

Then a possible implementation of ResourceWrapper would override them with the following, assuming the class called the instance it was wrapping "wrapped":

public void writeExternal(ObjectOutput out) throws IOException {

out.writeObject(wrapped.getClass().getName());
wrapped.writeExternal(out);
}

public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
wrapped = Class.forName((String)in.readObject());
wrapped.readExternal(in);

}

Regards
Ken Finnigan

----- Original Message -----

> From: "Ken Finnigan" <kfinniga_at_redhat.com>
> To: jsr344-experts_at_javaserverfaces-spec-public.java.net
> Sent: Tuesday, November 13, 2012 10:04:12 AM
> Subject: [jsr344-experts] [1144-ResourceWrapperExternalizable]
> PROPOSAL

> Hello Volunteers,

> Suggest modifying ResourceWrapper to implement Externalizable and
> alter the class javadoc to be something like:
> > Provides a simple implementation of Resource that can be subclassed
> > by developers wishing to provide specialized behavior to an
> > existing
> > Resource instance. The default implementation of all Resource
> > methods is to call through to the wrapped Resource.
>
> > Usage: extend this class, override getWrapped() to return the
> > instance we are wrapping and implement Externalizable methods by
> > calling their super equivalents.
>
> Method javadoc for writeExternal():
> > Write the wrapped Resource to ObjectOutput such that it can be read
> > by readExternal().
>
> Method javadoc for readExternal():
> > Read the ObjectInput to recreate the wrapped Resource.
>
> Regards
> Ken Finnigan