1 23 24 package com.sun.enterprise.admin.server.core.mbean.test; 25 26 import java.io.*; 28 import java.util.*; 29 30 import javax.management.*; 32 33 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 import com.sun.enterprise.util.i18n.StringManager; 43 44 public class GenericConfiguratorTest 45 { 46 47 48 private static StringManager localStrings = 50 StringManager.getManager( GenericConfiguratorTest.class ); 51 52 55 56 public static void main (String 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")); mbs.registerMBean(new GenConfigTestMBean("str3", 4), new ObjectName("ias:instance-name=ias1,component=test")); 72 AttributeList attrList = genConf.getGenericAttributes(new String []{"server.ias1.orb.name","server.ias1.orb.port","server.ias1.orb.*"}); 73 Iterator it = attrList.iterator(); 75 while (it.hasNext()) 76 { 77 Attribute attribute = (Attribute) it.next(); 78 String name = attribute.getName(); 79 Object value = attribute.getValue(); 80 System.out.println("Attribute name="+name+" value="+value); 81 } 82 } 83 catch(Throwable e) 84 { 85 e.printStackTrace(); 86 } 87 } 88 public class GenConfigTestMBean extends AdminBase 89 { 90 int mInt; 91 String mStr; 92 public GenConfigTestMBean(String strVal, int intVal) 93 { 94 mStr = strVal; 95 mInt = intVal; 96 } 97 public Object getAttribute(String attributeName) throws 98 AttributeNotFoundException, MBeanException, ReflectionException 99 { 100 System.out.println("TEST:getAttribute("+attributeName+")"); 101 if(attributeName.equals("port")) 102 return new Integer (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 [] attributeNames) 110 { 111 String msg = localStrings.getString( "admin.server.core.mbean.test.getattributes_not_implemented" ); 112 throw new UnsupportedOperationException ( msg ); 113 } 114 115 119 public Object invoke(String methodName, Object [] methodParams, 120 String [] 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 msg = localStrings.getString( "admin.server.core.mbean.test.setattributes_not_implemented" ); 130 throw new UnsupportedOperationException ( msg ); 131 } 132 133 public AttributeList setAttributes(AttributeList parm1) 134 { 135 String msg = localStrings.getString( "admin.server.core.mbean.test.setattributes_not_implemented" ); 136 throw new UnsupportedOperationException ( msg ); 137 } 138 139 String [] mAttrs = 142 { 143 "name, String, RW", 144 "port, int, RW", 145 }; 146 String [] mOpers = new String [0]; 147 148 152 public MBeanInfo getMBeanInfo() 153 { 154 155 try 156 { 157 return (new MBeanEasyConfig(getClass(), mAttrs, mOpers, null)).getMBeanInfo(); 158 } 159 catch(Exception 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 170 protected Class getImplementingClass() { 171 return (this.getClass()); 172 } 173 174 182 protected Object getImplementingMBean() { 183 return ( this ); 184 } 185 186 } 187 188 } 189 | Popular Tags |