KickJava   Java API By Example, From Geeks To Geeks.

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


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  * $Header: /cvs/glassfish/admin/mbeanapi-impl/src/java/com/sun/enterprise/management/config/ClusterConfigFactory.java,v 1.4 2006/03/09 20:30:36 llc Exp $
26  * $Revision: 1.4 $
27  * $Date: 2006/03/09 20:30:36 $
28  */

29 package com.sun.enterprise.management.config;
30
31 import java.util.Set JavaDoc;
32 import java.util.HashSet JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.Map JavaDoc;
35 import java.util.HashMap JavaDoc;
36 import java.util.Properties JavaDoc;
37 import java.util.Collections JavaDoc;
38
39 import javax.management.AttributeList JavaDoc;
40 import javax.management.ObjectName JavaDoc;
41
42 import com.sun.appserv.management.base.Util;
43 import com.sun.appserv.management.config.ConfigConfig;
44 import com.sun.appserv.management.util.misc.MapUtil;
45 import com.sun.appserv.management.util.jmx.JMXUtil;
46
47 import com.sun.enterprise.management.support.oldconfig.OldClustersMBean;
48
49 final class ClusterConfigFactory extends ConfigFactory
50 {
51     private final OldClustersMBean mOldClustersMBean;
52     
53         public
54     ClusterConfigFactory(
55         final ConfigFactoryCallback callbacks )
56     {
57         super( callbacks );
58         
59         mOldClustersMBean = getOldConfigProxies().getOldClustersMBean();
60     }
61
62         protected ObjectName JavaDoc
63     createOldChildConfig(
64         final AttributeList JavaDoc translatedAttrs,
65         final Properties JavaDoc props )
66     {
67         // YUCK--createCluster( AttributeList ) cannot be called;
68
// it won't work correctly; we must make the call explicity.
69
final Map JavaDoc<String JavaDoc,String JavaDoc> m = JMXUtil.attributeListToStringMap( translatedAttrs );
70         
71         final String JavaDoc config = (String JavaDoc)m.get( "config-ref" );
72         final String JavaDoc name = (String JavaDoc)m.get( "name" );
73         
74         return mOldClustersMBean.createCluster( name, config, props );
75     }
76     
77     private final static String JavaDoc REFERENCED_CONFIG_NAME = "ReferencedConfigName";
78     
79         protected Map JavaDoc<String JavaDoc,String JavaDoc>
80     getParamNameOverrides()
81     {
82         return( MapUtil.newMap( REFERENCED_CONFIG_NAME, "config-ref" ) );
83     }
84             
85         private void
86     checkConfigExists( final String JavaDoc configName )
87     {
88         final Map JavaDoc<String JavaDoc,ConfigConfig> configs = getDomainConfig().getConfigConfigMap();
89         
90         if( ! configs.keySet().contains( configName ) )
91         {
92             throw new IllegalArgumentException JavaDoc( "No ConfigConfig exists with the name: " + configName );
93         }
94     }
95     
96         private boolean
97     clusterExists( final String JavaDoc name )
98     {
99         return getDomainConfig().getClusterConfigMap().keySet().contains( name );
100     }
101     
102         public ObjectName JavaDoc
103     create(
104         final String JavaDoc name,
105         final String JavaDoc configName,
106         final Map JavaDoc<String JavaDoc,String JavaDoc> optional )
107     {
108         if ( configName != null )
109         {
110             checkNonEmptyString( configName, "configName" );
111             checkConfigExists( configName );
112             
113             // This is explicitly disallowed
114
if ( configName.equals( "server-config" ) || configName.equals( "default-config" ) )
115             {
116                 throw new IllegalArgumentException JavaDoc( configName );
117             }
118         }
119         
120         if ( clusterExists( name ) )
121         {
122             throw new IllegalArgumentException JavaDoc( "Cluster already exists: " + quote( name ) );
123         }
124
125         
126         final String JavaDoc[] requiredParams =
127         {
128             "ReferencedConfigName", configName,
129         };
130         
131         final Map JavaDoc<String JavaDoc,String JavaDoc> params = initParams( name, requiredParams, optional );
132         
133         return createNamedChild( name, params );
134     }
135     
136     // default-config to be used
137
public ObjectName JavaDoc
138     create(
139         final String JavaDoc name,
140         final Map JavaDoc<String JavaDoc,String JavaDoc> optional )
141     {
142         return create( name, null, optional );
143     }
144
145     protected void internalRemove(final ObjectName JavaDoc objectName){
146         final String JavaDoc name = Util.getName(objectName);
147         if ( ! clusterExists( name ) )
148         {
149             throw new IllegalArgumentException JavaDoc( "No such cluster: " + quote( name ) );
150         }
151         mOldClustersMBean.deleteCluster(name);
152     }
153 }
154
155
156
157
158
159
Popular Tags