[jboss-dev-forums] [Design of Embedded JBoss] - Covarient returns from a storage delagate
johnbailey
do-not-reply at jboss.com
Fri Aug 21 00:06:26 EDT 2009
I ran into some interesting gotchas when implementing the MemoryMapArchive. The chaining API breaks down a bit when implementing a storage archive. The difficulty is the return type of the storage implementation is set to be the actual type of the archive (JavaArchive, WebArchive, etc...). So it would be expected that each method that allows chaining would have a covarient return type of the actual archive type (JavaArchive, etc...). This can't be handled just by capturing the actual class to use and performing a cast, as the storage archive is only a delegate and is not guaranteed to be an instance of the return archive type. Without multiple inheritance, I don't think we can get this to work without one of the following:
1. The storage archives don't follow the same chaining API:
| void add(Path target, String name, Asset asset) throws IllegalArgumentException;
|
instead of...
| T add(Path target, String name, Asset asset) throws IllegalArgumentException;
|
2. The storage archive must maintain a reference to be used by any chaining methods.
| /** From some storage archive **/
|
| private T primaryArchive;
|
| public void initialize(T archive)
| {
| this.primaryArchive = archive;
| }
|
| protected T covarientReturn()
| {
| return primaryArchive;
| }
|
It would be unfortunate to go the first route as Storage archives would no longer be API compliant. Option two seems to make more sense. Since it is assumed the storage archive is going to be provided to the containers, this may be problematic as there will not be a strict contract to make sure the reference is set on the storage archive. I have an impl working with the second approach, but as this is early on I want to get input on it.
Any thoughts?
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4250781#4250781
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4250781
More information about the jboss-dev-forums
mailing list