1 22 package org.jboss.ejb3; 23 24 import java.net.URL ; 25 import java.net.MalformedURLException ; 26 import java.util.Hashtable ; 27 import java.util.List ; 28 import java.util.Map ; 29 import java.io.IOException ; 30 import java.io.File ; 31 32 import org.jboss.deployment.DeploymentInfo; 33 import org.jboss.ejb3.interceptor.InterceptorInfoRepository; 34 import org.jboss.mx.util.MBeanProxyExt; 35 import org.jboss.virtual.VirtualFile; 36 import org.jboss.virtual.VFS; 37 import org.jboss.virtual.VirtualFileFilter; 38 import org.jboss.virtual.VisitorAttributes; 39 import org.jboss.virtual.plugins.context.jar.JarUtils; 40 import org.jboss.virtual.plugins.vfs.helpers.FilterVirtualFileVisitor; 41 import org.jboss.virtual.plugins.vfs.helpers.SuffixesExcludeFilter; 42 43 49 public class JmxDeploymentUnit implements DeploymentUnit 50 { 51 private DeploymentInfo deploymentInfo; 52 InterceptorInfoRepository interceptorInfoRepository = new InterceptorInfoRepository(); 53 private VirtualFile virtualFile; 54 55 public JmxDeploymentUnit(DeploymentInfo deploymentInfo) 56 { 57 this.deploymentInfo = deploymentInfo; 58 try 59 { 60 VFS vfs = VFS.getVFS(deploymentInfo.url); 61 virtualFile = vfs.getRoot(); 62 } 63 catch (IOException e) 64 { 65 throw new RuntimeException (); 66 } 67 } 68 69 70 public URL getRelativeURL(String jar) 71 { 72 URL url = null; 73 try 74 { 75 url = new URL (jar); 76 } 77 catch (MalformedURLException e) 78 { 79 try 80 { 81 if (jar.startsWith("..")) 82 { 83 if (getUrl() == null) 84 throw new RuntimeException ("relative <jar-file> not allowed when standalone deployment unit is used"); 85 String base = getUrl().toString(); 86 jar = jar.replaceAll("\\.\\./", "+"); 87 int idx = jar.lastIndexOf('+'); 88 jar = jar.substring(idx + 1); 89 for (int i = 0; i < idx + 1; i++) 90 { 91 int slash = base.lastIndexOf('/'); 92 base = base.substring(0, slash + 1); 93 } 94 url = new URL (base + jar.substring(idx)); 95 } 96 else 97 { 98 File fp = new File (jar); 99 url = fp.toURL(); 100 } 101 } 102 catch (MalformedURLException e1) 103 { 104 throw new RuntimeException ("Unable to find relative url: " + jar, e1); 105 } 106 } 107 return url; 108 } 109 110 URL extractDescriptorUrl(String resource) 111 { 112 String urlStr = deploymentInfo.url.getFile(); 113 try 115 { 116 URL dd = deploymentInfo.localCl.findResource(resource); 117 if (dd == null) 118 { 119 return null; 120 } 121 122 if (deploymentInfo.localUrl != null) 126 { 127 urlStr = deploymentInfo.localUrl.toString(); 128 } 129 130 String ddStr = dd.toString(); 131 if (ddStr.indexOf(urlStr) >= 0) 132 { 133 return dd; 134 } 135 } 136 catch (Exception ignore) 137 { 138 } 139 return null; 140 } 141 142 public URL getPersistenceXml() 143 { 144 return extractDescriptorUrl("META-INF/persistence.xml"); 145 } 146 147 public URL getEjbJarXml() 148 { 149 return extractDescriptorUrl("META-INF/ejb-jar.xml"); 150 } 151 152 public URL getJbossXml() 153 { 154 return extractDescriptorUrl("META-INF/jboss.xml"); 155 } 156 157 public List <Class > getClasses() 158 { 159 return null; 160 } 161 162 public ClassLoader getClassLoader() 163 { 164 return deploymentInfo.ucl; 165 } 166 167 public ClassLoader getResourceLoader() 168 { 169 return deploymentInfo.localCl; 170 } 171 172 public String getShortName() 173 { 174 return deploymentInfo.shortName; 175 } 176 177 public URL getUrl() 178 { 179 return deploymentInfo.url; 180 } 181 182 public String getDefaultEntityManagerName() 183 { 184 String url = getUrl().toString(); 185 String name = url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('.')); 186 return name; 187 } 188 189 public Map getDefaultPersistenceProperties() 190 { 191 try 192 { 193 EJB3DeployerMBean deployer = (EJB3DeployerMBean) MBeanProxyExt.create(EJB3DeployerMBean.class, EJB3DeployerMBean.OBJECT_NAME, 194 deploymentInfo.getServer()); 195 196 return deployer.getDefaultProperties(); 197 } 198 catch (Exception e) 199 { 200 throw new RuntimeException (e); 201 } 202 } 203 204 205 public Hashtable getJndiProperties() 206 { 207 return null; 208 } 209 210 public InterceptorInfoRepository getInterceptorInfoRepository() 211 { 212 return interceptorInfoRepository; 213 } 214 215 216 public List <VirtualFile> getResources(VirtualFileFilter filter) 217 { 218 VisitorAttributes va = new VisitorAttributes(); 219 va.setLeavesOnly(true); 220 SuffixesExcludeFilter noJars = new SuffixesExcludeFilter(JarUtils.getSuffixes()); 221 va.setRecurseFilter(noJars); 222 FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filter, va); 223 try 224 { 225 virtualFile.visit(visitor); 226 } 227 catch (IOException e) 228 { 229 throw new RuntimeException (e); 230 } 231 return visitor.getMatched(); 232 233 } 234 } 235 | Popular Tags |