1
2
3
4
5
6 package net.sf.beanrunner.factory.impl;
7
8
9 import java.lang.reflect.Constructor;
10 import java.lang.reflect.InvocationTargetException;
11 import java.util.Collection;
12
13 import net.sf.beanrunner.factory.AbstractInstanceFactory;
14
15 public class NumberInstanceFactory extends AbstractInstanceFactory
16 {
17
18 public NumberInstanceFactory(Class number, Number minValue, Number maxValue)
19 {
20 type = number;
21 min = minValue;
22 max = maxValue;
23 }
24
25 protected void initCollection(Collection collection)
26 {
27 try
28 {
29 Constructor constructor = type.getConstructor(new Class[] {
30 java.lang.String.class
31 });
32 zero = (Number)constructor.newInstance(new Object[] {
33 "0"
34 });
35 one = (Number)constructor.newInstance(new Object[] {
36 "1"
37 });
38 minusOne = (Number)constructor.newInstance(new Object[] {
39 "-1"
40 });
41 theAnswer = (Number)constructor.newInstance(new Object[] {
42 "42"
43 });
44 }
45 catch(SecurityException e)
46 {
47 e.printStackTrace();
48 }
49 catch(NoSuchMethodException e)
50 {
51 e.printStackTrace();
52 }
53 catch(IllegalArgumentException e)
54 {
55 e.printStackTrace();
56 }
57 catch(InstantiationException e)
58 {
59 e.printStackTrace();
60 }
61 catch(IllegalAccessException e)
62 {
63 e.printStackTrace();
64 }
65 catch(InvocationTargetException e)
66 {
67 e.printStackTrace();
68 }
69 collection.add(zero);
70 collection.add(theAnswer);
71 collection.add(one);
72 collection.add(minusOne);
73 collection.add(min);
74 collection.add(max);
75 }
76
77 private Class type;
78 private Number min;
79 private Number max;
80 private Number zero;
81 private Number one;
82 private Number minusOne;
83 private Number theAnswer;
84 }