1 17 18 package org.apache.geronimo.kernel; 19 20 import java.lang.reflect.InvocationTargetException ; 21 import java.util.Collection ; 22 import java.util.Collections ; 23 import java.util.Iterator ; 24 25 import org.apache.geronimo.gbean.GBeanInfo; 26 import org.apache.geronimo.gbean.GBeanInfoBuilder; 27 28 31 public class MockGBean implements MockEndpoint, MockParentInterface1, MockParentInterface2, MockChildInterface1, MockChildInterface2 { 32 33 private static final GBeanInfo GBEAN_INFO; 34 35 private String objectName; 36 37 private ClassLoader classLoader; 38 39 private Kernel kernel; 40 41 private final String name; 42 43 private final int finalInt; 44 45 private int mutableInt; 46 47 private int exceptionMutableInt; 48 49 private String value; 50 51 private Object someObject; 52 53 private MockEndpoint endpoint; 54 55 private Collection endpointCollection = Collections.EMPTY_SET; 56 57 public static GBeanInfo getGBeanInfo() { 58 return GBEAN_INFO; 59 } 60 61 static { 62 GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(MockGBean.class); 63 infoFactory.addAttribute("name", String .class, true); 64 infoFactory.addAttribute("actualObjectName", String .class, false); 65 infoFactory.addAttribute("objectName", String .class, false); 66 infoFactory.addAttribute("actualClassLoader", ClassLoader .class, false); 67 infoFactory.addAttribute("classLoader", ClassLoader .class, false); 68 infoFactory.addAttribute("actualKernel", Kernel.class, false); 69 infoFactory.addAttribute("kernel", Kernel.class, false); 70 infoFactory.addAttribute("value", String .class, true); 71 infoFactory.addAttribute("finalInt", Integer.TYPE, true); 72 infoFactory.addAttribute("mutableInt", Integer.TYPE, false); 73 infoFactory.addAttribute("exceptionMutableInt", Integer.TYPE, true); 74 infoFactory.addAttribute("endpointMutableInt", Integer.TYPE, false); 75 infoFactory.addAttribute("someObject", Object .class, true); 76 77 infoFactory.addOperation("echo", new Class []{String .class}, "java.lang.Object"); 78 infoFactory.addOperation("checkEndpoint", "java.lang.Object"); 79 infoFactory.addOperation("checkEndpointCollection", "java.lang.Object"); 80 infoFactory.addOperation("doSomething", new Class []{String .class}, "java.lang.Object"); 81 infoFactory.addOperation("fetchValue", "java.lang.Object"); 82 83 infoFactory.addInterface(MockEndpoint.class, new String []{"mutableInt"}); 84 infoFactory.addInterface(MockParentInterface1.class, new String []{"value"}); 85 infoFactory.addInterface(MockParentInterface2.class, new String []{"value"}); 86 infoFactory.addInterface(MockChildInterface1.class, new String []{"finalInt"}); 87 infoFactory.addInterface(MockChildInterface2.class, new String []{}); 88 89 infoFactory.addReference("MockEndpoint", MockEndpoint.class, null); 90 infoFactory.addReference("EndpointCollection", MockEndpoint.class, null); 91 92 infoFactory.setConstructor(new String []{"name", "finalInt", "objectName", "classLoader", "kernel"}); 93 94 GBEAN_INFO = infoFactory.getBeanInfo(); 95 } 96 97 public MockGBean() { name = null; 99 finalInt = 0; 100 } 101 102 public MockGBean(String name, int finalInt) { 103 this.name = name; 104 this.finalInt = finalInt; 105 } 106 107 public MockGBean(String name, int finalInt, String objectName, ClassLoader classLoader, Kernel kernel) { 108 this.name = name; 109 this.finalInt = finalInt; 110 this.objectName = objectName; 111 this.classLoader = classLoader; 112 this.kernel = kernel; 113 } 114 115 public Object getSomeObject() { 116 return someObject; 117 } 118 119 public void setSomeObject(Object someObject) { 120 this.someObject = someObject; 121 } 122 123 public String getActualObjectName() { 124 return objectName; 125 } 126 127 public String getObjectName() { 128 return objectName; 129 } 130 131 public ClassLoader getActualClassLoader() { 132 return classLoader; 133 } 134 135 public ClassLoader getClassLoader() { 136 return classLoader; 137 } 138 139 public Kernel getActualKernel() { 140 return kernel; 141 } 142 143 public Kernel getKernel() { 144 return kernel; 145 } 146 147 public void setKernel(Kernel kernel) { 148 this.kernel = kernel; 149 } 150 151 public String getName() { 152 return name; 153 } 154 155 public void doNothing() { 156 } 157 158 public String echo(String msg) { 159 return msg; 160 } 161 162 public int getFinalInt() { 163 return finalInt; 164 } 165 166 169 public void setAnotherFinalInt(int ignored) { 170 } 171 172 175 public void setYetAnotherFinalInt(int ignored) { 176 } 177 178 181 public void setCharAsYetAnotherFinalInt(char yetAnotherFinalInt) { 182 setYetAnotherFinalInt((int) yetAnotherFinalInt); 183 } 184 185 188 public void setBooleanAsYetAnotherFinalInt(boolean yetAnotherFinalInt) { 189 setYetAnotherFinalInt((yetAnotherFinalInt ? 1 : 0)); 190 } 191 192 195 public void setByteAsYetAnotherFinalInt(byte yetAnotherFinalInt) { 196 setYetAnotherFinalInt(yetAnotherFinalInt); 197 } 198 199 202 public void setShortAsYetAnotherFinalInt(short yetAnotherFinalInt) { 203 setYetAnotherFinalInt(yetAnotherFinalInt); 204 } 205 206 209 public void setLongAsYetAnotherFinalInt(long yetAnotherFinalInt) { 210 setYetAnotherFinalInt((int) yetAnotherFinalInt); 211 } 212 213 216 public void setFloatAsYetAnotherFinalInt(float yetAnotherFinalInt) { 217 setYetAnotherFinalInt((int) yetAnotherFinalInt); 218 } 219 220 223 public void setDoubleAsYetAnotherFinalInt(double yetAnotherFinalInt) { 224 setYetAnotherFinalInt((int) yetAnotherFinalInt); 225 } 226 227 230 public void getVoidGetterOfFinalInt() { 231 } 232 233 public int getMutableInt() { 234 return mutableInt; 235 } 236 237 public void doSetMutableInt(int mutableInt) { 238 setMutableInt(mutableInt); 239 } 240 241 public void setMutableInt(int mutableInt) { 242 this.mutableInt = mutableInt; 243 } 244 245 public String getValue() { 246 return value; 247 } 248 249 public String fetchValue() { 250 return value; 251 } 252 253 public void setValue(String value) { 254 this.value = value; 255 } 256 257 public void setExceptionMutableInt(int exceptionMutableInt) throws InvocationTargetException { 258 this.exceptionMutableInt = exceptionMutableInt; 259 if (exceptionMutableInt == -1) { 260 throw new InvocationTargetException (new Exception ("Thrown when -1")); 261 } 262 if (exceptionMutableInt == -2) { 263 throw new InvocationTargetException (new Error ("Thrown when -2")); 264 } 265 if (exceptionMutableInt == -3) { 266 throw new InvocationTargetException (new Throwable ("Thrown when -3")); 267 } 268 } 269 270 public int getExceptionMutableInt() throws InvocationTargetException { 271 if (this.exceptionMutableInt == -1) { 272 throw new InvocationTargetException (new Exception ("Thrown when -1")); 273 } 274 if (this.exceptionMutableInt == -2) { 275 throw new InvocationTargetException (new Error ("Thrown when -2")); 276 } 277 if (exceptionMutableInt == -3) { 278 throw new InvocationTargetException (new Throwable ("Thrown when -3")); 279 } 280 return this.exceptionMutableInt; 281 } 282 283 public MockEndpoint getMockEndpoint() { 284 return endpoint; 285 } 286 287 public void setMockEndpoint(MockEndpoint endpoint) { 288 this.endpoint = endpoint; 289 } 290 291 public Collection getEndpointCollection() { 292 return endpointCollection; 293 } 294 295 public void setEndpointCollection(Collection endpointCollection) { 296 this.endpointCollection = endpointCollection; 297 } 298 299 public String doSomething(String name) { 300 return name; 301 } 302 303 public String endpointDoSomething(String name) { 304 return name; 305 } 306 307 public String checkEndpoint() { 308 if (endpoint == null) { 309 return "no endpoint"; 310 } 311 return endpoint.endpointDoSomething("endpointCheck"); 312 } 313 314 public int checkEndpointCollection() { 315 int successCount = 0; 316 for (Iterator iterator = endpointCollection.iterator(); iterator.hasNext();) { 317 MockEndpoint mockEndpoint = (MockEndpoint) iterator.next(); 318 String result = mockEndpoint.endpointDoSomething("endpointCheck"); 319 if ("endpointCheck".equals(result)) { 320 successCount++; 321 } 322 } 323 return successCount; 324 } 325 326 public int getEndpointMutableInt() { 327 return endpoint.getMutableInt(); 328 } 329 330 public void setEndpointMutableInt(int mutableInt) { 331 endpoint.setMutableInt(mutableInt); 332 } 333 } 334 | Popular Tags |