1 22 package org.jboss.deployers.plugins.structure.vfs.file; 23 24 import java.util.Set ; 25 import java.util.concurrent.CopyOnWriteArraySet ; 26 27 import org.jboss.deployers.plugins.structure.ContextInfoImpl; 28 import org.jboss.deployers.plugins.structure.vfs.AbstractStructureDeployer; 29 import org.jboss.deployers.spi.structure.vfs.StructureMetaData; 30 import org.jboss.deployers.spi.structure.vfs.StructuredDeployers; 31 import org.jboss.virtual.VirtualFile; 32 33 39 public class FileStructure extends AbstractStructureDeployer 40 { 41 42 private static Set <String > fileSuffixes = new CopyOnWriteArraySet <String >(); 43 44 static 46 { 47 fileSuffixes.add("-service.xml"); 48 fileSuffixes.add("-beans.xml"); 49 fileSuffixes.add("-ds.xml"); 50 fileSuffixes.add("-aop.xml"); 51 } 52 53 public FileStructure() 54 { 55 56 } 57 58 public FileStructure(Set <String > suffixes) 59 { 60 fileSuffixes.clear(); 61 fileSuffixes.addAll(suffixes); 62 } 63 64 69 public Set <String > getSuffixes() 70 { 71 return fileSuffixes; 72 } 73 74 75 82 public static boolean addFileSuffix(String suffix) 83 { 84 if (suffix == null) 85 throw new IllegalArgumentException ("Null suffix"); 86 return fileSuffixes.add(suffix); 87 } 88 89 96 public static boolean removeFileSuffix(String suffix) 97 { 98 if (suffix == null) 99 throw new IllegalArgumentException ("Null suffix"); 100 return fileSuffixes.remove(suffix); 101 } 102 103 110 public static boolean isKnownFile(String name) 111 { 112 if (name == null) 113 throw new IllegalArgumentException ("Null name"); 114 115 int index = name.lastIndexOf('-'); 116 if (index == -1) 117 return false; 118 String suffix = name.substring(index); 119 return fileSuffixes.contains(suffix); 120 } 121 122 public boolean determineStructure(VirtualFile root, StructureMetaData metaData, StructuredDeployers deployers) 123 { 124 try 125 { 126 if (root.isLeaf()) 127 { 128 if (isTopLevel(root, metaData) == false) 130 { 131 if (isKnownFile(root.getName()) == false) 132 { 133 log.trace("... no - it is not a top level file and not a known name"); 134 return false; 135 } 136 else 137 { 138 log.trace("... ok - not a top level file but it is a known name"); 139 } 140 } 141 else 142 { 143 log.trace("... ok - it is a top level file"); 144 } 145 146 ContextInfoImpl context = new ContextInfoImpl(root.getPathName()); 148 metaData.addContext(context); 149 return true; 151 } 152 else 153 { 154 log.trace("... no - not a file."); 155 return false; 156 } 157 } 158 catch (Exception e) 159 { 160 log.warn("Error determining structure: " + root.getName(), e); 161 return false; 162 } 163 } 164 } 165 | Popular Tags |