KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > WSDeploymentManager


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 package org.netbeans.modules.j2ee.websphere6;
20
21 import java.io.*;
22 import java.util.*;
23 import java.util.jar.JarFile JavaDoc;
24
25 import javax.enterprise.deploy.model.*;
26 import javax.enterprise.deploy.shared.*;
27 import javax.enterprise.deploy.spi.*;
28 import javax.enterprise.deploy.spi.exceptions.*;
29 import javax.enterprise.deploy.spi.factories.*;
30 import javax.enterprise.deploy.spi.status.*;
31 import javax.management.MalformedObjectNameException JavaDoc;
32 import javax.management.ObjectName JavaDoc;
33 import org.netbeans.modules.j2ee.websphere6.config.*;
34
35 import org.openide.*;
36 import org.openide.util.*;
37 import org.netbeans.modules.j2ee.deployment.plugins.api.*;
38
39 import org.netbeans.modules.j2ee.websphere6.util.WSDebug;
40 import java.lang.reflect.InvocationTargetException JavaDoc;
41 import java.lang.reflect.Method JavaDoc;
42 import java.util.zip.ZipEntry JavaDoc;
43
44 /**
45  * Main class of the deployment process. This serves a a wrapper for the
46  * server's DeploymentManager implementation, all calls are delegated to the
47  * server's implementation, with the thread's context classloader updated
48  * if necessary.
49  *
50  * @author Kirill Sorokin
51  */

