KickJava   Java API By Example, From Geeks To Geeks.

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


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  * WS70SunDeploymentManager.java
22  */

23
24 package org.netbeans.modules.j2ee.sun.ws7.dm;
25
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.io.InputStream JavaDoc;
29 import java.io.File JavaDoc;
30 import java.util.Locale JavaDoc;
31 import java.lang.reflect.Method JavaDoc;
32 import java.lang.reflect.InvocationTargetException JavaDoc;
33
34 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
35 import javax.enterprise.deploy.spi.Target JavaDoc;
36 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
37 import javax.enterprise.deploy.spi.status.ProgressObject JavaDoc;
38 import javax.enterprise.deploy.spi.status.ProgressListener JavaDoc;
39 import javax.enterprise.deploy.spi.status.ProgressEvent JavaDoc;
40 import javax.enterprise.deploy.spi.status.DeploymentStatus JavaDoc;
41 import javax.enterprise.deploy.shared.DConfigBeanVersionType JavaDoc;
42 import javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException JavaDoc;
43 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
44 import javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc;
45 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
46 import javax.enterprise.deploy.spi.exceptions.InvalidModuleException JavaDoc;
47 import javax.enterprise.deploy.spi.exceptions.TargetException JavaDoc;
48 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException JavaDoc;
49 import javax.enterprise.deploy.spi.factories.DeploymentFactory JavaDoc;
50 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
51
52
53 import java.io.*;
54 import org.netbeans.modules.j2ee.sun.share.configbean.SunONEDeploymentConfiguration;
55 import org.netbeans.modules.j2ee.sun.dd.api.DDProvider;
56 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp;
57 import org.netbeans.modules.j2ee.sun.ws7.j2ee.ResourceType;
58 import org.netbeans.modules.j2ee.sun.ws7.ui.WS70URIManager;
59 import org.netbeans.modules.j2ee.sun.ws7.ui.WS70ConfigSelectDialog;
60 import org.netbeans.modules.j2ee.sun.ws7.ui.WS70ServerUIWizardIterator;
61
62 import org.openide.DialogDisplayer;
63 import org.openide.NotifyDescriptor;
64 import org.openide.ErrorManager;
65 import org.openide.util.NbBundle;
66
67 /**
68  *
69  * @author Administrator
70  */

