1 9 package org.jboss.portal.server.plugins.mode; 10 11 import java.io.Serializable ; 12 13 19 public class Mode implements Serializable 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 name; 27 28 public Mode(String name) 29 { 30 if (name == null) 31 { 32 throw new NullPointerException (); 33 } 34 this.name = name.toLowerCase(); 35 } 36 37 public boolean equals(Object 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 toString() 52 { 53 return name; 54 } 55 56 private Object 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 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 |