KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > portlet > admin > bean > PortletMessageType


1 /*
2  * Copyright 2003,2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.pluto.portlet.admin.bean;
17
18 /**
19  * Typesafe enum (pre-JDK 1.5) that represents a Portlet Message Type
20  *
21  * @author Craig Doremus
22  *
23  */

24 public class PortletMessageType {
25
26     public static PortletMessageType INFO = new PortletMessageType("info", "portlet-msg-info");
27     public static PortletMessageType ERROR = new PortletMessageType("error", "portlet-msg-error");
28     public static PortletMessageType STATUS = new PortletMessageType("status", "portlet-msg-status");
29     public static PortletMessageType ALERT = new PortletMessageType("alert", "portlet-msg-alert");
30     public static PortletMessageType SUCCESS = new PortletMessageType("success", "portlet-msg-success");
31
32     public String JavaDoc name = null;
33     public String JavaDoc CssClass = null;
34
35     /**
36      *
37      */

38     private PortletMessageType(String JavaDoc name, String JavaDoc cssClass) {
39         this.name = name;
40         this.CssClass = cssClass;
41     }
42
43     public static PortletMessageType getTypeByName(String JavaDoc testName) {
44         if (testName.equalsIgnoreCase("info")){
45             return INFO;
46         } else if (testName.equalsIgnoreCase("error")){
47             return ERROR;
48         } else if (testName.equalsIgnoreCase("status")){
49             return STATUS;
50         } else if (testName.equalsIgnoreCase("alert")){
51             return ALERT;
52         } else if (testName.equalsIgnoreCase("success")){
53             return SUCCESS;
54         } else {
55             throw new IllegalArgumentException JavaDoc("PortletMessageType with name '" + testName + "' does not exist.");
56         }
57     }
58
59     public String JavaDoc toString(){
60         return name;
61     }
62
63     public static boolean equals(PortletMessageType msgType, String JavaDoc testName) {
64         if (msgType == getTypeByName(testName)) {
65             return true;
66         } else {
67             return false;
68         }
69     }
70
71     public boolean equals(Object JavaDoc obj) {
72         if (obj instanceof PortletMessageType) {
73             PortletMessageType comp = (PortletMessageType)obj;
74             return name.equals(comp.name);
75         } else {
76             return false;
77         }
78     }
79 }
80
Popular Tags