1 |
769 |
jeremybenn |
/* TypeLibrary.java --
|
2 |
|
|
Copyright (C) 2006 Free Software Foundation, Inc.
|
3 |
|
|
|
4 |
|
|
This file is part of GNU Classpath.
|
5 |
|
|
|
6 |
|
|
GNU Classpath is free software; you can redistribute it and/or modify
|
7 |
|
|
it under the terms of the GNU General Public License as published by
|
8 |
|
|
the Free Software Foundation; either version 2, or (at your option)
|
9 |
|
|
any later version.
|
10 |
|
|
|
11 |
|
|
GNU Classpath is distributed in the hope that it will be useful, but
|
12 |
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
|
|
General Public License for more details.
|
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU General Public License
|
17 |
|
|
along with GNU Classpath; see the file COPYING. If not, write to the
|
18 |
|
|
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
|
|
02110-1301 USA.
|
20 |
|
|
|
21 |
|
|
Linking this library statically or dynamically with other modules is
|
22 |
|
|
making a combined work based on this library. Thus, the terms and
|
23 |
|
|
conditions of the GNU General Public License cover the whole
|
24 |
|
|
combination.
|
25 |
|
|
|
26 |
|
|
As a special exception, the copyright holders of this library give you
|
27 |
|
|
permission to link this library with independent modules to produce an
|
28 |
|
|
executable, regardless of the license terms of these independent
|
29 |
|
|
modules, and to copy and distribute the resulting executable under
|
30 |
|
|
terms of your choice, provided that you also meet, for each linked
|
31 |
|
|
independent module, the terms and conditions of the license of that
|
32 |
|
|
module. An independent module is a module which is not derived from
|
33 |
|
|
or based on this library. If you modify this library, you may extend
|
34 |
|
|
this exception to your version of the library, but you are not
|
35 |
|
|
obligated to do so. If you do not wish to do so, delete this
|
36 |
|
|
exception statement from your version. */
|
37 |
|
|
|
38 |
|
|
package gnu.xml.validation.datatype;
|
39 |
|
|
|
40 |
|
|
import java.util.HashMap;
|
41 |
|
|
import java.util.Map;
|
42 |
|
|
import org.relaxng.datatype.Datatype;
|
43 |
|
|
import org.relaxng.datatype.DatatypeBuilder;
|
44 |
|
|
import org.relaxng.datatype.DatatypeException;
|
45 |
|
|
import org.relaxng.datatype.DatatypeLibrary;
|
46 |
|
|
|
47 |
|
|
/**
|
48 |
|
|
* Datatype library for XML Schema datatypes.
|
49 |
|
|
*
|
50 |
|
|
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
|
51 |
|
|
*/
|
52 |
|
|
public class TypeLibrary
|
53 |
|
|
implements DatatypeLibrary
|
54 |
|
|
{
|
55 |
|
|
|
56 |
|
|
public static final SimpleType ANY_SIMPLE_TYPE = new AnySimpleType();
|
57 |
|
|
|
58 |
|
|
public static final SimpleType STRING = new StringType();
|
59 |
|
|
public static final SimpleType BOOLEAN = new BooleanType();
|
60 |
|
|
public static final SimpleType DECIMAL = new DecimalType();
|
61 |
|
|
public static final SimpleType FLOAT = new FloatType();
|
62 |
|
|
public static final SimpleType DOUBLE = new DoubleType();
|
63 |
|
|
public static final SimpleType DURATION = new DurationType();
|
64 |
|
|
public static final SimpleType DATE_TIME = new DateTimeType();
|
65 |
|
|
public static final SimpleType TIME = new TimeType();
|
66 |
|
|
public static final SimpleType DATE = new DateType();
|
67 |
|
|
public static final SimpleType G_YEAR_MONTH = new GYearMonthType();
|
68 |
|
|
public static final SimpleType G_YEAR = new GYearType();
|
69 |
|
|
public static final SimpleType G_MONTH_DAY = new GMonthDayType();
|
70 |
|
|
public static final SimpleType G_DAY = new GDayType();
|
71 |
|
|
public static final SimpleType G_MONTH = new GMonthType();
|
72 |
|
|
public static final SimpleType HEX_BINARY = new HexBinaryType();
|
73 |
|
|
public static final SimpleType BASE64_BINARY = new Base64BinaryType();
|
74 |
|
|
public static final SimpleType ANY_URI = new AnyURIType();
|
75 |
|
|
public static final SimpleType QNAME = new QNameType();
|
76 |
|
|
public static final SimpleType NOTATION = new NotationType();
|
77 |
|
|
|
78 |
|
|
public static final SimpleType NORMALIZED_STRING = new NormalizedStringType();
|
79 |
|
|
public static final SimpleType TOKEN = new TokenType();
|
80 |
|
|
public static final SimpleType LANGUAGE = new LanguageType();
|
81 |
|
|
public static final SimpleType NMTOKEN = new NMTokenType();
|
82 |
|
|
public static final SimpleType NMTOKENS = new NMTokensType();
|
83 |
|
|
public static final SimpleType NAME = new NameType();
|
84 |
|
|
public static final SimpleType NCNAME = new NCNameType();
|
85 |
|
|
public static final SimpleType ID = new IDType();
|
86 |
|
|
public static final SimpleType IDREF = new IDRefType();
|
87 |
|
|
public static final SimpleType IDREFS = new IDRefsType();
|
88 |
|
|
public static final SimpleType ENTITY = new EntityType();
|
89 |
|
|
public static final SimpleType ENTITIES = new EntitiesType();
|
90 |
|
|
public static final SimpleType INTEGER = new IntegerType();
|
91 |
|
|
public static final SimpleType NON_POSITIVE_INTEGER = new NonPositiveIntegerType();
|
92 |
|
|
public static final SimpleType NEGATIVE_INTEGER = new NegativeIntegerType();
|
93 |
|
|
public static final SimpleType LONG = new LongType();
|
94 |
|
|
public static final SimpleType INT = new IntType();
|
95 |
|
|
public static final SimpleType SHORT = new ShortType();
|
96 |
|
|
public static final SimpleType BYTE = new ByteType();
|
97 |
|
|
public static final SimpleType NON_NEGATIVE_INTEGER = new NonNegativeIntegerType();
|
98 |
|
|
public static final SimpleType UNSIGNED_LONG = new UnsignedLongType();
|
99 |
|
|
public static final SimpleType UNSIGNED_INT = new UnsignedIntType();
|
100 |
|
|
public static final SimpleType UNSIGNED_SHORT = new UnsignedShortType();
|
101 |
|
|
public static final SimpleType UNSIGNED_BYTE = new UnsignedByteType();
|
102 |
|
|
public static final SimpleType POSITIVE_INTEGER = new PositiveIntegerType();
|
103 |
|
|
|
104 |
|
|
private static Map byName;
|
105 |
|
|
static
|
106 |
|
|
{
|
107 |
|
|
byName = new HashMap();
|
108 |
|
|
byName.put("anySimpleType", ANY_SIMPLE_TYPE);
|
109 |
|
|
byName.put("string", STRING);
|
110 |
|
|
byName.put("boolean", BOOLEAN);
|
111 |
|
|
byName.put("decimal", DECIMAL);
|
112 |
|
|
byName.put("float", FLOAT);
|
113 |
|
|
byName.put("double", DOUBLE);
|
114 |
|
|
byName.put("duration", DURATION);
|
115 |
|
|
byName.put("dateTime", DATE_TIME);
|
116 |
|
|
byName.put("time", TIME);
|
117 |
|
|
byName.put("date", DATE);
|
118 |
|
|
byName.put("gYearMonth", G_YEAR_MONTH);
|
119 |
|
|
byName.put("gYear", G_YEAR);
|
120 |
|
|
byName.put("gMonthDay", G_MONTH_DAY);
|
121 |
|
|
byName.put("gDay", G_DAY);
|
122 |
|
|
byName.put("gMonth",G_MONTH);
|
123 |
|
|
byName.put("hexBinary", HEX_BINARY);
|
124 |
|
|
byName.put("base64Binary", BASE64_BINARY);
|
125 |
|
|
byName.put("anyURI", ANY_URI);
|
126 |
|
|
byName.put("QName", QNAME);
|
127 |
|
|
byName.put("NOTATION", NOTATION);
|
128 |
|
|
byName.put("normalizedString", NORMALIZED_STRING);
|
129 |
|
|
byName.put("token", TOKEN);
|
130 |
|
|
byName.put("language", LANGUAGE);
|
131 |
|
|
byName.put("NMTOKEN", NMTOKEN);
|
132 |
|
|
byName.put("NMTOKENS", NMTOKENS);
|
133 |
|
|
byName.put("Name", NAME);
|
134 |
|
|
byName.put("NCName", NCNAME);
|
135 |
|
|
byName.put("ID", ID);
|
136 |
|
|
byName.put("IDREF", IDREF);
|
137 |
|
|
byName.put("IDREFS", IDREFS);
|
138 |
|
|
byName.put("ENTITY", ENTITY);
|
139 |
|
|
byName.put("ENTITIES", ENTITIES);
|
140 |
|
|
byName.put("integer", INTEGER);
|
141 |
|
|
byName.put("nonPositiveInteger", NON_POSITIVE_INTEGER);
|
142 |
|
|
byName.put("negativeInteger", NEGATIVE_INTEGER);
|
143 |
|
|
byName.put("long", LONG);
|
144 |
|
|
byName.put("int", INT);
|
145 |
|
|
byName.put("short", SHORT);
|
146 |
|
|
byName.put("byte", BYTE);
|
147 |
|
|
byName.put("nonNegativeInteger", NON_NEGATIVE_INTEGER);
|
148 |
|
|
byName.put("unsignedLong", UNSIGNED_LONG);
|
149 |
|
|
byName.put("unsignedInt", UNSIGNED_INT);
|
150 |
|
|
byName.put("unsignedShort", UNSIGNED_SHORT);
|
151 |
|
|
byName.put("unsignedByte", UNSIGNED_BYTE);
|
152 |
|
|
byName.put("positiveInteger", POSITIVE_INTEGER);
|
153 |
|
|
}
|
154 |
|
|
|
155 |
|
|
public DatatypeBuilder createDatatypeBuilder(String baseTypeLocalName)
|
156 |
|
|
throws DatatypeException
|
157 |
|
|
{
|
158 |
|
|
SimpleType type = (SimpleType) byName.get(baseTypeLocalName);
|
159 |
|
|
if (type == null)
|
160 |
|
|
throw new DatatypeException("Unknown type name: " + baseTypeLocalName);
|
161 |
|
|
return new TypeBuilder(type);
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
public Datatype createDatatype(String typeLocalName)
|
165 |
|
|
throws DatatypeException
|
166 |
|
|
{
|
167 |
|
|
SimpleType type = (SimpleType) byName.get(typeLocalName);
|
168 |
|
|
if (type == null)
|
169 |
|
|
throw new DatatypeException("Unknown type name: " + typeLocalName);
|
170 |
|
|
return type;
|
171 |
|
|
}
|
172 |
|
|
|
173 |
|
|
}
|