1 17 18 package org.apache.geronimo.connector; 19 20 import org.apache.geronimo.gbean.DynamicGBean; 21 import org.apache.geronimo.gbean.DynamicGBeanDelegate; 22 import org.apache.geronimo.gbean.AbstractName; 23 import org.apache.geronimo.kernel.Kernel; 24 import org.apache.geronimo.management.geronimo.JCAAdminObject; 25 26 import java.util.Map ; 27 import java.util.HashMap ; 28 import java.lang.reflect.Constructor ; 29 30 36 public class AdminObjectWrapper implements DynamicGBean, JCAAdminObject, AdminObjectSource { 37 38 private final String adminObjectInterface; 39 private final String adminObjectClass; 40 41 private final DynamicGBeanDelegate delegate; 42 private final Object adminObject; 43 44 45 private final Kernel kernel; 46 private final AbstractName abstractName; 47 private final String objectName; 48 49 52 public AdminObjectWrapper() { 53 adminObjectInterface = null; 54 adminObjectClass = null; 55 adminObject = null; 56 delegate = null; 57 kernel = null; 58 abstractName = null; 59 objectName = null; 60 } 61 62 70 public AdminObjectWrapper(final String adminObjectInterface, 71 final String adminObjectClass, 72 final Kernel kernel, 73 final AbstractName abstractName, 74 final String objectName, 75 final ClassLoader cl) throws IllegalAccessException , InstantiationException , ClassNotFoundException { 76 this.adminObjectInterface = adminObjectInterface; 77 this.adminObjectClass = adminObjectClass; 78 this.kernel = kernel; 79 this.abstractName = abstractName; 80 this.objectName = objectName; 81 Class clazz = cl.loadClass(adminObjectClass); 82 adminObject = clazz.newInstance(); 83 delegate = new DynamicGBeanDelegate(); 84 delegate.addAll(adminObject); 85 } 86 87 public String getAdminObjectInterface() { 88 return adminObjectInterface; 89 } 90 91 95 public String getAdminObjectClass() { 96 return adminObjectClass; 97 } 98 99 103 public Object $getResource() { 104 return adminObject; 105 } 106 107 108 110 116 public Object getAttribute(final String name) throws Exception { 117 return delegate.getAttribute(name); 118 } 119 120 126 public void setAttribute(final String name, final Object value) throws Exception { 127 delegate.setAttribute(name, value); 128 } 129 130 138 public Object invoke(final String name, final Object [] arguments, final String [] types) throws Exception { 139 return null; 141 } 142 143 147 public Map getConfigProperties() { 148 String [] props = delegate.getProperties(); 149 Map map = new HashMap (); 150 for (int i = 0; i < props.length; i++) { 151 String prop = props[i]; 152 if(prop.equals("logWriter")) { 153 continue; 154 } 155 map.put(prop, delegate.getPropertyType(prop)); 156 } 157 return map; 158 } 159 160 public void setConfigProperty(String property, Object value) throws Exception { 161 Class cls = delegate.getPropertyType(property); 162 if(value != null && value instanceof String && !cls.getName().equals("java.lang.String")) { 163 if(cls.isPrimitive()) { 164 if(cls.equals(int.class)) { 165 cls = Integer .class; 166 } else if(cls.equals(boolean.class)) { 167 cls = Boolean .class; 168 } else if(cls.equals(float.class)) { 169 cls = Float .class; 170 } else if(cls.equals(double.class)) { 171 cls = Double .class; 172 } else if(cls.equals(long.class)) { 173 cls = Long .class; 174 } else if(cls.equals(short.class)) { 175 cls = Short .class; 176 } else if(cls.equals(byte.class)) { 177 cls = Byte .class; 178 } else if(cls.equals(char.class)) { 179 cls = Character .class; 180 } 181 } 182 Constructor con = cls.getConstructor(new Class []{String .class}); 183 value = con.newInstance(new Object []{value}); 184 } 185 kernel.setAttribute(abstractName, property, value); 186 } 187 188 public Object getConfigProperty(String property) throws Exception { 189 return delegate.getAttribute(property); 190 } 191 192 public String getObjectName() { 193 return objectName; 194 } 195 196 public boolean isStateManageable() { 197 return false; 198 } 199 200 public boolean isStatisticsProvider() { 201 return false; 202 } 203 204 public boolean isEventProvider() { 205 return false; 206 } 207 } 208 | Popular Tags |