52 public class WSDeploymentManager implements DeploymentManager {
53     
54     /**
55      * Current classloader used to work with WS classes
56      */

57     private WSClassLoader loader;
58     
59     /**
60      * Server's DeploymentFactory implementation
61      */

62     private DeploymentFactory factory;
63     
64     /**
65      * Server's DeploymentManager implementation
66      */

67     private DeploymentManager dm;
68     
69     /**
70      * Current server instance's properties
71      */

72     private InstanceProperties instanceProperties;
73     
74     /**
75      * Connection properties - URI
76      */

77     private String JavaDoc uri;
78     
79     /**
80      * Connection properties - user name
81      */

82     private String JavaDoc username;
83     
84     /**
85      * Connection properties - password
86      */

87     private String JavaDoc password;
88     
89     /**
90      * Marker that indicated whether the server is connected
91      */

92     private boolean isConnected;
93     
94     /**
95      * Temporary hack for storing webmodule`s context path in EntApplication
96      */

97     private static String JavaDoc webUrlInEntApp = "";
98     /**
99      * Creates a new instance of the deployment manager
100      *
101      * @param uri the server's URI
102      * @param username username for connecting to the server
103      * @param password password for connecting to the server
104      */

105     public WSDeploymentManager(String JavaDoc uri, String JavaDoc username, String JavaDoc password) {
106         if (WSDebug.isEnabled()) // debug output
107
WSDebug.notify("WSDeploymentManager(" + uri + ", " + // NOI18N
108
username + ", " + password + ")"); // NOI18N
109

110         // save the connection properties
111
this.uri = uri;
112         this.username = username;
113         this.password = password;
114     }
115     
116     /**
117      * Creates a new instance of the deployment manager
118      *
119      * @param uri the server's URI
120      */

121     public WSDeploymentManager(String JavaDoc uri) {
122         this(uri, null, null);
123     }
124     
125     /**
126      * Parses the URI and stores the parsed URI in the instance properties
127      * object
128      */

129     private void parseUri() {
130         // split the uri
131
String JavaDoc[] parts = uri.split(":"); // NOI18N
132

133         // set the host and port properties
134
getInstanceProperties().setProperty(
135                 WSDeploymentFactory.HOST_ATTR, parts[2]);
136         getInstanceProperties().setProperty(
137                 WSDeploymentFactory.PORT_ATTR, parts[3]);
138     }
139     
140     ////////////////////////////////////////////////////////////////////////////
141
// Connection data methods
142
////////////////////////////////////////////////////////////////////////////
143
/**
144      * Returns the stored server URI
145      */

146     public String JavaDoc getURI() {
147         return this.uri;
148     }
149     
150     /**
151      * Returns the server host stored in the instance properties
152      */

153     public String JavaDoc getHost() {
154         return getInstanceProperties().getProperty(
155                 WSDeploymentFactory.HOST_ATTR);
156     }
157     
158     /**
159      * Returns the server password stored in the instance properties
160      */

161     public String JavaDoc getPassword() {
162         return getInstanceProperties().getProperty(WSDeploymentFactory.PASSWORD_ATTR);
163         
164     }
165     
166     /**
167      * Returns the server username stored in the instance properties
168      */

169     public String JavaDoc getUsername() {
170         return getInstanceProperties().getProperty(WSDeploymentFactory.USERNAME_ATTR);
171         
172     }
173     
174     
175     /**
176      * Returns the server port stored in the instance properties
177      */

178     public String JavaDoc getPort() {
179         return getInstanceProperties().getProperty(
180                 WSDeploymentFactory.PORT_ATTR);
181     }
182     public String JavaDoc getAdminPort() {
183         return getInstanceProperties().getProperty(
184                 WSDeploymentFactory.ADMIN_PORT_ATTR);
185     }
186     public String JavaDoc getDefaultHostPort() {
187         return getInstanceProperties().getProperty(
188                 WSDeploymentFactory.DEFAULT_HOST_PORT_ATTR);
189     }
190     /**
191      * Returns the server installation directory
192      */

193     public String JavaDoc getServerRoot() {
194         return (getInstanceProperties()!=null)?getInstanceProperties().getProperty(
195                 WSDeploymentFactory.SERVER_ROOT_ATTR):"";
196     }
197     
198     /**
199      * Returns the profile root directory
200      */

201     public String JavaDoc getDomainRoot() {
202         return (getInstanceProperties()!=null)?getInstanceProperties().getProperty(
203                 WSDeploymentFactory.DOMAIN_ROOT_ATTR):"";
204     }
205     
206     public String JavaDoc getLogFilePath() {
207         return getDomainRoot() + File.separator + "logs" + // NOI18N
208
File.separator +
209                 getInstanceProperties().getProperty(
210                 WSDeploymentFactory.SERVER_NAME_ATTR) + File.separator +
211                 "trace.log"; // NOI18N
212
}
213     
214     /**
215      * Returns true if the type of server is local. Otherwise return false
216      */

217     public String JavaDoc getIsLocal() {
218         return (getInstanceProperties()!=null)?getInstanceProperties().getProperty(
219                 WSDeploymentFactory.IS_LOCAL_ATTR):"";
220     }
221     
222     /**
223      * Set server root property
224      */

225     public void setServerRoot(String JavaDoc serverRoot) {
226         if(getInstanceProperties()!=null)
227             getInstanceProperties().setProperty(WSDeploymentFactory.SERVER_ROOT_ATTR,serverRoot);
228     }
229     
230     /**
231      * Set domain root property
232      */

233     public void setDomainRoot(String JavaDoc domainRoot) {
234         if(getInstanceProperties()!=null)
235             getInstanceProperties().setProperty(WSDeploymentFactory.DOMAIN_ROOT_ATTR,domainRoot);
236     }
237     
238     /**
239      * Set host property
240      */

241     public void setHost(String JavaDoc host) {
242         if(getInstanceProperties()!=null) {
243             getInstanceProperties().setProperty(WSDeploymentFactory.HOST_ATTR,host);
244         }
245     }
246     
247     /**
248      * Set port property
249      */

250     public void setPort(String JavaDoc port) {
251         if(getInstanceProperties()!=null){
252             getInstanceProperties().setProperty(WSDeploymentFactory.PORT_ATTR,port);
253         }
254     }
255     
256     
257     /**
258      * Set admin port property
259      */

260     public void setAdminPort(String JavaDoc adminPort) {
261         if(getInstanceProperties()!=null){
262             getInstanceProperties().setProperty(WSDeploymentFactory.ADMIN_PORT_ATTR,adminPort);
263         }
264     }
265     
266     /**
267      * Set admin port property
268      */

269     public void setDefaultHostPort(String JavaDoc defaultHostPort) {
270         if(getInstanceProperties()!=null){
271             getInstanceProperties().setProperty(WSDeploymentFactory.DEFAULT_HOST_PORT_ATTR,defaultHostPort);
272         }
273     }
274     /**
275      * Set password property
276      */

277     public void setPassword(String JavaDoc password) {
278         if(getInstanceProperties()!=null)
279             getInstanceProperties().setProperty(WSDeploymentFactory.PASSWORD_ATTR,password);
280     }
281     
282     /**
283      * Set username property
284      */

285     public void setUsername(String JavaDoc username) {
286         if(getInstanceProperties()!=null)
287             getInstanceProperties().setProperty(WSDeploymentFactory.USERNAME_ATTR,username);
288     }
289     
290     /**
291      * Set Server Name
292      */

293     public void setServerName(String JavaDoc name) {
294         if(getInstanceProperties()!=null)
295             getInstanceProperties().setProperty(WSDeploymentFactory.SERVER_NAME_ATTR,name);
296     }
297     
298     /**
299      * Set .xml configuration file path
300      */

301     public void setConfigXmlPath(String JavaDoc path) {
302         if(getInstanceProperties()!=null)
303             getInstanceProperties().setProperty(WSDeploymentFactory.CONFIG_XML_PATH,path);
304     }
305     
306     /**
307      * Set local/remote type of server
308      */

309     public void setIsLocal(String JavaDoc isLocal) {
310         if(getInstanceProperties()!=null)
311             getInstanceProperties().setProperty(WSDeploymentFactory.IS_LOCAL_ATTR,isLocal);
312     }
313     
314     ////////////////////////////////////////////////////////////////////////////
315
// Class loading related things
316
////////////////////////////////////////////////////////////////////////////
317
/**
318      * Loads the server's deployment factory if it's not already loaded. During
319      * this process the classloader for WS classes is initialized.
320      */

321     private void loadDeploymentFactory() {
322         if (WSDebug.isEnabled()) // debug output
323
WSDebug.notify("loadDeploymentFactory()"); // NOI18N
324

325         // if the factory is not loaded - load it
326
if (factory == null) {
327             // init the classloader
328

329             String JavaDoc serverProp=getServerRoot();
330             
331             String JavaDoc domainProp=getDomainRoot();
332             
333             loader = WSClassLoader.getInstance(serverProp,domainProp);
334             
335             // update the context classloader
336
loader.updateLoader();
337             
338             // load the factory class and instantiate it
339
try {
340                 factory = (DeploymentFactory) loader.loadClass(
341                         "com.ibm.ws.management.application.j2ee." + // NOI18N
342
"deploy.spi.factories.DeploymentFactoryImpl"). // NOI18N
343
newInstance();
344             } catch (ClassNotFoundException JavaDoc e) {
345                 //ErrorManager.getDefault().notify(ErrorManager.ERROR, e);
346
e=null;
347                 // do nothing. Fix for issue with Exception on IDE restarting
348
// after removing server from Runtime with opened projects
349
} catch (InstantiationException JavaDoc e) {
350                 ErrorManager.getDefault().notify(ErrorManager.ERROR, e);
351             } catch (IllegalAccessException JavaDoc e) {
352                 ErrorManager.getDefault().notify(ErrorManager.ERROR, e);
353             } finally {
354                 // restore the loader
355
loader.restoreLoader();
356             }
357         }
358     }
359     
360     /**
361      * Updates the stored deployment manager. This is used when the current
362      * deployment manager cannot be used due to any reason, for example
363      * it is disconnected, its deployment application is already defined, etc
364      */

365     private void updateDeploymentManager() {
366         if (WSDebug.isEnabled()) // debug output
367
WSDebug.notify("updateDeploymentManager()"); // NOI18N
368

369         // load the deployment factory
370
loadDeploymentFactory();
371         
372         // update the context classloader
373
loader.updateLoader();
374         
375         try {
376             // if the current deployment manager is not null - flush the
377
// resources it has registered
378
if (dm != null) {
379                 dm.release();
380             }
381             
382             if(factory!=null) {
383                 // try to get a connected deployment manager
384
dm = factory.getDeploymentManager(uri, username, password);
385                 
386                 // set the connected marker
387
isConnected = true;
388             }
389         } catch (DeploymentManagerCreationException e) {
390             try {
391                 // if the connected deployment manager cannot be obtained - get
392
// a disconnected one and set the connected marker to false
393
isConnected = false;
394                 dm = factory.getDisconnectedDeploymentManager(uri);
395             } catch (DeploymentManagerCreationException ex) {
396                 ErrorManager.getDefault().notify(ErrorManager.ERROR, ex);
397             }
398         } finally {
399             // restore the context classloader
400
loader.restoreLoader();
401         }
402     }
403     
404     ////////////////////////////////////////////////////////////////////////////
405
// IDE data methods
406
////////////////////////////////////////////////////////////////////////////
407
/**
408      * Returns the InstanceProperties object for the current server instance
409      */

410     public InstanceProperties getInstanceProperties() {
411         if (WSDebug.isEnabled()) // debug output
412
WSDebug.notify("getInstanceProperties()"); // NOI18N
413

414         // if the stored instance properties are null - get them via the
415
// InstanceProperties' static method
416
if (instanceProperties == null) {
417             instanceProperties = InstanceProperties.getInstanceProperties(uri);
418             
419             // if the instance properties were obtained successfully - parse
420
// the URI and store the host and port in the instance properties
421
if (instanceProperties != null) {
422                 parseUri();
423             }
424         }
425         
426         // return either the stored or the newly obtained instance properties
427
return instanceProperties;
428     }
429     
430     public boolean getIsConnected() {
431         return isConnected;
432     }
433     public String JavaDoc getServerTitleMessage() {
434         String JavaDoc title = "[" + getInstanceProperties(). // NOI18N
435
getProperty(WSDeploymentFactory.SERVER_NAME_ATTR) + ", "+
436                 getInstanceProperties().
437                 getProperty(WSDeploymentFactory.HOST_ATTR) + ":"+
438                 getInstanceProperties().
439                 getProperty(WSDeploymentFactory.PORT_ATTR)+ "]";
440         return title;
441     }
442     
443     
444     ////////////////////////////////////////////////////////////////////////////
445
// DeploymentManager Implementation
446
////////////////////////////////////////////////////////////////////////////
447
/**
448      * Delegates the call to the server's deployment manager, checking whether
449      * the server is connected, updating the manager if neccessary and throwing
450      * the IllegalStateException is appropriate
451      */

452     public ProgressObject distribute(Target[] target, File JavaDoc file, File JavaDoc file2)
453     throws IllegalStateException JavaDoc {
454         if (WSDebug.isEnabled()) // debug output
455
WSDebug.notify("distribute(" + target + ", " + file + // NOI18N
456
", " + file2 + ")"); // NOI18N
457

458         // update the deployment manager
459
updateDeploymentManager();
460         
461         // if the manager is not connected - throw an IllegalStateException
462
if (!isConnected) {
463             throw new IllegalStateException JavaDoc(NbBundle.getMessage(
464                     WSDeploymentManager.class, "ERR_illegalState")); // NOI18N
465
}
466         
467         // update the context classloader
468
loader.updateLoader();
469         //try {
470
webUrlInEntApp = null;
471         
472         if(file.exists() && file.getPath().endsWith(".ear")) {
473             // try to get WebApplication context path from EAR archive
474
JarFile JavaDoc jarFile = null;
475             ZipEntry JavaDoc ze= null;
476             InputStream is = null;
477             ByteArrayOutputStream os = null;
478             try {
479                 jarFile = new JarFile JavaDoc(file);
480                 ze = jarFile.getEntry("META-INF/application.xml");
481                 is = jarFile.getInputStream(ze);
482                 os = new ByteArrayOutputStream();
483                 int n=0;
484                 byte[] buf = new byte[1024];
485                 while ((n = is.read(buf, 0, 1024)) > -1) {
486                     os.write(buf, 0, n);
487                 }
488                 String JavaDoc content = os.toString();
489                 String JavaDoc token = "<context-root>";
490                 int startIndex = content.indexOf(token);
491                 int endIndex = content.indexOf("</context-root>");
492                 if (startIndex != -1 && endIndex != -1) {
493                     webUrlInEntApp = content.substring(startIndex + token.length(),
494                             endIndex);
495                 }
496             } catch (IOException ex) {
497                 //do nothing.. strange case
498
} finally {
499                 try {
500                     if(jarFile!=null) jarFile.close();
501                 } catch(IOException ex) {
502                 } finally {
503                     try {
504                         if(is != null) is.close();
505                     } catch(IOException ex) {
506                     } finally {
507                         try {
508                             if(os != null) is.close();
509                         } catch(IOException ex) {
510                         }
511                     }
512                 }
513             }
514             
515         }
516         
517         //}
518

519         try {
520             // delegate the call and return the result
521
ProgressObject po = dm.distribute(target, file, file2);
522             
523             return po;
524             
525         } finally {
526             // restore the context classloader
527
loader.restoreLoader();
528         }
529     }
530     
531     /**
532      * Delegates the call to the server's deployment manager, checking whether
533      * the server is connected, updating the manager if neccessary and throwing
534      * the IllegalStateException is appropriate
535      *
536      * @return a wrapper for the server's DeploymentConfiguration implementation
537      */

538     public DeploymentConfiguration createConfiguration(
539             DeployableObject deployableObject) throws InvalidModuleException {
540         if (WSDebug.isEnabled()) // debug output
541
WSDebug.notify("createConfiguration(" + // NOI18N
542
deployableObject + ")"); // NOI18N
543

544         // update the deployment manager
545
updateDeploymentManager();
546         
547         
548         
549         // update the context classloader
550
loader.updateLoader();
551         ModuleType type = deployableObject.getType();
552         try {
553             if(dm!=null) {
554                 InstanceProperties ip=getInstanceProperties();
555                 if (type == ModuleType.WAR) {
556                     return new WarDeploymentConfiguration(dm, deployableObject,ip);
557                 } else if (type == ModuleType.EAR) {
558                     if(deployableObject instanceof J2eeApplicationObject) {
559                         return new EarDeploymentConfiguration(dm, (J2eeApplicationObject)deployableObject,ip);
560                     }
561                     return new EarDeploymentConfiguration(dm, deployableObject,ip);
562                 } else if (type == ModuleType.EJB) {
563                     return new EjbDeploymentConfiguration(dm, deployableObject,ip);
564                 } else {
565                     throw new InvalidModuleException("Unsupported module type: " + type.toString()); // NOI18N
566
}
567             }
568         } finally {
569             // restore the context classloader
570
loader.restoreLoader();
571         }
572         return null;
573     }
574     
575     /**
576      * Delegates the call to the server's deployment manager, checking whether
577      * the server is connected, updating the manager if neccessary and throwing
578      * the IllegalStateException is appropriate
579      */

580     public ProgressObject redeploy(TargetModuleID[] targetModuleID,
581             InputStream inputStream, InputStream inputStream2)
582             throws UnsupportedOperationException JavaDoc, IllegalStateException JavaDoc {
583         if (WSDebug.isEnabled()) // debug output
584
WSDebug.notify("redeploy(" + targetModuleID + ", " + // NOI18N
585
inputStream + ", " + inputStream2 + ")"); // NOI18N
586

587         // update the deployment manager
588
updateDeploymentManager();
589         
590         // if the manager is not connected - throw an IllegalStateException
591
if (!isConnected) {
592             throw new IllegalStateException JavaDoc(NbBundle.getMessage(
593                     WSDeploymentManager.class, "ERR_illegalState")); // NOI18N
594
}
595         
596         // update the context classloader
597
loader.updateLoader();
598         
599         try {
600             // delegate the call and return the result
601
return dm.redeploy(targetModuleID, inputStream, inputStream2);
602         } finally {
603             // restore the context classloader
604
loader.restoreLoader();
605         }
606     }
607     
608     /**
609      * Delegates the call to the server's deployment manager, checking whether
610      * the server is connected, updating the manager if neccessary and throwing
611      * the IllegalStateException is appropriate
612      */

613     public ProgressObject distribute(Target[] target, InputStream inputStream,
614             InputStream inputStream2) throws IllegalStateException JavaDoc {
615         if (WSDebug.isEnabled()) // debug output
616
WSDebug.notify("distribute(" + target + ", " + // NOI18N
617
inputStream + ", " + inputStream2 + ")"); // NOI18N
618

619         // update the deployment manager
620
updateDeploymentManager();
621         
622         // if the manager is not connected - throw an IllegalStateException
623
if (!isConnected) {
624             throw new IllegalStateException JavaDoc(NbBundle.getMessage(
625                     WSDeploymentManager.class, "ERR_illegalState")); // NOI18N
626
}
627         
628         // update the context classloader
629
loader.updateLoader();
630         
631         try {
632             // delegate the call and return the result
633
return dm.distribute(target, inputStream, inputStream2);
634         } finally {
635             // restore the context classloader
636
loader.restoreLoader();
637         }
638     }
639     
640     /**
641      * Delegates the call to the server's deployment manager, checking whether
642      * the server is connected, updating the manager if neccessary and throwing
643      * the IllegalStateException is appropriate
644      */

645     public ProgressObject undeploy(TargetModuleID[] targetModuleID)
646     throws IllegalStateException JavaDoc {
647         if (WSDebug.isEnabled()) // debug output
648
WSDebug.notify("undeploy(" + targetModuleID + ")"); // NOI18N
649

650         // update the deployment manager
651
updateDeploymentManager();
652         
653         // if the manager is not connected - throw an IllegalStateException
654
if (!isConnected) {
655             throw new IllegalStateException JavaDoc(NbBundle.getMessage(
656                     WSDeploymentManager.class, "ERR_illegalState")); // NOI18N
657
}
658         
659         // update the context classloader
660
loader.updateLoader();
661         
662         try {
663             // delegate the call and return the result
664
return dm.undeploy(targetModuleID);
665         } finally {
666             // restore the context classloader
667
loader.restoreLoader();
668         }
669     }
670     
671     /**
672      * Delegates the call to the server's deployment manager, checking whether
673      * the server is connected, updating the manager if neccessary and throwing
674      * the IllegalStateException is appropriate
675      */

676     public ProgressObject stop(TargetModuleID[] targetModuleID)
677     throws IllegalStateException JavaDoc {
678         if (WSDebug.isEnabled()) // debug output
679
WSDebug.notify("stop(" + targetModuleID + ")"); // NOI18N
680

681         // update the deployment manager
682
updateDeploymentManager();
683         
684         // if the manager is not connected - throw an IllegalStateException
685
if (!isConnected) {
686             throw new IllegalStateException JavaDoc(NbBundle.getMessage(
687                     WSDeploymentManager.class, "ERR_illegalState")); // NOI18N
688
}
689         
690         // update the context classloader
691
loader.updateLoader();
692         
693         try {
694             // delegate the call and return the result
695
return dm.stop(targetModuleID);
696         } finally {
697             // restore the context classloader
698
loader.restoreLoader();
699         }
700     }
701     
702     /**
703      * Delegates the call to the server's deployment manager, checking whether
704      * the server is connected, updating the manager if neccessary and throwing
705      * the IllegalStateException is appropriate
706      */

707     public ProgressObject start(TargetModuleID[] targetModuleID)
708     throws IllegalStateException JavaDoc {
709         if (WSDebug.isEnabled()) // debug output
710
WSDebug.notify("start(" + targetModuleID + ")"); // NOI18N
711

712         // update the deployment manager
713
updateDeploymentManager();
714         
715         // if the manager is not connected - throw an IllegalStateException
716
if (!isConnected) {
717             throw new IllegalStateException JavaDoc(NbBundle.getMessage(
718                     WSDeploymentManager.class, "ERR_illegalState")); // NOI18N
719
}
720         
721         // update the context classloader
722
loader.updateLoader();
723         
724         String JavaDoc webUrl=null;
725         try {
726             // if WebSphere return null for getWebURL, then set it to the right value
727
Method JavaDoc method = targetModuleID[0].getClass().
728                     getMethod("getWebURL", new Class JavaDoc[0]); // NOI18N
729
webUrl = (String JavaDoc) method.
730                     invoke(targetModuleID[0], new Object JavaDoc[0]);
731             
732             if (webUrlInEntApp!=null && targetModuleID[0].getModuleID().contains("type=Application")) {
733                 TargetModuleID [] tmids = targetModuleID;
734                 if (tmids.length==1 &&
735                         tmids[0].getModuleID().contains("type=Application") &&
736                         tmids[0].getChildTargetModuleID()==null) {
737                     try {
738                         TargetModuleID child = (TargetModuleID) loader.loadClass(
739                                 "com.ibm.ws.management.application.j2ee.deploy.spi.TargetModuleIDImpl").
740                                 newInstance();
741                         
742                         //set target server
743
method = child.getClass().
744                                 getMethod("setTarget", new Class JavaDoc[] {Target.class}); // NOI18N
745
method.invoke(child, new Object JavaDoc[] {tmids[0].getTarget()});
746                         
747                         
748                         // set parent
749
method = child.getClass().
750                                 getMethod("setParentTargetModuleID", new Class JavaDoc[] {TargetModuleID.class}); // NOI18N
751
method.invoke(child, new Object JavaDoc[] {tmids[0]});
752                         
753                         
754                         // set object name
755
String JavaDoc id = "WebSphere:name=" + webUrlInEntApp.substring(1) + ",type=WebModule";
756                         String JavaDoc oname = id + ",*";
757                         ObjectName JavaDoc on = new ObjectName JavaDoc(oname);
758                         method = child.getClass().
759                                 getMethod("setObjectName", new Class JavaDoc[] {ObjectName JavaDoc.class} ); // NOI18N
760
method.invoke(child, new Object JavaDoc [] {on});
761                         
762                         
763                         //set module id
764
method = child.getClass().
765                                 getMethod("setModuleID", new Class JavaDoc[] {String JavaDoc.class}); // NOI18N
766
method.invoke(child, new Object JavaDoc [] {id});
767                         
768                         //set type
769
method = child.getClass().
770                                 getMethod("setModuleType", new Class JavaDoc[] {String JavaDoc.class}); // NOI18N
771
String JavaDoc type = ModuleType.WAR.toString();
772                         method.invoke(child, new Object JavaDoc[] {type});
773                         
774                         //set startable
775

776                         method = child.getClass().
777                                 getMethod("setStartable", new Class JavaDoc[] {boolean.class}); // NOI18N
778
method.invoke(child, new Object JavaDoc[] {true});
779                         
780                         //set weburl
781
String JavaDoc port=getDefaultHostPort();
782                         String JavaDoc host=getHost();
783                         if(uri.indexOf(WSURIManager.WSURI)!=-1) {
784                             host=uri.split(":")[2];
785                         }
786                         webUrl="http://" + host + ":" + port; // NOI18N
787
if (webUrlInEntApp != null) {
788                             webUrl = webUrl + webUrlInEntApp;
789                             webUrlInEntApp = null;
790                         } else {
791                             System.out.println(
792                                     NbBundle.getMessage(WSDeploymentManager.class,
793                                     "ERR_wrongContextRoot"));
794                         }
795                         method = child.getClass().
796                                 getMethod("setWebURL", new Class JavaDoc[] {String JavaDoc.class}); // NOI18N
797
method.invoke(child, new Object JavaDoc[] {webUrl});
798                         
799                         method = tmids[0].getClass().
800                                 getMethod("setChildTargetModuleID", new Class JavaDoc[] {TargetModuleID[].class}); // NOI18N
801
method.invoke(tmids[0], new Object JavaDoc[] {new TargetModuleID[] {child}});
802                         
803                     } catch (ClassNotFoundException JavaDoc ex) {
804                         ex=null;//do nothing
805
} catch (InstantiationException JavaDoc ex) {
806                         ex=null;//do nothing
807
} catch (IllegalAccessException JavaDoc ex) {
808                         ex=null;//do nothing
809
} catch (NoSuchMethodException JavaDoc ex) {
810                         ex=null;//do nothing
811
} catch (InvocationTargetException JavaDoc ex) {
812                         ex=null;//do nothing
813
} catch (NullPointerException JavaDoc ex) {
814                         ex=null;//do nothing
815
} catch (MalformedObjectNameException JavaDoc ex) {
816                         ex=null;//do nothing
817
}
818                 }
819             }
820             
821             
822             if(targetModuleID[0].getModuleID().contains("type=WebModule") /*||
823                     targetModuleID[0].getModuleID().contains("type=Application")*/
) {
824                 if(webUrl==null) {
825                     String JavaDoc port=getDefaultHostPort();
826                     String JavaDoc host=getHost();
827                     if(uri.indexOf(WSURIManager.WSURI)!=-1) {
828                         host=uri.split(":")[2];
829                     }
830                     webUrl="http://" + host + ":" + port; // NOI18N
831
if (webUrlInEntApp != null) {
832                         webUrl = webUrl + webUrlInEntApp;
833                         webUrlInEntApp = null;
834                     } else {
835                         System.out.println(
836                                 NbBundle.getMessage(WSDeploymentManager.class,
837                                 "ERR_wrongContextRoot"));
838                     }
839                     method = targetModuleID[0].getClass().
840                             getMethod("setWebURL", new Class JavaDoc[] {String JavaDoc.class}); // NOI18N
841
method.invoke(targetModuleID[0], new Object JavaDoc[] {webUrl});
842                     
843                     method = targetModuleID[0].getClass().
844                             getMethod("getWebURL", new Class JavaDoc[0] ); // NOI18N
845
String JavaDoc webUrlAfter = (String JavaDoc) method.
846                             invoke(targetModuleID[0], new Object JavaDoc[0]);
847                     webUrlAfter = webUrlAfter + "";
848                 }
849                 
850                 /* Commented as it doesn`t work properly
851                 try { // stop running web modules
852                  
853                     TargetModuleID [] modules = getRunningModules(
854                             ModuleType.WAR,
855                             new Target[] {targetModuleID[0].getTarget()});
856                     TargetModuleID [] amodules = getAvailableModules(
857                             ModuleType.WAR,
858                             new Target[] {targetModuleID[0].getTarget()});
859                  
860                  
861                     for(int i=0;i<modules.length;i++) {
862                         if(modules[i].getWebURL()==null || webUrl.equals(modules[i].getWebURL())) {
863                             //stop(new TargetModuleID[] {modules[i]} );
864                         }
865                     }
866                 } catch(TargetException ex) {
867                     ;//do nothing..
868                 } */

869             }
870             
871         } catch (IllegalAccessException JavaDoc e) {
872             ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
873         } catch (NoSuchMethodException JavaDoc e) {
874             ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
875         } catch (InvocationTargetException JavaDoc e) {
876             ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
877         } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
878             ErrorManager.getDefault().notify(ErrorManager.EXCEPTION, e);
879         }
880         
881         try {
882             // delegate the call and return the result
883
return dm.start(targetModuleID);
884         } finally {
885             // restore the context classloader
886
loader.restoreLoader();
887         }
888     }
889     
890     /**
891      * Delegates the call to the server's deployment manager, checking whether
892      * the server is connected, updating the manager if neccessary and throwing
893      * the IllegalStateException is appropriate
894      */

