01: /*
02: * Copyright (C) 2007 XStream Committers.
03: * All rights reserved.
04: *
05: * The software in this package is published under the terms of the BSD
06: * style license a copy of which has been included with this distribution in
07: * the LICENSE.txt file.
08: *
09: * Created on 06. September 2007 by Joerg Schaible
10: */
11: package com.thoughtworks.xstream.benchmark.reflection.targets;
12:
13: import com.thoughtworks.xstream.benchmark.reflection.model.A50InnerClasses;
14: import com.thoughtworks.xstream.tools.benchmark.Target;
15:
16: import java.lang.reflect.Constructor;
17: import java.lang.reflect.InvocationTargetException;
18: import java.util.ArrayList;
19: import java.util.List;
20:
21: /**
22: * A Target for multiple hierarchy level classes.
23: *
24: * @author Jörg Schaible
25: * @see com.thoughtworks.xstream.tools.benchmark.Harness
26: * @see Target
27: */
28: public class InnerClassesReflection extends AbstractReflectionTarget {
29:
30: public InnerClassesReflection() {
31: super (new ArrayList());
32: for (int i = 0; i < 10; ++i) {
33: List list = new ArrayList();
34: list.add(new A50InnerClasses());
35: StringBuffer name = new StringBuffer(A50InnerClasses.class
36: .getName());
37: for (int j = 0; j < 50; ++j) {
38: String no = "0" + j;
39: Object parent = list.get(j);
40: name.append("$L");
41: name.append(no.substring(no.length() - 2));
42: try {
43: Class cls = Class.forName(name.toString());
44: Constructor ctor = cls
45: .getDeclaredConstructor(new Class[] { parent
46: .getClass() });
47: Object o = ctor
48: .newInstance(new Object[] { parent });
49: fill(o);
50: list.add(o);
51: } catch (ClassNotFoundException e) {
52: throw new RuntimeException(e);
53: } catch (InstantiationException e) {
54: throw new RuntimeException(e);
55: } catch (IllegalAccessException e) {
56: throw new RuntimeException(e);
57: } catch (NoSuchMethodException e) {
58: throw new RuntimeException(e);
59: } catch (InvocationTargetException e) {
60: throw new RuntimeException(e);
61: }
62: }
63: list.remove(0);
64: ((List) target()).addAll(list);
65: }
66: }
67:
68: public String toString() {
69: return "InnerClasses Target";
70: }
71:
72: }
|