KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > connectors > ConnectorRuntime


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.connectors;
25
26 import java.util.logging.*;
27 import java.util.*;
28
29 import javax.resource.spi.*;
30 import javax.resource.*;
31 import javax.naming.NamingException JavaDoc;
32 import com.sun.enterprise.deployment.*;
33 import com.sun.logging.LogDomains;
34 import com.sun.enterprise.config.serverbeans.*;
35 import com.sun.enterprise.connectors.util.*;
36 import com.sun.enterprise.connectors.system.*;
37 import com.sun.enterprise.connectors.authentication.*;
38 import java.sql.Connection JavaDoc;
39 import java.sql.SQLException JavaDoc;
40
41 /**
42  * This class is the entry point to connector backend module.
43  * It exposes different API's called by external entities like admin
44  * to perform various connector backend related operations.
45  * It delegates calls to various connetcor admin services and other
46  * connector services which actually implement the functionality.
47  * This is a delegating class.
48  * @author Binod P.G, Srikanth P and Aditya Gore
49  */

50
51
52 public final class ConnectorRuntime implements ConnectorConstants {
53     static Logger _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
54      
55     private static ConnectorRegistry _registry = null;
56
57     private static ConnectorRuntime _runtime;
58
59  
60     private boolean debug=true;
61     private int environment = CLIENT;
62
63     private static ConnectorAdminObjectAdminServiceImpl
64                    adminObjectAdmService = null;
65     private static ConnectorConfigurationParserServiceImpl
66                    configParserAdmService =null;
67     private static ConnectorConnectionPoolAdminServiceImpl
68                    ccPoolAdmService =null;
69     private static ConnectorResourceAdminServiceImpl
70                    connectorResourceAdmService =null;
71     private static ConnectorSecurityAdminServiceImpl
72                    connectorSecurityAdmService =null;
73     private static ResourceAdapterAdminServiceImpl
74                    resourceAdapterAdmService = null;
75     private static ConnectorServiceImpl connectorService=null;
76
77
78     /**
79      * Returns the ConnectorRuntime instance.
80      * It follows singleton pattern and only one instance exists at any point
81      * of time. External entities need to call this method to get
82      * ConnectorRuntime instance
83      * @return ConnectorRuntime instance
84      */

85
86     public static ConnectorRuntime getRuntime() {
87         if (_runtime == null) {
88             _runtime = new ConnectorRuntime();
89             com.sun.enterprise.util.Utility.setDataDirectProperty();
90             createServices();
91         }
92         return _runtime;
93     }
94
95     /** Initializes the execution environment. If the execution environment
96      * is appserv runtime it is set to ConnectorConstants.SERVER else
97      * it is set ConnectorConstants.CLIENT
98      * @param environment set to ConnectorConstants.SERVER if execution
99      * environment is appserv runtime else set to
100      * ConnectorConstants.CLIENT
101      */

102
103     public void initialize(int environment) {
104         this.environment = environment;
105         initServices();
106     }
107
108     /**
109      * Returns the execution environment.
110      * @return ConnectorConstants.SERVER if execution environment is
111      * appserv runtime
112      * else it returns ConnectorConstants.CLIENT
113      */

114
115     public int getEnviron() {
116         return environment;
117     }
118
119     /**
120      * Private constructor. It is private as it follows singleton pattern.
121      */

122
123     private ConnectorRuntime() {
124         _registry = ConnectorRegistry.getInstance();
125     }
126
127     private static void createServices() {
128         adminObjectAdmService = (ConnectorAdminObjectAdminServiceImpl)
129            ConnectorAdminServicesFactory.getService(ConnectorAdminService.AOR);
130         ccPoolAdmService = ( ConnectorConnectionPoolAdminServiceImpl)
131            ConnectorAdminServicesFactory.getService(ConnectorAdminService.CCP);
132         connectorResourceAdmService = ( ConnectorResourceAdminServiceImpl)
133            ConnectorAdminServicesFactory.getService(ConnectorAdminService.CR);
134         connectorSecurityAdmService = ( ConnectorSecurityAdminServiceImpl)
135            ConnectorAdminServicesFactory.getService(ConnectorAdminService.SEC);
136         resourceAdapterAdmService = ( ResourceAdapterAdminServiceImpl)
137            ConnectorAdminServicesFactory.getService(ConnectorAdminService.RA);
138         configParserAdmService = new ConnectorConfigurationParserServiceImpl();
139         connectorService = new ConnectorServiceImpl();
140     }
141
142     private void initServices() {
143         connectorService.initialize(getEnviron());
144     }
145
146     /**
147      * Destroys/deletes the Active resource adapter object from the
148      * connector container. Active resource adapter abstracts the rar
149      * deployed. It checks whether any resources (pools and connector
150      * resources) are still present. If they are present the deletion
151      * fails and all the objects and datastructures pertaining to
152      * to the resource adapter are left untouched.
153      * @param moduleName Name of the rarModule to destroy/delete
154      * @throws ConnectorRuntimeException if the deletion fails
155      */

156     
157     public void destroyActiveResourceAdapter(String JavaDoc moduleName)
158                                 throws ConnectorRuntimeException
159     {
160         resourceAdapterAdmService.destroyActiveResourceAdapter(moduleName);
161     }
162
163     /**
164      * Destroys/deletes the Active resource adapter object from the
165      * connector container. Active resource adapter abstracts the rar
166      * deployed. It checks whether any resources (pools and connector
167      * resources) are still present. If they are present and cascade option
168      * is false the deletion fails and all the objects and datastructures
169      * pertaining to the resource adapter are left untouched.
170      * If cascade option is true, even if resources are still present, they are
171      * also destroyed with the active resource adapter
172      * @param moduleName Name of the rarModule to destroy/delete
173      * @param cascade If true all the resources belonging to the rar are
174      * destroyed recursively.
175      * If false, and if resources pertaining to resource adapter
176      * /rar are present deletetion is failed. Then cascade
177      * should be set to true or all the resources have to
178      * deleted explicitly before destroying the rar/Active
179      * resource adapter.
180      * @throws ConnectorRuntimeException if the deletion fails
181      */

182
183     public void destroyActiveResourceAdapter(String JavaDoc moduleName,boolean cascade)
184                                 throws ConnectorRuntimeException
185     {
186         resourceAdapterAdmService.destroyActiveResourceAdapter(
187                                   moduleName,cascade);
188     }
189
190     /** Creates Active resource Adapter which abstracts the rar module.
191      * During the creation of ActiveResourceAdapter, default pools and
192      * resources also are created.
193      * @param connectorDescriptor object which abstracts the connector
194      * deployment descriptor i.e rar.xml and sun-ra.xml.
195      * @param moduleName Name of the module
196      * @param moduleDir Directory where rar module is exploded.
197      * @param writeSunDescriptor If true write the sun-ra.xml props to
198      * domain.xml and if false it doesnot write to domain.xml
199      * @throws ConnectorRuntimeException if creation fails.
200      */

201
202     public void createActiveResourceAdapter(
203             ConnectorDescriptor connectorDescriptor,
204             String JavaDoc moduleName,
205             String JavaDoc moduleDir,
206             boolean writeSunDescriptor) throws ConnectorRuntimeException
207     {
208         resourceAdapterAdmService.createActiveResourceAdapter(
209                connectorDescriptor,moduleName,moduleDir,writeSunDescriptor);
210
211     }
212
213     /** Creates Active resource Adapter which abstracts the rar module.
214      * During the creation of ActiveResourceAdapter, default pools and
215      * resources also are created.
216      * @param moduleDir Directory where rar module is exploded.
217      * @param moduleName Name of the module
218      * @param writeSunDescriptor If true write the sun-ra.xml props to
219      * domain.xml and if false it doesnot write to domain.xml
220      * @throws ConnectorRuntimeException if creation fails.
221      */

222
223     public void createActiveResourceAdapter(String JavaDoc moduleDir ,
224                 String JavaDoc moduleName,
225                 boolean writeSunDescriptor) throws ConnectorRuntimeException
226     {
227         resourceAdapterAdmService.createActiveResourceAdapter(
228            moduleDir,moduleName,writeSunDescriptor);
229     }
230
231     public ConnectionManager obtainConnectionManager(String JavaDoc poolName)
232                                        throws ConnectorRuntimeException
233     {
234         return this.obtainConnectionManager( poolName, false );
235     }
236
237     public ConnectionManager obtainConnectionManager(String JavaDoc poolName,
238         boolean forceNoLazyAssoc)
239                                        throws ConnectorRuntimeException
240     {
241         ConnectionManager mgr = ConnectionManagerFactory.
242                 getAvailableConnectionManager(poolName, forceNoLazyAssoc);
243         return mgr;
244     }
245     /** Returns the MCF instance. If the MCF is already created and
246      * present in connectorRegistry that instance is returned. Otherwise it
247      * is created explicitly and added to ConnectorRegistry.
248      * @param poolName Name of the pool.MCF pertaining to this pool is
249      * created/returned.
250      * @return created/already present MCF instance
251      * @throws ConnectorRuntimeException if creation/retrieval of MCF fails
252      */

253  
254     public ManagedConnectionFactory obtainManagedConnectionFactory(
255            String JavaDoc poolName) throws ConnectorRuntimeException
256     {
257         return ccPoolAdmService.obtainManagedConnectionFactory(poolName);
258     }
259    
260     /** Creates connector connection pool in the connector container.
261      * @param ccp ConnectorConnectionPool instance to be bound to JNDI. This
262      * object contains the pool properties.
263      * @param connectionDefinitionName Connection definition name against which
264      * connection pool is being created
265      * @param rarName Name of the resource adapter
266      * @param props Properties of MCF which are present in domain.xml
267      * These properties override the ones present in ra.xml
268      * @param securityMaps Array fo security maps.
269      * @throws ConnectorRuntimeException When creation of pool fails.
270      */

271
272     public void createConnectorConnectionPool(ConnectorConnectionPool ccp,
273                           String JavaDoc connectionDefinitionName , String JavaDoc rarName,
274                           com.sun.enterprise.config.serverbeans.ElementProperty[] props,
275                           com.sun.enterprise.config.serverbeans.SecurityMap[] securityMaps)
276                           throws ConnectorRuntimeException
277     {
278         ccPoolAdmService.createConnectorConnectionPool(
279                  ccp,connectionDefinitionName,rarName,props,securityMaps);
280     }
281
282     /** Creates connector connection pool in the connector container.
283      * @param ccp ConnectorConnectionPool instance to be bound to JNDI. This
284      * object contains the pool properties.
285      * @param cdd ConnectorDescriptor obejct which abstracts the ra.xml
286      * @param rarName Name of the resource adapter
287      * @throws ConnectorRuntimeException When creation of pool fails.
288      */

289
290     public void createConnectorConnectionPool(ConnectorConnectionPool ccp,
291                     ConnectionDefDescriptor cdd, String JavaDoc rarName)
292                     throws ConnectorRuntimeException
293     {
294         ccPoolAdmService.createConnectorConnectionPool(ccp,cdd,rarName);
295
296     }
297
298     /** Creates connector connection pool in the connector container.
299      * @param ccp ConnectorConnectionPool instance to be bound to JNDI. This
300      * object contains the pool properties.
301      * @throws ConnectorRuntimeException When creation of pool fails.
302      */

303
304     public void createConnectorConnectionPool(
305                        ConnectorConnectionPool connectorPoolObj )
306                        throws ConnectorRuntimeException
307     {
308         ccPoolAdmService.createConnectorConnectionPool(
309                              connectorPoolObj);
310     }
311
312     /** Creates connector connection pool in the connector container.
313      * cannot be used for 1.5 rar cases
314      * @param ccp ConnectorConnectionPool instance to be bound to JNDI. This
315      * object contains the pool properties.
316      * @param security unused
317      * @param configProperties MCF config properties
318      * @throws ConnectorRuntimeException When creation of pool fails.
319      */

320
321     public void createConnectorConnectionPool(
322                 ConnectorConnectionPool connectorPoolObj, String JavaDoc security,
323                 Set configProperties) throws ConnectorRuntimeException
324     {
325         ccPoolAdmService.createConnectorConnectionPool(
326                              connectorPoolObj,security,configProperties);
327     }
328
329     /**
330      * Creates the connector resource on a given connection pool
331      * @param jndiName JNDI name of the resource to be created
332      * @poolName PoolName to which the connector resource belongs.
333      * @resourceType Resource type Unused.
334      * @throws ConnectorRuntimeException If the resouce creation fails.
335      */

336
337     public void createConnectorResource(String JavaDoc jndiName, String JavaDoc poolName,
338                     String JavaDoc resourceType) throws ConnectorRuntimeException
339     {
340
341         connectorResourceAdmService.createConnectorResource(
342                                  jndiName,poolName,resourceType);
343     }
344
345     /**
346      * Returns the generated default poolName of JMS resources.
347      * @jndiName jndi of the resources for which pool is to be created,
348      * @return generated poolname
349      */

350
351     public String JavaDoc getDefaultPoolName(String JavaDoc jndiName) {
352         return connectorService.getDefaultPoolName(jndiName);
353     }
354
355     public static boolean isJmsRa() {
356         return ResourceAdapterAdminServiceImpl.isJmsRa();
357     }
358
359     /**
360      * Returns the generated default connection poolName for a
361      * connection definition.
362      * @moduleName rar module name
363      * @connectionDefName connection definition name
364      * @return generated connection poolname
365      */

366
367     public String JavaDoc getDefaultPoolName(String JavaDoc moduleName,
368                        String JavaDoc connectionDefName) {
369         return connectorService.getDefaultPoolName(
370                          moduleName,connectionDefName);
371     }
372
373     /**
374      * Returns the generated default connector resource for a
375      * connection definition.
376      * @moduleName rar module name
377      * @connectionDefName connection definition name
378      * @return generated default connector resource name
379      */

380
381     public String JavaDoc getDefaultResourceName(String JavaDoc moduleName,
382                        String JavaDoc connectionDefName) {
383         return connectorService.getDefaultResourceName(
384                             moduleName,connectionDefName);
385     }
386
387     public void addAdminObject (
388             String JavaDoc appName,
389             String JavaDoc connectorName,
390             String JavaDoc jndiName,
391             String JavaDoc adminObjectType,
392             Properties props)
393             throws ConnectorRuntimeException
394     {
395         adminObjectAdmService.addAdminObject(
396                   appName,connectorName,jndiName,adminObjectType,props);
397     }
398
399     public void deleteAdminObject(String JavaDoc jndiName)
400                            throws ConnectorRuntimeException
401     {
402         adminObjectAdmService.deleteAdminObject(jndiName);
403
404     }
405
406     /** Deletes connector Connection pool
407      * @param poolName Name of the pool to delete
408      * @throws ConnectorRuntimeException if pool deletion operation fails
409      */

410
411     public void deleteConnectorConnectionPool(String JavaDoc poolName)
412                                  throws ConnectorRuntimeException
413     {
414         ccPoolAdmService.deleteConnectorConnectionPool(poolName);
415     }
416
417     /** Deletes connector Connection pool.
418      * @param poolName Name of the pool to delete
419      * @param cascade If true all the resources associed with that are also
420      * deleted from connector container
421      * If false and if some resources pertaining to pool
422      * are present deletion operation fails . If no resources
423      * are present pool is deleted.
424      * @throws ConnectorRuntimeException if pool deletion operation fails
425      */

426
427     public void deleteConnectorConnectionPool(String JavaDoc poolName,boolean cascade)
428                                  throws ConnectorRuntimeException
429     {
430
431         ccPoolAdmService.deleteConnectorConnectionPool(poolName,cascade);
432     }
433
434     /**
435      * Deletes the connector resource.
436      * @param jndiName JNDI name of the resource to delete.
437      * @throws ConnectorRuntimeException if connector resource deletion fails.
438      */

439
440     public void deleteConnectorResource(String JavaDoc jndiName)
441                        throws ConnectorRuntimeException
442     {
443         connectorResourceAdmService.deleteConnectorResource(jndiName);
444
445     }
446
447     /**
448      * Obtain the authentication service associated with rar module.
449      * Currently only the BasicPassword authentication is supported.
450      * @rarName Rar module Name
451      * @poolName Name of the pool. Used for creation of
452      * BasicPasswordAuthenticationService
453      */

454
455     public AuthenticationService getAuthenticationService(String JavaDoc rarName,
456                            String JavaDoc poolName) {
457
458         return connectorSecurityAdmService.getAuthenticationService(
459                             rarName,poolName);
460     }
461
462
463     public JmsRaMapping getJmsRaMapping() {
464         return resourceAdapterAdmService.getJmsRaMapping();
465     }
466
467     /**
468      * Obtains the Permission string that needs to be added to the
469      * to the security policy files. These are the security permissions needed
470      * by the resource adapter implementation classes.
471      * These strings are obtained by parsing the ra.xml
472      * @param moduleName rar module Name
473      * @ConnectorRuntimeException If rar.xml parsing fails.
474      */

475
476     public String JavaDoc getSecurityPermissionSpec(String JavaDoc moduleName)
477                          throws ConnectorRuntimeException
478     {
479         return configParserAdmService.getSecurityPermissionSpec(moduleName);
480     }
481
482  
483 // asadmin test-connection-pool
484
/**
485      * This method is used to provide backend functionality for the
486      * test-connection-pool asadmin command. Briefly the design is as
487      * follows:<br>
488      * 1. obtainManagedConnection for the poolname<br>
489      * 2. lookup ConnectorDescriptorInfo from InitialContext using poolname<br>
490      * 3. from cdi get username and password<br>
491      * 4. create ResourcePrincipal using default username and password<br>
492      * 5. create a Subject from this (doPriveleged)<br>
493      * 6. createManagedConnection using above subject<br>
494      * 7. getConnection from the ManagedConnection with above subject<br>
495      *
496      * @return true if the connection pool is healthy. false otherwise
497      * @throws ResourceException if pool is not usable
498      */

499     public boolean testConnectionPool( String JavaDoc poolName )
500             throws ResourceException {
501         
502         return ccPoolAdmService.testConnectionPool(poolName);
503     }
504     
505     /**
506      * Pool Monitoring
507      * This method returns the PoolStats for a given pool name
508      * If the poolName does not exist, it returns null
509      */

510     /*
511     public PoolStats getPoolStats( String poolName ) {
512         return ccPoolAdmService.getPoolStats(poolName);
513     }
514     */

515
516     /** Checks if the rar module is already reployed.
517      * @param moduleName Rarmodule name
518      * @return true if it is already deployed.
519      * false if it is not deployed.
520      */

521                        
522     public boolean isRarDeployed(String JavaDoc moduleName) {
523         
524         return resourceAdapterAdmService.isRarDeployed(moduleName);
525     }
526
527     /** The ActiveResourceAdapter object which abstract the rar module is
528      * recreated in the connector container/registry. All the pools and
529      * resources are killed. But the infrastructure to create the pools and
530      * and resources is untouched. Only the actual pool is killed.
531      * @param moduleName rar module Name.
532      * @throws ConnectorRuntimeException if recreation fails.
533      */

534  
535     public void reCreateActiveResourceAdapter(String JavaDoc moduleName)
536                          throws ConnectorRuntimeException {
537         resourceAdapterAdmService.reCreateActiveResourceAdapter(moduleName);
538     }
539
540     /**
541      * Stops the resourceAdapter and removes it from connector container/
542      * registry.
543      * @param moduleName Rarmodule name.
544      * @return true it is successful stop and removal of ActiveResourceAdapter
545      * false it stop and removal fails.
546      */

547
548     public boolean stopAndRemoveActiveResourceAdapter(String JavaDoc moduleName) {
549
550          return resourceAdapterAdmService.stopAndRemoveActiveResourceAdapter(
551                                              moduleName);
552     }
553
554     /**
555      * Kills all the pools pertaining to the rar module.
556      * @moduleName Rar module Name
557      */

558
559     public void killAllPools(String JavaDoc moduleName) {
560         ccPoolAdmService.killAllPools(moduleName);
561     }
562
563     /**
564      * Kills a specific pool
565      * @param poolName poolName to kill
566      */

567
568     public void killPool(String JavaDoc poolName) {
569         ccPoolAdmService.killPool(poolName);
570     }
571
572     /** Add the resource adapter configuration to the connector registry
573      * @param rarName rarmodule
574      * @param raConfig Resource Adapter configuration object
575      * @throws ConnectorRuntimeExcetion if the addition fails.
576      */

577
578     public void addResourceAdapterConfig(String JavaDoc rarName,
579            ResourceAdapterConfig raConfig) throws ConnectorRuntimeException {
580         resourceAdapterAdmService.addResourceAdapterConfig(rarName,raConfig);
581     }
582     
583     /** Delete the resource adapter configuration to the connector registry
584      * @param rarName rarmodule
585      */

586
587     public void deleteResourceAdapterConfig(String JavaDoc rarName) {
588         resourceAdapterAdmService.deleteResourceAdapterConfig(rarName);
589     }
590  
591 //Dynamic reconfig
592
/**
593      * Reconfigure a connection pool.
594      * This method compares the passed connector connection pool with the one
595      * in memory. If the pools are unequal and the MCF properties are changed
596      * a pool recreate is required. However if the pools are unequal and the
597      * MCF properties are not changed a recreate is not required
598      *
599      * @param ccp - the Updated connector connection pool object that admin
600      * hands over
601      * @return true - if a pool restart is required, false otherwise
602      * @throws ConnectorRuntimeException
603      */

604     public boolean reconfigureConnectorConnectionPool( ConnectorConnectionPool
605             ccp ) throws ConnectorRuntimeException
606     {
607         return ccPoolAdmService.reconfigureConnectorConnectionPool(ccp);
608     }
609
610     /**
611      * Reconfigure a connection pool.
612      * This method compares the passed connector connection pool with the one
613      * in memory. If the pools are unequal and the MCF properties are changed
614      * a pool recreate is required. However if the pools are unequal and the
615      * MCF properties are not changed a recreate is not required
616      *
617      * @param ccp - the Updated connector connection pool object that admin
618      * hands over
619      * @param excludedProps - A set of excluded property names that we want
620      * to be excluded in the comparison check while
621      * comparing MCF properties
622      * @return true - if a pool restart is required, false otherwise
623      * @throws ConnectorRuntimeException
624      */

625     public boolean reconfigureConnectorConnectionPool( ConnectorConnectionPool
626             ccp, Set excludedProps ) throws ConnectorRuntimeException
627     {
628         return ccPoolAdmService.reconfigureConnectorConnectionPool(
629                         ccp,excludedProps);
630     }
631     
632     /**
633      * Recreate a connector connection pool. This method essentially does
634      * the following things:
635      * 1. Delete the said connector connection pool<br>
636      * 2. Bind the pool to JNDI<br>
637      * 3. Create an MCF for this pool and register with the connector registry<br>
638      *
639      * @param ccp - the ConnectorConnectionPool to publish
640      */

641
642     public void recreateConnectorConnectionPool( ConnectorConnectionPool ccp)
643         throws ConnectorRuntimeException
644     {
645         ccPoolAdmService.recreateConnectorConnectionPool(ccp);
646     }
647
648     /** Obtains all the Connection definition names of a rar
649      * @param rarName rar moduleName
650      * @return Array of connection definition names.
651      */

652
653     public String JavaDoc[] getConnectionDefinitionNames(String JavaDoc rarName)
654                throws ConnectorRuntimeException
655     {
656         return configParserAdmService.getConnectionDefinitionNames(rarName);
657     }
658   
659     /** Obtains all the Admin object interface names of a rar
660      * @param rarName rar moduleName
661      * @return Array of admin object interface names.
662      */

663
664     public String JavaDoc[] getAdminObjectInterfaceNames(String JavaDoc rarName)
665                throws ConnectorRuntimeException
666     {
667         return configParserAdmService.getAdminObjectInterfaceNames(rarName);
668     }
669     /**
670      * Retrieves the Resource adapter javabean properties with default values.
671      * The default values will the values present in the ra.xml. If the
672      * value is not present in ra.xxml, javabean is introspected to obtain
673      * the default value present, if any. If intrspection fails or null is the
674      * default value, empty string is returned.
675      * If ra.xml has only the property and no value, empty string is the value
676      * returned.
677      * @param rarName rar module name
678      * @return Resource adapter javabean properties with default values.
679      * @throws ConnectorRuntimeException if property retrieval fails.
680      */

681
682     public Properties getResourceAdapterConfigProps(String JavaDoc rarName)
683                 throws ConnectorRuntimeException
684     {
685         return
686         rarName.indexOf( ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER ) == -1
687             ? configParserAdmService.getResourceAdapterConfigProps(rarName)
688         : new Properties();
689     }
690
691     /**
692      * Retrieves the MCF javabean properties with default values.
693      * The default values will the values present in the ra.xml. If the
694      * value is not present in ra.xxml, javabean is introspected to obtain
695      * the default value present, if any. If intrspection fails or null is the
696      * default value, empty string is returned.
697      * If ra.xml has only the property and no value, empty string is the value
698      * returned.
699      * @param rarName rar module name
700      * @return managed connection factory javabean properties with
701      * default values.
702      * @throws ConnectorRuntimeException if property retrieval fails.
703      */

704
705     public Properties getMCFConfigProps(
706      String JavaDoc rarName,String JavaDoc connectionDefName) throws ConnectorRuntimeException
707     {
708         return
709         rarName.indexOf( ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER ) == -1
710             ? configParserAdmService.getMCFConfigProps(
711             rarName,connectionDefName)
712             : new Properties();
713     }
714
715     /**
716      * Retrieves the admin object javabean properties with default values.
717      * The default values will the values present in the ra.xml. If the
718      * value is not present in ra.xxml, javabean is introspected to obtain
719      * the default value present, if any. If intrspection fails or null is the
720      * default value, empty string is returned.
721      * If ra.xml has only the property and no value, empty string is the value
722      * returned.
723      * @param rarName rar module name
724      * @return admin object javabean properties with
725      * default values.
726      * @throws ConnectorRuntimeException if property retrieval fails.
727      */

728
729     public Properties getAdminObjectConfigProps(
730       String JavaDoc rarName,String JavaDoc adminObjectIntf) throws ConnectorRuntimeException
731     {
732         return
733         rarName.indexOf( ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER ) == -1
734             ? configParserAdmService.getAdminObjectConfigProps(
735             rarName,adminObjectIntf)
736         : new Properties();
737     }
738
739     /**
740      * Retrieves the XXX javabean properties with default values.
741      * The javabean to introspect/retrieve is specified by the type.
742      * The default values will be the values present in the ra.xml. If the
743      * value is not present in ra.xxml, javabean is introspected to obtain
744      * the default value present, if any. If intrspection fails or null is the
745      * default value, empty string is returned.
746      * If ra.xml has only the property and no value, empty string is the value
747      * returned.
748      * @param rarName rar module name
749      * @return admin object javabean properties with
750      * default values.
751      * @throws ConnectorRuntimeException if property retrieval fails.
752      */

753
754     public Properties getConnectorConfigJavaBeans(String JavaDoc rarName,
755         String JavaDoc connectionDefName,String JavaDoc type) throws ConnectorRuntimeException
756     {
757
758         return configParserAdmService.getConnectorConfigJavaBeans(
759                              rarName,connectionDefName,type);
760     }
761
762     /**
763      * Return the ActivationSpecClass name for given rar and messageListenerType
764      * @param moduleDir The directory where rar is exploded.
765      * @param messageListenerType MessageListener type
766      * @throws ConnectorRuntimeException If moduleDir is null.
767      * If corresponding rar is not deployed.
768      */

769
770     public String JavaDoc getActivationSpecClass( String JavaDoc rarName,
771              String JavaDoc messageListenerType) throws ConnectorRuntimeException
772     {
773         return configParserAdmService.getActivationSpecClass(
774                           rarName,messageListenerType);
775     }
776
777     /* Parses the ra.xml and returns all the Message listener types.
778      *
779      * @param rarName name of the rar module.
780      * @return Array of message listener types as strings.
781      * @throws ConnectorRuntimeException If moduleDir is null.
782      * If corresponding rar is not deployed.
783      *
784      */

785
786     public String JavaDoc[] getMessageListenerTypes(String JavaDoc rarName)
787                throws ConnectorRuntimeException
788     {
789         return configParserAdmService.getMessageListenerTypes( rarName);
790     }
791
792     /** Parses the ra.xml for the ActivationSpec javabean
793      * properties. The ActivationSpec to be parsed is
794      * identified by the moduleDir where ra.xml is present and the
795      * message listener type.
796      *
797      * message listener type will be unique in a given ra.xml.
798      *
799      * It throws ConnectorRuntimeException if either or both the
800      * parameters are null, if corresponding rar is not deployed,
801      * if message listener type mentioned as parameter is not found in ra.xml.
802      * If rar is deployed and message listener (type mentioned) is present
803      * but no properties are present for the corresponding message listener,
804      * null is returned.
805      *
806      * @param rarName name of the rar module.
807      * @param messageListenerType message listener type.It is uniqie
808      * across all <messagelistener> sub-elements in <messageadapter>
809      * element in a given rar.
810      * @return Javabean properties with the property names and values
811      * of properties. The property values will be the values
812      * mentioned in ra.xml if present. Otherwise it will be the
813      * default values obtained by introspecting the javabean.
814      * In both the case if no value is present, empty String is
815      * returned as the value.
816      * @throws ConnectorRuntimeException if either of the parameters are null.
817      * If corresponding rar is not deployed i.e moduleDir is invalid.
818      * If messagelistener type is not found in ra.xml
819      */

820
821     public Properties getMessageListenerConfigProps(String JavaDoc rarName,
822          String JavaDoc messageListenerType)throws ConnectorRuntimeException
823     {
824         return
825         rarName.indexOf( ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER ) == -1
826             ? configParserAdmService.getMessageListenerConfigProps(
827                         rarName,messageListenerType)
828         : new Properties();
829     }
830
831     /** Returns the Properties object consisting of propertyname as the
832      * key and datatype as the value.
833      * @param rarName name of the rar module.
834      * @param messageListenerType message listener type.It is uniqie
835      * across all <messagelistener> sub-elements in <messageadapter>
836      * element in a given rar.
837      * @return Properties object with the property names(key) and datatype
838      * of property(as value).
839      * @throws ConnectorRuntimeException if either of the parameters are null.
840      * If corresponding rar is not deployed i.e moduleDir is invalid.
841      * If messagelistener type is not found in ra.xml
842      */

843
844     public Properties getMessageListenerConfigPropTypes(String JavaDoc rarName,
845                String JavaDoc messageListenerType) throws ConnectorRuntimeException
846     {
847         return configParserAdmService.getMessageListenerConfigPropTypes(
848                         rarName,messageListenerType);
849     }
850
851     /** Checks whether the executing environment is application server
852      * @return true if execution environment is server
853      * false if it is client
854      */

855
856     public static boolean isServer() {
857         return connectorService.isServer();
858     }
859
860     public void loadDeferredResourceAdapter(String JavaDoc rarName)
861                         throws ConnectorRuntimeException {
862         connectorService.loadDeferredResourceAdapter(rarName);
863     }
864
865     public boolean checkAndLoadResource(String JavaDoc resName) {
866         return connectorService.checkAndLoadResource(resName);
867     }
868
869     public boolean checkAccessibility(String JavaDoc rarName, ClassLoader JavaDoc loader) {
870         return connectorService.checkAccessibility(rarName, loader);
871     }
872
873     /**
874      * Gets the properties of the Java bean connection definition class that
875      * have setter methods defined
876      *
877      * @param connectionDefinitionClassName The Connection Definition Java bean class
878      * for which overrideable properties are required.
879      * @return A Set of properties that have a setter method defined in the
880      * Connection Definition class
881      */

882     public static Set getConnectionDefinitionProperties(String JavaDoc connectionDefinitionClassName) {
883         return ccPoolAdmService.getConnectionDefinitionProperties(
884             connectionDefinitionClassName);
885     }
886                                                                                                                                                
887     /**
888       * Gets the properties of the Java bean connection definition class that
889       * have setter methods defined and the default values as provided by the
890       * Connection Definition java bean developer.
891       *
892       * @param connectionDefinitionClassName
893       * The Connection Definition Java bean class for which
894       * overrideable properties are required.
895       * @return Map [property, defaultValue]
896       */

897     public static Map getConnectionDefinitionPropertiesAndDefaults(String JavaDoc connectionDefinitionClassName) {
898         return ccPoolAdmService.getConnectionDefinitionPropertiesAndDefaults(
899             connectionDefinitionClassName);
900     }
901  
902     /**
903      * Gets Connector Resource Rebind Event notifier.
904      * @return ConnectorNamingEventNotifier
905      */

906     public ConnectorNamingEventNotifier getResourceRebindEventNotifier(){
907         return connectorResourceAdmService.getResourceRebindEventNotifier();
908     }
909
910     /**
911      * Causes pool to switch on the matching of connections.
912      * It can be either directly on the pool or on the ConnectorConnectionPool
913      * object that is bound in JNDI.
914      *
915      * @param rarName Name of Resource Adpater.
916      * @param poolName Name of the pool.
917      */

918     public void switchOnMatching (String JavaDoc rarName, String JavaDoc poolName) {
919         connectorService.switchOnMatching(rarName, poolName);
920     }
921
922     /**
923      * Causes matching to be switched on the ConnectorConnectionPool
924      * bound in JNDI
925      *
926      * @param poolName Name of the pool
927      */

928     public void switchOnMatchingInJndi (String JavaDoc poolName)
929         throws ConnectorRuntimeException {
930         ccPoolAdmService.switchOnMatching(poolName);
931     }
932
933     /**
934      * Obtains the connector Descriptor pertaining to rar.
935      * If ConnectorDescriptor is present in registry, it is obtained from
936      * registry and returned. Else it is explicitly read from directory
937      * where rar is exploded.
938      * @param rarName Name of the rar
939      * @return ConnectorDescriptor pertaining to rar.
940      */

941     public ConnectorDescriptor getConnectorDescriptor( String JavaDoc rarName )
942         throws ConnectorRuntimeException
943     {
944         return connectorService.getConnectorDescriptor( rarName );
945         
946     }
947     
948     /**
949      * Calls the stop method for all J2EE Connector 1.5 spec compliant RARs
950      */

951     public static void stopAllActiveResourceAdapters(){
952         resourceAdapterAdmService.stopAllActiveResourceAdapters();
953     }
954     
955     /**
956      * Returns the configurable ResourceAdapterBean Properties
957      * for a connector module bundled as a RAR.
958      *
959      * @param pathToDeployableUnit a physical,accessible location of the connector module.
960      * [either a RAR for RAR-based deployments or a directory for Directory based deployments]
961      * @return A Map that is of <String RAJavaBeanPropertyName, String defaultPropertyValue>
962      * An empty map is returned in the case of a 1.0 RAR
963      */

964     public Map getResourceAdapterBeanProperties(String JavaDoc pathToDeployableUnit) throws ConnectorRuntimeException{
965         return configParserAdmService.getRABeanProperties(pathToDeployableUnit);
966     }
967
968     /**
969      * Initialize the monitoring listeners for connection pools, work management
970      * and message end point factory related stats
971      */

972     public void initializeConnectorMonitoring() {
973         connectorService.initializeConnectorMonitoring();
974     }
975
976
977
978     /**
979      * Get a sql connection from the DataSource specified by the jdbcJndiName.
980      * This API is intended to be used in the DAS. The motivation for having this
981      * API is to provide the CMP backend a means of acquiring a connection during
982      * the codegen phase. If a user is trying to deploy an app on a remote server,
983      * without this API, a resource reference has to be present both in the DAS
984      * and the server instance. This makes the deployment more complex for the
985      * user since a resource needs to be forcibly created in the DAS Too.
986      * This API will mitigate this need.
987      *
988      * @param jndiName the jndi name of the resource being used to get Connection from
989      * This resource can either be a pmf resource or a jdbc resource
990      * @param user the user used to authenticate this request
991      * @param password the password used to authenticate this request
992      *
993      * @return a java.sql.Connection
994      * @throws java.sql.SQLException in case of errors
995      */

996     public Connection JavaDoc getConnection(String JavaDoc jndiName, String JavaDoc user, String JavaDoc password)
997             throws SQLException JavaDoc
998     {
999              
1000
1001    return ccPoolAdmService.getConnection( jndiName, user, password );
1002    }
1003
1004    /**
1005     * Get a sql connection from the DataSource specified by the jdbcJndiName.
1006     * This API is intended to be used in the DAS. The motivation for having this
1007     * API is to provide the CMP backend a means of acquiring a connection during
1008     * the codegen phase. If a user is trying to deploy an app on a remote server,
1009     * without this API, a resource reference has to be present both in the DAS
1010     * and the server instance. This makes the deployment more complex for the
1011     * user since a resource needs to be forcibly created in the DAS Too.
1012     * This API will mitigate this need.
1013     *
1014     * @param jndiName the jndi name of the resource being used to get Connection from
1015     * This resource can either be a pmf resource or a jdbc resource
1016     *
1017     * @return a java.sql.Connection
1018     * @throws java.sql.SQLException in case of errors
1019     */

1020    public Connection JavaDoc getConnection(String JavaDoc jndiName)
1021            throws SQLException JavaDoc
1022    {
1023    return ccPoolAdmService.getConnection( jndiName );
1024    }
1025
1026    /**
1027     * Checks if a conncetor connection pool has been deployed to this server
1028     * instance
1029     * @param poolName
1030     * @return
1031     */

1032    public boolean isConnectorConnectionPoolDeployed(String JavaDoc poolName) {
1033        return ccPoolAdmService.isConnectorConnectionPoolDeployed(poolName);
1034    }
1035       
1036    /**
1037     * Returns a list of <code>MQJMXConnectorInfo</code> associated with the target
1038     */

1039    public MQJMXConnectorInfo[] getMQJMXConnectorInfo(String JavaDoc target) throws
1040                                                     ConnectorRuntimeException {
1041       /*
1042        For getting a JMXConnector for each jms-host defined in jms-service:
1043        If EMBEDDED/LOCAL and notclustered: get default JMS host from jms-service.
1044        If MQRA has already been started, get from registry, introspect and get
1045        the valid properties to construct MQJMXConnector
1046        If clustered: get all hosts from JMS host information and for each of them
1047        construct a MQRA instance, and get properties to construct MQJMXConnector
1048        */

1049        return MQJMXConnectorHelper.getMQJMXConnectorInfo(target);
1050    }
1051
1052    /**
1053     * Code that checks whether a jndi suffix is valid or not.
1054     */

1055    public boolean isValidJndiSuffix(String JavaDoc name) {
1056        return connectorResourceAdmService.isValidJndiSuffix(name);
1057    }
1058
1059    /**
1060     * Lookup using JNDI to get PM Resource
1061     * @param name
1062     * @return PMResource
1063     * @throws NamingException
1064     */

1065    public Object JavaDoc lookupPMResource(String JavaDoc name) throws NamingException JavaDoc{
1066        return connectorResourceAdmService.lookup(name+PM_JNDI_SUFFIX);
1067    }
1068
1069    /**
1070     * Lookup using JNDI to get NonTx Resource
1071     * @param name
1072     * @return NonTx Resource
1073     * @throws NamingException
1074     */

1075    public Object JavaDoc lookupNonTxResource(String JavaDoc name) throws NamingException JavaDoc{
1076        return connectorResourceAdmService.lookup(name+NON_TX_JNDI_SUFFIX);
1077    }
1078
1079    /**
1080     * Lookup the JNDI name with appropriate suffix.
1081     *
1082     * @param name : JNDI name to be looked up. This can be suffixed
1083     * with a proper suffix like __pm or __nontx
1084     */

1085    public Object JavaDoc lookup(String JavaDoc name) throws NamingException JavaDoc {
1086        return connectorResourceAdmService.lookup(name);
1087    }
1088
1089    /**
1090     * Returns the system RAR names that allow pool creation
1091     */

1092    public String JavaDoc[] getSystemConnectorsAllowingPoolCreation(){
1093        return new String JavaDoc[] {
1094                ConnectorConstants.DEFAULT_JMS_ADAPTER,
1095                ConnectorConstants.JAXR_RA_NAME};
1096    }
1097     
1098
1099}
1100
Popular Tags