KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ws7 > dm > WS70SunDeploymentFactory


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * WS70SunDeploymentFactory.java
22  */

23 package org.netbeans.modules.j2ee.sun.ws7.dm;
24
25 import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager JavaDoc;
26 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
27 import javax.enterprise.deploy.spi.factories.DeploymentFactory JavaDoc;
28 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException JavaDoc;
29 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
30
31 import org.openide.ErrorManager;
32 import org.openide.util.NbBundle;
33 import org.netbeans.modules.j2ee.sun.ws7.WS7LibsClassLoader;
34 import org.netbeans.modules.j2ee.sun.ws7.ui.WS70URIManager;
35 import org.netbeans.modules.j2ee.sun.ws7.ui.WS70ServerUIWizardIterator;
36 import java.io.File JavaDoc;
37 import java.util.HashMap JavaDoc;
38
39 public class WS70SunDeploymentFactory implements DeploymentFactory JavaDoc {
40     private DeploymentFactory JavaDoc ws70DF;
41     private static HashMap JavaDoc ws7ClassLoaders;
42     private static HashMap JavaDoc connectedDepManagers;
43     private static final String JavaDoc HTTPS=":https";//NOI18N
44

45     public static synchronized Object JavaDoc create(){
46         try{
47             DeploymentFactory JavaDoc factory = new WS70SunDeploymentFactory();
48             DeploymentFactoryManager.getInstance().registerDeploymentFactory (factory);
49             return factory;
50         }catch(Exception JavaDoc ex){
51             ex.printStackTrace();
52         }
53         return null;
54     }
55
56     /**
57      * Creates a new instance of WS70SunDeploymentFactory
58      */

59     public WS70SunDeploymentFactory() {
60         ws7ClassLoaders = new HashMap JavaDoc();
61         connectedDepManagers = new HashMap JavaDoc();
62     }
63
64     
65     /**
66      * Factory method to create DeploymentManager.
67      * @param uri URL of configured manager application.
68      * @param uname user with granted manager role
69      * @param passwd user's password
70      * @throws DeploymentManagerCreationException
71      * @return {@link WS70SunDeploymentManager}
72      */

73     public DeploymentManager JavaDoc getDeploymentManager(String JavaDoc uri, String JavaDoc uname,
74                                                   String JavaDoc passwd)
75         throws DeploymentManagerCreationException JavaDoc {
76         
77         String JavaDoc location = WS70URIManager.getLocation(uri);
78         
79         // If we can't find the location of the WS70 libraries
80
// We can not really use the actual deployment manager
81
// provided by jsr-88 impl of the WS70
82
// This wont likely happene for the getDeploymentManager case
83
// it happens in getDisconnectedDeploymentManager case if
84
// Web project's target server was removed and the IDE restarts
85

86         if(location==null){
87             return new WS70SunDeploymentManager(null, null, uri, uname, passwd);
88         }
89         WS7LibsClassLoader ws7Libloader = (WS7LibsClassLoader)ws7ClassLoaders.get(location);
90         if(ws7Libloader == null){
91             ws7Libloader = (WS7LibsClassLoader)getWs7ClassLoader(location);
92             ws7ClassLoaders.put(location, ws7Libloader);
93         }
94         if(ws70DF==null){
95             try{
96                 this.createInnerFactory(ws7Libloader);
97             }catch(Exception JavaDoc ex){
98                 throw new DeploymentManagerCreationException JavaDoc(ex.getMessage());
99             }
100         }
101         
102         ClassLoader JavaDoc origClassLoader=Thread.currentThread().getContextClassLoader();
103         try{
104             String JavaDoc ws70url = WS70URIManager.getURIWithoutLocation(uri);
105             InstanceProperties ip = InstanceProperties.getInstanceProperties(uri);
106             String JavaDoc isSSL = ip.getProperty(WS70ServerUIWizardIterator.PROP_SSL_PORT);
107             if(Boolean.parseBoolean(isSSL)){
108                 ws70url=ws70url+HTTPS;
109             }
110             Thread.currentThread().setContextClassLoader(ws7Libloader);
111             DeploymentManager JavaDoc manager = new WS70SunDeploymentManager(ws70DF, ws70DF.getDeploymentManager(ws70url, uname, passwd),
112                                                                         uri, uname, passwd);
113             if(connectedDepManagers!=null){
114                 connectedDepManagers.put(uri, manager);
115             }
116             return manager;
117         }catch(Exception JavaDoc e){
118             e.printStackTrace();
119             throw new DeploymentManagerCreationException JavaDoc(e.getMessage());
120         }finally{
121             Thread.currentThread().setContextClassLoader(origClassLoader);
122         }
123     }
124     
125     /** This method returns a disconnected deployment manager.
126      *
127      * Should a disconnected deployment manager be able to become connected?
128      *
129      * @param uri
130      * @throws DeploymentManagerCreationException
131      * @return a deployment manager for doing configuration.
132      */

133     public DeploymentManager JavaDoc getDisconnectedDeploymentManager(String JavaDoc uri)
134         throws DeploymentManagerCreationException JavaDoc {
135         
136         String JavaDoc location = WS70URIManager.getLocation(uri);
137         // If we can't find the location of the WS70 libraries
138
// We can not really use the actual deployment manager
139
// provided by jsr-88 impl of the WS70 //
140
// it happens in getDisconnectedDeploymentManager case if
141
// Web project's target server was removed and the IDE restarts
142

143         if(location==null){
144             return new WS70SunDeploymentManager(null, null, uri, null, null);
145         }
146         WS7LibsClassLoader ws7Libloader = (WS7LibsClassLoader)ws7ClassLoaders.get(location);
147         if(ws7Libloader == null){
148             ws7Libloader = (WS7LibsClassLoader)getWs7ClassLoader(location);
149             ws7ClassLoaders.put(location, ws7Libloader);
150         }
151         if(ws70DF==null){
152             try{
153                 this.createInnerFactory(ws7Libloader);
154             }catch(Exception JavaDoc ex){
155                 throw new DeploymentManagerCreationException JavaDoc(ex.getMessage());
156             }
157         }
158         
159         ClassLoader JavaDoc origClassLoader=Thread.currentThread().getContextClassLoader();
160         try{
161             String JavaDoc ws70url = WS70URIManager.getURIWithoutLocation(uri);
162             InstanceProperties ip = InstanceProperties.getInstanceProperties(uri);
163             String JavaDoc isSSL = ip.getProperty(WS70ServerUIWizardIterator.PROP_SSL_PORT);
164             if(Boolean.parseBoolean(isSSL)){
165                 ws70url=ws70url+HTTPS;
166             }
167             Thread.currentThread().setContextClassLoader(ws7Libloader);
168             DeploymentManager JavaDoc manager = new WS70SunDeploymentManager(ws70DF, ws70DF.getDisconnectedDeploymentManager(ws70url),
169                                                                         uri, null, null);
170             return manager;
171         }catch(Exception JavaDoc e){
172             e.printStackTrace();
173             throw new DeploymentManagerCreationException JavaDoc(e.getMessage());
174         }finally{
175             Thread.currentThread().setContextClassLoader(origClassLoader);
176         }
177     }
178     
179     /** Determines whether this URI is handled by the Deployment factory
180      * Iniitally we need to test the prefix. If the factory will support
181      * multiple managers, we need to extend this test to catch those cases.
182      *
183      * The tests should also be extended to deteremine if the URI is
184      * "complete" for this factory. It has to have a machine name
185      * (that can be resolved to an IP address) and a port. Whether the
186      * server is "up" may be an open question.
187      *
188      * @param uri
189      * @return boolean value
190      */

191     public boolean handlesURI(String JavaDoc uri) {
192         if (uri == null) {
193             return false;
194         }
195         String JavaDoc location = WS70URIManager.getLocation(uri);
196         if(location==null){
197             return false;
198         }
199         WS7LibsClassLoader ws7Libloader = (WS7LibsClassLoader)ws7ClassLoaders.get(location);
200         if(ws7Libloader == null){
201             ws7Libloader = (WS7LibsClassLoader)getWs7ClassLoader(location);
202             ws7ClassLoaders.put(location, ws7Libloader);
203         }
204         if(ws70DF==null){
205             try{
206                 this.createInnerFactory(ws7Libloader);
207             }catch(Exception JavaDoc ex){
208                 return false;
209             }
210         }
211         ClassLoader JavaDoc origClassLoader=Thread.currentThread().getContextClassLoader();
212         Thread.currentThread().setContextClassLoader(ws7Libloader);
213         boolean ret = ws70DF.handlesURI(WS70URIManager.getURIWithoutLocation(uri));
214         Thread.currentThread().setContextClassLoader(origClassLoader);
215         return ret;
216     }
217     
218     public String JavaDoc getDisplayName() {
219         return NbBundle.getMessage(WS70SunDeploymentFactory.class, "LBL_WS70SunDeploymentFactory");
220     }
221     
222     public String JavaDoc getProductVersion() {
223         return NbBundle.getMessage(WS70SunDeploymentFactory.class, "LBL_WS70SunDeploymentFactoryVersion");
224     }
225     private static ClassLoader JavaDoc getWs7ClassLoader(String JavaDoc location){
226         WS7LibsClassLoader ws7Loader = null;
227         try{
228             String JavaDoc libsLocation = location+"/lib"; //NOI18N
229
//ws7Loader = new WS7LibsClassLoader(Thread.currentThread().getContextClassLoader());
230
ClassLoader JavaDoc moduleClassLoader = new Dummy().getClass().getClassLoader();
231             ErrorManager.getDefault().log(ErrorManager.USER, "WS70 moduleclassloader is "+moduleClassLoader.toString());
232             ws7Loader = new WS7LibsClassLoader(moduleClassLoader);
233             File JavaDoc f = null;
234             
235             // removing s1as-jsr160-server.jar from this classloader as it is not
236
// needed by plugin
237
/* f = new File(libsLocation+"/s1as-jsr160-server.jar");//NO I118N
238             ws7Loader.addURL(f);
239 */

240             f = new File JavaDoc(libsLocation+"/sun-ws-jsr88-dm.jar");//NO I118N
241
ws7Loader.addURL(f);
242             f = new File JavaDoc(libsLocation+"/s1as-jsr160-client.jar");//NO I118N
243
ws7Loader.addURL(f);
244
245             f = new File JavaDoc(libsLocation+"/jmxremote_optional.jar"); //NO I118N
246
ws7Loader.addURL(f);
247             
248             // removing webserv-admin.jar from this classloader as it is not
249
// needed by plugin anymore
250
/* f = new File(libsLocation+"/webserv-admin.jar"); //NO I118N
251             ws7Loader.addURL(f);
252 */

253             f = new File JavaDoc(libsLocation+"/webserv-admin-shared.jar"); //NO I118N
254
ws7Loader.addURL(f);
255             
256         }catch(Exception JavaDoc ex){
257             ex.printStackTrace();
258         }
259         return ws7Loader;
260     }
261     private void createInnerFactory(WS7LibsClassLoader loader) throws Exception JavaDoc{
262         try{
263             Object JavaDoc factory = loader.loadClass("com.sun.web.admin.deployapi.SunDeploymentFactory").newInstance();
264             ws70DF = (DeploymentFactory JavaDoc)factory;
265         }catch(Exception JavaDoc ex){
266             ex.printStackTrace();
267             throw ex;
268         }
269     }
270     public static WS70SunDeploymentManager getConnectedCachedDeploymentManager(String JavaDoc uri){
271         WS70SunDeploymentManager dm = (WS70SunDeploymentManager)connectedDepManagers.get(uri);
272         return dm;
273     }
274     public static ClassLoader JavaDoc getLibClassLoader(String JavaDoc location){
275         return (ClassLoader JavaDoc)ws7ClassLoaders.get(location);
276     }
277     // Dummy class for WS70Deployment Factory to get classloader of this class
278
public static class Dummy{
279         
280     }
281                 
282 }
283
Popular Tags