KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > dav > server > utils > DataType


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19
20 package org.openharmonise.dav.server.utils;
21
22 import java.net.URL JavaDoc;
23 import java.util.Date JavaDoc;
24
25 import org.openharmonise.commons.xml.namespace.*;
26
27
28 /**
29  * This class provides data type constants to be used in publishing webdav properties.
30  *
31  * @author Michael Bell
32  * @version $Revision: 1.1 $
33  * @since December 5, 2003
34  */

35 public class DataType {
36     
37
38     private String JavaDoc m_sType = null;
39
40     NamespaceType m_ns = null;
41     
42     public final static DataType STRING = new DataType(NamespaceType.XML_SCHEMA,"string");
43     public final static DataType DATE = new DataType(NamespaceType.XML_SCHEMA,"date");
44     public final static DataType BOOLEAN = new DataType(NamespaceType.XML_SCHEMA,"boolean");
45     public final static DataType INTEGER = new DataType(NamespaceType.XML_SCHEMA,"integer");
46     public final static DataType FLOAT = new DataType(NamespaceType.XML_SCHEMA,"float");
47     public final static DataType URI = new DataType(NamespaceType.XML_SCHEMA,"anyURI");
48     public final static DataType HREF = new DataType(NamespaceType.DAV,"href");
49     public final static DataType PROP = new DataType(NamespaceType.DAV,"prop");
50     
51     /**
52      * Create data type with a namespace and type.
53      */

54     private DataType(NamespaceType ns,String JavaDoc sType) {
55         m_ns = ns;
56         m_sType = sType;
57     }
58     
59
60     /**
61      * Returns standard namespace prefix.
62      *
63      * @return
64      */

65     public String JavaDoc getPrefix() {
66         return m_ns.getPrefix();
67     }
68
69     /**
70      * Returns namespace uri for data type.
71      *
72      * @return
73      */

74     public String JavaDoc getURI() {
75         return m_ns.getURI();
76     }
77
78     /**
79      * Returns data type name.
80      *
81      * @return
82      */

83     public String JavaDoc getType() {
84         return m_sType;
85     }
86     
87     /**
88      * Returns data type for class name.
89      *
90      * @param sClassname
91      * @return
92      * @throws ClassNotFoundException
93      */

94     public static DataType getDataType(String JavaDoc sClassname) throws ClassNotFoundException JavaDoc {
95         return getDataType(Class.forName(sClassname));
96     }
97     
98     /**
99      * Returns data type for class.
100      *
101      * @param clss
102      * @return
103      */

104     public static DataType getDataType(Class JavaDoc clss) {
105         DataType result = null;
106         
107         if(clss.equals(String JavaDoc.class) == true) {
108             result = STRING;
109         } else if(clss.equals(Integer JavaDoc.class) == true) {
110             result = INTEGER;
111         } else if(clss.equals(Boolean JavaDoc.class) == true) {
112             result = BOOLEAN;
113         } else if(clss.equals(Date JavaDoc.class) == true) {
114             result = DATE;
115         } else if(clss.equals(Float JavaDoc.class) == true) {
116             result = FLOAT;
117         } else if(clss.equals(URL JavaDoc.class) == true) {
118             result = URI;
119         }
120         
121         return result;
122     }
123 }
124
Popular Tags