KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > mbean > test > ConfigBeansTest


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.test;
25
26 //JDK imports
27
import java.io.*;
28 import java.util.*;
29
30 //JMX imports
31
import javax.management.*;
32
33 //Admin imports
34
import com.sun.enterprise.admin.common.*;
35 import com.sun.enterprise.admin.common.constant.*;
36 import com.sun.enterprise.admin.util.*;
37 import com.sun.enterprise.admin.server.core.jmx.*;
38 import com.sun.enterprise.admin.server.core.mbean.config.*;
39 import com.sun.enterprise.admin.server.core.mbean.meta.*;
40 import com.sun.enterprise.admin.server.core.*;
41 public class ConfigBeansTest
42 {
43     
44     
45     /**
46      * @param args the command line arguments
47      */

48     
49     public static void main(String JavaDoc args[])
50     {
51         ConfigBeansTest testMain = new ConfigBeansTest();
52         testMain.test();
53     }
54     
55     private void printLine(String JavaDoc str)
56     {
57         System.out.println(str);
58     }
59     
60     private void printAttrList(AttributeList attrList, String JavaDoc title)
61     {
62         Iterator it = attrList.iterator();
63         printLine("\n\n\n################## " + title +" ##################");
64         AdminLocalStringsManager messages = AdminLocalStringsManager.createMessagesManager(this);
65         while (it.hasNext())
66         {
67             Attribute attribute = (Attribute) it.next();
68             String JavaDoc name = attribute.getName();
69             Object JavaDoc value = attribute.getValue();
70             printLine(messages.getString("mbeanstest.attrvalue", "======DO NOT KNOW=====", new Object JavaDoc[]{name,value}));
71             printLine("Attribute name="+name+" value="+value);
72         }
73     }
74     
75     private ObjectName getObjectName(String JavaDoc instance, String JavaDoc type, String JavaDoc name) throws Exception JavaDoc
76     {
77         String JavaDoc objname = "ias:" +
78                          ObjectNames.kServerInstanceKeyName + "=" + instance + "," +
79                          ObjectNames.kTypeKeyName + "=" + type;
80         if(name!=null)
81         {
82             objname += ("," + ObjectNames.kNameKeyName + "=" + name);
83         }
84 //printLine("OBJNAME="+objname);
85
return new ObjectName(objname);
86     }
87     
88     private String JavaDoc maskDots(String JavaDoc instance)
89     {
90         int idx = 0;
91         while((idx=instance.indexOf('.', idx))>=0)
92         {
93             instance = instance.substring(0,idx)+'\\'+instance.substring(idx);
94             idx += 2;
95         }
96         return instance;
97     }
98     
99     private void test()
100     {
101         try
102         {
103             String JavaDoc instance = "ias1";
104             String JavaDoc maskedInstance = maskDots(instance);
105
106             /*FileInputStream file = new FileInputStream("/export2/test/test.property");
107             Properties props = new Properties(System.getProperties());
108             props.load(file);
109             System.setProperties(props);
110             System.getProperty("com.sun.aas.instanceRoot");*/

111             AdminServiceLifeCycle aslc = new AdminServiceLifeCycle();
112             aslc.onInitialization(null);
113             MBeanServer mbs = SunoneInterceptor.getMBeanServerInstance();
114             GenericConfigurator genConf = new GenericConfigurator();
115 // mbs.registerMBean(genConf, new ObjectName("ias:type=configurator")); //a server-instance
116

117             AttributeList attrList;
118
119             
120             // ############# ejbs ##################
121
ManagedJ2EEEjbJarModule ejbmod = new ManagedJ2EEEjbJarModule(instance, "app", "helloworldEjb.jar");
122             {
123                 String JavaDoc[] arr = ejbmod.getEnterpriseBeans();
124                 for(int j=0; j<arr.length; j++)
125                    printLine("&&&&&&&&&+++++> "+arr[j]);
126             }
127
128             // ############# Standalone application ##################
129
ManagedJ2EEApplication app = new ManagedJ2EEApplication(instance, "app");
130             {
131                 String JavaDoc[] arr = app.getModules();
132                 for(int j=0; j<arr.length; j++)
133                    printLine("*************+++++> "+arr[j]);
134                 arr = app.getEjbModules();
135                 for(int j=0; j<arr.length; j++)
136                    printLine("------> "+arr[j]);
137                 arr = app.getModules();
138                 for(int j=0; j<arr.length; j++)
139                    printLine("*************+++++> "+arr[j]);
140             }
141 if(genConf!=null)
142     return;
143             attrList = genConf.getGenericAttributes(new String JavaDoc[]{maskedInstance + ".application.app.*"});
144             printAttrList(attrList, "Standalone application TEST");
145 if(genConf!=null)
146     return;
147
148             //########### HTTPService TEST ##################
149
ManagedHTTPService httpService = new ManagedHTTPService(instance);
150             genConf.setGenericAttribute(maskedInstance + ".httpservice.bandwidthLimit", "TESTbandWidthLimit");
151             attrList = genConf.getGenericAttributes(new String JavaDoc[]{maskedInstance + ".httpservice.*"});
152             printAttrList(attrList, "HTTPService TEST");
153             /** Ramakanth. Signature changed. 03/28/2002. 6:47pm
154     httpService.createHTTPListener("myID","myADDRESS",new Integer(123),new Boolean(false),
155              "myFAMILY", new Integer(456), new Boolean(false), new Boolean(false));
156              */

157 if(genConf!=null)
158     return;
159
160             // ############# JDBCResource ##################
161
ManagedJDBCResource jdbc = new ManagedJDBCResource(instance,"name1");
162 // mbs.registerMBean(jdbc, getObjectName(instance, ObjectNames.kJdbcResourceType, "name1/name1"));
163
// genConf.setGenericAttribute(maskedInstance + ".jdbc.name1-name1.log", "TESTVALUE2");
164
attrList = genConf.getGenericAttributes(new String JavaDoc[]{maskedInstance + ".jdbc.name1.*"});
165             printAttrList(attrList, "JDBC TEST");
166         // ############# JDBCConnectionPool ##################
167
ManagedJDBCConnectionPool jdbcpool = new ManagedJDBCConnectionPool(instance,"pool1");
168 // mbs.registerMBean(jdbcpool, getObjectName(instance, ObjectNames.kJdbcConnectionPoolType, "pool1"));
169
genConf.setGenericAttribute(maskedInstance + ".jdbcpool.pool1.url", "TESTURL2");
170             attrList = genConf.getGenericAttributes(new String JavaDoc[]{maskedInstance + ".jdbcpool.pool1.*"});
171             printAttrList(attrList, "JDBCConnectionPool TEST");
172
173
174  //if(mbs!=null)
175
// return;
176

177             // ############# ORB ##################
178
ManagedORBComponent orb = new ManagedORBComponent(instance);
179 // mbs.registerMBean(orb, getObjectName(instance, ObjectNames.kOrbType, null)); //a server-instance
180
genConf.setGenericAttribute(maskedInstance + ".orb.max", new Integer JavaDoc(333));
181             attrList = genConf.getGenericAttributes(new String JavaDoc[]
182             {maskedInstance + ".orb.max"});
183             printAttrList(attrList, "ORB max TEST");
184             attrList = genConf.getGenericAttributes(new String JavaDoc[]{maskedInstance + ".orb.*"});
185             printAttrList(attrList, "ORB TEST");
186             
187         // ############# ORBListener ##################
188
// orb.createOrbListener("myTestId5", "nowhere", null, null, new Integer(12345));
189
ManagedORBListener orbListener = new ManagedORBListener(instance, "myTestId5");
190               // orbListener.createSsl("MYcertNickname", null, null, null, null, null, null, null);
191

192 // orbListener.createAuthDb("MYauthID", "MYdatabase", "MYbasedn", "MYcertmaps");
193

194 // mbs.registerMBean(orbListener, getObjectName(instance, ObjectNames.kOrbListenerType, "myTestId5")); //a server-instance
195
genConf.setGenericAttribute(maskedInstance + ".orblistener.myTestId5.address", "TESTADDRESS2");
196             attrList = genConf.getGenericAttributes(new String JavaDoc[]{maskedInstance + ".orblistener.myTestId5.*"});
197             printAttrList(attrList, "ORBListener TEST");
198             
199
200        //########### JNDI ##################
201

202         ManagedJNDIResource jndi = new ManagedJNDIResource(instance, "myjndi");
203 // mbs.registerMBean(jndi, getObjectName(instance, ObjectNames.kJndiResourceType, "myjndi"));
204
genConf.setGenericAttribute(maskedInstance + ".jndi.myjndi.description", "my test description");
205             attrList = genConf.getGenericAttributes(new String JavaDoc[] {maskedInstance + ".jndi.myjndi.*"});
206             printAttrList(attrList, "JNDI Resource test");
207           
208             
209             // ############# Transaction service ##################
210
ManagedTransactionService transService = new ManagedTransactionService(instance);
211  // mbs.registerMBean(transService, getObjectName(instance, ObjectNames.kJtsComponent, null));
212
genConf.setGenericAttribute(maskedInstance + ".transaction.transactionLogDir", "logDir");
213             attrList = genConf.getGenericAttributes(new String JavaDoc[] {maskedInstance + ".transaction.*"});
214            printAttrList(attrList, "Transaction TEST");
215
216        // ########### MDB Container ################
217
ManagedMdbContainer MdbContainer = new ManagedMdbContainer(instance);
218  // mbs.registerMBean(MdbContainer, getObjectName(instance, ObjectNames.kMdbContainer, null));
219
genConf.setGenericAttribute(maskedInstance + ".mdbcontainer.queueConnectionFactoryJndiName", "jndi1");
220             attrList =genConf.getGenericAttributes(new String JavaDoc[] {maskedInstance + ".mdbcontainer.*"});
221            printAttrList(attrList, "MDB Container test");
222
223        //########### EJB Container ##################
224

225             ManagedEjbContainer EjbContainer = new ManagedEjbContainer(instance);
226 // mbs.registerMBean(EjbContainer, getObjectName(instance, ObjectNames.kEjbContainer, null));
227
genConf.setGenericAttribute(maskedInstance + ".ejbcontainer.minBeansInPool", new Integer JavaDoc(20));
228             attrList = genConf.getGenericAttributes(new String JavaDoc[] {maskedInstance + ".ejbcontainer.*"});
229            printAttrList(attrList, "EJB Container test");
230
231        //########### WEB Container ##################
232

233             ManagedWebContainer WebContainer = new ManagedWebContainer(instance);
234 // mbs.registerMBean(WebContainer, getObjectName(instance, ObjectNames.kWebContainer, null));
235
genConf.setGenericAttribute(maskedInstance + ".ejbcontainer.minBeansInPool", new Integer JavaDoc(20));
236             attrList = genConf.getGenericAttributes(new String JavaDoc[] {maskedInstance + ".webcontainer.*"});
237            printAttrList(attrList, "WEB Container test");
238
239        //########### JVM ##################
240

241             ManagedJVM Jvm = new ManagedJVM(instance);
242 // mbs.registerMBean(Jvm, getObjectName(instance, ObjectNames.kJvmType, null));
243
// genConf.setGenericAttribute(maskedInstance + ".jvm.javahome", "/tools/java");
244
attrList = genConf.getGenericAttributes(new String JavaDoc[] {maskedInstance + ".jvmconfig.*"});
245            printAttrList(attrList, "JVM test");
246           
247             // ############# SecurityService ##################
248
// ManagedSecurityService sec = new ManagedSecurityService(instance);
249
// mbs.registerMBean(jdbcpool, getObjectName(instance, ObjectNames.kJdbcConnectionPoolType, "pool1"));
250
attrList = genConf.getGenericAttributes(new String JavaDoc[]{maskedInstance + ".security.*"});
251             printAttrList(attrList, "SecurityService TEST");
252
253             // ############# Standalone application ##################
254
// ManagedStandaloneJ2EEApplication app = new ManagedStandaloneJ2EEApplication(instance, "app");
255
attrList = genConf.getGenericAttributes(new String JavaDoc[]{maskedInstance + ".application.app.*"});
256             printAttrList(attrList, "Standalone application TEST");
257
258             // ############# Standalone EjbJar module ##################
259
// ManagedStandaloneJ2EEEjbJarModule ejb = new ManagedStandaloneJ2EEEjbJarModule(instance, "ejb");
260
attrList = genConf.getGenericAttributes(new String JavaDoc[]{maskedInstance + ".ejbmodule.ejb.*"});
261             printAttrList(attrList, "Standalone EjbJar module TEST");
262             
263             // ############# Standalone Web Module ##################
264
// ManagedStandaloneJ2EEWebModule sec = new ManagedStandaloneJ2EEWebModule(instance, "web");
265
attrList = genConf.getGenericAttributes(new String JavaDoc[]{maskedInstance + ".webmodule.web.*"});
266             printAttrList(attrList, "Standalone Web Module TEST");
267             
268             // ############# Standalone Connector Module ##################
269
// ManagedStandaloneConnectorModule sec = new ManagedStandaloneConnectorModule(instance, "conn");
270
attrList = genConf.getGenericAttributes(new String JavaDoc[]{maskedInstance + ".connectormodule.conn.*"});
271             printAttrList(attrList, "Standalone Connector Module TEST");
272         }
273         catch(MBeanException m)
274         {
275             printLine(m.getMessage());
276             Exception JavaDoc t = m.getTargetException();
277             while(t instanceof MBeanException)
278             {
279                 t = ((MBeanException)t).getTargetException();
280             }
281             printLine(t.getMessage());
282             printLine(t.toString());
283             m.printStackTrace();
284         }
285         catch(Throwable JavaDoc e)
286         {
287             printLine(e.getMessage());
288             printLine(e.toString());
289             e.printStackTrace();
290         }
291     }
292     
293     
294 }
295
Popular Tags