KickJava   Java API By Example, From Geeks To Geeks.

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


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/CustomMBeanConfigFactory.java,v 1.4 2006/03/09 20:30:37 llc Exp $
26  * $Revision: 1.4 $
27  * $Date: 2006/03/09 20:30:37 $
28  */

29
30
31 package com.sun.enterprise.management.config;
32
33 import java.util.Map JavaDoc;
34 import java.util.Set JavaDoc;
35 import java.util.Properties JavaDoc;
36
37 import javax.management.ObjectName JavaDoc;
38 import javax.management.AttributeList JavaDoc;
39
40 import com.sun.appserv.management.base.Util;
41 import com.sun.appserv.management.base.QueryMgr;
42 import com.sun.appserv.management.base.XTypes;
43 import com.sun.appserv.management.base.Container;
44
45 import com.sun.appserv.management.config.CustomMBeanConfig;
46 import com.sun.appserv.management.config.DeployedItemRefConfig;
47 import com.sun.appserv.management.config.RefConfig;
48
49 import com.sun.appserv.management.helper.RefHelper;
50
51 import com.sun.appserv.management.util.misc.ExceptionUtil;
52 import com.sun.appserv.management.util.jmx.JMXUtil;
53 import com.sun.appserv.management.util.misc.GSetUtil;
54
55 import com.sun.enterprise.management.support.oldconfig.OldApplicationsConfigMBean;
56
57 import com.sun.enterprise.admin.mbeans.custom.CustomMBeanConstants;
58
59
60 public final class CustomMBeanConfigFactory extends ConfigFactory
61 {
62         public
63     CustomMBeanConfigFactory(
64         final ConfigFactoryCallback callbacks )
65     {
66         super( callbacks );
67     }
68                 
69   /**
70         The caller is responsible for dealing with any Properties.
71      */

72         protected ObjectName JavaDoc
73     createOldChildConfig(
74         final AttributeList JavaDoc translatedAttrs )
75     {
76         final Map JavaDoc<String JavaDoc,String JavaDoc> m =
77             JMXUtil.attributeListToStringMap( translatedAttrs );
78         
79         final String JavaDoc DOMAIN = null; // magic value
80
final String JavaDoc name = getOld().createMBean( DOMAIN, m );
81         
82         final ObjectName JavaDoc objectName = getOld().getMbeanByName( name );
83         
84         debug( "created custom MBean with name: " + objectName );
85         return( objectName );
86     }
87
88         private OldApplicationsConfigMBean
89     getOld()
90     {
91         return getOldConfigProxies().getOldApplicationsConfigMBean();
92     }
93
94         public ObjectName JavaDoc
95     create(
96         final String JavaDoc name,
97         final String JavaDoc implClassname,
98         final String JavaDoc objectName,
99         final boolean enabled,
100         final Map JavaDoc<String JavaDoc,String JavaDoc> optional )
101     {
102         final String JavaDoc[] requiredParams = new String JavaDoc[]
103         {
104         CustomMBeanConstants.NAME_KEY, name,
105         CustomMBeanConstants.IMPL_CLASS_NAME_KEY, implClassname,
106         CustomMBeanConstants.OBJECT_NAME_KEY, objectName,
107         CustomMBeanConstants.ENABLED_KEY, "" + enabled,
108         };
109         final Map JavaDoc<String JavaDoc,String JavaDoc> params = initParams( name, requiredParams, optional );
110
111         final ObjectName JavaDoc amxName = createNamedChild( name, params );
112         return amxName;
113     }
114     
115     
116         private final String JavaDoc
117     getRefContainerName( final String JavaDoc name )
118     {
119         final QueryMgr queryMgr = getDomainRoot().getQueryMgr();
120         
121         // this is all bug-workaround code
122
final Set JavaDoc<DeployedItemRefConfig> refs =
123             RefHelper.findAllRefConfigsWithName( queryMgr, XTypes.DEPLOYED_ITEM_REF_CONFIG, name );
124            
125         final RefConfig ref = GSetUtil.getSingleton( refs );
126         final Container refContainer = ref.getContainer();
127         
128         return refContainer.getName();
129     }
130     
131     
132         final public void
133     removeByName( final String JavaDoc name )
134     {
135         // bug-workaround code
136
getOld().deleteMBean( getRefContainerName( name ), name );
137     }
138 }
139
140
141
142
143
144
Popular Tags