00001
00026 package org.objectweb.jonas_lib.genbase.archive;
00027
00028 import java.io.File;
00029 import java.io.IOException;
00030 import java.io.InputStream;
00031 import java.util.Hashtable;
00032 import java.util.List;
00033 import java.util.Map;
00034 import java.util.Vector;
00035
00036 import javax.xml.parsers.ParserConfigurationException;
00037
00038 import org.w3c.dom.Document;
00039 import org.xml.sax.SAXException;
00040
00041 import org.objectweb.jonas_client.deployment.api.ClientContainerDeploymentDesc;
00042 import org.objectweb.jonas_client.deployment.lib.ClientDeploymentDescManager;
00043
00044 import org.objectweb.jonas_lib.deployment.api.DeploymentDescException;
00045 import org.objectweb.jonas_lib.deployment.api.EjbRefDesc;
00046 import org.objectweb.jonas_lib.genbase.GenBaseException;
00047 import org.objectweb.jonas_lib.genbase.utils.XMLUtils;
00048 import org.objectweb.jonas_lib.loader.ClientClassLoader;
00049
00050 import org.objectweb.jonas_ws.deployment.api.ServiceRefDesc;
00051
00052 import org.objectweb.util.monolog.api.BasicLevel;
00053
00059 public class Client extends J2EEArchive implements EjbRefModule, WsClient {
00060
00062 private Application app = null;
00063
00065 private ClientContainerDeploymentDesc clientDD = null;
00066
00068 private List sRefs;
00069
00073 private List ejbRefs;
00074
00076 private Map descriptors;
00077
00081 private Document jclientDoc;
00082
00090 public Client(Archive archive) throws GenBaseException {
00091 super(archive);
00092 getLogger().log(BasicLevel.DEBUG, "Wrapping '" + archive.getName() + "' in Client");
00093 init();
00094 }
00095
00104 public Client(Archive archive, Application app) throws GenBaseException {
00105 super(archive);
00106 setApplication(app);
00107 getLogger().log(BasicLevel.DEBUG, "Wrapping '" + archive.getName() + "' in Client");
00108 init();
00109 }
00110
00117 private void init() throws GenBaseException {
00118 loadDescriptors();
00119 }
00120
00126 private void loadDescriptors() throws GenBaseException {
00127
00128 descriptors = new Hashtable();
00129 try {
00130 InputStream jcis = getJonasClientInputStream();
00131 if (jcis != null) {
00132 jclientDoc = XMLUtils.newDocument(jcis, "META-INF/jonas-client.xml", isDTDsAllowed());
00133 descriptors.put("META-INF/jonas-client.xml", jclientDoc);
00134 }
00135 } catch (SAXException saxe) {
00136 String err = getI18n().getMessage("Client.loadDescriptors.parseError");
00137 throw new GenBaseException(err, saxe);
00138 } catch (ParserConfigurationException pce) {
00139 String err = getI18n().getMessage("Client.loadDescriptors.prepare");
00140 throw new GenBaseException(err, pce);
00141 } catch (IOException ioe) {
00142 String err = getI18n().getMessage("Client.loadDescriptors.parseError");
00143 throw new GenBaseException(err, ioe);
00144 }
00145 }
00146
00152 public void setApplication(Application app) {
00153 this.app = app;
00154 }
00155
00161 public Application getApplication() {
00162 return app;
00163 }
00164
00170 public List getServiceRefDescs() {
00171 return sRefs;
00172 }
00173
00179 public void addClasses(File classes) {
00180 addDirectory(classes);
00181 }
00182
00189 public Map getDescriptors() {
00190 return descriptors;
00191 }
00192
00200 public boolean omit(String name) {
00201 return (name.equals("META-INF/jonas-client.xml") || name.equals("META-INF\\jonas-client.xml"));
00202 }
00203
00209 public Document getJonasClientDoc() {
00210 return jclientDoc;
00211 }
00212
00221 public InputStream getJonasClientInputStream() throws IOException {
00222 InputStream is = null;
00223
00224 if (isPacked()) {
00225 is = getInputStream("META-INF/jonas-client.xml");
00226 } else {
00227 is = getInputStream("META-INF" + File.separator + "jonas-client.xml");
00228 }
00229
00230 return is;
00231 }
00232
00237 public void initialize() throws GenBaseException {
00238
00239
00240
00241 try {
00242 if (app == null) {
00243
00244 setModuleClassloader(new ClientClassLoader(getArchive().getRootFile().toURL(), Thread.currentThread()
00245 .getContextClassLoader()));
00246 } else {
00247
00248 setModuleClassloader(new ClientClassLoader(getArchive().getRootFile().toURL(), app.getEJBClassLoader()));
00249 }
00250 } catch (IOException ioe) {
00251 String err = getI18n().getMessage("Client.init.loader", getArchive().getRootFile());
00252 throw new GenBaseException(err, ioe);
00253 }
00254
00255 try {
00256 clientDD = ClientDeploymentDescManager.getInstance(getRootFile().getAbsolutePath(), getModuleClassloader());
00257 } catch (DeploymentDescException dde) {
00258 throw new GenBaseException(dde);
00259 }
00260
00261
00262 sRefs = new Vector();
00263 ServiceRefDesc[] refs = clientDD.getServiceRefDesc();
00264 for (int i = 0; i < refs.length; i++) {
00265 sRefs.add(refs[i]);
00266 }
00267
00268
00269 ejbRefs = new Vector();
00270 EjbRefDesc[] refDesc = clientDD.getEjbRefDesc();
00271
00272 for (int i = 0; i < refDesc.length; i++) {
00273 ejbRefs.add(refDesc[i]);
00274 }
00275
00276 }
00277
00282 public List getEjbRefDescs() {
00283 return ejbRefs;
00284 }
00285 }