KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > bridge > apis > AppserverMgmtController


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.sun.bridge.apis;
20
21 import java.util.Iterator JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Map JavaDoc;
24
25 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
26 import javax.management.Attribute JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28 import org.netbeans.modules.j2ee.sun.ide.controllers.*;
29
30 import org.netbeans.modules.j2ee.sun.util.NodeTypes;
31
32 import com.sun.appserv.management.base.AMX;
33 import com.sun.appserv.management.base.Util;
34 import com.sun.appserv.management.client.AppserverConnectionSource;
35 import com.sun.appserv.management.config.AdminObjectResourceConfig;
36 import com.sun.appserv.management.config.ConfigConfig;
37 import com.sun.appserv.management.config.ConnectorConnectionPoolConfig;
38 import com.sun.appserv.management.config.ConnectorResourceConfig;
39 import com.sun.appserv.management.config.CustomResourceConfig;
40 import com.sun.appserv.management.config.DomainConfig;
41 import com.sun.appserv.management.config.J2EEApplicationConfig;
42 import com.sun.appserv.management.config.JDBCConnectionPoolConfig;
43 import com.sun.appserv.management.config.JDBCResourceConfig;
44 import com.sun.appserv.management.config.JNDIResourceConfig;
45 import com.sun.appserv.management.config.JavaConfig;
46 import com.sun.appserv.management.config.LogServiceConfig;
47 import com.sun.appserv.management.config.MailResourceConfig;
48 import com.sun.appserv.management.config.ModuleLogLevelsConfig;
49 import com.sun.appserv.management.config.PersistenceManagerFactoryResourceConfig;
50 import com.sun.appserv.management.config.ResourceConfig;
51 import com.sun.appserv.management.config.StandaloneServerConfig;
52 import com.sun.appserv.management.config.WebModuleConfig;
53 import com.sun.appserv.management.j2ee.J2EEServer;
54
55
56
57 /**
58  * Used as a conduit between the Netbeans API's and the AMX MBean API
59  * data model. This API contains convienent methods for retrieving
60  * components allowing the netbeans module heirarchy remain agnostic to the
61  * underlying data model.
62  */

