KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ejb > EJBObjectIDGenerator


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6 package org.jfox.ejb;
7
8 import org.jfox.ioc.util.ObjectUUID;
9
10 /**
11  * 生成唯一的 ObjectID
12  *
13  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
14  */

15
16 public class EJBObjectIDGenerator {
17     private String JavaDoc ejbName;
18     private String JavaDoc homeInterf;
19     private String JavaDoc remoteInterf;
20     private ObjectUUID homeUUID;
21
22
23     private EJBObjectIDGenerator(String JavaDoc ejbName, String JavaDoc homeIntef, String JavaDoc remoteInterf) {
24         this.ejbName = ejbName;
25         this.homeInterf = homeIntef;
26         this.remoteInterf = remoteInterf;
27         this.homeUUID = ObjectUUID.randomUUID();
28     }
29
30     /**
31      * @param homeInterf Bean 的类名
32      * @return
33      */

34     public static EJBObjectIDGenerator newInstance(String JavaDoc ejbName, String JavaDoc homeInterf, String JavaDoc remoteInterf) {
35         return new EJBObjectIDGenerator(ejbName, homeInterf, remoteInterf);
36     }
37
38     public EJBObjectId getHomeObjectId() {
39         return new EJBObjectId(ejbName, homeInterf, remoteInterf, homeUUID, true);
40     }
41
42     public EJBObjectId nextBeanObjectId() {
43         return new EJBObjectId(ejbName, homeInterf, remoteInterf, ObjectUUID.randomUUID(), false);
44     }
45
46     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
47         EJBObjectIDGenerator oig = EJBObjectIDGenerator.newInstance("ejb/test", "org.jfox.TestHome", "org.jfox.Test");
48         System.out.println(oig.getHomeObjectId());
49         System.out.println(oig.nextBeanObjectId());
50         oig = EJBObjectIDGenerator.newInstance("ejb/test", "org.jfox.TestHome", "org.jfox.Test");
51         System.out.println(oig.getHomeObjectId());
52         System.out.println(oig.nextBeanObjectId());
53
54     }
55 }
56
Popular Tags