71 public class WS70SunDeploymentManager implements DeploymentManager JavaDoc{
72     private DeploymentManager JavaDoc ws70DM;
73     private DeploymentFactory JavaDoc ws70DF;
74     private String JavaDoc uri;
75     private String JavaDoc userName;
76     private String JavaDoc password;
77     private Class JavaDoc dmClass;
78     private String JavaDoc serverLocation;
79     private String JavaDoc host;
80     private int port;
81     // Target config selected by the user for deployment
82
private Target JavaDoc defaultTarget;
83     
84     // debug-jvm-option value in the server.xml of the default config.
85
private String JavaDoc debugOptions;
86     private boolean isDebugModeEnabled;
87
88     
89     /** Creates a new instance of WS70SunDeploymentManager */
90     public WS70SunDeploymentManager(DeploymentFactory JavaDoc df, DeploymentManager JavaDoc dm, String JavaDoc uri, String JavaDoc username, String JavaDoc password) {
91         this.ws70DF = df;
92         this.ws70DM = dm;
93         this.uri = uri;
94         this.userName = username;
95         this.password = password;
96         // ws70DM can be null in getDisconnectedDeploymentManager case if
97
// Web project's target server was removed and the IDE restarts
98
if(ws70DM!=null){
99             dmClass = ws70DM.getClass();
100             serverLocation = WS70URIManager.getLocation(uri);
101             host = WS70URIManager.getHostFromURI(uri);
102             String JavaDoc p = WS70URIManager.getPortFromURI(uri);
103             try{
104                 port = Integer.parseInt(p);
105             }catch(java.lang.NumberFormatException JavaDoc n){
106                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, n);
107             }
108         }
109     }
110     
111     public String JavaDoc getUserName() {
112         return userName;
113     }
114     
115     public String JavaDoc getPassword() {
116         return password;
117     }
118     public String JavaDoc getServerLocation(){
119         return serverLocation;
120     }
121     public String JavaDoc getUri(){
122         return uri;
123     }
124     public String JavaDoc getHost(){
125         return host;
126     }
127     public int getPort(){
128         return port;
129     }
130     
131     // Called from Manager Node Customizer only
132
public void refreshInnerDM(String JavaDoc uname, String JavaDoc pword) {
133         if(uname.equals(userName) && pword.equals(password)){
134             // Nothing is changed, take no action
135
return;
136         }
137         ClassLoader JavaDoc origClassLoader=Thread.currentThread().getContextClassLoader();
138         try{
139             String JavaDoc ws70url = WS70URIManager.getURIWithoutLocation(uri);
140             if(this.isAdminOnSSL()){
141                 ws70url=ws70url+":https";
142             }
143             ClassLoader JavaDoc loader = WS70SunDeploymentFactory.getLibClassLoader(serverLocation);
144             if(loader!=null){
145                 Thread.currentThread().setContextClassLoader(loader);
146             }
147             ws70DM = ws70DF.getDeploymentManager(ws70url, uname, pword);
148             userName = uname;
149             password = pword;
150             InstanceProperties ip = InstanceProperties.getInstanceProperties(this.getUri());
151             ip.setProperty(InstanceProperties.USERNAME_ATTR, uname);
152             ip.setProperty(InstanceProperties.PASSWORD_ATTR, pword);
153         }catch(DeploymentManagerCreationException JavaDoc ex){
154             ErrorManager.getDefault().log(ErrorManager.EXCEPTION, ex.getMessage());
155         }finally{
156             Thread.currentThread().setContextClassLoader(origClassLoader);
157         }
158     }
159     public boolean isLocalServer(){
160         InstanceProperties ip = InstanceProperties.getInstanceProperties(uri);
161         String JavaDoc isLocal = ip.getProperty(WS70ServerUIWizardIterator.PROP_LOCAL_SERVER);
162         return Boolean.parseBoolean(isLocal);
163     }
164     public boolean isAdminOnSSL(){
165         InstanceProperties ip = InstanceProperties.getInstanceProperties(uri);
166         String JavaDoc isSSL = ip.getProperty(WS70ServerUIWizardIterator.PROP_SSL_PORT);
167         return Boolean.parseBoolean(isSSL);
168     }
169     // returns the default config Target selected by the user.
170
// used by JSPServletFinder
171
public Target JavaDoc getDefaultTarget(){
172         return defaultTarget;
173     }
174     public DeploymentConfiguration JavaDoc createConfiguration(DeployableObject JavaDoc deplObj)
175         throws InvalidModuleException JavaDoc {
176         if (!ModuleType.WAR.equals(deplObj.getType())) {
177             throw new InvalidModuleException JavaDoc(
178                       NbBundle.getMessage(WS70SunDeploymentManager.class, "Invalid_MODULE"));
179         }
180
181         return new SunONEDeploymentConfiguration(deplObj);
182     }
183
184
185     /**
186      * Deploys web module using deploy command
187      * @param targets Array containg one web module
188      * @param is Web application stream
189      * @param deplPlan Server specific data
190      * @throws IllegalStateException when TomcatManager is disconnected
191      * @return Object that reports about deployment progress
192      */

193     public ProgressObject JavaDoc distribute(Target JavaDoc[] targets, InputStream JavaDoc is, InputStream JavaDoc deplPlan)
194                                         throws IllegalStateException JavaDoc {
195
196         return ws70DM.distribute(targets, is, deplPlan);
197     }
198
199
200     /**
201      * Deploys web module using install command
202      * @param targets Array containg one web module
203      * @param moduleArchive directory with web module or WAR file
204      * @param deplPlan Server specific data
205      * @throws IllegalStateException when TomcatManager is disconnected
206      * @return Object that reports about deployment progress
207      */

