KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > repository > IASJ2EEResourceFactoryImpl


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

24 package com.sun.enterprise.repository;
25
26 import java.util.*;
27 import java.io.*;
28 import com.sun.enterprise.ServerConfiguration;
29 import com.sun.enterprise.util.FileUtil;
30 import javax.rmi.PortableRemoteObject JavaDoc;
31 import javax.naming.*;
32
33 import com.sun.enterprise.server.ServerContext;
34 import com.sun.enterprise.server.ApplicationServer;
35
36 import com.sun.enterprise.config.ConfigContext;
37 import com.sun.enterprise.config.ConfigFactory;
38 import com.sun.enterprise.config.ConfigException;
39 import com.sun.enterprise.config.serverbeans.Resources;
40 import com.sun.enterprise.config.ConfigBean;
41 import com.sun.enterprise.config.serverbeans.Domain;
42 import com.sun.enterprise.config.serverbeans.Servers;
43 import com.sun.enterprise.config.serverbeans.Server;
44 import com.sun.enterprise.config.serverbeans.ResourceRef;
45 import com.sun.enterprise.config.serverbeans.ServerHelper;
46 import com.sun.enterprise.config.serverbeans.ServerBeansFactory;
47 import com.sun.enterprise.config.serverbeans.ElementProperty;
48 // IASRI 4660742 START
49
import java.util.logging.*;
50 import com.sun.logging.*;
51 // IASRI 4660742 END
52

53 /**
54  * Implementation of J2EEResourceFactory. Reads and writes
55  * XML Resource properties and converts them to J2EEResources.
56  * IASRI #4626188
57  * @author Sridatta Viswanath
58  */

