KickJava   Java API By Example, From Geeks To Geeks.

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


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
41 //i18n import
42
import com.sun.enterprise.util.i18n.StringManager;
43
44 public class GenericConfiguratorTest
45 {
46     
47
48     // i18n StringManager
49
private static StringManager localStrings =
50         StringManager.getManager( GenericConfiguratorTest.class );
51
52     /**
53         @param args the command line arguments
54     */

55     
56     public static void main (String JavaDoc args[])
57     {
58         GenericConfiguratorTest testMain = new GenericConfiguratorTest();
59         testMain.test();
60     }
61
62     private void test()
63     {
64         try
65         {
66                 MBeanServer mbs = SunoneInterceptor.getMBeanServerInstance();
67         GenericConfigurator genConf = new GenericConfigurator();
68         mbs.registerMBean(new GenConfigTestMBean("str1", 2), new ObjectName("ias:instance-name=ias1,component=orb")); //a server-instance
69
mbs.registerMBean(new GenConfigTestMBean("str3", 4), new ObjectName("ias:instance-name=ias1,component=test")); //a server-instance
70
// mbs.registerMBean(genConf, new ObjectName("ias:type=configurator")); //a server-instance
71

72             AttributeList attrList = genConf.getGenericAttributes(new String JavaDoc[]{"server.ias1.orb.name","server.ias1.orb.port","server.ias1.orb.*"});
73 // AttributeList attrList = genConf.getGenericAttributes(new String[]{"server.ias1.*.*"});
74
Iterator it = attrList.iterator();
75       while (it.hasNext())
76         {
77           Attribute attribute = (Attribute) it.next();
78           String JavaDoc name = attribute.getName();
79           Object JavaDoc value = attribute.getValue();
80           System.out.println("Attribute name="+name+" value="+value);
81         }
82         }
83         catch(Throwable JavaDoc e)
84         {
85             e.printStackTrace();
86         }
87     }
88   public class GenConfigTestMBean extends AdminBase
89   {
90     int mInt;
91     String JavaDoc mStr;
92     public GenConfigTestMBean(String JavaDoc strVal, int intVal)
93     {
94       mStr = strVal;
95       mInt = intVal;
96     }
97     public Object JavaDoc getAttribute(String JavaDoc attributeName) throws
98                    AttributeNotFoundException, MBeanException, ReflectionException
99     {
100 System.out.println("TEST:getAttribute("+attributeName+")");
101       if(attributeName.equals("port"))
102          return new Integer JavaDoc(mInt);
103       if(attributeName.equals("name"))
104          return mStr;
105 System.out.println("TEST:getAttribute("+attributeName+") pt2");
106       throw new AttributeNotFoundException();
107     }
108
109     public AttributeList getAttributes(String JavaDoc[] attributeNames)
110     {
111         String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.test.getattributes_not_implemented" );
112         throw new UnsupportedOperationException JavaDoc( msg );
113     }
114
115     /**
116         Every resource MBean should override this method to execute specific
117         operations on the MBean.
118     */

119     public Object JavaDoc invoke(String JavaDoc methodName, Object JavaDoc[] methodParams,
120         String JavaDoc[] methodSignature) throws MBeanException, ReflectionException
121     {
122         return null;
123     }
124
125     public void setAttribute(Attribute attribute) throws
126         AttributeNotFoundException, InvalidAttributeValueException,
127         MBeanException, ReflectionException
128     {
129         String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.test.setattributes_not_implemented" );
130         throw new UnsupportedOperationException JavaDoc( msg );
131     }
132
133     public AttributeList setAttributes(AttributeList parm1)
134     {
135         String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.test.setattributes_not_implemented" );
136         throw new UnsupportedOperationException JavaDoc( msg );
137     }
138
139     //***************************************************
140
//static MBean attributes and opeartions descriptions
141
String JavaDoc[] mAttrs =
142         {
143           "name, String, RW",
144           "port, int, RW",
145         };
146     String JavaDoc[] mOpers = new String JavaDoc[0];
147     
148       /** Implementation of <code>getMBeanInfo()</code>
149           Uses helper class <code>MBeanEasyConfig</code> to construct whole MBeanXXXInfo tree.
150           @return <code>MBeanInfo</code> objects containing full MBean description.
151       */

152       public MBeanInfo getMBeanInfo()
153       {
154       
155         try
156           {
157             return (new MBeanEasyConfig(getClass(), mAttrs, mOpers, null)).getMBeanInfo();
158           }
159         catch(Exception JavaDoc e)
160           {
161             System.out.println("++++++++++++++++++++E X C E P T I O N+++++++++++++++++++++++++ getMBeanInfo():Exception:"+e);
162             e.printStackTrace();
163             return null;
164           }
165       }
166           
167           /** Abstract method that subclasses have to implement. This is the way for
168            * invoke method to work, through reflection.
169            */

170           protected Class JavaDoc getImplementingClass() {
171               return (this.getClass());
172           }
173           
174           /** Every resource MBean should override this method to execute specific
175            * operations on the MBean. This method is enhanced in 8.0. It was a no-op
176            * in 7.0. In 8.0, it is modified to invoke the actual method through
177            * reflection.
178            * @since 8.0
179            * @see javax.management.MBeanServer#invoke
180            * @see #getImplementingClass
181            */

182           protected Object JavaDoc getImplementingMBean() {
183               return ( this );
184           }
185           
186  }
187  
188 }
189
Popular Tags