KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > mbean > config > ManagedORBComponent


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 package com.sun.enterprise.admin.server.core.mbean.config;
25
26 //JMX imports
27
import javax.management.*;
28
29 //Config imports
30
import com.sun.enterprise.config.ConfigException;
31 import com.sun.enterprise.config.serverbeans.ServerTags;
32 import com.sun.enterprise.config.serverbeans.ServerXPathHelper;
33 import com.sun.enterprise.config.serverbeans.IiopService;
34 import com.sun.enterprise.config.serverbeans.IiopListener;
35 import com.sun.enterprise.config.serverbeans.Ssl;
36 import com.sun.enterprise.config.serverbeans.SslClientConfig;
37
38 //Admin imports
39
import com.sun.enterprise.admin.common.ObjectNames;
40 import com.sun.enterprise.admin.common.exception.MBeanConfigException;
41 import com.sun.enterprise.admin.common.constant.ConfigAttributeName;
42
43 //i18n import
44
import com.sun.enterprise.util.i18n.StringManager;
45
46
47 /**
48     This Config MBean represents a ORB Component.
49     It extends ConfigMBeanBase class which provides get/set attribute(s) and getMBeanInfo services according to text descriptions.
50     ObjectName of this MBean is:
51         ias: type=orb, instance-name=<instance-name>
52 */