208     public ProgressObject JavaDoc distribute(Target JavaDoc[] targets, File JavaDoc moduleArchive,File JavaDoc deplPlan)
209                                         throws IllegalStateException JavaDoc {
210         SunWebApp swa = null;
211         try {
212             
213             InputStream JavaDoc inputStream = new BufferedInputStream(new FileInputStream(deplPlan),
214                                                            4096);
215             DDProvider provider = DDProvider.getDefault();
216             swa = provider.getWebDDRoot(inputStream);
217         } catch (Exception JavaDoc e) {
218             e.printStackTrace();
219         } // end of try-catch
220

221         String JavaDoc ctxRoot = null;
222         if (swa == null) {
223             ErrorManager.getDefault().log(
224                     ErrorManager.ERROR, NbBundle.getMessage(WS70SunDeploymentManager.class, "ERR_NULL_SWA"));
225         }else{
226             ctxRoot = swa.getContextRoot();
227             ErrorManager.getDefault().log(
228                     ErrorManager.USER, NbBundle.getMessage(WS70SunDeploymentManager.class, "MSG_CONTEXTROOT", ctxRoot));
229         }
230         
231         try{
232             Method JavaDoc distribute = dmClass.getDeclaredMethod("distribute", new Class JavaDoc[]{Target JavaDoc[].class, File JavaDoc.class, String JavaDoc.class});
233             ProgressObject JavaDoc po = (ProgressObject JavaDoc)distribute.invoke(this.ws70DM, new Object JavaDoc[]{targets, moduleArchive, ctxRoot});
234             return po;
235             
236         }catch(Exception JavaDoc ex){
237             ex.printStackTrace();
238         }
239         return null;
240     }
241     
242     public ProgressObject JavaDoc distribute(Target JavaDoc[] target, ModuleType JavaDoc moduleType, InputStream JavaDoc inputStream, InputStream JavaDoc inputStream0) throws IllegalStateException JavaDoc {
243         return distribute(target, inputStream, inputStream0);
244     }
245
246     public Locale JavaDoc getCurrentLocale() {
247         return Locale.getDefault();
248     }
249
250     public Locale JavaDoc getDefaultLocale() {
251         return Locale.getDefault();
252     }
253     
254     public Locale JavaDoc[] getSupportedLocales() {
255         return Locale.getAvailableLocales();
256     }
257
258     public boolean isLocaleSupported(Locale JavaDoc locale) {
259         if (locale == null) {
260             return false;
261         }
262         Locale JavaDoc [] supLocales = getSupportedLocales();
263         for (int i =0; i<supLocales.length; i++) {
264             if (locale.equals (supLocales[i])) {
265                 return true;
266             }
267         }
268         return false;
269     }
270
271     public void setLocale(Locale JavaDoc locale)
272         throws UnsupportedOperationException JavaDoc {
273          
274     }
275     
276     public DConfigBeanVersionType JavaDoc getDConfigBeanVersion() {
277         return DConfigBeanVersionType.V1_4;
278     }
279
280     public boolean isDConfigBeanVersionSupported(DConfigBeanVersionType JavaDoc v) {
281         return DConfigBeanVersionType.V1_4.equals(v);
282     }
283
284     public void setDConfigBeanVersion(DConfigBeanVersionType JavaDoc version)
285         throws DConfigBeanVersionUnsupportedException JavaDoc {
286         if (!DConfigBeanVersionType.V1_4.equals(version)) {
287             throw new DConfigBeanVersionUnsupportedException JavaDoc(
288                     NbBundle.getMessage(WS70SunDeploymentManager.class, "Invalid_CONFIG_VERSION"));
289         }
290     }
291
292     public TargetModuleID JavaDoc[] getAvailableModules(ModuleType JavaDoc moduleType,
293                                                 Target JavaDoc[] targetList)
294                 throws IllegalStateException JavaDoc, TargetException JavaDoc {
295         return ws70DM.getAvailableModules(moduleType, targetList);
296         
297     }
298
299
300     public TargetModuleID JavaDoc[] getNonRunningModules(ModuleType JavaDoc moduleType,
301                                                  Target JavaDoc[] targetList)
302         throws IllegalStateException JavaDoc, TargetException JavaDoc {
303         return ws70DM.getNonRunningModules(moduleType, targetList);
304     }
305
306     public TargetModuleID JavaDoc[] getRunningModules(ModuleType JavaDoc moduleType,
307                                               Target JavaDoc[] targetList)
308         throws IllegalStateException JavaDoc, TargetException JavaDoc {
309         return ws70DM.getRunningModules(moduleType, targetList);
310     }
311
312     public Target JavaDoc[] getTargets() throws IllegalStateException JavaDoc {
313         Target JavaDoc[] targets = ws70DM.getTargets();
314         InstanceProperties ip = InstanceProperties.getInstanceProperties(this.getUri());
315         String JavaDoc config = ip.getProperty("configName");// NO I18N
316
if(targets.length==1){
317             if(config==null){
318                 try{
319                     String JavaDoc cname = this.getConfigNameFromTarget(targets[0]);
320                     ip.setProperty("configName", cname);// NO I18N
321
}catch(Exception JavaDoc ex){
322                     ex.printStackTrace();
323                 }
324             }
325             defaultTarget = targets[0];
326             return targets;
327         }
328         
329         // If there are more than one configurations, ask user to select one
330
// and set it in the Instance properties.
331
String JavaDoc[] configs = new String JavaDoc[targets.length];
332         for(int i=0;i<targets.length;i++){
333             try{
334                 configs[i] = this.getConfigNameFromTarget(targets[i]);
335             }catch(Exception JavaDoc ex){
336                 configs[i]="";
337                 ex.printStackTrace();
338             }
339         }
340         
341
342         if(config==null){
343             //perheps this is the first time
344
WS70ConfigSelectDialog d = new WS70ConfigSelectDialog(configs);
345             if (DialogDisplayer.getDefault().notify(d) ==NotifyDescriptor.OK_OPTION){
346                 config = d.getSelectedConfig();
347             }
348             if(config==null){
349                 //if some error set the first target as default
350
try{
351                     ip.setProperty("configName", this.getConfigNameFromTarget(targets[0]));// NO I18N
352
}catch(Exception JavaDoc ex){
353                     ex.printStackTrace();
354                 }
355             }else{
356                 ip.setProperty("configName", config);// NO I18N
357
}
358             for(int i=0;i<targets.length;i++){
359                 String JavaDoc cname = null;
360                 try{
361                     cname = this.getConfigNameFromTarget(targets[i]);
362                 }catch(Exception JavaDoc ex){
363                     cname = "";
364                     ex.printStackTrace();
365                 }
366                 if(config.equals(cname)){
367                     defaultTarget = targets[i];
368                     return new Target JavaDoc[]{targets[i]};
369                 }
370             }
371         }else{
372             // It was already selected by the user previously
373
for(int j=0;j<targets.length;j++){
374                 String JavaDoc cname = null;
375                 try{
376                     cname = this.getConfigNameFromTarget(targets[j]);
377                 }catch(Exception JavaDoc ex){
378                     cname = "";
379                     ex.printStackTrace();
380                 }
381                 if(config.equals(cname)){
382                     defaultTarget = targets[j];
383                     return new Target JavaDoc[]{targets[j]};
384                 }
385             }
386         }
387
388         ErrorManager.getDefault().log(ErrorManager.WARNING,
389                 NbBundle.getMessage(WS70SunDeploymentManager.class,
390                 "ERR_GETTARGETS", targets[0].getName()));
391         defaultTarget = targets[0];
392         return new Target JavaDoc[]{targets[0]};
393     }
394     
395     public boolean isRedeploySupported() {
396         return false;
397     }
398
399     public ProgressObject JavaDoc redeploy(TargetModuleID JavaDoc[] targetModuleID,
400                                    InputStream JavaDoc inputStream,
401                                    InputStream JavaDoc inputStream2)
402         throws IllegalStateException JavaDoc, UnsupportedOperationException JavaDoc {
403         throw new UnsupportedOperationException JavaDoc(NbBundle.getMessage(
404                 WS70SunDeploymentManager.class, "UNSUPPORTED_REDPLOY"));
405     }
406
407     public ProgressObject JavaDoc redeploy(TargetModuleID JavaDoc[] tmID, File JavaDoc file,
408                                    File JavaDoc file2)
409         throws IllegalStateException JavaDoc, UnsupportedOperationException JavaDoc {
410         throw new UnsupportedOperationException JavaDoc(NbBundle.getMessage(
411                 WS70SunDeploymentManager.class, "UNSUPPORTED_REDPLOY"));
412     }
413
414     
415     public void release() {
416     }
417     
418
419     public ProgressObject JavaDoc start(TargetModuleID JavaDoc[] tmID)
420         throws IllegalStateException JavaDoc {
421         return ws70DM.start(tmID);
422     }
423
424
425     public ProgressObject JavaDoc stop(TargetModuleID JavaDoc[] tmID)
426         throws IllegalStateException JavaDoc {
427         return ws70DM.stop(tmID);
428
429     }
430
431
432     public ProgressObject JavaDoc undeploy(TargetModuleID JavaDoc[] tmID)
433         throws IllegalStateException JavaDoc {
434         return ws70DM.undeploy(tmID);
435     }
436  
437
438     // Extended methods
439
public void startServer(String JavaDoc configName) throws Exception JavaDoc{
440         try{
441             Method JavaDoc startServer = dmClass.getDeclaredMethod("startServer", new Class JavaDoc[]{String JavaDoc.class}); //NOI18N
442
Boolean JavaDoc retVal = (Boolean JavaDoc)startServer.invoke(this.ws70DM, new Object JavaDoc[]{configName});
443         }catch(InvocationTargetException JavaDoc ite){
444             ite.printStackTrace();
445             throw (Exception JavaDoc)ite.getTargetException();
446         }catch(Exception JavaDoc ex){
447             ex.printStackTrace();
448             throw ex;
449         }
450    }
451    public void stopServer(String JavaDoc configName) throws Exception JavaDoc {
452         try{
453             Method JavaDoc stopServer = dmClass.getDeclaredMethod("stopServer", new Class JavaDoc[]{String JavaDoc.class});//NOI18N
454
Boolean JavaDoc retVal = (Boolean JavaDoc)stopServer.invoke(this.ws70DM, new Object JavaDoc[]{configName});
455             
456         }catch(InvocationTargetException JavaDoc ite){
457             ite.printStackTrace();
458             throw (Exception JavaDoc)ite.getTargetException();
459         }catch(Exception JavaDoc ex){
460             ex.printStackTrace();
461             throw ex;
462         }
463    }
464
465     public List JavaDoc getJVMOptions(String JavaDoc configName, Boolean JavaDoc debugOptions, String JavaDoc profilerName){
466         try{
467             Method JavaDoc getJVMOptions = dmClass.getDeclaredMethod("getJVMOptions", new Class JavaDoc[]{String JavaDoc.class, Boolean JavaDoc.class, String JavaDoc.class});//NOI18N
468
List JavaDoc options = (List JavaDoc)getJVMOptions.invoke(this.ws70DM, new Object JavaDoc[]{configName, debugOptions, profilerName});
469             return options;
470             
471         }catch(Exception JavaDoc ex){
472             ex.printStackTrace();
473         }
474         return null;
475     }
476     public Map JavaDoc getJVMProps(String JavaDoc configName) throws IllegalStateException JavaDoc {
477         try{
478             Method JavaDoc getJvmProps = dmClass.getDeclaredMethod("getJVMProps", new Class JavaDoc[]{String JavaDoc.class});//NOI18N
479
Map JavaDoc options = (Map JavaDoc)getJvmProps.invoke(this.ws70DM, new Object JavaDoc[]{configName});
480             return options;
481             
482         }catch(Exception JavaDoc ex){
483             ex.printStackTrace();
484         }
485         return null;
486     }
487     public void deployAndReconfig(String JavaDoc configName) throws Exception JavaDoc {
488         try{
489             Method JavaDoc deployAndReconfig = dmClass.getDeclaredMethod("deployAndReconfig", new Class JavaDoc[]{String JavaDoc.class});
490             deployAndReconfig.invoke(this.ws70DM, new Object JavaDoc[]{configName});
491         }catch(InvocationTargetException JavaDoc ite){
492             throw (Exception JavaDoc)ite.getTargetException();
493         }catch(Exception JavaDoc ex){
494             throw ex;
495         }
496     }
497     public void changeDebugStatus(String JavaDoc configName,
498                                   boolean enableDisable) throws Exception JavaDoc{
499         try{
500             Method JavaDoc changeDebugStatus = dmClass.getDeclaredMethod("changeDebugStatus", new Class JavaDoc[]{String JavaDoc.class, boolean.class});//NOI18N
501
changeDebugStatus.invoke(this.ws70DM, new Object JavaDoc[]{configName, Boolean.valueOf(enableDisable)});
502         }catch(InvocationTargetException JavaDoc ite){
503             ite.printStackTrace();
504             throw (Exception JavaDoc)ite.getTargetException();
505         }catch(Exception JavaDoc ex){
506             ex.printStackTrace();
507             throw ex;
508         }
509         deployAndReconfig(configName);
510     }
511    // debug-jvm-option string in the server.xml
512
public String JavaDoc getDebugOptions(){
513         return this.debugOptions;
514     }
515     // debug-jvm-option string in the server.xml
516
public void setDebugOptions(String JavaDoc debugString){
517         this.debugOptions = debugString;
518     }
519     public boolean isDebugModeEnabled(){
520         return this.isDebugModeEnabled;
521     }
522     public void setDebugModeEnabled(boolean debugMode){
523         isDebugModeEnabled = debugMode;
524     }
525     public String JavaDoc getNodeNameForTarget(Target JavaDoc target){
526         try{
527             String JavaDoc configName = this.getConfigNameFromTarget(target);
528             Method JavaDoc getNodeName = dmClass.getDeclaredMethod("getNodeName", new Class JavaDoc[]{String JavaDoc.class});
529             return (String JavaDoc)getNodeName.invoke(this.ws70DM, new Object JavaDoc[]{configName});
530         }catch(Exception JavaDoc ex){
531             ex.printStackTrace();
532         }
533         return null;
534     }
535     public boolean changeAppProfilerStatus(String JavaDoc configName, boolean enableDisable){
536         return true;
537     }
538     public List JavaDoc getResources(ResourceType resType, String JavaDoc configName) throws Exception JavaDoc{
539         String JavaDoc methodName = null;
540         if(resType.eqauls(ResourceType.JDBC)){
541             methodName = "getJDBCResources";//NOI18N
542
}else if(resType.eqauls(ResourceType.JNDI)){
543             methodName = "getJNDIResources";//NOI18N
544
}else if(resType.eqauls(ResourceType.MAIL)){
545             methodName = "getMailResources";//NOI18N
546
}else if(resType.eqauls(ResourceType.CUSTOM)){
547             methodName = "getCustomResources";//NOI18N
548
}
549         try{
550             Method JavaDoc getResources = dmClass.getDeclaredMethod(methodName, new Class JavaDoc[]{String JavaDoc.class});
551             List JavaDoc resources = (List JavaDoc)getResources.invoke(this.ws70DM, new Object JavaDoc[]{configName});
552             return resources;
553         }catch(InvocationTargetException JavaDoc ite){
554             ite.printStackTrace();
555             throw (Exception JavaDoc)ite.getTargetException();
556         }catch(Exception JavaDoc ex){
557             ex.printStackTrace();
558             throw ex;
559         }
560     }
561
562     
563     public void setResource(ResourceType resType, String JavaDoc configName,
564             String JavaDoc resName, Map JavaDoc resElements, boolean reconfig) throws Exception JavaDoc{
565         try{
566             String JavaDoc methodName = null;
567             if(resType.eqauls(ResourceType.JDBC)){
568                 methodName = "setJDBCResource";//NOI18N
569
}else if(resType.eqauls(ResourceType.JNDI)){
570                 methodName = "setJNDIResource";//NOI18N
571
}else if(resType.eqauls(ResourceType.MAIL)){
572                 methodName = "setMailResource";//NOI18N
573
}else if(resType.eqauls(ResourceType.CUSTOM)){
574                 methodName = "setCustomResource";//NOI18N
575
}
576             Method JavaDoc setResource = dmClass.getDeclaredMethod(methodName, new Class JavaDoc[]{String JavaDoc.class, String JavaDoc.class, Map JavaDoc.class});
577             setResource.invoke(this.ws70DM, new Object JavaDoc[]{configName, resName, resElements});
578             if(reconfig){
579                 this.deployAndReconfig(configName);
580             }
581             
582         }catch(InvocationTargetException JavaDoc ite){
583             ite.printStackTrace();
584             throw (Exception JavaDoc)ite.getTargetException();
585         }catch(Exception JavaDoc ex){
586             ex.printStackTrace();
587             throw ex;
588         }
589     }
590     public void setUserResourceProp(String JavaDoc configName, String JavaDoc resourceType,
591                         String JavaDoc jndiName, String JavaDoc propType, List JavaDoc userProps, boolean reconfig) throws Exception JavaDoc {
592          try{
593
594             Method JavaDoc setUserProps = dmClass.getDeclaredMethod("setUserResourceProp",
595                         new Class JavaDoc[]{String JavaDoc.class, String JavaDoc.class, String JavaDoc.class, String JavaDoc.class, List JavaDoc.class});
596             setUserProps.invoke(this.ws70DM, new Object JavaDoc[]{configName, resourceType,
597                                         jndiName, propType, userProps});
598             if(reconfig){
599                 this.deployAndReconfig(configName);
600             }
601             
602         }catch(InvocationTargetException JavaDoc ite){
603             ite.printStackTrace();
604             throw (Exception JavaDoc)ite.getTargetException();
605         }catch(Exception JavaDoc ex){
606             ex.printStackTrace();
607             throw ex;
608         }
609     }
610     
611     public void deleteResource(ResourceType resType, String JavaDoc configName, String JavaDoc resName)throws Exception JavaDoc{
612         try{
613             String JavaDoc methodName = null;
614             if(resType.eqauls(ResourceType.JDBC)){
615                 methodName = "delJDBCResource";//NOI18N
616
}else if(resType.eqauls(ResourceType.JNDI)){
617                 methodName = "delJNDIResource";//NOI18N
618
}else if(resType.eqauls(ResourceType.MAIL)){
619                 methodName = "delMailResource";//NOI18N
620
}else if(resType.eqauls(ResourceType.CUSTOM)){
621                 methodName = "delCustomResource";//NOI18N
622
}
623             Method JavaDoc delResource = dmClass.getDeclaredMethod(methodName, new Class JavaDoc[]{String JavaDoc.class, String JavaDoc.class});
624             delResource.invoke(this.ws70DM, new Object JavaDoc[]{configName, resName});
625             this.deployAndReconfig(configName);
626             
627         }catch(InvocationTargetException JavaDoc ite){
628             ite.printStackTrace();
629             throw (Exception JavaDoc)ite.getTargetException();
630         }catch(Exception JavaDoc ex){
631             ex.printStackTrace();
632             throw ex;
633         }
634     }
635     public Map JavaDoc getUserResourceProps(String JavaDoc configName, String JavaDoc resourceType, String JavaDoc jndiName, String JavaDoc propType) throws IllegalStateException JavaDoc {
636         try{
637             Method JavaDoc getUserResourceProps = dmClass.getDeclaredMethod("getUserResourceProps",
638                     new Class JavaDoc[]{String JavaDoc.class, String JavaDoc.class, String JavaDoc.class, String JavaDoc.class});
639             Map JavaDoc resources = (Map JavaDoc)getUserResourceProps.invoke(this.ws70DM, new Object JavaDoc[]{configName, resourceType, jndiName, propType});
640             return resources;
641             
642         }catch(Exception JavaDoc ex){
643             ex.printStackTrace();
644         }
645         return null;
646     }
647     public void addJdbcResource(String JavaDoc configName, String JavaDoc resName,
648                                 Map JavaDoc resAttrs) throws Exception JavaDoc{
649         try{
650             Method JavaDoc addJdbcResource = dmClass.getDeclaredMethod("addJDBCResource",
651                     new Class JavaDoc[]{String JavaDoc.class, String JavaDoc.class, Map JavaDoc.class});
652             addJdbcResource.invoke(this.ws70DM, new Object JavaDoc[]{configName, resName, resAttrs});
653         }catch(InvocationTargetException JavaDoc ite){
654             throw (Exception JavaDoc)ite.getTargetException();
655         }catch(Exception JavaDoc ex){
656             throw ex;
657         }
658         
659     }
660     public void addCustomResource(String JavaDoc configName, String JavaDoc resName,
661                                 Map JavaDoc resAttrs) throws Exception JavaDoc{
662         try{
663             Method JavaDoc addCustomResource = dmClass.getDeclaredMethod("addCustomResource",
664                     new Class JavaDoc[]{String JavaDoc.class, String JavaDoc.class, Map JavaDoc.class});
665             addCustomResource.invoke(this.ws70DM, new Object JavaDoc[]{configName, resName, resAttrs});
666         }catch(InvocationTargetException JavaDoc ite){
667             throw (Exception JavaDoc)ite.getTargetException();
668         }catch(Exception JavaDoc ex){
669             throw ex;
670         }
671         
672     }
673
674     public void addJNDIResource(String JavaDoc configName, String JavaDoc resName,
675                                 Map JavaDoc resAttrs) throws Exception JavaDoc{
676         try{
677             Method JavaDoc addJNDIResource = dmClass.getDeclaredMethod("addJNDIResource",
678                     new Class JavaDoc[]{String JavaDoc.class, String JavaDoc.class, Map JavaDoc.class});
679             addJNDIResource.invoke(this.ws70DM, new Object JavaDoc[]{configName, resName, resAttrs});
680         }catch(InvocationTargetException JavaDoc ite){
681             throw (Exception JavaDoc)ite.getTargetException();
682         }catch(Exception JavaDoc ex){
683             throw ex;
684         }
685     }
686     public void addMailResource(String JavaDoc configName, String JavaDoc resName,
687                                 Map JavaDoc resAttrs) throws Exception JavaDoc{
688         try{
689             Method JavaDoc addMailResource = dmClass.getDeclaredMethod("addMailResource",
690                     new Class JavaDoc[]{String JavaDoc.class, String JavaDoc.class, Map JavaDoc.class});
691             addMailResource.invoke(this.ws70DM, new Object JavaDoc[]{configName, resName, resAttrs});
692         }catch(InvocationTargetException JavaDoc ite){
693             throw (Exception JavaDoc)ite.getTargetException();
694         }catch(Exception JavaDoc ex){
695             throw ex;
696         }
697     }
698     public void setJVMOptions(String JavaDoc configName, List JavaDoc jvmOptions, Boolean JavaDoc debugOptions,
699                                 String JavaDoc profilerName) throws Exception JavaDoc {
700           try{
701             Method JavaDoc setJVMOptions = dmClass.getDeclaredMethod("setJVMOptions",
702                     new Class JavaDoc[]{String JavaDoc.class, List JavaDoc.class, Boolean JavaDoc.class, String JavaDoc.class});
703             setJVMOptions.invoke(this.ws70DM, new Object JavaDoc[]{configName, jvmOptions, debugOptions, profilerName});
704             this.deployAndReconfig(configName);
705         }catch(InvocationTargetException JavaDoc ite){
706             throw (Exception JavaDoc)ite.getTargetException();
707         }catch(Exception JavaDoc ex){
708             throw ex;
709         }
710     }
711     public void setJVMProps(String JavaDoc configName, Map JavaDoc jvmElements) throws Exception JavaDoc {
712         try{
713             Method JavaDoc setJVMProps = dmClass.getDeclaredMethod("setJVMProps",
714                     new Class JavaDoc[]{String JavaDoc.class, Map JavaDoc.class});
715             setJVMProps.invoke(this.ws70DM, new Object JavaDoc[]{configName, jvmElements});
716             this.deployAndReconfig(configName);
717         }catch(InvocationTargetException JavaDoc ite){
718             throw (Exception JavaDoc)ite.getTargetException();
719         }catch(Exception JavaDoc ex){
720             throw ex;
721         }
722     }
723
724     
725     public boolean isRunning(){
726        try {
727              java.net.InetSocketAddress JavaDoc isa = new java.net.InetSocketAddress JavaDoc(java.net.InetAddress.getByName(host), port);
728              java.net.Socket JavaDoc socket = new java.net.Socket JavaDoc();
729              socket.connect(isa);
730              socket.close();
731              return true;
732         } catch (IOException e) {
733             return false;
734         }
735
736     }
737     
738     public boolean isRunning(String JavaDoc configName){
739         if(configName==null){
740             return isRunning();
741         }
742         try{
743             Method JavaDoc isRunning = dmClass.getDeclaredMethod("isServerRunning", new Class JavaDoc[]{String JavaDoc.class});
744             Boolean JavaDoc retVal= (Boolean JavaDoc)isRunning.invoke(this.ws70DM, new Object JavaDoc[]{configName});
745             return retVal.booleanValue();
746             
747         }catch(Exception JavaDoc ex){
748             ex.printStackTrace();
749             return false;
750         }
751     }
752     private String JavaDoc getConfigNameFromTarget(Target JavaDoc target) throws Exception JavaDoc{
753         try{
754             Method JavaDoc getConfigName = target.getClass().getDeclaredMethod("getConfigName", new Class JavaDoc[]{});
755             String JavaDoc configName = (String JavaDoc)getConfigName.invoke(target, new Object JavaDoc[]{});
756             return configName;
757             
758         }catch(InvocationTargetException JavaDoc ite){
759             throw (Exception JavaDoc)ite.getTargetException();
760         }catch(Exception JavaDoc ex){
761             throw ex;
762         }
763     }
764 }
765
Popular Tags