KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.management.config;
24
25 import java.util.Set JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.io.IOException JavaDoc;
28
29 import javax.management.ObjectName JavaDoc;
30 import javax.management.AttributeList JavaDoc;
31
32 import com.sun.appserv.management.config.JDBCResourceConfig;
33 import com.sun.appserv.management.config.JDBCConnectionPoolConfig;
34 import com.sun.appserv.management.config.ResourceRefConfig;
35
36 import com.sun.appserv.management.util.misc.MapUtil;
37 import com.sun.appserv.management.base.XTypes;
38
39 /**
40     MBean managing all instances of JDBC resource.
41  */

42
43 public final class JDBCResourceConfigFactory extends ResourceFactoryImplBase
44     // implements JDBCResourceConfigMgr
45
{
46         public
47     JDBCResourceConfigFactory( final ConfigFactoryCallback callbacks )
48     {
49         super( callbacks );
50     }
51
52                 
53     /**
54         The caller is responsible for dealing with any Properties.
55      */

56         protected ObjectName JavaDoc
57     createOldChildConfig(
58         final AttributeList JavaDoc translatedAttrs )
59     {
60         trace( "JDBCResourceConfigFactory.createOldChildConfig: creating using: " +
61             stringify( translatedAttrs ) );
62             
63         final ObjectName JavaDoc objectName =
64                 getOldResourcesMBean().createJdbcResource( translatedAttrs );
65         
66         return( objectName );
67     }
68                 
69         protected Map JavaDoc<String JavaDoc,String JavaDoc>
70     getParamNameOverrides()
71     {
72         return( MapUtil.newMap( CONFIG_NAME_KEY, "jndi-name" ) );
73     }
74                 
75                     
76     public static final String JavaDoc POOL_NAME_KEY = "PoolName";
77
78         /**
79         Create a new &lt;jdbc-resource&gt;
80         
81         @param jndiName
82         @param poolName
83         @param optional
84      */

85     public ObjectName JavaDoc create(
86         final String JavaDoc jndiName,
87         final String JavaDoc poolName,
88         final Map JavaDoc<String JavaDoc,String JavaDoc> optional )
89     {
90         final JDBCConnectionPoolConfig pool = (JDBCConnectionPoolConfig)
91             getCallbacks().getProxyFactory().getDomainRoot().getDomainConfig().
92                 getContainee( XTypes.JDBC_CONNECTION_POOL_CONFIG, poolName );
93         if ( pool == null )
94         {
95             throw new IllegalArgumentException JavaDoc( "JDBCConnectionPoolConfig does not exit: " + poolName );
96         }
97             
98         final String JavaDoc[] requiredParams = new String JavaDoc[]
99         {
100             POOL_NAME_KEY, poolName,
101         };
102             
103         final Map JavaDoc<String JavaDoc,String JavaDoc> params = initParams( jndiName, requiredParams, optional );
104
105         final ObjectName JavaDoc amxName = createNamedChild( jndiName, params );
106         return( amxName );
107     }
108         
109         protected void
110     removeByName( final String JavaDoc name )
111     {
112         final Set JavaDoc<ResourceRefConfig> refs =
113             findAllRefConfigs( XTypes.JDBC_RESOURCE_CONFIG, name );
114         
115         if ( refs.size() == 0 )
116         {
117             getOldResourcesMBean().removeJdbcResourceByJndiName( name );
118         }
119         else
120         {
121             for( final ResourceRefConfig ref : refs )
122             {
123                 final String JavaDoc target = ref.getContainer().getName();
124                 getOldResourcesMBean().deleteJdbcResource( name, target );
125             }
126         }
127     }
128     
129 }
130
131
Popular Tags