53 public class ManagedORBComponent extends ConfigMBeanBase implements ConfigAttributeName.OrbComponent
54 {
55     // i18n StringManager
56
private static StringManager localStrings =
57         StringManager.getManager( ManagedORBComponent.class );
58
59     private static final String JavaDoc ORB_ATTRIBUTE = ServerTags.ORB+ServerXPathHelper.XPATH_SEPARATOR+ATTRIBUTE;
60     /**
61      * MAPLIST array defines mapping between "external" name and its location in XML relatively base node
62      */

63     private static final String JavaDoc[][] MAPLIST =
64     {
65         {kMessageFragmentSize , ORB_ATTRIBUTE + ServerTags.MESSAGE_FRAGMENT_SIZE},
66         {kMaxConnections , ORB_ATTRIBUTE + ServerTags.MAX_CONNECTIONS},
67         //----- SSL -------- Ssl interface attributes appended here
68
};
69     /**
70      * ATTRIBUTES array specifies attributes descriptions in format defined for MBeanEasyConfig
71      */

72     private static final String JavaDoc[] ATTRIBUTES =
73     {
74         kMessageFragmentSize + ", int, RW" ,
75         kMaxConnections + ", int, RW" ,
76         //----- SSL -------- Ssl interface attributes appended here
77
};
78     /**
79      * OPERATIONS array specifies operations descriptions in format defined for MBeanEasyConfig
80      */

81     private static final String JavaDoc[] OPERATIONS =
82     {
83         "createORBListener(String id, String address, Integer port, Boolean enabled), ACTION",
84         "deleteORBListener(String id), ACTION",
85         "listORBListeners(), INFO",
86         "createSsl(String certNickname, Boolean ssl2Enabled, String ssl2Ciphers, Boolean ssl3Enabled, String ssl3TlsCiphers, Boolean tlsEnabled, Boolean tlsRollbackEnabled, Boolean clientAuthEnabled), ACTION",
87         "deleteSsl(), ACTION",
88         "isSslCreated(), INFO",
89     };
90     
91    
92     
93     /**
94         Default constructor sets MBean description tables
95     */

96     public ManagedORBComponent() throws MBeanConfigException
97     {
98         Object JavaDoc[] mergedAttrs = MergeAttributesWithAnotherMbean(
99              MAPLIST, ATTRIBUTES, SslBase.MAPLIST, SslBase.ATTRIBUTES,
100              ServerTags.SSL_CLIENT_CONFIG+ServerXPathHelper.XPATH_SEPARATOR+ServerTags.SSL , null);
101         this.setDescriptions( (String JavaDoc[][])mergedAttrs[0], (String JavaDoc[])mergedAttrs[1], OPERATIONS);
102     }
103
104     /**
105         Constructs Config MBean for ORB Component.
106         @param instanceName The server instance name.
107     */

108     public ManagedORBComponent(String JavaDoc instanceName) throws MBeanConfigException
109     {
110         this(); //set description tables
111
initialize(ObjectNames.kOrbType, new String JavaDoc[]{instanceName});
112     }
113     
114     /**
115     This operation creates OrbListener according to attributes and adds(links) it to current ORB;
116     If attribute is 'null' then default value will be set.
117      */

118     public void createORBListener(String JavaDoc id, String JavaDoc address, Integer JavaDoc port, Boolean JavaDoc enabled) throws ConfigException
119     {
120         IiopListener listener = new IiopListener();
121         if(id!=null)
122             listener.setId(id);
123         if(address!=null)
124             listener.setAddress(address);
125         if(port!=null)
126             listener.setPort(port.toString());
127         if(enabled!=null)
128             listener.setEnabled(enabled.booleanValue());
129         IiopService service = (IiopService)getConfigBeanByXPath( ServerXPathHelper.getIIOPServiceXpath() );
130         service.addIiopListener(listener);
131         
132         getConfigContext().flush();
133     }
134     
135     /**
136     This operation deletes OrbListener according to id if it connected to current ORB.
137     @throws ConfigException in case of failure.
138      */

139     public void deleteORBListener(String JavaDoc id) throws ConfigException
140     {
141         IiopService service = (IiopService)getConfigBeanByXPath( ServerXPathHelper.getIIOPServiceXpath() );
142         IiopListener listener = service.getIiopListenerById(id);
143         if(listener!=null)
144             service.removeIiopListener(listener);
145         getConfigContext().flush();
146     }
147
148     /**
149     This operation returns list of OrbListener's ids connected to current ORB.
150      */

151     public String JavaDoc[] listORBListeners() throws ConfigException
152     {
153         IiopService service = (IiopService)getConfigBeanByXPath( ServerXPathHelper.getIIOPServiceXpath() );
154         IiopListener[] listeners = service.getIiopListener();
155         String JavaDoc[] res = new String JavaDoc[listeners.length];
156         for(int i=0; i<listeners.length; i++)
157         {
158             res[i] = listeners[i].getId();
159         }
160         return res;
161     }
162
163     /**
164     This operation checks Ssl existance in current element;
165      */

166     public boolean isSslCreated() throws ConfigException
167     {
168         IiopService service = (IiopService)this.getBaseConfigBean();
169         SslClientConfig config = service.getSslClientConfig();
170         if(config==null)
171             return false;
172         return (config.getSsl()!=null);
173     }
174
175     /**
176     This operation deletes Ssl sub-element from current element;
177      */

178     public void deleteSsl() throws ConfigException
179     {
180         IiopService service = (IiopService)this.getBaseConfigBean();
181         service.setSslClientConfig(null); //because ssl is required and only element in config now
182
getConfigContext().flush();
183     }
184     /**
185      * This operation creates Ssl ConfigBean according to attributes and adds(links) it to current config bean;
186      * If attribute is 'null' then default value will be set.
187      */

188     public void createSsl(String JavaDoc certNickname, Boolean JavaDoc ssl2Enabled, String JavaDoc ssl2Ciphers,
189     Boolean JavaDoc ssl3Enabled, String JavaDoc ssl3TlsCiphers,
190     Boolean JavaDoc tlsEnabled, Boolean JavaDoc tlsRollbackEnabled, Boolean JavaDoc clientAuthEnabled) throws ConfigException
191     {
192         if(isSslCreated())
193         {
194             String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.iiopservice_has_ssl_created" );
195             throw new ConfigException( msg );
196         }
197             
198         IiopService service = (IiopService)this.getBaseConfigBean();
199         SslClientConfig config = service.getSslClientConfig();
200         if(config == null)
201         {
202             config = new SslClientConfig();
203         }
204   
205         Ssl ssl = new Ssl();
206         //strings
207
if(certNickname!=null)
208             ssl.setCertNickname(certNickname);
209         if(ssl2Ciphers!=null)
210             ssl.setSsl2Ciphers(ssl2Ciphers);
211         if(ssl3TlsCiphers!=null)
212             ssl.setSsl3TlsCiphers(ssl3TlsCiphers);
213         //Booleans
214
if(ssl2Enabled!=null)
215             ssl.setSsl2Enabled(ssl2Enabled.booleanValue());
216         if(ssl3Enabled!=null)
217             ssl.setSsl3Enabled(ssl3Enabled.booleanValue());
218         if(tlsEnabled!=null)
219             ssl.setTlsEnabled(tlsEnabled.booleanValue());
220         if(tlsRollbackEnabled!=null)
221             ssl.setTlsRollbackEnabled(tlsRollbackEnabled.booleanValue());
222         if(clientAuthEnabled!=null)
223             ssl.setClientAuthEnabled(clientAuthEnabled.booleanValue());
224         
225         config.setSsl(ssl);
226         service.setSslClientConfig(config);
227         
228         getConfigContext().flush();
229     }
230 }
231
Popular Tags