001: /*
002: * Copyright 2006 Day Management AG, Switzerland. All rights reserved.
003: */
004: package javax.jcr;
005:
006: /**
007: * The property types supported by the JCR standard.
008: * <p/>
009: * <p>This interface defines following property types:
010: * <ul>
011: * <li><code>STRING</code>
012: * <li><code>BINARY</code>
013: * <li><code>LONG</code>
014: * <li><code>DOUBLE</code>
015: * <li><code>DECIMAL</code>
016: * <li><code>DATE</code>
017: * <li><code>BOOLEAN</code>
018: * <li><code>NAME</code>
019: * <li><code>PATH</code>
020: * <li><code>REFERENCE</code>
021: * <li><code>WEAKREFERENCE</code>
022: * <li><code>URI</code>
023: * </ul>
024: */
025: public final class PropertyType {
026:
027: /*
028: * The supported property types.
029: */
030:
031: /**
032: * The <code>STRING</code> property type is used to store strings. It has
033: * the same characteristics as the Java <code>String</code> class.
034: */
035: public static final int STRING = 1;
036:
037: /**
038: * <code>BINARY</code> properties are used to store binary data.
039: */
040: public static final int BINARY = 2;
041:
042: /**
043: * The <code>LONG</code> property type is used to store integers. It has
044: * the same characteristics as the Java primitive type <code>long</code>.
045: */
046: public static final int LONG = 3;
047:
048: /**
049: * The <code>DOUBLE</code> property type is used to store floating point
050: * numbers. It has the same characteristics as the Java primitive type
051: * <code>double</code>.
052: */
053: public static final int DOUBLE = 4;
054:
055: /**
056: * The <code>DATE</code> property type is used to store time and date
057: * information. See <i>4.2.6.1 Date</i> in the specification.
058: */
059: public static final int DATE = 5;
060:
061: /**
062: * The <code>BOOLEAN</code> property type is used to store boolean values.
063: * It has the same characteristics as the Java primitive type
064: * <code>boolean</code>.
065: */
066: public static final int BOOLEAN = 6;
067:
068: /**
069: * A <code>NAME</code> is a pairing of a namespace and a local name. When
070: * read, the namespace is mapped to the current prefix. See
071: * <i>4.2.6.2 Name</i> in the specification.
072: */
073: public static final int NAME = 7;
074:
075: /**
076: * A <code>PATH</code> property is an ordered list of path elements. A path
077: * element is a <code>NAME</code> with an optional index. When read, the
078: * <code>NAME</code>s within the path are mapped to their current prefix.
079: * A path may be absolute or relative. See <i>4.2.6.3 Path</i> in the
080: * specification.
081: */
082: public static final int PATH = 8;
083:
084: /**
085: * A <code>REFERENCE</code> property stores the identifier of a
086: * referenceable node (one having type <code>mix:referenceable</code>),
087: * which must exist within the same workspace or session as the
088: * <code>REFERENCE</code> property. A <code>REFERENCE</code> property
089: * enforces this referential integrity by preventing (in level 2
090: * implementations) the removal of its target node. See
091: * <i>4.2.6.4 Reference</i> in the specification.
092: */
093: public static final int REFERENCE = 9;
094:
095: /**
096: * A <code>WEAKREFERENCE</code> property stores the identifier of a
097: * referenceable node (one having type <code>mix:referenceable</code>).
098: * A <code>WEAKREFERENCE</code> property does not enforce referential
099: * integrity. See <i>4.2.6.5 Weak Reference</i> in the specification.
100: *
101: * @since JCR 2.0
102: */
103: public static final int WEAKREFERENCE = 10;
104:
105: /**
106: * A <code>URI</code> property is identical to <code>STRING</code> property
107: * except that it only accepts values that conform to the syntax of a
108: * URI-reference as defined in RFC 3986. See also <i>4.2.6.6 URI</i> in the
109: * specification.
110: *
111: * @since JCR 2.0
112: */
113: public static final int URI = 11;
114:
115: /**
116: * The <code>DECIMAL</code> property type is used to store precise decimal
117: * numbers. It has the same characteristics as the Java class
118: * <code>java.math.BigDecimal</code>.
119: *
120: * @since JCR 2.0
121: */
122: public static final int DECIMAL = 12;
123:
124: /**
125: * This constant can be used within a property definition (see
126: * <i>4.7.5 Property Definitions</i>) to specify that the property in
127: * question may be of any type. However, it cannot be the actual type of
128: * any property instance. For example it will never be returned by
129: * {@link Property#getType} and (in level 2 implementations) it cannot be
130: * assigned as the type when creating a new property.
131: */
132: public static final int UNDEFINED = 0;
133:
134: /*
135: * The names of the supported property types,
136: * as used in serialization.
137: */
138: public static final String TYPENAME_STRING = "String";
139: public static final String TYPENAME_BINARY = "Binary";
140: public static final String TYPENAME_LONG = "Long";
141: public static final String TYPENAME_DOUBLE = "Double";
142: public static final String TYPENAME_DECIMAL = "Decimal";
143: public static final String TYPENAME_DATE = "Date";
144: public static final String TYPENAME_BOOLEAN = "Boolean";
145: public static final String TYPENAME_NAME = "Name";
146: public static final String TYPENAME_PATH = "Path";
147: public static final String TYPENAME_REFERENCE = "Reference";
148: public static final String TYPENAME_WEAKREFERENCE = "WeakReference";
149: public static final String TYPENAME_URI = "URI";
150:
151: /*
152: * String representation of <i>undefined</i> type.
153: */
154: public static final String TYPENAME_UNDEFINED = "undefined";
155:
156: /**
157: * Returns the name of the specified <code>type</code>,
158: * as used in serialization.
159: *
160: * @param type the property type
161: * @return the name of the specified <code>type</code>
162: * @throws IllegalArgumentException if <code>type</code>
163: * is not a valid property type.
164: */
165: public static String nameFromValue(int type) {
166: switch (type) {
167: case STRING:
168: return TYPENAME_STRING;
169: case BINARY:
170: return TYPENAME_BINARY;
171: case BOOLEAN:
172: return TYPENAME_BOOLEAN;
173: case LONG:
174: return TYPENAME_LONG;
175: case DOUBLE:
176: return TYPENAME_DOUBLE;
177: case DECIMAL:
178: return TYPENAME_DECIMAL;
179: case DATE:
180: return TYPENAME_DATE;
181: case NAME:
182: return TYPENAME_NAME;
183: case PATH:
184: return TYPENAME_PATH;
185: case REFERENCE:
186: return TYPENAME_REFERENCE;
187: case WEAKREFERENCE:
188: return TYPENAME_WEAKREFERENCE;
189: case URI:
190: return TYPENAME_URI;
191: case UNDEFINED:
192: return TYPENAME_UNDEFINED;
193: default:
194: throw new IllegalArgumentException("unknown type: " + type);
195: }
196: }
197:
198: /**
199: * Returns the numeric constant value of the type with the specified name.
200: *
201: * @param name the name of the property type
202: * @return the numeric constant value
203: * @throws IllegalArgumentException if <code>name</code>
204: * is not a valid property type name.
205: */
206: public static int valueFromName(String name) {
207: if (name.equals(TYPENAME_STRING)) {
208: return STRING;
209: } else if (name.equals(TYPENAME_BINARY)) {
210: return BINARY;
211: } else if (name.equals(TYPENAME_BOOLEAN)) {
212: return BOOLEAN;
213: } else if (name.equals(TYPENAME_LONG)) {
214: return LONG;
215: } else if (name.equals(TYPENAME_DOUBLE)) {
216: return DOUBLE;
217: } else if (name.equals(TYPENAME_DECIMAL)) {
218: return DECIMAL;
219: } else if (name.equals(TYPENAME_DATE)) {
220: return DATE;
221: } else if (name.equals(TYPENAME_NAME)) {
222: return NAME;
223: } else if (name.equals(TYPENAME_PATH)) {
224: return PATH;
225: } else if (name.equals(TYPENAME_REFERENCE)) {
226: return REFERENCE;
227: } else if (name.equals(TYPENAME_WEAKREFERENCE)) {
228: return WEAKREFERENCE;
229: } else if (name.equals(TYPENAME_URI)) {
230: return URI;
231: } else if (name.equals(TYPENAME_UNDEFINED)) {
232: return UNDEFINED;
233: } else {
234: throw new IllegalArgumentException("unknown type: " + name);
235: }
236: }
237:
238: /**
239: * private constructor to prevent instantiation
240: */
241: private PropertyType() {
242: }
243: }
|