KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > EntityMode


1 // $Id: EntityMode.java,v 1.2 2005/02/12 07:19:50 steveebersole Exp $
2
package org.hibernate;
3
4 import java.util.Map JavaDoc;
5 import java.util.HashMap JavaDoc;
6 import java.io.Serializable JavaDoc;
7
8 /**
9  * Defines the representation modes available for entities.
10  *
11  * @author Steve Ebersole
12  */

13 public class EntityMode implements Serializable JavaDoc {
14
15     private static final Map JavaDoc INSTANCES = new HashMap JavaDoc();
16
17     public static final EntityMode POJO = new EntityMode( "pojo" );
18     public static final EntityMode DOM4J = new EntityMode( "dom4j" );
19     public static final EntityMode MAP = new EntityMode( "dynamic-map" );
20
21     static {
22         INSTANCES.put( POJO.name, POJO );
23         INSTANCES.put( DOM4J.name, DOM4J );
24         INSTANCES.put( MAP.name, MAP );
25     }
26
27     private final String JavaDoc name;
28
29     public EntityMode(String JavaDoc name) {
30         this.name = name;
31     }
32
33     public String JavaDoc toString() {
34         return name;
35     }
36
37     private Object JavaDoc readResolve() {
38         return INSTANCES.get( name );
39     }
40
41     public static EntityMode parse(String JavaDoc name) {
42         EntityMode rtn = ( EntityMode ) INSTANCES.get( name );
43         if ( rtn == null ) {
44             // default is POJO
45
rtn = POJO;
46         }
47         return rtn;
48     }
49 }
50
Popular Tags