[jboss-dev-forums] [Embedded JBoss Development] - Re: ShrinkWrap - Descriptors

aslak do-not-reply at jboss.com
Mon Sep 28 10:38:02 EDT 2009


"epbernard" wrote : 
  | "aslak" wrote : 
  |   | They all 'share' the same base Archive impl as a backing, so there is no problem having code like this:
  |   | 
  |   | 
  |   |   | WebArchive war = new WebArchiveImpl(new MemoryMapArchiveImpl());
  |   |   | EnterpriseArchive ear = new EnterpriseArchiveImpl(war.getInternalArchive());
  |   |   | 
  |   | 
  | 
  | well this code is fugly, that's a huge problem :)
  | 

Hehe, yes, that is fugly, but it was just to illustrate that the WebArchives backing can easily be moved to run as the EnterpriseArchives backing.

"epbernard" wrote : 
  | "aslak" wrote : 
  |   | 
  |   |   | EnterpriseArchive ear = new EnterpriseArchiveImpl(new MemoryMapArchiveImpl());
  |   |   | WebArchive war = ear.getWebModule("my.war");
  |   |   | 
  |   | 
  | That's a different scenario here, you are creating a new archive so a dedicated method makes sense.
  | 
True, but the getWebModule() impl would use the specializer api internally was the point.

"epbernard" wrote : 
  | Still it seems to me that delegation is less heavy on the specializer implementation and subclassing the core archive impl does not give you much.
  | 
I'm not sure I understand. The way it is today is as following:
interface WebArchive extends ResourceContainer, ClassContainer....
WebArchiveImpl extends ContainerBase implements  WebArchive -> has a Archive

WebArchiveImpl is a pure delegator to the Archive, but with some fixed prefix Paths etc to follow the War spec, ie ClassContainer mappes to /WEB-INF/classes/.

There is no subclassing of the backing Archive(MemoryMapArchiveImpl) in WebArchiveImpl.

The different archive extensions(WarArchive, EnterpriseArchive etc) extend a common ContainerBase class, but that is only as a convenient way of implementing the diff containers.

I see no problem with adding a spercializes method to the Archive interface and having a common impl in the ContainerBase(or even ArchiveBase) to load the spercialized impl. Something like.


  | public class ContainerBase {
  | ...
  |    T specializes(Class<T extends Archive<T>> clazz) {
  |      return specializes(clazz, new BasicPath("/"))
  |    }
  | 
  |    T specializes(Class<T extends Archive<T>> clazz, Path basePath) {
  |      pesudo: 
  |         lookup delegation implementation of clazz, ie WebArchiveImpl
  |         return new WebArchiveImpl(basePath, this.backingArchive);
  |    }
  | ...
  | }
  | 
This will open up for:

  | EnterpriseArchive ear = ...
  | WarArchive war = ear.specializes(WebArchive.class, "my.war");
  | 
  | war = ear.getWebModule("my.war") {
  |    return this.specializes(WebArchive.class, "my.war");
  | };
  | 
  | JavaArchive jar = ...
  | WebArchive war = jar.specializes(WebArchive.class);
  | 
  | 

The 'Descriptor' part is a bit different since it operates on the content of a Asset, but if we turn them around to be pretty much the same as the archive extensions ie:
WebArchiveDescriptor has a Archive. 
and WebArchive no long impls WebArchiveDescriptor

we could do 

  | WebArchive war = 
  | WebArchiveDescriptor desc = war.specializes(WebArchiveDescriptor.class);
  | desc.addServlet()...
  | 

Which is what you're referring to I guess.. 

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4257398#4257398

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4257398



More information about the jboss-dev-forums mailing list