Statistics
| Revision:

root / trunk / libraries / libGPE / src / org / gvsig / xmlschema / utils / TypeUtils.java @ 12175

History | View | Annotate | Download (5.16 KB)

1
package org.gvsig.xmlschema.utils;
2

    
3
import org.gvsig.xmlschema.som.IXSElementDeclaration;
4

    
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
/* CVS MESSAGES:
46
 *
47
 * $Id: TypeUtils.java 12175 2007-06-14 16:15:05Z jorpiell $
48
 * $Log$
49
 * Revision 1.1  2007-06-14 16:15:03  jorpiell
50
 * builds to create the jars generated and add the schema code to the libGPEProject
51
 *
52
 * Revision 1.1  2007/06/14 13:50:07  jorpiell
53
 * The schema jar name has been changed
54
 *
55
 * Revision 1.1  2007/06/07 14:54:13  jorpiell
56
 * Add the schema support
57
 *
58
 *
59
 */
60
/**
61
 * A class with some utils to manage the types
62
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
63
 */
64
public class TypeUtils {
65
        public static final String STRING = "string";
66
        public static final String INTEGER = "integer";
67
        public static final String DOUBLE = "double";
68
        public static final String LONG = "long";
69
        public static final String BOOLEAN = "boolean";
70
        public static final String DURATION = "duration";
71
        public static final String DATETIME = "dateTime";
72
        public static final String TIME = "time";
73
        public static final String DATE = "date";
74
        public static final String GYEARMONTH = "gYearMonth";
75
        public static final String GYEAR = "gYear";
76
        public static final String GMONTHDAY = "gMonthDay";
77
        public static final String GDAY = "gDay";
78
        public static final String GMONTH = "gMonth";
79
        public static final String BASE64BINARY = "base64Binary";
80
        public static final String HEXBINARY = "hexBinary";
81
        public static final String ANYURI = "anyUri";
82
        public static final String QNAME = "QName";
83
        public static final String NOTATION = "NOTATION";
84
        public static final String DECIMAL = "decimal";
85
        public static final String NONPOSITIVEINTEGER = "nonPositiveInteger";
86
        public static final String NONNEGATIVEINTEGER = "nonNegativeInteger";
87
        public static final String NEGATIVEINTEGER = "negativeInteger";
88
        public static final String POSITIVEINTEGER = "positiveInteger";
89
        public static final String INT = "int";
90
        public static final String INSIGNEDSHORT = "unsignedLong";
91
        public static final String SHORT = "short";
92
        public static final String UNSIGNEDINT = "unsignedInt";
93
        public static final String BYTE = "byte";
94
        public static final String UNSIGNEDSHORT = "unsignedShort";
95
        public static final String UNSIGNEDBYTE = "unsignedByte";
96
        public static final String NORMALIZEDSTRING = "normalizedString";
97
        public static final String TOKEN = "token";
98
        public static final String LANGUAGE = "language";
99
        public static final String NAME = "Name";
100
        public static final String NMTOKEN = "NMTOKEN";
101
        public static final String NCNAME = "NCName";
102
        public static final String ID = "ID";
103
        public static final String IDREF = "IDREF";
104
        public static final String ENTITY = "ENTITY";
105

    
106
        /**
107
         * Return the XML schema simple type from a class
108
         * @param clazz
109
         * Clazz to compare the name
110
         * @return
111
         * Xml schema simple type
112
         */
113
        public static String getType(Class clazz){
114
                if (clazz.getName().compareTo(String.class.getName()) == 0){
115
                        return STRING;
116
                }else if (clazz.getName().compareTo(Integer.class.getName()) == 0){
117
                        return INTEGER;
118
                }else if (clazz.getName().compareTo(Double.class.getName()) == 0){
119
                        return DOUBLE;
120
                }else if (clazz.getName().compareTo(Long.class.getName()) == 0){
121
                        return LONG;
122
                }else if (clazz.getName().compareTo(Boolean.class.getName()) == 0){
123
                        return BOOLEAN;
124
                }
125
                return STRING;
126
        }
127
        
128
        /**
129
         * Return the XML schema simple type from a class. The 
130
         * name contains the Xlink namespace
131
         * @param clazz
132
         * Clazz to compare the name
133
         * @return
134
         * Xml schema simple type with the xlink prefix
135
         */
136
        public static String getXSType(Class clazz){
137
                return SchemaTags.XS_NS + ":" + getType(clazz);
138
        }
139

    
140
        public static Object getValue(IXSElementDeclaration element, String value) {
141
                if ((element == null) || (element.getTypeName() == null)){
142
                        return value;
143
                }
144
                String typeName = element.getTypeName();
145
                typeName = typeName.substring(typeName.indexOf(":") + 1,typeName.length());
146
                if (typeName.compareTo(INTEGER) == 0){
147
                        return new Integer(Integer.parseInt(value));
148
                }else if (typeName.compareTo(BOOLEAN) == 0){
149
                        return new Boolean(Boolean.getBoolean(value));
150
                }
151
                return value;
152
        }
153
        
154
        
155
}