1 28 29 package com.caucho.server.e_app; 30 31 import com.caucho.config.Config; 32 import com.caucho.log.Log; 33 import com.caucho.server.deploy.ExpandDeployController; 34 import com.caucho.util.L10N; 35 import com.caucho.vfs.JarPath; 36 import com.caucho.vfs.Path; 37 import com.caucho.vfs.Vfs; 38 39 import java.util.ArrayList ; 40 import java.util.Iterator ; 41 import java.util.logging.Logger ; 42 43 46 public class AppClientDeployController extends ExpandDeployController<EntAppClient> { 47 private static final Logger log = Log.open(AppClientDeployController.class); 48 private static final L10N L = new L10N(AppClientDeployController.class); 49 50 private String _name = ""; 52 53 55 private JarPath _clientJar; 56 57 private ArrayList <Path> _configList = new ArrayList <Path>(); 58 59 private boolean _isInit; 60 61 public AppClientDeployController() 62 { 63 super("client"); 64 } 65 66 69 public void setRootDirectory(Path path) 70 { 71 super.setRootDirectory(path); 72 } 73 74 77 public void addConfig(Path path) 78 { 79 _configList.add(path); 80 } 81 82 85 public void addEar(Path path) 86 { 87 System.out.println("ADD EAR: " + path); 88 89 JarPath jar = JarPath.create(path); 90 91 Path app = jar.lookup("META-INF/application.xml"); 92 93 System.out.println(" APP: " + app + " " + app.exists()); 94 95 if (app.exists()) 96 addConfig(app); 97 98 app = jar.lookup("META-INF/resin-application.xml"); 99 100 System.out.println(" APP: " + app + " " + app.exists()); 101 102 if (app.exists()) 103 addConfig(app); 104 } 105 106 109 public void main(String []args) 110 throws Throwable 111 { 112 System.out.println("MAIN()"); 113 init(); 114 start(); 115 116 EntAppClient appClient = request(); 117 if (appClient != null) 118 appClient.main(args); 119 } 120 121 124 public void main(String mainClass, String []args) 125 throws Throwable 126 { 127 System.out.println("MAIN: " + mainClass); 128 init(); 129 start(); 130 131 EntAppClient appClient = request(); 132 System.out.println("MAIN: " + appClient + " " + mainClass); 133 if (appClient != null) 134 appClient.main(mainClass, args); 135 } 136 137 public ClassLoader getLoader() 139 { 140 init(); 141 start(); 142 143 EntAppClient appClient = request(); 144 145 if (appClient != null) 146 return appClient.getClassLoader(); 147 else 148 return null; 149 } 150 151 154 protected EntAppClient instantiateDeployInstance() 155 { 156 return new EntAppClient(this, getId()); 157 } 158 159 162 protected void configureInstance(EntAppClient appClient) 163 throws Throwable 164 { 165 Thread thread = Thread.currentThread(); 166 ClassLoader oldLoader = thread.getContextClassLoader(); 167 168 Path rootDir = null; 169 try { 170 thread.setContextClassLoader(getParentClassLoader()); 171 172 appClient.setArchivePath(getArchivePath()); 173 174 rootDir = getRootDirectory(); 175 176 if (rootDir == null) 177 throw new NullPointerException ("Null root-directory"); 178 179 185 186 appClient.setRootDirectory(rootDir); 187 188 thread.setContextClassLoader(appClient.getClassLoader()); 189 Vfs.setPwd(rootDir); 190 191 addManifestClassPath(); 192 193 configApplication(appClient); 194 195 197 Path curr = rootDir; 198 199 Iterator <String > it = curr.iterator(); 200 201 while (it.hasNext()) { 202 203 String s = it.next(); 204 205 Path path = curr.lookup(s); 206 207 if (path.isDirectory()) { 208 } 209 else if (s.endsWith(".jar")) { 210 appClient.getClassLoader().addJar(path); 211 212 _clientJar = JarPath.create(path); 213 214 configClientApplication(appClient); 215 } 216 } 217 218 for (int i = 0; i < _configList.size(); i++) 219 configClientConfig(appClient, _configList.get(i)); 220 221 appClient.init(); 222 } finally { 223 thread.setContextClassLoader(oldLoader); 224 } 225 } 226 227 private void configApplication(EntAppClient appClient) 228 throws Exception 229 { 230 Path rootDir = getRootDirectory(); 231 232 Path xml = rootDir.lookup("META-INF/application.xml"); 233 234 if (xml.canRead()) 235 new Config().configureBean(appClient, xml); 236 237 xml = rootDir.lookup("META-INF/resin-application.xml"); 238 239 if (xml.canRead()) 240 new Config().configureBean(appClient, xml); 241 242 246 247 256 257 285 } 286 287 private void configClientApplication(EntAppClient appClient) 288 throws Exception 289 { 290 if (_clientJar == null) 291 return; 292 293 Path xml = _clientJar.lookup("META-INF/application-client.xml"); 294 295 if (! xml.canRead()) 296 return; 297 298 new Config().configureBean(appClient, xml, 299 "com/caucho/server/e_app/app-client.rnc"); 300 } 301 302 private void configClientConfig(EntAppClient appClient, Path xml) 303 throws Exception 304 { 305 if (! xml.canRead()) 306 return; 307 308 new Config().configureBean(appClient, xml); 309 } 310 311 314 public boolean equals(Object o) 315 { 316 if (! (o instanceof AppClientDeployController)) 317 return false; 318 319 AppClientDeployController controller = (AppClientDeployController) o; 320 321 return getId().equals(controller.getId()); 322 } 323 324 327 public String toString() 328 { 329 return "AppClientDeployController[" + getId() + "]"; 330 } 331 } 332 | Popular Tags |