1 29 30 package com.caucho.amber.manager; 31 32 import com.caucho.loader.EnvironmentClassLoader; 33 import com.caucho.loader.EnvironmentListener; 34 import com.caucho.vfs.JarPath; 35 import com.caucho.vfs.Path; 36 import com.caucho.vfs.Vfs; 37 38 import java.net.URL ; 39 40 43 public class PersistenceEnvironmentListener implements EnvironmentListener { 44 47 public void environmentStart(EnvironmentClassLoader loader) 48 throws Throwable 49 { 50 Path pwd = Vfs.getPwd(loader); 51 52 URL []urls = loader.getURLs(); 53 54 for (int i = 0; i < urls.length; i++) { 55 56 String s = urls[i].toString(); 58 Path path; 59 if (s.endsWith("jar!/")) { 60 s = s.substring(9, s.length()-2); 61 path = JarPath.create(pwd.lookup(s)); 62 } 63 else { 64 path = pwd.lookup(s); 65 } 66 67 Path persistenceXml = path.lookup("META-INF/persistence.xml"); 68 69 if (persistenceXml.canRead()) { 70 AmberContainer container = AmberContainer.getLocalContainer(); 71 72 container.addPersistenceRoot(path); 73 } 74 } 75 } 76 77 80 public void environmentStop(EnvironmentClassLoader loader) 81 { 82 } 83 } 84 85 86 | Popular Tags |