View Javadoc

1   /*
2    * Copyright 2007-2009 Hippo
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" 
12   * BASIS, 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 nl.hippo.client.api.event;
17  
18  import java.io.Serializable;
19  
20  public class NamedEvent implements Serializable {
21  
22      private static final long serialVersionUID = 1L;
23      private static final String[] TYPE_NAMES = new String[] { "update", "create", "delete", "null" };
24  
25      public static final int UPDATE_TYPE = 0;
26      public static final int CREATE_TYPE = 1;
27      public static final int DELETE_TYPE = 2;
28      public static final int NULL_TYPE = 3;
29  
30      protected int type;
31      protected String namespace;
32      protected String path;
33  
34      protected final String name;
35  
36      public NamedEvent(String name) {
37      	if(name != null) {
38  	        this.name = name.toLowerCase();
39  	    } else {
40  	        this.name = name;
41  	    }
42      }
43  
44      public NamedEvent(int type, String namespace, String path) {
45          this.type = type;
46          if(namespace != null) {
47  	        this.namespace = namespace.toLowerCase();
48  	    } else {
49  	        this.namespace = namespace;
50  	    }
51  	    if(path != null) {
52  	        this.path = path.toLowerCase();
53  	    } else {
54  	        this.path = path;
55  	    }
56  
57          this.name = "/" + this.namespace + this.path;
58      }
59  
60      public String getName() {
61          return name;
62      }
63  
64      public String getPath() {
65          return path;
66      }
67  
68      public String getType() {
69          return TYPE_NAMES[type];
70      }
71  
72      public String getNamespace() {
73          return namespace;
74      }
75  
76      public boolean equals(Object obj) {
77          if (obj != null && obj instanceof NamedEvent) {
78              return name.equalsIgnoreCase(((NamedEvent) obj).getName());
79          }
80          return false;
81      }
82  
83      public int hashCode() {
84          return name.hashCode();
85      }
86  
87      public String toString() {
88          return "NamedEvent[" + name + "]";
89      }
90  }