1 22 package org.jboss.deployers.plugins.structure.vfs; 23 24 import java.io.IOException ; 25 import java.util.ArrayList ; 26 import java.util.List ; 27 28 import org.jboss.deployers.plugins.structure.ClassPathInfoImpl; 29 import org.jboss.deployers.plugins.structure.vfs.jar.JARCandidateStructureVisitorFactory; 30 import org.jboss.deployers.spi.structure.vfs.ClassPathInfo; 31 import org.jboss.deployers.spi.structure.vfs.ContextInfo; 32 import org.jboss.deployers.spi.structure.vfs.StructureDeployer; 33 import org.jboss.deployers.spi.structure.vfs.StructureMetaData; 34 import org.jboss.deployers.spi.structure.vfs.StructuredDeployers; 35 import org.jboss.logging.Logger; 36 import org.jboss.virtual.VFSUtils; 37 import org.jboss.virtual.VirtualFile; 38 import org.jboss.virtual.VirtualFileVisitor; 39 import org.jboss.virtual.VisitorAttributes; 40 41 49 public abstract class AbstractStructureDeployer implements StructureDeployer 50 { 51 52 protected Logger log = Logger.getLogger(getClass()); 53 private int relativeOrder = Integer.MAX_VALUE; 54 55 56 private CandidateStructureVisitorFactory candidateStructureVisitorFactory = JARCandidateStructureVisitorFactory.INSTANCE; 57 58 public int getRelativeOrder() 59 { 60 return relativeOrder; 61 } 62 public void setRelativeOrder(int order) 63 { 64 this.relativeOrder = order; 65 } 66 67 68 73 public CandidateStructureVisitorFactory getCandidateStructureVisitorFactory() 74 { 75 return candidateStructureVisitorFactory; 76 } 77 78 84 public void setCandidateStructureVisitorFactory(CandidateStructureVisitorFactory candidateStructureVisitorFactory) 85 { 86 if (candidateStructureVisitorFactory == null) 87 throw new IllegalArgumentException ("Null candidateStructureVisitorFactory"); 88 this.candidateStructureVisitorFactory = candidateStructureVisitorFactory; 89 } 90 91 public abstract boolean determineStructure(VirtualFile root, 92 StructureMetaData metaData, StructuredDeployers deployers); 93 94 101 public boolean isTopLevel(VirtualFile file, StructureMetaData metaData) 102 throws IOException 103 { 104 VirtualFile parent = file.getParent(); 106 String parentPath = parent != null ? parent.getPathName() : null; 107 boolean isTopLevel = parentPath == null || metaData.getContext(parentPath) == null; 108 return isTopLevel; 109 } 110 111 123 protected void addClassPath(VirtualFile root, VirtualFile entry, 124 boolean includeEntry, boolean includeRootManifestCP, 125 ContextInfo context) 126 throws IOException 127 { 128 List <VirtualFile> paths = new ArrayList <VirtualFile>(); 130 if( includeEntry ) 131 paths.add(entry); 132 String rootPath = root.getPathName(); 133 if( includeRootManifestCP && entry.isLeaf() == false ) 134 { 135 try 136 { 137 VFSUtils.addManifestLocations(entry, paths); 138 } 139 catch(Exception e) 140 { 141 if( log.isTraceEnabled() ) 142 log.trace("Failed to add manifest locations", e); 143 } 144 } 145 List <ClassPathInfo> pathInfo = new ArrayList <ClassPathInfo>(); 147 if( context.getClassPath() != null ) 148 pathInfo.addAll(context.getClassPath()); 149 for(VirtualFile vf : paths) 151 { 152 String cp = vf.getPathName(); 154 if( !"".equals(rootPath) && cp.startsWith(rootPath) ) 155 { 156 if( cp.length() == rootPath.length() ) 157 cp = ""; 158 else 159 cp = cp.substring(rootPath.length()+1); 160 } 161 ClassPathInfoImpl cpi = new ClassPathInfoImpl(cp); 162 pathInfo.add(cpi); 163 } 164 context.setClassPath(pathInfo); 165 } 166 167 173 protected void addAllChildren(VirtualFile parent, StructureMetaData metaData, StructuredDeployers deployers) 174 throws Exception 175 { 176 addChildren(parent, metaData, deployers, null); 177 } 178 179 186 protected void addChildren(VirtualFile parent, StructureMetaData metaData, StructuredDeployers deployers, 187 VisitorAttributes attributes) throws Exception 188 { 189 if (parent == null) 190 throw new IllegalArgumentException ("Null parent"); 191 192 VirtualFileVisitor visitor = candidateStructureVisitorFactory.createVisitor(parent, metaData, deployers, attributes); 193 parent.visit(visitor); 194 } 195 } 196 | Popular Tags |