KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > jcr > PropertyType


1 /*
2  * $Id: PropertyType.java,v 1.2 2004/07/24 00:16:21 benjmestrallet Exp $
3  *
4  * Copyright 2002-2004 Day Management AG, Switzerland.
5  *
6  * Licensed under the Day RI License, Version 2.0 (the "License"),
7  * as a reference implementation of the following specification:
8  *
9  * Content Repository API for Java Technology, revision 0.12
10  * <http://www.jcp.org/en/jsr/detail?id=170>
11  *
12  * You may not use this file except in compliance with the License.
13  * You may obtain a copy of the License files at
14  *
15  * http://www.day.com/content/en/licenses/day-ri-license-2.0
16  * http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  */

24 package javax.jcr;
25
26 /**
27  * The property types supported by the JCR standard.
28  * <p/>
29  * <p>This interface defines following property types:
30  * <UL>
31  * <LI>STRING
32  * <LI>BINARY
33  * <LI>LONG
34  * <LI>DOUBLE
35  * <LI>DATE
36  * <LI>BOOLEAN
37  * <LI>SOFTLINK
38  * <LI>REFERENCE
39  * </UL>
40  *
41  * @author Stefan Guggisberg
42  */

43 public final class PropertyType {
44   /**
45    * The supported property types.
46    */

47   public static final int STRING = 1;
48   public static final int BINARY = 2;
49   public static final int LONG = 3;
50   public static final int DOUBLE = 4;
51   public static final int DATE = 5;
52   public static final int BOOLEAN = 6;
53   public static final int SOFTLINK = 7;
54   public static final int REFERENCE = 8;
55
56   /**
57    * Undefined type.
58    */

59   public static final int UNDEFINED = 0;
60
61   /**
62    * The names of the supported property types,
63    * as used in serialization.
64    */

65   public static final String JavaDoc TYPENAME_STRING = "String";
66   public static final String JavaDoc TYPENAME_BINARY = "Binary";
67   public static final String JavaDoc TYPENAME_LONG = "Long";
68   public static final String JavaDoc TYPENAME_DOUBLE = "Double";
69   public static final String JavaDoc TYPENAME_DATE = "Date";
70   public static final String JavaDoc TYPENAME_BOOLEAN = "Boolean";
71   public static final String JavaDoc TYPENAME_SOFTLINK = "SoftLink";
72   public static final String JavaDoc TYPENAME_REFERENCE = "Reference";
73
74   /**
75    * Returns the name of the specified <code>type</code>,
76    * as used in serialization.
77    *
78    * @param type the property type
79    * @return the name of the specified <code>type</code>
80    * @throws IllegalArgumentException if <code>type</code>
81    * is not a valid property type.
82    */

83   public static String JavaDoc nameFromValue(int type) {
84     switch (type) {
85       case STRING:
86         return TYPENAME_STRING;
87       case BINARY:
88         return TYPENAME_BINARY;
89       case BOOLEAN:
90         return TYPENAME_BOOLEAN;
91       case LONG:
92         return TYPENAME_LONG;
93       case DOUBLE:
94         return TYPENAME_DOUBLE;
95       case DATE:
96         return TYPENAME_DATE;
97       case SOFTLINK:
98         return TYPENAME_SOFTLINK;
99       case REFERENCE:
100         return TYPENAME_REFERENCE;
101       default:
102         throw new IllegalArgumentException JavaDoc("unknown type: " + type);
103     }
104   }
105
106   /**
107    * Returns the numeric constant value of the type with the specified name.
108    *
109    * @param name the name of the property type
110    * @return the numeric constant value
111    * @throws IllegalArgumentException if <code>name</code>
112    * is not a valid property type name.
113    */

114   public static int valueFromName(String JavaDoc name) {
115     if (name.equals(TYPENAME_STRING)) {
116       return STRING;
117     } else if (name.equals(TYPENAME_BINARY)) {
118       return BINARY;
119     } else if (name.equals(TYPENAME_BOOLEAN)) {
120       return BOOLEAN;
121     } else if (name.equals(TYPENAME_LONG)) {
122       return LONG;
123     } else if (name.equals(TYPENAME_DOUBLE)) {
124       return DOUBLE;
125     } else if (name.equals(TYPENAME_DATE)) {
126       return DATE;
127     } else if (name.equals(TYPENAME_SOFTLINK)) {
128       return SOFTLINK;
129     } else if (name.equals(TYPENAME_REFERENCE)) {
130       return REFERENCE;
131     } else {
132       throw new IllegalArgumentException JavaDoc("unknown type: " + name);
133     }
134   }
135
136   /**
137    * private constructor to prevent instantiation
138    */

139   private PropertyType() {
140   }
141 }
142
143
Popular Tags