1 22 package org.jboss.virtual.plugins.context.jar; 23 24 import java.io.FileNotFoundException ; 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 import java.net.URL ; 28 import java.util.ArrayList ; 29 import java.util.Collections ; 30 import java.util.HashMap ; 31 import java.util.List ; 32 import java.util.Map ; 33 34 import org.jboss.virtual.plugins.context.AbstractURLHandler; 35 import org.jboss.virtual.plugins.context.StructuredVirtualFileHandler; 36 import org.jboss.virtual.spi.VFSContext; 37 import org.jboss.virtual.spi.VirtualFileHandler; 38 39 45 public class SynthenticDirEntryHandler extends AbstractURLHandler 46 implements StructuredVirtualFileHandler 47 { 48 49 private static final long serialVersionUID = 1L; 50 51 52 private long lastModified; 53 private transient List <VirtualFileHandler> entryChildren; 54 private transient Map <String , VirtualFileHandler> entryMap; 55 56 67 public SynthenticDirEntryHandler(VFSContext context, VirtualFileHandler parent, 68 String entryName, long lastModified, URL url) 69 throws IOException 70 { 71 super(context, parent, url, entryName); 72 this.lastModified = lastModified; 73 } 74 75 79 public void addChild(VirtualFileHandler child) 80 { 81 if( entryChildren == null ) 82 entryChildren = new ArrayList <VirtualFileHandler>(); 83 entryChildren.add(child); 84 } 85 86 @Override 87 public long getLastModified() 88 { 89 return lastModified; 90 } 91 92 @Override 93 public long getSize() 94 { 95 return 0; 96 } 97 98 public boolean isLeaf() 99 { 100 return false; 101 } 102 103 public boolean isHidden() 104 { 105 checkClosed(); 106 return false; 107 } 108 109 @Override 110 public InputStream openStream() throws IOException 111 { 112 throw new IOException ("Directories cannot be opened"); 113 } 114 115 public List <VirtualFileHandler> getChildren(boolean ignoreErrors) throws IOException 116 { 117 checkClosed(); 118 List <VirtualFileHandler> children = entryChildren; 119 if( entryChildren == null ) 120 children = Collections.emptyList(); 121 return children; 122 } 123 124 public VirtualFileHandler findChild(String path) throws IOException 125 { 126 return super.structuredFindChild(path); 127 } 128 129 132 public VirtualFileHandler createChildHandler(String name) throws IOException 133 { 134 if( entryChildren == null ) 135 throw new FileNotFoundException (this+" has no children"); 136 if( entryMap == null ) 137 { 138 entryMap = new HashMap <String , VirtualFileHandler>(); 139 for(VirtualFileHandler child : entryChildren) 140 entryMap.put(child.getName(), child); 141 } 142 VirtualFileHandler child = entryMap.get(name); 143 if( child == null ) 144 throw new FileNotFoundException (this+" has no child: "+name); 145 return child; 146 } 147 148 } 149 | Popular Tags |