895     public TargetModuleID[] getAvailableModules(ModuleType moduleType,
896             Target[] target) throws TargetException JavaDoc, IllegalStateException JavaDoc {
897         if (WSDebug.isEnabled()) // debug output
898
WSDebug.notify("getAvailableModules(" + moduleType + // NOI18N
899
", " + target + ")"); // NOI18N
900

901         // update the deployment manager
902
updateDeploymentManager();
903         
904         // if the manager is not connected - throw an IllegalStateException
905
if (!isConnected) {
906             throw new IllegalStateException JavaDoc(NbBundle.getMessage(
907                     WSDeploymentManager.class, "ERR_illegalState")); // NOI18N
908
}
909         
910         // update the context classloader
911
loader.updateLoader();
912         
913         try {
914             // delegate the call and return the result
915
TargetModuleID[] am = dm.getAvailableModules(moduleType, target);
916             return am;
917         } finally {
918             // restore the context classloader
919
loader.restoreLoader();
920         }
921     }
922     
923     /**
924      * Delegates the call to the server's deployment manager, checking whether
925      * the server is connected, updating the manager if neccessary and throwing
926      * the IllegalStateException is appropriate
927      */

928     public TargetModuleID[] getNonRunningModules(ModuleType moduleType,
929             Target[] target) throws TargetException JavaDoc, IllegalStateException JavaDoc {
930         if (WSDebug.isEnabled()) // debug output
931
WSDebug.notify("getNonRunningModules(" + moduleType + // NOI18N
932
", " + target + ")"); // NOI18N
933

934         // update the deployment manager
935
updateDeploymentManager();
936         
937         // if the manager is not connected - throw an IllegalStateException
938
if (!isConnected) {
939             throw new IllegalStateException JavaDoc(NbBundle.getMessage(
940                     WSDeploymentManager.class, "ERR_illegalState")); // NOI18N
941
}
942         
943         // update the context classloader
944
loader.updateLoader();
945         
946         try {
947             // delegate the call and return the result
948
TargetModuleID [] nrm = dm.getNonRunningModules(moduleType, target);
949             return nrm;
950         } finally {
951             // restore the context classloader
952
loader.restoreLoader();
953         }
954     }
955     
956     /**
957      * Delegates the call to the server's deployment manager, checking whether
958      * the server is connected, updating the manager if neccessary and throwing
959      * the IllegalStateException is appropriate
960      */

