KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > resource > ResourceUtility


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: ResourceUtility.java,v 1.6 2005/05/14 01:34:27 rhs Exp $
23  * --------------------------------------------------------------------------
24  */

25
26
27 package org.objectweb.jonas.resource;
28
29 import java.io.PrintWriter JavaDoc;
30 import java.lang.reflect.Method JavaDoc;
31 import java.text.SimpleDateFormat JavaDoc;
32 import java.util.Date JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.List JavaDoc;
35 import java.util.Properties JavaDoc;
36 import java.util.Vector JavaDoc;
37
38 import javax.management.MBeanServer JavaDoc;
39 import javax.management.ObjectName JavaDoc;
40 import javax.management.modelmbean.ModelMBean JavaDoc;
41 import javax.naming.BinaryRefAddr JavaDoc;
42 import javax.naming.Context JavaDoc;
43 import javax.naming.Reference JavaDoc;
44 import javax.naming.StringRefAddr JavaDoc;
45 import javax.resource.Referenceable JavaDoc;
46 import javax.resource.spi.ConnectionManager JavaDoc;
47 import javax.resource.spi.ManagedConnectionFactory JavaDoc;
48 import javax.resource.spi.ResourceAdapter JavaDoc;
49 import javax.resource.spi.ResourceAdapterAssociation JavaDoc;
50
51 import org.apache.commons.modeler.ManagedBean;
52 import org.apache.commons.modeler.Registry;
53 import org.objectweb.jonas.common.JNDIUtils;
54 import org.objectweb.jonas.common.Log;
55 import org.objectweb.jonas.jmx.J2eeObjectName;
56 import org.objectweb.jonas.naming.CompNamingContext;
57 import org.objectweb.jonas_ejb.deployment.api.ActivationConfigPropertyDesc;
58 import org.objectweb.jonas_rar.deployment.api.ConfigPropertyDesc;
59 import org.objectweb.jonas_rar.deployment.api.ConnectorDesc;
60 import org.objectweb.jonas_rar.deployment.api.JdbcConnParamsDesc;
61 import org.objectweb.jonas_rar.deployment.api.JonasConfigPropertyDesc;
62 import org.objectweb.jonas_rar.deployment.api.JonasConnectorDesc;
63 import org.objectweb.jonas_rar.deployment.api.PoolParamsDesc;
64 import org.objectweb.transaction.jta.TransactionManager;
65 import org.objectweb.util.monolog.api.BasicLevel;
66 import org.objectweb.util.monolog.api.Logger;
67
68 /**
69  * ResourceUtility class
70  * @author Eric Hardesty
71  * Contributor(s):
72  *
73  */

