1 22 package org.jboss.ejb3.deployers; 23 24 import org.jboss.deployers.spi.deployer.DeploymentUnit; 25 import org.jboss.ejb3.interceptor.InterceptorInfoRepository; 26 import org.jboss.virtual.VirtualFile; 27 import org.jboss.virtual.VirtualFileFilter; 28 import org.jboss.virtual.VisitorAttributes; 29 import org.jboss.virtual.plugins.context.jar.JarUtils; 30 import org.jboss.virtual.plugins.vfs.helpers.FilterVirtualFileVisitor; 31 import org.jboss.virtual.plugins.vfs.helpers.SuffixesExcludeFilter; 32 33 import java.net.URL ; 34 import java.net.MalformedURLException ; 35 import java.net.URISyntaxException ; 36 import java.util.Hashtable ; 37 import java.util.List ; 38 import java.util.Map ; 39 import java.io.IOException ; 40 import java.io.File ; 41 42 48 public class JBoss5DeploymentUnit implements org.jboss.ejb3.DeploymentUnit 49 { 50 private DeploymentUnit deploymentInfo; 51 private InterceptorInfoRepository interceptorInfoRepository = new InterceptorInfoRepository(); 52 private Map defaultPersistenceProperties; 53 54 public JBoss5DeploymentUnit(DeploymentUnit deploymentInfo) 55 { 56 this.deploymentInfo = deploymentInfo; 57 } 58 59 60 public URL getRelativeURL(String jar) 61 { 62 try 63 { 64 return new URL (jar); 65 } 66 catch (MalformedURLException e) 67 { 68 try 69 { 70 if (jar.startsWith("..")) 71 { 72 if (getUrl() == null) 73 throw new RuntimeException ("relative <jar-file> not allowed when standalone deployment unit is used"); 74 String tmpjar = jar.substring(3); 75 VirtualFile vf = deploymentInfo.getDeploymentContext().getRoot().getParent().findChild(tmpjar); 76 return vf.toURL(); 77 } 78 else 79 { 80 File fp = new File(jar); 81 return fp.toURL(); 82 } 83 } 84 catch (Exception e1) 85 { 86 throw new RuntimeException ("could not find relative path: " + jar, e1); 87 } 88 } 89 } 90 91 URL extractDescriptorUrl(String resource) 92 { 93 try 94 { 95 VirtualFile vf = deploymentInfo.getMetaDataFile(resource); 96 if (vf == null) return null; 97 return vf.toURL(); 98 } 99 catch (Exception e) 100 { 101 throw new RuntimeException (e); 102 } 103 } 104 105 public URL getPersistenceXml() 106 { 107 return extractDescriptorUrl("persistence.xml"); 108 } 109 110 public URL getEjbJarXml() 111 { 112 return extractDescriptorUrl("ejb-jar.xml"); 113 } 114 115 public URL getJbossXml() 116 { 117 return extractDescriptorUrl("jboss.xml"); 118 } 119 120 public List <Class > getClasses() 121 { 122 return null; 123 } 124 125 public ClassLoader getClassLoader() 126 { 127 return deploymentInfo.getClassLoader(); 128 } 129 130 public ClassLoader getResourceLoader() 131 { 132 return deploymentInfo.getClassLoader(); 133 } 134 135 public String getShortName() 136 { 137 return deploymentInfo.getDeploymentContext().getRoot().getName(); 138 } 139 140 public URL getUrl() 141 { 142 try 143 { 144 return deploymentInfo.getDeploymentContext().getRoot().toURL(); 145 } 146 catch (Exception e) 147 { 148 throw new RuntimeException (e); 149 } 150 } 151 152 public String getDefaultEntityManagerName() 153 { 154 String url = getUrl().toString(); 155 String name = url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('.')); 156 return name; 157 } 158 159 public Map getDefaultPersistenceProperties() 160 { 161 return defaultPersistenceProperties; 162 } 163 164 public void setDefaultPersistenceProperties(Map defaultPersistenceProperties) 165 { 166 this.defaultPersistenceProperties = defaultPersistenceProperties; 167 } 168 169 public Hashtable getJndiProperties() 170 { 171 return null; 172 } 173 174 public InterceptorInfoRepository getInterceptorInfoRepository() 175 { 176 return interceptorInfoRepository; 177 } 178 179 public List <VirtualFile> getResources(VirtualFileFilter filter) 180 { 181 VisitorAttributes va = new VisitorAttributes(); 182 va.setLeavesOnly(true); 183 SuffixesExcludeFilter noJars = new SuffixesExcludeFilter(JarUtils.getSuffixes()); 184 va.setRecurseFilter(noJars); 185 FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter, va); 186 187 List <VirtualFile> classpath = deploymentInfo.getDeploymentContext().getClassPath(); 188 if (classpath != null) 189 { 190 for (VirtualFile vf : classpath) 191 { 192 try 193 { 194 vf.visit(visitor); 195 } 196 catch (IOException e) 197 { 198 throw new RuntimeException (e); 199 } 200 } 201 } 202 return visitor.getMatched(); 203 } 204 205 } 206 | Popular Tags |