961     public TargetModuleID[] getRunningModules(ModuleType moduleType,
962             Target[] target) throws TargetException JavaDoc, IllegalStateException JavaDoc {
963         if (WSDebug.isEnabled()) // debug output
964
WSDebug.notify("getRunningModules(" + moduleType + // NOI18N
965
", " + target + ")"); // NOI18N
966

967         // update the deployment manager
968
updateDeploymentManager();
969         
970         // if the manager is not connected - throw an IllegalStateException
971
if (!isConnected) {
972             throw new IllegalStateException JavaDoc(NbBundle.getMessage(
973                     WSDeploymentManager.class, "ERR_illegalState")); // NOI18N
974
}
975         
976         // update the context classloader
977
loader.updateLoader();
978         
979         try {
980             // delegate the call and return the result
981
TargetModuleID [] rm = dm.getRunningModules(moduleType, target);
982             return rm;
983         } finally {
984             // restore the context classloader
985
loader.restoreLoader();
986         }
987     }
988     
989     /**
990      * Delegates the call to the server's deployment manager, checking whether
991      * the server is connected, updating the manager if neccessary and throwing
992      * the IllegalStateException is appropriate
993      */

994     public ProgressObject redeploy(TargetModuleID[] targetModuleID, File JavaDoc file,
995             File JavaDoc file2) throws UnsupportedOperationException JavaDoc,
996             IllegalStateException JavaDoc {
997         if (WSDebug.isEnabled()) // debug output
998
WSDebug.notify("redeploy(" + targetModuleID + ", " + // NOI18N
999
file + ", " + file2 + ")"); // NOI18N
1000

1001        // update the deployment manager
1002
updateDeploymentManager();
1003        
1004        // if the manager is not connected - throw an IllegalStateException
1005
if (!isConnected) {
1006            throw new IllegalStateException JavaDoc(NbBundle.getMessage(
1007                    WSDeploymentManager.class, "ERR_illegalState")); // NOI18N
1008
}
1009        
1010        // update the context classloader
1011
loader.updateLoader();
1012        
1013        try {
1014            // delegate the call and return the result
1015
return dm.redeploy(targetModuleID, file, file2);
1016        } finally {
1017            // restore the context classloader
1018
loader.restoreLoader();
1019        }
1020    }
1021    
1022    /**
1023     * Delegates the call to the server's deployment manager, checking whether
1024     * the server is connected, updating the manager if neccessary and throwing
1025     * the IllegalStateException is appropriate
1026     */

