Programmatic policy for jar handling
alesj Apr 15, 2008 6:40 AMRegarding yesterday's discussion about breaking existing external frameworks working on top of VFS and no_copy jar handling.
One way to change the behavior is by changing URI, to add additional query parameter.
But I think we should add better control over this, introducing some sort of policy into VFSContext (or some other top level handle).
This is what I have initially in mind:
public interface JarHandlerPolicy { /** * Should we create a copy. * * @param context * @param parent * @param jarFile * @param entry * @param url * @param entryName * @return */ boolean createCopy(VFSContext context, VirtualFileHandler parent, JarFile jarFile, ZipEntry entry, URL url, String entryName); }
which would get used at the point where we decide whether we copy the jar or not:
JarHandlerPolicy policy = context.getPolicy(); if (forceCopy || policy.createCopy(context, parent, getJar(), entry, url, entryName)) vfh = NestedJarHandler.create(context, parent, getJar(), entry, url, entryName); else vfh = new NoCopyNestedJarHandler(context, parent, getJar(), entry, url, entryName);
And for example, very simple war policy would look like
public class WarHandlingPolicy extends AbstractJarHandlingPolicy { public boolean internalCreateCopy(VFSContext context, VirtualFileHandler parent, JarFile jarFile, ZipEntry entry, URL url, String entryName) { return entryName.contains(".war"); } } public abstract class AbstractJarHandlingPolicy implements JarHandlerPolicy { public boolean createCopy(VFSContext context, VirtualFileHandler parent, JarFile jarFile, ZipEntry entry, URL url, String entryName) { return hasCopyOption(context) || internalCreateCopy(context, parent, jarFile, entry, url, entryName); } protected abstract boolean internalCreateCopy(VFSContext context, VirtualFileHandler parent, JarFile jarFile, ZipEntry entry, URL url, String entryName); protected boolean hasCopyOption(VFSContext context) { Map<String, String> options = context.getOptions(); return (options != null && options.get(VFSUtils.USE_COPY_QUERY) != null); } }
The question is, if we decide to go this way, where do we set this policy?