KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > config > ConnectorResourceConfigTest


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

23  
24 package com.sun.enterprise.management.config;
25
26 import java.util.Map JavaDoc;
27 import java.util.Set JavaDoc;
28
29 import javax.management.ObjectName JavaDoc;
30
31 import com.sun.appserv.management.base.Container;
32 import com.sun.appserv.management.base.XTypes;
33 import com.sun.appserv.management.base.AMX;
34 import com.sun.appserv.management.base.Util;
35
36 import com.sun.appserv.management.config.AMXConfig;
37 import com.sun.appserv.management.config.DomainConfig;
38 import com.sun.appserv.management.config.ConnectorConnectionPoolConfig;
39 import com.sun.appserv.management.config.ConnectorResourceConfig;
40 import com.sun.appserv.management.config.ResourceRefConfig;
41 import com.sun.appserv.management.config.ResourceRefConfigCR;
42
43 import com.sun.appserv.management.util.misc.StringUtil;
44 import com.sun.appserv.management.util.misc.CollectionUtil;
45
46 import com.sun.appserv.management.helper.RefHelper;
47
48 /**
49  */

50 public final class ConnectorResourceConfigTest extends ResourceConfigTestBase
51 {
52     public ConnectorResourceConfigTest()
53     {
54         if ( checkNotOffline( "ensureDefaultInstance" ) )
55         {
56             ensureDefaultInstance( getDomainConfig() );
57         }
58     }
59     
60         public static String JavaDoc
61     getDefaultInstanceName()
62     {
63         return getDefaultInstanceName( "ConnectorResourceConfig" );
64     }
65     
66          public static ConnectorResourceConfig
67     ensureDefaultInstance( final DomainConfig domainConfig )
68     {
69         ConnectorResourceConfig result =
70             domainConfig.getConnectorResourceConfigMap().get( getDefaultInstanceName() );
71         
72         final ConnectorConnectionPoolConfig connectorConnectionPool =
73             ConnectorConnectionPoolConfigTest.ensureDefaultInstance( domainConfig );
74         
75         if ( result == null )
76         {
77             result = createInstance( domainConfig,
78                 getDefaultInstanceName(),
79                     connectorConnectionPool.getName(), null );
80         }
81         
82         return result;
83     }
84     
85         public static ConnectorResourceConfig
86     createInstance(
87         final DomainConfig domainConfig,
88         final String JavaDoc name,
89         final String JavaDoc poolName,
90         final Map JavaDoc<String JavaDoc,String JavaDoc> optional )
91     {
92         return domainConfig.createConnectorResourceConfig(
93                 name, poolName, optional );
94     }
95     
96         protected String JavaDoc
97     getProgenyTestName()
98     {
99         return( "jndi/ConnectorResourceConfigTest" );
100     }
101         
102         protected Container
103     getProgenyContainer()
104     {
105         return getDomainConfig();
106     }
107
108         protected String JavaDoc
109     getProgenyJ2EEType()
110     {
111         return XTypes.CONNECTOR_RESOURCE_CONFIG;
112     }
113
114
115         protected void
116     removeProgeny( final String JavaDoc name )
117     {
118         final Set JavaDoc<ResourceRefConfig> resourceRefs =
119             getQueryMgr().queryJ2EETypeNameSet(XTypes.RESOURCE_REF_CONFIG,name);
120
121         getDomainConfig().removeConnectorResourceConfig( name );
122     }
123     
124     
125         protected final AMXConfig
126     createProgeny( final String JavaDoc name, final Map JavaDoc<String JavaDoc,String JavaDoc> options )
127     {
128         final String JavaDoc poolName =
129             ConnectorConnectionPoolConfigTest.ensureDefaultInstance( getDomainConfig() ).getName();
130         
131         assert( getDomainConfig().getConnectorResourceConfigMap().get( name ) == null ) :
132             "A resource already exists with name: " + name;
133         
134         final Set JavaDoc<ResourceRefConfig> resourceRefs =
135             getQueryMgr().queryJ2EETypeNameSet(XTypes.RESOURCE_REF_CONFIG,name);
136         
137         ConnectorResourceConfig config = null;
138         
139         final Set JavaDoc<ObjectName JavaDoc> resourceRefObjectNames = Util.toObjectNames( resourceRefs );
140         if ( resourceRefs.size() != 0 )
141         {
142         assert( false );
143             warning( "A DANGLING resource ref already exists with name: " + name +
144                 ", {" +
145                 CollectionUtil.toString( resourceRefObjectNames ) + "} (SKIPPING TEST)");
146         }
147         else
148         {
149             config = getDomainConfig().createConnectorResourceConfig( name,
150                     poolName, options );
151                     
152             final Set JavaDoc<ResourceRefConfig> refs =
153                 getQueryMgr().queryJ2EETypeNameSet(XTypes.RESOURCE_REF_CONFIG,name);
154             if ( resourceRefs.size() != 0 )
155             {
156                 final ResourceRefConfig ref = refs.iterator().next();
157                 
158                 warning( "A resource ref within " +
159                     Util.getObjectName( ref.getContainer() ) +
160                     " was automatically created when creating the ConnectorResourceConfig " );
161             }
162         }
163                 
164         addReference( config );
165
166         return( config );
167     }
168 }
169
170
171
Popular Tags