KickJava   Java API By Example, From Geeks To Geeks.

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


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
28 import javax.management.AttributeList JavaDoc;
29 import javax.management.ObjectName JavaDoc;
30     
31 import com.sun.appserv.management.base.XTypes;
32
33 import com.sun.appserv.management.config.JNDIResourceConfig;
34 import com.sun.appserv.management.config.ResourceRefConfig;
35
36 import com.sun.appserv.management.helper.RefHelper;
37
38 import com.sun.appserv.management.util.misc.MapUtil;
39
40
41 /**
42     MBean managing all instances of JNDIResource.
43  */

44
45 public final class JNDIResourceConfigFactory extends ResourceFactoryImplBase
46 {
47         public
48     JNDIResourceConfigFactory( final ConfigFactoryCallback callbacks )
49     {
50         super( callbacks );
51     }
52
53     private static final String JavaDoc JNDI_LOOKUP_NAME_KEY = "JNDILookupName";
54     private static final String JavaDoc FACTORY_CLASS_KEY = "FactoryClass";
55     private static final String JavaDoc RES_TYPE_KEY = "ResType";
56
57                 
58         /**
59         The caller is responsible for dealing with any Properties.
60      */

61         protected ObjectName JavaDoc
62     createOldChildConfig(
63         final AttributeList JavaDoc translatedAttrs )
64     {
65         
66         trace( "JNDIResourceConfigFactory.createOldChildConfig: creating using: " +
67             stringify( translatedAttrs ) );
68             
69         final ObjectName JavaDoc objectName =
70                 getOldResourcesMBean().createExternalJndiResource( translatedAttrs );
71         
72         return( objectName );
73     }
74                 
75         protected Map JavaDoc<String JavaDoc,String JavaDoc>
76     getParamNameOverrides()
77     {
78         return( MapUtil.newMap( CONFIG_NAME_KEY, "jndi-name" ) );
79     }
80                 
81     /**
82         Creates a new &lt;external-jndi-resource&gt;.
83  
84         @param jndiName
85         @param jndiLookupName
86         @param resType
87         @param factoryClass
88         @param optional
89      */

90         public ObjectName JavaDoc
91     create( String JavaDoc jndiName,
92         String JavaDoc jndiLookupName,
93         String JavaDoc resType,
94         String JavaDoc factoryClass,
95         Map JavaDoc<String JavaDoc,String JavaDoc> optional)
96     {
97         final String JavaDoc[] requiredParams = new String JavaDoc[]
98         {
99             JNDI_LOOKUP_NAME_KEY, jndiLookupName,
100             RES_TYPE_KEY, resType,
101             FACTORY_CLASS_KEY, factoryClass,
102         };
103                 
104         final Map JavaDoc<String JavaDoc,String JavaDoc> params = initParams( jndiName, requiredParams, optional );
105
106         final ObjectName JavaDoc amxName = createNamedChild( jndiName, params );
107
108         return( amxName );
109     }
110         
111     
112         protected void
113     removeByName( final String JavaDoc name )
114     {
115         final Set JavaDoc<ResourceRefConfig> refs =
116             findAllRefConfigs( XTypes.JNDI_RESOURCE_CONFIG, name );
117         
118         if ( refs.size() == 0 )
119         {
120             getOldResourcesMBean().removeExternalJndiResourceByJndiName( name );
121         }
122         else
123         {
124             for( final ResourceRefConfig ref : refs )
125             {
126                 final String JavaDoc target = ref.getContainer().getName();
127                 getOldResourcesMBean().deleteExternalJndiResource( name, target );
128             }
129         }
130     }
131 }
132
133
Popular Tags