01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 2007.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.http.protocol.error;
07:
08: import java.util.HashMap;
09: import java.util.Map;
10:
11: /**
12: * @author Arjohn Kampman
13: */
14: public class ErrorType {
15:
16: private static final Map<String, ErrorType> registry = new HashMap<String, ErrorType>();
17:
18: public static final ErrorType MALFORMED_QUERY = register("MALFORMED QUERY");
19:
20: public static final ErrorType MALFORMED_DATA = register("MALFORMED DATA");
21:
22: public static final ErrorType UNSUPPORTED_QUERY_LANGUAGE = register("UNSUPPORTED QUERY LANGUAGE");
23:
24: public static final ErrorType UNSUPPORTED_FILE_FORMAT = register("UNSUPPORTED FILE FORMAT");
25:
26: protected static ErrorType register(String label) {
27: synchronized (registry) {
28: ErrorType errorType = registry.get(label);
29:
30: if (errorType == null) {
31: errorType = new ErrorType(label);
32: registry.put(label, errorType);
33: }
34:
35: return errorType;
36: }
37: }
38:
39: public static ErrorType forLabel(String label) {
40: synchronized (registry) {
41: return registry.get(label);
42: }
43: }
44:
45: /**
46: * The error type's label.
47: */
48: private String label;
49:
50: private ErrorType(String label) {
51: this .label = label;
52: }
53:
54: public String getLabel() {
55: return label;
56: }
57:
58: public boolean equals(Object other) {
59: if (other instanceof ErrorType) {
60: return ((ErrorType) other).getLabel().equals(
61: this .getLabel());
62: }
63:
64: return false;
65: }
66:
67: @Override
68: public String toString() {
69: return label;
70: }
71: }
|