63 public class AppserverMgmtController extends AppserverMgmtControllerBase {
64
65
66     /**
67      * Create an instance of AppserverMgmtController used in the interaction
68      * with AMX API for Sun Java System Application Server.
69      *
70      * @param deployMgr The DeploymentManager object responsible for creating
71      * the connection source.
72      * @param connection An AppserverConnectionSource object used to connect
73      * to the appserver.
74      */

75     public AppserverMgmtController(final DeploymentManager JavaDoc deployMgr,
76             final AppserverConnectionSource connection) {
77         super(deployMgr, connection);
78     }
79
80        
81     /**
82      * Return the J2EEServerMgmtController responsible for handling all
83      * operations on AMX apis involving server specific configuration and
84      * management. Currently this returns the DAS server instance.
85      *
86      * @returns The J2EEServerMgmtController controller for the DAS server
87      * instance.
88      */

89     public J2EEServerMgmtController getJ2EEServerMgmtController() {
90         return getJ2EEServerMgmtController(DAS_SERVER_NAME);
91     }
92
93
94     /**
95      * Return the J2EEServerMgmtController responsible for handling all
96      * operations on AMX apis involving server specific configuration and
97      * management.
98      *
99      * @param serverName The name of the server instance.
100      * @returns The J2EEServerMgmtController controller for the server instance
101      * specified by name.
102      */

103     public J2EEServerMgmtController getJ2EEServerMgmtController(
104             final String JavaDoc serverName) {
105         Map JavaDoc serverMap = getJ2EEDomain().getServerMap();
106         J2EEServer j2eeServer =
107             (J2EEServer) ControllerUtil.getAMXComponentFromMap(
108                 serverMap, serverName);
109         return new J2EEServerMgmtController(j2eeServer, getDeploymentManager(),
110                 appMgmtConnection);
111     }
112     
113    
114     /**
115      * Returns the names of the JDBC Resources.
116      */

117     public String JavaDoc[] getJDBCResources() {
118        return getComponentNamesFromMap(getDomainConfig().
119             getJDBCResourceConfigMap());
120     }
121     
122     
123     /**
124      * Returns the names of the JDBC Connection Pools.
125      */

126     public String JavaDoc[] getJDBCConnectionPools() {
127        return getComponentNamesFromMap(getDomainConfig().
128             getJDBCConnectionPoolConfigMap());
129     }
130     
131     
132     /**
133      * Returns the names of the JMS Connection Factories.
134      */

135     public String JavaDoc[] getJMSConnectionFactories() {
136        return getConnectorResources();
137     }
138     
139     
140     /**
141      * Returns the names of the JDBC Connection Pools.
142      */

143     public String JavaDoc[] getDestinationResources() {
144        return getAdminObjectResources();
145     }
146     
147     
148     /**
149      * Returns the names of the JDBC Connection Pools.
150      */

151     public String JavaDoc[] getJavaMailResources() {
152        return getComponentNamesFromMap(
153         getDomainConfig().getMailResourceConfigMap());
154     }
155     
156     /**
157      * Returns the names of the Connector Resources.
158      */

159     public String JavaDoc[] getConnectorResources() {
160        return getComponentNamesFromMap(
161         getDomainConfig().getConnectorResourceConfigMap());
162     }
163     
164     /**
165      * Returns the names of the Custom Resources.
166      */

167     public String JavaDoc[] getCustomResources() {
168        return getComponentNamesFromMap(
169         getDomainConfig().getCustomResourceConfigMap());
170     }
171     
172     /**
173      * Returns the names of the External Resources.
174      */

175     public String JavaDoc[] getExternalResources() {
176        return getComponentNamesFromMap(
177         getDomainConfig().getJNDIResourceConfigMap());
178     }
179     
180     /**
181      * Returns the names of the Connector Connection Pools.
182      */

183     public String JavaDoc[] getConnectorConnectionPools() {
184         return getComponentNamesFromMap(
185             getDomainConfig().getConnectorConnectionPoolConfigMap());
186     }
187     
188     /**
189      * Returns the names of the Admin Object Resources.
190      */

191     public String JavaDoc[] getAdminObjectResources() {
192        return getComponentNamesFromMap(
193         getDomainConfig().getAdminObjectResourceConfigMap());
194     }
195     
196     
197     /**
198      * Returns the names of the Persistence Manager Factory Resources.
199      */

200     public String JavaDoc[] getPersistenceManagerFactoryResources() {
201        return getComponentNamesFromMap(
202         getDomainConfig().getPersistenceManagerFactoryResourceConfigMap());
203     }
204     
205     
206     /**
207      * Returns the names of the Web Modules.
208      */

209     public String JavaDoc[] getWebModules() {
210        return getComponentNamesFromMap(
211         getDomainConfig().getWebModuleConfigMap());
212     }
213     
214     
215     /**
216      * Returns the names of the Enterprise Applications.
217      */

218     public String JavaDoc[] getEnterpriseApplications() {
219        return getComponentNamesFromMap(
220             getDomainConfig().getJ2EEApplicationConfigMap());
221     }
222     
223     
224     /**
225      * Returns the properties jdbc resource given the jndi name.
226      *
227      * @param The jndi name of the JDBC resource.
228      * @return A Map of all the JDBC properties given the jndi name.
229      */

230     public java.util.Map JavaDoc getJDBCResourceProperties(
231             final String JavaDoc jdbcResourceName,
232             final List JavaDoc propsToIgnore) {
233         JDBCResourceConfig res = getJDBCResourceConfigByName(jdbcResourceName);
234         return getPropertiesFromBackend(NodeTypes.JDBC_RESOURCE, res,
235                 propsToIgnore);
236     }
237     
238     
239     /**
240      * Returns the properties of a jdbc connection pool given the jndi name.
241      *
242      * @param jdbcConnPoolName The jndi name of the JDBC Connection Pool.
243      * @return A Map of all the JDBC Connection Pool properties given the jndi name.
244      */

245     public java.util.Map JavaDoc getJDBCConnectionPoolProperties(
246             final String JavaDoc jdbcConnPoolName,
247             final List JavaDoc propsToIgnore) {
248         JDBCConnectionPoolConfig res =
249             getJDBCConnectionPoolConfigByName(jdbcConnPoolName);
250         return getPropertiesFromBackend(NodeTypes.CONNECTION_POOL, res,
251                 propsToIgnore);
252     }
253     
254     
255     /**
256      * Returns all of the properties of a jvm.
257      *
258      * @param serverName The name of the server from which JVM properties are
259      * requested for properties.
260      * @return A Map of all the JVM properties for this server instance.
261      */

262     public java.util.Map JavaDoc getJVMProperties(final String JavaDoc serverName,
263             final List JavaDoc propsToIgnore) {
264         JavaConfig javaConfig = getReferencedConfig(serverName).getJavaConfig();
265         return getPropertiesFromBackend(NodeTypes.JVM, javaConfig,
266                 propsToIgnore);
267     }
268     
269     /**
270      * Returns all of the properties of a pm resource.
271      *
272      * @param pmResourceName The name of the pm resource.
273      * @return A Map of all the Pm resource properties for this server instance.
274      */

275     public java.util.Map JavaDoc getPersistenceManagerFactoryProperties(
276             final String JavaDoc pmResourceName,
277             final List JavaDoc propsToIgnore) {
278         PersistenceManagerFactoryResourceConfig res =
279             getPersistenceManagerResourceFactoryConfigByName(pmResourceName);
280         return getPropertiesFromBackend(NodeTypes.PM_RESOURCE, res,
281                 propsToIgnore);
282     }
283     
284     /**
285      * Returns the properties of a jmx connection factory given the jndi name.
286      *
287      * @param jmsConnFactoryName The jndi name of the JMS Resource.
288      * @return All the JMS Connection Factory properties given the jndi
289      * name.
290      */

291     public java.util.Map JavaDoc getJMSConnectionFactoryProperties(
292             final String JavaDoc jmsConnFactoryName,
293             final List JavaDoc propsToIgnore) {
294         ConnectorResourceConfig res =
295                 getConnectorResourceConfigByName(jmsConnFactoryName);
296         return getPropertiesFromBackend(NodeTypes.CONNECTION_FACTORY, res,
297                 propsToIgnore);
298     }
299     
300     
301     /**
302      * Returns the properties of a destination resource given the jndi name.
303      *
304      * @param destResName The jndi name of the destination resource.
305      * @return All of the JMS destination resource properties given the jndi
306      * name.
307      */

308     public java.util.Map JavaDoc getDestinationResourceProperties(
309             final String JavaDoc destResName,
310             final List JavaDoc propsToIgnore) {
311         AdminObjectResourceConfig res =
312                 getAdminObjectResourceConfigByName(destResName);
313         return getPropertiesFromBackend(NodeTypes.DESTINATION_RESOURCE, res,
314                 propsToIgnore);
315     }
316     
317     
318     /**
319      * Returns the properties JavaMail resource given the jndi name.
320      *
321      * @param The jndi name of the JavaMail resource.
322      * @return All the JavaMail properties given the jndi name.
323      */

324     public java.util.Map JavaDoc getJavaMailResourceProperties(
325             final String JavaDoc mailResourceName,
326             final List JavaDoc propsToIgnore) {
327         MailResourceConfig res = getMailResourceConfigByName(mailResourceName);
328         return getPropertiesFromBackend(NodeTypes.MAIL_RESOURCE, res,
329                 propsToIgnore);
330     }
331     
332     
333     /**
334      * Returns the properties of a connector connection pool given the name.
335      *
336      * @param The name of the Connector Connection Pool resource.
337      * @return All the Connector Connection Pool properties given the name.
338      */

339     public java.util.Map JavaDoc getConnectorConnectionPoolProperties(
340             final String JavaDoc poolName,
341             final List JavaDoc propsToIgnore) {
342         ConnectorConnectionPoolConfig res =
343                 getConnectorConnectionPoolConfigByName(poolName);
344         return getPropertiesFromBackend(NodeTypes.CONNECTOR_CONNECTION_POOL,
345                 res, propsToIgnore);
346     }
347     
348     
349     /**
350      * Returns the properties of an admin object resource given the name.
351      *
352      * @param resName The name of the Admin Object Resource.
353      * @return All the admin object resource properties given the name.
354      */

355     public java.util.Map JavaDoc getAdminObjectResourceProperties(
356             final String JavaDoc resName,
357             final List JavaDoc propsToIgnore) {
358         AdminObjectResourceConfig res =
359                 getAdminObjectResourceConfigByName(resName);
360         return getPropertiesFromBackend(NodeTypes.ADMIN_OBJECT_RESOURCE, res,
361                 propsToIgnore);
362     }
363   
364     
365     /**
366      * Returns the properties of a connector resource given the name.
367      *
368      * @param The name of the Connector Resource.
369      * @return All the Connector Resource properties given the name.
370      */

371     public java.util.Map JavaDoc getConnectorResourceProperties(
372             final String JavaDoc resName,
373             final List JavaDoc propsToIgnore) {
374         ConnectorResourceConfig res =
375                 getConnectorResourceConfigByName(resName);
376         return getPropertiesFromBackend(NodeTypes.CONNECTOR_RESOURCE, res,
377                 propsToIgnore);
378     }
379     
380     
381     /**
382      * Returns the properties of a custom resource given the name.
383      *
384      * @param The name of the Custom Resource.
385      * @return All the Custom Resource properties given the name.
386      */

387     public java.util.Map JavaDoc getCustomResourceProperties(
388             final String JavaDoc resName,
389             final List JavaDoc propsToIgnore) {
390         CustomResourceConfig res =
391                 getCustomResourceConfigByName(resName);
392         return getPropertiesFromBackend(NodeTypes.CUSTOM_RESOURCE, res,
393                 propsToIgnore);
394     }
395
396     /**
397      * Returns the properties of an external resource module given the name.
398      *
399      * @param The name of the External Resource.
400      * @return All the External Resource properties given the name.
401      */

402     public java.util.Map JavaDoc getExternalResourceProperties(
403             final String JavaDoc moduleName,
404             final List JavaDoc propsToIgnore) {
405         JNDIResourceConfig res =
406                 getJNDIResourceConfigByName(moduleName);
407         return getPropertiesFromBackend(NodeTypes.EXTERNAL_RESOURCE, res,
408                 propsToIgnore);
409     }
410     
411     
412     /**
413      *
414      *
415      */

416     public Attribute JavaDoc setExternalResourceProperty(String JavaDoc resName, String JavaDoc attributeName,
417             Object JavaDoc value) {
418         
419         testIfServerInDebug();
420         
421         JNDIResourceConfig res =
422                 getJNDIResourceConfigByName(resName);
423         Attribute JavaDoc attr = ControllerUtil.setAttributeValue(res, attributeName, value,
424             getMBeanServerConnection());
425         return attr;
426     }
427  
428     
429     /**
430      *
431      *
432      */

433     public String JavaDoc[] getClusters() {
434        return getComponentNamesFromMap(getClustersMap());
435     }
436    
437     
438     StandaloneServerConfig getStandaloneServerConfigByName(
439             String JavaDoc serverName) {
440         java.util.Map JavaDoc map = getStandaloneServerInstancesMap();
441         return (StandaloneServerConfig)map.get(serverName);
442     }
443     
444     
445     /**
446      *
447      */

448     JDBCResourceConfig getJDBCResourceConfigByName(
449             String JavaDoc jdbcResourceName) {
450         java.util.Map JavaDoc map = getDomainConfig().getJDBCResourceConfigMap();
451         return (JDBCResourceConfig)map.get(jdbcResourceName);
452     }
453     
454     
455     /**
456      *
457      */

458     MailResourceConfig getMailResourceConfigByName(
459             String JavaDoc mailResourceName) {
460         java.util.Map JavaDoc map = getDomainConfig().getMailResourceConfigMap();
461         return (MailResourceConfig)map.get(mailResourceName);
462     }
463     
464     
465     /**
466      *
467      */

468     JNDIResourceConfig getJNDIResourceConfigByName(
469             String JavaDoc resName) {
470         java.util.Map JavaDoc map = getDomainConfig().getJNDIResourceConfigMap();
471         return (JNDIResourceConfig)map.get(resName);
472     }
473     
474     /**
475      *
476      */

477     JDBCConnectionPoolConfig getJDBCConnectionPoolConfigByName(
478             String JavaDoc jdbcConnPoolName) {
479         java.util.Map JavaDoc map = getDomainConfig().getJDBCConnectionPoolConfigMap();
480         return (JDBCConnectionPoolConfig)map.get(jdbcConnPoolName);
481     }
482     
483     /**
484      *
485      */

486 // JMSResourceConfig getJMSResourceConfigByName(
487
// String jmsResourceName) {
488
// java.util.Map map = getDomainConfig().getJMSResourceConfigMap();
489
// return (JMSResourceConfig)map.get(jmsResourceName);
490
// }
491

492     /**
493      *
494      */

495     ConnectorResourceConfig getConnectorResourceConfigByName(
496             String JavaDoc connResourceName) {
497         java.util.Map JavaDoc map =
498             getDomainConfig().getConnectorResourceConfigMap();
499         return (ConnectorResourceConfig)map.get(connResourceName);
500     }
501     
502     /**
503      *
504      */

505     ConnectorConnectionPoolConfig getConnectorConnectionPoolConfigByName(
506             String JavaDoc connPoolName) {
507         java.util.Map JavaDoc map =
508             getDomainConfig().getConnectorConnectionPoolConfigMap();
509         return (ConnectorConnectionPoolConfig)map.get(connPoolName);
510     }
511     
512     /**
513      *
514      */

515     CustomResourceConfig getCustomResourceConfigByName(String JavaDoc resName) {
516         java.util.Map JavaDoc map =
517             getDomainConfig().getCustomResourceConfigMap();
518         return (CustomResourceConfig)map.get(resName);
519     }
520     
521     /**
522      *
523      */

524     AdminObjectResourceConfig getAdminObjectResourceConfigByName(
525             String JavaDoc adminObjName) {
526         java.util.Map JavaDoc map = getDomainConfig().getAdminObjectResourceConfigMap();
527         return (AdminObjectResourceConfig)map.get(adminObjName);
528     }
529     
530     /**
531      *
532      */

533     PersistenceManagerFactoryResourceConfig
534             getPersistenceManagerResourceFactoryConfigByName(
535                 String JavaDoc pmResourceName) {
536         java.util.Map JavaDoc map =
537             getDomainConfig().getPersistenceManagerFactoryResourceConfigMap();
538         return (PersistenceManagerFactoryResourceConfig)map.get(pmResourceName);
539     }
540     
541     
542     /**
543      *
544      */

545     WebModuleConfig getWebModuleConfigByName(String JavaDoc webModuleName) {
546         java.util.Map JavaDoc map = getDomainConfig().getWebModuleConfigMap();
547         return (WebModuleConfig)map.get(webModuleName);
548     }
549     
550     
551     /**
552      *
553      */

554     J2EEApplicationConfig getJ2EEApplicationConfigByName(String JavaDoc appName) {
555         java.util.Map JavaDoc map =
556             getDomainConfig().getJ2EEApplicationConfigMap();
557         return (J2EEApplicationConfig)map.get(appName);
558     }
559     
560     /**
561      *
562      *
563      */

564     private String JavaDoc[] getComponentNamesFromMap(java.util.Map JavaDoc map) {
565        return ControllerUtil.getComponentNamesFromMap(map);
566     }
567     
568     /**
569      *
570      *
571      */

572     java.util.Map JavaDoc getClustersMap() {
573        return getDomainConfig().getClusterConfigMap();
574     }
575     
576     /**
577      *
578      *
579      */

580     java.util.Map JavaDoc getStandaloneServerInstancesMap() {
581        return getDomainConfig().getStandaloneServerConfigMap();
582     }
583     
584
585     /**
586      *
587      */

588     public ConfigConfig getReferencedConfig(String JavaDoc serverName) {
589         StandaloneServerConfig serverConfig =
590             getStandaloneServerConfigByName(serverName);
591         DomainConfig config = (DomainConfig)serverConfig.getContainer();
592         AMX component =
593             ControllerUtil.getAMXComponentFromMap(config.getConfigConfigMap(),
594                 serverConfig.getReferencedConfigName());
595         return (ConfigConfig)component;
596     }
597
598     
599     /**
600      *
601      *
602      */

603     public Attribute JavaDoc setJDBCResourceProperty(String JavaDoc jdbcName, String JavaDoc attributeName,
604             Object JavaDoc value) {
605         
606         testIfServerInDebug();
607         JDBCResourceConfig res = getJDBCResourceConfigByName(jdbcName);
608         Attribute JavaDoc attr = ControllerUtil.setAttributeValue(res, attributeName, value,
609                     getMBeanServerConnection());
610         return attr;
611     }
612     
613     /**
614      *
615      *
616      */

617     public Attribute JavaDoc setJDBCConnectionPoolProperty(String JavaDoc resName,
618             String JavaDoc attributeName, Object JavaDoc value) {
619         
620         testIfServerInDebug();
621         
622         Attribute JavaDoc attr = ControllerUtil.setAttributeValue(
623             getJDBCConnectionPoolConfigByName(resName), attributeName, value,
624                 getMBeanServerConnection());
625         return attr;
626     }
627     
628     
629     /**
630      *
631      *
632      */

633     public Attribute JavaDoc setJMSResourceProperty(String JavaDoc resName,
634             String JavaDoc attributeName, Object JavaDoc value) {
635         
636         testIfServerInDebug();
637         
638         Attribute JavaDoc attr = ControllerUtil.setAttributeValue(
639             getConnectorResourceConfigByName(resName), attributeName, value,
640                 getMBeanServerConnection());
641         return attr;
642     }
643     
644     /**
645      *
646      *
647      */

648     public Attribute JavaDoc setDestinationResourceProperty(String JavaDoc resName,
649             String JavaDoc attributeName, Object JavaDoc value) {
650         
651         testIfServerInDebug();
652         
653         Attribute JavaDoc attr = ControllerUtil.setAttributeValue(
654             getAdminObjectResourceConfigByName(resName), attributeName, value,
655                 getMBeanServerConnection());
656         return attr;
657     }
658     
659     
660     /**
661      *
662      *
663      */

664     public Attribute JavaDoc setJavaMailResourceProperty(String JavaDoc resName,
665             String JavaDoc attributeName, Object JavaDoc value) {
666         
667         testIfServerInDebug();
668         
669         Attribute JavaDoc attr = ControllerUtil.setAttributeValue(
670             this.getMailResourceConfigByName(resName), attributeName, value,
671                 getMBeanServerConnection());
672         return attr;
673     }
674     
675     
676     /**
677      *
678      *
679      */

680     public Attribute JavaDoc setPersistenceManagerResourceFactoryProperty(String JavaDoc resName,
681             String JavaDoc attributeName, Object JavaDoc value) {
682         
683         testIfServerInDebug();
684         
685         Attribute JavaDoc attr = ControllerUtil.setAttributeValue(
686             getPersistenceManagerResourceFactoryConfigByName(resName),
687                 attributeName, value, getMBeanServerConnection());
688         return attr;
689     }
690     
691     /**
692      *
693      *
694      */

695     public Attribute JavaDoc setConnectorResourceProperty(String JavaDoc resName,
696             String JavaDoc attributeName, Object JavaDoc value) {
697         Attribute JavaDoc attr = ControllerUtil.setAttributeValue(
698             getConnectorResourceConfigByName(resName), attributeName,
699                 value, getMBeanServerConnection());
700         return attr;
701     }
702     
703     
704     /**
705      *
706      *
707      */

708     public Attribute JavaDoc setConnectorConnectionPoolProperty(String JavaDoc resName,
709             String JavaDoc attributeName, Object JavaDoc value) {
710         
711         testIfServerInDebug();
712         
713         Attribute JavaDoc attr = ControllerUtil.setAttributeValue(
714             getConnectorConnectionPoolConfigByName(resName), attributeName,
715                 value, getMBeanServerConnection());
716         return attr;
717     }
718     
719     
720     /**
721      *
722      *
723      */

724     public Attribute JavaDoc setAdminObjectResourceProperty(String JavaDoc resName,
725             String JavaDoc attributeName, Object JavaDoc value) {
726         
727         testIfServerInDebug();
728         
729         Attribute JavaDoc attr = ControllerUtil.setAttributeValue(
730             getAdminObjectResourceConfigByName(resName), attributeName,
731                 value, getMBeanServerConnection());
732         return attr;
733     }
734     
735    /**
736      *
737      *
738      */

739     public Attribute JavaDoc setJVMProperty(String JavaDoc serverName, String JavaDoc attributeName,
740             Object JavaDoc value) {
741         
742         testIfServerInDebug();
743         
744         Attribute JavaDoc attr = ControllerUtil.setAttributeValue(
745             getReferencedConfig(serverName).getJavaConfig(), attributeName,
746                 value, getMBeanServerConnection());
747         return attr;
748     }
749     
750     
751     /**
752      *
753      *
754      */

755     public Attribute JavaDoc setJMSConnectionFactoryProperty(String JavaDoc resName,
756             String JavaDoc attributeName, Object JavaDoc value) {
757         
758         testIfServerInDebug();
759         
760         Attribute JavaDoc attr = ControllerUtil.setAttributeValue(
761             getConnectorResourceConfigByName(resName), attributeName, value,
762                 getMBeanServerConnection());
763         return attr;
764     }
765     
766     /**
767      *
768      *
769      */

770     public Attribute JavaDoc setCustomResourceProperty(String JavaDoc resName,
771             String JavaDoc attributeName, Object JavaDoc value) {
772         
773         testIfServerInDebug();
774         
775         Attribute JavaDoc attr = ControllerUtil.setAttributeValue(
776             getCustomResourceConfigByName(resName), attributeName, value,
777                 getMBeanServerConnection());
778         return attr;
779     }
780     
781     
782     /**
783      * Deletes an admin object resource.
784      *
785      * @param resName The name of the resource.
786      */

787     public void deleteAdminObjectResource(final String JavaDoc resName) {
788         AdminObjectResourceConfig res =
789                 getAdminObjectResourceConfigByName(resName);
790         if(isEightPlatform()){
791             deleteResourceFromBackend_WorkaroundForPE(
792                     NodeTypes.ADMIN_OBJECT_RESOURCE, resName);
793         }else{
794             removeResourceRef(res, resName);
795             getDomainConfig().removeAdminObjectResourceConfig(resName);
796         }
797         
798     }
799     
800     
801     /**
802      * Deletes an external jndi resource.
803      *
804      * @param resName The name of the resource.
805      */

806     public void deleteExternalResource(final String JavaDoc resName) {
807         JNDIResourceConfig res =
808                 getJNDIResourceConfigByName(resName);
809         if(isEightPlatform()){
810             deleteResourceFromBackend_WorkaroundForPE(
811                     NodeTypes.EXTERNAL_RESOURCE, resName);
812         }else{
813             removeResourceRef(res, resName);
814             getDomainConfig().removeJNDIResourceConfig(resName);
815         }
816     }
817     
818     
819     /**
820      * Delete a custom resource.
821      *
822      * @param resName The name of the resource.
823      */

824     public void deleteCustomResource(final String JavaDoc resName) {
825         CustomResourceConfig res =
826                 getCustomResourceConfigByName(resName);
827         if(isEightPlatform()){
828             deleteResourceFromBackend_WorkaroundForPE(
829                     NodeTypes.CUSTOM_RESOURCE, resName);
830         }else{
831             removeResourceRef(res, resName);
832             getDomainConfig().removeCustomResourceConfig(resName);
833         }
834     }
835     
836     
837     /**
838      * Delete a jms connection factory resource.
839      *
840      * @param resName The name of the resource.
841      */

842     public void deleteJMSConnectionFactory(final String JavaDoc resName) {
843         ConnectorResourceConfig res =
844                 getConnectorResourceConfigByName(resName);
845         if(isEightPlatform()){
846             deleteResourceFromBackend_WorkaroundForPE(
847                     NodeTypes.CONNECTION_FACTORY, resName);
848         }else{
849             removeResourceRef(res, resName);
850             getDomainConfig().removeConnectorResourceConfig(resName);
851         }
852     }
853     
854     
855     /**
856      * Delete a jdbc connection factory resource.
857      *
858      * @param resName The name of the resource.
859      */

860     public void deleteJDBCConnectionPool(final String JavaDoc resName) {
861         JDBCConnectionPoolConfig res =
862             getJDBCConnectionPoolConfigByName(resName);
863         if(isEightPlatform()){
864             deleteResourceFromBackend_WorkaroundForPE(
865                     NodeTypes.CONNECTION_POOL, resName);
866         }else
867             getDomainConfig().removeJDBCConnectionPoolConfig(resName);
868     }
869     
870     
871     /**
872      * Delete a connector connection pool resource.
873      *
874      * @param resName The name of the resource.
875      */

876     public void deleteConnectorConnectionPool(final String JavaDoc resName) {
877         ConnectorConnectionPoolConfig res =
878                 getConnectorConnectionPoolConfigByName(resName);
879         if(isEightPlatform()){
880             deleteResourceFromBackend_WorkaroundForPE(
881                     NodeTypes.CONNECTOR_CONNECTION_POOL, resName);
882         }else
883             getDomainConfig().removeConnectorConnectionPoolConfig(resName);
884      }
885     
886     
887     /**
888      * Delete a connector resource.
889      *
890      * @param resName The name of the resource.
891      */

892     public void deleteConnectorResource(final String JavaDoc resName) {
893         ConnectorResourceConfig res =
894                 getConnectorResourceConfigByName(resName);
895         if(isEightPlatform()){
896             deleteResourceFromBackend_WorkaroundForPE(
897                     NodeTypes.CONNECTOR_RESOURCE, resName);
898         }else{
899             removeResourceRef(res, resName);
900             getDomainConfig().removeConnectorResourceConfig(resName);
901         }
902     }
903     
904     
905     /**
906      * Delete a destination resource.
907      *
908      * @param resName The name of the resource.
909      */

910     public void deleteDestinationResource(final String JavaDoc resName) {
911         AdminObjectResourceConfig res =
912                 getAdminObjectResourceConfigByName(resName);
913         if(isEightPlatform()){
914             deleteResourceFromBackend_WorkaroundForPE(
915                     NodeTypes.DESTINATION_RESOURCE, resName);
916         }else{
917             removeResourceRef(res, resName);
918             getDomainConfig().removeAdminObjectResourceConfig(resName);
919         }
920     }
921     
922     
923     /**
924      * Delete a jdbc resource.
925      *
926      * @param resName The name of the resource.
927      */

928     public void deleteJDBCResource(final String JavaDoc resName) {
929         JDBCResourceConfig res = getJDBCResourceConfigByName(resName);
930         if(isEightPlatform()){
931             deleteResourceFromBackend_WorkaroundForPE(
932                     NodeTypes.JDBC_RESOURCE, resName);
933         }else{
934             removeResourceRef(res, resName);
935             getDomainConfig().removeJDBCResourceConfig(resName);
936         }
937     }
938     
939     
940     /**
941      * Delete a Java mail resource.
942      *
943      * @param resName The name of the resource.
944      */

945     public void deleteJavaMailResource(final String JavaDoc resName) {
946         MailResourceConfig res = getMailResourceConfigByName(resName);
947         if(isEightPlatform()){
948             deleteResourceFromBackend_WorkaroundForPE(
949                     NodeTypes.MAIL_RESOURCE, resName);
950         }else{
951             removeResourceRef(res, resName);
952             getDomainConfig().removeMailResourceConfig(resName);
953         }
954     }
955     
956     
957     /**
958      * Delete a PM resource.
959      *
960      * @param resName The name of the resource.
961      */

962     public void deletePersistenceManagerResourceFactory(final String JavaDoc resName) {
963         PersistenceManagerFactoryResourceConfig res =
964             getPersistenceManagerResourceFactoryConfigByName(resName);
965         if(isEightPlatform()){
966             deleteResourceFromBackend_WorkaroundForPE(
967                     NodeTypes.PM_RESOURCE, resName);
968         }else{
969             removeResourceRef(res, resName);
970             getDomainConfig().removePersistenceManagerFactoryResourceConfig(resName);
971         }
972     }
973     
974     
975     /**
976      * Delete dependent resources.
977      *
978      * @param jdbcConnectionPoolName The name of the JDBC connection pool
979      * referenced by 1+ jdbc resources.
980      */

981     public void deleteDependentJDBCResources(
982             final String JavaDoc jdbcConnectionPoolName) {
983         String JavaDoc [] jdbcResourceNames =
984             getDependentJDBCResourceNames(jdbcConnectionPoolName);
985         for(int i = 0; i < jdbcResourceNames.length; i++) {
986             deleteJDBCResource(jdbcResourceNames[i]);
987         }
988     }
989     
990     
991     /**
992      * Retrieves all the jdbc resources that reference the specified
993      * jdbcConnectionPoolName.
994      *
995      * @param jdbcConnectionPoolName The name of the JDBC connection pool
996      * referenced by 1+ jdbc resources.
997      * @return A String array of all the names of the dependent jdbc resources.
998      */

999     public String JavaDoc[] getDependentJDBCResourceNames(
1000            final String JavaDoc jdbcConnectionPoolName) {
1001        java.util.Map JavaDoc jdbcResMap =
1002                getDomainConfig().getJDBCResourceConfigMap();
1003        java.util.Vector JavaDoc namesToReturn = new java.util.Vector JavaDoc();
1004        if(jdbcConnectionPoolName != null) {
1005            for(Iterator JavaDoc itr = jdbcResMap.values().iterator(); itr.hasNext(); ) {
1006                JDBCResourceConfig config = (JDBCResourceConfig) itr.next();
1007                if(jdbcConnectionPoolName.equals(config.getPoolName())) {
1008                    namesToReturn.add(config.getName());
1009                }
1010            }
1011        }
1012        final String JavaDoc[] names = new String JavaDoc[namesToReturn.size()];
1013        return (String JavaDoc[]) namesToReturn.toArray(names);
1014    }
1015    
1016    
1017    /**
1018     * NOTE: WORKAROUND!
1019     *
1020     *
1021     */

1022    private void deleteResourceFromBackend_WorkaroundForPE(
1023            final String JavaDoc nodeType, final String JavaDoc resName) {
1024        String JavaDoc domainName = BACKEND_COM_SUN_APPSERV_MBEAN_DOMAIN_NAME;
1025        String JavaDoc props = Util.makeProp("type", "resources");
1026        String JavaDoc props2 = Util.makeProp("category", "config");
1027        props = Util.concatenateProps(props, props2);
1028        String JavaDoc operationName = null;
1029        ObjectName JavaDoc resourcesMBeanObjName =
1030                Util.newObjectName(domainName, props);
1031        operationName = NodeTypes.getDeleteResourceMethodName(nodeType);
1032        if(operationName != null) {
1033            try {
1034                getMBeanServerConnection().invoke(resourcesMBeanObjName,
1035                    operationName, new Object JavaDoc[]{resName, DAS_SERVER_NAME},
1036                    new String JavaDoc[]{"java.lang.String", "java.lang.String"} );
1037            } catch(Exception JavaDoc e) {
1038                e.printStackTrace();
1039            }
1040        }
1041    }
1042
1043    
1044    /**
1045     *
1046     */

1047    public String JavaDoc getName() {
1048        return "";
1049    }
1050    
1051    /**
1052     * Returns the properties of the Domain Node given the name.
1053     *
1054     * @param appName The name of the application.
1055     * @return All the application properties.
1056     */

1057    public java.util.Map JavaDoc getLogProperties(String JavaDoc serverName) {
1058        LogServiceConfig logService = getReferencedConfig(serverName).getLogServiceConfig();
1059        ModuleLogLevelsConfig moduleLevels =
1060                logService.getModuleLogLevelsConfig();
1061        return getLogPropertiesFromBackend(moduleLevels, moduleLevels.getAllLevels());
1062    }
1063    
1064    /**
1065     *
1066     *
1067     */

1068    public Attribute JavaDoc setLogProperties(String JavaDoc serverName, String JavaDoc attributeName, Object JavaDoc value) {
1069        testIfServerInDebug();
1070        LogServiceConfig logService = getReferencedConfig(serverName).getLogServiceConfig();
1071        ModuleLogLevelsConfig moduleLevels =
1072                logService.getModuleLogLevelsConfig();
1073        Attribute JavaDoc attr = ControllerUtil.setAttributeValue(
1074            moduleLevels, attributeName, value, getMBeanServerConnection());
1075        return attr;
1076    }
1077        
1078    /**
1079     *
1080     *
1081     */

1082    public void updateResourceExtraProperty(String JavaDoc resourceName, String JavaDoc resourceType, Object JavaDoc[] props, java.util.Map JavaDoc oldProps) {
1083        testIfServerInDebug();
1084        if(resourceType.equals(NodeTypes.CONNECTION_POOL)){
1085            JDBCConnectionPoolConfig cpConfig = getJDBCConnectionPoolConfigByName(resourceName);
1086            if(cpConfig != null){
1087                removeResourceExtraProperty(cpConfig, oldProps);
1088                ControllerUtil.setPropertyValue(cpConfig, props);
1089            }
1090        }else if(resourceType.equals(NodeTypes.CONNECTOR_CONNECTION_POOL)){
1091            ConnectorConnectionPoolConfig connConfig = getConnectorConnectionPoolConfigByName(resourceName);
1092            if(connConfig != null){
1093                removeResourceExtraProperty(connConfig, oldProps);
1094                ControllerUtil.setPropertyValue(connConfig, props);
1095            }
1096        }else{
1097            ResourceConfig res = getRelevantResourceConfig(resourceName, resourceType);
1098            if(res != null){
1099                removeResourceExtraProperty(res, oldProps);
1100                ControllerUtil.setPropertyValue(res, props);
1101            }
1102        }
1103    }
1104    
1105    /**
1106     *
1107     *
1108     */

1109    private ResourceConfig getRelevantResourceConfig(String JavaDoc resourceName, String JavaDoc resourceType) {
1110        ResourceConfig resConfig = null;
1111        if(resourceType.equals(NodeTypes.ADMIN_OBJECT_RESOURCE) || resourceType.equals(NodeTypes.DESTINATION_RESOURCE)){
1112            resConfig = getAdminObjectResourceConfigByName(resourceName);
1113        }else if(resourceType.equals(NodeTypes.CONNECTION_FACTORY) || resourceType.equals(NodeTypes.CONNECTOR_RESOURCE)){
1114            resConfig = getConnectorResourceConfigByName(resourceName);
1115        }else if(resourceType.equals(NodeTypes.JDBC_RESOURCE)){
1116            resConfig = getJDBCResourceConfigByName(resourceName);
1117        }else if(resourceType.equals(NodeTypes.CUSTOM_RESOURCE)){
1118            resConfig = getCustomResourceConfigByName(resourceName);
1119        }else if(resourceType.equals(NodeTypes.EXTERNAL_RESOURCE)){
1120            resConfig = getJNDIResourceConfigByName(resourceName);
1121        }else if(resourceType.equals(NodeTypes.MAIL_RESOURCE)){
1122            resConfig = getMailResourceConfigByName(resourceName);
1123        }else if(resourceType.equals(NodeTypes.PM_RESOURCE)){
1124            resConfig = getPersistenceManagerResourceFactoryConfigByName(resourceName);
1125        }
1126        
1127        return resConfig;
1128    }
1129    
1130    /**
1131     *
1132     *
1133     */

1134    private static void removeResourceExtraProperty(ResourceConfig res, Map JavaDoc oldProps) {
1135        try{
1136            Iterator JavaDoc it = oldProps.keySet().iterator();
1137            while(it.hasNext()){
1138                res.removeProperty(it.next().toString());
1139            }
1140        }catch(Exception JavaDoc ex){
1141            return;
1142            //Suppress any exception
1143
//When properties have been updated outside the IDE and IDE
1144
//is working with a stale copy.
1145
}
1146    }
1147    
1148    /**
1149     *
1150     *
1151     */

1152    private static void removeResourceExtraProperty(JDBCConnectionPoolConfig res, Map JavaDoc oldProps) {
1153        try{
1154            Iterator JavaDoc it = oldProps.keySet().iterator();
1155            while(it.hasNext()){
1156                res.removeProperty(it.next().toString());
1157            }
1158        }catch(Exception JavaDoc ex){
1159            return;
1160            //Suppress any exception
1161
//When properties have been updated outside the IDE and IDE
1162
//is working with a stale copy.
1163
}
1164    }
1165    
1166    /**
1167     *
1168     *
1169     */

1170    private static void removeResourceExtraProperty(ConnectorConnectionPoolConfig res, Map JavaDoc oldProps) {
1171        try{
1172            Iterator JavaDoc it = oldProps.keySet().iterator();
1173            while(it.hasNext()){
1174                res.removeProperty(it.next().toString());
1175            }
1176        }catch(Exception JavaDoc ex){
1177            //Suppress any exception
1178
//When properties have been updated outside the IDE and IDE
1179
//is working with a stale copy.
1180
}
1181    }
1182        
1183    /**
1184     * Obtains the location of a web module given its context root.
1185     * @param contextRoot Context Root of web module
1186     * @return Return the location of the web module with the specified context root
1187     */

1188    public String JavaDoc getWebModuleName(String JavaDoc contextRoot){
1189        J2EEServerMgmtController controller = getJ2EEServerMgmtController();
1190        String JavaDoc modname = null;
1191        if(controller != null)
1192            modname = controller.getWebModuleName(contextRoot);
1193        
1194        return modname;
1195    }
1196    
1197    /*
1198     * Get Server Type : PR or EE
1199     *
1200     * @return true if 8.x EE
1201     */

1202    public boolean isEightPlatform(){
1203        boolean isPlatform = true;
1204        J2EEServerMgmtController controller = getJ2EEServerMgmtController();
1205        String JavaDoc serverName = controller.getServerName();
1206        if((serverName != null) && (serverName.indexOf("Enterprise Edition 8.") != -1)) //NOI18N
1207
isPlatform = false;
1208        return isPlatform;
1209    }
1210    
1211    /*
1212     * Get Server Version
1213     *
1214     * @return true if 9.0
1215     */

1216    public boolean isGlassfish(){
1217        boolean isGlassfish = true;
1218        J2EEServerMgmtController controller = getJ2EEServerMgmtController();
1219        String JavaDoc serverName = controller.getServerName();
1220        if((serverName != null) && (serverName.indexOf("8.") != -1)) //NOI18N
1221
isGlassfish = false;
1222        return isGlassfish;
1223    }
1224}
1225
Popular Tags