KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > poker > spec > PokerGameFactory


1 /*
2  * poker
3  *
4  * Enhydra super-servlet specification object
5  *
6  */

7 package poker.spec;
8
9 import java.lang.reflect.Constructor JavaDoc;
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 JavaDoc fullClassName) {
23         
24         PokerGame result = null;
25        
26         Class JavaDoc objectClass = null;
27
28         try {
29             // Create the value object
30

31       
32          objectClass = Class.forName(fullClassName);
33                                    
34           result = (PokerGame)objectClass.newInstance();
35                
36                        
37                     
38       } catch (Exception JavaDoc ex) {
39             System.out.println("Error on creating the object" + ex);
40         }
41
42         return result;
43     }
44
45    /**
46      * Create a PokerGame as state object/value object/data transfer object
47      */

48   public static PokerGame getPokerGame(String JavaDoc fullClassName,String JavaDoc username,String JavaDoc pw,String JavaDoc id,int cash) {
49         
50         PokerGame result = null;
51        
52         Class JavaDoc objectClass = null;
53
54         try {
55             // Create the value object
56

57          objectClass = Class.forName(fullClassName);
58                     
59          Class JavaDoc[] parameterTypes =new Class JavaDoc[4];
60          
61          parameterTypes[0]= String JavaDoc.class;
62          parameterTypes[1]= String JavaDoc.class;
63          parameterTypes[2]= String JavaDoc.class;
64          parameterTypes[3]= int.class;
65        
66          Constructor JavaDoc constr = objectClass.getConstructor(parameterTypes);
67          
68         
69          
70         Object JavaDoc[] objects = new Object JavaDoc[4];
71         objects[0]=username;
72         objects[1]=pw;
73         objects[2]=id;
74         objects[3]=new Integer JavaDoc(cash);
75       
76         Object JavaDoc obj = constr.newInstance(objects);
77       
78        return (PokerGame)obj;
79         
80         
81                        
82                     
83       } catch (Exception JavaDoc ex) {
84             System.out.println("Error on creating the object" + ex);
85         }
86
87         return result;
88     }
89
90
91
92
93
94
95
96
97 }
Popular Tags