1027    public void setLocale(Locale locale) throws UnsupportedOperationException JavaDoc {
1028        if (WSDebug.isEnabled()) // debug output
1029
WSDebug.notify("setLocale(" + locale + ")"); // NOI18N
1030

1031        // update the deployment manager
1032
updateDeploymentManager();
1033        
1034        // delegate the call
1035
dm.setLocale(locale);
1036    }
1037    
1038    /**
1039     * Delegates the call to the server's deployment manager, checking whether
1040     * the server is connected, updating the manager if neccessary and throwing
1041     * the IllegalStateException is appropriate
1042     */

1043    public boolean isLocaleSupported(Locale locale) {
1044        if (WSDebug.isEnabled()) // debug output
1045
WSDebug.notify("isLocaleSupported(" + locale + ")"); // NOI18N
1046

1047        // update the deployment manager
1048
updateDeploymentManager();
1049        
1050        // delegate the call
1051
return dm.isLocaleSupported(locale);
1052    }
1053    
1054    /**
1055     * Delegates the call to the server's deployment manager, checking whether
1056     * the server is connected, updating the manager if neccessary and throwing
1057     * the IllegalStateException is appropriate
1058     */

1059    public void setDConfigBeanVersion(
1060            DConfigBeanVersionType dConfigBeanVersionType)
1061            throws DConfigBeanVersionUnsupportedException {
1062        if (WSDebug.isEnabled()) // debug output
1063
WSDebug.notify("setDConfigBeanVersion(" + // NOI18N
1064
dConfigBeanVersionType + ")"); // NOI18N
1065

1066        // update the deployment manager
1067
updateDeploymentManager();
1068        
1069        // delegate the call
1070
dm.setDConfigBeanVersion(dConfigBeanVersionType);
1071    }
1072    
1073    /**
1074     * Delegates the call to the server's deployment manager, checking whether
1075     * the server is connected, updating the manager if neccessary and throwing
1076     * the IllegalStateException is appropriate
1077     */

