KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > server > plugins > mode > Mode


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.server.plugins.mode;
10
11 import java.io.Serializable JavaDoc;
12
13 /**
14  * The mode similar to javax.portlet.PortletMode.
15  *
16  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
17  * @version $Revision: 1.1.1.1 $
18  */

19 public class Mode implements Serializable JavaDoc
20 {
21
22    public static final Mode EDIT = new Mode("edit");
23    public static final Mode HELP = new Mode("help");
24    public static final Mode VIEW = new Mode("view");
25
26    private String JavaDoc name;
27
28    public Mode(String JavaDoc name)
29    {
30       if (name == null)
31       {
32          throw new NullPointerException JavaDoc();
33       }
34       this.name = name.toLowerCase();
35    }
36
37    public boolean equals(Object JavaDoc o)
38    {
39       if (o instanceof Mode)
40       {
41          return o == this || name.equals(((Mode)o).name);
42       }
43       return false;
44    }
45
46    public int hashCode()
47    {
48       return name.hashCode();
49    }
50
51    public String JavaDoc toString()
52    {
53       return name;
54    }
55
56    private Object JavaDoc readResolve()
57    {
58       if (VIEW.name.equals(name))
59       {
60          return VIEW;
61       }
62       else if (EDIT.name.equals(name))
63       {
64          return EDIT;
65       }
66       else if (HELP.name.equals(name))
67       {
68          return HELP;
69       }
70       else
71       {
72          return this;
73       }
74    }
75
76    public static Mode create(String JavaDoc s)
77    {
78       if (Mode.EDIT.toString().equalsIgnoreCase(s))
79       {
80          return Mode.EDIT;
81       }
82       else if (Mode.HELP.toString().equalsIgnoreCase(s))
83       {
84          return Mode.HELP;
85       }
86       else if (Mode.VIEW.toString().equalsIgnoreCase(s))
87       {
88          return Mode.VIEW;
89       }
90       else
91       {
92          return new Mode(s);
93       }
94    }
95 }
96
Popular Tags