Source Code Cross Referenced for ResourceUtility.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » resource » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.resource 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: ResourceUtility.java 9932 2007-01-18 00:03:16Z ehardesty $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas.resource;
025:
026:        import java.io.PrintWriter;
027:        import java.lang.reflect.Method;
028:        import java.text.SimpleDateFormat;
029:        import java.util.Date;
030:        import java.util.Iterator;
031:        import java.util.List;
032:        import java.util.Properties;
033:        import java.util.Vector;
034:
035:        import javax.management.MBeanServer;
036:        import javax.management.ObjectName;
037:        import javax.management.modelmbean.ModelMBean;
038:        import javax.naming.BinaryRefAddr;
039:        import javax.naming.Context;
040:        import javax.naming.Reference;
041:        import javax.naming.StringRefAddr;
042:        import javax.resource.Referenceable;
043:        import javax.resource.spi.ConnectionManager;
044:        import javax.resource.spi.ManagedConnectionFactory;
045:        import javax.resource.spi.ResourceAdapter;
046:        import javax.resource.spi.ResourceAdapterAssociation;
047:
048:        import org.apache.commons.modeler.ManagedBean;
049:        import org.apache.commons.modeler.Registry;
050:        import org.objectweb.jonas.common.JNDIUtils;
051:        import org.objectweb.jonas.common.Log;
052:        import org.objectweb.jonas.jmx.J2eeObjectName;
053:        import org.objectweb.jonas.naming.CompNamingContext;
054:        import org.objectweb.jonas_ejb.deployment.api.ActivationConfigPropertyDesc;
055:        import org.objectweb.jonas_rar.deployment.api.ConfigPropertyDesc;
056:        import org.objectweb.jonas_rar.deployment.api.ConnectorDesc;
057:        import org.objectweb.jonas_rar.deployment.api.JdbcConnParamsDesc;
058:        import org.objectweb.jonas_rar.deployment.api.JonasConfigPropertyDesc;
059:        import org.objectweb.jonas_rar.deployment.api.JonasConnectorDesc;
060:        import org.objectweb.jonas_rar.deployment.api.PoolParamsDesc;
061:        import org.objectweb.transaction.jta.TransactionManager;
062:        import org.objectweb.util.monolog.api.BasicLevel;
063:        import org.objectweb.util.monolog.api.Logger;
064:
065:        /**
066:         * ResourceUtility class
067:         * @author Eric Hardesty
068:         * Contributor(s):
069:         *
070:         */
071:
072:        public class ResourceUtility {
073:
074:            /**
075:             * Main logger
076:             */
077:            private static Logger logger = null;
078:            /**
079:             * Config property setter logger
080:             */
081:            private static Logger setterLogger = null;
082:            /**
083:             * Management logger
084:             */
085:            private static Logger manageLogger = null;
086:
087:            /**
088:             * Reference to a Registry object
089:             */
090:            private Registry oRegistry = null;
091:
092:            /**
093:             * Reference to a MBean server.
094:             */
095:            private MBeanServer mbeanServer = null;
096:
097:            // Properties for inits
098:
099:            /**
100:             * JOnAS Connection Definition
101:             */
102:            public static final String JCD = "JCD";
103:            /**
104:             * JOnAS Activationspec
105:             */
106:            public static final String JAS = "JAS";
107:            /**
108:             * JOnAS Administrated Object
109:             */
110:            public static final String JAO = "JAO";
111:
112:            /**
113:             * Default constructor
114:             *
115:             */
116:            public ResourceUtility() {
117:            }
118:
119:            /**
120:             * Constructor
121:             *
122:             * @param mbeanServer MBeanServer object
123:             * @param oRegistry Registry object
124:             * @param log Logger main logger
125:             * @param sLog Logger setter logger
126:             * @param mLog Logger management logger
127:             */
128:            public ResourceUtility(MBeanServer mbeanServer, Registry oRegistry,
129:                    Logger log, Logger sLog, Logger mLog) {
130:                this .mbeanServer = mbeanServer;
131:                this .oRegistry = oRegistry;
132:                logger = log;
133:                setterLogger = sLog;
134:                manageLogger = mLog;
135:            }
136:
137:            /**
138:             *
139:             * @param raCfg List
140:             * @param jRaCfg1 List
141:             * @param jRaCfg2 List
142:             * @return ConfigPropertyDesc array
143:             */
144:            public ConfigPropertyDesc[] buildConfigProperty(List raCfg,
145:                    List jRaCfg1, List jRaCfg2) {
146:                Vector cfVec = null;
147:                ConfigPropertyDesc[] configs = null;
148:
149:                // Global config parameters for the Resource adapter
150:                if (raCfg != null) {
151:                    for (Iterator i = raCfg.iterator(); i.hasNext();) {
152:                        if (cfVec == null) {
153:                            cfVec = new Vector();
154:                        }
155:                        cfVec.add(new ConfigPropertyDesc((ConfigPropertyDesc) i
156:                                .next()));
157:                    }
158:                } else { //Special case for configuring ActivationSpecs
159:                    ActivationConfigPropertyDesc acp = null;
160:                    ConfigPropertyDesc cp = null;
161:                    if (jRaCfg1 != null) {
162:                        for (Iterator i = jRaCfg1.iterator(); i.hasNext();) {
163:                            if (cfVec == null) {
164:                                cfVec = new Vector();
165:                            }
166:                            acp = (ActivationConfigPropertyDesc) i.next();
167:                            cp = new ConfigPropertyDesc();
168:                            cp.setConfigPropertyName(acp
169:                                    .getActivationConfigPropertyName());
170:                            cp.setConfigPropertyValue(acp
171:                                    .getActivationConfigPropertyValue());
172:                            cfVec.add(cp);
173:                        }
174:                    }
175:
176:                    if (cfVec == null) {
177:                        if (jRaCfg2 != null) {
178:                            for (Iterator i = jRaCfg2.iterator(); i.hasNext();) {
179:                                if (cfVec == null) {
180:                                    cfVec = new Vector();
181:                                }
182:                                acp = (ActivationConfigPropertyDesc) i.next();
183:                                cp = new ConfigPropertyDesc();
184:                                cp.setConfigPropertyName(acp
185:                                        .getActivationConfigPropertyName());
186:                                cp.setConfigPropertyValue(acp
187:                                        .getActivationConfigPropertyValue());
188:                                cfVec.add(cp);
189:                            }
190:                            if (cfVec != null) {
191:                                configs = new ConfigPropertyDesc[cfVec.size()];
192:                                cfVec.copyInto(configs);
193:                            }
194:                        }
195:                    } else {
196:                        if (jRaCfg2 != null) {
197:                            boolean found = false;
198:                            for (Iterator i = jRaCfg2.iterator(); i.hasNext();) {
199:                                found = false;
200:                                acp = (ActivationConfigPropertyDesc) i.next();
201:                                String name = acp
202:                                        .getActivationConfigPropertyName();
203:                                String val = acp
204:                                        .getActivationConfigPropertyValue();
205:                                if (val != null && val.length() > 0) {
206:                                    for (int j = 0; j < cfVec.size(); j++) {
207:                                        cp = (ConfigPropertyDesc) cfVec.get(j);
208:                                        if (name.equalsIgnoreCase(cp
209:                                                .getConfigPropertyName())) {
210:                                            cp.setConfigPropertyValue(val);
211:                                            cfVec.set(j, cp);
212:                                            found = true;
213:                                            break;
214:                                        }
215:                                    }
216:                                    // This is the case where a new activation-config property is in
217:                                    // the jonas specific dd
218:                                    if (!found) {
219:                                        cp = new ConfigPropertyDesc();
220:                                        cp.setConfigPropertyName(name);
221:                                        cp.setConfigPropertyValue(val);
222:                                        cfVec.add(cp);
223:                                    }
224:                                }
225:                            }
226:                        }
227:                        configs = new ConfigPropertyDesc[cfVec.size()];
228:                        cfVec.copyInto(configs);
229:                    }
230:
231:                    if (cfVec == null) {
232:                        return null;
233:                    }
234:                    return configs;
235:                }
236:
237:                if (cfVec == null) {
238:                    return null;
239:                }
240:
241:                configs = new ConfigPropertyDesc[cfVec.size()];
242:                cfVec.copyInto(configs);
243:
244:                JonasConfigPropertyDesc jcpNext = null;
245:                if (jRaCfg2 != null) {
246:                    for (Iterator i = jRaCfg2.iterator(); i.hasNext();) {
247:                        jcpNext = (JonasConfigPropertyDesc) i.next();
248:                        String name = jcpNext.getJonasConfigPropertyName();
249:                        String val = jcpNext.getJonasConfigPropertyValue();
250:                        if (val != null && val.length() > 0) {
251:                            for (int j = 0; j < configs.length; j++) {
252:                                if (name.equalsIgnoreCase(configs[j]
253:                                        .getConfigPropertyName())) {
254:                                    configs[j].setConfigPropertyValue(val);
255:                                    break;
256:                                }
257:                            }
258:                        }
259:                    }
260:                }
261:
262:                if (jRaCfg1 != null) {
263:                    for (Iterator i = jRaCfg1.iterator(); i.hasNext();) {
264:                        jcpNext = (JonasConfigPropertyDesc) i.next();
265:                        String name = jcpNext.getJonasConfigPropertyName();
266:                        String val = jcpNext.getJonasConfigPropertyValue();
267:                        if (val != null && val.length() > 0) {
268:                            for (int j = 0; j < configs.length; j++) {
269:                                if (name.equalsIgnoreCase(configs[j]
270:                                        .getConfigPropertyName())) {
271:                                    configs[j].setConfigPropertyValue(val);
272:                                    break;
273:                                }
274:                            }
275:                        }
276:                    }
277:                }
278:                return configs;
279:            }
280:
281:            /**
282:             *
283:             * @param inp String
284:             * @return boolean
285:             */
286:            private boolean checkLogEnabled(String inp) {
287:                if (inp.equals("1") || inp.equalsIgnoreCase("on")
288:                        || inp.equalsIgnoreCase("t")
289:                        || inp.equalsIgnoreCase("true")
290:                        || inp.equalsIgnoreCase("y")
291:                        || inp.equalsIgnoreCase("yes")) {
292:                    return true;
293:                }
294:                return false;
295:            }
296:
297:            /**
298:             *
299:             * @param trans String
300:             * @param tm TransactionManager
301:             * @param logger Logger
302:             * @param poolLogger Logger
303:             * @param jndiName String
304:             * @return ConnectionManager
305:             * @throws Exception any exception
306:             */
307:            public ConnectionManager createConnectionManager(String trans,
308:                    TransactionManager tm, Logger logger, Logger poolLogger,
309:                    String jndiName) throws Exception {
310:
311:                ConnectionManagerImpl cm = new ConnectionManagerImpl(trans);
312:
313:                Context c = new CompNamingContext("");
314:                c.rebind(ConnectionManagerImpl.TRANSACTION_MANAGER, tm);
315:                c.rebind(ConnectionManagerImpl.RESOURCE_MANAGER_EVENT_LISTENER,
316:                        tm);
317:
318:                // Set the MonologFactory into context of initialisation
319:                c.rebind(ConnectionManagerImpl.LOGGER, logger);
320:                c.rebind(ConnectionManagerImpl.POOL_LOGGER, poolLogger);
321:                c.rebind(ConnectionManagerImpl.JNDINAME, jndiName);
322:
323:                // Initialize the ConnectionManager with the configured Context
324:                cm.init(c);
325:                return cm;
326:            }
327:
328:            /**
329:             * Process the ManagedConnectionFactory object
330:             *
331:             * @param conn ConnectorDesc
332:             * @param jonasConn JonasConnectorDesc
333:             * @param cm ConnectionManager
334:             * @param curLoader ClassLoader
335:             * @param rarName String
336:             * @param mcfc String
337:             * @param jndiName String
338:             * @param logEnabled String
339:             * @param logTopic String
340:             * @param cfgRaJonas ConfigPropertyDesc array
341:             * @param resAdp ResourceAdapter
342:             * @param idOff int
343:             * @return Object
344:             * @throws Exception any exception
345:             */
346:            public Object processMCF(ConnectorDesc conn,
347:                    JonasConnectorDesc jonasConn, ConnectionManager cm,
348:                    ClassLoader curLoader, String rarName, String mcfc,
349:                    String jndiName, String logEnabled, String logTopic,
350:                    ConfigPropertyDesc[] cfgRaJonas, ResourceAdapter resAdp,
351:                    int idOff) throws Exception {
352:
353:                if (mcfc == null) {
354:                    logger
355:                            .log(
356:                                    BasicLevel.ERROR,
357:                                    "ResourceService.createRA:"
358:                                            + " managedconnectionfactoryclass property not found");
359:                    throw new Exception("configuration file incorrect");
360:                }
361:
362:                if (jndiName == null || jndiName.length() == 0) {
363:                    logger
364:                            .log(BasicLevel.ERROR,
365:                                    "ResourceService.createRA: jndi-name not set in jonas-ra.xml");
366:                    throw new Exception("configuration file incorrect");
367:                }
368:
369:                // Instantiate into the currect loader
370:                Class mcfClass = curLoader.loadClass(mcfc);
371:                ManagedConnectionFactory mcf = (ManagedConnectionFactory) mcfClass
372:                        .newInstance();
373:
374:                if (resAdp != null) {
375:                    try {
376:                        ((ResourceAdapterAssociation) mcf)
377:                                .setResourceAdapter(resAdp);
378:                    } catch (ClassCastException ce) {
379:                        // Not able to associate ResourceAdapter to MCF
380:                    } catch (Exception ex) {
381:                        logger
382:                                .log(
383:                                        BasicLevel.ERROR,
384:                                        "ResourceService: Error setting ResourceAdapter class to ManagedConnectionFactory ("
385:                                                + mcfc + ") for " + jndiName);
386:                        throw ex;
387:                    }
388:                }
389:
390:                if (logger.isLoggable(BasicLevel.DEBUG)) {
391:                    logger.log(BasicLevel.DEBUG, "jndiName=" + jndiName);
392:                }
393:
394:                // Check if logging desired and the value of the desired topic
395:                if (logEnabled != null) {
396:                    if (logger.isLoggable(BasicLevel.DEBUG)) {
397:                        logger.log(BasicLevel.DEBUG, "log-enabled="
398:                                + logEnabled);
399:                    }
400:                    if (checkLogEnabled(logEnabled)) {
401:                        if (logTopic != null && logTopic.length() > 0) {
402:                            if (logger.isLoggable(BasicLevel.DEBUG)) {
403:                                logger.log(BasicLevel.DEBUG, "log-topic="
404:                                        + logTopic);
405:                            }
406:                            mcf.setLogWriter(Log.getLogWriter(logTopic));
407:                        } else {
408:                            if (logger.isLoggable(BasicLevel.DEBUG)) {
409:                                logger.log(BasicLevel.DEBUG,
410:                                        "default log-topic="
411:                                                + Log.JONAS_JCA_PREFIX);
412:                            }
413:                            mcf.setLogWriter(Log
414:                                    .getLogWriter(Log.JONAS_JCA_PREFIX)); // "org.objectweb.jonas.jca"
415:                        }
416:                    }
417:                }
418:
419:                processSetters(mcfClass, mcf, rarName, cfgRaJonas);
420:
421:                PrintWriter pw = mcf.getLogWriter();
422:                if (pw != null) {
423:                    //Create a date format
424:                    SimpleDateFormat sdf = new SimpleDateFormat(
425:                            "yyyy.MM.dd HH:mm:ss z");
426:                    String date = sdf.format(new Date());
427:                    pw.println("MCF: output starting at " + date);
428:                    pw.flush();
429:                }
430:
431:                // Set hashCode for ManagedConnectionFactory
432:                try {
433:                    mcf.hashCode();
434:                } catch (Exception ex) {
435:                    String err = "Exception  in ManagedConnectionFactory.hashCode(): ";
436:                    logger.log(BasicLevel.ERROR, err + ex);
437:                }
438:
439:                return mcf;
440:            }
441:
442:            /**
443:             *
444:             * @param cf Referenceable
445:             * @param jndiName String
446:             * @param rarName String
447:             * @param conn ConnectorDesc
448:             * @param jonasConn JonasConnectorDesc
449:             * @param factType String factory type
450:             * @param factOffset int factory offset
451:             * @param jcaResourceMBean JCAResource
452:             * @param jcaResourceName String
453:             * @param jDomain String of JOnAS domain name
454:             * @param jServer String of JOnAS server name
455:             * @param ictx Context
456:             * @param prop Properties
457:             * @throws Exception any Exception
458:             */
459:            public void registerMBean(Referenceable cf, String jndiName,
460:                    String rarName, String rarFileName, ConnectorDesc conn,
461:                    JonasConnectorDesc jonasConn, String factType,
462:                    int factOffset, JCAResource jcaResourceMBean,
463:                    String jcaResourceName, String jDomain, String jServer,
464:                    Context ictx, Properties prop, String description,
465:                    ConnectionManagerImpl cm) throws Exception {
466:
467:                try {
468:                    Reference ref = new Reference(cf.getClass().getName(),
469:                            ResourceObjectJNDIHandler.class.getName(), null);
470:
471:                    ref.add(new StringRefAddr(ResourceServiceImpl.JNDI_NAME,
472:                            jndiName));
473:                    ref.add(new StringRefAddr(ResourceServiceImpl.RAR_OBJNAME,
474:                            rarName));
475:                    ref.add(new StringRefAddr(ResourceServiceImpl.FACTORY_TYPE,
476:                            factType));
477:                    ref
478:                            .add(new StringRefAddr(
479:                                    ResourceServiceImpl.FACTORY_OFFSET, ""
480:                                            + factOffset));
481:                    //Put the connector objects
482:                    byte[] bytes = JNDIUtils.getBytesFromObject(conn);
483:                    if (bytes != null) {
484:                        ref.add(new BinaryRefAddr(ResourceServiceImpl.RA_XML,
485:                                bytes));
486:                    }
487:
488:                    bytes = JNDIUtils.getBytesFromObject(jonasConn);
489:                    if (bytes != null) {
490:                        ref.add(new BinaryRefAddr(
491:                                ResourceServiceImpl.JONAS_RA_XML, bytes));
492:                    }
493:
494:                    cf.setReference(ref);
495:                    ictx.rebind(jndiName, cf);
496:
497:                } catch (Exception e) {
498:                    logger.log(BasicLevel.ERROR,
499:                            "ResourceService: Cannot register ResourceAdapter in naming with the name "
500:                                    + jndiName);
501:                    logger.log(BasicLevel.ERROR,
502:                            "ResourceService: Exception caught : " + e);
503:                }
504:
505:                // --------------------------
506:                // Register MBeans cf. JSR 77
507:                // --------------------------
508:                if (mbeanServer != null) {
509:
510:                    // Available ConnectionFactories and ManagedConnectionFactories
511:                    // ------------------------------------------------------------
512:                    // ConnectionFactory MBean
513:                    // -----------------------
514:                    String jcaConnectionFactoryName = jndiName;
515:                    ObjectName onJCAConnectionFactory = J2eeObjectName
516:                            .getJCAConnectionFactory(jDomain, jcaResourceName,
517:                                    jServer, jcaConnectionFactoryName);
518:                    JCAConnectionFactory jcaConnectionFactoryMBean = new JCAConnectionFactory(
519:                            onJCAConnectionFactory.toString(), jndiName,
520:                            rarFileName, prop, description, cm);
521:                    ManagedBean oManaged = oRegistry
522:                            .findManagedBean("JCAConnectionFactory");
523:                    ModelMBean oMBean = oManaged
524:                            .createMBean(jcaConnectionFactoryMBean);
525:                    if (manageLogger.isLoggable(BasicLevel.DEBUG)) {
526:                        manageLogger.log(BasicLevel.DEBUG,
527:                                "JCAConnectionFactory created");
528:                    }
529:                    mbeanServer.registerMBean(oMBean, onJCAConnectionFactory);
530:
531:                    // Update the list of connection factories in the JCAResource MBean with the JCAConnectionFactory
532:                    // MBean's OBJECT_NAME
533:                    jcaResourceMBean
534:                            .setConnectionFactory(onJCAConnectionFactory
535:                                    .toString());
536:
537:                    // ManagedConnectionFactory MBean
538:                    // ------------------------------
539:                    String jcaManagedConnectionFactoryName = getJcaMcfName(jcaConnectionFactoryName);
540:                    ObjectName onJCAManagedConnectionFactory = J2eeObjectName
541:                            .getJCAManagedConnectionFactory(jDomain, jServer,
542:                                    jcaManagedConnectionFactoryName);
543:                    JCAManagedConnectionFactory jcaManagedConnectionFactoryMBean = new JCAManagedConnectionFactory(
544:                            onJCAManagedConnectionFactory.toString());
545:                    oManaged = oRegistry
546:                            .findManagedBean("JCAManagedConnectionFactory");
547:                    oMBean = oManaged
548:                            .createMBean(jcaManagedConnectionFactoryMBean);
549:                    if (manageLogger.isLoggable(BasicLevel.DEBUG)) {
550:                        manageLogger.log(BasicLevel.DEBUG,
551:                                "JCAManagedConnectionFactory created");
552:                    }
553:                    mbeanServer.registerMBean(oMBean,
554:                            onJCAManagedConnectionFactory);
555:
556:                    // Update the JCA ConnectionFactory with the JCA ManagedConnectionFactory
557:                    jcaConnectionFactoryMBean
558:                            .setManagedConnectionFactory(onJCAManagedConnectionFactory
559:                                    .toString());
560:                    if (manageLogger.isLoggable(BasicLevel.DEBUG)) {
561:                        manageLogger.log(BasicLevel.DEBUG,
562:                                "JCAConnectionFactory updated");
563:                    }
564:                } // end JMX registration
565:            }
566:
567:            /**
568:             *
569:             * @param clsClass Class
570:             * @param clsObj Object
571:             * @param rarFileName String
572:             * @param cProp ConfigPropertyDesc array
573:             * @throws Exception any exception
574:             */
575:            public void processSetters(Class clsClass, Object clsObj,
576:                    String rarFileName, ConfigPropertyDesc[] cProp)
577:                    throws Exception {
578:
579:                int curParam = 0;
580:                while (cProp != null && curParam < cProp.length) {
581:                    String fieldName = cProp[curParam].getConfigPropertyName();
582:                    String methodName = "set"
583:                            + fieldName.substring(0, 1).toUpperCase()
584:                            + fieldName.substring(1);
585:                    String fieldType = cProp[curParam].getConfigPropertyType();
586:                    Method[] m = clsClass.getMethods();
587:
588:                    int i = 0;
589:                    while (i < m.length
590:                            && (!m[i].getName().equals(methodName)
591:                                    || m[i].getParameterTypes().length != 1 || (fieldType != null && !(m[i]
592:                                    .getParameterTypes())[0].getName().equals(
593:                                    fieldType)))) {
594:                        i++;
595:                    }
596:                    if (i < m.length) {
597:                        Class[] paramtype = m[i].getParameterTypes();
598:                        Object[] param = new Object[1];
599:
600:                        String curValue = cProp[curParam]
601:                                .getConfigPropertyValue();
602:                        if (setterLogger.isLoggable(BasicLevel.DEBUG)) {
603:                            setterLogger.log(BasicLevel.DEBUG,
604:                                    "Processing Field Name: " + fieldName
605:                                            + " Type: " + fieldType
606:                                            + " Value: " + curValue);
607:                        }
608:
609:                        if (paramtype[0].equals(java.lang.Integer.TYPE)
610:                                || paramtype[0].equals(java.lang.Integer.class)) {
611:                            param[0] = new Integer(curValue);
612:
613:                        } else if (paramtype[0].equals(java.lang.Boolean.TYPE)
614:                                || paramtype[0].equals(java.lang.Boolean.class)) {
615:                            param[0] = new Boolean(curValue);
616:
617:                        } else if (paramtype[0].equals(java.lang.Double.TYPE)
618:                                || paramtype[0].equals(java.lang.Double.class)) {
619:                            param[0] = new Double(curValue);
620:
621:                        } else if (paramtype[0].equals(java.lang.Byte.TYPE)
622:                                || paramtype[0].equals(java.lang.Byte.class)) {
623:                            param[0] = new Byte(curValue);
624:
625:                        } else if (paramtype[0].equals(java.lang.Short.TYPE)
626:                                || paramtype[0].equals(java.lang.Short.class)) {
627:                            param[0] = new Short(curValue);
628:
629:                        } else if (paramtype[0].equals(java.lang.Long.TYPE)
630:                                || paramtype[0].equals(java.lang.Long.class)) {
631:                            param[0] = new Long(curValue);
632:
633:                        } else if (paramtype[0].equals(java.lang.Float.TYPE)
634:                                || paramtype[0].equals(java.lang.Float.class)) {
635:                            param[0] = new Float(curValue);
636:
637:                        } else if (paramtype[0]
638:                                .equals(java.lang.Character.TYPE)
639:                                || paramtype[0]
640:                                        .equals(java.lang.Character.class)) {
641:                            param[0] = new Character(curValue.charAt(0));
642:
643:                        } else if (paramtype[0].equals(java.lang.String.class)) {
644:                            param[0] = curValue;
645:                            if (setterLogger.isLoggable(BasicLevel.DEBUG)) {
646:                                setterLogger.log(BasicLevel.DEBUG,
647:                                        "Calling String method with "
648:                                                + curValue);
649:                            }
650:
651:                        } else {
652:                            logger.log(BasicLevel.ERROR,
653:                                    "Type unsupported for setter method:"
654:                                            + methodName);
655:                            throw new Exception(
656:                                    "incorrect type for setter method ");
657:                        }
658:                        // invocation of the corresponding setter method on
659:                        // class object instance
660:                        try {
661:                            m[i].invoke(clsObj, param);
662:                        } catch (Exception e) {
663:                            if (logger.isLoggable(BasicLevel.DEBUG)) {
664:                                logger.log(BasicLevel.DEBUG, "method "
665:                                        + methodName + " not found for "
666:                                        + rarFileName
667:                                        + "check its configuration ");
668:                            }
669:                        }
670:                        curParam++;
671:                    } else {
672:                        logger.log(BasicLevel.ERROR,
673:                                "Method not found in class '" + clsClass
674:                                        + "': " + methodName);
675:                        throw new Exception("method name '" + methodName
676:                                + "' not found in class '" + clsClass + "'");
677:                    }
678:                }
679:            }
680:
681:            /**
682:             * set the PoolParams from the JonasConnector specified
683:             * @param pParams PoolParamsDesc
684:             * @param jConnParams JdbcConnParamsDesc
685:             * @param pool ConnectionManagerPoolParams
686:             * @return ConnectionManagerPoolParams
687:             * @throws Exception any exception
688:             */
689:            public ConnectionManagerPoolParams configurePoolParams(
690:                    PoolParamsDesc pParams, JdbcConnParamsDesc jConnParams,
691:                    ConnectionManagerPoolParams pool) throws Exception {
692:
693:                ConnectionManagerPoolParams cmpp = null;
694:                if (pool == null) {
695:                    cmpp = new ConnectionManagerPoolParams();
696:                } else {
697:                    cmpp = new ConnectionManagerPoolParams(pool);
698:                }
699:                String tmpPool = null;
700:                try {
701:                    if (pParams != null) {
702:                        if (pParams.getPoolInit() != null) {
703:                            tmpPool = pParams.getPoolInit();
704:                            if (tmpPool != null && tmpPool.length() > 0) {
705:                                cmpp.setPoolInit(Integer.parseInt(tmpPool));
706:                            }
707:                        }
708:                        if (pParams.getPoolMin() != null) {
709:                            tmpPool = pParams.getPoolMin();
710:                            if (tmpPool != null && tmpPool.length() > 0) {
711:                                cmpp.setPoolMin(Integer.parseInt(tmpPool));
712:                            }
713:                        }
714:                        if (pParams.getPoolMax() != null) {
715:                            tmpPool = pParams.getPoolMax();
716:                            if (tmpPool != null && tmpPool.length() > 0) {
717:                                cmpp.setPoolMax(Integer.parseInt(tmpPool));
718:                            }
719:                        }
720:                        if (pParams.getPoolMaxAge() != null) {
721:                            tmpPool = pParams.getPoolMaxAge();
722:                            if (tmpPool != null && tmpPool.length() > 0) {
723:                                cmpp.setPoolMaxAge(Long.parseLong(tmpPool));
724:                            }
725:                        }
726:                        if (pParams.getPoolMaxAgeMinutes() != null) {
727:                            tmpPool = pParams.getPoolMaxAgeMinutes();
728:                            if (tmpPool != null && tmpPool.length() > 0) {
729:                                cmpp.setPoolMaxAgeMinutes(Integer
730:                                        .parseInt(tmpPool));
731:                            }
732:                        }
733:                        if (pParams.getPoolMaxOpentime() != null) {
734:                            tmpPool = pParams.getPoolMaxOpentime();
735:                            if (tmpPool != null && tmpPool.length() > 0) {
736:                                cmpp.setPoolMaxOpentime(Integer
737:                                        .parseInt(tmpPool));
738:                            }
739:                        }
740:                        if (pParams.getPoolMaxWaiters() != null) {
741:                            tmpPool = pParams.getPoolMaxWaiters();
742:                            if (tmpPool != null && tmpPool.length() > 0) {
743:                                cmpp.setPoolMaxWaiters(Integer
744:                                        .parseInt(tmpPool));
745:                            }
746:                        }
747:                        if (pParams.getPoolMaxWaittime() != null) {
748:                            tmpPool = pParams.getPoolMaxWaittime();
749:                            if (tmpPool != null && tmpPool.length() > 0) {
750:                                cmpp.setPoolMaxWaittime(Integer
751:                                        .parseInt(tmpPool));
752:                            }
753:                        }
754:                        if (pParams.getPoolSamplingPeriod() != null) {
755:                            tmpPool = pParams.getPoolSamplingPeriod();
756:                            if (tmpPool != null && tmpPool.length() > 0) {
757:                                cmpp.setPoolSamplingPeriod(Integer
758:                                        .parseInt(tmpPool));
759:                            }
760:                        }
761:                        if (pParams.getPstmtMax() != null) {
762:                            tmpPool = pParams.getPstmtMax();
763:                            if (tmpPool != null && tmpPool.length() > 0) {
764:                                cmpp.setPstmtMax(Integer.parseInt(tmpPool));
765:                            }
766:                        }
767:                    }
768:                    if (jConnParams != null) {
769:                        if (jConnParams.getJdbcCheckLevel() != null) {
770:                            tmpPool = jConnParams.getJdbcCheckLevel();
771:                            if (tmpPool != null && tmpPool.length() > 0) {
772:                                cmpp
773:                                        .setJdbcConnLevel(Integer
774:                                                .parseInt(tmpPool));
775:                            }
776:                        }
777:                        if (jConnParams.getJdbcTestStatement() != null) {
778:                            cmpp.setJdbcConnTestStmt(jConnParams
779:                                    .getJdbcTestStatement());
780:                        }
781:                    }
782:                } catch (Exception ex) {
783:                    ex.printStackTrace();
784:                    logger
785:                            .log(
786:                                    BasicLevel.ERROR,
787:                                    "Invalid Pool parameter from jonas-ra.xml:  Ensure that numeric values are used. "
788:                                            + tmpPool);
789:                    throw new Exception("incorrect pool parameter ");
790:                }
791:                return cmpp;
792:            }
793:
794:            /**
795:             * Return the parsed XML object relative to the section
796:             *
797:             * @param jonasConn JonasConnectorDesc object
798:             * @param id String id of the section
799:             * @param idOffset int offset within the section
800:             * @param oType String type of section
801:             * @return Object of parsed XML object
802:             * @throws Exception if the element is out of bound
803:             */
804:            public Object getJonasXML(JonasConnectorDesc jonasConn, String id,
805:                    int idOffset, String oType) throws Exception {
806:                try {
807:                    Object obj = null;
808:                    if (oType == JCD) {
809:                        obj = jonasConn.getJonasConnectionDefinitionList().get(
810:                                idOffset);
811:                    } else if (oType == JAS) {
812:                        obj = jonasConn.getJonasActivationspecList().get(
813:                                idOffset);
814:                    } else if (oType == JAO) {
815:                        obj = jonasConn.getJonasAdminobjectList().get(idOffset);
816:                    }
817:                    return obj;
818:                } catch (IndexOutOfBoundsException e) {
819:                    throw new Exception("Element " + oType + ", " + idOffset
820:                            + " is not found in the jonas-ra.xml", e);
821:                }
822:            }
823:
824:            /**
825:             * Return the JCA Managed Connection Factory name
826:             * @param jndiName String of jndi name
827:             * @return String of JCA Managed Connection Factory name
828:             */
829:            public String getJcaMcfName(String jndiName) {
830:                return jndiName;
831:            }
832:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.