1 25 26 package org.objectweb.jonas_lib.genbase.archive; 27 28 import java.io.File ; 29 import java.io.IOException ; 30 import java.io.InputStream ; 31 import java.util.Hashtable ; 32 import java.util.List ; 33 import java.util.Map ; 34 import java.util.Vector ; 35 36 import javax.xml.parsers.ParserConfigurationException ; 37 38 import org.w3c.dom.Document ; 39 import org.xml.sax.SAXException ; 40 41 import org.objectweb.jonas_client.deployment.api.ClientContainerDeploymentDesc; 42 import org.objectweb.jonas_client.deployment.lib.ClientDeploymentDescManager; 43 44 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException; 45 import org.objectweb.jonas_lib.deployment.api.EjbRefDesc; 46 import org.objectweb.jonas_lib.genbase.GenBaseException; 47 import org.objectweb.jonas_lib.genbase.utils.XMLUtils; 48 import org.objectweb.jonas_lib.loader.ClientClassLoader; 49 50 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc; 51 52 import org.objectweb.util.monolog.api.BasicLevel; 53 54 59 public class Client extends J2EEArchive implements EjbRefModule, WsClient { 60 61 62 private Application app = null; 63 64 65 private ClientContainerDeploymentDesc clientDD = null; 66 67 68 private List sRefs; 69 70 73 private List ejbRefs; 74 75 76 private Map descriptors; 77 78 81 private Document jclientDoc; 82 83 90 public Client(Archive archive) throws GenBaseException { 91 super(archive); 92 if (getLogger().isLoggable(BasicLevel.DEBUG)) { 93 getLogger().log(BasicLevel.DEBUG, "Wrapping '" + archive.getName() + "' in Client"); 94 } 95 init(); 96 } 97 98 106 public Client(Archive archive, Application app) throws GenBaseException { 107 super(archive); 108 setApplication(app); 109 if (getLogger().isLoggable(BasicLevel.DEBUG)) { 110 getLogger().log(BasicLevel.DEBUG, "Wrapping '" + archive.getName() + "' in Client"); 111 } 112 init(); 113 } 114 115 121 private void init() throws GenBaseException { 122 loadDescriptors(); 123 } 124 125 130 private void loadDescriptors() throws GenBaseException { 131 132 descriptors = new Hashtable (); 133 try { 134 InputStream jcis = getJonasClientInputStream(); 135 if (jcis != null) { 136 jclientDoc = XMLUtils.newDocument(jcis, "META-INF/jonas-client.xml", isDTDsAllowed()); 137 descriptors.put("META-INF/jonas-client.xml", jclientDoc); 138 } 139 } catch (SAXException saxe) { 140 String err = getI18n().getMessage("Client.loadDescriptors.parseError"); 141 throw new GenBaseException(err, saxe); 142 } catch (ParserConfigurationException pce) { 143 String err = getI18n().getMessage("Client.loadDescriptors.prepare"); 144 throw new GenBaseException(err, pce); 145 } catch (IOException ioe) { 146 String err = getI18n().getMessage("Client.loadDescriptors.parseError"); 147 throw new GenBaseException(err, ioe); 148 } 149 } 150 151 156 public void setApplication(Application app) { 157 this.app = app; 158 } 159 160 165 public Application getApplication() { 166 return app; 167 } 168 169 174 public List getServiceRefDescs() { 175 return sRefs; 176 } 177 178 183 public void addClasses(File classes) { 184 addDirectory(classes); 185 } 186 187 193 public Map getDescriptors() { 194 return descriptors; 195 } 196 197 204 public boolean omit(String name) { 205 return (name.equals("META-INF/jonas-client.xml") || name.equals("META-INF\\jonas-client.xml")); 206 } 207 208 213 public Document getJonasClientDoc() { 214 return jclientDoc; 215 } 216 217 225 public InputStream getJonasClientInputStream() throws IOException { 226 InputStream is = null; 227 228 if (isPacked()) { 229 is = getInputStream("META-INF/jonas-client.xml"); 230 } else { 231 is = getInputStream("META-INF" + File.separator + "jonas-client.xml"); 232 } 233 234 return is; 235 } 236 237 241 public void initialize() throws GenBaseException { 242 245 try { 246 if (app == null) { 247 setModuleClassloader(new ClientClassLoader(getArchive().getRootFile().toURL(), Thread.currentThread() 249 .getContextClassLoader())); 250 } else { 251 setModuleClassloader(new ClientClassLoader(getArchive().getRootFile().toURL(), app.getEJBClassLoader())); 253 } 254 } catch (IOException ioe) { 255 String err = getI18n().getMessage("Client.init.loader", getArchive().getRootFile()); 256 throw new GenBaseException(err, ioe); 257 } 258 259 try { 260 clientDD = ClientDeploymentDescManager.getInstance(getRootFile().getAbsolutePath(), getModuleClassloader()); 261 } catch (DeploymentDescException dde) { 262 throw new GenBaseException(dde); 263 } 264 265 sRefs = new Vector (); 267 ServiceRefDesc[] refs = clientDD.getServiceRefDesc(); 268 for (int i = 0; i < refs.length; i++) { 269 sRefs.add(refs[i]); 270 } 271 272 ejbRefs = new Vector (); 274 EjbRefDesc[] refDesc = clientDD.getEjbRefDesc(); 275 276 for (int i = 0; i < refDesc.length; i++) { 277 ejbRefs.add(refDesc[i]); 278 } 279 280 } 281 282 286 public List getEjbRefDescs() { 287 return ejbRefs; 288 } 289 290 293 public void close() { 294 super.close(); 295 ejbRefs = null; 296 clientDD = null; 297 app = null; 298 descriptors = null; 299 jclientDoc = null; 300 } 301 } | Popular Tags |