1 22 package org.jboss.virtual.plugins.context.jar; 23 24 import java.io.IOException ; 25 import java.net.URISyntaxException ; 26 import java.net.URL ; 27 28 import org.jboss.virtual.VirtualFile; 29 import org.jboss.virtual.plugins.context.AbstractVFSContext; 30 import org.jboss.virtual.spi.VirtualFileHandler; 31 32 39 public class JarContext extends AbstractVFSContext 40 { 41 42 private final VirtualFileHandler root; 43 44 45 private final VirtualFile rootFile; 46 47 54 public JarContext(URL rootURL) throws IOException , URISyntaxException 55 { 56 super(rootURL); 57 root = createVirtualFileHandler(null, rootURL); 58 rootFile = root.getVirtualFile(); 59 } 60 61 public VirtualFileHandler getRoot() throws IOException 62 { 63 return root; 64 } 65 66 75 public VirtualFileHandler createVirtualFileHandler(VirtualFileHandler parent, URL url) throws IOException 76 { 77 if (url == null) 78 throw new IllegalArgumentException ("Null url"); 79 80 String name = url.toString(); 81 int index = name.indexOf('!'); 82 if (index != -1) 83 name = name.substring(0, index); 84 index = name.lastIndexOf('/'); 85 if (index != -1 && index < name.length()-1) 86 name = name.substring(index+1); 87 88 return new JarHandler(this, parent, url, name); 89 } 90 91 @Override 92 protected void finalize() throws Throwable 93 { 94 if (rootFile != null) 95 rootFile.close(); 96 super.finalize(); 97 } 98 } 99 | Popular Tags |