You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2006/09/01 01:59:36 UTC

svn commit: r439106 - /incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/ResourceType.java

Author: jmsnell
Date: Thu Aug 31 16:59:35 2006
New Revision: 439106

URL: http://svn.apache.org/viewvc?rev=439106&view=rev
Log:
don't use an enum for this.  implementations may want to extend the types of resources
targeted for the implementation.  For instance, Queso provides a history feed resource.

Modified:
    incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/ResourceType.java

Modified: incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/ResourceType.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/ResourceType.java?rev=439106&r1=439105&r2=439106&view=diff
==============================================================================
--- incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/ResourceType.java (original)
+++ incubator/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/util/ResourceType.java Thu Aug 31 16:59:35 2006
@@ -17,14 +17,104 @@
 */
 package org.apache.abdera.protocol.server.util;
 
-public enum ResourceType {
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 
-  UNKNOWN, 
-  SERVICE, 
-  COLLECTION, 
-  ENTRY, 
-  ENTRY_EDIT, 
-  MEDIA, 
-  MEDIA_EDIT
+public final class ResourceType 
+  implements Comparable<ResourceType>, 
+             Serializable {
+
+  private static final long serialVersionUID = -4325229702865059923L;
+  public static final int UNKNOWN_ORDINAL = 0;
+  public static final int SERVICE_ORDINAL = 1;
+  public static final int COLLECTION_ORDINAL = 2;
+  public static final int ENTRY_ORDINAL = 3;
+  public static final int ENTRY_EDIT_ORDINAL = 4;
+  public static final int MEDIA_ORDINAL = 5;
+  public static final int MEDIA_EDIT_ORDINAL = 6;
+  
+  public static final ResourceType UNKNOWN = new ResourceType("UNKNOWN", UNKNOWN_ORDINAL); 
+  public static final ResourceType SERVICE = new ResourceType("SERVICE", SERVICE_ORDINAL);
+  public static final ResourceType COLLECTION = new ResourceType("COLLECTION", COLLECTION_ORDINAL); 
+  public static final ResourceType ENTRY = new ResourceType("ENTRY", ENTRY_ORDINAL);
+  public static final ResourceType ENTRY_EDIT = new ResourceType("ENTRY_EDIT", ENTRY_EDIT_ORDINAL);
+  public static final ResourceType MEDIA = new ResourceType("MEDIA", MEDIA_ORDINAL);
+  public static final ResourceType MEDIA_EDIT = new ResourceType("MEDIA_EDIT", MEDIA_EDIT_ORDINAL);
+  
+  private static List<ResourceType> values;
+  
+  private static synchronized List<ResourceType> get_values() {
+    if (values == null) {
+      values = Collections.synchronizedList(
+          new ArrayList<ResourceType>());
+    }
+    return values;
+  }
+  
+  private static synchronized void add(ResourceType type) {
+    List<ResourceType> values = get_values();
+    values.add(type);
+  }
+  
+  public static synchronized ResourceType[] values() {
+    List<ResourceType> values = get_values();
+    return values.toArray(new ResourceType[values.size()]);
+  }
+  
+  public static ResourceType valueOf(String string) {
+    for (ResourceType type: values()) {
+      if (type.name() == string.intern()) return type;
+    }
+    return null;
+  }
+  
+  private int i;
+  private String name;
+  
+  public ResourceType(String name, int ordinal) {
+    this.i = ordinal;
+    this.name = name.intern();
+    ResourceType.add(this);
+  }
+  
+  public String name() {
+    return name;
+  }
+  
+  public int ordinal() {
+    return i;
+  }
+  
+  public int hashCode() {
+    final int PRIME = 31;
+    int result = 1;
+    result = PRIME * result + i;
+    result = PRIME * result + ((name == null) ? 0 : name.hashCode());
+    return result;
+  }
+
+  public boolean equals(Object obj) {
+    if (this == obj) return true;
+    if (obj == null) return false;
+    if (getClass() != obj.getClass()) return false;
+    final ResourceType other = (ResourceType) obj;
+    if (i != other.i) return false;
+    if (name == null) {
+      if (other.name != null) return false;
+    } else if (!name.equals(other.name))
+      return false;
+    return true;
+  }
+
+  public int compareTo(ResourceType o) {
+    if (o.ordinal() > ordinal()) return -1;
+    if (o.ordinal() < ordinal()) return 1;
+    return 0;
+  }
   
+  public String toString() {
+    return name();
+  }
 }