001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.kernel;
017:
018: import java.lang.reflect.InvocationTargetException;
019: import java.util.Collection;
020: import java.util.Collections;
021: import java.util.Iterator;
022:
023: import org.apache.geronimo.gbean.GBeanInfo;
024: import org.apache.geronimo.gbean.GBeanInfoBuilder;
025:
026: /**
027: * @version $Rev: 487505 $ $Date: 2006-12-15 02:00:35 -0800 (Fri, 15 Dec 2006) $
028: */
029: public class MockGBean implements MockEndpoint, MockParentInterface1,
030: MockParentInterface2, MockChildInterface1, MockChildInterface2 {
031:
032: private static final GBeanInfo GBEAN_INFO;
033:
034: private String objectName;
035:
036: private ClassLoader classLoader;
037:
038: private Kernel kernel;
039:
040: private final String name;
041:
042: private final int finalInt;
043:
044: private int mutableInt;
045:
046: private int exceptionMutableInt;
047:
048: private String value;
049:
050: private Object someObject;
051:
052: private MockEndpoint endpoint;
053:
054: private Collection endpointCollection = Collections.EMPTY_SET;
055:
056: public static GBeanInfo getGBeanInfo() {
057: return GBEAN_INFO;
058: }
059:
060: static {
061: GBeanInfoBuilder infoFactory = GBeanInfoBuilder
062: .createStatic(MockGBean.class);
063: infoFactory.addAttribute("name", String.class, true);
064: infoFactory.addAttribute("actualObjectName", String.class,
065: false);
066: infoFactory.addAttribute("objectName", String.class, false);
067: infoFactory.addAttribute("actualClassLoader",
068: ClassLoader.class, false);
069: infoFactory.addAttribute("classLoader", ClassLoader.class,
070: false);
071: infoFactory.addAttribute("actualKernel", Kernel.class, false);
072: infoFactory.addAttribute("kernel", Kernel.class, false);
073: infoFactory.addAttribute("value", String.class, true);
074: infoFactory.addAttribute("finalInt", Integer.TYPE, true);
075: infoFactory.addAttribute("mutableInt", Integer.TYPE, false);
076: infoFactory.addAttribute("exceptionMutableInt", Integer.TYPE,
077: true);
078: infoFactory.addAttribute("endpointMutableInt", Integer.TYPE,
079: false);
080: infoFactory.addAttribute("someObject", Object.class, true);
081:
082: infoFactory.addOperation("echo", new Class[] { String.class });
083: infoFactory.addOperation("checkEndpoint");
084: infoFactory.addOperation("checkEndpointCollection");
085: infoFactory.addOperation("doSomething",
086: new Class[] { String.class });
087: infoFactory.addOperation("fetchValue");
088:
089: infoFactory.addInterface(MockEndpoint.class,
090: new String[] { "mutableInt" });
091: infoFactory.addInterface(MockParentInterface1.class,
092: new String[] { "value" });
093: infoFactory.addInterface(MockParentInterface2.class,
094: new String[] { "value" });
095: infoFactory.addInterface(MockChildInterface1.class,
096: new String[] { "finalInt" });
097: infoFactory.addInterface(MockChildInterface2.class,
098: new String[] {});
099:
100: infoFactory.addReference("MockEndpoint", MockEndpoint.class,
101: null);
102: infoFactory.addReference("EndpointCollection",
103: MockEndpoint.class, null);
104:
105: infoFactory.setConstructor(new String[] { "name", "finalInt",
106: "objectName", "classLoader", "kernel" });
107:
108: GBEAN_INFO = infoFactory.getBeanInfo();
109: }
110:
111: public MockGBean() { // present so we can test creating a class-based proxy
112: name = null;
113: finalInt = 0;
114: }
115:
116: public MockGBean(String name, int finalInt) {
117: this .name = name;
118: this .finalInt = finalInt;
119: }
120:
121: public MockGBean(String name, int finalInt, String objectName,
122: ClassLoader classLoader, Kernel kernel) {
123: this .name = name;
124: this .finalInt = finalInt;
125: this .objectName = objectName;
126: this .classLoader = classLoader;
127: this .kernel = kernel;
128: }
129:
130: public Object getSomeObject() {
131: return someObject;
132: }
133:
134: public void setSomeObject(Object someObject) {
135: this .someObject = someObject;
136: }
137:
138: public String getActualObjectName() {
139: return objectName;
140: }
141:
142: public String getObjectName() {
143: return objectName;
144: }
145:
146: public ClassLoader getActualClassLoader() {
147: return classLoader;
148: }
149:
150: public ClassLoader getClassLoader() {
151: return classLoader;
152: }
153:
154: public Kernel getActualKernel() {
155: return kernel;
156: }
157:
158: public Kernel getKernel() {
159: return kernel;
160: }
161:
162: public void setKernel(Kernel kernel) {
163: this .kernel = kernel;
164: }
165:
166: public String getName() {
167: return name;
168: }
169:
170: public void doNothing() {
171: }
172:
173: public String echo(String msg) {
174: return msg;
175: }
176:
177: public int getFinalInt() {
178: return finalInt;
179: }
180:
181: /**
182: * Parameter ignored
183: */
184: public void setAnotherFinalInt(int ignored) {
185: }
186:
187: /**
188: * Only setter for YetAnotherFinalInt
189: */
190: public void setYetAnotherFinalInt(int ignored) {
191: }
192:
193: /**
194: * @see #setYetAnotherFinalInt(int)
195: */
196: public void setCharAsYetAnotherFinalInt(char yetAnotherFinalInt) {
197: setYetAnotherFinalInt((int) yetAnotherFinalInt);
198: }
199:
200: /**
201: * @see #setYetAnotherFinalInt(int)
202: */
203: public void setBooleanAsYetAnotherFinalInt(
204: boolean yetAnotherFinalInt) {
205: setYetAnotherFinalInt((yetAnotherFinalInt ? 1 : 0));
206: }
207:
208: /**
209: * @see #setYetAnotherFinalInt(int)
210: */
211: public void setByteAsYetAnotherFinalInt(byte yetAnotherFinalInt) {
212: setYetAnotherFinalInt(yetAnotherFinalInt);
213: }
214:
215: /**
216: * @see #setYetAnotherFinalInt(int)
217: */
218: public void setShortAsYetAnotherFinalInt(short yetAnotherFinalInt) {
219: setYetAnotherFinalInt(yetAnotherFinalInt);
220: }
221:
222: /**
223: * @see #setYetAnotherFinalInt(int)
224: */
225: public void setLongAsYetAnotherFinalInt(long yetAnotherFinalInt) {
226: setYetAnotherFinalInt((int) yetAnotherFinalInt);
227: }
228:
229: /**
230: * @see #setYetAnotherFinalInt(int)
231: */
232: public void setFloatAsYetAnotherFinalInt(float yetAnotherFinalInt) {
233: setYetAnotherFinalInt((int) yetAnotherFinalInt);
234: }
235:
236: /**
237: * @see #setYetAnotherFinalInt(int)
238: */
239: public void setDoubleAsYetAnotherFinalInt(double yetAnotherFinalInt) {
240: setYetAnotherFinalInt((int) yetAnotherFinalInt);
241: }
242:
243: /**
244: * Getter that returns nothing
245: */
246: public void getVoidGetterOfFinalInt() {
247: }
248:
249: public int getMutableInt() {
250: return mutableInt;
251: }
252:
253: public void doSetMutableInt(int mutableInt) {
254: setMutableInt(mutableInt);
255: }
256:
257: public void setMutableInt(int mutableInt) {
258: this .mutableInt = mutableInt;
259: }
260:
261: public String getValue() {
262: return value;
263: }
264:
265: public String fetchValue() {
266: return value;
267: }
268:
269: public void setValue(String value) {
270: this .value = value;
271: }
272:
273: public void setExceptionMutableInt(int exceptionMutableInt)
274: throws InvocationTargetException {
275: this .exceptionMutableInt = exceptionMutableInt;
276: if (exceptionMutableInt == -1) {
277: throw new InvocationTargetException(new Exception(
278: "Thrown when -1"));
279: }
280: if (exceptionMutableInt == -2) {
281: throw new InvocationTargetException(new Error(
282: "Thrown when -2"));
283: }
284: if (exceptionMutableInt == -3) {
285: throw new InvocationTargetException(new Throwable(
286: "Thrown when -3"));
287: }
288: }
289:
290: public int getExceptionMutableInt()
291: throws InvocationTargetException {
292: if (this .exceptionMutableInt == -1) {
293: throw new InvocationTargetException(new Exception(
294: "Thrown when -1"));
295: }
296: if (this .exceptionMutableInt == -2) {
297: throw new InvocationTargetException(new Error(
298: "Thrown when -2"));
299: }
300: if (exceptionMutableInt == -3) {
301: throw new InvocationTargetException(new Throwable(
302: "Thrown when -3"));
303: }
304: return this .exceptionMutableInt;
305: }
306:
307: public MockEndpoint getMockEndpoint() {
308: return endpoint;
309: }
310:
311: public void setMockEndpoint(MockEndpoint endpoint) {
312: this .endpoint = endpoint;
313: }
314:
315: public Collection getEndpointCollection() {
316: return endpointCollection;
317: }
318:
319: public void setEndpointCollection(Collection endpointCollection) {
320: this .endpointCollection = endpointCollection;
321: }
322:
323: public String doSomething(String name) {
324: return name;
325: }
326:
327: public String endpointDoSomething(String name) {
328: return name;
329: }
330:
331: public String checkEndpoint() {
332: if (endpoint == null) {
333: return "no endpoint";
334: }
335: return endpoint.endpointDoSomething("endpointCheck");
336: }
337:
338: public int checkEndpointCollection() {
339: int successCount = 0;
340: for (Iterator iterator = endpointCollection.iterator(); iterator
341: .hasNext();) {
342: MockEndpoint mockEndpoint = (MockEndpoint) iterator.next();
343: String result = mockEndpoint
344: .endpointDoSomething("endpointCheck");
345: if ("endpointCheck".equals(result)) {
346: successCount++;
347: }
348: }
349: return successCount;
350: }
351:
352: public int getEndpointMutableInt() {
353: return endpoint.getMutableInt();
354: }
355:
356: public void setEndpointMutableInt(int mutableInt) {
357: endpoint.setMutableInt(mutableInt);
358: }
359: }
|