1078    public boolean isDConfigBeanVersionSupported(
1079            DConfigBeanVersionType dConfigBeanVersionType) {
1080        if (WSDebug.isEnabled()) // debug output
1081
WSDebug.notify("isDConfigBeanVersionSupported(" + // NOI18N
1082
dConfigBeanVersionType + ")"); // NOI18N
1083

1084        // update the deployment manager
1085
updateDeploymentManager();
1086        
1087        // delegate the call and return the result
1088
return dm.isDConfigBeanVersionSupported(dConfigBeanVersionType);
1089    }
1090    
1091    /**
1092     * Delegates the call to the server's deployment manager, checking whether
1093     * the server is connected, updating the manager if neccessary and throwing
1094     * the IllegalStateException is appropriate
1095     */

1096    public void release() {
1097        if (WSDebug.isEnabled()) // debug output
1098
WSDebug.notify("release()"); // NOI18N
1099

1100        if (dm != null) {
1101            // delegate the call and clear the stored deployment manager
1102
dm.release();
1103            dm = null;
1104        }
1105    }
1106    
1107    /**
1108     * Delegates the call to the server's deployment manager, checking whether
1109     * the server is connected, updating the manager if neccessary and throwing
1110     * the IllegalStateException is appropriate
1111     */

1112    public boolean isRedeploySupported() {
1113        if (WSDebug.isEnabled()) // debug output
1114
WSDebug.notify("isRedeploySupported()"); // NOI18N
1115

1116        // update the deployment manager
1117
updateDeploymentManager();
1118        
1119        // delegate the call and return the result
1120
return dm.isRedeploySupported();
1121    }
1122    
1123    /**
1124     * Delegates the call to the server's deployment manager, checking whether
1125     * the server is connected, updating the manager if neccessary and throwing
1126     * the IllegalStateException is appropriate
1127     */

