You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ws.apache.org by aj...@apache.org on 2005/11/28 09:18:57 UTC
svn commit: r349397 - in /webservices/commons/trunk/XmlSchema:
src/org/apache/ws/commons/schema/XmlSchemaCollection.java
test-resources/allSimpleTypes.xsd test/tests/AllSimpleTypeTest.java
Author: ajith
Date: Mon Nov 28 00:17:53 2005
New Revision: 349397
URL: http://svn.apache.org/viewcvs?rev=349397&view=rev
Log:
1. Added support for all the built-in simple types - see http://www.w3.org/TR/2004/PER-xmlschema-2-20040318/datatypes.html#built-in-datatypes for the list of datatypes
2. Added a testcase and the relevant xsd resource - Note . This test resource is NOT complete. Needs to include all the derived types to test the schema fully
Added:
webservices/commons/trunk/XmlSchema/test-resources/allSimpleTypes.xsd
webservices/commons/trunk/XmlSchema/test/tests/AllSimpleTypeTest.java
Modified:
webservices/commons/trunk/XmlSchema/src/org/apache/ws/commons/schema/XmlSchemaCollection.java
Modified: webservices/commons/trunk/XmlSchema/src/org/apache/ws/commons/schema/XmlSchemaCollection.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/XmlSchema/src/org/apache/ws/commons/schema/XmlSchemaCollection.java?rev=349397&r1=349396&r2=349397&view=diff
==============================================================================
--- webservices/commons/trunk/XmlSchema/src/org/apache/ws/commons/schema/XmlSchemaCollection.java (original)
+++ webservices/commons/trunk/XmlSchema/src/org/apache/ws/commons/schema/XmlSchemaCollection.java Mon Nov 28 00:17:53 2005
@@ -20,6 +20,7 @@
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
+import org.apache.ws.commons.schema.constants.Constants;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
@@ -48,7 +49,7 @@
* Namespaces we know about. Each one has an equivalent XmlSchema.
*/
Map namespaces = new HashMap();
- /**
+ /**
* base URI is used as the base for loading the
* imports
*/
@@ -69,36 +70,70 @@
this.baseUri = baseUri;
}
+ /**
+ * This section should comply to the XMLSchema specification
+ * @see http://www.w3.org/TR/2004/PER-xmlschema-2-20040318/datatypes.html#built-in-datatypes
+ * todo - Some types may be missing.Need a thorough comparison with the mentioned document
+ * to fix it.
+ */
public void init() {
- XmlSchemaSimpleType type;
- type = new XmlSchemaSimpleType(xsd);
- type.setName("string");
- xsd.addType(type);
- type = new XmlSchemaSimpleType(xsd);
- type.setName("int");
- xsd.addType(type);
- type = new XmlSchemaSimpleType(xsd);
- type.setName("boolean");
- xsd.addType(type);
- type = new XmlSchemaSimpleType(xsd);
- type.setName("float");
- xsd.addType(type);
- type = new XmlSchemaSimpleType(xsd);
- type.setName("double");
- xsd.addType(type);
- type = new XmlSchemaSimpleType(xsd);
- type.setName("long");
- xsd.addType(type);
- type = new XmlSchemaSimpleType(xsd);
- type.setName("short");
- xsd.addType(type);
- type = new XmlSchemaSimpleType(xsd);
- type.setName("qname");
- xsd.addType(type);
+ //Primitive types
+ addSimpleType(xsd, Constants.XSD_STRING.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_BOOLEAN.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_FLOAT.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DOUBLE.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_QNAME.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DECIMAL.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DURATION.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DATE.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DATETIME.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_DAY.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_MONTH.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_MONTHDAY.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_YEAR.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_YEARMONTH.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NOTATION.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_HEXBIN.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_BASE64.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_ANYURI.getLocalPart());
+
+ //derived types from decimal
+ addSimpleType(xsd, Constants.XSD_LONG.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_SHORT.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_BYTE.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_INTEGER.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_INT.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_POSITIVEINTEGER.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NEGATIVEINTEGER.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NONPOSITIVEINTEGER.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NONNEGATIVEINTEGER.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_UNSIGNEDBYTE.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_UNSIGNEDINT.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_UNSIGNEDLONG.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_UNSIGNEDSHORT.getLocalPart());
+
+ //derived types from string
+ addSimpleType(xsd, Constants.XSD_NAME.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NCNAME.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NMTOKEN.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_NMTOKENS.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_ENTITY.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_ENTITIES.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_ID.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_IDREF.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_IDREFS.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_LANGUAGE.getLocalPart());
+ addSimpleType(xsd, Constants.XSD_TOKEN.getLocalPart());
namespaces.put(XmlSchema.SCHEMA_NS, xsd);
}
+ private void addSimpleType(XmlSchema schema,String typeName){
+ XmlSchemaSimpleType type;
+ type = new XmlSchemaSimpleType(schema);
+ type.setName(typeName);
+ schema.addType(type);
+ }
public XmlSchema read(Reader r, ValidationEventHandler veh) {
return read(new InputSource(r), veh);
}
Added: webservices/commons/trunk/XmlSchema/test-resources/allSimpleTypes.xsd
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/XmlSchema/test-resources/allSimpleTypes.xsd?rev=349397&view=auto
==============================================================================
--- webservices/commons/trunk/XmlSchema/test-resources/allSimpleTypes.xsd (added)
+++ webservices/commons/trunk/XmlSchema/test-resources/allSimpleTypes.xsd Mon Nov 28 00:17:53 2005
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
+ <!--
+ 3.2.1 string
+ 3.2.2 boolean
+ 3.2.3 decimal
+ 3.2.4 float
+ 3.2.5 double
+ 3.2.6 duration
+ 3.2.7 dateTime
+ 3.2.8 time
+ 3.2.9 date
+ 3.2.10 gYearMonth
+ 3.2.11 gYear
+ 3.2.12 gMonthDay
+ 3.2.13 gDay
+ 3.2.14 gMonth
+ 3.2.15 hexBinary
+ 3.2.16 base64Binary
+ 3.2.17 anyURI
+ 3.2.18 QName
+ 3.2.19 NOTATION
+
+ -->
+ <xs:element name="PrimitiveString" type="xs:string"/>
+ <xs:element name="PrimitiveBoolean" type="xs:boolean"/>
+ <xs:element name="PrimitiveDecimal" type="xs:decimal"/>
+ <xs:element name="PrimitiveFloat" type="xs:float"/>
+ <xs:element name="PrimitiveDouble" type="xs:double"/>
+ <xs:element name="PrimitiveDate" type="xs:date"/>
+ <xs:element name="PrimitiveDateTime" type="xs:dateTime"/>
+ <xs:element name="PrimitiveDuration" type="xs:duration"/>
+ <xs:element name="PrimitiveDay" type="xs:gDay"/>
+ <xs:element name="PrimitiveMonth" type="xs:gMonth"/>
+ <xs:element name="PrimitiveMonthDay" type="xs:gMonthDay"/>
+ <xs:element name="PrimitiveYear" type="xs:gYear"/>
+ <xs:element name="PrimitiveBase64Bin" type="xs:base64Binary"/>
+ <xs:element name="PrimitiveHexBin" type="xs:hexBinary"/>
+ <xs:element name="PrimitiveQName" type="xs:QName"/>
+ <xs:element name="PrimitiveNotation" type="xs:NOTATION"/>
+ <xs:element name="PrimitiveAnyURI" type="xs:anyURI"/>
+ <xs:element name="PrimitiveYearMonth" type="xs:gYearMonth"/>
+ <!--3.3.1 normalizedString
+ 3.3.2 token
+ 3.3.3 language
+ 3.3.4 NMTOKEN
+ 3.3.5 NMTOKENS
+ 3.3.6 Name
+ 3.3.7 NCName
+ 3.3.8 ID
+ 3.3.9 IDREF
+ 3.3.10 IDREFS
+ 3.3.11 ENTITY
+ 3.3.12 ENTITIES
+ 3.3.13 integer
+ 3.3.14 nonPositiveInteger
+ 3.3.15 negativeInteger
+ 3.3.16 long
+ 3.3.17 int
+ 3.3.18 short
+ 3.3.19 byte
+ 3.3.20 nonNegativeInteger
+ 3.3.21 unsignedLong
+ 3.3.22 unsignedInt
+ 3.3.23 unsignedShort
+ 3.3.24 unsignedByte
+ 3.3.25 positiveInteger
+
+-->
+ <xs:element name="DerivedPositiveInteger" type="xs:positiveInteger"/>
+ <xs:element name="DerivedByte" type="xs:byte"/>
+ <xs:element name="DerivedToken" type="xs:token"/>
+ <xs:element name="DerivedLanguage" type="xs:language"/>
+ <xs:element name="DerivedNMTOKEN" type="xs:NMTOKEN"/>
+ <xs:element name="DerivedNMTOKENS" type="xs:NMTOKENS"/>
+ <!-- todo Add the other types here -->
+</xs:schema>
Added: webservices/commons/trunk/XmlSchema/test/tests/AllSimpleTypeTest.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/XmlSchema/test/tests/AllSimpleTypeTest.java?rev=349397&view=auto
==============================================================================
--- webservices/commons/trunk/XmlSchema/test/tests/AllSimpleTypeTest.java (added)
+++ webservices/commons/trunk/XmlSchema/test/tests/AllSimpleTypeTest.java Mon Nov 28 00:17:53 2005
@@ -0,0 +1,56 @@
+package tests;
+
+import junit.framework.TestCase;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaType;
+
+import java.util.Iterator;
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class AllSimpleTypeTest extends TestCase {
+
+ public void testSimpleTypeSchemaGeneration() throws Exception {
+ //create a DOM document
+ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ Document doc = documentBuilderFactory.newDocumentBuilder().
+ parse("test-resources/allSimpleTypes.xsd");
+
+ XmlSchemaCollection schemaCol = new XmlSchemaCollection();
+ XmlSchema schema = schemaCol.read(doc,null);
+ assertNotNull(schema);
+
+ //loop through the schema elements and inspect the SchemaTypeObject
+ //if the type is registered, then getSchemaType should return a SchemaType
+ //object
+ Iterator values = schema.getElements().getValues();
+ while (values.hasNext()) {
+ XmlSchemaElement elt = (XmlSchemaElement) values.next();
+ XmlSchemaType schemaType = elt.getSchemaType();
+ assertNotNull(schemaType);
+
+ }
+
+
+ }
+}