KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > server > ResourcesUtil


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.server;
25
26 import com.sun.appserv.server.util.ASClassLoaderUtil;
27 import com.sun.enterprise.config.serverbeans.*;
28 import com.sun.enterprise.config.*;
29 import com.sun.logging.LogDomains;
30 import com.sun.enterprise.admin.event.ResourceDeployEvent;
31 import com.sun.enterprise.deployment.runtime.connector.SunConnector;
32 import com.sun.enterprise.deployment.ConnectorDescriptor;
33 import com.sun.enterprise.deployment.ConnectionDefDescriptor;
34 import com.sun.enterprise.deployment.EnvironmentProperty;
35 import com.sun.enterprise.deployment.Application;
36 import com.sun.enterprise.deployment.runtime.connector.ResourceAdapter;
37
38 import com.sun.enterprise.server.ApplicationLifecycle;
39 import com.sun.enterprise.instance.AppsManager;
40 import com.sun.enterprise.instance.EjbModulesManager;
41 import com.sun.enterprise.instance.InstanceFactory;
42 import com.sun.enterprise.instance.InstanceEnvironment;
43 import com.sun.enterprise.loader.EJBClassPathUtils;
44
45 import com.sun.enterprise.connectors.ConnectorRegistry;
46 import com.sun.enterprise.connectors.ConnectorRuntime;
47 import com.sun.enterprise.connectors.ConnectorConstants;
48 import com.sun.enterprise.connectors.ConnectorRuntimeException;
49 import com.sun.enterprise.connectors.DeferredResourceConfig;
50 import com.sun.enterprise.connectors.util.ConnectionPoolObjectsUtils;
51 import com.sun.enterprise.util.RelativePathResolver;
52 import com.sun.enterprise.util.Utility;
53 import java.util.Vector JavaDoc;
54 import java.util.logging.Level JavaDoc;
55 import java.util.logging.LogRecord JavaDoc;
56 import java.util.logging.Logger JavaDoc;
57 import java.util.Set JavaDoc;
58 import java.util.Iterator JavaDoc;
59 import java.lang.Integer JavaDoc;
60 import java.util.ArrayList JavaDoc;
61 import java.lang.reflect.Method JavaDoc;
62 import javax.resource.spi.ManagedConnectionFactory JavaDoc;
63
64
65 /**
66   *
67   * @author Srikanth P, Sivakumar Thyagarajan, Aditya Gore
68   * @version
69  */