1128    public Locale getCurrentLocale() {
1129        if (WSDebug.isEnabled()) // debug output
1130
WSDebug.notify("getCurrentLocale()"); // NOI18N
1131

1132        // update the deployment manager
1133
updateDeploymentManager();
1134        
1135        // delegate the call and return the result
1136
return dm.getCurrentLocale();
1137    }
1138    
1139    /**
1140     * Delegates the call to the server's deployment manager, checking whether
1141     * the server is connected, updating the manager if neccessary and throwing
1142     * the IllegalStateException is appropriate
1143     */

1144    public DConfigBeanVersionType getDConfigBeanVersion() {
1145        if (WSDebug.isEnabled()) // debug output
1146
WSDebug.notify("getDConfigBeanVersion()"); // NOI18N
1147

1148        // update the deployment manager
1149
updateDeploymentManager();
1150        
1151        // delegate the call and return the result
1152
return dm.getDConfigBeanVersion();
1153    }
1154    
1155    /**
1156     * Delegates the call to the server's deployment manager, checking whether
1157     * the server is connected, updating the manager if neccessary and throwing
1158     * the IllegalStateException is appropriate
1159     */

1160    public Locale getDefaultLocale() {
1161        if (WSDebug.isEnabled()) // debug output
1162
WSDebug.notify("getDefaultLocale()"); // NOI18N
1163

1164        // update the deployment manager
1165
updateDeploymentManager();
1166        
1167        // delegate the call and return the result
1168
return dm.getDefaultLocale();
1169    }
1170    
1171    /**
1172     * Delegates the call to the server's deployment manager, checking whether
1173     * the server is connected, updating the manager if neccessary and throwing
1174     * the IllegalStateException is appropriate
1175     */