74
75 public class ResourceUtility {
76
77     /**
78      * Main logger
79      */

80     private static Logger logger = null;
81     /**
82      * Config property setter logger
83      */

84     private static Logger setterLogger = null;
85     /**
86      * Management logger
87      */

88     private static Logger manageLogger = null;
89
90     /**
91      * Reference to a Registry object
92      */

93     private Registry oRegistry = null;
94
95     /**
96      * Reference to a MBean server.
97      */

98     private MBeanServer JavaDoc mbeanServer = null;
99
100     // Properties for inits
101

102     /**
103      * JOnAS Connection Definition
104      */

105     public static final String JavaDoc JCD = "JCD";
106     /**
107      * JOnAS Activationspec
108      */

109     public static final String JavaDoc JAS = "JAS";
110     /**
111      * JOnAS Administrated Object
112      */

113     public static final String JavaDoc JAO = "JAO";
114
115     /**
116      * Default constructor
117      *
118      */

119     public ResourceUtility() {
120     }
121
122     /**
123      * Constructor
124      *
125      * @param mbeanServer MBeanServer object
126      * @param oRegistry Registry object
127      * @param log Logger main logger
128      * @param sLog Logger setter logger
129      * @param mLog Logger management logger
130      */

131     public ResourceUtility(MBeanServer JavaDoc mbeanServer, Registry oRegistry,
132                            Logger log, Logger sLog, Logger mLog) {
133         this.mbeanServer = mbeanServer;
134         this.oRegistry = oRegistry;
135         logger = log;
136         setterLogger = sLog;
137         manageLogger = mLog;
138     }
139
140     /**
141      *
142      * @param raCfg List
143      * @param jRaCfg1 List
144      * @param jRaCfg2 List
145      * @return ConfigPropertyDesc array
146      */

147     public ConfigPropertyDesc [] buildConfigProperty(List JavaDoc raCfg,
148                                                      List JavaDoc jRaCfg1,
149                                                      List JavaDoc jRaCfg2) {
150         Vector JavaDoc cfVec = null;
151         ConfigPropertyDesc[] configs = null;
152
153         // Global config parameters for the Resource adapter
154
if (raCfg != null) {
155             for (Iterator JavaDoc i = raCfg.iterator(); i.hasNext();) {
156                 if (cfVec == null) {
157                     cfVec = new Vector JavaDoc();
158                 }
159                 cfVec.add(new ConfigPropertyDesc((ConfigPropertyDesc) i.next()));
160             }
161         } else { //Special case for configuring ActivationSpecs
162
ActivationConfigPropertyDesc acp = null;
163             ConfigPropertyDesc cp = null;
164             if (jRaCfg1 != null) {
165                 for (Iterator JavaDoc i = jRaCfg1.iterator(); i.hasNext();) {
166                     if (cfVec == null) {
167                         cfVec = new Vector JavaDoc();
168                     }
169                     acp = (ActivationConfigPropertyDesc) i.next();
170                     cp = new ConfigPropertyDesc();
171                     cp.setConfigPropertyName(acp.getActivationConfigPropertyName());
172                     cp.setConfigPropertyValue(acp.getActivationConfigPropertyValue());
173                     cfVec.add(cp);
174                 }
175             }
176
177             if (cfVec == null) {
178                 if (jRaCfg2 != null) {
179                     for (Iterator JavaDoc i = jRaCfg2.iterator(); i.hasNext();) {
180                         if (cfVec == null) {
181                             cfVec = new Vector JavaDoc();
182                         }
183                         acp = (ActivationConfigPropertyDesc) i.next();
184                         cp = new ConfigPropertyDesc();
185                         cp.setConfigPropertyName(acp.getActivationConfigPropertyName());
186                         cp.setConfigPropertyValue(acp.getActivationConfigPropertyValue());
187                         cfVec.add(cp);
188                     }
189                     configs = new ConfigPropertyDesc[cfVec.size()];
190                     cfVec.copyInto(configs);
191                 }
192             } else {
193                 if (jRaCfg2 != null) {
194                     boolean found = false;
195                     for (Iterator JavaDoc i = jRaCfg2.iterator(); i.hasNext();) {
196                         found = false;
197                         acp = (ActivationConfigPropertyDesc) i.next();
198                         String JavaDoc name = acp.getActivationConfigPropertyName();
199                         String JavaDoc val = acp.getActivationConfigPropertyValue();
200                         if (val != null && val.length() > 0) {
201                             for (int j = 0; j < cfVec.size(); j++) {
202                                 cp = (ConfigPropertyDesc) cfVec.get(j);
203                                 if (name.equalsIgnoreCase(cp.getConfigPropertyName())) {
204                                     cp.setConfigPropertyValue(val);
205                                     cfVec.set(j, cp);
206                                     found = true;
207                                     break;
208                                 }
209                             }
210                             // This is the case where a new activation-config property is in
211
// the jonas specific dd
212
if (!found) {
213                                 cp = new ConfigPropertyDesc();
214                                 cp.setConfigPropertyName(name);
215                                 cp.setConfigPropertyValue(val);
216                                 cfVec.add(cp);
217                             }
218                         }
219                     }
220                 }
221                 configs = new ConfigPropertyDesc[cfVec.size()];
222                 cfVec.copyInto(configs);
223             }
224
225             return configs;
226         }
227
228         if (cfVec == null) {
229             return null;
230         }
231
232         configs = new ConfigPropertyDesc[cfVec.size()];
233         cfVec.copyInto(configs);
234
235         JonasConfigPropertyDesc jcpNext = null;
236         if (jRaCfg2 != null) {
237             for (Iterator JavaDoc i = jRaCfg2.iterator(); i.hasNext();) {
238                 jcpNext = (JonasConfigPropertyDesc) i.next();
239                 String JavaDoc name = jcpNext.getJonasConfigPropertyName();
240                 String JavaDoc val = jcpNext.getJonasConfigPropertyValue();
241                 if (val != null && val.length() > 0) {
242                     for (int j = 0; j < configs.length; j++) {
243                         if (name.equalsIgnoreCase(configs[j].getConfigPropertyName())) {
244                             configs[j].setConfigPropertyValue(val);
245                             break;
246                         }
247                     }
248                 }
249             }
250         }
251
252         if (jRaCfg1 != null) {
253             for (Iterator JavaDoc i = jRaCfg1.iterator(); i.hasNext();) {
254                 jcpNext = (JonasConfigPropertyDesc) i.next();
255                 String JavaDoc name = jcpNext.getJonasConfigPropertyName();
256                 String JavaDoc val = jcpNext.getJonasConfigPropertyValue();
257                 if (val != null && val.length() > 0) {
258                     for (int j = 0; j < configs.length; j++) {
259                         if (name.equalsIgnoreCase(configs[j].getConfigPropertyName())) {
260                             configs[j].setConfigPropertyValue(val);
261                             break;
262                         }
263                     }
264                 }
265             }
266         }
267         return configs;
268     }
269
270     /**
271      *
272      * @param inp String
273      * @return boolean
274      */

275     private boolean checkLogEnabled(String JavaDoc inp) {
276         if (inp.equals("1") || inp.equalsIgnoreCase("on")
277             || inp.equalsIgnoreCase("t") || inp.equalsIgnoreCase("true")
278             || inp.equalsIgnoreCase("y") || inp.equalsIgnoreCase("yes")) {
279             return true;
280         }
281          return false;
282     }
283
284     /**
285      *
286      * @param trans String
287      * @param tm TransactionManager
288      * @param logger Logger
289      * @param poolLogger Logger
290      * @return ConnectionManager
291      * @throws Exception any exception
292      */

293     public ConnectionManager JavaDoc createConnectionManager(String JavaDoc trans,
294                                                      TransactionManager tm,
295                                                      Logger logger,
296                                                      Logger poolLogger)
297            throws Exception JavaDoc {
298
299         ConnectionManagerImpl cm = new ConnectionManagerImpl(trans);
300
301         Context JavaDoc c = new CompNamingContext("");
302         c.rebind(ConnectionManagerImpl.TRANSACTION_MANAGER, tm);
303         c.rebind(ConnectionManagerImpl.RESOURCE_MANAGER_EVENT_LISTENER, tm);
304
305         // Set the MonologFactory into context of initialisation
306
c.rebind(ConnectionManagerImpl.LOGGER, logger);
307         c.rebind(ConnectionManagerImpl.POOL_LOGGER, poolLogger);
308
309         // Initialize the ConnectionManager with the configured Context
310
cm.init(c);
311         return cm;
312     }
313
314     /**
315      * Process the ManagedConnectionFactory object
316      *
317      * @param conn ConnectorDesc
318      * @param jonasConn JonasConnectorDesc
319      * @param cm ConnectionManager
320      * @param curLoader ClassLoader
321      * @param rarName String
322      * @param mcfc String
323      * @param jndiName String
324      * @param logEnabled String
325      * @param logTopic String
326      * @param cfgRaJonas ConfigPropertyDesc array
327      * @param resAdp ResourceAdapter
328      * @param idOff int
329      * @return Object
330      * @throws Exception any exception
331      */

332     public Object JavaDoc processMCF(ConnectorDesc conn, JonasConnectorDesc jonasConn, ConnectionManager JavaDoc cm,
333                               ClassLoader JavaDoc curLoader, String JavaDoc rarName, String JavaDoc mcfc,
334                               String JavaDoc jndiName, String JavaDoc logEnabled, String JavaDoc logTopic,
335                               ConfigPropertyDesc [] cfgRaJonas, ResourceAdapter resAdp,
336                               int idOff) throws Exception JavaDoc {
337
338         if (mcfc == null) {
339             logger.log(BasicLevel.ERROR, "ResourceService.createRA:"
340                        + " managedconnectionfactoryclass property not found");
341             throw new Exception JavaDoc("configuration file incorrect");
342         }
343
344         if (jndiName == null || jndiName.length() == 0) {
345             logger.log(BasicLevel.ERROR, "ResourceService.createRA: jndi-name not set in jonas-ra.xml");
346             throw new Exception JavaDoc("configuration file incorrect");
347         }
348
349         // Instantiate into the currect loader
350
Class JavaDoc mcfClass = curLoader.loadClass(mcfc);
351         ManagedConnectionFactory JavaDoc mcf =
352             (ManagedConnectionFactory JavaDoc) mcfClass.newInstance();
353
354         if (resAdp != null) {
355             try {
356                 ((ResourceAdapterAssociation JavaDoc) mcf).setResourceAdapter(resAdp);
357             } catch (ClassCastException JavaDoc ce) {
358                 // Not able to associate ResourceAdapter to MCF
359
} catch (Exception JavaDoc ex) {
360                 logger.log(BasicLevel.ERROR, "ResourceService: Error setting ResourceAdapter class to ManagedConnectionFactory ("
361                            + mcfc + ") for " + jndiName);
362                 throw ex;
363             }
364         }
365
366         if (logger.isLoggable(BasicLevel.DEBUG)) {
367             logger.log(BasicLevel.DEBUG, "jndiName=" + jndiName);
368         }
369
370         // Check if logging desired and the value of the desired topic
371
if (logEnabled != null) {
372             if (logger.isLoggable(BasicLevel.DEBUG)) {
373                 logger.log(BasicLevel.DEBUG, "log-enabled=" + logEnabled);
374             }
375             if (checkLogEnabled(logEnabled)) {
376                 if (logTopic != null && logTopic.length() > 0) {
377                     if (logger.isLoggable(BasicLevel.DEBUG)) {
378                         logger.log(BasicLevel.DEBUG, "log-topic=" + logTopic);
379                     }
380                     mcf.setLogWriter(Log.getLogWriter(logTopic));
381                 } else {
382                     if (logger.isLoggable(BasicLevel.DEBUG)) {
383                         logger.log(BasicLevel.DEBUG, "default log-topic=" + Log.JONAS_JCA_PREFIX);
384                     }
385                     mcf.setLogWriter(Log.getLogWriter(Log.JONAS_JCA_PREFIX)); // "org.objectweb.jonas.jca"
386
}
387             }
388         }
389
390         processSetters(mcfClass, mcf, rarName, cfgRaJonas);
391
392         PrintWriter JavaDoc pw = mcf.getLogWriter();
393         if (pw != null) {
394             //Create a date format
395
SimpleDateFormat JavaDoc sdf = new SimpleDateFormat JavaDoc("yyyy.MM.dd HH:mm:ss z");
396             String JavaDoc date = sdf.format(new Date JavaDoc());
397             pw.println("MCF: output starting at " + date);
398             pw.flush();
399         }
400
401         // Set hashCode for ManagedConnectionFactory
402
mcf.hashCode();
403
404         return mcf;
405     }
406
407
408     /**
409      *
410      * @param cf Referenceable
411      * @param jndiName String
412      * @param rarName String
413      * @param conn ConnectorDesc
414      * @param jonasConn JonasConnectorDesc
415      * @param factType String factory type
416      * @param factOffset int factory offset
417      * @param jcaResourceMBean JCAResource
418      * @param jcaResourceName String
419      * @param jDomain String of JOnAS domain name
420      * @param jServer String of JOnAS server name
421      * @param ictx Context
422      * @param prop Properties
423      * @throws Exception any Exception
424      */

425     public void registerMBean(Referenceable JavaDoc cf, String JavaDoc jndiName, String JavaDoc rarName,
426                               ConnectorDesc conn, JonasConnectorDesc jonasConn,
427                               String JavaDoc factType, int factOffset,
428                               JCAResource jcaResourceMBean, String JavaDoc jcaResourceName,
429                               String JavaDoc jDomain, String JavaDoc jServer, Context JavaDoc ictx, Properties JavaDoc prop,
430                               String JavaDoc description, ConnectionManagerImpl cm) throws Exception JavaDoc {
431
432         try {
433             Reference JavaDoc ref =
434                 new Reference JavaDoc(cf.getClass().getName(),
435                               ResourceObjectJNDIHandler.class.getName(),
436                               null);
437
438             ref.add(new StringRefAddr JavaDoc(ResourceServiceImpl.JNDI_NAME, jndiName));
439             ref.add(new StringRefAddr JavaDoc(ResourceServiceImpl.RAR_OBJNAME, rarName));
440             ref.add(new StringRefAddr JavaDoc(ResourceServiceImpl.FACTORY_TYPE, factType));
441             ref.add(new StringRefAddr JavaDoc(ResourceServiceImpl.FACTORY_OFFSET, "" + factOffset));
442             //Put the connector objects
443
byte[] bytes = JNDIUtils.getBytesFromObject(conn);
444             if (bytes != null) {
445                 ref.add(new BinaryRefAddr JavaDoc(ResourceServiceImpl.RA_XML, bytes));
446             }
447
448             bytes = JNDIUtils.getBytesFromObject(jonasConn);
449             if (bytes != null) {
450                 ref.add(new BinaryRefAddr JavaDoc(ResourceServiceImpl.JONAS_RA_XML, bytes));
451             }
452
453             cf.setReference(ref);
454             ictx.rebind(jndiName, cf);
455
456         } catch (Exception JavaDoc e) {
457             logger.log(BasicLevel.ERROR, "ResourceService: Cannot register ResourceAdapter in naming with the name " + jndiName);
458             logger.log(BasicLevel.ERROR, "ResourceService: Exception caught : " + e);
459         }
460
461         // --------------------------
462
// Register MBeans cf. JSR 77
463
// --------------------------
464
if (mbeanServer != null) {
465
466             // Available ConnectionFactories and ManagedConnectionFactories
467
// ------------------------------------------------------------
468
// ConnectionFactory MBean
469
// -----------------------
470
String JavaDoc jcaConnectionFactoryName = jndiName;
471             ObjectName JavaDoc onJCAConnectionFactory =
472                 J2eeObjectName.getJCAConnectionFactory(jDomain,
473                                                        jcaResourceName,
474                                                        jServer,
475                                                        jcaConnectionFactoryName);
476             JCAConnectionFactory jcaConnectionFactoryMBean = new JCAConnectionFactory(onJCAConnectionFactory.toString(), jndiName, prop, description, cm);
477             ManagedBean oManaged = oRegistry.findManagedBean("JCAConnectionFactory");
478             ModelMBean JavaDoc oMBean = oManaged.createMBean(jcaConnectionFactoryMBean);
479             if (manageLogger.isLoggable(BasicLevel.DEBUG)) {
480                 manageLogger.log(BasicLevel.DEBUG, "JCAConnectionFactory created");
481             }
482             mbeanServer.registerMBean(oMBean, onJCAConnectionFactory);
483
484             // Update the list of connection factories in the JCAResource MBean with the JCAConnectionFactory
485
// MBean's OBJECT_NAME
486
jcaResourceMBean.setConnectionFactory(onJCAConnectionFactory.toString());
487
488             // ManagedConnectionFactory MBean
489
// ------------------------------
490
String JavaDoc jcaManagedConnectionFactoryName = getJcaMcfName(jcaConnectionFactoryName);
491             ObjectName JavaDoc onJCAManagedConnectionFactory =
492                 J2eeObjectName.getJCAManagedConnectionFactory(jDomain,
493                                                        jServer,
494                                                        jcaManagedConnectionFactoryName);
495             JCAManagedConnectionFactory jcaManagedConnectionFactoryMBean =
496                 new JCAManagedConnectionFactory(onJCAManagedConnectionFactory.toString());
497             oManaged = oRegistry.findManagedBean("JCAManagedConnectionFactory");
498             oMBean = oManaged.createMBean(jcaManagedConnectionFactoryMBean);
499             if (manageLogger.isLoggable(BasicLevel.DEBUG)) {
500                 manageLogger.log(BasicLevel.DEBUG, "JCAManagedConnectionFactory created");
501             }
502             mbeanServer.registerMBean(oMBean, onJCAManagedConnectionFactory);
503
504             // Update the JCA ConnectionFactory with the JCA ManagedConnectionFactory
505
jcaConnectionFactoryMBean.setManagedConnectionFactory(onJCAManagedConnectionFactory.toString());
506             if (manageLogger.isLoggable(BasicLevel.DEBUG)) {
507                 manageLogger.log(BasicLevel.DEBUG, "JCAConnectionFactory updated");
508             }
509         } // end JMX registration
510
}
511
512
513     /**
514      *
515      * @param clsClass Class
516      * @param clsObj Object
517      * @param rarFileName String
518      * @param cProp ConfigPropertyDesc array
519      * @throws Exception any exception
520      */

521     public void processSetters(Class JavaDoc clsClass, Object JavaDoc clsObj, String JavaDoc rarFileName,
522                                ConfigPropertyDesc [] cProp) throws Exception JavaDoc {
523
524         int curParam = 0;
525         while (cProp != null && curParam < cProp.length) {
526             String JavaDoc fieldName = cProp[curParam].getConfigPropertyName();
527             String JavaDoc methodName = "set" + fieldName.substring(0, 1).toUpperCase()
528                                 + fieldName.substring(1);
529             String JavaDoc fieldType = cProp[curParam].getConfigPropertyType();
530             Method JavaDoc[] m = clsClass.getMethods();
531
532             int i = 0;
533             while (i < m.length
534                    && (!m[i].getName().equals(methodName)
535                        || m[i].getParameterTypes().length != 1
536                        || (fieldType != null
537                            && !(m[i].getParameterTypes())[0].getName().equals(fieldType)))
538                    ) {
539                 i++;
540             }
541             if (i < m.length) {
542                 Class JavaDoc [] paramtype = m[i].getParameterTypes();
543                 Object JavaDoc[] param = new Object JavaDoc[1];
544
545                 String JavaDoc curValue = cProp[curParam].getConfigPropertyValue();
546                 if (setterLogger.isLoggable(BasicLevel.DEBUG)) {
547                     setterLogger.log(BasicLevel.DEBUG, "Processing Field Name: " + fieldName
548                             + " Type: " + fieldType + " Value: " + curValue);
549                 }
550
551                 if (paramtype[0].equals(java.lang.Integer.TYPE)
552                     || paramtype[0].equals(java.lang.Integer JavaDoc.class)) {
553                     param[0] = new Integer JavaDoc(curValue);
554
555                 } else if (paramtype[0].equals(java.lang.Boolean.TYPE)
556                            || paramtype[0].equals(java.lang.Boolean JavaDoc.class)) {
557                     param[0] = new Boolean JavaDoc(curValue);
558
559                 } else if (paramtype[0].equals(java.lang.Double.TYPE)
560                            || paramtype[0].equals(java.lang.Double JavaDoc.class)) {
561                     param[0] = new Double JavaDoc(curValue);
562
563                 } else if (paramtype[0].equals(java.lang.Byte.TYPE)
564                            || paramtype[0].equals(java.lang.Byte JavaDoc.class)) {
565                     param[0] = new Byte JavaDoc(curValue);
566
567                 } else if (paramtype[0].equals(java.lang.Short.TYPE)
568                            || paramtype[0].equals(java.lang.Short JavaDoc.class)) {
569                     param[0] = new Short JavaDoc(curValue);
570
571                 } else if (paramtype[0].equals(java.lang.Long.TYPE)
572                            || paramtype[0].equals(java.lang.Long JavaDoc.class)) {
573                     param[0] = new Long JavaDoc(curValue);
574
575                 } else if (paramtype[0].equals(java.lang.Float.TYPE)
576                            || paramtype[0].equals(java.lang.Float JavaDoc.class)) {
577                     param[0] = new Float JavaDoc(curValue);
578
579                 } else if (paramtype[0].equals(java.lang.Character.TYPE)
580                            || paramtype[0].equals(java.lang.Character JavaDoc.class)) {
581                     param[0] = new Character JavaDoc(curValue.charAt(0));
582
583                 } else if (paramtype[0].equals(java.lang.String JavaDoc.class)) {
584                     param[0] = curValue;
585                     if (setterLogger.isLoggable(BasicLevel.DEBUG)) {
586                         setterLogger.log(BasicLevel.DEBUG, "Calling String method with " + curValue);
587                     }
588
589                 } else {
590                     logger.log(BasicLevel.ERROR, "Type unsupported for setter method:"
591                                 + methodName);
592                     throw new Exception JavaDoc("incorrect type for setter method ");
593                 }
594                 // invocation of the corresponding setter method on
595
// class object instance
596
try {
597                     m[i].invoke(clsObj, param);
598                 } catch (Exception JavaDoc e) {
599                     if (logger.isLoggable(BasicLevel.DEBUG)) {
600                         logger.log(BasicLevel.DEBUG, "method "
601                                 + methodName
602                                 + " not found for " + rarFileName + "check its configuration ");
603                     }
604                 }
605                 curParam++;
606             } else {
607                 logger.log(BasicLevel.ERROR, "Method not found in class '" + clsClass + "': " + methodName);
608                 throw new Exception JavaDoc("method name '" + methodName + "' not found in class '" + clsClass + "'");
609             }
610         }
611     }
612
613     /**
614      * set the PoolParams from the JonasConnector specified
615      * @param pParams PoolParamsDesc
616      * @param jConnParams JdbcConnParamsDesc
617      * @param pool ConnectionManagerPoolParams
618      * @return ConnectionManagerPoolParams
619      * @throws Exception any exception
620      */

621     public ConnectionManagerPoolParams configurePoolParams (PoolParamsDesc pParams,
622                                                             JdbcConnParamsDesc jConnParams,
623                                                             ConnectionManagerPoolParams pool)
624                throws Exception JavaDoc {
625
626         ConnectionManagerPoolParams cmpp = null;
627         if (pool == null) {
628             cmpp = new ConnectionManagerPoolParams();
629         } else {
630             cmpp = new ConnectionManagerPoolParams(pool);
631         }
632         String JavaDoc tmpPool = null;
633         try {
634             if (pParams != null) {
635                 if (pParams.getPoolInit() != null) {
636                     tmpPool = pParams.getPoolInit();
637                     if (tmpPool != null && tmpPool.length() > 0) {
638                         cmpp.setPoolInit(Integer.parseInt(tmpPool));
639                     }
640                 }
641                 if (pParams.getPoolMin() != null) {
642                     tmpPool = pParams.getPoolMin();
643                     if (tmpPool != null && tmpPool.length() > 0) {
644                         cmpp.setPoolMin(Integer.parseInt(tmpPool));
645                     }
646                 }
647                 if (pParams.getPoolMax() != null) {
648                     tmpPool = pParams.getPoolMax();
649                     if (tmpPool != null && tmpPool.length() > 0) {
650                         cmpp.setPoolMax(Integer.parseInt(tmpPool));
651                     }
652                 }
653                 if (pParams.getPoolMaxAge() != null) {
654                     tmpPool = pParams.getPoolMaxAge();
655                     if (tmpPool != null && tmpPool.length() > 0) {
656                         cmpp.setPoolMaxAge(Long.parseLong(tmpPool));
657                     }
658                 }
659                 if (pParams.getPoolMaxAgeMinutes() != null) {
660                     tmpPool = pParams.getPoolMaxAgeMinutes();
661                     if (tmpPool != null && tmpPool.length() > 0) {
662                         cmpp.setPoolMaxAgeMinutes(Integer.parseInt(tmpPool));
663                     }
664                 }
665                 if (pParams.getPoolMaxOpentime() != null) {
666                     tmpPool = pParams.getPoolMaxOpentime();
667                     if (tmpPool != null && tmpPool.length() > 0) {
668                         cmpp.setPoolMaxOpentime(Integer.parseInt(tmpPool));
669                     }
670                 }
671                 if (pParams.getPoolMaxWaiters() != null) {
672                     tmpPool = pParams.getPoolMaxWaiters();
673                     if (tmpPool != null && tmpPool.length() > 0) {
674                         cmpp.setPoolMaxWaiters(Integer.parseInt(tmpPool));
675                     }
676                 }
677                 if (pParams.getPoolMaxWaittime() != null) {
678                     tmpPool = pParams.getPoolMaxWaittime();
679                     if (tmpPool != null && tmpPool.length() > 0) {
680                         cmpp.setPoolMaxWaittime(Integer.parseInt(tmpPool));
681                     }
682                 }
683                 if (pParams.getPoolSamplingPeriod() != null) {
684                     tmpPool = pParams.getPoolSamplingPeriod();
685                     if (tmpPool != null && tmpPool.length() > 0) {
686                         cmpp.setPoolSamplingPeriod(Integer.parseInt(tmpPool));
687                     }
688                 }
689                 if (pParams.getPstmtMax() != null) {
690                     tmpPool = pParams.getPstmtMax();
691                     if (tmpPool != null && tmpPool.length() > 0) {
692                         cmpp.setPstmtMax(Integer.parseInt(tmpPool));
693                     }
694                 }
695             }
696            if (jConnParams != null) {
697                 if (jConnParams.getJdbcCheckLevel() != null) {
698                     tmpPool = jConnParams.getJdbcCheckLevel();
699                     if (tmpPool != null && tmpPool.length() > 0) {
700                         cmpp.setJdbcConnLevel(Integer.parseInt(tmpPool));
701                     }
702                 }
703                 if (jConnParams.getJdbcTestStatement() != null) {
704                     cmpp.setJdbcConnTestStmt(jConnParams.getJdbcTestStatement());
705                 }
706             }
707         } catch (Exception JavaDoc ex) {
708             ex.printStackTrace();
709             logger.log(BasicLevel.ERROR, "Invalid Pool parameter from jonas-ra.xml: Ensure that numeric values are used. " + tmpPool);
710             throw new Exception JavaDoc("incorrect pool parameter ");
711         }
712         return cmpp;
713     }
714
715     /**
716      * Return the parsed XML object relative to the section
717      *
718      * @param jonasConn JonasConnectorDesc object
719      * @param id String id of the section
720      * @param idOffset int offset within the section
721      * @param oType String type of section
722      * @return Object of parsed XML object
723      */

724     public Object JavaDoc getJonasXML(JonasConnectorDesc jonasConn,
725                               String JavaDoc id, int idOffset, String JavaDoc oType) {
726         Object JavaDoc obj = null;
727         if (oType == JCD) {
728             obj = jonasConn.getJonasConnectionDefinitionList().get(idOffset);
729         } else if (oType == JAS) {
730             obj = jonasConn.getJonasActivationspecList().get(idOffset);
731         } else if (oType == JAO) {
732             obj = jonasConn.getJonasAdminobjectList().get(idOffset);
733         }
734         return obj;
735     }
736
737     /**
738      * Return the JCA Managed Connection Factory name
739      * @param jndiName String of jndi name
740      * @return String of JCA Managed Connection Factory name
741      */

742     public String JavaDoc getJcaMcfName(String JavaDoc jndiName) {
743         return jndiName;
744     }
745 }
746
Popular Tags