01: /*--------------------------------------------------------------------------*
02: | Copyright (C) 2006 Christopher Kohlhaas |
03: | |
04: | This program is free software; you can redistribute it and/or modify |
05: | it under the terms of the GNU General Public License as published by the |
06: | Free Software Foundation. A copy of the license has been included with |
07: | these distribution in the COPYING file, if not go to www.fsf.org |
08: | |
09: | As a special exception, you are granted the permissions to link this |
10: | program with every library, which license fulfills the Open Source |
11: | Definition as published by the Open Source Initiative (OSI). |
12: *--------------------------------------------------------------------------*/
13: package org.rapla.entities.dynamictype;
14:
15: import java.io.Serializable;
16: import java.util.HashMap;
17: import java.util.Map;
18:
19: /** Attributes are to DynamicTypes, what properties are to Beans.
20: Currently Rapla supports the following types:
21: <li>string</li>
22: <li>int</li>
23: <li>date</li>
24: <li>boolean</li>
25: <li>rapla:category</li>
26: @see DynamicType */
27: public class AttributeType implements Serializable {
28: // Don't forget to increase the serialVersionUID when you change the fields
29: private static final long serialVersionUID = 1;
30:
31: private String type;
32:
33: static public AttributeType STRING = new AttributeType("string");
34: static public AttributeType INT = new AttributeType("int");
35: static public AttributeType DATE = new AttributeType("date");
36: static public AttributeType BOOLEAN = new AttributeType("boolean");
37: static public AttributeType CATEGORY = new AttributeType(
38: "rapla:category");
39:
40: private static Map types;
41:
42: private AttributeType(String type) {
43: this .type = type;
44: if (types == null) {
45: types = new HashMap();
46: }
47: types.put(type, this );
48: }
49:
50: public boolean is(AttributeType other) {
51: if (other == null)
52: return false;
53: return type.equals(other.type);
54: }
55:
56: public static AttributeType findForString(String string) {
57: return (AttributeType) types.get(string);
58: }
59:
60: public String toString() {
61: return type;
62: }
63:
64: public boolean equals(Object other) {
65: if (!(other instanceof AttributeType))
66: return false;
67: return is((AttributeType) other);
68: }
69:
70: public int hashCode() {
71: return type.hashCode();
72: }
73: }
|