59 public class IASJ2EEResourceFactoryImpl implements J2EEResourceFactory {
60
61 // IASRI 4660742 START
62
private static Logger _logger=null;
63     static{
64        _logger=LogDomains.getLogger(LogDomains.ROOT_LOGGER);
65         }
66 // IASRI 4660742 END
67
static final String JavaDoc JMS_QUEUE = "javax.jms.Queue";
68     static final String JavaDoc JMS_TOPIC = "javax.jms.Topic";
69     static final String JavaDoc JMS_QUEUE_CONNECTION_FACTORY = "javax.jms.QueueConnectionFactory";
70     static final String JavaDoc JMS_TOPIC_CONNECTION_FACTORY = "javax.jms.TopicConnectionFactory";
71
72     // START OF IASRI 4693548 - resource enabled flag needs to be checked
73
/** generic resource type for jndi */
74     public static final String JavaDoc CUSTOM_RES_TYPE = "custom-resource";
75
76     /** resource type residing in an external JNDI repository */
77     public static final String JavaDoc EXT_JNDI_RES_TYPE = "external-jndi-resource";
78
79     /** JDBC javax.sql.(XA)DataSource resource type */
80     public static final String JavaDoc JDBC_RES_TYPE = "jdbc-resource";
81
82     /** java mail resource type */
83     public static final String JavaDoc MAIL_RES_TYPE = "mail-resource";
84
85     /** jms resource type */
86     public static final String JavaDoc JMS_RES_TYPE = "jms-resource";
87
88     /** persistence manager runtime configuration resource type */
89     public static final String JavaDoc PMF_RES_TYPE="persistence-manager-factory-resource";
90     /** jdbc connection pool resource type */
91     public static final String JavaDoc JDBC_CONN_POOL_RES_TYPE = "jdbc-connection-pool";
92     /** Connector resource type */
93     public static final String JavaDoc CONNECTOR_CONN_POOL_TYPE = "connector-connection-pool";
94     // END OF IASRI 4693548
95

96
97     private ConfigContext ctx = null;
98     private Resources rBean = null;
99     
100     private String JavaDoc serverName = null;
101     private static J2EEResourceCollection resources = null;
102
103     public J2EEResourceCollection loadDefaultResourceCollection()
104                                             throws J2EEResourceException {
105         if (resources != null) {
106             return resources;
107         } else {
108             return loadResourceCollection(null);
109         }
110     }
111
112     public J2EEResourceCollection loadResourceCollection(String JavaDoc resourcesURL)
113                                             throws J2EEResourceException {
114
115         resources = new J2EEResourceCollectionImpl();
116
117            ServerContext sc = ApplicationServer.getServerContext();
118            if(sc == null) {
119 //IASRI 4660742 System.out.println("Not Running in server. Returning empty resources...");
120
// START OF IASRI 4660742
121
_logger.log(Level.FINE,"Not Running in server. Returning empty resources...");
122 // END OF IASRI 4660742
123
return resources;
124            } else {
125                 // name of this server instance
126
serverName = sc.getInstanceName();
127            }
128
129            try {
130                ctx = sc.getConfigContext();
131                //ROB: config changes
132
//rBean = ServerBeansFactory.getServerBean(ctx).getResources();
133
rBean = ServerBeansFactory.getDomainBean(ctx).getResources();
134                //RAMAKANTH
135
if (rBean == null)
136                {
137                    rBean = new Resources();
138                }
139            } catch (ConfigException ce) {
140 /** IASRI 4660742
141                ce.printStackTrace();
142                System.out.println("Error initializing context");
143                System.out.println("Returning empty resources...");
144 */

145 // START OF IASRI 4660742
146
_logger.log(Level.SEVERE,"enterprise.empty_resource",ce);
147         _logger.log(Level.FINE,"Error initializing context. Returning empty resources...");
148 // END OF IASRI 4660742
149
return resources;
150            }
151
152         try {
153 /** IASRI 4660742
154             System.out.println("Loading Jdbc Connection Pool==========");
155             // load connection pool before jdbc resource
156             loadJdbcConnectionPool(resources);
157             System.out.println("Loading Jdbc Resource==========");
158             loadJdbcResource(resources);
159             //System.out.println("Loading Jms Resource==========");
160             //loadJmsResource(resources);
161             System.out.println("Loading PMF Resource==========");
162             loadPMFResource(resources);
163             System.out.println("Loading Custom Resource==========");
164             loadCustomResource(resources);
165             System.out.println("Loading External Jndi Resource==========");
166             loadExternalJndiResource(resources);
167 // START OF IASRI 4650786
168             System.out.println("Loading Mail Resource==========");
169             loadMailResource(resources);
170 // END OF IASRI 4650786
171 */

172 // START OF IASRI 4660742
173
_logger.log(Level.FINE,"Loading Jdbc Connection Pool==========");
174             // load connection pool before jdbc resource
175
loadJdbcConnectionPool(resources);
176         _logger.log(Level.FINE,"Loading Jdbc Resource==========");
177             loadJdbcResource(resources);
178             //_logger.log(Level.FINE,"Loading Jms Resource==========");
179
//loadJmsResource(resources);
180
_logger.log(Level.FINE,"Loading PMF Resource==========");
181             loadPMFResource(resources);
182             _logger.log(Level.FINE,"Loading Custom Resource==========");
183             loadCustomResource(resources);
184             _logger.log(Level.FINE,"Loading External Jndi Resource==========");
185             loadExternalJndiResource(resources);
186 // START OF IASRI 4650786
187
_logger.log(Level.FINE,"Loading Mail Resource==========");
188             loadMailResource(resources);
189 // END OF IASRI 4650786
190
// END OF IASRI 4660742
191
} catch (ConfigException ce) {
192 // IASRI 4660742 ce.printStackTrace();
193
// IASRI 4660742 System.out.println("Error Loading resources: "+ce.getMessage());
194
// START OF IASRI 4660742
195
_logger.log(Level.SEVERE,"enterprise.config_exception",ce);
196         _logger.log(Level.FINE,"Error Loading resources: "+ce.getMessage());
197 // END OF IASRI 4660742
198
throw new J2EEResourceException(ce);
199         }
200         return resources;
201
202     }
203
204     public void storeDefaultResourceCollection(J2EEResourceCollection resources)
205         throws J2EEResourceException {
206         storeResourceCollection(resources, null);
207     }
208
209     public void storeResourceCollection(J2EEResourceCollection resources, String JavaDoc resourcesURL)
210     throws J2EEResourceException {
211  /* ServerContext sc = ApplicationServer.getServerContext();
212
213         if(sc == null) {
214             throw new J2EEResourceException("Server Not Initialized");
215         }
216
217         try {
218             ctx = sc.getConfigContext();
219             rBean = ConfigBean.getServerObject(ctx).getResources();
220         } catch (ConfigException ce) {
221 // IASRI 4660742 ce.printStackTrace();
222 // IASRI 4660742 System.out.println("Error initializing context");
223 // START OF IASRI 4660742
224          _logger.log(Level.SEVERE,"enterprise.config_exception",ce);
225         _logger.log(Level.FINE,"Error initializing context ");
226 // END OF IASRI 4660742
227             throw new J2EEResourceException(ce);
228         }
229
230         try {
231             rBean.removeAllChildObjects();
232
233 // IASRI 4660742 System.out.println("Saving Jdbc Connection Pool==========");
234 // IASRI 4660742 saveJdbcConnectionPool(resources);
235 // IASRI 4660742 System.out.println("Saving Jdbc Resource==========");
236 // IASRI 4660742 saveJdbcResource(resources);
237 // IASRI 4660742 System.out.println("Saving Jms Resource==========");
238 // IASRI 4660742 saveJmsResource(resources);
239 // IASRI 4660742 System.out.println("Saving PMF Resource==========");
240 // IASRI 4660742 savePMFResource(resources);
241 // IASRI 4660742 System.out.println("Saving Custom Resource==========");
242 // IASRI 4660742 saveCustomResource(resources);
243 // IASRI 4660742 System.out.println("Saving External Jndi Resource==========");
244 // START OF IASRI 4660742
245             _logger.log(Level.FINE,"Saving Jdbc Connection Pool==========");
246             saveJdbcConnectionPool(resources);
247             _logger.log(Level.FINE,"Saving Jdbc Resource==========");
248             saveJdbcResource(resources);
249             _logger.log(Level.FINE,"Saving Jms Resource==========");
250             saveJmsResource(resources);
251             _logger.log(Level.FINE,"Saving PMF Resource==========");
252             savePMFResource(resources);
253             _logger.log(Level.FINE,"Saving Custom Resource==========");
254             saveCustomResource(resources);
255             _logger.log(Level.FINE,"Saving External Jndi Resource==========");
256 // END OF IASRI 4660742
257             saveExternalJndiResource(resources);
258 // START OF IASRI 4650786
259             _logger.log(Level.FINE,"Saving Mail Resource==========");
260             saveMailResource(resources);
261 // END OF IASRI 4650786
262             rBean.save();
263         } catch (ConfigException ce) {
264 //IASRI 4660742 ce.printStackTrace();
265 //IASRI 4660742 System.out.println("Error Loading resources");
266 // START OF IASRI 4660742
267          _logger.log(Level.SEVERE,"enterprise.config_exception",ce);
268         _logger.log(Level.FINE,"Error Loading resources ");
269 // END OF IASRI 4660742
270             throw new J2EEResourceException(ce);
271         }
272   */

273     }
274
275     public J2EEResource createResource(int type, String JavaDoc name) {
276
277         J2EEResource resource = null;
278
279         switch(type) {
280             case J2EEResource.JMS_DESTINATION :
281                 resource = new JmsDestinationResource(name);
282                 break;
283             case J2EEResource.JMS_CNX_FACTORY :
284                 resource = new JmsCnxFactoryResource(name);
285                 break;
286             case J2EEResource.JDBC_RESOURCE :
287                 resource = new JdbcResource(name);
288                 break;
289             case J2EEResource.JDBC_XA_RESOURCE :
290                 resource = new JdbcXAResource(name);
291                 break;
292             case J2EEResource.JDBC_DRIVER :
293                 resource = new JdbcDriver(name);
294                 break;
295             case J2EEResource.JDBC_CONNECTION_POOL :
296                 resource = new JdbcConnectionPool(name);
297                 break;
298             case J2EEResource.PMF_RESOURCE :
299                 resource = new PMFResource(name);
300                 break;
301             case J2EEResource.CUSTOM_RESOURCE :
302                 resource = new CustomResource(name);
303                 break;
304             case J2EEResource.EXTERNAL_JNDI_RESOURCE :
305                 resource = new ExternalJndiResource(name);
306                 break;
307 // START OF IASRI 4650786
308
case J2EEResource.MAIL_RESOURCE :
309                 resource = new MailResource(name);
310                 break;
311 // END OF IASRI 4650786
312
default :
313                 throw new java.lang.IllegalArgumentException JavaDoc();
314         }
315
316         return resource;
317     }
318
319     public ResourceProperty createProperty(String JavaDoc name) {
320         return new ResourcePropertyImpl(name);
321     }
322
323     /**
324      * Returns true if the named pool has a reference from a jdbc resource
325      * that is used by this server instance.
326      *
327      * @param poolName jdbc resource pool name
328      * @return true if the pool is used by the server instance
329      *
330      * @throw ConfigException if an error while parsing domain.xml
331      */

332     private boolean isJdbcPoolReferenced(String JavaDoc poolName)
333             throws ConfigException {
334
335         com.sun.enterprise.config.serverbeans.JdbcResource[] jdbcBeans =
336                                                     rBean.getJdbcResource();
337
338         // no jdbc resource in the domain, so it is not possible
339
// for the jdbc pool to be in use by a server in this domain
340
if (jdbcBeans == null) {
341             return false;
342         }
343
344         for (int i = 0; i <jdbcBeans.length; i++) {
345
346             com.sun.enterprise.config.serverbeans.JdbcResource next =
347               (com.sun.enterprise.config.serverbeans.JdbcResource) jdbcBeans[i];
348
349             // jdbc resource is not referenced by the server instance
350
if ( !isReferenced(next.getJndiName()) ) {
351                 continue;
352             } else {
353                 String JavaDoc pool = next.getPoolName();
354                 if ( (pool != null) && pool.equals(poolName) ) {
355                     // jdbc pool is referenced by server (server->res->pool)
356
return true;
357                 }
358             }
359         }
360
361         // no jdbc resource referred by this server is using this pool
362
return false;
363     }
364
365     /**
366      * Returns true if the given resource is referenced by this server.
367      *
368      * @param resourceName name (jndi) of the resource
369      * @return true if the named resource is used/referred by this server
370      *
371      * @throws ConfigException if an error while parsing domain.xml
372      */

373     private boolean isReferenced(String JavaDoc resourceName) throws ConfigException {
374         return ServerHelper.serverReferencesResource(ctx, serverName, resourceName);
375     }
376
377     private void loadJdbcResource(J2EEResourceCollection resources) throws ConfigException {
378         com.sun.enterprise.config.serverbeans.JdbcResource[] jBeanSet = rBean.getJdbcResource();
379         if(jBeanSet == null) return;
380
381         for(int i = 0; i <jBeanSet.length; i++) {
382             com.sun.enterprise.config.serverbeans.JdbcResource next =
383             (com.sun.enterprise.config.serverbeans.JdbcResource) jBeanSet[i];
384             
385             // resource is not referenced by the server instance
386
if ( !isReferenced(next.getJndiName()) ) {
387                 _logger.fine("Skipping Jdbc Resource: " + next.getJndiName()
388                             + ". It is not used by server: " + serverName);
389                 continue;
390             }
391
392             // Start Bug Fix: 4693395
393
if (!next.isEnabled()) {
394                 logMessageIfNotEnabled(next.getJndiName(), JDBC_RES_TYPE);
395                 continue;
396             }
397             // End Bug Fix: 4693395
398

399              String JavaDoc poolName = next.getPoolName();
400             JdbcConnectionPool jcp = (JdbcConnectionPool)resources.getResourceByName(
401                         J2EEResource.JDBC_CONNECTION_POOL, poolName);
402
403             // Start Bug Fix: 4669820
404
if(jcp == null) {
405                 //log message
406
_logger.log(Level.WARNING, "enterprise.connection_pool_does_not_exist", poolName);
407                 _logger.log(Level.WARNING, "enterprise.error_loading_jdbc_resource", next.getJndiName());
408                 _logger.info("Error loading Jdbc Resource:" + next.getJndiName() + ". skipping...");
409                 continue;
410             }
411             // End Bug Fix: 4669820
412

413             boolean isXA = jcp.isXA();
414             J2EEResourceBase jr = null;
415             if(isXA) {
416                 jr = new IASJdbcXAResource(next.getJndiName());
417                 ((IASJdbcXAResource)jr).setJdbcConnectionPool(jcp);
418             } else {
419                 jr = new IASJdbcResource(next.getJndiName());
420                 ((IASJdbcResource)jr).setJdbcConnectionPool(jcp);
421             }
422             //jr.setDescription(next.getDescription()); // FIXME add this
423
jr.setEnabled(next.isEnabled());
424             resources.addResource(jr);
425         }
426     }
427
428 /*
429     private void loadJmsResource(J2EEResourceCollection resources) throws ConfigException{
430         com.sun.enterprise.config.serverbeans.JmsResource[] jBeanSet = rBean.getJmsResource();
431         if(jBeanSet == null) return;
432
433         for(int i = 0; i <jBeanSet.length; i++) {
434
435             com.sun.enterprise.config.serverbeans.JmsResource next =
436             (com.sun.enterprise.config.serverbeans.JmsResource) jBeanSet[i];
437
438             // Start Bug Fix: 4693395
439             if (!next.isEnabled()) {
440                 logMessageIfNotEnabled(next.getJndiName(), JMS_RES_TYPE);
441                 continue;
442             }
443             // End Bug Fix: 4693395
444
445             J2EEResource jr = toJMSJ2EEResource(next);
446             resources.addResource(jr);
447         }
448     }
449
450
451     public static J2EEResource toJMSJ2EEResource(com.sun.enterprise.config.serverbeans.JmsResource rbean)
452                                                 throws ConfigException {
453             String resType = rbean.getResType();
454             if (resType == null) {
455                 throw new ConfigException("Bad JMS Resource (null type)"); // FIXME i18n
456             }
457             J2EEResourceBase jr = null;
458             if(resType.equals(JMS_QUEUE) || resType.equals(JMS_TOPIC)) {
459                 jr = new JmsDestinationResource(rbean.getJndiName());
460                 ((JmsDestinationResource)jr).setIsQueue(resType.equals(JMS_QUEUE));
461
462                 ElementProperty[] s = rbean.getElementProperty();
463                 if(s!= null) {
464                   for(int j = 0; j <s.length; j++) {
465                     com.sun.enterprise.config.serverbeans.ElementProperty next1 =
466                     (com.sun.enterprise.config.serverbeans.ElementProperty) s[j];
467                     ResourceProperty rp = new ResourcePropertyImpl(next1.getName(), next1.getValue());
468                     jr.addProperty(rp);
469                   }
470                 }
471             } else if (resType.equals(JMS_QUEUE_CONNECTION_FACTORY) || resType.equals(JMS_TOPIC_CONNECTION_FACTORY)) {
472                 jr = new JmsCnxFactoryResource(rbean.getJndiName());
473                 ((JmsCnxFactoryResource)jr).setIsQueue(resType.equals(JMS_QUEUE_CONNECTION_FACTORY));
474
475                 ElementProperty[] s = rbean.getElementProperty();
476                 if(s!= null) {
477                     for(int j = 0; j <s.length; j++) {
478                         com.sun.enterprise.config.serverbeans.ElementProperty next1 =
479                         (com.sun.enterprise.config.serverbeans.ElementProperty) s[j];
480                         ResourceProperty rp = new ResourcePropertyImpl(next1.getName(), next1.getValue());
481                         jr.addProperty(rp);
482                     }
483                 }
484             } else {
485                 throw new ConfigException("Bad JMS resource (unexpected type)"); // FIXME i18n
486             }
487
488             jr.setEnabled(rbean.isEnabled());
489             //jr.setDescription(rbean.getDescription()); // FIXME add this
490             return jr;
491     }
492 */

493
494     // start 4650787
495
// loadJdbcConnectionPool method was splited in two for fixing bug # 4650787
496
// Because, we calling the method loadJdbcConnectionPool(com.sun.enterprise.config.serverbeans.JdbcConnectionPool jcp)
497
// from com.sun.enterprise.resource.JdbcConnectionPoolDeployer
498

499     private void loadJdbcConnectionPool(J2EEResourceCollection resources) throws ConfigException{
500         com.sun.enterprise.config.serverbeans.JdbcConnectionPool[] jBeanSet = rBean.getJdbcConnectionPool();
501         if(jBeanSet == null) return;
502
503         for(int i = 0; i <jBeanSet.length; i++) {
504             com.sun.enterprise.config.serverbeans.JdbcConnectionPool next =
505             (com.sun.enterprise.config.serverbeans.JdbcConnectionPool) jBeanSet[i];
506             // connection pool is not referenced by server instance
507
if ( !isJdbcPoolReferenced(next.getName()) ) {
508                 _logger.fine("Skipping Jdbc Pool:" + next.getName()
509                             + ". It is not used by server: " + serverName);
510                 continue;
511             }
512            
513             JdbcConnectionPool jr = loadJdbcConnectionPool(next);
514             resources.addResource(jr);
515         }
516     }
517
518
519     public static JdbcConnectionPool loadJdbcConnectionPool(com.sun.enterprise.config.serverbeans.JdbcConnectionPool jcp) throws ConfigException{
520             JdbcConnectionPool jr = new JdbcConnectionPool(jcp.getName());
521             //jr.setUrl(jcp.getUrl());
522
//jr.setUserName(jcp.getUserName());
523
//jr.setPassword(jcp.getPassword());
524
jr.setDatasourceClassname(jcp.getDatasourceClassname());
525             //jr.setDescription(jcp.getDescription()); // FIXME: getting error
526
jr.setMaxPoolSize(jcp.getMaxPoolSize());
527             jr.setSteadyPoolSize(jcp.getSteadyPoolSize());
528             jr.setMaxWaitTimeInMillis(jcp.getMaxWaitTimeInMillis());
529             // start IASRI 4667083
530
jr.setPoolResizeQuantity(jcp.getPoolResizeQuantity());
531             // end IASRI 4667083
532
jr.setIdleTimeoutInSeconds(jcp.getIdleTimeoutInSeconds());
533             jr.setIsConnectionValidationRequired(jcp.isIsConnectionValidationRequired());
534             jr.setConnectionValidationMethod(jcp.getConnectionValidationMethod());
535             jr.setValidationTableName(jcp.getValidationTableName());
536             jr.setFailAllConnections(jcp.isFailAllConnections());
537
538         // start IASRI 4687826
539
jr.setResType(jcp.getResType());
540             jr.setTransactionIsolationLevel(jcp.getTransactionIsolationLevel());
541             jr.setIsIsolationLevelGuaranteed(jcp.isIsIsolationLevelGuaranteed());
542         // end IASRI 4687826
543

544
545             ElementProperty[] s = jcp.getElementProperty();
546             if(s!= null) {
547                 for(int j = 0; j <s.length; j++) {
548                     com.sun.enterprise.config.serverbeans.ElementProperty ep =
549                     (com.sun.enterprise.config.serverbeans.ElementProperty) s[j];
550                     ResourceProperty rp = new ResourcePropertyImpl(ep.getName(),
551                                                                 ep.getValue());
552                     jr.addProperty(rp);
553                 }
554             }
555         return jr;
556     }
557
558 // end 4650787
559

560
561     /**
562      * Loads all the available custom resources into the resource collection.
563      *
564      * @param resources j2ee resource collection
565      * @throws ConfigException if an error while loading data into beans
566      */

567     private void loadCustomResource(J2EEResourceCollection resources)
568             throws ConfigException {
569
570         com.sun.enterprise.config.serverbeans.CustomResource[] jBeanSet =
571             rBean.getCustomResource();
572
573         if (jBeanSet == null) {
574             return;
575         }
576
577         for (int i=0; i < jBeanSet.length; i++) {
578             com.sun.enterprise.config.serverbeans.CustomResource next =
579                 (com.sun.enterprise.config.serverbeans.CustomResource) jBeanSet[i];
580
581             // custom resource is not referenced by this server
582
if ( !isReferenced(next.getJndiName()) ) {
583                 _logger.fine("Skipping Custom Resource:" + next.getJndiName()
584                             + ". It is not used by server: " + serverName);
585                 continue;
586             }
587
588             // Start Bug Fix: 4693395
589
if (!next.isEnabled()) {
590                 logMessageIfNotEnabled(next.getJndiName(), CUSTOM_RES_TYPE);
591                 continue;
592             }
593             // End Bug Fix: 4693395
594

595             // convets the config bean to j2ee resource
596
J2EEResource jr = toCustomJ2EEResource(next);
597
598             resources.addResource(jr);
599         }
600     }
601
602     /**
603      * Returns a new instance of j2ee custom resource from the given
604      * config bean.
605      *
606      * This method gets called from the custom resource deployer
607      * to convert custom-resource config bean into custom j2ee resource.
608      *
609      * @param rbean custom-resource config bean
610      *
611      * @return new instance of j2ee custom resource
612      *
613      * @throws ConfigException if an error while loading data into beans
614      */

615     public static J2EEResource toCustomJ2EEResource(
616             com.sun.enterprise.config.serverbeans.CustomResource rbean)
617             throws ConfigException {
618
619         CustomResource jr = new CustomResource( rbean.getJndiName() );
620
621         //jr.setDescription(rbean.getDescription()); // FIXME: getting error
622

623         // sets the enable flag
624
jr.setEnabled( rbean.isEnabled() );
625
626         // sets the resource type
627
jr.setResType( rbean.getResType() );
628
629         // sets the factory class name
630
jr.setFactoryClass( rbean.getFactoryClass() );
631
632         // sets the properties
633
ElementProperty[] s = rbean.getElementProperty();
634         if (s!= null) {
635             for(int j = 0; j <s.length; j++) {
636
637                 com.sun.enterprise.config.serverbeans.ElementProperty next =
638                     (com.sun.enterprise.config.serverbeans.ElementProperty) s[j];
639
640                 ResourceProperty rp =
641                     new ResourcePropertyImpl(next.getName(), next.getValue());
642
643                 jr.addProperty(rp);
644             }
645         }
646
647         return jr;
648     }
649
650     /**
651      * Returns a new instance of j2ee external jndi resource from the given
652      * config bean.
653      *
654      * This method gets called from the external resource
655      * deployer to convert external-jndi-resource config bean into
656      * external-jndi j2ee resource.
657      *
658      * @param rbean external-jndi-resource config bean
659      *
660      * @return a new instance of j2ee external jndi resource
661      *
662      * @throws ConfigException if an error while loading data into beans
663      */

664     public static J2EEResource toExternalJndiJ2EEResource(
665             com.sun.enterprise.config.serverbeans.ExternalJndiResource rbean)
666             throws ConfigException {
667
668         ExternalJndiResource jr = new ExternalJndiResource(rbean.getJndiName());
669
670         //jr.setDescription( rbean.getDescription() ); // FIXME: getting error
671

672         // sets the enable flag
673
jr.setEnabled( rbean.isEnabled() );
674
675         // sets the jndi look up name
676
jr.setJndiLookupName( rbean.getJndiLookupName() );
677
678         // sets the resource type
679
jr.setResType( rbean.getResType() );
680
681         // sets the factory class name
682
jr.setFactoryClass( rbean.getFactoryClass() );
683
684         // sets the properties
685
ElementProperty[] s = rbean.getElementProperty();
686         if (s!= null) {
687             for (int j=0; j<s.length; j++) {
688                 com.sun.enterprise.config.serverbeans.ElementProperty next =
689                     (com.sun.enterprise.config.serverbeans.ElementProperty) s[j];
690
691                 ResourceProperty rp =
692                     new ResourcePropertyImpl(next.getName(), next.getValue());
693                 jr.addProperty(rp);
694             }
695         }
696
697         return jr;
698     }
699
700     /**
701      * Loads all available external jndi resources into the given resource
702      * collection.
703      *
704      * @param resources j2ee resource collection
705      *
706      * @throws ConfigException if an error while loading data into beans
707      */

708     private void loadExternalJndiResource(J2EEResourceCollection resources)
709             throws ConfigException {
710
711         com.sun.enterprise.config.serverbeans.ExternalJndiResource[] jBeanSet =
712             rBean.getExternalJndiResource();
713
714         if (jBeanSet == null) {
715             return;
716         }
717
718         for (int i=0; i<jBeanSet.length; i++) {
719             com.sun.enterprise.config.serverbeans.ExternalJndiResource next =
720                 (com.sun.enterprise.config.serverbeans.ExternalJndiResource) jBeanSet[i];
721             
722             // external jndi resource is not referenced by this server
723
if ( !isReferenced(next.getJndiName()) ) {
724                 _logger.fine("Skipping External JNDI Resource:"
725                             + next.getJndiName()
726                             + ". It is not used by server: " + serverName);
727                 continue;
728             }
729
730             // Start Bug Fix: 4693395
731
if (!next.isEnabled()) {
732                 logMessageIfNotEnabled(next.getJndiName(), EXT_JNDI_RES_TYPE);
733                 continue;
734             }
735             // End Bug Fix: 4693395
736

737             // convets the config bean to j2ee resource
738
J2EEResource jr = toExternalJndiJ2EEResource(next);
739
740             resources.addResource(jr);
741         }
742     }
743
744     private void loadPMFResource(J2EEResourceCollection resources) throws ConfigException {
745         com.sun.enterprise.config.serverbeans.PersistenceManagerFactoryResource[] jBeanSet = rBean.getPersistenceManagerFactoryResource();
746         if(jBeanSet == null) return;
747
748         for(int i = 0; i <jBeanSet.length; i++) {
749             com.sun.enterprise.config.serverbeans.PersistenceManagerFactoryResource next =
750             (com.sun.enterprise.config.serverbeans.PersistenceManagerFactoryResource) jBeanSet[i];
751             
752             // PMF resource is not referenced by this server
753
if ( !isReferenced(next.getJndiName()) ) {
754                 _logger.fine("Skipping PMF Resource:" + next.getJndiName()
755                             + ". It is not used by server: " + serverName);
756                 continue;
757             }
758
759             // Start Bug Fix: 4693395
760
if (!next.isEnabled()) {
761                 logMessageIfNotEnabled(next.getJndiName(), PMF_RES_TYPE);
762                 continue;
763             }
764             // End Bug Fix: 4693395
765

766             resources.addResource(toPMFJ2EEResource(next));
767         }
768     }
769
770     /**
771      * Returns a new instance of j2ee pmf resource from the given config bean.
772      *
773      * This method gets called from the Persistence Manager Factory Resource
774      * deployer to convert persistence-manager-resource-factory config bean into
775      * pmf j2ee resource.
776      *
777      * @param rbean persistence-manager-resource-factory config bean
778      *
779      * @return a new instance of j2ee pmf resource
780      *
781      * @throws ConfigException if an error while loading data into beans
782      */

783     public static J2EEResource toPMFJ2EEResource(
784             com.sun.enterprise.config.serverbeans.PersistenceManagerFactoryResource
785             rbean) throws ConfigException {
786         PMFResource jr = new PMFResource(rbean.getJndiName());
787         jr.setEnabled(rbean.isEnabled());
788         jr.setFactoryClass(rbean.getFactoryClass());
789         jr.setJdbcResourceJndiName(rbean.getJdbcResourceJndiName());
790
791         ElementProperty[] s = rbean.getElementProperty();
792         if (s!= null) {
793             for (int j = 0; j <s.length; j++) {
794                 com.sun.enterprise.config.serverbeans.ElementProperty next1 =
795                 (com.sun.enterprise.config.serverbeans.ElementProperty) s[j];
796                 ResourceProperty rp = new ResourcePropertyImpl(next1.getName(),
797                         next1.getValue());
798                 jr.addProperty(rp);
799             }
800         }
801         //jr.setDescription(next.getDescription()); // FIXME add this
802

803         return jr;
804     }
805
806 // START OF IASRI 4650786
807
/**
808      * Returns a new instance of j2ee mail resource from the given config bean.
809      *
810      * This method gets called from the mail resource deployer to convert mail
811      * config bean into mail j2ee resource.
812      *
813      * @param rbean mail-resource config bean
814      *
815      * @return a new instance of j2ee mail resource
816      *
817      * @throws ConfigException if an error while loading data into beans
818      */

819     public static J2EEResource toMailJ2EEResource(
820         com.sun.enterprise.config.serverbeans.MailResource rbean)
821         throws ConfigException {
822
823         MailResource jr = new MailResource(rbean.getJndiName());
824
825         //jr.setDescription(rbean.getDescription()); // FIXME: getting error
826
jr.setEnabled(rbean.isEnabled());
827         jr.setStoreProtocol(rbean.getStoreProtocol());
828         jr.setStoreProtocolClass(rbean.getStoreProtocolClass());
829         jr.setTransportProtocol(rbean.getTransportProtocol());
830         jr.setTransportProtocolClass(rbean.getTransportProtocolClass());
831         jr.setMailHost(rbean.getHost());
832         jr.setUsername(rbean.getUser());
833         jr.setMailFrom(rbean.getFrom());
834         jr.setDebug(rbean.isDebug());
835
836         // sets the properties
837
ElementProperty[] s = rbean.getElementProperty();
838         if (s != null) {
839             for (int j = 0; j < s.length; j++) {
840                 com.sun.enterprise.config.serverbeans.ElementProperty next =
841                     (com.sun.enterprise.config.serverbeans.ElementProperty)s[j];
842
843                 ResourceProperty rp =
844                     new ResourcePropertyImpl(next.getName(), next.getValue());
845                 jr.addProperty(rp);
846             }
847         }
848
849         return jr;
850     }
851
852     /**
853      * Loads all available mail resources into the given resource collection.
854      *
855      * @param resources j2ee resource collection
856      *
857      * @throws ConfigException if an error while loading data into beans
858      */

859     private void loadMailResource(J2EEResourceCollection resources)
860         throws ConfigException {
861
862         com.sun.enterprise.config.serverbeans.MailResource[] jBeanSet =
863             rBean.getMailResource();
864
865         if (jBeanSet == null) {
866             return;
867         }
868
869         for (int i = 0; i < jBeanSet.length; i++) {
870             com.sun.enterprise.config.serverbeans.MailResource next =
871                 (com.sun.enterprise.config.serverbeans.MailResource)jBeanSet[i];
872             
873             // mail resource is not referenced by this server
874
if ( !isReferenced(next.getJndiName()) ) {
875                 _logger.fine("Skipping Mail Resource:" + next.getJndiName()
876                             + ". It is not used by server: " + serverName);
877                 continue;
878             }
879
880             // Start Bug Fix: 4693395
881
if (!next.isEnabled()) {
882                 logMessageIfNotEnabled(next.getJndiName(), MAIL_RES_TYPE);
883                 continue;
884             }
885             // End Bug Fix: 4693395
886

887             // convets the config bean to j2ee resource
888
J2EEResource jr = toMailJ2EEResource(next);
889
890             resources.addResource(jr);
891         }
892     }
893
894     // Start Bug Fix: 4693395
895
private void logMessageIfNotEnabled(String JavaDoc name, String JavaDoc type) {
896         _logger.log(Level.INFO, "enterprise.resource_disabled", new Object JavaDoc[] {name, type});
897     }
898     // End Bug Fix: 4693395
899

900
901 // END OF IASRI 4650786
902

903     /*
904     private void saveJdbcResource(J2EEResourceCollection resources) throws ConfigException {
905         Set jBeanSet = resources.getResourcesByType(J2EEResource.JDBC_RESOURCE);
906         if(jBeanSet == null || jBeanSet.size() <1) return;
907
908         for(Iterator iter = jBeanSet.iterator(); iter.hasNext();) {
909             IASJdbcResource next = (IASJdbcResource)iter.next();
910
911             com.sun.enterprise.config.beans.JdbcResource jr =
912                 new com.sun.enterprise.config.beans.JdbcResource(this.ctx);
913             jr.setJndiName(next.getName());
914             jr.setEnabled(next.isEnabled());
915             jr.setPoolName(next.getJdbcConnectionPool().getName());
916             jr.setSupportsGlobalTransactions(false);
917             //jr.setDescription(next.getDescription()); // FIXME add this
918             rBean.addJdbcResource(jr);
919         }
920
921         ////////////////////////////////////
922
923         jBeanSet = resources.getResourcesByType(J2EEResource.JDBC_XA_RESOURCE);
924         if(jBeanSet == null || jBeanSet.size() <1) return;
925
926         for(Iterator iter = jBeanSet.iterator(); iter.hasNext();) {
927             IASJdbcXAResource next = (IASJdbcXAResource)iter.next();
928
929             com.sun.enterprise.config.beans.JdbcResource jr =
930                 new com.sun.enterprise.config.beans.JdbcResource(this.ctx);
931             jr.setJndiName(next.getName());
932             jr.setEnabled(next.isEnabled());
933             jr.setPoolName(next.getJdbcConnectionPool().getName());
934             jr.setSupportsGlobalTransactions(true);
935             //jr.setDescription(next.getDescription()); // FIXME add this
936             rBean.addJdbcResource(jr);
937         }
938     }
939
940     private void saveJmsResource(J2EEResourceCollection resources) throws ConfigException{
941         Set jBeanSet = resources.getResourcesByType(J2EEResource.JMS_DESTINATION);
942         if(jBeanSet == null || jBeanSet.size() <1) return;
943
944         for(Iterator iter = jBeanSet.iterator(); iter.hasNext();) {
945             JmsDestinationResource next = (JmsDestinationResource) iter.next();
946             com.sun.enterprise.config.beans.JmsResource jr =
947                 new com.sun.enterprise.config.beans.JmsResource(this.ctx);;
948             jr.setJndiName(next.getName());
949             boolean queue = next.getIsQueue();
950             jr.setResType(queue?JMS_QUEUE:JMS_TOPIC);
951
952             Set s = next.getProperties();
953             for(Iterator iter1 = s.iterator(); iter1.hasNext();) {
954                 ResourceProperty next1 = (ResourceProperty) iter1.next();
955                 com.sun.enterprise.config.beans.Property rp = new
956                                 com.sun.enterprise.config.beans.Property(this.ctx);
957                 rp.setName(next1.getName());
958                 rp.setValue((String) next1.getValue());
959                 jr.addProperty(rp);
960             }
961
962             jr.setEnabled(next.isEnabled());
963             //jr.setDescription(next.getDescription()); // FIXME add this
964             jr.setFactoryClass("HARD_CODED"); // dont know.
965             rBean.addJmsResource(jr);
966
967         }
968
969         //////////////////////////////////////////////
970
971         jBeanSet = resources.getResourcesByType(J2EEResource.JMS_CNX_FACTORY);
972         if(jBeanSet == null || jBeanSet.size() <1) return;
973
974         for(Iterator iter = jBeanSet.iterator(); iter.hasNext();) {
975             JmsCnxFactoryResource next = (JmsCnxFactoryResource) iter.next();
976             com.sun.enterprise.config.beans.JmsResource jr =
977                 new com.sun.enterprise.config.beans.JmsResource(this.ctx);;
978             jr.setJndiName(next.getName());
979             boolean queue = next.getIsQueue();
980             jr.setResType(queue?JMS_QUEUE_CONNECTION_FACTORY:JMS_TOPIC_CONNECTION_FACTORY);
981
982             Set s = next.getProperties();
983             for(Iterator iter1 = s.iterator(); iter1.hasNext();) {
984                 ResourceProperty next1 = (ResourceProperty) iter1.next();
985                 com.sun.enterprise.config.beans.Property rp = new
986                                 com.sun.enterprise.config.beans.Property(this.ctx);
987                 rp.setName(next1.getName());
988                 rp.setValue((String) next1.getValue());
989                 jr.addProperty(rp);
990             }
991
992             jr.setEnabled(next.isEnabled());
993             //jr.setDescription(next.getDescription()); // FIXME add this
994             jr.setFactoryClass("HARD_CODED"); // dont know.
995             rBean.addJmsResource(jr);
996         }
997     }
998
999     private void saveJdbcConnectionPool(J2EEResourceCollection resources) throws ConfigException{
1000        Set jBeanSet = resources.getResourcesByType(J2EEResource.JDBC_CONNECTION_POOL);
1001        if(jBeanSet == null || jBeanSet.size() <1) return;
1002
1003        for(Iterator iter = jBeanSet.iterator(); iter.hasNext();) {
1004            JdbcConnectionPool next = (JdbcConnectionPool) iter.next();
1005
1006            com.sun.enterprise.config.beans.JdbcConnectionPool jr =
1007                new com.sun.enterprise.config.beans.JdbcConnectionPool(this.ctx);
1008            jr.setId(next.getName());
1009            jr.setUrl(next.getUrl());
1010            jr.setUserName(next.getUserName());
1011            jr.setPassword(next.getPassword());
1012            jr.setDatasourceClassname(next.getDatasourceClassname());
1013            //jr.setDescription(next.getDescription()); // FIXME: getting error
1014            // jr.setEnabled(next.isEnabled()); // does not have it. ignore
1015            jr.setMinConnectionsInPool(next.getMinConnectionsInPool());
1016            jr.setInitialConnectionsInPool(next.getInitialConnectionsInPool());
1017            jr.setMaxConnectionsInPool(next.getMaxConnectionsInPool());
1018            jr.setMaxConnectionWaitTimeInMillis(next.getMaxConnectionWaitTimeInMillis());
1019            jr.setConnectionsIncrement(next.getConnectionsIncrement());
1020            jr.setConnectionIdleTimeoutInSeconds(next.getConnectionIdleTimeoutInSeconds());
1021            jr.setIsConnectionValidationRequired(next.isIsConnectionValidationRequired());
1022            jr.setConnectionValidation(next.getConnectionValidation());
1023            jr.setValidationTableName(next.getValidationTableName());
1024            jr.setFailAllConnections(next.isFailAllConnections());
1025
1026            Set s = next.getProperties();
1027            for(Iterator iter1 = s.iterator(); iter1.hasNext();) {
1028                ResourceProperty next1 = (ResourceProperty) iter1.next();
1029                com.sun.enterprise.config.beans.Property rp = new
1030                                com.sun.enterprise.config.beans.Property(this.ctx);
1031                rp.setName(next1.getName());
1032                rp.setValue((String) next1.getValue());
1033                jr.addProperty(rp);
1034            }
1035
1036            rBean.addJdbcConnectionPool(jr);
1037        }
1038    }
1039
1040    private void saveCustomResource(J2EEResourceCollection resources) throws ConfigException{
1041        Set jBeanSet = resources.getResourcesByType(J2EEResource.CUSTOM_RESOURCE);
1042        if(jBeanSet == null || jBeanSet.size() <1) return;
1043
1044        for(Iterator iter = jBeanSet.iterator(); iter.hasNext();) {
1045            CustomResource next = (CustomResource) iter.next();
1046
1047            com.sun.enterprise.config.beans.CustomResource jr =
1048                new com.sun.enterprise.config.beans.CustomResource(this.ctx);
1049
1050            //jr.setDescription(next.getDescription()); // FIXME: getting error
1051            jr.setEnabled(next.isEnabled());
1052            jr.setResType(next.getResType());
1053            jr.setFactoryClass(next.getFactoryClass());
1054
1055            Set s = next.getProperties();
1056            for(Iterator iter1 = s.iterator(); iter1.hasNext();) {
1057                ResourceProperty next1 = (ResourceProperty) iter1.next();
1058                com.sun.enterprise.config.beans.Property rp = new
1059                                com.sun.enterprise.config.beans.Property(this.ctx);
1060                rp.setName(next1.getName());
1061                rp.setValue((String) next1.getValue());
1062                jr.addProperty(rp);
1063            }
1064
1065            rBean.addCustomResource(jr);
1066        }
1067    }
1068
1069    private void saveExternalJndiResource(J2EEResourceCollection resources) throws ConfigException{
1070        Set jBeanSet = resources.getResourcesByType(J2EEResource.EXTERNAL_JNDI_RESOURCE);
1071        if(jBeanSet == null || jBeanSet.size() <1) return;
1072
1073        for(Iterator iter = jBeanSet.iterator(); iter.hasNext();) {
1074            ExternalJndiResource next = (ExternalJndiResource) iter.next();
1075
1076            com.sun.enterprise.config.beans.ExternalJndiResource jr =
1077                new com.sun.enterprise.config.beans.ExternalJndiResource(this.ctx);
1078
1079            //jr.setDescription(next.getDescription()); // FIXME: getting error
1080            jr.setEnabled(next.isEnabled());
1081            jr.setJndiLookupName(next.getJndiLookupName());
1082            jr.setResType(next.getResType());
1083            jr.setFactoryClass(next.getFactoryClass());
1084
1085            Set s = next.getProperties();
1086            for(Iterator iter1 = s.iterator(); iter1.hasNext();) {
1087                ResourceProperty next1 = (ResourceProperty) iter1.next();
1088                com.sun.enterprise.config.beans.Property rp = new
1089                                com.sun.enterprise.config.beans.Property(this.ctx);
1090                rp.setName(next1.getName());
1091                rp.setValue((String) next1.getValue());
1092                jr.addProperty(rp);
1093            }
1094
1095            rBean.addExternalJndiResource(jr);
1096        }
1097    }
1098
1099    private void savePMFResource(J2EEResourceCollection resources) throws ConfigException {
1100        Set jBeanSet = resources.getResourcesByType(J2EEResource.PMF_RESOURCE);
1101        if(jBeanSet == null || jBeanSet.size() <1) return;
1102
1103        for(Iterator iter = jBeanSet.iterator(); iter.hasNext();) {
1104            PMFResource next = (PMFResource) iter.next();
1105
1106            com.sun.enterprise.config.beans.PersistenceManagerFactoryResource jr =
1107                new com.sun.enterprise.config.beans.PersistenceManagerFactoryResource(this.ctx);
1108            jr.setJndiName(next.getName());
1109            jr.setEnabled(next.isEnabled());
1110            jr.setResType(next.getResType());
1111            jr.setFactoryClass(next.getFactoryClass());
1112            jr.setDatabaseConnectionFactory(next.getDatabaseConnectionFactory());
1113            jr.setIgnoreCache(next.isIgnoreCache());
1114            jr.setNontransactionalRead(next.isNontransactionalRead());
1115            jr.setNontransactionalWrite(next.isNontransactionalWrite());
1116            jr.setOptimisticConcurrency(next.isOptimisticConcurrency());
1117            jr.setRetainValues(next.isRetainValues());
1118
1119            Set s = next.getProperties();
1120            for(Iterator iter1 = s.iterator(); iter1.hasNext();) {
1121                ResourceProperty next1 = (ResourceProperty) iter1.next();
1122                com.sun.enterprise.config.beans.Property rp = new
1123                                com.sun.enterprise.config.beans.Property(this.ctx);
1124                rp.setName(next1.getName());
1125                rp.setValue((String) next1.getValue());
1126                jr.addProperty(rp);
1127            }
1128            //jr.setDescription(next.getDescription()); // FIXME add this
1129            rBean.addPersistenceManagerFactoryResource(jr);
1130        }
1131    }
1132
1133 */

1134}
1135
Popular Tags