KickJava   Java API By Example, From Geeks To Geeks.

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


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  *
26  */

27
28 package com.sun.enterprise.admin.mbeans;
29
30 import com.sun.enterprise.admin.target.Target;
31 import com.sun.enterprise.admin.target.TargetBuilder;
32 import com.sun.enterprise.admin.target.TargetType;
33 import com.sun.enterprise.config.ConfigContext;
34 import com.sun.enterprise.config.ConfigException;
35 import com.sun.enterprise.config.serverbeans.ClusterHelper;
36 import com.sun.enterprise.config.serverbeans.ConfigAPIHelper;
37 import com.sun.enterprise.config.serverbeans.ServerHelper;
38 import com.sun.enterprise.util.i18n.StringManager;
39 import java.util.List JavaDoc;
40
41 import javax.management.Attribute JavaDoc;
42
43 import com.sun.enterprise.config.serverbeans.ServerTags;
44 import javax.management.MBeanException JavaDoc;
45 import javax.management.MBeanServer JavaDoc;
46
47
48 /**
49  * Static utility class for common functions in config mbeans. Place all common
50  * utility type functions into this class for access across all config mbeans.
51  *
52  * @author Rob Ruyak
53  */

54 public class ConfigMBeanUtil {
55     
56     /**
57      * i18n strings manager object
58      */

59     private static final StringManager localStrings =
60         StringManager.getManager(ConfigsMBean.class);
61     
62     
63     //disallow the instantiation of this object
64
private ConfigMBeanUtil() {
65     }
66     
67     /**
68      * Given a list and an Attribute object, returns whether or not the
69      * attribute with the specified name exists.
70      *
71      * @param list the list of Attribute objects
72      * @param name the name of the attribute to find
73      * @return true/false
74      */

75     public static boolean attributeDefinedInList(final List JavaDoc list,
76             final String JavaDoc name) {
77         if(name != null) {
78             for(java.util.Iterator JavaDoc itr = list.iterator(); itr.hasNext(); ) {
79                 Attribute JavaDoc attr = (Attribute JavaDoc) itr.next();
80                 if(name != null && name.equals(attr.getName())) {
81                     return true;
82                 }
83             }
84         }
85         return false;
86     }
87     
88     /**
89      *
90      *
91      */

92     public static MBeanServer JavaDoc getMBeanServer() throws MBeanException JavaDoc {
93         return com.sun.enterprise.admin.common.MBeanServerFactory.getMBeanServer();
94     }
95     
96     
97     /**
98      *
99      *
100      */

101     public static Target getTarget(String JavaDoc targetName, TargetType[] targetTypes,
102             ConfigContext configContext) throws MBeanException JavaDoc {
103                 
104         try {
105             Target target = TargetBuilder.INSTANCE.createTarget(
106                     targetTypes, targetName, configContext);
107             if (target.getType() == TargetType.SERVER ||
108                 target.getType() == TargetType.DAS) {
109                 //If we are operating on a server, ensure that the server is the only entity
110
//referencing its config
111
String JavaDoc configName = ServerHelper.getConfigForServer(configContext,
112                     target.getName()).getName();
113                 if (!ConfigAPIHelper.isConfigurationReferencedByServerOnly(configContext,
114                     configName, target.getName())) {
115                         throw new ConfigException(localStrings.getString(
116                             "configurationHasMultipleRefs", target.getName(), configName,
117                             ConfigAPIHelper.getConfigurationReferenceesAsString(
118                                 configContext, configName)));
119                 }
120             } else if (target.getType() == TargetType.CLUSTER) {
121                 //If we are operating on a cluster, ensure that the cluster is the only entity
122
//referencing its config
123
String JavaDoc configName = ClusterHelper.getConfigForCluster(configContext,
124                     target.getName()).getName();
125                 if (!ConfigAPIHelper.isConfigurationReferencedByClusterOnly(configContext,
126                     configName, target.getName())) {
127                         throw new ConfigException(localStrings.getString(
128                             "configurationHasMultipleRefs", target.getName(), configName,
129                             ConfigAPIHelper.getConfigurationReferenceesAsString(
130                                 configContext, configName)));
131                 }
132             }
133             return target;
134         }
135         catch (Exception JavaDoc e) {
136             throw MBeanExceptionFormatter.toMBeanException(e, null);
137         }
138     }
139 }
140
Popular Tags