01: /*
02: * poker
03: *
04: * Enhydra super-servlet specification object
05: *
06: */
07: package poker.spec;
08:
09: import java.lang.reflect.Constructor;
10:
11: public class PokerGameFactory {
12:
13: /**
14: * Constructor can't be used.
15: */
16: private PokerGameFactory() {
17: }
18:
19: /**
20: * Create a PokerGame as state object/value object/data transfer object
21: */
22: public static PokerGame getPokerGame(String fullClassName) {
23:
24: PokerGame result = null;
25:
26: Class objectClass = null;
27:
28: try {
29: // Create the value object
30:
31: objectClass = Class.forName(fullClassName);
32:
33: result = (PokerGame) objectClass.newInstance();
34:
35: } catch (Exception ex) {
36: System.out.println("Error on creating the object" + ex);
37: }
38:
39: return result;
40: }
41:
42: /**
43: * Create a PokerGame as state object/value object/data transfer object
44: */
45: public static PokerGame getPokerGame(String fullClassName,
46: String username, String pw, String id, int cash) {
47:
48: PokerGame result = null;
49:
50: Class objectClass = null;
51:
52: try {
53: // Create the value object
54:
55: objectClass = Class.forName(fullClassName);
56:
57: Class[] parameterTypes = new Class[4];
58:
59: parameterTypes[0] = String.class;
60: parameterTypes[1] = String.class;
61: parameterTypes[2] = String.class;
62: parameterTypes[3] = int.class;
63:
64: Constructor constr = objectClass
65: .getConstructor(parameterTypes);
66:
67: Object[] objects = new Object[4];
68: objects[0] = username;
69: objects[1] = pw;
70: objects[2] = id;
71: objects[3] = new Integer(cash);
72:
73: Object obj = constr.newInstance(objects);
74:
75: return (PokerGame) obj;
76:
77: } catch (Exception ex) {
78: System.out.println("Error on creating the object" + ex);
79: }
80:
81: return result;
82: }
83:
84: }
|