70
71 public class ResourcesUtil {
72     static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
73     static int NO_OF_ALL_CONNECTOR_RESOURCE_TYPE = 4;
74     static int NO_OF_CONNECTOR_RESOURCE_TYPE = 3;
75     static int NO_OF_JDBC_RESOURCE_TYPE = 2;
76
77     private static ServerContext sc_ = null;
78     private static Resources res = null;
79     private static Domain dom = null;
80     private static ConfigContext configContext_ =null;
81     private static ResourcesUtil instance_=null;
82     private ConnectorConnectionPool[] standAloneRarConnectorConnectionPools =
83                          null;
84     private ConnectorConnectionPool[] embeddedRarConnectorConnectionPools =
85                          null;
86     private boolean filteredConnectorConnectionPool = false;
87     private ConnectorResource[] standAloneRarConnectorResources = null;
88     private ConnectorResource[] embeddedRarConnectorResources = null;
89     private boolean filteredConnectorResources = false;
90     private AdminObjectResource[] standAloneRarAdminObjectResources = null;
91     private AdminObjectResource[] embeddedRarAdminObjectResources = null;
92     private boolean filteredAdminObjectResources = false;
93     private static Applications apps = null;
94     private static ConnectorModule[] connectorModules = null;
95     private static J2eeApplication[] j2eeApps = null;
96     private boolean reinitConfigContext=true;
97     
98     private static final String JavaDoc JNDI_METHOD = "getJndiName";
99     private static final String JavaDoc NAME_METHOD = "getName";
100
101     public static ResourcesUtil getInstance(ServerContext sc)
102                 throws ConfigException {
103         if(instance_ == null) {
104             sc_ = sc;
105             configContext_ = sc.getConfigContext();
106             dom = ServerBeansFactory.getDomainBean(configContext_);
107             res = dom.getResources();
108             apps = dom.getApplications();
109             connectorModules = apps.getConnectorModule();
110             j2eeApps = apps.getJ2eeApplication();
111         if (isDAS()) {
112             if (_logger.isLoggable(Level.FINE)) {
113             _logger.fine("Creating DASResourcesUtil. We are in DAS");
114         }
115             instance_ = new DASResourcesUtil();
116         } else {
117                 instance_ = new ResourcesUtil();
118         }
119
120         }
121         return instance_;
122     }
123
124     public static ResourcesUtil getInstance() {
125        return instance_;
126     }
127
128     protected ResourcesUtil() {
129     }
130
131     public ConfigBean[][] getConnectorResources() throws ConfigException{
132
133         ConfigBean configBeanArray[][] =
134                         new ConfigBean[NO_OF_ALL_CONNECTOR_RESOURCE_TYPE][];
135
136         // connector connection pool
137
ConnectorConnectionPool[] ccp = res.getConnectorConnectionPool();
138         configBeanArray[0] = getReferencedBeans(ccp, NAME_METHOD);
139
140         // connector resource
141
ConnectorResource[] cr = res.getConnectorResource();
142         configBeanArray[1] = getReferencedConnectorResourceBeans(cr, JNDI_METHOD);
143
144         // admin object resource
145
AdminObjectResource[] ar = res.getAdminObjectResource();
146         configBeanArray[2] = getReferencedBeans(ar, JNDI_METHOD);
147
148         // resource adapter config
149
ResourceAdapterConfig[] rac = res.getResourceAdapterConfig();
150         configBeanArray[3] = getReferencedBeans(rac, NAME_METHOD);
151
152         return configBeanArray;
153     }
154     public ConfigBean[][] getConnectorResources(boolean onlystandAloneRars)
155                                 throws ConfigException{
156
157         ConfigBean configBeanArray[][] =
158                         new ConfigBean[NO_OF_CONNECTOR_RESOURCE_TYPE][];
159         configBeanArray[0] = getFilteredConnectorConnectionPools(
160                                       onlystandAloneRars);
161         configBeanArray[1] = getFilteredConnectorResources(
162                                                onlystandAloneRars);
163         configBeanArray[2] = getFilteredAdminObjectResources(
164                                                onlystandAloneRars);
165 /*
166         if(onlystandAloneRars) {
167             configBeanArray[3] = getResourceAdapterConfigProps();
168         }
169 */

170         return configBeanArray;
171     }
172
173     public ConfigBean[][] getStandAloneNonSystemRarConnectorResources()
174                            throws ConfigException {
175
176         boolean onlystandAloneRars = true;
177         ConfigBean configBeanArray[][] =
178                         new ConfigBean[NO_OF_CONNECTOR_RESOURCE_TYPE][];
179         ConfigBean[] ccp = getFilteredConnectorConnectionPools(
180                                       onlystandAloneRars);
181         
182         configBeanArray[0] = getNonSystemRarPools(ccp);
183         ConfigBean[] connectorResource = getFilteredConnectorResources(
184                                                onlystandAloneRars);
185         configBeanArray[1] = getNonSystemRarResources(
186                                 configBeanArray[0],connectorResource);
187         ConfigBean[] adminObjectRes = getFilteredAdminObjectResources(
188                                                onlystandAloneRars);
189
190         configBeanArray[2] = getNonSystemRarAdminObjects(adminObjectRes);
191
192         return configBeanArray;
193     }
194
195     private ConfigBean[] getNonSystemRarPools(ConfigBean[] ccp) {
196
197         if(ccp == null || ccp.length == 0 ) {
198             return null;
199         }
200         int noOfPools = 0;
201         String JavaDoc rarName = null;
202         Vector JavaDoc indexes = new Vector JavaDoc();
203         for(int i=0;i<ccp.length;++i) {
204             rarName = ((ConnectorConnectionPool)ccp[i]).getResourceAdapterName();
205             if(rarName != null && !belongToSystemRar(rarName)) {
206                 noOfPools++;
207                 indexes.add(new Integer JavaDoc(i));
208             }
209         }
210         ConfigBean configBeanArray[] = null;
211         if(noOfPools != 0) {
212             configBeanArray = new ConfigBean[noOfPools];
213         }
214         int location = 0;
215         for(int i=0;i<indexes.size();++i) {
216             location = ((Integer JavaDoc)(indexes.elementAt(i))).intValue();
217             configBeanArray[i] = ccp[location];
218         }
219         return configBeanArray;
220     }
221
222     private ConfigBean[] getNonSystemRarAdminObjects(
223                           ConfigBean[] adminObjectRes)
224     {
225         if(adminObjectRes == null || adminObjectRes.length == 0 ) {
226             return null;
227         }
228         int noOfRes = 0;
229         String JavaDoc rarName = null;
230         Vector JavaDoc indexes = new Vector JavaDoc();
231         for(int i=0;i<adminObjectRes.length;++i) {
232             rarName = ((AdminObjectResource)adminObjectRes[i]).getResAdapter();
233             if(rarName != null && !belongToSystemRar(rarName)) {
234                 noOfRes++;
235                 indexes.add(new Integer JavaDoc(i));
236             }
237         }
238         ConfigBean configBeanArray[] = null;
239         if(noOfRes != 0) {
240             configBeanArray = new ConfigBean[noOfRes];
241         }
242         int location = 0;
243         for(int i=0;i<indexes.size();++i) {
244             location = ((Integer JavaDoc)(indexes.elementAt(i))).intValue();
245             configBeanArray[i] = adminObjectRes[location];
246         }
247         return configBeanArray;
248     }
249     private ConfigBean[] getNonSystemRarResources(
250          ConfigBean[] ccp,ConfigBean[] connectorResource)
251     {
252         if(ccp == null || ccp.length == 0 ||
253                  connectorResource == null || connectorResource.length == 0) {
254             return null;
255         }
256         int noOfRes = 0;
257         String JavaDoc poolName = null;
258         String JavaDoc connectionPoolName = null;
259         Vector JavaDoc indexes = new Vector JavaDoc();
260         for(int i=0;i<connectorResource.length;++i) {
261             poolName = ((ConnectorResource)connectorResource[i]).getPoolName();
262             for(int j=0;poolName != null && j<ccp.length;++j) {
263                 connectionPoolName = ((ConnectorConnectionPool)ccp[j]).getName();
264                 if(poolName.equals(connectionPoolName)) {
265                     noOfRes++;
266                     indexes.add(new Integer JavaDoc(i));
267                 }
268             }
269         }
270         ConfigBean configBeanArray[] = null;
271         if(noOfRes != 0) {
272             configBeanArray = new ConfigBean[noOfRes];
273         }
274         int location = 0;
275         for(int i=0;i<indexes.size();++i) {
276             location = ((Integer JavaDoc)(indexes.elementAt(i))).intValue();
277             configBeanArray[i] = connectorResource[location];
278         }
279         return configBeanArray;
280     }
281     public ConfigBean[] getResourceAdapterConfigs() throws ConfigException {
282         reinitialize();
283         ResourceAdapterConfig[] raConfigBeans = res.getResourceAdapterConfig();
284         return raConfigBeans;
285     }
286
287     public ConfigBean[] getResourceAdapterConfigs(String JavaDoc rarName)
288                                throws ConfigException
289     {
290         reinitialize();
291         ResourceAdapterConfig[] raConfigBeans = res.getResourceAdapterConfig();
292         if(raConfigBeans == null) {
293             return null;
294         }
295         Vector JavaDoc tmpVector = new Vector JavaDoc();
296         for(int i=0;raConfigBeans != null && i<raConfigBeans.length;++i) {
297             if(raConfigBeans[i].getResourceAdapterName().equals(rarName)){
298                 tmpVector.add(raConfigBeans[i]);
299             }
300         }
301         return convertToConfigBeans(tmpVector);
302     }
303
304     public ConfigBean[] getEmbeddedRarResourceAdapterConfigs(String JavaDoc appName)
305                                throws ConfigException
306     {
307         reinitialize();
308         
309         Applications apps = dom.getApplications();
310         J2eeApplication j2eeApp = apps.getJ2eeApplicationByName(appName);
311         if(j2eeApp == null || !j2eeApp.isEnabled()) {
312             return null;
313         }
314         
315         ResourceAdapterConfig[] raConfigBeans = res.getResourceAdapterConfig();
316         
317         if(raConfigBeans == null) {
318             return null;
319         }
320         String JavaDoc appNameToken = null;
321         Vector JavaDoc tmpVector = new Vector JavaDoc();
322         for(int i=0;i<raConfigBeans.length;++i) {
323             appNameToken =
324                   getAppNameToken(raConfigBeans[i].getResourceAdapterName());
325             if(appNameToken != null && appName.equals(appNameToken)) {
326                 tmpVector.add(raConfigBeans[i]);
327             }
328         }
329         return convertToConfigBeans(tmpVector);
330     }
331
332     private String JavaDoc getAppNameToken(String JavaDoc rarName) {
333         if(rarName == null) {
334             return null;
335         }
336       
337         int index = rarName.indexOf(
338                      ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER);
339         if(index != -1) {
340                 return rarName.substring(0,index);
341         } else {
342             return null;
343         }
344     }
345
346     public ConfigBean[][] getConnectorResources(String JavaDoc rarName)
347                        throws ConfigException
348     {
349
350         ConfigBean configBeanArray[][] =
351                         new ConfigBean[NO_OF_CONNECTOR_RESOURCE_TYPE][];
352         configBeanArray[0] = getEnabledConnectorConnectionPools(
353                                       rarName);
354         configBeanArray[1] = getEnabledConnectorResources(
355                                                rarName);
356         configBeanArray[2] = getEnabledAdminObjectResources(
357                                                rarName);
358         return configBeanArray;
359
360     }
361
362     public ConfigBean[][] getAllConnectorResources(String JavaDoc rarName)
363                        throws ConfigException
364     {
365
366         ConfigBean configBeanArray[][] =
367                         new ConfigBean[NO_OF_ALL_CONNECTOR_RESOURCE_TYPE][];
368         configBeanArray[0] = getEnabledConnectorConnectionPools(
369                                       rarName);
370         configBeanArray[1] = getEnabledConnectorResources(
371                                                rarName);
372         configBeanArray[2] = getEnabledAdminObjectResources(
373                                                rarName);
374         configBeanArray[3] = getResourceAdapterConfigs(rarName);
375
376         return configBeanArray;
377
378     }
379
380     public void setConfigContext(ConfigContext ctx) {
381         configContext_ = ctx;
382     }
383
384     public ConfigContext getConfigContext() {
385         return configContext_;
386     }
387
388     public void setReinitConfigContext(boolean reinitConfigContext) {
389         this.reinitConfigContext = reinitConfigContext;
390     }
391
392     public boolean isReinitConfigContext() {
393         return this.reinitConfigContext;
394     }
395     public void reinitialize() {
396         try {
397             if(reinitConfigContext) {
398                 configContext_ =
399                    ApplicationServer.getServerContext().getConfigContext();
400             }
401             dom = ServerBeansFactory.getDomainBean(configContext_);
402             res = dom.getResources();
403             apps = dom.getApplications();
404         } catch (ConfigException ce) {
405         }
406     }
407
408     public boolean poolBelongsToSystemRar(String JavaDoc poolName) {
409         DeferredResourceConfig poolConfig =
410                        getDeferredConnectorPoolConfigs(poolName);
411         if(poolConfig != null &&
412                  belongToSystemRar(poolConfig.getRarName())) {
413             return true;
414         } else {
415             poolConfig = getDeferredJdbcPoolConfigs(poolName);
416             if(poolConfig != null) {
417                 return belongToSystemRar(poolConfig.getRarName());
418             }
419         }
420         return false;
421     }
422
423     public boolean resourceBelongsToSystemRar(String JavaDoc resourceName) {
424         DeferredResourceConfig resourceConfig =
425                        getDeferredConnectorResourceConfigs(resourceName);
426         if(resourceConfig != null &&
427                 belongToSystemRar(resourceConfig.getRarName())) {
428             return true;
429         } else {
430             resourceConfig =
431                        getDeferredJdbcResourceConfigs(resourceName);
432             if(resourceConfig != null) {
433                 return belongToSystemRar(resourceConfig.getRarName());
434             }
435         }
436         return false;
437     }
438
439     public boolean adminObjectBelongsToSystemRar(String JavaDoc adminObject) {
440         DeferredResourceConfig adminObjectConfig =
441                        getDeferredAdminObjectConfigs(adminObject);
442         if(adminObjectConfig != null) {
443             return belongToSystemRar(adminObjectConfig.getRarName());
444         }
445         return false;
446     }
447     protected DeferredResourceConfig getDeferredConnectorResourceConfigs(
448                   String JavaDoc resourceName)
449     {
450
451         if(resourceName == null) {
452             return null;
453         }
454         
455         ConfigBean[] resourcesToload = new ConfigBean[2];
456         reinitialize();
457
458         try {
459             if(!isReferenced(resourceName)){
460                 return null;
461             }
462         } catch (ConfigException e) {
463             _logger.log(Level.WARNING, e.getMessage());
464             _logger.log(Level.FINE, "Error while finding resource references " , e);
465         }
466         
467         
468         ConnectorResource connectorResource =
469                      res.getConnectorResourceByJndiName(resourceName);
470         if(connectorResource == null || !connectorResource.isEnabled()) {
471             return null;
472         }
473         String JavaDoc poolName = connectorResource.getPoolName();
474         ConnectorConnectionPool ccPool =
475                        res.getConnectorConnectionPoolByName(poolName);
476         if(ccPool == null) {
477             return null;
478         }
479         String JavaDoc rarName = ccPool.getResourceAdapterName();
480         if(rarName != null && belongToSystemRar(rarName)) {
481             resourcesToload[0] = ccPool;
482             resourcesToload[1] = connectorResource;
483             ResourceAdapterConfig[] resourceAdapterConfig =
484                                         new ResourceAdapterConfig[1];
485             resourceAdapterConfig[0] =
486                          res.getResourceAdapterConfigByResourceAdapterName(
487                           rarName);
488             DeferredResourceConfig resourceConfig =
489                             new DeferredResourceConfig(rarName,null,ccPool,
490                             connectorResource,null,null,
491                             resourceAdapterConfig);
492             resourceConfig.setResourcesToLoad(resourcesToload);
493             return resourceConfig;
494         }
495         return null;
496     }
497
498     protected DeferredResourceConfig getDeferredConnectorPoolConfigs(
499                   String JavaDoc poolName)
500     {
501
502         ConfigBean[] resourcesToload = new ConfigBean[1];
503         if(poolName == null) {
504             return null;
505         }
506         
507         
508         reinitialize();
509
510         ConnectorConnectionPool ccPool =
511                 res.getConnectorConnectionPoolByName(poolName);
512         if(ccPool == null) {
513             return null;
514         }
515         
516         String JavaDoc rarName = ccPool.getResourceAdapterName();
517         
518         if(rarName != null && belongToSystemRar(rarName)) {
519             resourcesToload[0] = ccPool;
520             ResourceAdapterConfig[] resourceAdapterConfig =
521                       new ResourceAdapterConfig[1];
522             resourceAdapterConfig[0] =
523                    res.getResourceAdapterConfigByResourceAdapterName(
524                    rarName);
525             DeferredResourceConfig resourceConfig =
526                  new DeferredResourceConfig(rarName,null,ccPool,
527                  null,null,null,resourceAdapterConfig);
528             resourceConfig.setResourcesToLoad(resourcesToload);
529             return resourceConfig;
530         }
531         return null;
532     }
533     protected DeferredResourceConfig getDeferredAdminObjectConfigs(
534                   String JavaDoc resourceName)
535     {
536
537         if(resourceName == null) {
538             return null;
539         }
540         ConfigBean[] resourcesToload = new ConfigBean[1];
541         reinitialize();
542         
543         try {
544             if(!isReferenced(resourceName)){
545                 return null;
546             }
547         } catch (ConfigException e) {
548             _logger.log(Level.WARNING, e.getMessage());
549             _logger.log(Level.FINE, "Error while finding resource references " , e);
550         }
551         
552         AdminObjectResource adminObjectResource =
553                       res.getAdminObjectResourceByJndiName(resourceName);
554         if(adminObjectResource == null || !adminObjectResource.isEnabled()) {
555             return null;
556         }
557         String JavaDoc rarName = adminObjectResource.getResAdapter();
558         if(rarName != null && belongToSystemRar(rarName)) {
559             resourcesToload[0] = adminObjectResource;
560             ResourceAdapterConfig[] resourceAdapterConfig =
561                                         new ResourceAdapterConfig[1];
562             resourceAdapterConfig[0] =
563                    res.getResourceAdapterConfigByResourceAdapterName(rarName);
564             DeferredResourceConfig resourceConfig =
565                          new DeferredResourceConfig(rarName,adminObjectResource,
566                          null,null,null,null,resourceAdapterConfig);
567             resourceConfig.setResourcesToLoad(resourcesToload);
568             return resourceConfig;
569         }
570         return null;
571     }
572
573     protected DeferredResourceConfig getDeferredJdbcResourceConfigs(
574                   String JavaDoc resourceName)
575     {
576
577         ConfigBean[] resourcesToload = new ConfigBean[2];
578         if(resourceName == null) {
579             return null;
580         }
581         reinitialize();
582         
583         try {
584             //__pm does not have a domain.xml entry and hence will not
585
//be referenced
586
if(!(resourceName.endsWith("__pm"))){
587                 if(!isReferenced(resourceName)){
588                     return null;
589                 }
590             }
591         } catch (ConfigException e) {
592             _logger.log(Level.WARNING, e.getMessage());
593             _logger.log(Level.FINE, "Error while finding resource references " , e);
594         }
595         
596         JdbcResource jdbcResource = res.getJdbcResourceByJndiName(resourceName);
597         if(jdbcResource == null || !jdbcResource.isEnabled()) {
598             String JavaDoc cmpResourceName =
599                         getCorrespondingCmpResourceName(resourceName);
600             jdbcResource =res.getJdbcResourceByJndiName(cmpResourceName);
601             if(jdbcResource == null) {
602                 return null;
603             }
604         }
605         JdbcConnectionPool jdbcPool =
606                 res.getJdbcConnectionPoolByName(jdbcResource.getPoolName());
607         if(jdbcPool == null) {
608             return null;
609         }
610         String JavaDoc rarName = getRAForJdbcConnectionPool(jdbcPool);
611         if(rarName != null && belongToSystemRar(rarName)) {
612             resourcesToload[0] = jdbcPool;
613             resourcesToload[1] = jdbcResource;
614             DeferredResourceConfig resourceConfig =
615                             new DeferredResourceConfig(rarName,null,null,
616                             null,jdbcPool,jdbcResource,null);
617             resourceConfig.setResourcesToLoad(resourcesToload);
618             return resourceConfig;
619         }
620         return null;
621     }
622
623     protected DeferredResourceConfig getDeferredJdbcPoolConfigs(
624                   String JavaDoc poolName)
625     {
626     
627         ConfigBean[] resourcesToload = new ConfigBean[1];
628         if(poolName == null) {
629             return null;
630         }
631         reinitialize();
632
633         JdbcConnectionPool jdbcPool =
634                 res.getJdbcConnectionPoolByName(poolName);
635         if(jdbcPool == null) {
636             return null;
637         }
638         String JavaDoc rarName = getRAForJdbcConnectionPool(jdbcPool);
639         
640         if(rarName != null && belongToSystemRar(rarName)) {
641                     resourcesToload[0] = jdbcPool;
642                     DeferredResourceConfig resourceConfig =
643                             new DeferredResourceConfig(rarName,null,null,
644                             null,jdbcPool,null,null);
645                     resourceConfig.setResourcesToLoad(resourcesToload);
646                     return resourceConfig;
647         }
648         return null;
649     }
650
651     public DeferredResourceConfig getDeferredResourceConfig(String JavaDoc resourceName)
652     {
653         DeferredResourceConfig resConfig = getDeferredConnectorResourceConfigs(
654                                               resourceName);
655         if(resConfig != null) {
656             return resConfig;
657         }
658  
659         resConfig = getDeferredJdbcResourceConfigs(
660                                               resourceName);
661         
662         if(resConfig != null) {
663             return resConfig;
664         }
665        
666         resConfig = getDeferredAdminObjectConfigs(
667                                               resourceName);
668         
669         if(resConfig != null) {
670             return resConfig;
671         }
672         return null;
673     }
674
675     public DeferredResourceConfig getDeferredPoolConfig(String JavaDoc poolName)
676     {
677
678         DeferredResourceConfig resConfig = getDeferredConnectorPoolConfigs(
679                                               poolName);
680         if(resConfig != null) {
681             return resConfig;
682         }
683
684         if(poolName == null){
685             return null;
686         }
687          
688         resConfig = getDeferredJdbcPoolConfigs(poolName);
689         
690         if(resConfig != null) {
691             return resConfig;
692         }
693        
694         return null;
695     }
696     
697     protected String JavaDoc getCorrespondingCmpResourceName(String JavaDoc resourceName) {
698
699         int index = resourceName.lastIndexOf("__pm");
700         if(index != -1) {
701             return resourceName.substring(0,index);
702         }
703         return null;
704     }
705
706     private ConfigBean[] getEnabledConnectorConnectionPools(String JavaDoc rarName) throws ConfigException {
707
708         reinitialize();
709         ConnectorConnectionPool[] connectorConnectionPools =
710                      res.getConnectorConnectionPool();
711         int size = connectorConnectionPools.length;
712         if(size == 0) {
713             return null;
714         }
715
716         Vector JavaDoc tmpVector = new Vector JavaDoc();
717         for(int i=0;connectorConnectionPools != null && i<connectorConnectionPools.length;++i) {
718             if(connectorConnectionPools[i].getResourceAdapterName().equals(rarName)
719                       && isEnabled(connectorConnectionPools[i])){
720                 tmpVector.add(connectorConnectionPools[i]);
721             }
722         }
723         return convertToConfigBeans(tmpVector);
724     }
725
726
727     private ConfigBean[] getEnabledConnectorResources(String JavaDoc rarName) throws ConfigException {
728
729         reinitialize();
730         ConnectorResource[] connectorResources =
731                      res.getConnectorResource();
732         int size = connectorResources.length;
733         if(size == 0) {
734             return null;
735         }
736
737         Vector JavaDoc tmpVector = new Vector JavaDoc();
738         for(int i=0;connectorResources != null && i<connectorResources.length;++i) {
739             if(belongToRar(rarName,connectorResources[i])
740                     && isEnabled(connectorResources[i])
741                     && isReferenced(connectorResources[i].getJndiName())){
742                 tmpVector.add(connectorResources[i]);
743             }
744         }
745         return convertToConfigBeans(tmpVector);
746     }
747     
748     public ConfigBean[] getEnabledAdminObjectResources(String JavaDoc rarName) throws ConfigException {
749
750         reinitialize();
751         AdminObjectResource[] aor =
752                      res.getAdminObjectResource();
753         int size = aor.length;
754         if(size == 0) {
755             return null;
756         }
757
758         Vector JavaDoc tmpVector = new Vector JavaDoc();
759         for(int i=0;aor != null && i<aor.length;++i) {
760             if(belongToRar(rarName,aor[i]) && isEnabled(aor[i])
761                     && isReferenced(aor[i].getJndiName())){
762                 tmpVector.add(aor[i]);
763             }
764         }
765         return convertToConfigBeans(tmpVector);
766     }
767
768     private ConfigBean[] convertToConfigBeans(Vector JavaDoc vector) {
769         int size = vector.size();
770         if(size == 0) {
771             return null;
772         }
773         ConfigBean[] retConfigBeans = new ConfigBean[size];
774         for(int i=0;i<size;++i) {
775             retConfigBeans[i] = (ConfigBean)vector.get(i);
776         }
777         return retConfigBeans;
778     }
779     
780     private ConfigBean[] getFilteredAdminObjectResources(boolean onlystandAloneRars)
781         throws ConfigException
782     {
783         if( filteredAdminObjectResources) {
784             if(onlystandAloneRars) {
785                 return standAloneRarAdminObjectResources;
786             } else {
787                 return embeddedRarAdminObjectResources;
788
789             }
790         }
791         filteredAdminObjectResources=true;
792         int noOfAdminObjectResources = res.sizeAdminObjectResource();
793         if(noOfAdminObjectResources == 0) {
794             return null;
795         }
796
797         Vector JavaDoc standAloneRarAdminObjectResourcesVector = new Vector JavaDoc();
798         Vector JavaDoc embeddedRarAdminObjectResourcesVector = new Vector JavaDoc();
799         for(int i=0; i< noOfAdminObjectResources; ++i) {
800             AdminObjectResource adminObjectResource = res.getAdminObjectResource(i);
801
802             // skips the admin resource if it is not referenced by the server
803
if(adminObjectResource == null || !isEnabled(adminObjectResource)
804                     || !isReferenced(adminObjectResource.getJndiName())) {
805                 continue;
806             }
807             String JavaDoc resourceAdapterName = adminObjectResource.getResAdapter();
808             if(belongToStandAloneRarAdminObjectResources(resourceAdapterName) ||
809                                           belongToSystemRar(resourceAdapterName)) {
810                 standAloneRarAdminObjectResourcesVector.add(adminObjectResource);
811             } else if(belongToEmbeddedRarAdminObjectResources(resourceAdapterName)){
812                 embeddedRarAdminObjectResourcesVector.add(adminObjectResource);
813             } else {
814                 _logger.log(Level.WARNING,"loading.wrong_adminobject_entry",
815                                               resourceAdapterName);
816             }
817         }
818
819         if(standAloneRarAdminObjectResourcesVector.size() != 0) {
820             standAloneRarAdminObjectResources = new AdminObjectResource[
821                        standAloneRarAdminObjectResourcesVector.size()];
822             for(int i=0;i<standAloneRarAdminObjectResourcesVector.size();++i) {
823                 standAloneRarAdminObjectResources[i] = (AdminObjectResource)
824                             standAloneRarAdminObjectResourcesVector.elementAt(i);
825             }
826         }
827         if(embeddedRarAdminObjectResourcesVector.size() != 0) {
828             embeddedRarAdminObjectResources = new AdminObjectResource[
829                       embeddedRarAdminObjectResourcesVector.size()];
830             for(int i=0;i<embeddedRarAdminObjectResourcesVector.size();++i) {
831                 embeddedRarAdminObjectResources[i] = (AdminObjectResource)
832                          embeddedRarAdminObjectResourcesVector.elementAt(i);
833             }
834         }
835         if(onlystandAloneRars) {
836             return standAloneRarAdminObjectResources;
837         } else {
838             return embeddedRarAdminObjectResources;
839         }
840     }
841   
842     private ConfigBean[] getFilteredConnectorResources(
843                             boolean onlystandAloneRars) throws ConfigException {
844         if( filteredConnectorResources) {
845             if(onlystandAloneRars) {
846                 return standAloneRarConnectorResources;
847             } else {
848                 return embeddedRarConnectorResources;
849
850             }
851         }
852
853         filteredConnectorResources = true;
854         int noOfConnectorResources = res.sizeConnectorResource();
855
856         if(noOfConnectorResources == 0) {
857             return null;
858         }
859
860         Vector JavaDoc standAloneRarConnectorResourcesVector = new Vector JavaDoc();
861         Vector JavaDoc embeddedRarConnectorResourcesVector = new Vector JavaDoc();
862         for(int i=0; i< noOfConnectorResources; ++i) {
863             ConnectorResource ccResource = res.getConnectorResource(i);
864             // skips if the connector resource is not referenced by server
865
if(ccResource == null || !isEnabled(ccResource)
866                     || !isReferenced(ccResource.getJndiName())) {
867                 continue;
868             }
869             String JavaDoc poolName = ccResource.getPoolName();
870             if(belongToStandAloneRarConnectorResources(poolName)) {
871                 standAloneRarConnectorResourcesVector.add(ccResource);
872             } else if(belongToEmbeddedRarConnectorResources(poolName)){
873                 embeddedRarConnectorResourcesVector.add(ccResource);
874             } else {
875                 _logger.log(Level.WARNING,"loading.wrong_resources_entry",poolName);
876             }
877         }
878         if(standAloneRarConnectorResourcesVector.size() != 0) {
879             standAloneRarConnectorResources = new ConnectorResource[
880                       standAloneRarConnectorResourcesVector.size()];
881             for(int i=0;i<standAloneRarConnectorResourcesVector.size();++i) {
882                 standAloneRarConnectorResources[i] = (ConnectorResource)
883                       standAloneRarConnectorResourcesVector.elementAt(i);
884             }
885         }
886         if(embeddedRarConnectorResourcesVector.size() != 0) {
887             embeddedRarConnectorResources = new ConnectorResource[
888                       embeddedRarConnectorResourcesVector.size()];
889             for(int i=0;i<embeddedRarConnectorResourcesVector.size();++i) {
890                 embeddedRarConnectorResources[i] = (ConnectorResource)
891                          embeddedRarConnectorResourcesVector.elementAt(i);
892             }
893         }
894         if(onlystandAloneRars) {
895             return standAloneRarConnectorResources;
896         } else {
897             return embeddedRarConnectorResources;
898         }
899
900     }
901     
902     private ConfigBean[] getFilteredConnectorConnectionPools(
903                         boolean onlystandAloneRars) throws ConfigException {
904         if( filteredConnectorConnectionPool ) {
905             if(onlystandAloneRars) {
906                 return standAloneRarConnectorConnectionPools;
907             } else {
908                 return embeddedRarConnectorConnectionPools;
909             }
910         }
911
912         filteredConnectorConnectionPool = true;
913         int noOfConnectorConnectionPools = res.sizeConnectorConnectionPool();
914
915         if(noOfConnectorConnectionPools == 0) {
916             return null;
917         }
918
919         Vector JavaDoc standAloneRarPoolsVector = new Vector JavaDoc();
920         Vector JavaDoc embeddedRarPoolsVector = new Vector JavaDoc();
921         for(int i=0; i< noOfConnectorConnectionPools; ++i) {
922             ConnectorConnectionPool ccPool = res.getConnectorConnectionPool(i);
923             // skips the pool if not referenced by the server
924
if(ccPool == null || !isEnabled(ccPool)) {
925                 continue;
926             }
927             String JavaDoc resourceAdapterName = ccPool.getResourceAdapterName();
928             if(belongToStandAloneRarConnectionPools(resourceAdapterName) ||
929                            belongToSystemRar(resourceAdapterName)) {
930                 standAloneRarPoolsVector.add(ccPool);
931             } else if(belongToEmbeddedRarConnectionPools(
932                                                resourceAdapterName)) {
933                 embeddedRarPoolsVector.add(ccPool);
934             } else {
935                 _logger.log(Level.WARNING,"loading.wrong_connectorpool_entry",
936                                  resourceAdapterName);
937             }
938         }
939         if(standAloneRarPoolsVector.size() != 0) {
940             standAloneRarConnectorConnectionPools =
941                 new ConnectorConnectionPool[standAloneRarPoolsVector.size()];
942             for(int i=0;i<standAloneRarPoolsVector.size();++i) {
943                 standAloneRarConnectorConnectionPools[i] =
944                  (ConnectorConnectionPool)standAloneRarPoolsVector.elementAt(i);
945             }
946         }
947         if(embeddedRarPoolsVector.size() != 0) {
948             embeddedRarConnectorConnectionPools =
949                 new ConnectorConnectionPool[embeddedRarPoolsVector.size()];
950             for(int i=0;i<embeddedRarPoolsVector.size();++i) {
951                 embeddedRarConnectorConnectionPools[i] =
952                   (ConnectorConnectionPool)embeddedRarPoolsVector.elementAt(i);
953             }
954         }
955         if(onlystandAloneRars) {
956             return standAloneRarConnectorConnectionPools;
957         } else {
958             return embeddedRarConnectorConnectionPools;
959         }
960     }
961
962     private boolean belongToStandAloneRarAdminObjectResources(
963                                         String JavaDoc resourceAdapterName) {
964         if(connectorModules == null || connectorModules.length == 0) {
965             return false;
966         }
967         for(int i=0; i<connectorModules.length;++i) {
968             if(resourceAdapterName.equals(connectorModules[i].getName())) {
969                 return true;
970             }
971         }
972         return false;
973     }
974
975
976     private boolean belongToEmbeddedRarAdminObjectResources(String JavaDoc resourceAdapterName) {
977         if(j2eeApps == null || j2eeApps.length==0) {
978             return false;
979         }
980         for(int i=0; i<j2eeApps.length;++i) {
981             int index = resourceAdapterName.indexOf(
982                      ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER);
983             if(index != -1) {
984                 String JavaDoc appName = resourceAdapterName.substring(0,index);
985                 if(appName.equals(j2eeApps[i].getName())) {
986                     return true;
987                 }
988             }
989         }
990         return false;
991     }
992
993     private boolean belongToStandAloneRarConnectorResources(String JavaDoc poolName) {
994         if(standAloneRarConnectorConnectionPools==null ||
995                         standAloneRarConnectorConnectionPools.length==0) {
996             return false;
997         }
998         for (int i=0; i<standAloneRarConnectorConnectionPools.length;i++) {
999             if(poolName.equals(
1000                    standAloneRarConnectorConnectionPools[i].getName())){
1001                return true;
1002            }
1003        }
1004        return false;
1005    }
1006    private boolean belongToEmbeddedRarConnectorResources(String JavaDoc poolName) {
1007        if(embeddedRarConnectorConnectionPools == null ||
1008                            embeddedRarConnectorConnectionPools.length==0) {
1009            return false;
1010        }
1011        for (int i=0; i<embeddedRarConnectorConnectionPools.length;i++) {
1012            if(poolName.equals(
1013                    embeddedRarConnectorConnectionPools[i].getName())){
1014                return true;
1015            }
1016        }
1017        return false;
1018    }
1019
1020    private boolean belongToStandAloneRarConnectionPools(
1021                    String JavaDoc resourceAdapterName) {
1022        if(connectorModules == null || connectorModules.length == 0) {
1023            return false;
1024        }
1025        for(int i=0; i<connectorModules.length;++i) {
1026            if(resourceAdapterName.equals(connectorModules[i].getName())) {
1027                return true;
1028            }
1029        }
1030        return false;
1031    }
1032
1033    public boolean belongToSystemRar(String JavaDoc resourceAdapterName) {
1034
1035        for(int i=0;i<ConnectorRuntime.systemRarNames.length;++i) {
1036            if(resourceAdapterName.equals(ConnectorRuntime.systemRarNames[i])) {
1037                return true;
1038            }
1039        }
1040        return false;
1041    }
1042                    
1043
1044    private boolean belongToEmbeddedRarConnectionPools(
1045                    String JavaDoc resourceAdapterName) {
1046        if(j2eeApps == null || j2eeApps.length==0) {
1047            return false;
1048        }
1049        for(int i=0; i<j2eeApps.length;++i) {
1050            int index = resourceAdapterName.indexOf(
1051                     ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER);
1052            if(index != -1) {
1053                String JavaDoc appName = resourceAdapterName.substring(0,index);
1054                if(appName.equals(j2eeApps[i].getName())) {
1055                    return true;
1056                }
1057            }
1058        }
1059        return false;
1060    }
1061
1062    public boolean belongToStandAloneRar(String JavaDoc resourceAdapterName){
1063        return belongToStandAloneRarConnectionPools(resourceAdapterName);
1064    }
1065
1066    public Object JavaDoc[] getConnectorResourcesJndiNames(String JavaDoc poolName) {
1067
1068        Vector JavaDoc jndiNamesVector = new Vector JavaDoc();
1069        reinitialize();
1070        ConnectorResource[] connectorResource = res.getConnectorResource();
1071        if (connectorResource == null || connectorResource.length == 0) {
1072            return null;
1073        }
1074
1075        for(int i=0; i<connectorResource.length; ++ i) {
1076            if(connectorResource[i].getPoolName().equals(poolName)) {
1077                jndiNamesVector.add(connectorResource[i].getJndiName());
1078            }
1079
1080        }
1081        return jndiNamesVector.toArray();
1082    }
1083
1084    public Object JavaDoc[] getConnectorConnectionPoolNames(String JavaDoc moduleName) {
1085        reinitialize();
1086        Vector JavaDoc poolNamesVector = new Vector JavaDoc();
1087        ConnectorConnectionPool[] connectorConnectionPool=
1088                res.getConnectorConnectionPool();
1089        if (connectorConnectionPool== null
1090               || connectorConnectionPool.length == 0) {
1091          return null;
1092        }
1093
1094        for(int i=0; i<connectorConnectionPool.length; ++ i) {
1095            if(connectorConnectionPool[i].getResourceAdapterName().equals(
1096                            moduleName)) {
1097              poolNamesVector.add(connectorConnectionPool[i].getName());
1098            }
1099        }
1100        return poolNamesVector.toArray();
1101    }
1102
1103    public ConnectorConnectionPool[] getConnectorConnectionPools() {
1104        reinitialize();
1105        ConnectorConnectionPool[] connectorConnectionPool = null;
1106        connectorConnectionPool = res.getConnectorConnectionPool();
1107        if (connectorConnectionPool.length == 0) {
1108            return null;
1109        } else {
1110            return connectorConnectionPool;
1111        }
1112    }
1113
1114    public JdbcConnectionPool[] getJdbcConnectionPools() {
1115        reinitialize();
1116        JdbcConnectionPool[] jdbcConnectionPool = res.getJdbcConnectionPool();
1117        if(jdbcConnectionPool == null) return null;
1118        if (jdbcConnectionPool.length == 0) {
1119            return null;
1120        } else {
1121            return jdbcConnectionPool;
1122        }
1123    }
1124
1125    public String JavaDoc[] getdbUserPasswordOfJdbcConnectionPool(
1126                  JdbcConnectionPool jdbcConnectionPool) {
1127
1128        String JavaDoc[] userPassword = new String JavaDoc[2];
1129        userPassword[0]=null;
1130        userPassword[1]=null;
1131        ElementProperty[] elementProperty =
1132                 jdbcConnectionPool.getElementProperty();
1133        if(elementProperty==null || elementProperty.length == 0) {
1134            return userPassword;
1135        }
1136
1137        for (int i=0; i<elementProperty.length;i++) {
1138        String JavaDoc prop = elementProperty[i].getName().toUpperCase();
1139            if ("USERNAME".equals( prop ) || "USER".equals( prop ) ) {
1140                userPassword[0]=elementProperty[i].getValue();
1141            } else if("PASSWORD".equals( prop ) ) {
1142                userPassword[1]=elementProperty[i].getValue();
1143            }
1144        }
1145        return userPassword;
1146    }
1147 
1148    public String JavaDoc[] getdbUserPasswordOfConnectorConnectionPool(
1149                  ConnectorConnectionPool connectorConnectionPool) {
1150
1151        String JavaDoc[] userPassword = new String JavaDoc[2];
1152        userPassword[0]=null;
1153        userPassword[1]=null;
1154        ElementProperty[] elementProperty =
1155                 connectorConnectionPool.getElementProperty();
1156        if(elementProperty != null && elementProperty.length != 0) {
1157            boolean foundUserPassword = false;
1158            for (int i=0; i<elementProperty.length;i++) {
1159            String JavaDoc prop = elementProperty[i].getName().toUpperCase();
1160
1161                if( "USERNAME".equals( prop ) || "USER".equals( prop ) ) {
1162                    userPassword[0]=elementProperty[i].getValue();
1163                    foundUserPassword = true;
1164                } else if("PASSWORD".equals( prop ) ) {
1165                    userPassword[1]=elementProperty[i].getValue();
1166                    foundUserPassword = true;
1167                }
1168            }
1169            if(foundUserPassword == true) {
1170                return userPassword;
1171            }
1172        }
1173
1174    String JavaDoc poolName = connectorConnectionPool.getName();
1175        String JavaDoc rarName = connectorConnectionPool.getResourceAdapterName();
1176        String JavaDoc connectionDefName =
1177                 connectorConnectionPool.getConnectionDefinitionName();
1178        ConnectorRegistry connectorRegistry =
1179                    ConnectorRegistry.getInstance();
1180        ConnectorDescriptor connectorDescriptor =
1181                    connectorRegistry.getDescriptor(rarName);
1182        ConnectionDefDescriptor cdd =
1183                    connectorDescriptor.getConnectionDefinitionByCFType(
1184                    connectionDefName);
1185        Set JavaDoc configProps = cdd.getConfigProperties();
1186        for(Iterator JavaDoc iter = configProps.iterator(); iter.hasNext();) {
1187            EnvironmentProperty envProp= (EnvironmentProperty)iter.next();
1188        String JavaDoc prop = envProp.getName().toUpperCase();
1189        
1190            if("USER".equals( prop ) || "USERNAME".equals( prop )) {
1191                
1192                    userPassword[0]=envProp.getValue();
1193            } else if( "PASSWORD".equals(prop) ) {
1194                    userPassword[1]=envProp.getValue();
1195            }
1196
1197        }
1198
1199    if ( userPassword[0] != null && ! "".equals(userPassword[0].trim()) ) {
1200            return userPassword;
1201    }
1202
1203    //else read the default username and password from the ra.xml
1204
ManagedConnectionFactory JavaDoc mcf =
1205        connectorRegistry.getManagedConnectionFactory( poolName );
1206    userPassword[0] = ConnectionPoolObjectsUtils.getValueFromMCF(
1207        "UserName", poolName, mcf);
1208    userPassword[1] = ConnectionPoolObjectsUtils.getValueFromMCF(
1209        "Password", poolName, mcf);
1210
1211    return userPassword;
1212    }
1213
1214    public void deleteConnectorResources(String JavaDoc poolname)
1215                   throws ConfigException{
1216        ConnectorResource[] connectorResource = res.getConnectorResource();
1217        if (connectorResource == null || connectorResource.length == 0) {
1218            return;
1219        }
1220
1221        for(int i=0; i<connectorResource.length; ++ i) {
1222            if(connectorResource[i].getPoolName().equals(poolname)) {
1223                res.removeConnectorResource(connectorResource[i]);
1224                configContext_.flush();
1225            }
1226        }
1227    }
1228
1229    public void deleteConnectorConnectionPool(String JavaDoc moduleName)
1230                 throws ConfigException{
1231
1232        ConnectorConnectionPool[] connectorConnectionPool =
1233                 res.getConnectorConnectionPool();
1234
1235        if (connectorConnectionPool == null
1236                 || connectorConnectionPool.length == 0) {
1237            return ;
1238        }
1239        for(int i=0; i<connectorConnectionPool.length;++i) {
1240            if(connectorConnectionPool[i].getResourceAdapterName().equals(
1241                       moduleName)){
1242                res.removeConnectorConnectionPool(connectorConnectionPool[i]);
1243                configContext_.flush();
1244            }
1245        }
1246    }
1247
1248    public String JavaDoc getResourceType(ConfigBean cb) {
1249        if(cb instanceof ConnectorConnectionPool) {
1250           return ResourceDeployEvent.RES_TYPE_CCP;
1251        } else if(cb instanceof ConnectorResource) {
1252           return ResourceDeployEvent.RES_TYPE_CR;
1253        } else if(cb instanceof AdminObjectResource) {
1254           return ResourceDeployEvent.RES_TYPE_AOR;
1255        } else if(cb instanceof ResourceAdapterConfig) {
1256           return ResourceDeployEvent.RES_TYPE_RAC;
1257        } else if (cb instanceof JdbcConnectionPool) {
1258       return ResourceDeployEvent.RES_TYPE_JCP;
1259        } else if (cb instanceof JdbcResource) {
1260       return ResourceDeployEvent.RES_TYPE_JDBC;
1261        }
1262        return null;
1263
1264    }
1265
1266    public ResourceDeployer getResourceDeployer(String JavaDoc type)
1267                           throws Exception JavaDoc {
1268
1269        ResourceDeployerFactory factory = new ResourceDeployerFactory();
1270        return factory.getResourceDeployer(type);
1271    }
1272
1273 
1274    public void writeSunConnector(ConnectorDescriptor connectorDescriptor,
1275                String JavaDoc rarName, String JavaDoc poolName) throws ConfigException{
1276
1277        configContext_ = sc_.getConfigContext();
1278        dom = ServerBeansFactory.getDomainBean(configContext_);
1279        res = dom.getResources();
1280       
1281        ConnectorConnectionPool connectorConnectionPool = getConnectionPoolObj(
1282                   connectorDescriptor);
1283        connectorConnectionPool.setName(poolName);
1284        connectorConnectionPool.setResourceAdapterName(rarName);
1285
1286        ConnectorConnectionPool existingPool =
1287                   res.getConnectorConnectionPoolByName(poolName);
1288        if(existingPool != null) {
1289            res.removeConnectorConnectionPool(existingPool);
1290            configContext_.flush();
1291        }
1292        res.addConnectorConnectionPool(connectorConnectionPool);
1293        
1294        configContext_.flush();
1295
1296        String JavaDoc jndiName = (String JavaDoc)connectorDescriptor.getSunDescriptor().
1297                  getResourceAdapter().getValue(ResourceAdapter.JNDI_NAME);
1298
1299        ConnectorResource connectorResource = getConnectorResource(
1300                  poolName,jndiName);
1301        ConnectorResource existingConnectorResource =
1302                  res.getConnectorResourceByJndiName(jndiName);
1303        if(existingConnectorResource != null) {
1304            res.removeConnectorResource(existingConnectorResource);
1305            configContext_.flush();
1306        }
1307        res.addConnectorResource(connectorResource);
1308        configContext_.flush();
1309    }
1310
1311    private ConnectorResource getConnectorResource(String JavaDoc poolName,
1312                    String JavaDoc jndiName) {
1313
1314        ConnectorResource connectorResource = new ConnectorResource();
1315
1316        connectorResource.setJndiName(jndiName);
1317        connectorResource.setPoolName(poolName);
1318        return connectorResource;
1319
1320    }
1321
1322    private ConnectorConnectionPool getConnectionPoolObj(
1323                ConnectorDescriptor connectorDescriptor) {
1324        String JavaDoc connectiondefName = connectorDescriptor.
1325                getOutboundResourceAdapter().getConnectionFactoryIntf();
1326        SunConnector sunConnector = connectorDescriptor.getSunDescriptor();
1327        ResourceAdapter sunRAXML = sunConnector.getResourceAdapter();
1328        ConnectorConnectionPool connectorConnectionPool =
1329                new ConnectorConnectionPool();
1330        connectorConnectionPool.setConnectionDefinitionName(connectiondefName);
1331        connectorConnectionPool.setSteadyPoolSize(
1332                (String JavaDoc)sunRAXML.getValue(ResourceAdapter.STEADY_POOL_SIZE));
1333        connectorConnectionPool.setMaxPoolSize(
1334                (String JavaDoc)sunRAXML.getValue(ResourceAdapter.MAX_POOL_SIZE));
1335        connectorConnectionPool.setMaxWaitTimeInMillis(
1336           (String JavaDoc)sunRAXML.getValue(ResourceAdapter.MAX_WAIT_TIME_IN_MILLIS));
1337        connectorConnectionPool.setPoolResizeQuantity("2");
1338        connectorConnectionPool.setIdleTimeoutInSeconds(
1339           (String JavaDoc)sunRAXML.getValue(ResourceAdapter.IDLE_TIMEOUT_IN_SECONDS));
1340        connectorConnectionPool.setFailAllConnections(false);
1341        return connectorConnectionPool;
1342    }
1343
1344    public String JavaDoc getLocation(String JavaDoc moduleName) {
1345
1346        if(moduleName == null) {
1347            return null;
1348        }
1349        reinitialize();
1350        String JavaDoc location = null;
1351        ConnectorModule connectorModule =
1352              dom.getApplications().getConnectorModuleByName(moduleName);
1353        if(connectorModule != null) {
1354            location = connectorModule.getLocation();
1355        }
1356        return location;
1357
1358    }
1359
1360    public ConfigBean[][] getJdbcResources() throws ConfigException{
1361
1362        ConfigBean configBeanArray[][] =
1363                        new ConfigBean[NO_OF_JDBC_RESOURCE_TYPE][];
1364        // returns only the associated jdbc connection pools
1365
JdbcConnectionPool[] jcp = res.getJdbcConnectionPool();
1366        configBeanArray[0] = getReferencedBeans(jcp, NAME_METHOD);
1367
1368        // returns only the associated jdbc resources
1369
JdbcResource[] jr = res.getJdbcResource();
1370        configBeanArray[1] = getReferencedJdbcResourceBeans(jr, JNDI_METHOD);
1371
1372        return configBeanArray;
1373    }
1374
1375    /**
1376     * Returns true if the given resource is referenced by this server.
1377     *
1378     * @param resourceName the name of the resource
1379     *
1380     * @return true if the named resource is used/referred by this server
1381     *
1382     * @throws ConfigException if an error while parsing domain.xml
1383     */

1384    protected boolean isReferenced(String JavaDoc resourceName) throws ConfigException {
1385        if (_logger.isLoggable(Level.FINE)) {
1386            _logger.fine("isReferenced :: " + resourceName + " - "
1387                            + ServerHelper.serverReferencesResource(
1388                                  configContext_, sc_.getInstanceName(),
1389                                  resourceName));
1390        }
1391        
1392        return ServerHelper.serverReferencesResource(configContext_,
1393            sc_.getInstanceName(), resourceName);
1394    }
1395    
1396    /**
1397     * Returns an array of beans that are associated to this server instance.
1398     *
1399     * @param beans array of config beans representing the resources
1400     * @param methodName name of the method name to invoke to get the
1401     * resource name. Example, getJndiName, getName, etc.
1402     *
1403     * @return an array of beans that are associated to this server instance
1404     */

1405    private ConfigBean[] getReferencedBeans(ConfigBean[] beans,
1406            String JavaDoc methodName) {
1407
1408        ArrayList JavaDoc list = new ArrayList JavaDoc();
1409
1410        for (int i=0; i<beans.length; i++) {
1411
1412            try {
1413                String JavaDoc name = null;
1414
1415                if (methodName != null) {
1416                    Class JavaDoc c = beans[i].getClass();
1417                    Method JavaDoc m = c.getDeclaredMethod(methodName, (java.lang.Class JavaDoc[])null);
1418                    name = (String JavaDoc) m.invoke(beans[i], (java.lang.Object JavaDoc[])null);
1419                }
1420
1421                if (isReferenced(name)) {
1422                    list.add(beans[i]);
1423                }
1424            } catch (Exception JavaDoc e) {
1425                _logger.log(Level.WARNING, "isReferenced.unexpectedException", e);
1426            }
1427        }
1428        // returns an array of beans referenced by this server
1429
ConfigBean[] refList = new ConfigBean[list.size()];
1430
1431        return ( (ConfigBean[]) list.toArray(refList) );
1432    }
1433
1434    public boolean isEnabled(ConnectorResource cr) throws ConfigException {
1435        reinitialize();
1436        if(cr == null ) {
1437            return false;
1438        } else {
1439            //Since AS 8.1 PE/SE/EE resources must be referenced and their references
1440
//must be enabled as well.
1441
_logger.fine("ResourcesUtil :: isEnabled " + cr);
1442            boolean resRef = isReferenced(cr.getJndiName());
1443            _logger.fine("ResourcesUtil :: is Referenced" + resRef);
1444            boolean isResRefEnabled = isResourceReferenceEnabled(cr.getJndiName());
1445            _logger.fine("isResRefEnabled " + isResRefEnabled);
1446            if (! (cr.isEnabled() && resRef && isResRefEnabled )) return false;
1447        }
1448        
1449        String JavaDoc poolName = cr.getPoolName();
1450        ConnectorConnectionPool ccp = res.getConnectorConnectionPoolByName(poolName);
1451        if (ccp == null) {
1452            return false;
1453        }
1454        String JavaDoc raName = ccp.getResourceAdapterName();
1455        ConnectorModule module = dom.getApplications().getConnectorModuleByName(raName);
1456        if(module != null) {
1457            return module.isEnabled();
1458        } else if(belongToSystemRar(raName)) {
1459            return true;
1460        } else {
1461            return belongToEmbeddedRarAndEnabled(raName);
1462        }
1463    }
1464
1465    public boolean isEnabled(AdminObjectResource aot) throws ConfigException {
1466        reinitialize();
1467        if(aot == null) {
1468            return false;
1469        } else {
1470            //Since AS 8.1 PE/SE/EE resources must be referenced and their references
1471
//must be enabled as well.
1472
boolean resRef = isReferenced(aot.getJndiName());
1473            boolean isResRefEnabled = isResourceReferenceEnabled(aot.getJndiName());
1474            if (! (aot.isEnabled() && resRef && isResRefEnabled )) return false;
1475        }
1476        
1477        String JavaDoc raName = aot.getResAdapter();
1478        ConnectorModule module = dom.getApplications().getConnectorModuleByName(raName);
1479        if(module != null) {
1480            return module.isEnabled();
1481        } else if(belongToSystemRar(raName)){
1482            return true;
1483        } else {
1484            return belongToEmbeddedRarAndEnabled(raName);
1485        }
1486    }
1487
1488    public boolean isEnabled(ConnectorConnectionPool ccp) {
1489        if(ccp == null) {
1490            return false;
1491        }
1492        reinitialize();
1493        String JavaDoc raName = ccp.getResourceAdapterName();
1494        ConnectorModule module = dom.getApplications().getConnectorModuleByName(raName);
1495        if(module != null) {
1496            return module.isEnabled();
1497        } else if(belongToSystemRar(raName)) {
1498            return true;
1499        } else {
1500            return belongToEmbeddedRarAndEnabled(raName);
1501        }
1502    }
1503    
1504    public boolean belongToRar(String JavaDoc rarName,ConnectorConnectionPool ccp) {
1505        if(ccp == null || rarName== null) {
1506            return false;
1507        }
1508        if(ccp.getResourceAdapterName().equals(rarName)) {
1509            return true;
1510        } else {
1511            return false;
1512        }
1513    }
1514    public boolean belongToRar(String JavaDoc rarName,ConnectorResource cr) {
1515        if(cr == null || rarName== null) {
1516            return false;
1517        }
1518        reinitialize();
1519        String JavaDoc poolName = cr.getPoolName();
1520        ConnectorConnectionPool ccp = res.getConnectorConnectionPoolByName(poolName);
1521        if (ccp == null) {
1522            return false;
1523        }
1524        if(ccp.getResourceAdapterName().equals(rarName)) {
1525            return true;
1526        } else {
1527            return false;
1528        }
1529    }
1530
1531    public boolean belongToRar(String JavaDoc rarName,AdminObjectResource aor) {
1532        if(aor == null || rarName== null) {
1533            return false;
1534        }
1535        if(aor.getResAdapter().equals(rarName)) {
1536            return true;
1537        } else {
1538            return false;
1539        }
1540    }
1541    private boolean belongToEmbeddedRarAndEnabled(
1542                    String JavaDoc resourceAdapterName) {
1543        reinitialize();
1544        Applications apps = dom.getApplications();
1545        J2eeApplication[] j2eeApps = apps.getJ2eeApplication();
1546        if(j2eeApps == null || j2eeApps.length==0) {
1547            return false;
1548        }
1549        for(int i=0; i<j2eeApps.length;++i) {
1550            int index = resourceAdapterName.indexOf(
1551                     ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER);
1552            if(index != -1) {
1553                String JavaDoc appName = resourceAdapterName.substring(0,index);
1554                if(appName.equals(j2eeApps[i].getName()) && j2eeApps[i].isEnabled()) {
1555                    return true;
1556                }
1557            }
1558        }
1559        return false;
1560    }
1561
1562    public String JavaDoc[] listConnectorModuleNames() {
1563
1564        reinitialize();
1565        Applications apps = dom.getApplications();
1566        ConnectorModule[] connectorModules = null;
1567        String JavaDoc[] connectorModuleNames = null;
1568        if(apps != null) {
1569            connectorModules = apps.getConnectorModule();
1570        }
1571        if(connectorModules != null) {
1572            connectorModuleNames = new String JavaDoc[connectorModules.length];
1573            for(int i=0;connectorModules != null && i<connectorModules.length;
1574                                ++i){
1575                connectorModuleNames[i] = connectorModules[i].getName();
1576            }
1577        }
1578        return connectorModuleNames;
1579    }
1580
1581    public boolean belongToEmbeddedRar(
1582                    String JavaDoc resourceAdapterName) {
1583        reinitialize();
1584        J2eeApplication[] j2eeApps = null;
1585        j2eeApps = apps.getJ2eeApplication();
1586        if(j2eeApps == null || j2eeApps.length==0) {
1587            return false;
1588        }
1589        for(int i=0; i<j2eeApps.length;++i) {
1590            int index = resourceAdapterName.indexOf(
1591                     ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER);
1592            if(index != -1) {
1593                String JavaDoc appName = resourceAdapterName.substring(0,index);
1594                if(appName.equals(j2eeApps[i].getName())) {
1595                    return true;
1596                }
1597            }
1598        }
1599        return false;
1600    }
1601
1602    /**
1603      * This method takes in an admin JdbcConnectionPool and returns the RA
1604      * that it belongs to.
1605      *
1606      * @param pool - The pool to check
1607      * @return The name of the JDBC RA that provides this pool's datasource
1608      *
1609      */

1610
1611    public String JavaDoc getRAForJdbcConnectionPool( JdbcConnectionPool pool ) {
1612        String JavaDoc dsRAName = ConnectorConstants.JDBCDATASOURCE_RA_NAME;
1613
1614        if ( pool.getResType() == null ) {
1615             return dsRAName;
1616        }
1617
1618        //check if its XA
1619
if ( "javax.sql.XADataSource".equals( pool.getResType() ) ) {
1620            if ( pool.getDatasourceClassname() == null ) {
1621                return dsRAName;
1622            }
1623            try {
1624                Class JavaDoc dsClass=Utility.loadClass(pool.getDatasourceClassname());
1625                if (javax.sql.XADataSource JavaDoc.class.isAssignableFrom(dsClass)) {
1626                     return ConnectorConstants.JDBCXA_RA_NAME;
1627                }
1628            } catch( ClassNotFoundException JavaDoc cnfe) {
1629                return dsRAName;
1630            }
1631         }
1632
1633         //check if its CP
1634
if ("javax.sql.ConnectionPoolDataSource".equals(pool.getResType())) {
1635             if ( pool.getDatasourceClassname() == null ) {
1636                 return dsRAName;
1637             }
1638             try {
1639                 Class JavaDoc dsClass=Utility.loadClass(pool.getDatasourceClassname());
1640                 if(javax.sql.ConnectionPoolDataSource JavaDoc.class.isAssignableFrom(
1641                                           dsClass) ) {
1642                     return
1643                       ConnectorConstants.JDBCCONNECTIONPOOLDATASOURCE_RA_NAME;
1644                 }
1645             } catch( ClassNotFoundException JavaDoc cnfe) {
1646                 return dsRAName;
1647             }
1648         }
1649         //default to __ds
1650
return dsRAName;
1651     }
1652   
1653    public ConnectorResource[] getAllJmsResources() {
1654        reinitialize();
1655        ConnectorResource[] cr = res.getConnectorResource();
1656        
1657        Vector JavaDoc vector = new Vector JavaDoc();
1658        for(int i=0;cr != null && i<cr.length;++i) {
1659            if(belongToRar(ConnectorConstants.DEFAULT_JMS_ADAPTER,cr[i])) {
1660                vector.add(cr[i]);
1661            }
1662        }
1663        return (ConnectorResource[]) vector.toArray();
1664    }
1665    
1666    /**
1667     * Gets the shutdown-timeout attribute from domain.xml
1668     * via the connector server config bean.
1669     * @return
1670     */

1671    public int getShutdownTimeout() throws ConnectorRuntimeException {
1672        try {
1673            ConnectorService connectorServiceElement = ServerBeansFactory
1674            .getConnectorServiceBean(ApplicationServer.getServerContext().
1675                    getConfigContext());
1676            int shutdownTimeout;
1677            if (connectorServiceElement == null) {
1678                //Connector service element is not specified in
1679
//domain.xml and hence going with the default time-out
1680
shutdownTimeout =
1681                    ConnectorConstants.DEFAULT_RESOURCE_ADAPTER_SHUTDOWN_TIMEOUT;
1682                _logger.log(Level.FINE, "Shutdown timeout set to "
1683                        + shutdownTimeout
1684                        + "through default");
1685               return shutdownTimeout;
1686            } else {
1687                shutdownTimeout = (new Integer JavaDoc(connectorServiceElement.
1688                        getShutdownTimeoutInSeconds())).intValue();
1689                _logger.log(Level.FINE, "Shutdown timeout set to "
1690                        + shutdownTimeout + " from domain.xml");
1691                return shutdownTimeout;
1692            }
1693        } catch (Exception JavaDoc e) {
1694            ConnectorRuntimeException crex = new ConnectorRuntimeException(e.getMessage());
1695            crex.initCause(e);
1696            throw crex;
1697        }
1698    }
1699
1700     /**
1701      * Returns an array of beans that are associated to this server instance.
1702      *
1703      * @param beans array of config beans representing the Jdbc resources
1704      * @param methodName name of the method name to invoke to get the
1705      * resource name. Example, getJndiName, getName, etc.
1706      *
1707      * @return an array of beans that are associated to this server instance
1708      */

1709     private ConfigBean[] getReferencedJdbcResourceBeans(JdbcResource[] beans,
1710             String JavaDoc methodName) {
1711
1712        ArrayList JavaDoc list = new ArrayList JavaDoc();
1713
1714        for (int i=0; i<beans.length; i++) {
1715
1716            try {
1717                String JavaDoc name = null;
1718
1719                if (methodName != null) {
1720                    Class JavaDoc c = beans[i].getClass();
1721                    Method JavaDoc m = c.getDeclaredMethod(methodName, (java.lang.Class JavaDoc[])null);
1722                    name = (String JavaDoc) m.invoke(beans[i], (java.lang.Object JavaDoc[])null);
1723                }
1724
1725                if (isReferenced(name)) {
1726                    list.add(beans[i]);
1727                }
1728            } catch (Exception JavaDoc e) {
1729                _logger.log(Level.WARNING, "isReferenced.unexpectedException", e);
1730            }
1731        }
1732        // returns an array of beans referenced by this server
1733
JdbcResource[] refList = new JdbcResource[list.size()];
1734
1735        return ( (JdbcResource[]) list.toArray(refList) );
1736    }
1737    
1738     /**
1739      * Returns an array of beans that are associated to this server instance.
1740      *
1741      * @param beans array of config beans representing the Connector resources
1742      * @param methodName name of the method name to invoke to get the
1743      * resource name. Example, getJndiName, getName, etc.
1744      *
1745      * @return an array of beans that are associated to this server instance
1746      */

1747     private ConfigBean[] getReferencedConnectorResourceBeans(ConnectorResource[] beans,
1748             String JavaDoc methodName) {
1749
1750        ArrayList JavaDoc list = new ArrayList JavaDoc();
1751
1752        for (int i=0; i<beans.length; i++) {
1753
1754            try {
1755                String JavaDoc name = null;
1756
1757                if (methodName != null) {
1758                    Class JavaDoc c = beans[i].getClass();
1759                    Method JavaDoc m = c.getDeclaredMethod(methodName, (java.lang.Class JavaDoc[])null);
1760                    name = (String JavaDoc) m.invoke(beans[i], (java.lang.Object JavaDoc[])null);
1761                }
1762
1763                if (isReferenced(name)) {
1764                    list.add(beans[i]);
1765                }
1766            } catch (Exception JavaDoc e) {
1767                _logger.log(Level.WARNING, "isReferenced.unexpectedException", e);
1768            }
1769        }
1770        // returns an array of beans referenced by this server
1771
ConnectorResource[] refList = new ConnectorResource[list.size()];
1772
1773        return ( (ConnectorResource[]) list.toArray(refList) );
1774    }
1775
1776
1777    public static boolean isDAS() {
1778        try {
1779        return ServerHelper.isDAS( com.sun.enterprise.admin.server.core.AdminService.getAdminService().getAdminContext().getAdminConfigContext(), sc_.getInstanceName() );
1780    } catch( ConfigException ce ) {
1781        //better be more restrictive by returning false
1782
return false;
1783    }
1784    }
1785
1786    
1787    /**
1788     * Determines if a connector connection pool is referred in a
1789     * server-instance via resource-refs
1790     *
1791     * @param poolName
1792     * @return boolean true if pool is referred in this server instance, false
1793     * otherwise
1794     * @throws ConfigException
1795     */

1796    public boolean isPoolReferredInServerInstance(String JavaDoc poolName)
1797                                        throws ConfigException {
1798        reinitialize();
1799        ConnectorResource[] connRes = res.getConnectorResource();
1800        
1801        for (int i = 0; i < connRes.length; i++) {
1802            _logger.fine("poolname " + connRes[i].getPoolName()
1803                            + "resource " + connRes[i].getJndiName());
1804            
1805            if ((connRes[i].getPoolName().equalsIgnoreCase(poolName))){
1806                _logger.fine("Connector resource " + connRes[i].getJndiName() +
1807                                "refers " + poolName + "in this server instance");
1808                return true;
1809            }
1810        }
1811        
1812        _logger.fine("No JDBC resource refers " + poolName
1813                        + "in this server instance");
1814        return false;
1815    }
1816
1817    /**
1818     * Determines if a JDBC connection pool is referred in a
1819     * server-instance via resource-refs
1820     *
1821     * @param jdbcPoolName
1822     * @return boolean true if pool is referred in this server instance, false
1823     * otherwise
1824     * @throws ConfigException
1825     */

1826    public boolean isJdbcPoolReferredInServerInstance(String JavaDoc jdbcPoolName)
1827                                        throws ConfigException {
1828        reinitialize();
1829        JdbcResource[] jdbcRes = res.getJdbcResource();
1830        
1831        for (int i = 0; i < jdbcRes.length; i++) {
1832            _logger.fine("poolname " + jdbcRes[i].getPoolName()
1833                            + "resource " + jdbcRes[i].getJndiName()
1834                            + " referred " + isReferenced(jdbcRes[i].getJndiName()));
1835            //Have to check isReferenced here!
1836
if ((jdbcRes[i].getPoolName().equalsIgnoreCase(jdbcPoolName))
1837                            && isReferenced(jdbcRes[i].getJndiName())){
1838                _logger.fine("JDBC resource " + jdbcRes[i].getJndiName() +
1839                            "refers " + jdbcPoolName + "in this server instance");
1840                return true;
1841            }
1842        }
1843        _logger.fine("No JDBC resource refers " + jdbcPoolName +
1844                        "in this server instance");
1845        return false;
1846    }
1847
1848    /**
1849     * Gets the list of applications deployed.
1850     * @param none
1851     * @return Application[] of deloyed applications.
1852     */

1853    
1854    public Application[] getDeployedApplications() throws ConfigException{
1855        reinitialize();
1856        
1857        _logger.log(Level.FINE, "in ResourcesUtil.getApplicationNames()");
1858        
1859        // Get list of deployed "Applications"
1860
Applications apps = dom.getApplications();
1861        // From Applications, get the J2ee Applications and ejb modules
1862
J2eeApplication[] j2ee_apps = apps.getJ2eeApplication();
1863        EjbModule[] ejb_modules = apps.getEjbModule();
1864        
1865        // This array would contain the deployment descriptors of all the
1866
// ejbmodules and aplications.
1867
ArrayList JavaDoc deployedAppsDescriptorList = new ArrayList JavaDoc();
1868        
1869        if ((j2ee_apps.length + ejb_modules.length) == 0)
1870            return (new Application[] {});
1871        
1872        // Get the respective Managers to retrieve Deployment descriptors
1873
AppsManager appsManager = getAppsManager();
1874        EjbModulesManager ejbModulesManager = getEjbModulesManager();
1875
1876        // Get Deployment desc for J2EE apps.
1877
for (int i=0; i<j2ee_apps.length; i++){
1878            String JavaDoc appName = j2ee_apps[i].getName();
1879            // Check if the application is referenced by the server instance on
1880
// which recovery is happening.
1881
if (!(ServerHelper.serverReferencesApplication(configContext_, sc_.getInstanceName(), appName) ))
1882                continue;
1883            
1884            try{
1885            Application appDescriptor =
1886                appsManager.getAppDescriptor(appName,
1887                                            ASClassLoaderUtil.getSharedClassLoader());
1888            deployedAppsDescriptorList.add(appDescriptor);
1889            } catch (Exception JavaDoc e){
1890                _logger.log(Level.WARNING, "Exception while getting " +
1891                        "Application DD from AppsManager" + e.getMessage());
1892            }
1893        }
1894        
1895        // Get deployment desc for EJB modules.
1896
for (int i=0; i<ejb_modules.length; i++){
1897            String JavaDoc modName = ejb_modules[i].getName();
1898            
1899            if (!(ServerHelper.serverReferencesApplication(configContext_, sc_.getInstanceName(), modName) ))
1900                continue;
1901            
1902            try{
1903            Application appDescriptor =
1904                ejbModulesManager.getDescriptor(modName,
1905                                                ASClassLoaderUtil.getSharedClassLoader());
1906            deployedAppsDescriptorList.add(appDescriptor);
1907            } catch (Exception JavaDoc e){
1908                _logger.log(Level.WARNING, "Exception while getting " +
1909                        "Application DD from EjbModuleManager" + e.getMessage());
1910            }
1911        }
1912        
1913        return (Application[])(deployedAppsDescriptorList.toArray(new Application[] {}));
1914        
1915        }
1916        
1917    public ConnectorDescriptor getConnectorDescriptorFromUri(String JavaDoc appName, String JavaDoc raLoc)
1918    throws ConfigException{
1919        AppsManager am = getAppsManager();
1920        Application app = am.getAppDescriptor(appName,
1921                                               ASClassLoaderUtil.getSharedClassLoader());
1922        return app.getRarDescriptorByUri(raLoc);
1923    }
1924    
1925    
1926    private AppsManager getAppsManager() throws ConfigException{
1927        InstanceEnvironment iEnv = sc_.getInstanceEnvironment();
1928        return InstanceFactory.createAppsManager(iEnv, false);
1929    }
1930    
1931    private EjbModulesManager getEjbModulesManager() throws ConfigException{
1932        InstanceEnvironment iEnv = sc_.getInstanceEnvironment();
1933        return InstanceFactory.createEjbModuleManager(iEnv, false);
1934    }
1935    
1936    
1937    /**
1938     * Gets the deployment location for a J2EE application.
1939     * @param rarName
1940     * @return
1941     */

1942    public String JavaDoc getApplicationDeployLocation(String JavaDoc appName) {
1943        reinitialize();
1944        J2eeApplication app = dom.getApplications().getJ2eeApplicationByName(appName);
1945        return RelativePathResolver.resolvePath(app.getLocation());
1946    }
1947
1948    protected Resources getResourcesServerBean() {
1949        return this.res;
1950    }
1951    
1952
1953    /**
1954     * Checks if a resource reference is enabled
1955     * @since SJSAS 8.1 PE/SE/EE
1956     */

1957    private boolean isResourceReferenceEnabled(String JavaDoc resourceName)
1958                        throws ConfigException {
1959        ResourceRef ref = ServerHelper.getServerByName( configContext_,
1960                        sc_.getInstanceName()).getResourceRefByRef(resourceName);
1961        //@todo ref would be null only when call from deployers?
1962
if (ref == null) {
1963            _logger.fine("ResourcesUtil :: isResourceReferenceEnabled null ref");
1964            return true;
1965        }
1966        _logger.fine("ResourcesUtil :: isResourceReferenceEnabled ref enabled ?" + ref.isEnabled());
1967        return ref.isEnabled();
1968    }
1969
1970    public boolean isEnabled(ConfigBean res) throws ConfigException{
1971        //If no config context use application server's server config context
1972
return isEnabled(ApplicationServer.getServerContext().getConfigContext(), res);
1973    }
1974
1975    /**
1976     * Checks if a Resource is enabled.
1977     *
1978     * Since 8.1 PE/SE/EE, A resource [except resource adapter configs, connector and
1979     * JDBC connection pools which are global and hence enabled always] is enabled
1980     * only when the resource is enabled and there exists a resource ref to this
1981     * resource in this server instance and that resource ref is enabled.
1982     *
1983     * Before a resource is loaded or deployed, it is checked to see if it is
1984     * enabled.
1985     *
1986     * @since 8.1 PE/SE/EE
1987     */

1988    public boolean isEnabled(ConfigContext config, ConfigBean res)
1989                throws ConfigException{
1990        _logger.fine("ResourcesUtil :: isEnabled");
1991        if (res instanceof ResourceAdapterConfig ||
1992                        res instanceof ConnectorConnectionPool ||
1993                        res instanceof JdbcConnectionPool) {
1994            boolean enabled = (res!=null && res.isEnabled());
1995            _logger.fine("ResourcesUtil :: isEnabled " + res +
1996                            " is pool/config - enabled :" + enabled);
1997            return enabled;
1998        }
1999        
2000        Server server = ServerBeansFactory.getServerBean(config);
2001        //using ServerTags, otherwise have to resort to reflection or multiple instanceof/casts
2002
ResourceRef resRef = server.getResourceRefByRef(res.getAttributeValue(ServerTags.JNDI_NAME));
2003
2004        boolean enabled = ((res != null && res.isEnabled()) &&
2005                    (resRef != null && resRef.isEnabled()));
2006        _logger.fine("ResourcesUtil :: isEnabled " + res +
2007                        " is resource - enabled :" + enabled);
2008        return enabled;
2009    }
2010
2011    
2012    public com.sun.enterprise.config.serverbeans.JdbcConnectionPool
2013        getJdbcConnectionPoolByName( String JavaDoc poolName ) {
2014        reinitialize();
2015    return res.getJdbcConnectionPoolByName( poolName );
2016    }
2017     
2018    public com.sun.enterprise.config.serverbeans.ConnectorConnectionPool
2019        getConnectorConnectionPoolByName( String JavaDoc poolName )
2020    {
2021        reinitialize();
2022    return res.getConnectorConnectionPoolByName( poolName );
2023    }
2024    
2025    public com.sun.enterprise.config.serverbeans.JdbcConnectionPool
2026           getJDBCPoolForResource(String JavaDoc resourceName) throws ConfigException {
2027        JdbcResource jr = res.getJdbcResourceByJndiName(resourceName);
2028        if (isEnabled(jr)) {
2029            return this.getJdbcConnectionPoolByName(jr.getPoolName());
2030        }
2031        return null;
2032    }
2033
2034}
2035
Popular Tags