1 22 package org.jboss.aop; 23 24 import org.jboss.util.file.ArchiveBrowser; 25 import org.jboss.util.file.ClassFileFilter; 26 27 import java.io.File ; 28 import java.io.FilenameFilter ; 29 import java.net.URL ; 30 import java.util.Enumeration ; 31 import java.util.Iterator ; 32 import java.util.StringTokenizer ; 33 34 40 public class Deployment 41 { 42 public static boolean searchClasspath = true; 43 44 public static void deploy() 45 { 46 try 47 { 48 49 deployThroughClassAnnotations(); 50 preconfigThroughClassPath(); 51 preconfigThroughSystemProperty(); 52 } 53 catch (Exception e) 54 { 55 e.printStackTrace(); 56 } 57 } 58 59 64 public static void preconfigThroughClassPath() 65 { 66 String search = System.getProperty("jboss.aop.search.classpath", null); 67 if (search != null) searchClasspath = (new Boolean (search)).booleanValue(); 68 if (AspectManager.verbose) System.out.println("[debug] jboss.aop.search.classpath: '" + search + "' " + searchClasspath); 69 if (searchClasspath) 70 { 71 try 72 { 73 Enumeration en = Thread.currentThread().getContextClassLoader().getResources("META-INF/jboss-aop.xml"); 74 while (en.hasMoreElements()) 75 { 76 URL url = (URL ) en.nextElement(); 77 if (AspectManager.verbose) System.out.println("[deploying] " + url); 78 AspectXmlLoader.deployXML(url); 79 } 80 } 81 catch (Exception ex) 82 { 83 throw new RuntimeException (ex); 84 } 85 } 86 } 87 88 91 public static void deployThroughClassAnnotations() 92 { 93 String path = System.getProperty("jboss.aop.class.path", null); 94 if (path == null) 95 { 96 if (AspectManager.verbose) System.out.println("[debug] jboss.aop.class.path is NULL"); 97 return; 98 } 99 if (AspectManager.verbose) System.out.println("[debug] jboss.aop.class.path: " + path); 100 StringTokenizer t = new StringTokenizer (path, File.pathSeparator); 101 while (t.hasMoreTokens()) 102 { 103 String token = t.nextToken(); 104 File f = new File (token); 105 if (!f.exists()) 106 { 107 System.err.println("[error] Unable to find jboss.aop.class.path: " + f.getName()); 108 } 109 try 110 { 111 URL url = f.toURL(); 112 Iterator it = ArchiveBrowser.getBrowser(url, new ClassFileFilter()); 113 AspectAnnotationLoader loader = new AspectAnnotationLoader(AspectManager.instance()); 114 loader.deployInputStreamIterator(it); 115 } 116 catch (Exception ex) 117 { 118 ex.printStackTrace(); 119 if (ex instanceof RuntimeException ) 120 throw (RuntimeException ) ex; 121 else 122 throw new RuntimeException ("[error] failed to load aop class path: " + f.toString(), ex); 123 } 124 } 125 } 126 127 130 public static void preconfigThroughSystemProperty() 131 { 132 String path = System.getProperty("jboss.aop.path", null); 133 if (AspectManager.verbose) System.out.println("[debug] jboss.aop.path: " + path); 134 if (path == null) return; 135 StringTokenizer t = new StringTokenizer (path, File.pathSeparator); 136 int j = 0; 137 while (t.hasMoreTokens()) 138 { 139 String token = t.nextToken(); 140 if (AspectManager.verbose) System.out.println("jboss.aop.path[" + j + "]: " + token); 141 File f = new File (token); 142 try 143 { 144 if (f.isDirectory()) 145 { 146 FilenameFilter filter = new FilenameFilter () 147 { 148 public boolean accept(File dir, String name) 149 { 150 return name.endsWith("aop.xml"); 151 } 152 }; 153 File [] files = f.listFiles(filter); 154 for (int i = 0; i < files.length; i++) 155 { 156 deployXmlFile(files[i]); 157 } 158 } 159 else 160 { 161 deployXmlFile(f); 162 } 163 } 164 catch (Exception ex) 165 { 166 ex.printStackTrace(); 167 if (ex instanceof RuntimeException ) 168 throw (RuntimeException ) ex; 169 else 170 throw new RuntimeException ("[error] failed to load aop path: " + f.toString(), ex); 171 } 172 } 173 } 174 175 private static void deployXmlFile(File f) throws Exception ![JavaDoc](../../../../cmn/javadoc.gif) 176 { 177 URL url = f.toURL(); 178 if (AspectManager.verbose) System.out.println("[deploying] " + url); 179 AspectXmlLoader.deployXML(url); 180 } 181 } 182 | Popular Tags |