KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > mbeans > ResourcesMBean


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

23
24 /*
25  * $Id: ResourcesMBean.java,v 1.14 2006/03/28 06:10:18 sivakumart Exp $
26  * author hamid@sun.com
27  */

28
29 package com.sun.enterprise.admin.mbeans;
30
31 import java.util.List JavaDoc;
32 import java.util.Properties JavaDoc;
33 import java.util.Set JavaDoc;
34 import java.util.Enumeration JavaDoc;
35 import java.util.Arrays JavaDoc;
36 import java.util.ArrayList JavaDoc;
37 import java.util.Vector JavaDoc;
38 import java.util.logging.Level JavaDoc;
39 import java.util.logging.Logger JavaDoc;
40 import java.util.Iterator JavaDoc;
41 import java.lang.reflect.InvocationTargetException JavaDoc;
42 import java.util.StringTokenizer JavaDoc;
43 import java.util.Map JavaDoc;
44 import java.util.HashMap JavaDoc;
45
46 //JMX imports
47
import javax.management.Attribute JavaDoc;
48 import javax.management.AttributeList JavaDoc;
49 import javax.management.ObjectName JavaDoc;
50 import javax.management.MBeanException JavaDoc;
51 import javax.management.MalformedObjectNameException JavaDoc;
52 import javax.management.RuntimeOperationsException JavaDoc;
53 import javax.management.MBeanServerFactory JavaDoc;
54 import javax.management.MBeanServer JavaDoc;
55 import javax.management.modelmbean.ModelMBeanOperationInfo JavaDoc;
56 import javax.management.modelmbean.ModelMBeanAttributeInfo JavaDoc;
57 import javax.management.MBeanInfo JavaDoc;
58 import javax.management.AttributeNotFoundException JavaDoc;
59
60 // JMS util imports
61
import com.sun.enterprise.jms.IASJmsUtil;
62
63 //JMS SPI imports
64
import com.sun.messaging.jmq.jmsspi.JMSAdmin;
65 import com.sun.messaging.jmq.jmsspi.JMSAdminFactory;
66 import com.sun.messaging.jmq.jmsspi.JMSConstants;
67
68 //config imports
69
import com.sun.enterprise.config.ConfigContext;
70 import com.sun.enterprise.config.ConfigException;
71
72 import com.sun.enterprise.admin.MBeanHelper;
73 import com.sun.enterprise.admin.config.BaseConfigMBean;
74 import com.sun.enterprise.admin.config.ConfigMBeanHelper;
75 import com.sun.enterprise.admin.config.MBeanConfigException;
76 import com.sun.enterprise.admin.common.constant.AdminConstants;
77 import com.sun.enterprise.admin.common.exception.AFResourceException;
78
79 import com.sun.enterprise.admin.server.core.AdminService;
80 import com.sun.enterprise.admin.server.core.jmx.SunoneInterceptor;
81 import com.sun.enterprise.util.i18n.StringManager;
82
83 import com.sun.enterprise.config.serverbeans.ServerTags;
84 import com.sun.enterprise.config.serverbeans.ServerXPathHelper;
85 import com.sun.enterprise.config.serverbeans.JmsService;
86 import com.sun.enterprise.config.serverbeans.JmsHost;
87 import com.sun.enterprise.config.serverbeans.ResourceRef;
88 import com.sun.enterprise.config.serverbeans.Resources;
89 import com.sun.enterprise.config.serverbeans.ResourceHelper;
90 import com.sun.enterprise.config.serverbeans.ServerHelper;
91 import com.sun.enterprise.config.serverbeans.ClusterHelper;
92 import com.sun.enterprise.config.ConfigBeansFactory;
93 import com.sun.enterprise.config.serverbeans.Config;
94
95 // For 8.1 event
96
import com.sun.enterprise.admin.event.EventBuilder;
97 import com.sun.enterprise.admin.event.EventContext;
98 import com.sun.enterprise.admin.event.ConfigChangeEvent;
99 import com.sun.enterprise.admin.event.BaseDeployEvent;
100
101 // For 8.0 JMS implementation
102
import javax.resource.ResourceException JavaDoc;
103 import javax.jms.JMSException JavaDoc;
104 import com.sun.enterprise.connectors.ConnectorRuntime;
105 import com.sun.enterprise.connectors.ConnectorConstants;
106 import com.sun.enterprise.connectors.util.JmsRaMapping;
107 import com.sun.enterprise.connectors.util.ConnectionDefinitionUtils;
108 import com.sun.enterprise.resource.Resource;
109 import com.sun.enterprise.resource.ResourcesXMLParser;
110 import com.sun.enterprise.admin.common.exception.JMSAdminException;
111 import com.sun.enterprise.admin.common.constant.JMSAdminConstants;
112 import com.sun.enterprise.admin.common.JMSStatus;
113 import com.sun.enterprise.admin.common.JMSDestinationInfo;
114
115 import com.sun.enterprise.server.ApplicationServer;
116
117 import com.sun.enterprise.admin.mbeanapi.IResourcesMBean;
118
119 import com.sun.enterprise.admin.target.Target;
120 import com.sun.enterprise.admin.target.TargetType;
121 import com.sun.enterprise.admin.target.TargetBuilder;
122
123 import com.sun.enterprise.admin.configbeans.ResourceReferenceHelper;
124
125 public class ResourcesMBean extends BaseConfigMBean
126     implements IResourcesMBean
127 {
128     private static final String JavaDoc CUSTOM_RESOURCE = ServerTags.CUSTOM_RESOURCE;
129     private static final String JavaDoc JDBC_CONNECTION_POOL = ServerTags.JDBC_CONNECTION_POOL;
130     private static final String JavaDoc CONNECTOR_RESOURCE = ServerTags.CONNECTOR_RESOURCE;
131     private static final String JavaDoc ADMIN_OBJECT_RESOURCE = ServerTags.ADMIN_OBJECT_RESOURCE;
132     private static final String JavaDoc JDBC_RESOURCE = ServerTags.JDBC_RESOURCE;
133     private static final String JavaDoc RESOURCE_ADAPTER_CONFIG = ServerTags.RESOURCE_ADAPTER_CONFIG;
134     private static final String JavaDoc MAIL_RESOURCE = ServerTags.MAIL_RESOURCE;
135     private static final String JavaDoc EXTERNAL_JNDI_RESOURCE = ServerTags.EXTERNAL_JNDI_RESOURCE;
136     private static final String JavaDoc CONNECTOR_CONNECTION_POOL = ServerTags.CONNECTOR_CONNECTION_POOL;
137     private static final String JavaDoc PERSISTENCE_MANAGER_FACTORY_RESOURCE = ServerTags.PERSISTENCE_MANAGER_FACTORY_RESOURCE;
138
139     public static final Logger JavaDoc sLogger = Logger.getLogger(AdminConstants.kLoggerName);
140     private static final StringManager localStrings = StringManager.getManager( ResourcesMBean.class );
141
142     private static final String JavaDoc GET = "get";
143     private static final String JavaDoc BYNAME = "ByName";
144     private static final String JavaDoc BYJNDINAME = "ByJndiName";
145     private static final String JavaDoc PMF_SUFFIX = "PM";
146
147     // For JMS resources
148
private static final String JavaDoc QUEUE = "javax.jms.Queue";
149     private static final String JavaDoc TOPIC = "javax.jms.Topic";
150     private static final String JavaDoc QUEUE_CF = "javax.jms.QueueConnectionFactory";
151     private static final String JavaDoc TOPIC_CF = "javax.jms.TopicConnectionFactory";
152     private static final String JavaDoc UNIFIED_CF = "javax.jms.ConnectionFactory";
153
154     private static final String JavaDoc RESOURCES = "resources";
155     private static final String JavaDoc POOL_NAME = "pool-name";
156     private static final String JavaDoc POOL_TYPE = "connector-connection-pool";
157     private static final String JavaDoc CONFIG = "config";
158
159     //operations
160
private static final String JavaDoc CREATE_SECURITY_MAP = "createSecurityMap";
161
162     //JMS constants....
163
private static final String JavaDoc DEST_NAME = "destName";
164     private static final String JavaDoc DEST_TYPE = "destType";
165
166     /**
167      * Valid targets for the resource mbeans are 1) domain,
168      * 2) a named server instance 3) a named cluster
169      *
170      * FIXTHIS: This needs to be made pluggable.
171      */

172     private static final TargetType[] VALID_CREATE_DELETE_TYPES = new TargetType[] {
173         TargetType.CONFIG,
174     TargetType.SERVER,
175     TargetType.DOMAIN,
176     TargetType.CLUSTER,
177     TargetType.STANDALONE_SERVER,
178     TargetType.UNCLUSTERED_SERVER,
179     TargetType.STANDALONE_CLUSTER,
180     TargetType.DAS};
181         
182     private static final TargetType[] VALID_LIST_TYPES = new TargetType[] {
183         TargetType.CONFIG,
184     TargetType.SERVER,
185     TargetType.DOMAIN,
186     TargetType.CLUSTER,
187     TargetType.STANDALONE_SERVER,
188     TargetType.UNCLUSTERED_SERVER,
189     TargetType.STANDALONE_CLUSTER,
190     TargetType.DAS};
191
192     /**
193      */

194     public ResourcesMBean()
195     {
196         super();
197     }
198     
199     private ResourceReferenceHelper getResourceReferenceHelper()
200     {
201         return new ResourceReferenceHelper(getConfigContext());
202     }
203     
204     /**
205      * Returns an array of all system resource adapters that allow connector
206      * connection pool creation.
207      * Presently we need this separate method as the system resource adapters are
208      * not registered in the config. this method will not be required if the system
209      * resource adapters (connector modules) will have entry in domain.xml
210      * @return an array of names of system RARs that allow pool creation.
211      */

212     public String JavaDoc[] getSystemConnectorsAllowingPoolCreation() {
213             return ConnectorRuntime.getRuntime().getSystemConnectorsAllowingPoolCreation();
214     }
215     
216     /**
217      */

218     public ObjectName JavaDoc createCustomResource( AttributeList JavaDoc attrList,
219                                             Properties JavaDoc props,
220                                             String JavaDoc tgtName )
221         throws Exception JavaDoc
222     {
223         return createResource( CUSTOM_RESOURCE, attrList, props, tgtName );
224     }
225
226     public ObjectName JavaDoc createExternalJndiResource( AttributeList JavaDoc attrList,
227                                                   Properties JavaDoc props,
228                                                   String JavaDoc tgtName)
229         throws Exception JavaDoc
230     {
231         return createResource( EXTERNAL_JNDI_RESOURCE, attrList, props, tgtName );
232     }
233
234     public ObjectName JavaDoc createPersistenceManagerFactoryResource( AttributeList JavaDoc attrList,
235                                                                Properties JavaDoc props,
236                                                                String JavaDoc tgtName)
237         throws Exception JavaDoc
238     {
239         return createResource( PERSISTENCE_MANAGER_FACTORY_RESOURCE, attrList, props, tgtName );
240     }
241
242     public ObjectName JavaDoc createPMFResourceWithJDBCResource( AttributeList JavaDoc attrList,
243                                                          Properties JavaDoc props,
244                                                          String JavaDoc tgtName)
245         throws Exception JavaDoc
246     {
247         // create jdbc-resource with the given jdbc-connection-pool
248
String JavaDoc poolName = null;
249         String JavaDoc jndiName = null;
250         int indx = 0;
251         
252         for (int i=0; i<attrList.size(); i++)
253         {
254             Attribute JavaDoc attr = (Attribute JavaDoc)attrList.get(i);
255             if (isAttrNameMatch(attr, "pool-name")) {
256                 poolName = (String JavaDoc)attr.getValue();
257                 indx = i;
258             }
259             if (isAttrNameMatch(attr, "jndi-name"))
260                 jndiName = (String JavaDoc)attr.getValue();
261         }
262         
263         if (poolName != null && !(poolName.equals(""))) {
264             jndiName = jndiName + PMF_SUFFIX; // Add PM suffix to jndiName to indicate it has been created with PMF.
265
AttributeList JavaDoc jdbcAttrList = new AttributeList JavaDoc();
266             jdbcAttrList.add(new Attribute JavaDoc("jndi_name", (Object JavaDoc)jndiName));
267             jdbcAttrList.add(new Attribute JavaDoc("pool_name", (Object JavaDoc)poolName));
268
269             createResource( JDBC_RESOURCE, jdbcAttrList, null, tgtName );
270
271             // Remove the connection-pool name from the attrib list for pmf as pmf creation doesn't require it.
272
attrList.remove(indx);
273             // Add the jdbc-resource-jndi-name in the attrib list for pmf resource.
274
attrList.add(new Attribute JavaDoc("jdbc_resource_jndi_name", (Object JavaDoc)jndiName));
275         }
276         
277         return createResource( PERSISTENCE_MANAGER_FACTORY_RESOURCE, attrList, props, tgtName );
278     }
279
280     public ObjectName JavaDoc createJmsConnectionFactory( AttributeList JavaDoc attrList,
281                                                   Properties JavaDoc props,
282                                                   String JavaDoc tgtName)
283         throws Exception JavaDoc
284     {
285         return createJmsResource(attrList, props, tgtName);
286     }
287
288     public ObjectName JavaDoc createJmsDestinationResource( AttributeList JavaDoc attrList,
289                                                     Properties JavaDoc props,
290                                                     String JavaDoc tgtName)
291         throws Exception JavaDoc
292     {
293         return createJmsResource(attrList, props, tgtName);
294     }
295     
296     //this method is added to provide backward compartibility with old JMS prop names (for GUI)
297
public String JavaDoc getJmsRaMappedName(String JavaDoc name) {
298     return ConnectorRuntime.getRuntime().getJmsRaMapping().getMappedName(name);
299     }
300
301     public ObjectName JavaDoc createJmsResource( AttributeList JavaDoc attrList,
302                                          Properties JavaDoc props,
303                                          String JavaDoc tgtName)
304         throws Exception JavaDoc
305     {
306         sLogger.info("createJmsResource -------------------" );
307         ObjectName JavaDoc mbean = null;
308         Properties JavaDoc properties = null;
309
310         Target target = getResourceTarget(tgtName);
311
312 // try {
313
JmsRaMapping ramap = ConnectorRuntime.getRuntime().getJmsRaMapping();
314
315             /* Map MQ properties to Resource adapter properties */
316             if (props != null) {
317                 Enumeration JavaDoc en = props.keys();
318                 properties = new Properties JavaDoc();
319                 while (en.hasMoreElements()) {
320                     String JavaDoc key = (String JavaDoc) en.nextElement();
321                     String JavaDoc raKey = ramap.getMappedName(key);
322                     if (raKey == null) raKey = key;
323                     properties.put(raKey, (String JavaDoc) props.get(key));
324                 }
325             }
326
327             // Get the default res adapter name from Connector-runtime
328
String JavaDoc raName = ConnectorRuntime.DEFAULT_JMS_ADAPTER;
329
330             // Find out the jndiName & resourceType from the attributeList.
331
String JavaDoc resourceType = null;
332             String JavaDoc jndiName = null;
333             String JavaDoc description = null;
334             Object JavaDoc enabled = null;
335             String JavaDoc steadyPoolSize = null;
336             String JavaDoc maxPoolSize = null;
337             String JavaDoc poolResizeQuantity = null;
338             String JavaDoc idleTimeoutInSecs = null;
339             String JavaDoc maxWaitTimeInMillis = null;
340         String JavaDoc failAllConnections = null;
341         String JavaDoc transactionSupport = null;
342
343             for (int i=0; i<attrList.size(); i++)
344             {
345                 Attribute JavaDoc attr = (Attribute JavaDoc)attrList.get(i);
346                 if (isAttrNameMatch(attr, "res-type"))
347                     resourceType = (String JavaDoc)attr.getValue();
348                 else if (isAttrNameMatch(attr, "jndi-name"))
349                     jndiName = (String JavaDoc)attr.getValue();
350                 else if (isAttrNameMatch(attr, "enabled"))
351                     enabled = attr.getValue();
352                 else if (isAttrNameMatch(attr, "description"))
353                     description = (String JavaDoc)attr.getValue();
354                 else if (isAttrNameMatch(attr, "steady-pool-size"))
355                     steadyPoolSize = (String JavaDoc) attr.getValue();
356                 else if (isAttrNameMatch(attr, "max-pool-size"))
357                     maxPoolSize = (String JavaDoc) attr.getValue();
358                 else if (isAttrNameMatch(attr, "pool-resize-quantity"))
359                     poolResizeQuantity = (String JavaDoc) attr.getValue();
360                 else if (isAttrNameMatch(attr, "idle-timeout-in-seconds"))
361                     idleTimeoutInSecs = (String JavaDoc) attr.getValue();
362                 else if (isAttrNameMatch(attr, "max-wait-time-in-millis"))
363                     maxWaitTimeInMillis = (String JavaDoc) attr.getValue();
364         else if (isAttrNameMatch(attr, "transaction-support"))
365             transactionSupport = (String JavaDoc) attr.getValue();
366         else if(isAttrNameMatch(attr, "fail-all-connections"))
367             failAllConnections = (String JavaDoc) attr.getValue();
368
369                  
370             }
371
372             if (resourceType == null)
373                 throw new Exception JavaDoc(localStrings.getString("admin.mbeans.rmb.null_res_type"));
374
375             ObjectName JavaDoc resObjName = m_registry.getMbeanObjectName(RESOURCES, new String JavaDoc[]{getDomainName()});
376             if (resourceType.equals(TOPIC_CF) || resourceType.equals(QUEUE_CF) || resourceType.equals(UNIFIED_CF))
377             {
378                 // Add a connector-connection-pool & a connector-resource
379

380                 String JavaDoc defPoolName = ConnectorRuntime.getRuntime().getDefaultPoolName(jndiName);
381
382                 // Check for existence of this connection pool
383
ObjectName JavaDoc connPool = null;
384                 try {
385                     connPool = (ObjectName JavaDoc)getMBeanServer().invoke(resObjName, "getConnectorConnectionPoolByName",
386                             new Object JavaDoc[] {defPoolName, tgtName},
387                             new String JavaDoc[] {"java.lang.String", "java.lang.String"});
388                 } catch (Exception JavaDoc ee){}
389
390                 // If pool is already existing, do not try to create it again
391
if (connPool == null) {
392                     // Add connector-connection-pool.
393
AttributeList JavaDoc cpAttrList = new AttributeList JavaDoc();
394                     cpAttrList.add(new Attribute JavaDoc("name", (Object JavaDoc)defPoolName));
395                     cpAttrList.add(new Attribute JavaDoc("resource_adapter_name", (Object JavaDoc)raName));
396                     cpAttrList.add(new Attribute JavaDoc("connection_definition_name", (Object JavaDoc)resourceType));
397                     cpAttrList.add(new Attribute JavaDoc("max_pool_size", (maxPoolSize == null) ? (Object JavaDoc)"250" : (Object JavaDoc)maxPoolSize));
398                     cpAttrList.add(new Attribute JavaDoc("steady_pool_size", (steadyPoolSize == null) ? (Object JavaDoc)"1" : (Object JavaDoc)steadyPoolSize));
399                     if (poolResizeQuantity != null) {
400                         cpAttrList.add(new Attribute JavaDoc("pool_resize_quantity", (Object JavaDoc)poolResizeQuantity));
401                     }
402                     if (idleTimeoutInSecs != null) {
403                         cpAttrList.add(new Attribute JavaDoc("idle_timeout_in_seconds", (Object JavaDoc)idleTimeoutInSecs));
404                     }
405                     if (maxWaitTimeInMillis != null) {
406                         cpAttrList.add(new Attribute JavaDoc("max_wait_time_in_millis", (Object JavaDoc)maxWaitTimeInMillis));
407                     }
408             if (failAllConnections != null) {
409                 cpAttrList.add(new Attribute JavaDoc("fail-all-connections",(Object JavaDoc)failAllConnections));
410             }
411             if (transactionSupport != null) {
412                 cpAttrList.add(new Attribute JavaDoc("transaction-support", (Object JavaDoc)transactionSupport));
413             }
414
415
416                     getMBeanServer().invoke(resObjName, "createConnectorConnectionPool",
417                                 new Object JavaDoc[] {cpAttrList, properties, tgtName},
418                                 new String JavaDoc[] {AttributeList JavaDoc.class.getName(), Properties JavaDoc.class.getName(), "java.lang.String"});
419                 }
420
421                 // Add connector-resource
422
AttributeList JavaDoc crAttrList = new AttributeList JavaDoc();
423                 crAttrList.add(new Attribute JavaDoc("jndi_name", (Object JavaDoc)jndiName));
424                 crAttrList.add(new Attribute JavaDoc("pool_name", (Object JavaDoc)defPoolName));
425                 if(enabled!=null)
426                     crAttrList.add(new Attribute JavaDoc("enabled", enabled));
427                 if(description!=null)
428                     crAttrList.add(new Attribute JavaDoc("description", description));
429                 try {
430                     mbean = (ObjectName JavaDoc)getMBeanServer().invoke(resObjName, "createConnectorResource",
431                                 new Object JavaDoc[] {crAttrList, null, tgtName},
432                                 new String JavaDoc[] {AttributeList JavaDoc.class.getName(), Properties JavaDoc.class.getName(), "java.lang.String"});
433                 } catch (MBeanException JavaDoc me) {
434                     me.printStackTrace();
435                     // Rollback the change of connector-connection-pool creation
436
// delete pool only if it was created in this method
437
if(connPool==null)
438                     {
439                             getMBeanServer().invoke(resObjName, "deleteConnectorConnectionPool",
440                                 new Object JavaDoc[] {defPoolName, tgtName},
441                                 new String JavaDoc[] {"java.lang.String", "java.lang.String"});
442                     }
443                     throw me;
444                 }
445             }
446             else if (resourceType.equals("javax.jms.Topic") ||
447                     resourceType.equals("javax.jms.Queue"))
448             {
449                 validateDestinationResource(properties, jndiName);
450                 // create admin object
451
AttributeList JavaDoc aoAttrList = new AttributeList JavaDoc();
452                 aoAttrList.add(new Attribute JavaDoc("jndi_name", (Object JavaDoc)jndiName));
453                 aoAttrList.add(new Attribute JavaDoc("res_type", (Object JavaDoc)resourceType));
454                 aoAttrList.add(new Attribute JavaDoc("res_adapter", (Object JavaDoc)raName));
455                 if(enabled!=null)
456                     aoAttrList.add(new Attribute JavaDoc("enabled", enabled));
457                 if(description!=null)
458                     aoAttrList.add(new Attribute JavaDoc("description", description));
459                 sLogger.info("props = " + properties);
460
461                 mbean = (ObjectName JavaDoc)getMBeanServer().invoke(resObjName, "createAdminObjectResource",
462                             new Object JavaDoc[] {aoAttrList, properties, tgtName},
463                             new String JavaDoc[] {AttributeList JavaDoc.class.getName(), Properties JavaDoc.class.getName(), "java.lang.String"});
464             } else {
465                 throw new Exception JavaDoc(localStrings.getString("admin.mbeans.rmb.invalid_res_type", resourceType));
466             }
467 /* }
468         catch (MBeanException me) {
469             throw me;
470         }
471         catch (Exception e) {
472             throw new MBeanException(e, e.getLocalizedMessage());
473         }
474 */

475         return mbean;
476     }
477     
478     private void validateDestinationResource(Properties JavaDoc props, String JavaDoc jndiName)
479                                                     throws Exception JavaDoc {
480         if (props == null) {
481             throw new Exception JavaDoc(localStrings.getString(
482                     "admin.mbeans.rmb.destination_name_missing", jndiName));
483         }
484         for (Enumeration JavaDoc e = props.keys() ; e.hasMoreElements() ;) {
485             String JavaDoc key = (String JavaDoc)e.nextElement();
486             String JavaDoc value = (String JavaDoc)props.get(key);
487             if(key.equals("Name") || key.equals("imqDestinationName")){
488                 if (value != null && value.length() != 0) return;
489             }
490         }
491         throw new Exception JavaDoc(localStrings.getString(
492         "admin.mbeans.rmb.destination_name_missing", jndiName));
493
494     }
495
496     public ObjectName JavaDoc createJdbcConnectionPool( AttributeList JavaDoc attrList,
497                                                 Properties JavaDoc props,
498                                                 String JavaDoc tgtName)
499         throws Exception JavaDoc
500     {
501         return createResource( JDBC_CONNECTION_POOL, attrList, props, tgtName );
502     }
503
504     public ObjectName JavaDoc createConnectorConnectionPool( AttributeList JavaDoc attrList,
505                                                      Properties JavaDoc props,
506                                                      String JavaDoc tgtName)
507         throws Exception JavaDoc
508     {
509         //validateCnctorConnPoolAttrList(attrList);
510
return createResource( CONNECTOR_CONNECTION_POOL, attrList, props, tgtName );
511     }
512
513     public ObjectName JavaDoc createConnectorResource( AttributeList JavaDoc attrList,
514                                                Properties JavaDoc props,
515                                                String JavaDoc tgtName)
516         throws Exception JavaDoc
517     {
518         return createResource( CONNECTOR_RESOURCE, attrList, props, tgtName );
519     }
520
521     public ObjectName JavaDoc createAdminObjectResource( AttributeList JavaDoc attrList,
522                                                  Properties JavaDoc props,
523                                                  String JavaDoc tgtName)
524         throws Exception JavaDoc
525     {
526         String JavaDoc raName = null;
527         String JavaDoc resType = null;
528         boolean validResType = false;
529
530         // Find out the value of raname attribute in the attrList
531
for (int i=0; i<attrList.size(); i++)
532         {
533             Attribute JavaDoc attr = (Attribute JavaDoc)attrList.get(i);
534
535             if (isAttrNameMatch(attr, "res-adapter")) {
536                 raName = (String JavaDoc)attr.getValue();
537             }
538             if (isAttrNameMatch(attr, "res-type")) {
539                 resType = (String JavaDoc)attr.getValue();
540             }
541         }
542
543         if (isValidRAName(raName)) {
544             // Check if the restype is valid -
545
// To check this, we need to get the list of admin-object-interface
546
// names and then find out if this list contains the restype.
547
String JavaDoc[] resTypes = ConnectorRuntime.getRuntime().getAdminObjectInterfaceNames(raName);
548             if (resTypes == null || resTypes.length <= 0)
549                 throw new Exception JavaDoc(localStrings.getString("admin.mbeans.rmb.null_ao_intf", raName));
550             
551             for (int i=0; i<resTypes.length; i++) {
552                 if (resTypes[i].equals(resType)) {
553                     validResType = true;
554                     break;
555                 }
556             }
557
558             if (!validResType) {
559                 throw new Exception JavaDoc(localStrings.getString("admin.mbeans.rmb.invalid_res_type", resType));
560             }
561
562             return createResource( ADMIN_OBJECT_RESOURCE, attrList, props, tgtName );
563         }
564         else return null;
565     }
566
567     public ObjectName JavaDoc createJdbcResource( AttributeList JavaDoc attrList,
568                                           Properties JavaDoc props,
569                                           String JavaDoc tgtName)
570         throws Exception JavaDoc
571     {
572         return createResource( JDBC_RESOURCE, attrList, props, tgtName );
573     }
574
575     public ObjectName JavaDoc createMailResource( AttributeList JavaDoc attrList,
576                                           Properties JavaDoc props,
577                                           String JavaDoc tgtName)
578         throws Exception JavaDoc
579     {
580         return createResource( MAIL_RESOURCE, attrList, props, tgtName );
581     }
582
583     public ObjectName JavaDoc createResourceAdapterConfig( AttributeList JavaDoc attrList,
584                                                    Properties JavaDoc props,
585                                                    String JavaDoc tgtName)
586         throws Exception JavaDoc
587     {
588         final ObjectName JavaDoc on = createResource( RESOURCE_ADAPTER_CONFIG, attrList, props, tgtName );
589
590         return on;
591     }
592
593     private ObjectName JavaDoc createResource( String JavaDoc resourceType,
594                                        AttributeList JavaDoc attrList,
595                                        Properties JavaDoc props,
596             String JavaDoc tgtName ) throws Exception JavaDoc {
597         return createResource(resourceType, attrList, props, tgtName,true);
598     }
599     
600     private ObjectName JavaDoc createResource( String JavaDoc resourceType,
601                                        AttributeList JavaDoc attrList,
602                                        Properties JavaDoc props,
603                                        String JavaDoc tgtName,
604                                        boolean createResourceRefs )
605         throws Exception JavaDoc
606     {
607         if (resourceType.equals(CONNECTOR_CONNECTION_POOL))
608              validateCnctorConnPoolAttrList(attrList);
609
610         
611         ObjectName JavaDoc mbean = null;
612
613         final Target target = TargetBuilder.INSTANCE.createTarget(
614             VALID_CREATE_DELETE_TYPES,
615             tgtName, getConfigContext()); // This method call fails as getConfigContext is returning null.
616
boolean hasReferences = isResourceReferenceValid(resourceType, target.getType());
617
618         boolean enabled = true;
619         String JavaDoc resName = getResourceName(resourceType, attrList);
620         int idxEnabled = -1;
621         if (attrList != null)
622         {
623             for(int i=0; i<attrList.size(); i++)
624             {
625                 Attribute JavaDoc attr = (Attribute JavaDoc)attrList.get(i);
626                 if (attr.getName().equals("enabled"))
627                 {
628                     enabled = Boolean.valueOf(attr.getValue().toString()).booleanValue();
629                     idxEnabled = i;
630                 }
631             }
632         }
633         
634
635         Attribute JavaDoc saveEnabledAtttr = null;
636         if(!enabled && hasReferences)
637         { //change original "enabled" value to true
638
saveEnabledAtttr = (Attribute JavaDoc)attrList.get(idxEnabled);
639             attrList.set(idxEnabled, new Attribute JavaDoc("enabled", "true"));
640         }
641         mbean = (ObjectName JavaDoc)super.invoke( "create" + ConfigMBeanHelper.convertTagName(resourceType),
642                     new Object JavaDoc[] {attrList},
643                     new String JavaDoc[] {AttributeList JavaDoc.class.getName()});
644
645         if(!enabled && hasReferences)
646         { //restore original enabled value
647
attrList.set(idxEnabled, saveEnabledAtttr);
648         }
649                     
650         // Add properties
651
if (props != null)
652         {
653             setProperties(mbean, props);
654         }
655
656         /*
657             No need to create resource-ref if
658             - resource is a jdbc-connection-pool or connector-connection-pool
659               or resource-adapter-config
660             - target is domain
661          */

662         if (!hasReferences)
663         {
664             return mbean;
665         }
666
667         // If target is server or cluster, resource-ref should also be
668
// created inside server or group/cluster element
669
if (target.getType() == TargetType.SERVER ||
670             target.getType() == TargetType.CLUSTER ||
671             target.getType() == TargetType.DAS)
672         {
673             if ( (resName != null) && !(resName.equals("")) && createResourceRefs )
674             {
675                 //System.out.println("ResourcesMBean - default creation of resource refs "+ target.getName() + " " + resName);
676
getResourceReferenceHelper().createResourceReference(
677                     target.getName(), enabled, resName);
678             }
679         }
680         return mbean;
681     }
682
683     /**
684      * Checks to see if resourcerefs are valid and can be created for
685      * the given <code>resourceType</code> in a <code>TargetType</code>
686      * @return true if resource references are valid and can be created for
687      * the passed in resourceType and targetType.
688      */

689     private boolean isResourceReferenceValid(String JavaDoc resourceType, TargetType targetType) {
690         boolean hasReferences = (!( resourceType.equals(CONNECTOR_CONNECTION_POOL) ||
691                 resourceType.equals(JDBC_CONNECTION_POOL) ||
692                 resourceType.equals(RESOURCE_ADAPTER_CONFIG) ||
693                 (targetType == TargetType.DOMAIN)));
694         return hasReferences;
695     }
696
697     /**
698      * Gets the name of the resource from the attribute list associated with the
699      * resource.
700      */

701     private String JavaDoc getResourceName(String JavaDoc resourceType, AttributeList JavaDoc attrList) {
702         if (attrList != null) {
703             if (resourceType.equals(RESOURCE_ADAPTER_CONFIG)) {
704                 for(int i=0; i<attrList.size(); i++) {
705                     Attribute JavaDoc attr = (Attribute JavaDoc)attrList.get(i);
706                     if ( attr.getName().equals("resource-adapter-name") ){
707                         return (String JavaDoc)attr.getValue();
708                     }
709                 }
710             } else {
711                 for(int i=0; i<attrList.size(); i++) {
712                     Attribute JavaDoc attr = (Attribute JavaDoc)attrList.get(i);
713                     //resource-adapter-name is for RA configs.
714
if (attr.getName().equals("name") || attr.getName().equals("jndi_name") ||
715                                     attr.getName().equals("jndi-name")) {
716                                 return (String JavaDoc)attr.getValue();
717                     }
718                 }
719             }
720         }
721         return "";
722     }
723     
724     //FIXME: this method is copied from EE Resources MBean to support AMXBean calls
725
// redundancy should be resolved in 8.2
726
public void createResourceReference(String JavaDoc targetName, boolean enabled,
727         String JavaDoc referenceName) throws ConfigException
728     {
729         //System.out.println("ResourcesMBean: createResourceRef" + targetName + " " + referenceName);
730
getResourceReferenceHelper().createResourceReference(
731                 targetName, enabled, referenceName);
732     }
733            
734     /**
735      * Creates a Resource Reference for the resource passed in the targe
736      * @param resource <code>Resource</code> object for which the resource-ref
737      * needs to be created.
738      * @throws ConfigException
739      */

740     public void createResourceReference(String JavaDoc targetName, boolean enabled,
741                     Resource resource) throws ConfigException {
742         this.createResourceReference(targetName, enabled, getResourceName(resource.getType(), resource.getAttributes()));
743     }
744     
745     /**
746      * Creating resources from sun-resources.xml file. This API
747      * is used by the deployment backend to create resource refs
748      * @param resources An iterator that returns the resources for which the resource
749      * refs needs to be created
750      * @param tgtName target in which the resource ref needs to be created
751      * @param isEnabled enables/disables the resource ref
752      */

753     public void createResourceReference(List JavaDoc<Resource> res, List JavaDoc<String JavaDoc> tgtNames,
754                                                            Boolean JavaDoc isEnabled) throws Exception JavaDoc {
755         Iterator JavaDoc<Resource> resources = res.iterator();
756         //@todo: handle isEnabled. This should override the enabled flag specified
757
//in the individual Resources.
758
while (resources.hasNext()) {
759             createAResourceReference(resources.next(), tgtNames, isEnabled);
760         }
761     }
762     
763     private void createAResourceReference(Resource res, List JavaDoc<String JavaDoc> tgtNames, Boolean JavaDoc isEnabled)
764                                                            throws Exception JavaDoc {
765         for (String JavaDoc target : tgtNames) {
766             createAResourceReference(res, target, isEnabled);
767         }
768     }
769     
770     private void createAResourceReference(Resource res, String JavaDoc target, Boolean JavaDoc isEnabled)
771     throws Exception JavaDoc {
772         TargetType targetType = getResourceTarget(target).getType();
773         String JavaDoc resourceType = res.getType();
774         if (isResourceReferenceValid(resourceType,targetType)) {
775             createResourceReference(target, isEnabled.booleanValue(), getResourceName(res.getType(), res.getAttributes()));
776         }
777     }
778     
779     /**
780      * Deletes the Resource Reference for the resource passed in the target
781      * @param targetName target from which the resource ref needs to be deleted
782      * @param resource <code>Resource</code> object for which the resource-ref
783      * needs to be deleted.
784      * @throws Exception
785      */

786     public void deleteResourceReference(String JavaDoc targetName, Resource resource) throws Exception JavaDoc {
787         Target target = getResourceTarget(targetName);
788         this.deleteResourceRef(getResourceName(resource.getType(), resource.getAttributes()), target, targetName);
789     }
790     
791     /**
792      * Deletes the Resource Reference for the resource passed in the target
793      * @param targetName target from which the resource ref needs to be deleted
794      * @param resource <code>Resource</code> object for which the resource-ref
795      * needs to be deleted.
796      * @throws Exception
797      */

798     public void deleteResourceReference(List JavaDoc<Resource> res, List JavaDoc<String JavaDoc> targetNames) throws Exception JavaDoc {
799         //System.out.println("Dlete resource refs in refs");
800
int size = res.size();
801         //@todo: modify this to simplify the loop logic
802
for (int i = (size -1); i >= 0 ; i--) {
803             Resource resource = res.get(i);
804             deleteAResourceRef(resource, targetNames);
805         }
806     }
807     
808
809     private void deleteAResourceRef(Resource resource, List JavaDoc<String JavaDoc> targetNames) throws Exception JavaDoc {
810         //System.out.println("ResourcesMBean deleteAResourceRef " + resource.getType());
811
for (String JavaDoc tgt : targetNames) {
812             Target target = getResourceTarget(tgt);
813             if (isResourceReferenceValid(resource.getType(),target.getType())) {
814                 this.deleteResourceRef(getResourceName(resource.getType(), resource.getAttributes()), target, tgt);
815             }
816         }
817     }
818     
819     
820     private void setProperties(ObjectName JavaDoc objName, Properties JavaDoc props)
821         throws Exception JavaDoc
822     {
823             if ( props != null )
824             {
825                 Enumeration JavaDoc keys = props.keys();
826                 while (keys.hasMoreElements())
827                 {
828                     final String JavaDoc key = (String JavaDoc)keys.nextElement();
829                     final Attribute JavaDoc property = new Attribute JavaDoc(key, props.get(key));
830                     getMBeanServer().invoke(objName, "setProperty", new Object JavaDoc[]{property}, new String JavaDoc[]{Attribute JavaDoc.class.getName()});
831                 }
832             }
833     }
834
835     private boolean isValidRAName(String JavaDoc raName) throws Exception JavaDoc
836     {
837         boolean retVal = false;
838
839 // try {
840
if ((raName == null) || (raName.equals("")))
841                 throw new Exception JavaDoc(localStrings.getString("admin.mbeans.rmb.null_res_adapter"));
842
843             // To check for embedded conenctor module
844
if (raName.equals(ConnectorRuntime.DEFAULT_JMS_ADAPTER) || raName.equals(ConnectorRuntime.JAXR_RA_NAME)) {
845                 // System RA, so don't validate
846
retVal = true;
847             } else {
848                 // Check if the raName contains double underscore or hash.
849
// If that is the case then this is the case of an embedded rar,
850
// hence look for the application which embeds this rar,
851
// otherwise look for the webconnector module with this raName.
852

853                 ObjectName JavaDoc applnObjName = m_registry.getMbeanObjectName(ServerTags.APPLICATIONS, new String JavaDoc[]{getDomainName()});
854                 int indx = raName.indexOf(
855                        ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER);
856                 if (indx != -1) {
857                     String JavaDoc appName = raName.substring(0, indx);
858                     ObjectName JavaDoc j2eeAppObjName = (ObjectName JavaDoc)getMBeanServer().invoke(applnObjName, "getJ2eeApplicationByName", new Object JavaDoc[]{appName}, new String JavaDoc[]{"java.lang.String"});
859
860                     if (j2eeAppObjName == null)
861                         throw new Exception JavaDoc(localStrings.getString("admin.mbeans.rmb.invalid_ra_app_not_found", appName));
862                     else retVal = true;
863                 } else {
864                     ObjectName JavaDoc connectorModuleObjName = (ObjectName JavaDoc)getMBeanServer().invoke(applnObjName, "getConnectorModuleByName", new Object JavaDoc[]{raName}, new String JavaDoc[]{"java.lang.String"});
865
866                     if (connectorModuleObjName == null)
867                         throw new Exception JavaDoc(localStrings.getString("admin.mbeans.rmb.invalid_ra_cm_not_found", raName));
868                     else retVal = true;
869                 }
870             }
871 /* }
872         catch (javax.management.MBeanException me) {
873             throw me;
874         }
875         catch (Exception e) {
876             throw new MBeanException(e, e.getLocalizedMessage());
877         }
878 */

879         return retVal;
880     }
881
882
883
884     /**
885      *
886      */

887     private void validateCnctorConnPoolAttrList(AttributeList JavaDoc list) throws Exception JavaDoc {
888         String JavaDoc raName = getAttributeValueFromList("resource_adapter_name",list);
889         String JavaDoc connDef = getAttributeValueFromList("connection_definition_name",list);
890         if(isValidRAName(raName)) {
891             if(!isValidConnectionDefinition(connDef,raName)) {
892                 throw new Exception JavaDoc(localStrings.getString(
893                         "admin.mbeans.rmb.invalid_ra_connectdef_not_found",connDef));
894             }
895         }
896     }
897
898     /**
899      *
900      */

901     private boolean isValidConnectionDefinition(String JavaDoc connectionDef,String JavaDoc raName) throws Exception JavaDoc{
902         String JavaDoc [] names =
903                 ConnectorRuntime.getRuntime().getConnectionDefinitionNames(raName);
904         for(int i = 0; i < names.length; i++) {
905             if(names[i].equals(connectionDef)) {
906                 return true;
907             }
908         }
909         return false;
910     }
911
912
913     /**
914      *
915      */

916     private String JavaDoc getAttributeValueFromList(String JavaDoc name, AttributeList JavaDoc list) {
917         for (int i=0; i<list.size(); i++) {
918             Attribute JavaDoc attr = (Attribute JavaDoc)list.get(i);
919             if (isAttrNameMatch(attr, name)) {
920                 return (String JavaDoc)attr.getValue();
921             }
922         }
923         return "";
924     }
925
926
927     /**
928      * GETTER Methods for resources
929      */

930     public ObjectName JavaDoc getCustomResourceByJndiName( String JavaDoc key, String JavaDoc tgtName )
931         throws Exception JavaDoc
932     {
933         return getResourceByName( CUSTOM_RESOURCE, key, tgtName );
934     }
935
936     public ObjectName JavaDoc getJdbcResourceByJndiName( String JavaDoc key, String JavaDoc tgtName )
937         throws Exception JavaDoc
938     {
939         return getResourceByName( JDBC_RESOURCE, key, tgtName );
940     }
941
942     public ObjectName JavaDoc getJdbcConnectionPoolByName( String JavaDoc key, String JavaDoc tgtName )
943         throws Exception JavaDoc
944     {
945         return getResourceByName( JDBC_CONNECTION_POOL, key, tgtName );
946     }
947
948     public ObjectName JavaDoc getExternalJndiResourceByJndiName( String JavaDoc key, String JavaDoc tgtName )
949         throws Exception JavaDoc
950     {
951         return getResourceByName( EXTERNAL_JNDI_RESOURCE, key, tgtName );
952     }
953
954     public ObjectName JavaDoc getMailResourceByJndiName( String JavaDoc key, String JavaDoc tgtName )
955         throws Exception JavaDoc
956     {
957         return getResourceByName( MAIL_RESOURCE, key, tgtName );
958     }
959
960     public ObjectName JavaDoc getConnectorResourceByJndiName( String JavaDoc key, String JavaDoc tgtName )
961         throws Exception JavaDoc
962     {
963         return getResourceByName( CONNECTOR_RESOURCE, key, tgtName );
964     }
965
966     public ObjectName JavaDoc getResourceAdapterConfigByResourceAdapterName( String JavaDoc key, String JavaDoc tgtName )
967         throws Exception JavaDoc
968     {
969         return getResourceByName( RESOURCE_ADAPTER_CONFIG, key, tgtName );
970     }
971
972     public ObjectName JavaDoc getAdminObjectResourceByJndiName( String JavaDoc key, String JavaDoc tgtName )
973         throws Exception JavaDoc
974     {
975         return getResourceByName( ADMIN_OBJECT_RESOURCE, key, tgtName );
976     }
977
978     public ObjectName JavaDoc getPersistenceManagerFactoryResourceByJndiName( String JavaDoc key, String JavaDoc tgtName )
979         throws Exception JavaDoc
980     {
981         return getResourceByName( PERSISTENCE_MANAGER_FACTORY_RESOURCE, key, tgtName );
982     }
983
984     public ObjectName JavaDoc getConnectorConnectionPoolByName( String JavaDoc key, String JavaDoc tgtName )
985         throws Exception JavaDoc
986     {
987         return getResourceByName( CONNECTOR_CONNECTION_POOL, key, tgtName );
988     }
989
990     private ObjectName JavaDoc getResourceByName( String JavaDoc resType, String JavaDoc key, String JavaDoc tgtName )
991         throws Exception JavaDoc
992     {
993         ObjectName JavaDoc mbean = null;
994
995 // try
996
{
997             final Target target = TargetBuilder.INSTANCE.createTarget(
998                 VALID_LIST_TYPES, tgtName, getConfigContext());
999             String JavaDoc opName = "";
1000            if (resType.equals(RESOURCE_ADAPTER_CONFIG)) {
1001                // opName is getResourceAdapterConfigByResourceAdapterName
1002
opName = GET + ConfigMBeanHelper.convertTagName(resType) + "By" + ConfigMBeanHelper.convertTagName(ServerTags.RESOURCE_ADAPTER_NAME);
1003            } else if (resType.equals(JDBC_CONNECTION_POOL) || resType.equals(CONNECTOR_CONNECTION_POOL)) {
1004                // opName is getJdbcConnectionPoolByName or getConnectorConnectionPoolByName
1005
opName = GET + ConfigMBeanHelper.convertTagName(resType) + BYNAME;
1006            } else opName = GET + ConfigMBeanHelper.convertTagName(resType) + BYJNDINAME;
1007
1008            mbean = (ObjectName JavaDoc)super.invoke(opName, new Object JavaDoc[] {key},
1009                        new String JavaDoc[] {key.getClass().getName()});
1010        }
1011/* catch (MBeanException me)
1012        {
1013            throw me;
1014        }
1015        catch (Exception e)
1016        {
1017            e.printStackTrace();
1018            throw new MBeanException(e, e.getLocalizedMessage());
1019        }
1020*/

1021        return mbean;
1022    }
1023
1024    /**
1025     * GETTER Methods for resources
1026     */

1027    public ObjectName JavaDoc[] getCustomResource( String JavaDoc tgtName )
1028        throws Exception JavaDoc
1029    {
1030        return getResource( CUSTOM_RESOURCE, tgtName );
1031    }
1032
1033    public ObjectName JavaDoc[] getPersistenceManagerFactoryResource( String JavaDoc tgtName )
1034        throws Exception JavaDoc
1035    {
1036        return getResource( PERSISTENCE_MANAGER_FACTORY_RESOURCE, tgtName );
1037    }
1038
1039    public ObjectName JavaDoc[] getJmsResource( String JavaDoc tgtName )
1040        throws Exception JavaDoc
1041    {
1042        return getJmsResource( null, tgtName );
1043    }
1044
1045    public ObjectName JavaDoc[] getJmsConnectionFactory( String JavaDoc tgtName )
1046        throws Exception JavaDoc
1047    {
1048        ObjectName JavaDoc[] QRes = null;
1049        ObjectName JavaDoc[] TRes = null;
1050        ObjectName JavaDoc[] uRes = null;
1051        ObjectName JavaDoc[] retVal = null;
1052
1053        QRes = getJmsResource( QUEUE_CF, tgtName );
1054        TRes = getJmsResource( TOPIC_CF, tgtName );
1055        uRes = getJmsResource( UNIFIED_CF, tgtName );
1056
1057        int i = 0;
1058        if (QRes != null) i = QRes.length;
1059        if (TRes != null) i = i + TRes.length;
1060        if (uRes != null) i = i + uRes.length;
1061
1062        if (i > 0) {
1063            ArrayList JavaDoc ret = new ArrayList JavaDoc();
1064            if (QRes != null) ret.addAll(Arrays.asList(QRes));
1065            if (TRes != null) ret.addAll(Arrays.asList(TRes));
1066            if (uRes != null) ret.addAll(Arrays.asList(uRes));
1067
1068            if (ret.size() > 0) {
1069                    retVal = new ObjectName JavaDoc[ret.size()];
1070                    ret.toArray(retVal);
1071            }
1072        }
1073
1074        return retVal;
1075    }
1076
1077    public ObjectName JavaDoc[] getJmsDestinationResource( String JavaDoc tgtName )
1078        throws Exception JavaDoc
1079    {
1080        ObjectName JavaDoc[] QRes = null;
1081        ObjectName JavaDoc[] TRes = null;
1082        ObjectName JavaDoc[] retVal = null;
1083
1084        QRes = getJmsResource( QUEUE, tgtName );
1085        TRes = getJmsResource( TOPIC, tgtName );
1086
1087        int i = 0;
1088        if (QRes != null) i = QRes.length;
1089        if (TRes != null) i = i + TRes.length;
1090
1091        if (i > 0) {
1092            ArrayList JavaDoc ret = new ArrayList JavaDoc();
1093            if (QRes != null) ret.addAll(Arrays.asList(QRes));
1094            if (TRes != null) ret.addAll(Arrays.asList(TRes));
1095
1096            if (ret.size() > 0) {
1097                    retVal = new ObjectName JavaDoc[ret.size()];
1098                    ret.toArray(retVal);
1099            }
1100        }
1101
1102        return retVal;
1103    }
1104
1105    public ObjectName JavaDoc[] getJmsResource( String JavaDoc resType, String JavaDoc tgtName )
1106        throws Exception JavaDoc
1107    {
1108        Target target = getResourceTarget(tgtName);
1109
1110        ObjectName JavaDoc[] QRes = null;
1111        ObjectName JavaDoc[] TRes = null;
1112        ObjectName JavaDoc[] QCFRes = null;
1113        ObjectName JavaDoc[] TCFRes = null;
1114        ObjectName JavaDoc[] uCFRes = null;
1115        ObjectName JavaDoc[] retVal = null;
1116
1117// try {
1118
if (resType == null || resType.equals("null")) {
1119            // All types of JMS resources are needed
1120
QRes = getJmsResourceForResType(QUEUE);
1121            TRes = getJmsResourceForResType(TOPIC);
1122            QCFRes = getJmsResourceForResType(QUEUE_CF);
1123            TCFRes = getJmsResourceForResType(TOPIC_CF);
1124            uCFRes = getJmsResourceForResType(UNIFIED_CF);
1125
1126            int i = 0;
1127            if (QRes != null) i = QRes.length;
1128            if (TRes != null) i = i + TRes.length;
1129            if (QCFRes != null) i = i + QCFRes.length;
1130            if (TCFRes != null) i = i + TCFRes.length;
1131            if (uCFRes != null) i = i + uCFRes.length;
1132            if (i > 0) {
1133                ArrayList JavaDoc ret = new ArrayList JavaDoc();
1134                if (QRes != null) ret.addAll(Arrays.asList(QRes));
1135                if (TRes != null) ret.addAll(Arrays.asList(TRes));
1136                if (QCFRes != null) ret.addAll(Arrays.asList(QCFRes));
1137                if (TCFRes != null) ret.addAll(Arrays.asList(TCFRes));
1138                if (uCFRes != null) ret.addAll(Arrays.asList(uCFRes));
1139
1140                if (ret.size() > 0) {
1141                    retVal = new ObjectName JavaDoc[ret.size()];
1142                    ret.toArray(retVal);
1143                }
1144            }
1145        } else {
1146            if (!(resType.equals(QUEUE) || resType.equals(TOPIC)
1147               || resType.equals(QUEUE_CF) || resType.equals(TOPIC_CF) || resType.equals(UNIFIED_CF))) {
1148                throw new Exception JavaDoc(localStrings.getString("admin.mbeans.rmb.invalid_res_type", resType));
1149            } else {
1150                retVal = getJmsResourceForResType(resType);
1151            }
1152        }
1153/* }
1154        catch (MBeanException me)
1155        {
1156            throw me;
1157        }
1158        catch (Exception e)
1159        {
1160            throw new MBeanException(e, e.getLocalizedMessage());
1161        }
1162*/

1163        return retVal;
1164    }
1165
1166    private ObjectName JavaDoc[] getJmsResourceForResType( String JavaDoc resType )
1167        throws MBeanException JavaDoc
1168    {
1169        ObjectName JavaDoc[] retVal = null;
1170        ArrayList JavaDoc al = new ArrayList JavaDoc();
1171        try {
1172            if (resType.equals(QUEUE) || resType.equals(TOPIC)) {
1173                // get all admin-objects whose resType is Queue or Topic and
1174
// res-adapter is Default-jms-adapter
1175
ObjectName JavaDoc o = m_registry.getMbeanObjectName(RESOURCES, new String JavaDoc[]{getDomainName()});
1176                ObjectName JavaDoc[] adminObjNames = (ObjectName JavaDoc[])getMBeanServer().invoke(o, "getAdminObjectResource", null, null);
1177                if (adminObjNames != null) {
1178                    for (int i=0; i<adminObjNames.length; i++) {
1179                        String JavaDoc adminResType = (String JavaDoc)getMBeanServer().getAttribute(adminObjNames[i], "res_type");
1180                        if ((adminResType != null) && ((adminResType.equals(QUEUE) && resType.equals(QUEUE)) || (adminResType.equals(TOPIC) && resType.equals(TOPIC)))) {
1181                            //Check for the res-adapter
1182
String JavaDoc adminResAdapter = (String JavaDoc)getMBeanServer().getAttribute(adminObjNames[i], "res_adapter");
1183                            if ((adminResAdapter != null) && (adminResAdapter.equals(ConnectorRuntime.DEFAULT_JMS_ADAPTER)))
1184                                al.add(adminObjNames[i]);
1185                        }
1186                    }
1187                    if (!al.isEmpty()) {
1188                        retVal = new ObjectName JavaDoc[al.size()];
1189                        al.toArray(retVal);
1190                    }
1191                }
1192            } else {
1193                // get all connector-resources whose connector-connection-pool
1194
// satisfy the criterion -
1195
// connection-definition-name is QCF or TCF &
1196
// resource-adapter-name is DEFAULT_JMS_ADAPTER
1197
ObjectName JavaDoc o = m_registry.getMbeanObjectName(RESOURCES, new String JavaDoc[]{getDomainName()});
1198                ObjectName JavaDoc[] CRObjNames = CRObjNames = (ObjectName JavaDoc[])getMBeanServer().invoke(o, "getConnectorResource", null, null);
1199                if (CRObjNames != null) {
1200                    for (int i=0; i<CRObjNames.length; i++) {
1201                        String JavaDoc poolName = (String JavaDoc)getMBeanServer().getAttribute(CRObjNames[i], "pool_name");
1202                        if (poolName != null) {
1203                            ObjectName JavaDoc CCPObjName = null;
1204                            try {
1205                               CCPObjName = (ObjectName JavaDoc)getMBeanServer().invoke(o, "getConnectorConnectionPoolByName", new Object JavaDoc[]{poolName}, new String JavaDoc[]{"java.lang.String"});
1206                            } catch (Exception JavaDoc ee){};
1207                            if (CCPObjName != null) {
1208                                String JavaDoc cdn = (String JavaDoc)getMBeanServer().getAttribute(CCPObjName, "connection_definition_name");
1209                                if ((cdn != null) && ((cdn.equals(resType)) || ((cdn.equals(resType))))) {
1210                                    //Check for the res-adapter
1211
String JavaDoc resAdapter = (String JavaDoc)getMBeanServer().getAttribute(CCPObjName, "resource_adapter_name");
1212                                    if ((resAdapter != null) && (resAdapter.equals(ConnectorRuntime.DEFAULT_JMS_ADAPTER)))
1213                                        al.add(CRObjNames[i]);
1214                                }
1215                            }
1216                        }
1217                    }
1218
1219                    if (!al.isEmpty()) {
1220                        retVal = new ObjectName JavaDoc[al.size()];
1221                        al.toArray(retVal);
1222                    }
1223                }
1224            }//end of else block
1225
}//end of try
1226
catch (javax.management.InstanceNotFoundException JavaDoc infe) {}
1227        catch (javax.management.ReflectionException JavaDoc re) {}
1228        catch (javax.management.AttributeNotFoundException JavaDoc anf) {}
1229
1230        return retVal;
1231    }
1232
1233    public ObjectName JavaDoc[] getJdbcConnectionPool( String JavaDoc tgtName )
1234        throws Exception JavaDoc
1235    {
1236        return getResource( JDBC_CONNECTION_POOL, tgtName );
1237    }
1238
1239    public ObjectName JavaDoc[] getConnectorResource( String JavaDoc tgtName )
1240        throws Exception JavaDoc
1241    {
1242        return getResource( CONNECTOR_RESOURCE, tgtName );
1243    }
1244
1245    public ObjectName JavaDoc[] getAdminObjectResource( String JavaDoc tgtName )
1246        throws Exception JavaDoc
1247    {
1248        return getResource( ADMIN_OBJECT_RESOURCE, tgtName );
1249    }
1250
1251    public ObjectName JavaDoc[] getConnectorConnectionPool( String JavaDoc tgtName )
1252        throws Exception JavaDoc
1253    {
1254        return getResource( CONNECTOR_CONNECTION_POOL, tgtName );
1255    }
1256
1257    public ObjectName JavaDoc[] getJdbcResource( String JavaDoc tgtName )
1258        throws Exception JavaDoc
1259    {
1260        return getResource( JDBC_RESOURCE, tgtName );
1261    }
1262
1263    public ObjectName JavaDoc[] getResourceAdapterConfig( String JavaDoc tgtName )
1264        throws Exception JavaDoc
1265    {
1266        return getResource( RESOURCE_ADAPTER_CONFIG, tgtName );
1267    }
1268
1269    public String JavaDoc getResourceAdapterConfig( String JavaDoc resAdapterConfig, Boolean JavaDoc verbose, String JavaDoc tgtName )
1270        throws Exception JavaDoc
1271    {
1272        String JavaDoc retVal = null;
1273        StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
1274
1275// try {
1276
if ((resAdapterConfig != null) && !(resAdapterConfig.equals("")) && !(resAdapterConfig.equals("null"))) {
1277                ObjectName JavaDoc rac = null;
1278                try {
1279                    rac = (ObjectName JavaDoc) super.invoke("getResourceAdapterConfigByResourceAdapterName", new Object JavaDoc[]{resAdapterConfig}, new String JavaDoc[]{"java.lang.String"});
1280                } catch (Exception JavaDoc ee){};
1281                if (rac == null) {
1282                    throw new Exception JavaDoc(localStrings.getString("admin.mbeans.rmb.null_rac"));
1283                }
1284                else {
1285                    /**
1286                        get the properties if verbose=true. Otherwise return the
1287                        name.
1288                     */

1289                    retVal = verbose.booleanValue() ?
1290                        getFormattedProperties(rac) :
1291                        rac.getKeyProperty("resource-adapter-name");
1292                }
1293            }
1294            else {
1295                ObjectName JavaDoc[] rac = getResource( RESOURCE_ADAPTER_CONFIG, tgtName );
1296
1297                if (verbose.booleanValue() && rac != null && rac.length>0) {
1298                    for (int i=0; i<rac.length; i++) {
1299                        sb.append(getFormattedProperties(rac[i]));
1300            sb.append("\n");
1301                    }
1302                } else if(!verbose.booleanValue() && rac != null && rac.length>0) {
1303                    for (int i=0; i<rac.length; i++) {
1304                        sb.append(rac[i].getKeyProperty("resource-adapter-name"));
1305                        sb.append("\n");
1306                    }
1307                } else sb.append("No resource-adapter-config found.");
1308
1309                retVal = sb.toString();
1310            }
1311/* }
1312        catch (MBeanException me) {
1313            throw me;
1314        }
1315        catch (Exception e) {
1316            throw new MBeanException(e, e.getLocalizedMessage());
1317        }
1318*/

1319        return retVal;
1320    }
1321
1322    private String JavaDoc getFormattedProperties(ObjectName JavaDoc objName) throws Exception JavaDoc
1323    {
1324        StringBuffer JavaDoc retVal = new StringBuffer JavaDoc();
1325
1326// try {
1327
if (objName == null)
1328                throw new Exception JavaDoc(localStrings.getString("admin.mbeans.rmb.null_rac"));
1329
1330            retVal.append(objName.getKeyProperty("resource-adapter-name"));
1331
1332            AttributeList JavaDoc props = (AttributeList JavaDoc) getMBeanServer().invoke(objName, "getProperties", null, null);
1333
1334            if (!props.isEmpty()) {
1335                for (int i=0; i<props.size(); i++) {
1336                    Attribute JavaDoc attrib = (Attribute JavaDoc)props.get(i);
1337                    if (i==0) retVal.append("\n");
1338                    retVal.append("\t");
1339                    retVal.append(attrib.getName());
1340                    retVal.append("=");
1341                    retVal.append(attrib.getValue());
1342                    retVal.append("\n");
1343                }
1344            }
1345/* }
1346        catch (Exception e) {
1347            e.printStackTrace();
1348            throw new MBeanException(e, e.getLocalizedMessage());
1349        }
1350*/

1351        return retVal.toString();
1352    }
1353
1354    public ObjectName JavaDoc[] getMailResource( String JavaDoc tgtName )
1355        throws Exception JavaDoc
1356    {
1357        return getResource( MAIL_RESOURCE, tgtName );
1358    }
1359
1360    public ObjectName JavaDoc[] getExternalJndiResource( String JavaDoc tgtName )
1361        throws Exception JavaDoc
1362    {
1363        return getResource( EXTERNAL_JNDI_RESOURCE, tgtName );
1364    }
1365
1366    private ObjectName JavaDoc[] getResource( String JavaDoc resType, String JavaDoc tgtName )
1367       throws Exception JavaDoc
1368    {
1369        ArrayList JavaDoc result = new ArrayList JavaDoc();
1370
1371        final Target target = TargetBuilder.INSTANCE.createTarget(
1372            VALID_LIST_TYPES, tgtName, getConfigContext());
1373        ObjectName JavaDoc[] mbean = (ObjectName JavaDoc[])super.invoke( GET + ConfigMBeanHelper.convertTagName(resType), null, null);
1374
1375        /**
1376            resource-ref business doesnot apply to jdbc-connection-pool,
1377            connector-connection-pool & resource-adapter-config. So return
1378            the pools as if the target were domain. &
1379
1380            If the target is domain, return all the resources of the specific
1381            type.
1382         */

1383        if (CONNECTOR_CONNECTION_POOL.equals(resType) ||
1384            JDBC_CONNECTION_POOL.equals(resType) ||
1385            RESOURCE_ADAPTER_CONFIG.equals(resType) ||
1386            (target.getType() == TargetType.DOMAIN))
1387        {
1388            return mbean;
1389        }
1390
1391
1392        if (target.getType() == TargetType.SERVER ||
1393            target.getType() == TargetType.CLUSTER ||
1394            target.getType() == TargetType.DAS) {
1395            //filter out only those resources referenced by the target
1396
ResourceRef[] refs = target.getResourceRefs();
1397            String JavaDoc objectProps = null;
1398            for (int i = 0; i < mbean.length; i++) {
1399                for (int j = 0; j < refs.length; j++) {
1400                    objectProps = mbean[i].getKeyPropertyListString();
1401                    if (objectProps.indexOf(refs[j].getRef()) > 0) {
1402                        result.add(mbean[i]);
1403                        break;
1404                    }
1405                }
1406            }
1407        }
1408
1409        return (ObjectName JavaDoc[])result.toArray(new ObjectName JavaDoc[result.size()]);
1410    }
1411
1412    /**
1413    * Delete Methods for the resources
1414    */

1415    public void deleteCustomResource( String JavaDoc name, String JavaDoc tgtName )
1416        throws Exception JavaDoc
1417    {
1418        this.deleteResource(CUSTOM_RESOURCE, name, tgtName);
1419    }
1420
1421    public void deleteJdbcConnectionPool( String JavaDoc name, String JavaDoc tgtName )
1422        throws Exception JavaDoc
1423    {
1424        this.deleteJdbcConnectionPool(name, new Boolean JavaDoc(false), tgtName);
1425    }
1426
1427    public void deleteJdbcConnectionPool( String JavaDoc name, Boolean JavaDoc cascade, String JavaDoc tgtName )
1428        throws Exception JavaDoc
1429    {
1430        // Passing the resType as eleteConnectionPool is common method for both
1431
// jdbc-connection-pool and connector-connection-pool deletion
1432
deleteConnectionPool(JDBC_RESOURCE, name, cascade, tgtName);
1433    }
1434
1435    void deleteResourceRefFromTargets(String JavaDoc ref) throws Exception JavaDoc
1436    {
1437        //System.out.println("del res ref from Targets" + ref);
1438
final ConfigContext ctx = getConfigContext();
1439        final String JavaDoc targets = ResourceHelper.getResourceReferenceesAsString(
1440            ctx, ref);
1441        final StringTokenizer JavaDoc strTok = new StringTokenizer JavaDoc(targets, ",");
1442        while (strTok.hasMoreTokens())
1443        {
1444            final String JavaDoc target = strTok.nextToken();
1445            if (ServerHelper.isAServer(ctx, target) &&
1446                ServerHelper.isServerClustered (ctx, target))
1447            {
1448                //Skip the clustered servers.
1449
continue;
1450            }
1451            getResourceReferenceHelper().deleteResourceReference(
1452                target, ref);
1453        }
1454    }
1455
1456    private void deleteConnectionPool( String JavaDoc resType, String JavaDoc name, Boolean JavaDoc cascade, String JavaDoc tgtName )
1457        throws Exception JavaDoc
1458    {
1459        // Find out if the connection-pool is being accessed by any jdbc-resource/connector-resource
1460
// If yes, throw MBeanException that it can't be deleted as it is being
1461
// referenced by jdbc-resource in case cascade is false
1462
boolean crFound = false;
1463        boolean pmfFound = false;
1464
1465        Target target = getResourceTarget(tgtName);
1466
1467// try {
1468
String JavaDoc[] resArr = null;
1469            String JavaDoc[] pmfArr = null;
1470
1471            String JavaDoc opName = GET + ConfigMBeanHelper.convertTagName(resType);
1472            ObjectName JavaDoc[] resObjNames = (ObjectName JavaDoc[])super.invoke(opName, new Object JavaDoc[]{tgtName}, new String JavaDoc[]{"java.lang.String"});
1473
1474            if (resObjNames != null && resObjNames.length > 0)
1475            {
1476                int k=0;
1477                resArr = new String JavaDoc[resObjNames.length];
1478                for (int i=0; i<resObjNames.length; i++)
1479                {
1480                    String JavaDoc poolName = (String JavaDoc)getMBeanServer().getAttribute(resObjNames[i], "pool_name");
1481                    if (poolName.equals(name)) {
1482                        String JavaDoc jndiName = (String JavaDoc)getMBeanServer().getAttribute(resObjNames[i], "jndi_name");
1483                        resArr[k++] = jndiName;
1484                        crFound = true;
1485                    }
1486                }
1487            }
1488
1489            if (resType.equalsIgnoreCase(JDBC_RESOURCE) && crFound)
1490            {
1491                // If there exists, pmf with jdbc-resource-jndi-name as the jdbc-resources' jndi-name,
1492
// we need to delete them too as they are indirectly connected to this conn-pool.
1493
String JavaDoc pmfOp = GET + ConfigMBeanHelper.convertTagName(PERSISTENCE_MANAGER_FACTORY_RESOURCE);
1494                ObjectName JavaDoc[] pmfObjNames = (ObjectName JavaDoc[])super.invoke(pmfOp, new Object JavaDoc[]{tgtName}, new String JavaDoc[]{"java.lang.String"});
1495                
1496                if (pmfObjNames != null && pmfObjNames.length > 0)
1497                {
1498                    int k=0;
1499                    pmfArr = new String JavaDoc[pmfObjNames.length];
1500                    for (int i=0; i<pmfObjNames.length; i++)
1501                    {
1502                        String JavaDoc jrjnName = (String JavaDoc)getMBeanServer().getAttribute(pmfObjNames[i], "jdbc_resource_jndi_name");
1503                        for (int j=0; j<resArr.length && resArr[j] != null; j++)
1504                        {
1505                            if (jrjnName.equals(resArr[j])) {
1506                                String JavaDoc pmfJndiName = (String JavaDoc)getMBeanServer().getAttribute(pmfObjNames[i], "jndi_name");
1507                                pmfArr[k++] = pmfJndiName;
1508                                pmfFound = true;
1509                                break;
1510                            }
1511                        }
1512                    }
1513                }
1514            }
1515
1516            if (!cascade.booleanValue() && (crFound || pmfFound))
1517            {
1518                if (resType.equalsIgnoreCase(JDBC_RESOURCE))
1519                    throw new Exception JavaDoc(localStrings.getString("admin.mbeans.rmb.jdbc_res_pmf_ref_exists"));
1520                else
1521                    throw new Exception JavaDoc(localStrings.getString("admin.mbeans.rmb.conn_res_ref_exists"));
1522            } else if(cascade.booleanValue()) {
1523                if (pmfFound && (pmfArr!=null))
1524                {
1525                    // Delete the pmf resources attached with this conn pool also
1526
for (int i=0; i<pmfArr.length && pmfArr[i] != null; i++) {
1527                        deleteResourceRefFromTargets(pmfArr[i]);
1528                        boolean isDeleted = destroyResource(PERSISTENCE_MANAGER_FACTORY_RESOURCE, pmfArr[i]);
1529                        if (!isDeleted) {
1530                            throw new Exception JavaDoc (localStrings.getString("admin.mbeans.rmb.pmf_not_deleted", pmfArr[i]));
1531                        }
1532                    }
1533                }
1534                
1535                if (resArr != null) {
1536                    // Delete the jdbc/connector resources attached with this conn pool also
1537
for (int i=0; i<resArr.length && resArr[i] != null; i++) {
1538                        deleteResourceRefFromTargets(resArr[i]);
1539                        boolean isDeleted = destroyResource(resType, resArr[i]);
1540                        if (!isDeleted) {
1541                            if (resType.equalsIgnoreCase(JDBC_RESOURCE))
1542                                throw new Exception JavaDoc (localStrings.getString("admin.mbeans.rmb.jdbc_res_not_deleted", resArr[i]));
1543                            else
1544                                throw new Exception JavaDoc (localStrings.getString("admin.mbeans.rmb.conn_res_not_deleted", resArr[i]));
1545                        }
1546                    }
1547                }
1548            }
1549
1550            /*
1551                There wont be any resource-refs for jdbc & connector connection
1552                pools.
1553
1554                deleteResourceRef(name, target, tgtName);
1555             */

1556            if (resType.equalsIgnoreCase(JDBC_RESOURCE))
1557                destroyResource(JDBC_CONNECTION_POOL,name);
1558            else
1559                destroyResource(CONNECTOR_CONNECTION_POOL,name);
1560            
1561/* }
1562        catch (MBeanException me) {
1563            throw me;
1564        }
1565        catch (Exception e) {
1566            throw new MBeanException(e, e.getLocalizedMessage());
1567        }
1568*/

1569    }
1570
1571    public void deletePersistenceManagerFactoryResource( String JavaDoc name, String JavaDoc tgtName )
1572        throws Exception JavaDoc
1573    {
1574        // *** first we remove persistence resource itself as it has references
1575
// *** to jdbc-resources and should be removed first to avoid
1576
// *** Validator's reject
1577
this.deleteResource(PERSISTENCE_MANAGER_FACTORY_RESOURCE, name, tgtName);
1578
1579        
1580        // If creation of pmf resource also resulted in creation of jdbc-resource,
1581
// then that needs to be removed. This will be identified by suffix PM.
1582
Resources resources = (Resources)this.getBaseConfigBean();
1583        if (resources.getJdbcResourceByJndiName(name + PMF_SUFFIX)!=null)
1584        {
1585           this.deleteResource(JDBC_RESOURCE, name + PMF_SUFFIX, tgtName);
1586        }
1587        
1588    }
1589
1590    /**
1591      * Helper method for deleting Jms connection factory
1592      */

1593    public void deleteJmsConenctionFactory( String JavaDoc name, String JavaDoc tgtName )
1594        throws Exception JavaDoc
1595    {
1596        deleteJmsResource(name, tgtName);
1597    }
1598
1599    /**
1600      * Helper method for deleting Jms destination resource
1601      */

1602    public void deleteJmsDestinationResource( String JavaDoc name, String JavaDoc tgtName )
1603        throws Exception JavaDoc
1604    {
1605        deleteJmsResource(name, tgtName);
1606    }
1607
1608    public void deleteJmsResource( String JavaDoc name, String JavaDoc tgtName )
1609        throws Exception JavaDoc
1610    {
1611// try {
1612
Target target = getResourceTarget(tgtName);
1613            ObjectName JavaDoc connResource = null;
1614            try {
1615               connResource = (ObjectName JavaDoc)super.invoke("getConnectorResourceByJndiName", new Object JavaDoc[]{name}, new String JavaDoc[]{"java.lang.String"});
1616            } catch (Exception JavaDoc ee){};
1617
1618            if (connResource == null)
1619            {
1620                // delete any admin objects with this jndi name
1621
super.invoke("deleteAdminObjectResource", new Object JavaDoc[]{name, tgtName}, new String JavaDoc[]{"java.lang.String", "java.lang.String"});
1622            } else {
1623                // Delete the connector resource and connector connection pool
1624
String JavaDoc defPoolName = ConnectorRuntime.getRuntime().getDefaultPoolName(name);
1625                String JavaDoc poolName = (String JavaDoc) getMBeanServer().getAttribute(connResource, "pool_name");
1626                if (poolName != null && poolName.equals(defPoolName))
1627                    {
1628                    deleteResourceRef(name, target, tgtName);
1629                    // Delete both the resource and the poolname
1630
destroyResource(CONNECTOR_RESOURCE, name);
1631
1632                    ObjectName JavaDoc connPool = getObjectNameForResType(CONNECTOR_CONNECTION_POOL, poolName);
1633                    if (connPool != null) {
1634                        destroyResource(CONNECTOR_CONNECTION_POOL,poolName);
1635                    }
1636                }
1637                else
1638                {
1639                    // There is no connector pool with the default poolName.
1640
// However, no need to throw exception as the connector
1641
// resource might still be there. Try to delete the
1642
// connector-resource without touching the ref. as
1643
// ref. might have been deleted while deleting connector-connection-pool
1644
// as the ref. is the same.
1645
ObjectName JavaDoc connResMBean = getObjectNameForResType(CONNECTOR_RESOURCE, name);
1646                    super.invoke("removeConnectorResourceByJndiName",new Object JavaDoc[]{name},new String JavaDoc[] {"java.lang.String"});
1647                }
1648            }
1649/* }
1650        catch (MBeanException me) {
1651            throw me;
1652        }
1653        catch (Exception e) {
1654            throw new MBeanException(e, e.getLocalizedMessage());
1655        }
1656*/

1657    }
1658
1659    public void deleteConnectorResource( String JavaDoc name, String JavaDoc tgtName )
1660        throws Exception JavaDoc
1661    {
1662        this.deleteResource(CONNECTOR_RESOURCE, name, tgtName);
1663    }
1664
1665    public void deleteAdminObjectResource( String JavaDoc name, String JavaDoc tgtName )
1666        throws Exception JavaDoc
1667    {
1668        this.deleteResource(ADMIN_OBJECT_RESOURCE, name, tgtName);
1669    }
1670
1671    public void deleteConnectorConnectionPool( String JavaDoc name, String JavaDoc tgtName )
1672        throws Exception JavaDoc
1673    {
1674        this.deleteConnectorConnectionPool( name, new Boolean JavaDoc(false), tgtName);
1675    }
1676
1677    public void deleteConnectorConnectionPool( String JavaDoc name, Boolean JavaDoc cascade, String JavaDoc tgtName )
1678        throws Exception JavaDoc
1679    {
1680        // Passing the resType as deleteConnectionPool is common method for both
1681
// jdbc-connection-pool and connector-connection-pool deletion
1682
deleteConnectionPool( CONNECTOR_RESOURCE, name, cascade, tgtName);
1683    }
1684
1685    public void deleteJdbcResource( String JavaDoc name, String JavaDoc tgtName )
1686        throws Exception JavaDoc
1687    {
1688        this.deleteResource(JDBC_RESOURCE, name, tgtName);
1689    }
1690
1691    public void deleteResourceAdapterConfig( String JavaDoc name, String JavaDoc tgtName )
1692        throws Exception JavaDoc
1693    {
1694        this.deleteResource(RESOURCE_ADAPTER_CONFIG, name, tgtName);
1695    }
1696
1697    public void deleteMailResource( String JavaDoc name, String JavaDoc tgtName )
1698        throws Exception JavaDoc
1699    {
1700        this.deleteResource(MAIL_RESOURCE, name, tgtName);
1701    }
1702
1703    public void deleteExternalJndiResource( String JavaDoc name, String JavaDoc tgtName )
1704        throws Exception JavaDoc
1705    {
1706        this.deleteResource(EXTERNAL_JNDI_RESOURCE, name, tgtName);
1707    }
1708
1709    private Target getResourceTarget( String JavaDoc tgtName )
1710        throws Exception JavaDoc
1711    {
1712// try
1713
// {
1714
return TargetBuilder.INSTANCE.createTarget(VALID_CREATE_DELETE_TYPES,
1715                tgtName, getConfigContext());
1716/* }
1717        catch (Exception e)
1718        {
1719            e.printStackTrace();
1720            throw new MBeanException(e, e.getLocalizedMessage());
1721        }
1722*/

1723    }
1724
1725    private void deleteResource( String JavaDoc resType, String JavaDoc name, String JavaDoc tgtName )
1726        throws Exception JavaDoc
1727    {
1728        String JavaDoc operation = null;
1729        String JavaDoc suffix = null;
1730
1731        if (resType.equals(RESOURCE_ADAPTER_CONFIG))
1732           suffix = "ByResourceAdapterName";
1733        else if (resType.equals(JDBC_CONNECTION_POOL) || resType.equals(CONNECTOR_CONNECTION_POOL))
1734           suffix = "ByName";
1735        else suffix = "ByJndiName";
1736
1737        operation = "remove" + ConfigMBeanHelper.convertTagName(resType) + suffix;
1738
1739        if (!(RESOURCE_ADAPTER_CONFIG.equals(resType) ||
1740              JDBC_CONNECTION_POOL.equals(resType) ||
1741              CONNECTOR_CONNECTION_POOL.equals(resType))) {
1742            /*
1743                delete the resource-refs before calling the delete for this
1744                resource.
1745             */

1746            Target target = getResourceTarget(tgtName);
1747            deleteResourceRef(name, target, tgtName);
1748        }
1749
1750        // Invoke removeXXXByXXXName() for the appropriate MBean
1751
super.invoke(operation,new Object JavaDoc[]{name},new String JavaDoc[] {"java.lang.String"});
1752    }
1753
1754    /**
1755     * Used by the deployment backend to destroy resources defined in
1756     * sun-resources.xml
1757     * @param resources Resources to be destroyed
1758     * @throws Exception
1759     */

1760    public void deleteResource(List JavaDoc<Resource> res) throws Exception JavaDoc{
1761        //Delete Resource and ResourceRefs in the reverse order.
1762
int size = res.size();
1763        for (int i = (size -1); i >= 0 ; i--) {
1764            Resource resource = res.get(i);
1765            deleteAResource(resource);
1766        }
1767    }
1768    
1769    private void deleteAResource(Resource resource) throws Exception JavaDoc{
1770        //System.out.println("ResourcesMBean deleteAResource " + resource.getType());
1771
this.destroyResource(resource.getType(),
1772                getResourceName(resource.getType(), resource.getAttributes()));
1773    }
1774
1775
1776    private boolean destroyResource(String JavaDoc resType, String JavaDoc name)
1777        throws Exception JavaDoc
1778    {
1779        String JavaDoc operation = null;
1780        String JavaDoc suffix = null;
1781        boolean isDeleted = false;
1782
1783        if (resType.equals(RESOURCE_ADAPTER_CONFIG)){
1784           suffix = "ByResourceAdapterName";
1785        }else if (resType.equals(JDBC_CONNECTION_POOL) || resType.equals(CONNECTOR_CONNECTION_POOL)){
1786           suffix = "ByName";
1787        }else{
1788            suffix = "ByJndiName";
1789        }
1790
1791        operation = "remove" + ConfigMBeanHelper.convertTagName(resType) + suffix;
1792        try {
1793            super.invoke(operation, new Object JavaDoc[]{name}, new String JavaDoc[] {"java.lang.String"});
1794            isDeleted = true;
1795        }
1796        catch (javax.management.ReflectionException JavaDoc re) {}
1797
1798        return isDeleted;
1799    }
1800
1801
1802    private ObjectName JavaDoc getObjectNameForResType(String JavaDoc resType, String JavaDoc name)
1803        throws Exception JavaDoc
1804    {
1805        return m_registry.getMbeanObjectName(resType, new String JavaDoc[]{getDomainName(), name});
1806    }
1807   
1808    private void deleteResourceRef(String JavaDoc resRef, Target target, String JavaDoc tgtName)
1809        throws Exception JavaDoc
1810    {
1811        //System.out.println("deleteResourceRef " + resRef + " target " + target + " tgtName " + tgtName );
1812
// try {
1813

1814            //This call is a sanity check to make sure that the resource exists.
1815
final String JavaDoc resType = getResourceReferenceHelper().getResourceType(resRef);
1816            
1817            // If target is server or cluster, resource-ref should also be
1818
// deleted from server or cluster element.
1819
if (target.getType() == TargetType.SERVER ||
1820                target.getType() == TargetType.DAS) {
1821
1822                //Delete the resource reference only if the resource is referenced
1823
//by the target server only
1824
if (!ServerHelper.serverReferencesResource(getConfigContext(),
1825                    tgtName, resRef)) {
1826                    throw new ConfigException(localStrings.getString("serverResourceRefDoesNotExist",
1827                        tgtName, resRef));
1828                } else if (ResourceHelper.isResourceReferencedByServerOnly(getConfigContext(),
1829                    resRef, tgtName)) {
1830                    getResourceReferenceHelper().deleteResourceReference(tgtName, resRef);
1831                } else {
1832                    throw new ConfigException(localStrings.getString("resourceHasMultipleRefs",
1833                        tgtName, resRef, ResourceHelper.getResourceReferenceesAsString(
1834                            getConfigContext(), resRef)));
1835                }
1836            } else if (target.getType() == TargetType.CLUSTER) {
1837                //Delete the resource reference only if the resource is referenced
1838
//by the target cluster only
1839
if (!ClusterHelper.clusterReferencesResource(getConfigContext(),
1840                    tgtName, resRef)) {
1841                    throw new ConfigException(localStrings.getString("clusterResourceRefDoesNotExist",
1842                        tgtName, resRef));
1843                 } else if (ResourceHelper.isResourceReferencedByClusterOnly(getConfigContext(),
1844                    resRef, tgtName)) {
1845                    getResourceReferenceHelper().deleteResourceReference(tgtName, resRef);
1846                 } else {
1847                    throw new ConfigException(localStrings.getString("resourceHasMultipleRefs",
1848                        tgtName, resRef, ResourceHelper.getResourceReferenceesAsString(
1849                            getConfigContext(), resRef)));
1850                 }
1851            }
1852            //As a sanity check ensure that the resource has no references; otherwise
1853
//it cannot be deleted from the domain
1854
if (ResourceHelper.isResourceReferenced(getConfigContext(), resRef)) {
1855                throw new ConfigException(localStrings.getString("resourceIsReferenced",
1856                    resRef, ResourceHelper.getResourceReferenceesAsString(
1857                        getConfigContext(), resRef)));
1858            }
1859/* }
1860        catch (javax.management.MalformedObjectNameException mone) {}
1861        catch (javax.management.InstanceNotFoundException infe) {}
1862        catch (javax.management.ReflectionException re) {}
1863*/

1864    }
1865
1866     /**
1867     * Creating resources from sun-resources.xml file. This method is used by
1868     * the admin framework when the add-resources command is used to create
1869     * resources
1870     */

1871    public ArrayList JavaDoc createResource(String JavaDoc resourceXMLFile, String JavaDoc tgtName)
1872                                                            throws Exception JavaDoc {
1873        //@todo: how do we handle failures?
1874
boolean retVal = false;
1875        ArrayList JavaDoc results = new ArrayList JavaDoc();
1876        com.sun.enterprise.resource.ResourcesXMLParser resourcesParser =
1877            new com.sun.enterprise.resource.ResourcesXMLParser(resourceXMLFile);
1878        List JavaDoc<Resource> resources = resourcesParser.getResourcesList();
1879        //First add all non connector resources.
1880
;
1881        Iterator JavaDoc<Resource> nonConnectorResources = ResourcesXMLParser.getNonConnectorResourcesList(resources,false).iterator();
1882        while (nonConnectorResources.hasNext()) {
1883            Resource resource = (Resource) nonConnectorResources.next();
1884            String JavaDoc s = "";
1885            try {
1886                s = createAResource(resource, tgtName, true);
1887            } catch (Exception JavaDoc e) {
1888                s = e.getMessage();
1889            }
1890            results.add(s);
1891        }
1892
1893        //Now add all connector resources
1894
Iterator JavaDoc connectorResources = ResourcesXMLParser.getConnectorResourcesList(resources, false).iterator();
1895        while (connectorResources.hasNext()) {
1896            Resource resource = (Resource) connectorResources.next();
1897            String JavaDoc s = "";
1898            try {
1899                s = createAResource(resource, tgtName, true);
1900            } catch (Exception JavaDoc e) {
1901                s = e.getMessage();
1902            }
1903            results.add(s);
1904        }
1905
1906        return results;
1907    }
1908
1909
1910     /**
1911     * Creating resources from sun-resources.xml file. This API
1912     * is used by the deployment backend to create Resources
1913     * @param isEnabled the enabled flag as passed in via asadmin
1914     */

1915    public void createResource(List JavaDoc<Resource> res,
1916            Boolean JavaDoc isEnabled) throws Exception JavaDoc {
1917        //@todo: handle isEnabled. This should override the enabled flag specified
1918
//in the individual Resources.
1919
Iterator JavaDoc<Resource> resources = res.iterator();
1920        while (resources.hasNext()) {
1921            Resource resource = (Resource) resources.next();
1922            createAResource(resource, null, false);
1923        }
1924    }
1925    
1926    public void createResourceAndResourceReference(
1927                    List JavaDoc<Resource> resources, List JavaDoc<String JavaDoc> targetNameList,
1928                    Boolean JavaDoc enabled) throws Exception JavaDoc {
1929        Iterator JavaDoc<Resource> resourceList = resources.iterator();
1930        while (resourceList.hasNext()) {
1931            Resource resource = (Resource) resourceList.next();
1932            for (String JavaDoc target : targetNameList) {
1933                createAResource(resource, target, false);
1934                createAResourceReference(resource, target, enabled);
1935            }
1936            
1937        }
1938    }
1939
1940    public void deleteResourceAndResourceReference (
1941                    List JavaDoc<Resource> resources,
1942                    List JavaDoc<String JavaDoc> targetNameList) throws Exception JavaDoc{
1943        //Delete Resource and ResourceRefs in the reverse order.
1944
int size = resources.size();
1945        for (int i = (size -1); i >= 0 ; i--) {
1946            Resource resource = (Resource)resources.get(i);
1947            //System.out.println(" *********** r&r " + resource.getType() + " ********");
1948
deleteAResourceRef(resource, targetNameList);
1949            deleteAResource(resource);
1950        }
1951    }
1952    
1953    /**
1954     * Adds a resource
1955     * @param resource Resource to be added
1956     * @param tgtName Target to which the resource needs to be added
1957     * @return a string representing the status of the resource-addition
1958     */

1959    private String JavaDoc createAResource(Resource resource, String JavaDoc tgtName, boolean createResourceRefs ) throws Exception JavaDoc {
1960        //System.out.println("ResourcesMBean : createAResource " + resource.getType());
1961
String JavaDoc resourceType = resource.getType();
1962                //if the resource element is security-map then invoke connector-
1963
//connection-pool MBean which has all the operations for
1964
// security-map and its sub-elemnents....
1965
// This is a special case since security-map element is a part
1966
//of connector-connection-pool and not a resource by itself.
1967

1968                if(resourceType.equals(ServerTags.SECURITY_MAP)){
1969                    AttributeList JavaDoc mapAttributes = resource.getAttributes();
1970                    // get the pool name.
1971
String JavaDoc poolName = null;
1972                    String JavaDoc username = null ;
1973                    String JavaDoc password = null;
1974                    if(mapAttributes != null){
1975                        int s = mapAttributes.size();
1976                        for(int i=0;i<s;i++){
1977                            Attribute JavaDoc attribute =(Attribute JavaDoc)mapAttributes.get(i);
1978                            String JavaDoc n= attribute.getName();
1979                            if((attribute.getName()).equalsIgnoreCase("pool-name"))
1980                                poolName = (String JavaDoc)attribute.getValue();
1981                            if((attribute.getName()).equalsIgnoreCase("user-name"))
1982                               username = (String JavaDoc)attribute.getValue();
1983                            if((attribute.getName()).equalsIgnoreCase("password"))
1984                                password = (String JavaDoc)attribute.getValue();
1985                            
1986                        }
1987                    }
1988                    mapAttributes.add(new Attribute JavaDoc(POOL_NAME,poolName));
1989                    ObjectName JavaDoc poolObj = m_registry.getMbeanObjectName(POOL_TYPE,
1990                           new String JavaDoc[]{getDomainName(),poolName,CONFIG});
1991
1992                    try{
1993                        ObjectName JavaDoc map =(ObjectName JavaDoc)getMBeanServer().invoke(poolObj,
1994                            CREATE_SECURITY_MAP, new Object JavaDoc[] {mapAttributes,username,
1995                            password, tgtName},
1996                            new String JavaDoc[] {AttributeList JavaDoc.class.getName(),"java.lang.String",
1997                            "java.lang.String","java.lang.String"});
1998                String JavaDoc s = localStrings.getString("admin.mbeans.rmb.res_type_added", resourceType);
1999                sLogger.log(Level.INFO, s);
2000                return s;
2001                    }catch(Exception JavaDoc e){
2002                        e.printStackTrace();
2003                String JavaDoc s = localStrings.getString("admin.mbeans.rmb.res_type_not_added", resourceType, e.getMessage());
2004                sLogger.log(Level.INFO, s);
2005                throw new Exception JavaDoc(s, e);
2006                    }
2007                }
2008                else{
2009                    AttributeList JavaDoc attr = resource.getAttributes();
2010                    String JavaDoc desc = resource.getDescription();
2011                    if (desc != null)
2012                        attr.add(new Attribute JavaDoc("description", desc));
2013
2014                    Properties JavaDoc props = resource.getProperties();
2015                    try{
2016                        ObjectName JavaDoc objName = createResource(resource.getType(),
2017                                                attr, props, tgtName, createResourceRefs);
2018                        //results.add("Added Resource Type :"+resourceType);
2019
String JavaDoc s = localStrings.getString("admin.mbeans.rmb.res_type_added", resourceType);
2020                sLogger.log(Level.INFO, s);
2021                return s;
2022                    }catch(Exception JavaDoc e){
2023                e.printStackTrace();
2024                         //results.add("Could not add Resource Type "
2025
//+":"+resourceType +" because :"+e.getMessage());
2026
String JavaDoc s = localStrings.getString("admin.mbeans.rmb.res_type_not_added", resourceType, e.getMessage());
2027                sLogger.log(Level.INFO, s);
2028                throw new Exception JavaDoc (s, e);
2029                    }
2030                }
2031
2032    }
2033
2034    /**
2035     * Get list of properties and default values for connection with
2036     * defined data source.
2037     *
2038     * returns "null" if no info or error
2039    */

2040    public Map JavaDoc getConnectionDefinitionPropertiesAndDefaults(String JavaDoc dataSource)
2041    {
2042       try {
2043         return new HashMap JavaDoc( ConnectionDefinitionUtils.
2044             getConnectionDefinitionPropertiesAndDefaults(dataSource.trim()));
2045       } catch(Throwable JavaDoc t) {
2046           return null;
2047       }
2048    }
2049
2050    /**
2051     * Get list of properties for resource adapter defined by location
2052     *
2053     * returns "null" if no info or error
2054    */

2055    public Map JavaDoc getResourceAdapterBeanProperties(String JavaDoc location)
2056    {
2057       try {
2058            return new HashMap JavaDoc(ConnectorRuntime.getRuntime().
2059               getResourceAdapterBeanProperties(location));
2060       } catch(Throwable JavaDoc t) {
2061           return null;
2062       }
2063    }
2064   
2065    /**
2066     * Get the list of connection definition names supported by a specific
2067     * resource adapter deployed on the server.
2068     */

2069    public String JavaDoc[] getConnectionDefinitionNames(String JavaDoc rarName)
2070        throws Exception JavaDoc
2071    {
2072// try {
2073
return ConnectorRuntime.getRuntime().
2074                getConnectionDefinitionNames(rarName);
2075/* } catch (Exception e) {
2076            throw new MBeanException(e, e.getMessage());
2077        }
2078 */

2079    }
2080
2081    /**
2082     * Get the resource-adapter-config properties supported by a specific
2083     * resource adapter deployed on the server.
2084     */

2085    public Properties JavaDoc getResourceAdapterConfigProps(AttributeList JavaDoc attrList)
2086        throws Exception JavaDoc
2087    {
2088        String JavaDoc rarName = null;
2089
2090// try {
2091
if (attrList != null)
2092            {
2093                int s = attrList.size();
2094                for(int i=0; i<s; i++)
2095                {
2096                    Attribute JavaDoc attribute =(Attribute JavaDoc)attrList.get(i);
2097                    String JavaDoc n= attribute.getName();
2098                    
2099                    if(isAttrNameMatch(attribute, "resource-adapter-name"))
2100                        rarName = (String JavaDoc)attribute.getValue();
2101                }
2102            } else
2103                throw new Exception JavaDoc (localStrings.getString("admin.mbeans.rmb.null_attrib_list"));
2104            
2105            return ConnectorRuntime.getRuntime().
2106                getResourceAdapterConfigProps(rarName);
2107/* } catch (Exception e) {
2108            throw new MBeanException(e, e.getMessage());
2109        }
2110 */

2111    }
2112
2113    /**
2114     * Get the Managed Connection Factory Config Properties supported by a
2115     * specific resource adapter for the given connection definition name,
2116     * deployed on the server.
2117     */

2118    public Properties JavaDoc getMCFConfigProps(AttributeList JavaDoc attrList)
2119        throws Exception JavaDoc
2120    {
2121        String JavaDoc rarName = null;
2122        String JavaDoc connDefName = null;
2123
2124// try {
2125
if (attrList != null)
2126            {
2127                int s = attrList.size();
2128                for(int i=0; i<s; i++){
2129                    Attribute JavaDoc attribute =(Attribute JavaDoc)attrList.get(i);
2130                    String JavaDoc n= attribute.getName();
2131                    
2132                    if(isAttrNameMatch(attribute, "resource-adapter-name"))
2133                        rarName = (String JavaDoc)attribute.getValue();
2134                    
2135                    if(isAttrNameMatch(attribute, "connection-definition-name"))
2136                        connDefName = (String JavaDoc)attribute.getValue();
2137                }
2138            } else
2139                throw new Exception JavaDoc (localStrings.getString("admin.mbeans.rmb.null_attrib_list_mcf"));
2140
2141            return ConnectorRuntime.getRuntime().
2142                getMCFConfigProps(rarName, connDefName);
2143/* } catch (Exception e) {
2144            throw new MBeanException(e, e.getMessage());
2145        }
2146 */

2147    }
2148
2149    /**
2150     * Get the list of Admin Object Config Properties supported by a specific
2151     * resource adapter for the given admin object interface,
2152     * deployed on the server.
2153     */

2154    public Properties JavaDoc getAdminObjectConfigProps(AttributeList JavaDoc attrList)
2155        throws Exception JavaDoc
2156    {
2157        String JavaDoc rarName = null;
2158        String JavaDoc adminObjIntf = null;
2159
2160// try {
2161
if (attrList != null)
2162            {
2163                int s = attrList.size();
2164                for(int i=0; i<s; i++){
2165                    Attribute JavaDoc attribute =(Attribute JavaDoc)attrList.get(i);
2166                    String JavaDoc n= attribute.getName();
2167                    
2168                    if(isAttrNameMatch(attribute, "resource-adapter-name"))
2169                        rarName = (String JavaDoc)attribute.getValue();
2170                    
2171                    if(isAttrNameMatch(attribute, "admin-object-interface"))
2172                        adminObjIntf = (String JavaDoc)attribute.getValue();
2173                }
2174            } else
2175                throw new Exception JavaDoc (localStrings.getString("admin.mbeans.rmb.null_attrib_list_ao"));
2176
2177            return ConnectorRuntime.getRuntime().
2178                getAdminObjectConfigProps(rarName, adminObjIntf);
2179/* } catch (Exception e) {
2180            throw new MBeanException(e, e.getMessage());
2181        }
2182 */

2183    }
2184
2185    /**
2186     * Get the list of Admin Object Interface Names supported by a specific
2187     * resource adapter deployed on the server.
2188     */

2189    public String JavaDoc[] getAdminObjectInterfaceNames(String JavaDoc rarName)
2190        throws Exception JavaDoc
2191    {
2192        if (rarName == null)
2193            //throw new Exception ("Could not get Admin Object Interface Names. Resource Adapter Name is null");
2194
throw new Exception JavaDoc (localStrings.getString("admin.mbeans.rmb.null_raname_ao"));
2195
2196        return ConnectorRuntime.getRuntime().getAdminObjectInterfaceNames(rarName);
2197    }
2198
2199    /*
2200     * Temporary method for PE. This method should ideally be in Runtime MBean.
2201     */

2202    public Boolean JavaDoc pingConnectionPool(String JavaDoc poolName, String JavaDoc tgtName) throws Exception JavaDoc
2203    {
2204        boolean retVal = false;
2205        final Target target;
2206
2207// try
2208
{
2209            //FIXTHIS: Not sure why this can only be a server instance. We should be
2210
//able to reference a server, domain, or cluster here.
2211
//Ramakanth: Sure. Why can't they be?
2212
final TargetType[] validTargets = new TargetType[]
2213                {TargetType.CLUSTER, TargetType.DOMAIN,
2214                 TargetType.SERVER, TargetType.DAS};
2215
2216            target = TargetBuilder.INSTANCE.createTarget(validTargets,
2217                tgtName, getConfigContext());
2218            retVal = ConnectorRuntime.getRuntime().testConnectionPool(poolName);
2219        }
2220/* catch (MBeanException me) {
2221            throw me;
2222        }
2223        catch (Exception e) {
2224            e.printStackTrace();
2225            throw new MBeanException(e, e.getLocalizedMessage());
2226        }
2227*/

2228        return new Boolean JavaDoc(retVal);
2229    }
2230
2231    protected MBeanServer JavaDoc getMBeanServer()
2232    {
2233        return com.sun.enterprise.admin.common.MBeanServerFactory.getMBeanServer();
2234    }
2235
2236    // JMS Handling Starts
2237
/**
2238         Ping the JMS service.
2239
2240         @return Status of JMS service
2241    */

2242    public JMSStatus JMSPing() throws JMSAdminException
2243    {
2244        try {
2245            JMSAdmin jmsAdmin = getJMSAdmin();
2246            jmsAdmin.pingProvider();
2247        } catch (Exception JavaDoc e) {
2248            sLogger.throwing(getClass().getName(), "JMSPing", e);
2249            handleException(e);
2250        }
2251
2252        JMSStatus js = new JMSStatus();
2253        return (js);
2254
2255    }
2256
2257    /**
2258        Ping the JMS service.
2259
2260        @return Status of JMS service
2261    */

2262    public JMSStatus JMSPing(String JavaDoc username, String JavaDoc password, int port)
2263                        throws JMSAdminException
2264    {
2265        try {
2266            JMSAdmin jmsAdmin = getJMSAdmin();
2267            jmsAdmin.pingProvider(username, password, port);
2268        } catch (Exception JavaDoc e) {
2269            sLogger.throwing(getClass().getName(), "JMSPing", e);
2270            handleException(e);
2271        }
2272
2273        JMSStatus js = new JMSStatus();
2274        return (js);
2275    }
2276
2277    /**
2278    fix for bug# 6157447
2279        Ping the JMS service.
2280
2281    @param target server, cluster, config, etc.
2282        @return String status of jms ping RUNNING or exception
2283    */

2284    public String JavaDoc JMSPing(String JavaDoc targetName)
2285                        throws JMSAdminException
2286    {
2287        try {
2288            Target target = getResourceTarget(targetName);
2289            // check and use JMX
2290
if (JMSDestination.useJMX(target)) {
2291                JMSDestination jmsd = new JMSDestination();
2292                return(jmsd.JMSPing(target.getName()));
2293            } else {
2294                JMSAdmin jmsAdmin = getJMSAdmin(targetName);
2295                jmsAdmin.pingProvider();
2296            }
2297        } catch (Exception JavaDoc e) {
2298            sLogger.throwing(getClass().getName(), "JMSPing", e);
2299            handleException(e);
2300        }
2301
2302        return JMSAdminConstants.JMS_HOST_RUNNING;
2303    }
2304
2305
2306    /**
2307         Create a JMS Destination.
2308
2309         @param destName Destination name.
2310         @param destType Type of destination to create. See
2311                                JMSAdminConstants for details.
2312         @param destProps Properties of destination to create.
2313    */

2314    public void createJMSDestination(String JavaDoc destName,
2315                                     String JavaDoc destType,
2316                                     Properties JavaDoc destProps,
2317                                     String JavaDoc tgtName)
2318                throws JMSAdminException
2319    {
2320        sLogger.entering(getClass().getName(), "createJMSDestination",
2321        new Object JavaDoc[] {destName, destType, destProps, tgtName});
2322
2323        validateJMSDestName(destName);
2324        validateJMSDestType(destType);
2325
2326        int newDestType = JMSConstants.QUEUE;
2327        JMSAdmin jmsAdmin = null;
2328        boolean connected = false;
2329
2330
2331        try {
2332            if (isClustered(tgtName)
2333                && destType.equals(JMSAdminConstants.JMS_DEST_TYPE_QUEUE)) {
2334                if (destProps == null) {
2335                    destProps = new Properties JavaDoc();
2336                }
2337                String JavaDoc maxConsumersProperty = IASJmsUtil.getMaxActiveConsumersProperty();
2338                String JavaDoc maxConsumersAttribute = IASJmsUtil.getMaxActiveConsumersAttribute();
2339                String JavaDoc maxConsumersValue = IASJmsUtil.getDefaultMaxActiveConsumers();
2340                if (!destProps.containsKey(maxConsumersProperty) &&
2341                    !destProps.containsKey(maxConsumersAttribute) ) {
2342                    destProps.put(maxConsumersAttribute, maxConsumersValue);
2343                }
2344            }
2345
2346            // check and use JMX
2347
Target target = getResourceTarget(tgtName);
2348            if (JMSDestination.useJMX(target)) {
2349                JMSDestination jmsd = new JMSDestination();
2350                jmsd.createJMSDestination(destName, destType, destProps, tgtName);
2351                return;
2352            } else {
2353                jmsAdmin = getJMSAdmin(tgtName);
2354                jmsAdmin.connectToProvider();
2355                connected = true;
2356    
2357                if (destType.equals(JMSAdminConstants.JMS_DEST_TYPE_TOPIC)) {
2358                    newDestType = JMSConstants.TOPIC;
2359                } else if (destType.equals(JMSAdminConstants.JMS_DEST_TYPE_QUEUE)) {
2360                    newDestType = JMSConstants.QUEUE;
2361                }
2362    
2363                jmsAdmin.createProviderDestination(destName, newDestType, destProps);
2364            }
2365        } catch (Exception JavaDoc e) {
2366            handleException(e);
2367        } finally {
2368            if (connected) {
2369                try {
2370                    jmsAdmin.disconnectFromProvider();
2371                } catch (Exception JavaDoc ex) {
2372                    handleException(ex);
2373                }
2374            }
2375        }
2376    }
2377
2378    /**
2379         Delete a JMS Destination.
2380
2381         @param destName Destination name.
2382         @param destType Type of destination to delete. See
2383                                JMSAdminConstants for details.
2384    */

2385    public void deleteJMSDestination(String JavaDoc destName, String JavaDoc destType, String JavaDoc tgtName)
2386                throws JMSAdminException
2387    {
2388        sLogger.entering(getClass().getName(), "deleteJMSDestination",
2389        new Object JavaDoc[] {destName, destType});
2390
2391        validateJMSDestName(destName);
2392        validateJMSDestType(destType);
2393
2394        int newDestType = JMSConstants.QUEUE;
2395        JMSAdmin jmsAdmin = null;
2396        boolean connected = false;
2397
2398        try {
2399            // check and use JMX
2400
Target target = getResourceTarget(tgtName);
2401            if (JMSDestination.useJMX(target)) {
2402                JMSDestination jmsd = new JMSDestination();
2403                jmsd.deleteJMSDestination(destName, destType, tgtName);
2404                return;
2405            } else {
2406                jmsAdmin = getJMSAdmin(tgtName);
2407                jmsAdmin.connectToProvider();
2408                connected = true;
2409    
2410                if (destType.equals(JMSAdminConstants.JMS_DEST_TYPE_TOPIC)) {
2411                        newDestType = JMSConstants.TOPIC;
2412                } else if (destType.equals(JMSAdminConstants.JMS_DEST_TYPE_QUEUE)) {
2413                        newDestType = JMSConstants.QUEUE;
2414                }
2415    
2416                jmsAdmin.deleteProviderDestination(destName, newDestType);
2417            }
2418        } catch (Exception JavaDoc e) {
2419            sLogger.throwing(getClass().getName(), "deleteJMSDestination", e);
2420            handleException(e);
2421        } finally {
2422            if (connected) {
2423                try {
2424                    jmsAdmin.disconnectFromProvider();
2425                } catch (Exception JavaDoc ex) {
2426                    handleException(ex);
2427                }
2428            }
2429        }
2430    }
2431
2432
2433    /**
2434      * Purge a JMS Destination.
2435      * @param destName Destination name.
2436      * @param destType Type of destination to purge.
2437      */

2438    public void flushJMSDestination(String JavaDoc destName, String JavaDoc destType, String JavaDoc tgtName)
2439        throws JMSAdminException {
2440        // check and use JMX
2441
try {
2442            Target target = getResourceTarget(tgtName);
2443            if (JMSDestination.useJMX(target)) {
2444                JMSDestination jmsd = new JMSDestination();
2445                jmsd.purgeJMSDestination(destName, destType, tgtName);
2446            } else {
2447                sLogger.log(Level.WARNING, "Flush JMS destination not supported in the JMS SPI");
2448            }
2449        } catch (Exception JavaDoc e) {
2450            sLogger.throwing(getClass().getName(), "flushJMSDestination", e);
2451            handleException(e);
2452        }
2453    }
2454
2455    /**
2456      * List JMS Destinations.
2457      *
2458          * @param destType Type of destination to list. See
2459          * JMSAdminConstants for details.
2460          * @return An array of JMSDestinationInfo objects.
2461          * Each JMSDestinationInfo object contains
2462          * information such as destination name,
2463      * * * * type and other attributes.
2464      */

2465    public JMSDestinationInfo[] listJMSDestinations(String JavaDoc destType, String JavaDoc tgtName)
2466                throws JMSAdminException
2467    {
2468        JMSDestinationInfo destInfoArray[] = null;
2469        JMSAdmin jmsAdmin = null;
2470        boolean connected = false;
2471
2472        sLogger.entering(getClass().getName(), "listJMSDestinations", destType);
2473        
2474        try {
2475            // check and use JMX
2476
Target target = getResourceTarget(tgtName);
2477            if (JMSDestination.useJMX(target)) {
2478                JMSDestination jmsd = new JMSDestination();
2479                return (jmsd.listJMSDestinations(tgtName, destType));
2480            } else {
2481                String JavaDoc s[][] = {null, null};
2482                jmsAdmin = getJMSAdmin(tgtName);
2483                jmsAdmin.connectToProvider();
2484                connected = true;
2485    
2486                s = jmsAdmin.getProviderDestinations();
2487    
2488                if (destType == null) {
2489                    destInfoArray = listAllDestinations(s);
2490                } else if (destType.equals(JMSAdminConstants.JMS_DEST_TYPE_TOPIC) ||
2491                   destType.equals(JMSAdminConstants.JMS_DEST_TYPE_QUEUE)) {
2492                   destInfoArray = listDestinationsByType(destType, s);
2493                } else {
2494                   destInfoArray = listAllDestinations(s);
2495                }
2496                return (destInfoArray);
2497            }
2498        } catch (Exception JavaDoc e) {
2499            sLogger.throwing(getClass().getName(), "listJMSDestinations", e);
2500            handleException(e);
2501        } finally {
2502            if (connected) {
2503                try {
2504                    jmsAdmin.disconnectFromProvider();
2505                } catch (Exception JavaDoc ex) {
2506                    handleException(ex);
2507                }
2508            }
2509        }
2510        return null;
2511    }
2512
2513
2514    private void validateJMSDestName(String JavaDoc destName) {
2515        if(destName==null || destName.length() <= 0)
2516            throw new IllegalArgumentException JavaDoc(localStrings.getString("admin.mbeans.rmb.invalid_jms_destname",destName));
2517    }
2518
2519    private void validateJMSDestType(String JavaDoc destType) {
2520        if(destType==null || destType.length() <= 0)
2521            throw new IllegalArgumentException JavaDoc(localStrings.getString("admin.mbeans.rmb.invalid_jms_desttype",destType));
2522        if(!destType.equals(JMSAdminConstants.JMS_DEST_TYPE_QUEUE) &&
2523            !destType.equals(JMSAdminConstants.JMS_DEST_TYPE_TOPIC))
2524            throw new IllegalArgumentException JavaDoc(localStrings.getString("admin.mbeans.rmb.invalid_jms_desttype",destType));
2525    }
2526
2527    /** calls {@link createJMSDestination } after getting the values from attribute list
2528     * @param attrList attributeList with destName and destType attributes
2529     * @param props JMS properties
2530     * @param target ignored
2531     * @return void
2532     * @throws JMSAdminException thrown from createJMSDestination call
2533     * @throws MBeanException thrown from createJMSDestination call
2534     */

2535    public void createPhysicalDestination(AttributeList JavaDoc attrList ,Properties JavaDoc props,
2536        String JavaDoc target)throws JMSAdminException,MBeanException JavaDoc
2537    {
2538        String JavaDoc destType = null;
2539        String JavaDoc destName = null;
2540        if(attrList == null)
2541            throw new IllegalArgumentException JavaDoc();
2542        
2543        int size = attrList.size();
2544        for(int i=0;i<size;i++){
2545                Attribute JavaDoc attribute =(Attribute JavaDoc)attrList.get(i);
2546                if((attribute.getName().equalsIgnoreCase(DEST_TYPE)))
2547                    destType = (String JavaDoc)attribute.getValue();
2548                if((attribute.getName().equalsIgnoreCase(DEST_NAME)))
2549                    destName = (String JavaDoc)attribute.getValue();
2550        }
2551        //FIXME: Should target be passed in here???
2552
createJMSDestination(destName,destType,props, target);
2553    }
2554    
2555    /** calls {@link deleteJMSDestination }
2556     * @param destName destination name
2557     * @param destType destination type "queue" or "topic"
2558     * @param target ignored
2559     * @return void
2560     * @throws JMSAdminException from deleteJMSDestination
2561     * @throws MBeanException from deleteJMSDestination
2562     */

2563    public void deletePhysicalDestination(String JavaDoc destName, String JavaDoc destType,
2564        String JavaDoc target)throws JMSAdminException,MBeanException JavaDoc
2565    {
2566        deleteJMSDestination(destName,destType, target);
2567    }
2568    
2569    
2570    /** returns ObjectName array of all jms destinations
2571     * @param target ignored
2572     * @return ObjectName array of all jms destinations with attributes destName and destType
2573     * @throws JMSAdminException from the list JMSDestination call
2574     * @throws MBeanException from the listJMSDestination call
2575     */

2576    public ObjectName JavaDoc[] listPhysicalDestinations(String JavaDoc target)
2577        throws JMSAdminException,MBeanException JavaDoc
2578    {
2579        ObjectName JavaDoc[] objectNames = null;
2580        
2581        JMSDestinationInfo[] destInfos = listJMSDestinations(null, target);
2582        int infoLength=0;
2583        if (destInfos != null && destInfos.length >0 )
2584            infoLength = destInfos.length;
2585
2586        // Instead of null, convey the message that there are no jms destinations.
2587
if (infoLength ==0 )
2588            return null;
2589        
2590        objectNames = new ObjectName JavaDoc[infoLength];
2591        for(int i=0;i<infoLength;i++) {
2592            String JavaDoc destName = destInfos[i].getDestinationName();
2593            String JavaDoc destType = destInfos[i].getDestinationType();
2594            try {
2595                ObjectName JavaDoc objectName =
2596                new ObjectName JavaDoc(getDomainName()+":"+DEST_NAME+"="+destName+","+DEST_TYPE+"="+destType);
2597                objectNames[i]=objectName;
2598            }catch(javax.management.MalformedObjectNameException JavaDoc e){
2599                sLogger.warning(e.toString());
2600            }
2601        }
2602        
2603        return objectNames;
2604    }
2605    
2606// <NEW CODE> Ram Jeyaraman
2607

2608    /**
2609     * Retrieve the list of message listener types supported by a specific
2610     * resource adapter deployed on the server.
2611     */

2612    public String JavaDoc[] getMessageListenerTypes(String JavaDoc raName)
2613            throws Exception JavaDoc {
2614// try {
2615
return ConnectorRuntime.getRuntime().
2616                getMessageListenerTypes(raName);
2617/* } catch (Exception e) {
2618            throw new MBeanException(e, e.getMessage());
2619        }
2620 */

2621    }
2622
2623    /**
2624     * Retrieve the list of activation configuration property names
2625     * for a specific message listener type from the resource adapter deployed
2626     * on the server.
2627     */

2628    public Properties JavaDoc getActivationConfProps(String JavaDoc raName,
2629                                           String JavaDoc msgLsnrType)
2630            throws Exception JavaDoc {
2631// try {
2632
return ConnectorRuntime.getRuntime().
2633                getMessageListenerConfigProps(raName, msgLsnrType);
2634/* } catch (Exception e) {
2635            throw new MBeanException(e, e.getMessage());
2636        }
2637 */

2638    }
2639
2640    /**
2641     * Retrieve the list of activation configuration property types
2642     * for a specific message listener type from the resource adapter deployed
2643     * on the server.
2644     *
2645     * Note, the types need to correspond to the names in the
2646     * same retrieval order.
2647     */

2648    public Properties JavaDoc getActivationConfPropTypes(String JavaDoc raName,
2649                                           String JavaDoc msgLsnrType)
2650            throws Exception JavaDoc {
2651// try {
2652
return ConnectorRuntime.getRuntime().
2653                getMessageListenerConfigPropTypes(raName, msgLsnrType);
2654/* } catch (Exception e) {
2655            throw new MBeanException(e, e.getMessage());
2656        }
2657 */

2658    }
2659
2660    /**
2661     * Retrieve the list of required activation configuration property names
2662     * for a specific message listener type from the resource adapter deployed
2663     * on the server.
2664     */

2665    /* yet to be implemented
2666    public Properties getRequiredActivationConfProps(String raName,
2667                                                   String msgLsnrType)
2668            throws MBeanException {
2669        try {
2670            return ConnectorRuntime.getRuntime().
2671                getRequiredActivationConfProps(raName, msgLsnrType);
2672            throw new MBeanException("Function Not Supported");
2673        } catch (Exception e) {
2674            throw new MBeanException(e, e.getMessage());
2675        }
2676    }
2677    */

2678
2679// <NEW CODE END> Ram Jeyaraman
2680

2681    /**
2682     * Synchronized to serialize access to _jmsAdmin, in case there are
2683     * multiple admin clients accessing the broker and modifying
2684     * the admin username/passwd or port.
2685     */

2686    private synchronized JMSAdmin getJMSAdmin() throws Exception JavaDoc
2687    {
2688        ConfigContext serverContext;
2689        JmsService jmsService;
2690        JMSAdminFactory jmsaf;
2691        JMSAdmin _jmsAdmin = null;
2692        String JavaDoc instanceName, portStr, username, password, localhost, jmsAdminURL;
2693
2694        serverContext = getConfigContext();
2695
2696        jmsaf = IASJmsUtil.getJMSAdminFactory();
2697
2698        jmsService = (JmsService)ConfigBeansFactory.getConfigBeanByXPath(
2699            serverContext, ServerXPathHelper.XPATH_JMS_SERVICE);
2700
2701        localhost = java.net.InetAddress.getLocalHost().getHostName();
2702        JmsHost hostElement = jmsService.getJmsHost(0); //ms1 krav
2703
portStr = hostElement.getPort();
2704        username = hostElement.getAdminUserName();
2705        password = hostElement.getAdminPassword();
2706        jmsAdminURL = localhost + ((portStr == null) ?
2707                        "" : ":" + portStr);
2708
2709        _jmsAdmin = jmsaf.getJMSAdmin(jmsAdminURL, username, password);
2710
2711        return _jmsAdmin;
2712    }
2713
2714    private JMSAdmin getJMSAdmin(String JavaDoc targetName) throws Exception JavaDoc
2715    {
2716        final TargetType[] vaildTargetTypes = new TargetType[] {
2717            TargetType.CLUSTER, TargetType.SERVER, TargetType.DAS, TargetType.CONFIG};
2718        final Target target = TargetBuilder.INSTANCE.createTarget(
2719                vaildTargetTypes, targetName, getConfigContext());
2720        assert target != null;
2721
2722        final Config config = target.getConfigs()[0];
2723        final JmsService jmsService = config.getJmsService();
2724        JmsHost host = jmsService.getJmsHostByName(jmsService.getDefaultJmsHost());
2725        if (host == null)
2726        {
2727            host = jmsService.getJmsHost(0);
2728        }
2729
2730        final String JavaDoc hostName = host.getHost();
2731        final String JavaDoc port = host.getPort();
2732        final String JavaDoc adminUser = host.getAdminUserName();
2733        final String JavaDoc adminPassword = host.getAdminPassword();
2734        String JavaDoc url = hostName + (port == null ? "" : ":" + port);
2735        if (adminUser == null)
2736        {
2737           return IASJmsUtil.getJMSAdminFactory().getJMSAdmin(url);
2738        }
2739        else
2740        {
2741           return IASJmsUtil.getJMSAdminFactory().getJMSAdmin(
2742                url, adminUser, adminPassword);
2743        }
2744    }
2745
2746    private JMSDestinationInfo[] listAllDestinations(String JavaDoc[][] s)
2747    {
2748        JMSDestinationInfo destInfo;
2749        Vector JavaDoc dests = new Vector JavaDoc();
2750        String JavaDoc destName, destType;
2751
2752        // Convert the array[1] from JMSAdminConstants.QUEUE/TOPIC
2753
// to a JMSConstants.QUEUE/TOPIC
2754
for (int i = 0; i < s[1].length; i++) {
2755            destName = s[0][i];
2756
2757            if (s[1][i].equals(new Integer JavaDoc(JMSConstants.QUEUE).toString())) {
2758                destType = JMSAdminConstants.JMS_DEST_TYPE_QUEUE;
2759            } else if (s[1][i].equals(new Integer JavaDoc(JMSConstants.TOPIC).toString())) {
2760                destType = JMSAdminConstants.JMS_DEST_TYPE_TOPIC;
2761            } else {
2762                destType = "";
2763            }
2764
2765            destInfo = new JMSDestinationInfo(destName, destType);
2766            dests.addElement(destInfo);
2767        }
2768
2769        if (dests.size() > 0) {
2770            Object JavaDoc objArray[] = dests.toArray();
2771            JMSDestinationInfo jmsDestArray[];
2772            int size = dests.size();
2773
2774            jmsDestArray = new JMSDestinationInfo [size];
2775
2776            for (int i = 0; i < size; ++i) {
2777                jmsDestArray[i] = (JMSDestinationInfo)objArray[i];
2778            }
2779
2780            return (jmsDestArray);
2781        }
2782
2783        return (null);
2784    }
2785
2786    private JMSDestinationInfo[] listDestinationsByType(String JavaDoc destType, String JavaDoc[][] s)
2787    {
2788        JMSDestinationInfo destInfo;
2789        Vector JavaDoc dests = new Vector JavaDoc();
2790        String JavaDoc destName, type;
2791        String JavaDoc lookFor = null;
2792
2793        if (destType.equals(JMSAdminConstants.JMS_DEST_TYPE_TOPIC))
2794            lookFor = new Integer JavaDoc(JMSConstants.TOPIC).toString();
2795        else
2796            lookFor = new Integer JavaDoc(JMSConstants.QUEUE).toString();
2797
2798        // Convert the array[1] from JMSAdminConstants.QUEUE/TOPIC
2799
// to a JMSConstants.QUEUE/TOPIC
2800
int j = 0;
2801        for (int i = 0; i < s[1].length; i++) {
2802            if (s[1][i].equals(lookFor)) {
2803                destName = s[0][i];
2804
2805                if (s[1][i].equals(new Integer JavaDoc(JMSConstants.QUEUE).toString())) {
2806                    type = JMSAdminConstants.JMS_DEST_TYPE_QUEUE;
2807                } else if (s[1][i].equals(new Integer JavaDoc(JMSConstants.TOPIC).toString())) {
2808                    type = JMSAdminConstants.JMS_DEST_TYPE_TOPIC;
2809                } else {
2810                    type = "";
2811                }
2812
2813                destInfo = new JMSDestinationInfo(destName, type);
2814                dests.addElement(destInfo);
2815            }
2816        }
2817
2818        if (dests.size() > 0) {
2819            Object JavaDoc objArray[] = dests.toArray();
2820            JMSDestinationInfo jmsDestArray[];
2821            int size = dests.size();
2822
2823            jmsDestArray = new JMSDestinationInfo [size];
2824
2825            for (int i = 0; i < size; ++i) {
2826                    jmsDestArray[i] = (JMSDestinationInfo)objArray[i];
2827            }
2828
2829            return (jmsDestArray);
2830        }
2831
2832        return (null);
2833    }
2834
2835
2836    private void handleException(Exception JavaDoc e) throws JMSAdminException
2837    {
2838        if (e instanceof JMSAdminException) {
2839            throw ((JMSAdminException)e);
2840        }
2841
2842        String JavaDoc msg = e.getMessage();
2843
2844        JMSAdminException jae;
2845
2846        if (msg == null) {
2847            jae = new JMSAdminException();
2848        } else {
2849            jae = new JMSAdminException(msg);
2850        }
2851
2852        /*
2853         * Don't do this for now because the CLI does not include jms.jar
2854         * (at least not yet) in the classpath. Sending over a JMSException
2855         * will cause a class not found exception to be thrown.
2856        jae.setLinkedException(e);
2857         */

2858
2859        throw jae;
2860    }
2861    
2862    private static boolean isAttrNameMatch(Attribute JavaDoc attr, String JavaDoc name)
2863    {
2864        //FIXME: this code should be changed after FCS
2865
// for now we supporting both "dashed" and "underscored" names
2866
return attr.getName().replace('_','-').equals(name.replace('_','-'));
2867    }
2868
2869    // JMS Handling Ends
2870
private boolean isClustered(String JavaDoc tgt) throws ConfigException{
2871        final TargetType[] vaildTargetTypes = new TargetType[] {
2872                        TargetType.CLUSTER, TargetType.SERVER, TargetType.DAS, TargetType.CONFIG};
2873        final Target target = TargetBuilder.INSTANCE.createTarget(
2874                vaildTargetTypes, tgt, getConfigContext());
2875        assert target != null;
2876        return target.getType() == TargetType.CLUSTER;
2877    }
2878
2879}
2880
2881
Popular Tags