1176    public Locale[] getSupportedLocales() {
1177        if (WSDebug.isEnabled()) // debug output
1178
WSDebug.notify("getSupportedLocales()"); // NOI18N
1179

1180        // update the deployment manager
1181
updateDeploymentManager();
1182        
1183        // delegate the call and return the result
1184
return dm.getSupportedLocales();
1185    }
1186    
1187    /**
1188     * Delegates the call to the server's deployment manager, checking whether
1189     * the server is connected, updating the manager if neccessary and throwing
1190     * the IllegalStateException is appropriate
1191     */

1192    public Target[] getTargets() throws IllegalStateException JavaDoc {
1193        if (WSDebug.isEnabled()) // debug output
1194
WSDebug.notify("getTargets()"); // NOI18N
1195

1196        // update the deployment manager
1197
updateDeploymentManager();
1198        
1199        // update the context classloader
1200
loader.updateLoader();
1201        
1202        // if the manager is not connected - throw an IllegalStateException
1203
if (!isConnected) {
1204            throw new IllegalStateException JavaDoc(NbBundle.getMessage(
1205                    WSDeploymentManager.class, "ERR_illegalState")); // NOI18N
1206
}
1207        
1208        try {
1209            // delegate the call and return the result
1210
return dm.getTargets();
1211        } finally {
1212            // restore the context classloader
1213
loader.restoreLoader();
1214        }
1215    }
1216    
1217}
Popular Tags