You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jaxme-dev@ws.apache.org by jo...@apache.org on 2006/11/24 13:15:06 UTC

svn commit: r478855 [4/21] - in /webservices/jaxme/branches/MAVEN/jaxme-xs: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/ws/ src/main/java/org/apache/ws/jaxme/ src/main/java/org/apache/ws/jaxme/...

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSLogicalParser.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSLogicalParser.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSLogicalParser.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSLogicalParser.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,763 @@
+/*
+ * Copyright 2003, 2004  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.
+
+ */
+package org.apache.ws.jaxme.xs.impl;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.ws.jaxme.xs.SchemaTransformer;
+import org.apache.ws.jaxme.xs.XSContentHandler;
+import org.apache.ws.jaxme.xs.XSElement;
+import org.apache.ws.jaxme.xs.XSObjectFactory;
+import org.apache.ws.jaxme.xs.XSParser;
+import org.apache.ws.jaxme.xs.XSSchema;
+import org.apache.ws.jaxme.xs.parser.XSContext;
+import org.apache.ws.jaxme.xs.parser.XsSAXParser;
+import org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
+import org.apache.ws.jaxme.xs.util.LoggingContentHandler;
+import org.apache.ws.jaxme.xs.xml.XsAnyURI;
+import org.apache.ws.jaxme.xs.xml.XsEAnnotation;
+import org.apache.ws.jaxme.xs.xml.XsEImport;
+import org.apache.ws.jaxme.xs.xml.XsEInclude;
+import org.apache.ws.jaxme.xs.xml.XsENotation;
+import org.apache.ws.jaxme.xs.xml.XsERedefine;
+import org.apache.ws.jaxme.xs.xml.XsESchema;
+import org.apache.ws.jaxme.xs.xml.XsETopLevelSimpleType;
+import org.apache.ws.jaxme.xs.xml.XsNCName;
+import org.apache.ws.jaxme.xs.xml.XsObject;
+import org.apache.ws.jaxme.xs.xml.XsObjectFactory;
+import org.apache.ws.jaxme.xs.xml.XsQName;
+import org.apache.ws.jaxme.xs.xml.XsRedefinable;
+import org.apache.ws.jaxme.xs.xml.XsTAttribute;
+import org.apache.ws.jaxme.xs.xml.XsTAttributeGroup;
+import org.apache.ws.jaxme.xs.xml.XsTComplexType;
+import org.apache.ws.jaxme.xs.xml.XsTLocalElement;
+import org.apache.ws.jaxme.xs.xml.XsTNamedGroup;
+import org.apache.ws.jaxme.xs.xml.XsTSimpleExplicitGroup;
+import org.apache.ws.jaxme.xs.xml.XsTTopLevelElement;
+import org.w3c.dom.Node;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.LocatorImpl;
+
+
+/** <p>Implementation of a logical parser.</p>
+ *
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public class XSLogicalParser {
+	/** This class is used to ensure, that schemata aren't loaded
+	 * twice. It can also be used for preloading schemata.
+	 */
+	public static class AddedImport {
+		private final String targetNamespace, schemaLocation;
+		private final Node node;
+		/** Creates a new instance with the given target namespace and
+		 * schema location.
+		 * @param pTargetNamespace The schemas target namespace.
+		 * @param pSchemaLocation The schemas location.
+		 */
+		public AddedImport(XsAnyURI pTargetNamespace, String pSchemaLocation) {
+			this(pTargetNamespace == null ? "" : pTargetNamespace.toString(), pSchemaLocation);
+		}
+		/** Creates a new instance with the given target namespace and
+		 * schema location.
+		 * @param pTargetNamespace The schemas target namespace.
+		 * @param pSchemaLocation The schemas location.
+		 */
+		public AddedImport(String pTargetNamespace, String pSchemaLocation) {
+			this(pTargetNamespace, pSchemaLocation, null);
+		}
+		/** Creates a new instance with the given target namespace and
+		 * schema location. The schema isn't parsed from the location.
+		 * Instead, the supplied nodes contents should be used as a
+		 * schema.
+		 * @param pTargetNamespace The schemas target namespace.
+		 * @param pSchemaLocation The schemas location.
+		 * @param pNode The schemas contents as a DOM node.
+		 */
+		public AddedImport(String pTargetNamespace, String pSchemaLocation, Node pNode) {
+			targetNamespace = pTargetNamespace == null ? "" : pTargetNamespace.toString();
+			if (pSchemaLocation == null) {
+				throw new IllegalStateException("The schemaLocation must not be null.");
+			}
+			schemaLocation = pSchemaLocation;
+			node = pNode;
+		}
+		public boolean equals(Object pOther) {
+			if (pOther instanceof AddedImport) {
+				AddedImport other = (AddedImport) pOther;
+				return targetNamespace.equals(other.targetNamespace) &&
+				schemaLocation.equals(other.schemaLocation);
+			} else {
+				return false;
+			}
+		}
+		public int hashCode() {
+			return targetNamespace.hashCode() + schemaLocation.hashCode();
+		}
+		
+		/** Returns the imported schemas target namespace.
+		 */
+		public String getNamespace() {
+			return targetNamespace;
+		}
+		
+		/** Returns the URL, from which the schema is being loaded.
+		 * Returns null, if the schema is loaded from a DOM node.
+		 */
+		public String getSchemaLocation() {
+			return schemaLocation;
+		}
+		
+		/** Returns the DOM node, from which the schema is being loaded.
+		 * Returns null, if the schema is loaded from an URL.
+		 */
+		public Node getNode() {
+			return node;
+		}
+	}
+	
+	private boolean notValidating;
+	private List syntaxSchemas = new ArrayList();
+	private XsESchema[] syntaxSchemaArray;
+	private XSSchema schema;
+	private Set parsedSchemas;
+	private List addedImports = new ArrayList();
+	
+	protected XSContext getData() {
+		return XSParser.getRunningInstance().getContext();
+	}
+	
+	/** <p>Sets whether the parser is validating.</p>
+	 */
+	public void setValidating(boolean pValidating) {
+		notValidating = !pValidating;
+	}
+	
+	/** <p>Returns whether the parser is validating.</p>
+	 */
+	public boolean isValidating() {
+		return !notValidating;
+	}
+	
+	/** <p>Adds a schema being imported by the parser. This feature
+	 * is useful, if a schema silently assumes the presence of additional
+	 * datatypes. For example, a WSDL definition will contain references
+	 * to SOAP datatypes without explicit import.</p>
+	 * <p>In practice, the declaration will silently create an
+	 * "xs:import" node.</p>
+	 * @param pNamespace Matches the "xs:import" nodes "namespace" attribute.
+	 *   In particular it may be null, in which case the imported schema may
+	 *   not have a targetNamespace.
+	 * @param pSchemaLocation Matches the "xs:import" nodes "schemaLocation"
+	 *   attribute. In particular it may be null.
+	 */
+	public void addImport(String pNamespace, String pSchemaLocation) {
+		addedImports.add(new AddedImport(pNamespace, pSchemaLocation));
+	}
+	
+	/** <p>Adds a schema being imported by the parser. The schema is
+	 * provided as a DOM node. This feature is useful, if a schema
+	 * silently assumes the presence of additional datatypes. For
+	 * example, a WSDL definition will contain references to SOAP
+	 * datatypes without explicit import.</p>
+	 * @param pNamespace Matches the "xs:import" nodes "namespace"
+	 *   attribute. In particular it may be null, in which case the
+	 *   imported schema may not have a targetNamespace.
+	 * @param pSchemaLocation System ID of the schema being imported,
+	 * if known, or null. Knowing the system ID is important only,
+	 * if you need to prevent recursive parsing of schemata.
+	 * @param pSchema A DOM node with the schema being imported.
+	 */
+	public void addImport(String pNamespace, String pSchemaLocation, Node pSchema) {
+		addedImports.add(new XSLogicalParser.AddedImport(pNamespace, pSchemaLocation, pSchema));
+	}
+	
+	/** <p>Returns the array of added imports, typically empty.</p>
+	 */
+	public AddedImport[] getAddedImports() {
+		return (AddedImport[]) addedImports.toArray(new AddedImport[addedImports.size()]);
+	}
+	
+	/** <p>Returns the schema, which is currently being parsed.</p>
+	 */
+	public XSSchema getSchema() { return schema; }
+	
+	/** <p>Sets the schema, which is currently being parsed.</p>
+	 */
+	protected void setSchema(XSSchema pSchema) {
+		schema = pSchema;
+	}
+	
+	protected XsESchema parseSyntax(Node pNode) throws SAXException {
+		XSContext data = getData();
+		try {
+			XsObjectFactory factory = data.getXsObjectFactory();
+			XsESchema mySchema = factory.newXsESchema();
+			XsSAXParser xsSAXParser = factory.newXsSAXParser(mySchema);
+			addSyntaxSchema(mySchema);
+			try {
+				data.setCurrentContentHandler(xsSAXParser);
+				DOMSerializer ds = new DOMSerializer();
+				ds.serialize(pNode, xsSAXParser);
+				return (XsESchema) xsSAXParser.getBean();
+			} finally {
+				removeSyntaxSchema();
+			}
+		} finally {
+			data.setCurrentContentHandler(null);
+		}
+	}
+	
+	/** <p>Converts the given URI into an instance of InputSource.</p>
+	 */
+	protected InputSource getInputSource(String pReferencingSystemId, String pURI) throws SAXException {
+		URL url = null;
+		if (pReferencingSystemId != null) {
+			// Try to create the new URI based on the old URI; may be its relative?
+			try {
+				url = new URL(new URL(pReferencingSystemId), pURI);
+			} catch (MalformedURLException e) {
+			}
+			
+			if (url == null) {
+				try {
+					url = new File(new File(pReferencingSystemId).getParentFile(), pURI).toURL();
+				} catch (MalformedURLException e) {
+				}
+			}
+		}
+		
+		if (url == null) {
+			try {
+				url = new URL(pURI);
+			} catch (MalformedURLException e) {
+				try {
+					url = new File(pURI).toURL();
+				} catch (MalformedURLException f) {
+					throw new SAXException("Failed to parse the URI " + pURI);
+				}
+			}
+		}
+		
+		try {
+			InputSource isource = new InputSource(url.openStream());
+			isource.setSystemId(url.toString());
+			return isource;
+		} catch (IOException e) {
+			throw new SAXException("Failed to open the URL " + url, e);
+		}
+	}
+	
+	
+	protected XsESchema parseSyntax(Locator pLocator, String pSchemaLocation)
+	throws SAXException, IOException, ParserConfigurationException {
+		XsESchema result = getData().getXsObjectFactory().newXsESchema();
+		parseSyntax(pLocator, pSchemaLocation, result);
+		return result;
+	}
+
+	private void runContentHandler(XMLReader pReader, ContentHandler pHandler, InputSource pSource)
+			throws SAXException, IOException {
+		String logDir = System.getProperty("org.apache.ws.jaxme.xs.logDir");
+		FileOutputStream fos = null;
+		try {
+			SchemaTransformer transformer = getData().getXSObjectFactory().getSchemaTransformer();
+			if (transformer != null) {
+				transformer.parse(pSource, pReader);
+				final InputSource newSource = transformer.getTransformedInputSource();
+				newSource.setSystemId(pSource.getSystemId());
+				newSource.setPublicId(pSource.getPublicId());
+				pSource = newSource;
+				pReader = transformer.getTransformedXMLReader();
+			}
+			if (logDir != null) {
+				File tmpFile = File.createTempFile("jaxmexs", ".xsd", new File(logDir));
+				fos = new FileOutputStream(tmpFile);
+				LoggingContentHandler lch = new LoggingContentHandler(fos);
+				lch.setParent(pReader);
+				pReader = lch;
+				String msg = "Read from " + pSource.getPublicId() + ", " + pSource.getSystemId() + " at " + new Date();
+				lch.comment(msg.toCharArray(), 0, msg.length());
+			}
+			pReader.setContentHandler(pHandler);
+			LocatorImpl loc = new LocatorImpl();
+			loc.setSystemId(pSource.getSystemId());
+			loc.setPublicId(pSource.getPublicId());
+            loc.setLineNumber(-1);
+            loc.setColumnNumber(-1);
+			pHandler.setDocumentLocator(loc);
+			pReader.parse(pSource);
+			if (fos != null) {
+				fos.close();
+				fos = null;
+			}
+		} catch (ParserConfigurationException e) {
+			throw new SAXException(e);
+		} finally {
+			if (fos != null) {
+				try { fos.close(); } catch (Throwable ignore) {}
+			}
+		}
+	}
+
+	protected void parseSyntax(Locator pLocator, String pSchemaLocation,
+			XsESchema pSchema)
+	throws SAXException, IOException, ParserConfigurationException {
+		XSContext data = getData();
+		try {
+			XsObjectFactory factory = data.getXsObjectFactory();
+			XMLReader xr = factory.newXMLReader(isValidating());
+			EntityResolver entityResolver = xr.getEntityResolver();
+			InputSource schemaSource = null;
+			if (entityResolver != null) {
+				schemaSource = entityResolver.resolveEntity(null, pSchemaLocation);
+			}
+			if (schemaSource == null) {
+				schemaSource = getInputSource(pLocator == null ? null : pLocator.getSystemId(),
+						pSchemaLocation);
+			}
+			
+			XsSAXParser xsSAXParser = factory.newXsSAXParser(pSchema);
+			addSyntaxSchema(pSchema);
+			try {
+				data.setCurrentContentHandler(xsSAXParser);
+				runContentHandler(xr, xsSAXParser, schemaSource);
+			} finally {
+				removeSyntaxSchema();
+			}
+		} finally {
+			data.setCurrentContentHandler(null);
+		}
+	}
+	
+	/** <p>Redefines the given {@link XsRedefinable}.</p>
+	 */
+	protected void redefine(XsESchema pSyntaxSchema,
+			XsERedefine pRedefine, XsRedefinable pChild) throws SAXException {
+		XSSchema mySchema = getSchema();
+		XSContext data = getData();
+		XSObjectFactory factory = data.getXSObjectFactory();
+		if (pChild instanceof XsTAttributeGroup) {
+			XsTAttributeGroup attributeGroup = (XsTAttributeGroup) pChild;
+			mySchema.redefine(factory.newXSAttributeGroup(mySchema, attributeGroup));
+		} else if (pChild instanceof XsTNamedGroup) {
+			XsTNamedGroup group = (XsTNamedGroup) pChild;
+			mySchema.redefine(factory.newXSGroup(mySchema, group));
+		} else if (pChild instanceof XsETopLevelSimpleType) {
+			XsETopLevelSimpleType type = (XsETopLevelSimpleType) pChild;
+			mySchema.redefine(factory.newXSType(mySchema, type));
+		} else if (pChild instanceof XsTComplexType) {
+			XsTComplexType type = (XsTComplexType) pChild;
+			mySchema.redefine(factory.newXSType(mySchema, type));
+		} else {
+			Locator locator = (pChild instanceof XsObject) ? ((XsObject) pChild).getLocator() : pRedefine.getLocator();
+			throw new LocSAXException("Unknown type for redefinition: " + pChild.getClass().getName() +
+					", perhaps you should handle this in a subclass?", locator);
+		}
+	}
+	
+	
+	
+	/** <p>Adds the given object to the schema.</p>
+	 * 
+	 */
+	protected void add(XsESchema pSyntaxSchema, Object pChild) throws SAXException {
+		XSSchema mySchema = getSchema();
+		XSContext data = getData();
+		XSObjectFactory factory = data.getXSObjectFactory();
+		if (pChild instanceof XsEAnnotation) {
+			XsEAnnotation annotation = (XsEAnnotation) pChild;
+			mySchema.add(factory.newXSAnnotation(mySchema, annotation));
+		} else if (pChild instanceof XsETopLevelSimpleType) {
+			XsETopLevelSimpleType type = (XsETopLevelSimpleType) pChild;
+			mySchema.add(factory.newXSType(mySchema, type));
+		} else if (pChild instanceof XsTComplexType) {
+			XsTComplexType type = (XsTComplexType) pChild;
+			mySchema.add(factory.newXSType(mySchema, type));
+		} else if (pChild instanceof XsTNamedGroup) {
+			XsTNamedGroup group = (XsTNamedGroup) pChild;
+			mySchema.add(factory.newXSGroup(mySchema, group));
+		} else if (pChild instanceof XsTAttributeGroup) {
+			XsTAttributeGroup attributeGroup = (XsTAttributeGroup) pChild;
+			mySchema.add(factory.newXSAttributeGroup(mySchema, attributeGroup));
+		} else if (pChild instanceof XsTTopLevelElement) {
+			XsTTopLevelElement element = (XsTTopLevelElement) pChild;
+			mySchema.add(factory.newXSElement(mySchema, element));
+		} else if (pChild instanceof XsTAttribute) {
+			XsTAttribute attribute = (XsTAttribute) pChild;
+			mySchema.add(factory.newXSAttribute(mySchema, attribute));
+		} else if (pChild instanceof XsENotation) {
+			XsENotation notation = (XsENotation) pChild;
+			mySchema.add(factory.newXSNotation(mySchema, notation));
+		} else {
+			Locator locator = (pChild instanceof XsObject) ?
+					((XsObject) pChild).getLocator() : pSyntaxSchema.getLocator();
+					throw new LocSAXException("Unknown child type: " + pChild.getClass().getName() +
+							", perhaps you should handle this in a subclass?", locator);
+		}
+	}
+	
+	/** <p>Handles xs:refefine.</p>
+	 */
+	protected void redefineSchema(XsESchema pRedefiningSchema,
+			XsERedefine pRedefine)
+	throws SAXException, IOException, ParserConfigurationException {
+		// TODO: Implement redefine
+		throw new LocSAXException("Redefine isn't yet implemented.", pRedefine.getLocator());
+	}
+	
+	/** <p>Handles xs:include.</p>
+	 */
+	protected void includeSchema(XsESchema pIncludingSchema,
+			XsEInclude pInclude, Locator pLocator,
+			String pSchemaLocation)
+	throws SAXException, IOException, ParserConfigurationException {
+		final XsAnyURI schemaLocation = pInclude.getSchemaLocation();
+		if (schemaLocation == null) {
+			throw new LocSAXException("Invalid include: Missing 'schemaLocation' attribute.",
+					pInclude.getLocator());
+		}
+		XsESchema includedSchema = parseSyntax(pLocator, schemaLocation.toString());
+		XsAnyURI incNamespace = includedSchema.getTargetNamespace();
+		if (incNamespace == null) {
+			if (pIncludingSchema.getTargetNamespace() != null) {
+				includedSchema.setTargetNamespace(pIncludingSchema.getTargetNamespace());
+			}
+		} else {
+			XsAnyURI myNamespace = includedSchema.getTargetNamespace();
+			if (!incNamespace.equals(myNamespace)) {
+				throw new LocSAXException("Invalid include: The included schemas target namespace " +
+						incNamespace + " and the including schemas target namespace " +
+						myNamespace + " do not match.",
+						pInclude.getLocator());
+			}
+		}
+		parse(includedSchema, pSchemaLocation);
+	}
+	
+	private void checkValidImportSchema(XsESchema pImportingSchema, String pNamespace,
+			Locator pLocator)
+	throws SAXException {
+		if (pNamespace == null) {
+			if (pImportingSchema.getTargetNamespace() == null) {
+				throw new LocSAXException("The importing schema has no 'targetNamespace' attribute and" +
+						" the 'import' element has no 'namespace' attribute, which is" +
+						" forbidden. Perhaps you want to use include?",
+						pLocator);
+			}
+		} else {
+			if ("".equals(pNamespace)) {
+				throw new LocSAXException("Invalid import: Empty 'namespace' attribute, which is forbidden." +
+						" Perhaps you want to omit the attribute to indicate the absence of a namespace?",
+						pLocator);
+			}
+			XsAnyURI targetNamespace = pImportingSchema.getTargetNamespace();
+			if (targetNamespace != null  &&
+					pNamespace.equals(targetNamespace.toString())) {
+				throw new LocSAXException("The importing schema and the imported schema have the same namespace, which is forbidden. Perhaps you want to use include?",
+						pLocator);
+			}
+		}
+	}
+	
+	private void importSchema(XsESchema pImportingSchema, String pNamespace,
+			XsESchema pImportedSchema, Locator pLocator,
+			String pSchemaLocation)
+	throws SAXException, ParserConfigurationException, IOException {
+		XsAnyURI impNamespace = pImportedSchema.getTargetNamespace();
+		if (pNamespace == null) {
+			if (impNamespace != null) {
+				throw new LocSAXException("The 'import' element does not have a 'namespace' attribute, but the imported schema has target namespace " +
+						impNamespace + ", it ought to match and have none.",
+						pLocator);
+			}
+		} else {
+			if (impNamespace == null) {
+				throw new LocSAXException("The 'import' element has a 'namespace' attribute (" + pNamespace +
+						"), but the imported schema has no 'targetNamespace' attribute.",
+						pLocator);
+			} else if (!pNamespace.equals(impNamespace.toString())) {
+				throw new LocSAXException("The 'import' elements 'namespace' attribute (" + pNamespace +
+						") and the imported schemas 'targetNamespace' attribute (" +
+						impNamespace + ") do not match.",
+						pLocator);
+			}
+		}
+		parse(pImportedSchema, pSchemaLocation);
+	}
+	
+	/** <p>Handles xs:import.</p>
+	 */
+	protected void importSchema(XsESchema pImportingSchema,
+			String pNamespace, String pSchemaLocation,
+			Locator pLocator)
+	throws SAXException, IOException, ParserConfigurationException {
+		if (pSchemaLocation == null) {
+			return;
+		}
+		checkValidImportSchema(pImportingSchema, pNamespace, pLocator);
+		
+		XsESchema importedSchema = parseSyntax(pLocator, pSchemaLocation);
+		importSchema(pImportingSchema, pNamespace, importedSchema, pLocator, pSchemaLocation);
+	}
+	
+	protected void importSchema(XsESchema pImportingSchema, String pNamespace, Node pNode,
+			String pSchemaLocation)
+	throws SAXException, IOException, ParserConfigurationException {
+		checkValidImportSchema(pImportingSchema, pNamespace, null);
+		XsESchema importedSchema = parseSyntax(pNode);
+		importSchema(pImportingSchema, pNamespace, importedSchema, null, pSchemaLocation);
+	}
+
+	/** <p>Parses the given {@link InputSource} syntactically and
+	 * converts the objects that it finds into logical objects.
+	 * These logical objects are added to the given {@link XSSchema}.</p>
+	 */
+	protected void parse(XsESchema pSyntaxSchema, String pSchemaLocation)
+			throws ParserConfigurationException, SAXException, IOException {
+		if (pSchemaLocation != null) {
+			AddedImport schema = new AddedImport(pSyntaxSchema.getTargetNamespace(),
+									 			 pSchemaLocation);
+			if (parsedSchemas == null) {
+				parsedSchemas = new HashSet();
+			} else if (parsedSchemas.contains(schema)) {
+				return; // Already imported/included, ignore it
+			}
+			parsedSchemas.add(schema);
+
+			for (int i = 0;  i < addedImports.size();  i++) {
+				AddedImport addedImport = (AddedImport) addedImports.get(i);
+				if (schema.equals(addedImport)) {
+					return;
+				}
+			}
+		}
+		addSyntaxSchema(pSyntaxSchema);
+		try {
+			Object[] childs = pSyntaxSchema.getChilds();
+
+			for (int i = 0;  i < childs.length;  i++) {
+				Object o = childs[i];
+				if (o instanceof XsEInclude) {
+					XsEInclude xsEInclude = (XsEInclude) o;
+					XsAnyURI schemaLocation = xsEInclude.getSchemaLocation();
+					includeSchema(pSyntaxSchema, xsEInclude,
+							getImportLocator(xsEInclude, pSchemaLocation),
+							schemaLocation == null ? null : schemaLocation.toString());
+				} else if (o instanceof XsERedefine) {
+					redefineSchema(pSyntaxSchema, (XsERedefine) o);
+				} else if (o instanceof XsEImport) {
+					XsEImport xsEImport = (XsEImport) o;
+					XsAnyURI namespace = xsEImport.getNamespace();
+					XsAnyURI schemaLocation = xsEImport.getSchemaLocation();
+					importSchema(pSyntaxSchema, namespace == null ? null : namespace.toString(),
+							schemaLocation == null ? null : schemaLocation.toString(),
+									getImportLocator(xsEImport, pSchemaLocation));
+				} else {
+					add(pSyntaxSchema, childs[i]);
+				}
+			}
+		} finally {
+			removeSyntaxSchema();
+		}
+	}
+
+	private Locator getImportLocator(XsObject pObject, String pSchemaLocation) {
+		Locator result = pObject.getLocator();
+		if (result == null  &&  pSchemaLocation != null) {
+			LocatorImpl loc = new LocatorImpl();
+			loc.setSystemId(pSchemaLocation);
+			result = loc;
+		}
+		return result;
+	}
+	
+	
+	private static class SubstitutionGroup {
+		private final List members = new ArrayList();
+		private final XSElement head;
+		
+		SubstitutionGroup(XSElement pHead) {
+			head = pHead;
+		}
+		XSElement getHead() { return head; }
+		XSElement[] getMembers() {
+			return (XSElement[]) members.toArray(new XSElement[members.size()]);
+		}
+		void addMember(XSElement pElement) {
+			members.add(pElement);
+		}
+	}
+	
+	protected void createSubstitutionGroups(XSSchema pSchema) throws SAXException {
+		Object[] myChilds = pSchema.getChilds();
+		
+		// Build the Map of substitution groups.
+		Map substitutionGroups = new HashMap();
+		for (int i = 0;  i < myChilds.length;  i++) {
+			if (myChilds[i] instanceof XSElement) {
+				XSElement element = (XSElement) myChilds[i];
+				XsQName qName = element.getSubstitutionGroupName();
+				if (qName != null) {
+					SubstitutionGroup group = (SubstitutionGroup) substitutionGroups.get(qName);
+					if (group == null) {
+						XSElement head = pSchema.getElement(qName);
+						if (head == null) {
+							throw new LocSAXException("The substituted element " + qName + " is missing in the schema.",
+									element.getLocator());
+						}
+						if (head.isBlockedForSubstitution()) {
+							throw new LocSAXException("The substituted element " + qName + " is blocked for substitution.",
+									element.getLocator());
+						}
+						group = new SubstitutionGroup(head);
+						if (!head.isAbstract()) {
+							group.addMember(head);
+						}
+						substitutionGroups.put(qName, group);
+					}
+					group.addMember(element);
+				}
+			}
+		}
+		
+		// For any substitution group: Build an implicit choice group, which
+		// may be used to replace the substitution groups head, if required.
+		for (Iterator iter = substitutionGroups.values().iterator();  iter.hasNext();  ) {
+			SubstitutionGroup group = (SubstitutionGroup) iter.next();
+			XSElementImpl head = (XSElementImpl) group.getHead();
+			XsObject object = head.getXsObject();
+			XsESchema syntaxSchema = object.getXsESchema();
+			
+			// Find a name for the group
+			String namespace = syntaxSchema.getTargetNamespace().toString();
+			String localName = head.getName().getLocalName() + "Group";
+			XsQName suggestion = new XsQName(namespace, localName);
+			if (pSchema.getGroup(suggestion) != null) {
+				for (int i = 0;  ;  i++) {
+					suggestion = new XsQName(namespace, localName + i);
+					if (pSchema.getGroup(suggestion) == null) {
+						break;
+					}
+				}
+			}
+			
+			XsTNamedGroup namedGroup = object.getObjectFactory().newXsTNamedGroup(syntaxSchema);
+			namedGroup.setName(new XsNCName(suggestion.getLocalName()));
+			XsTSimpleExplicitGroup choice = namedGroup.createChoice();
+			XSElement[] members = group.getMembers();
+			for (int j = 0;  j < members.length;  j++) {
+				XSElement member = members[j];
+				XsTLocalElement memberElement = choice.createElement();
+				memberElement.setRef(member.getName());
+			}
+			
+			XSGroupImpl xsGroup = (XSGroupImpl) getSchema().getXSObjectFactory().newXSGroup(pSchema, namedGroup);
+			pSchema.add(xsGroup);
+			head.setSubstitutionGroup(xsGroup);
+		}
+	}
+	
+	/** <p>This is the logical parsers frontend for parsing a stream
+	 * of SAX events.</p>
+	 * @param pSystemId System Id (schema location of the schema being parsed, if known.
+	 * Null otherwise. Knowing the system id is important only, if you want
+	 * to prevent recursive includes.
+	 */
+	public XSContentHandler getXSContentHandler(String pSystemId) throws SAXException {
+		return new XSContentHandlerImpl(this, pSystemId);
+	}
+	
+	/** <p>This is the logical parsers frontend for parsing a DOM node.</p>
+	 */
+	public XSSchema parse(Node pNode) throws SAXException {
+		XSContentHandler handler = getXSContentHandler(null);
+		DOMSerializer ds = new DOMSerializer();
+		ds.serialize(pNode, handler);
+		return handler.getXSSchema();
+	}
+	
+	/** <p>This is the logical parsers frontend for parsing the given
+	 * {@link InputSource}. If the parsed schema includes or imports other
+	 * schemas, they are also parsed and added to the parsers object
+	 * tree.</p>
+	 * @see #getXSContentHandler()
+	 */
+	public XSSchema parse(InputSource pSource)
+			throws ParserConfigurationException, SAXException, IOException {
+		XSContentHandler contentHandler = getXSContentHandler(pSource.getSystemId());
+		XSContext data = getData();
+		XMLReader xr = data.getXsObjectFactory().newXMLReader(isValidating());
+		runContentHandler(xr, contentHandler, pSource);
+		return getSchema();
+	}
+	
+	protected void clearSyntaxSchemas() {
+		syntaxSchemas.clear();
+		syntaxSchemaArray = null;
+	}
+	
+	protected void addSyntaxSchema(XsESchema pSyntaxSchema) {
+		syntaxSchemas.add(pSyntaxSchema);
+		syntaxSchemaArray = null;
+	}
+	
+	protected void removeSyntaxSchema() {
+		syntaxSchemas.remove(syntaxSchemas.size()-1);
+		syntaxSchemaArray = null;
+	}
+	
+	/** <p>Provides context information to the schema which is currently being parsed.
+	 * The schema with index 0 is the outermost schema, on which the parser is actually
+	 * invoked.</p>
+	 */
+	public XsESchema[] getSyntaxSchemas() {
+		if (syntaxSchemaArray == null) {
+			syntaxSchemaArray = (XsESchema[]) syntaxSchemas.toArray(new XsESchema[syntaxSchemas.size()]);
+		}
+		return syntaxSchemaArray;
+	}
+	
+	/** <p>Returns the syntax schema, which is currently being parsed.</p>
+	 */
+	public XsESchema getCurrentSyntaxSchema() {
+		if (syntaxSchemaArray == null  ||  syntaxSchemaArray.length == 0) {
+			return null;
+		} else {
+			return syntaxSchemaArray[syntaxSchemaArray.length-1];
+		}
+	}
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSModelGroupImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSModelGroupImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSModelGroupImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSModelGroupImpl.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2003, 2004  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.
+
+ */
+package org.apache.ws.jaxme.xs.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.ws.jaxme.xs.XSModelGroup;
+import org.apache.ws.jaxme.xs.XSParticle;
+import org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+
+/**
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public class XSModelGroupImpl implements XSModelGroup {
+  private final XSModelGroup.Compositor compositor;
+  private final List particles = new ArrayList();
+  private final Locator locator;
+
+  public XSModelGroupImpl(XSModelGroup.Compositor pCompositor, Locator pLocator) {
+    if (pCompositor == null) {
+      throw new NullPointerException("The model group compositor must not be null.");
+    }
+    compositor = pCompositor;
+    locator = pLocator;
+  }
+
+  public Compositor getCompositor() {
+    return compositor;
+  }
+
+  public boolean isSequence() {
+    return XSModelGroup.SEQUENCE.equals(compositor);
+  }
+
+  public boolean isChoice() {
+    return XSModelGroup.CHOICE.equals(compositor);
+  }
+
+  public boolean isAll() {
+    return XSModelGroup.ALL.equals(compositor);
+  }
+
+  public void addParticle(XSParticle pParticle) throws SAXException {
+    if (isAll()) {
+      if (pParticle.getMaxOccurs() == -1  ||  pParticle.getMaxOccurs() > 1) {
+        throw new LocSAXException("Illegal 'maxOccurs' value inside 'all' group: " + pParticle.getMaxOccurs(),
+                                     pParticle.getLocator());
+      }
+    }
+    if (pParticle.getMaxOccurs() != -1  &&  pParticle.getMaxOccurs() < pParticle.getMinOccurs()) {
+      throw new LocSAXException("Illegal 'maxOccurs' value, which is lower than 'minOccurs' value: " +
+                                   pParticle.getMaxOccurs() + " < " + pParticle.getMinOccurs(),
+                                   pParticle.getLocator());
+    }
+    particles.add(pParticle);
+  }
+
+  public XSParticle[] getParticles() {
+    return (XSParticle[]) particles.toArray(new XSParticle[particles.size()]);
+  }
+
+  public void validate() throws SAXException {
+    if (isChoice()  &&  particles.size() == 0) {
+      throw new LocSAXException("A 'choice' model group must have at least one 'group', 'any', or 'element'.",
+                                   getLocator());
+    }
+    for (Iterator iter = particles.iterator();  iter.hasNext();  ) {
+      XSParticle particle = (XSParticle) iter.next();
+      if (particle.isElement()) {
+        particle.getElement().validate();
+      } else if (particle.isGroup()) {
+        particle.getGroup().validate();
+      } else if (particle.isWildcard()) {
+        particle.getWildcard().validate();
+      } else {
+        throw new IllegalStateException("Invalid particle");
+      }
+    }
+  }
+
+  public Locator getLocator() {
+    return locator;
+  }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSNotationImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSNotationImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSNotationImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSNotationImpl.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2003, 2004  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.
+
+ */
+package org.apache.ws.jaxme.xs.impl;
+
+import org.apache.ws.jaxme.xs.XSNotation;
+import org.apache.ws.jaxme.xs.XSObject;
+import org.apache.ws.jaxme.xs.xml.XsObject;
+import org.xml.sax.SAXException;
+
+/**
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public class XSNotationImpl extends XSObjectImpl implements XSNotation {
+  protected XSNotationImpl(XSObject pParent, XsObject pBaseObject) {
+    super(pParent, pBaseObject);
+  }
+
+  public void validate() throws SAXException {
+  }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSObjectFactoryImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSObjectFactoryImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSObjectFactoryImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSObjectFactoryImpl.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,210 @@
+/*
+ * Copyright 2003, 2004  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.
+
+ */
+package org.apache.ws.jaxme.xs.impl;
+
+import org.apache.ws.jaxme.xs.SchemaTransformer;
+import org.apache.ws.jaxme.xs.XSAnnotation;
+import org.apache.ws.jaxme.xs.XSAny;
+import org.apache.ws.jaxme.xs.XSAppinfo;
+import org.apache.ws.jaxme.xs.XSAttribute;
+import org.apache.ws.jaxme.xs.XSAttributeGroup;
+import org.apache.ws.jaxme.xs.XSDocumentation;
+import org.apache.ws.jaxme.xs.XSElement;
+import org.apache.ws.jaxme.xs.XSEnumeration;
+import org.apache.ws.jaxme.xs.XSGroup;
+import org.apache.ws.jaxme.xs.XSIdentityConstraint;
+import org.apache.ws.jaxme.xs.XSKeyRef;
+import org.apache.ws.jaxme.xs.XSNotation;
+import org.apache.ws.jaxme.xs.XSObject;
+import org.apache.ws.jaxme.xs.XSObjectFactory;
+import org.apache.ws.jaxme.xs.XSSchema;
+import org.apache.ws.jaxme.xs.XSSimpleContentType;
+import org.apache.ws.jaxme.xs.XSSimpleType;
+import org.apache.ws.jaxme.xs.XSType;
+import org.apache.ws.jaxme.xs.XSWildcard;
+import org.apache.ws.jaxme.xs.parser.XSContext;
+import org.apache.ws.jaxme.xs.xml.*;
+import org.xml.sax.SAXException;
+
+
+/** <p>Default implementation of the {@link XSObjectFactory}.</p>
+ *
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public class XSObjectFactoryImpl implements XSObjectFactory {
+  private static final XSAnnotation[] NO_ANNOTATIONS = new XSAnnotation[] {};
+
+  public XSLogicalParser newXSLogicalParser() {
+    return new XSLogicalParser();
+  }
+
+  public XSSchema newXSSchema(XSContext pContext, XsESchema pSchema) throws SAXException {
+    return new XSSchemaImpl(pContext, pSchema);
+  }
+
+  public XSAnnotation newXSAnnotation(XSObject pParent, XsEAnnotation pAnnotation) throws SAXException {
+    return new XSAnnotationImpl(pParent, pAnnotation);
+  }
+
+  public XSAnnotation[] newXSAnnotations(XSObject pParent, XsEAnnotation pAnnotation) throws SAXException {
+    if ( pAnnotation == null ) {
+      return NO_ANNOTATIONS;
+    } else {
+      return new XSAnnotation[] { newXSAnnotation(pParent, pAnnotation) };
+    }
+  }
+
+
+  public XSAppinfo newXSAppinfo(XSObject pParent, XsEAppinfo pAppinfo) {
+    return new XSAppinfoImpl(pParent, pAppinfo);
+  }
+
+  public XSSimpleType newXSAtomicType(XSType pParent, XSType pRestrictedType, XsERestriction pRestriction) throws SAXException {
+    return new XSAtomicTypeRestrictionImpl(pParent, pRestrictedType, pRestriction);
+  }
+
+  public XSSimpleType newXSAtomicType(XSType pParent, XSType pRestrictedType, XsTSimpleRestrictionType pRestriction) throws SAXException {
+    return new XSAtomicTypeRestrictionImpl(pParent, pRestrictedType, pRestriction);
+  }
+
+  public XSAttribute newXSAttribute(XSObject pParent, XsTAttribute pAttribute) throws SAXException {
+    return new XSAttributeImpl(pParent, pAttribute);
+  }
+
+  public XSAttributeGroup newXSAttributeGroup(XSObject pParent, XsTAttributeGroup pGroup) throws SAXException {
+    return new XSAttributeGroupImpl(pParent, pGroup);
+  }
+
+  public XSDocumentation newXSDocumentation(XSObject pParent, XsEDocumentation pDocumentation) throws SAXException {
+    return new XSDocumentationImpl(pParent, pDocumentation);
+  }
+
+  public XSElement newXSElement(XSObject pParent, XsTElement pElement) throws SAXException {
+    return new XSElementImpl(pParent, pElement);
+  }
+
+  public XSEnumeration newXSEnumeration(XSObject pParent, XsEEnumeration pEnumeration) throws SAXException {
+    return new XSEnumerationImpl(pParent, pEnumeration);
+  }
+
+  public XSGroup newXSGroup(XSObject pParent, XsTAll pAll) throws SAXException {
+    return new XSGroupImpl(pParent, pAll);
+  }
+
+  public XSGroup newXSGroup(XSObject pParent, XsEChoice pChoice) throws SAXException {
+    return new XSGroupImpl(pParent, pChoice);
+  }
+
+  public XSGroup newXSGroup(XSObject pParent, XsESequence pSequence) throws SAXException {
+    return new XSGroupImpl(pParent, pSequence);
+  }
+
+  public XSGroup newXSGroup(XSObject pParent, XsTGroupRef pGroupRef) throws SAXException {
+    return new XSGroupImpl(pParent, pGroupRef);
+  }
+
+  public XSGroup newXSGroup(XSObject pParent, XsTNamedGroup pNamedGroup) throws SAXException {
+    return new XSGroupImpl(pParent, pNamedGroup);
+  }
+
+  public XSSimpleType newXSListType(XSType pParent, XsEList pList) throws SAXException {
+    return new XSListTypeImpl(pParent, pList);
+  }
+
+  public XSSimpleType newXSListType(XSType pParent, XSType pRestrictedType, XsERestriction pRestriction) throws SAXException {
+    return new XSListTypeRestrictionImpl(pParent, pRestrictedType, pRestriction);
+  }
+
+  public XSSimpleType newXSListType(XSType pParent, XSType pRestrictedType, XsTSimpleRestrictionType pRestriction) throws SAXException {
+    return new XSListTypeRestrictionImpl(pParent, pRestrictedType, pRestriction);
+  }
+
+  public XSType newXSType(XSObject pParent, XsETopLevelSimpleType pType) throws SAXException {
+    return new XSTypeImpl(pParent, pType);
+  }
+
+  public XSType newXSType(XSObject pParent, XsTComplexType pType) throws SAXException {
+    return new XSTypeImpl(pParent, pType);
+  }
+
+  public XSType newXSType(XSObject pParent, XsTLocalComplexType pType) throws SAXException {
+    return new XSTypeImpl(pParent, pType);
+  }
+
+  public XSType newXSType(XSObject pParent, XsTLocalSimpleType pType) throws SAXException {
+    return new XSTypeImpl(pParent, pType);
+  }
+
+  public XSType newXSType(XSObject pParent, XsTSimpleRestrictionType pType) throws SAXException {
+    return new XSTypeImpl(pParent, pType);
+  }
+
+  public XSSimpleType newXSUnionType(XSType pParent, XsEUnion pUnion) throws SAXException {
+    return new XSUnionTypeImpl(pParent, pUnion);
+  }
+
+  public XSSimpleType newXSUnionType(XSType pParent, XSType pRestrictedType, XsERestriction pRestriction) throws SAXException {
+    return new XSUnionTypeRestrictionImpl(pParent, pRestrictedType, pRestriction);
+  }
+
+  public XSSimpleType newXSUnionType(XSType pParent, XSType pRestrictedType, XsTSimpleRestrictionType pRestriction) throws SAXException {
+    return new XSUnionTypeRestrictionImpl(pParent, pRestrictedType, pRestriction);
+  }
+
+  public XSNotation newXSNotation(XSObject pParent, XsENotation pNotation) throws SAXException {
+    return new XSNotationImpl(pParent, pNotation);
+  }
+
+  public XSAny newXSAny(XSObject pParent, XsEAny pAny) throws SAXException {
+    return new XSAnyImpl(pParent, pAny);
+  }
+
+  public XSSimpleContentType newXSSimpleContentType(XSType pParent, XSType pSimpleType, XsObject pBaseType) throws SAXException {
+    return new XSSimpleContentTypeImpl(pParent, pSimpleType, pBaseType);
+  }
+
+  public XSWildcard newXSWildcard(XSObject pParent, XsTWildcard pWildcard) throws SAXException {
+    return new XSWildcardImpl(pParent, pWildcard);
+  }
+
+  public XSIdentityConstraint newXSIdentityConstraint( 
+    XSElement pParent, 
+    XsEKey key 
+  )
+    throws SAXException 
+  {
+    return new XSIdentityConstraintImpl( pParent, key );
+  }
+
+  public XSKeyRef newXSKeyRef( 
+    XSElement pParent, 
+    XsEKeyref keyRef 
+  ) throws SAXException {
+    return new XSKeyRefImpl( pParent, keyRef );
+  }
+
+  public XSIdentityConstraint newXSIdentityConstraint( 
+    XSElement pParent, 
+    XsEUnique unique 
+  ) throws SAXException {
+    return new XSIdentityConstraintImpl( pParent, unique );
+  }
+
+  public SchemaTransformer getSchemaTransformer() {
+	return null;
+  }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSObjectImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSObjectImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSObjectImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSObjectImpl.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2003, 2004  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.
+
+ */
+package org.apache.ws.jaxme.xs.impl;
+
+import org.apache.ws.jaxme.xs.XSObject;
+import org.apache.ws.jaxme.xs.XSSchema;
+import org.apache.ws.jaxme.xs.xml.XsObject;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+
+/**
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public abstract class XSObjectImpl implements XSObject {
+  private final XSObject parent;
+  private final XsObject baseObject;
+
+  protected XSObjectImpl(XSObject pParent, XsObject pBaseObject) {
+    if (pParent == null) {
+      if (!(this instanceof XSSchema)) {
+        throw new IllegalStateException("Null parents are allowed for XSSchema objects only.");
+      }
+    } else {
+      if (this instanceof XSSchema) {
+        throw new IllegalStateException("An XSSchema object must have a null parent.");
+      }
+    }
+    parent = pParent;
+    baseObject = pBaseObject;
+  }
+
+  public XSObject getParentObject() { return parent; }
+  public XSSchema getXSSchema() {
+    if (parent == null) {
+      return (XSSchema) this;
+    } else {
+      return parent.getXSSchema();
+    }
+  }
+  public boolean isTopLevelObject() { return parent == null  ||  parent instanceof XSSchema; }
+  public Locator getLocator() { return baseObject.getLocator(); }
+  protected XsObject getXsObject() { return baseObject; }
+  public void validate() throws SAXException {}
+
+
+  /**
+   * Utility method used to call validate() on every element within an 
+   * array.
+   *
+   * @param objects Array must not have any null elements.
+   */
+  protected final void validateAllIn( XSObject[] objects ) 
+    throws SAXException 
+  {
+    if ( objects == null ) {
+      return;
+    }
+
+    int numObjects = objects.length;
+
+    for ( int i=0; i<numObjects; i++ ) {
+      objects[i].validate();
+    }
+  }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSOpenAttrsImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSOpenAttrsImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSOpenAttrsImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSOpenAttrsImpl.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2003, 2004  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.
+ */
+ 
+package org.apache.ws.jaxme.xs.impl;
+
+import org.apache.ws.jaxme.xs.XSObject;
+import org.apache.ws.jaxme.xs.XSOpenAttrs;
+import org.apache.ws.jaxme.xs.xml.XsTOpenAttrs;
+import org.xml.sax.Attributes;
+
+
+/**
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public class XSOpenAttrsImpl extends XSObjectImpl implements XSOpenAttrs {
+  private final Attributes openAttributes;
+
+  public XSOpenAttrsImpl(XSObject pParent, XsTOpenAttrs pXsOpenAttrs) {
+    super(pParent, pXsOpenAttrs);
+    openAttributes = pXsOpenAttrs.getOpenAttributes();
+  }
+
+  public Attributes getOpenAttributes() {
+    return openAttributes;
+  }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSParticleImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSParticleImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSParticleImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSParticleImpl.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,137 @@
+/*
+ * Copyright 2003, 2004  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.
+
+ */
+package org.apache.ws.jaxme.xs.impl;
+
+import org.apache.ws.jaxme.xs.XSAny;
+import org.apache.ws.jaxme.xs.XSElement;
+import org.apache.ws.jaxme.xs.XSGroup;
+import org.apache.ws.jaxme.xs.XSParticle;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+
+/** <p>Default implementation of a particle.</p>
+ *
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public class XSParticleImpl implements XSParticle {
+  private final XSGroup group;
+  private final XSAny wildcard;
+  private final XSElement element;
+  private int minOccurs = 1;
+  private int maxOccurs = 1;
+
+  public XSParticleImpl(XSGroup pGroup) throws SAXException {
+    if (pGroup == null) {
+      throw new NullPointerException("The particle group must not be null.");
+    }
+    group = pGroup;
+    element = null;
+    wildcard = null;
+  }
+
+  public XSParticleImpl(XSAny pWildcard) {
+    if (pWildcard == null) {
+      throw new NullPointerException("The particle wildcard must not be null.");
+    }
+    wildcard = pWildcard;
+    group = null;
+    element = null;
+  }
+
+  public XSParticleImpl(XSElement pElement) {
+    if (pElement == null) {
+      throw new NullPointerException("The particle element must not be null.");
+    }
+    element = pElement;
+    group = null;
+    wildcard = null;
+  }
+
+  public XSParticle.Type getType() {
+    if (group != null) {
+      return XSParticle.GROUP;
+    } else if (wildcard != null) {
+      return XSParticle.WILDCARD;
+    } else if (element != null) {
+      return XSParticle.ELEMENT;
+    } else {
+      throw new IllegalStateException("Neither of the particle group, wildcard, or element has been set.");
+    }
+  }
+
+  public boolean isGroup() {
+    return group != null;
+  }
+
+  public XSGroup getGroup() {
+    if (group == null) {
+      throw new IllegalStateException("This particle doesn't have the group type.");
+    }
+    return group;
+  }
+
+  public boolean isWildcard() {
+    return wildcard != null;
+  }
+
+  public XSAny getWildcard() {
+    if (wildcard == null) {
+      throw new IllegalStateException("This particle doesn't have the wildcard type.");
+    }
+    return wildcard;
+  }
+
+  public boolean isElement() {
+    return element != null;
+  }
+
+  public XSElement getElement() {
+    if (element == null) {
+      throw new IllegalStateException("This particle doesn't have the element type.");
+    }
+    return element;
+  }
+
+  public int getMinOccurs() {
+    return minOccurs;
+  }
+
+  public void setMinOccurs(int pMinOccurs) {
+    minOccurs = pMinOccurs;
+  }
+
+  public int getMaxOccurs() {
+    return maxOccurs;
+  }
+
+  public void setMaxOccurs(int pMaxOccurs) {
+    maxOccurs = pMaxOccurs;
+  }
+
+  public Locator getLocator() {
+    if (isWildcard()) {
+      return getWildcard().getLocator();
+    } else if (isElement()) {
+      return getElement().getLocator();
+    } else if (isGroup()) {
+      return getGroup().getLocator();
+    } else {
+      throw new IllegalStateException("Invalid particle, neither of element, wildcard, or model group.");
+    }
+  }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSSchemaImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSSchemaImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSSchemaImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSSchemaImpl.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,463 @@
+/*
+ * Copyright 2003, 2004  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.
+
+ */
+package org.apache.ws.jaxme.xs.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import org.apache.ws.jaxme.xs.XSAnnotation;
+import org.apache.ws.jaxme.xs.XSAttribute;
+import org.apache.ws.jaxme.xs.XSAttributeGroup;
+import org.apache.ws.jaxme.xs.XSElement;
+import org.apache.ws.jaxme.xs.XSGroup;
+import org.apache.ws.jaxme.xs.XSIdentityConstraint;
+import org.apache.ws.jaxme.xs.XSKeyRef;
+import org.apache.ws.jaxme.xs.XSNotation;
+import org.apache.ws.jaxme.xs.XSObject;
+import org.apache.ws.jaxme.xs.XSObjectFactory;
+import org.apache.ws.jaxme.xs.XSSchema;
+import org.apache.ws.jaxme.xs.XSType;
+import org.apache.ws.jaxme.xs.parser.XSContext;
+import org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
+import org.apache.ws.jaxme.xs.types.*;
+import org.apache.ws.jaxme.xs.xml.XsAnyURI;
+import org.apache.ws.jaxme.xs.xml.XsESchema;
+import org.apache.ws.jaxme.xs.xml.XsQName;
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+
+/** <p>Implementation of an XML Schema, as defined by the
+ * {@link XSSchema} interface.</p>
+ *
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public class XSSchemaImpl implements XSSchema {
+  private static final XSType[] BUILTIN_TYPES = new XSType[]{
+    XSAnySimpleType.getInstance(),
+    XSAnyURI.getInstance(),
+    XSBase64Binary.getInstance(),
+    XSBoolean.getInstance(),
+    XSByte.getInstance(),
+    XSDate.getInstance(),
+    XSDateTime.getInstance(),
+    XSDecimal.getInstance(),
+    XSDouble.getInstance(),
+    XSDuration.getInstance(),
+    XSEntities.getInstance(),
+    XSEntity.getInstance(),
+    XSFloat.getInstance(),
+    XSGDay.getInstance(),
+    XSGMonth.getInstance(),
+    XSGMonthDay.getInstance(),
+    XSGYear.getInstance(),
+    XSGYearMonth.getInstance(),
+    XSHexBinary.getInstance(),
+    XSID.getInstance(),
+    XSIDREF.getInstance(),
+    XSIDREFs.getInstance(),
+    XSInt.getInstance(),
+    XSInteger.getInstance(),
+    XSLanguage.getInstance(),
+    XSLong.getInstance(),
+    XSName.getInstance(),
+    XSNCName.getInstance(),
+    XSNegativeInteger.getInstance(),
+    XSNMToken.getInstance(),
+    XSNMTokens.getInstance(),
+    XSNonNegativeInteger.getInstance(),
+    XSNonPositiveInteger.getInstance(),
+    XSNormalizedString.getInstance(),
+    org.apache.ws.jaxme.xs.types.XSNotation.getInstance(),
+    XSPositiveInteger.getInstance(),
+    XSQName.getInstance(),
+    XSShort.getInstance(),
+    XSString.getInstance(),
+    XSTime.getInstance(),
+    XSToken.getInstance(),
+    XSUnsignedByte.getInstance(),
+    XSUnsignedInt.getInstance(),
+    XSUnsignedLong.getInstance(),
+    XSUnsignedShort.getInstance(),
+    XSAnyType.getInstance()
+  };
+
+  private final XSContext context;
+  private final XsESchema syntaxSchema;
+  private final List childs = new ArrayList(1);
+  private final Map types = new HashMap(1);
+  private final Map builtinTypes = new HashMap(1);
+  private final Map groups = new HashMap(1);
+  private final Map attributeGroups = new HashMap(1);
+  private final Map attributes = new HashMap(1);
+  private final Map elements = new HashMap(1);
+  private final Attributes openAttrs;
+
+  private final Map identityConstraintsMap = new HashMap(1);
+  private final Map keyRefsMap = new HashMap(1);
+
+  private final Map immutableIdentityConstraintsMap 
+    = Collections.unmodifiableMap( identityConstraintsMap );
+  private final Map immutableKeyRefsMap = Collections.unmodifiableMap( 
+    keyRefsMap 
+  );
+
+  private boolean isValidated;
+
+  /** <p>Creates a new logical schema by loading data,
+   * which represents the given syntactical schema
+   * <code>pSchema</code> and uses the given context
+   * <code>pContext</code> for acquiring additional
+   * information.</p>
+   */
+  public XSSchemaImpl(XSContext pContext, XsESchema pSchema) {
+    context = pContext;
+    syntaxSchema = pSchema;
+    for (int i = 0;  i < BUILTIN_TYPES.length;  i++) {
+      builtinTypes.put(BUILTIN_TYPES[i].getName(), BUILTIN_TYPES[i]);
+    }
+    openAttrs = pSchema.getOpenAttributes();
+  }
+
+  public XSContext getContext() { return context; }
+  public boolean isTopLevelObject() { return true; }
+  public XSObject getParentObject() { return null; }
+  public XSObjectFactory getXSObjectFactory() { return context.getXSObjectFactory(); }
+  public Locator getLocator() { return syntaxSchema.getLocator(); }
+  public XSSchema getXSSchema() { return this; }
+  protected XsESchema getXsESchema() { return syntaxSchema; }
+
+  /** <p>Adds a new child to the array returned by {@link #getChilds()}.</p>
+   */
+  protected void addChild(Object pChild) {
+    childs.add(pChild);
+  }
+
+  /** <p>Replaces the existing child <code>pOldChild</code> with
+   * the replacement object <code>pNewChild</code>. This method
+   * is used from within the various <code>redefine()</code> methods.</p>
+   */
+  protected void replace(Object pOldChild, Object pNewChild) {
+    for (ListIterator iter = childs.listIterator();  iter.hasNext();  ) {
+      Object o = iter.next();
+      if (o.equals(pOldChild)) {
+        iter.set(pNewChild);
+        return;
+      }
+    }
+    throw new NoSuchElementException();
+  }
+
+  public XSAnnotation[] getAnnotations() {
+    List result = new ArrayList();
+    for (Iterator iter = childs.iterator();  iter.hasNext();  ) {
+      Object o = iter.next();
+      if (o instanceof XSAnnotation) {
+        result.add(o);
+      }
+    }
+    return (XSAnnotation[]) result.toArray(new XSAnnotation[result.size()]);
+  }
+
+  public XSType[] getTypes() {
+    List result = new ArrayList();
+    for (Iterator iter = childs.iterator();  iter.hasNext();  ) {
+      Object o = iter.next();
+      if (o instanceof XSType) {
+        result.add(o);
+      }
+    }
+    return (XSType[]) result.toArray(new XSType[result.size()]);
+  }
+
+  public XSType[] getBuiltinTypes() {
+    return BUILTIN_TYPES;
+  }
+
+  public XSType getType(XsQName pName) {
+    XSType result = (XSType) types.get(pName);
+    if (result == null) {
+      result = (XSType) builtinTypes.get(pName);
+    }
+    return result;
+  }
+
+  public XSGroup[] getGroups() {
+    List result = new ArrayList();
+    for (Iterator iter = childs.iterator();  iter.hasNext();  ) {
+      Object o = iter.next();
+      if (o instanceof XSGroup) {
+        result.add(o);
+      }
+    }
+    return (XSGroup[]) result.toArray(new XSGroup[result.size()]);
+  }
+
+  public XSGroup getGroup(XsQName pName) {
+    return (XSGroup) groups.get(pName);
+  }
+
+  public XSAttributeGroup[] getAttributeGroups() {
+    List result = new ArrayList();
+    for (Iterator iter = childs.iterator();  iter.hasNext();  ) {
+      Object o = iter.next();
+      if (o instanceof XSAttributeGroup) {
+        result.add(o);
+      }
+    }
+    return (XSAttributeGroup[]) result.toArray(new XSAttributeGroup[result.size()]);
+  }
+
+  public XSAttributeGroup getAttributeGroup(XsQName pName) {
+    return (XSAttributeGroup) attributeGroups.get(pName);
+  }
+
+  public XSElement[] getElements() {
+    List result = new ArrayList();
+    for (Iterator iter = childs.iterator();  iter.hasNext();  ) {
+      Object o = iter.next();
+      if (o instanceof XSElement) {
+        result.add(o);
+      }
+    }
+    return (XSElement[]) result.toArray(new XSElement[result.size()]);
+  }
+
+  public XSElement getElement(XsQName pName) {
+    return (XSElement) elements.get(pName);
+  }
+
+  public Map getIdentityConstraints() {
+    return immutableIdentityConstraintsMap;
+  }
+
+  public Map getKeyRefs() {
+    return immutableKeyRefsMap;
+  }
+
+  public void add( XSIdentityConstraint ic ) throws SAXException {
+    String name = ic.getName();
+
+    if ( name == null ) {
+      throw new LocSAXException(
+        "An identity constraint must have a 'name' attribute.", 
+        ic.getLocator()
+      );
+    } else if ( identityConstraintsMap.put( name, ic ) != null ) {
+      throw new LocSAXException(
+        "No two identity constraints may share the same name.", 
+        ic.getLocator()
+      );
+    }
+
+    identityConstraintsMap.put( name, ic );
+  }
+
+  public void add( XSKeyRef rf ) throws SAXException {
+    String name = rf.getName();
+
+    if ( name == null ) {
+      throw new LocSAXException(
+        "A key ref must have a 'name' attribute.", 
+        rf.getLocator()
+      );
+    } else if ( keyRefsMap.put( name, rf ) != null ) {
+      throw new LocSAXException(
+        "No two key refs may share the same name.", 
+        rf.getLocator()
+      );
+    }
+
+    keyRefsMap.put( name, rf );
+  }
+
+
+
+  public XSAttribute[] getAttributes() {
+    List result = new ArrayList();
+    for (Iterator iter = childs.iterator();  iter.hasNext();  ) {
+      Object o = iter.next();
+      if (o instanceof XSAttribute) {
+        result.add(o);
+      }
+    }
+    return (XSAttribute[]) result.toArray(new XSAttribute[result.size()]);
+  }
+
+  public XSAttribute getAttribute(XsQName pQName) {
+    return (XSAttribute) attributes.get(pQName);
+  }
+
+  public void add(XSAnnotation pAnnotation) {
+    addChild(pAnnotation);
+  }
+
+  public void add(XSType pType) throws SAXException {
+    XsQName name = pType.getName();
+    if (name == null) {
+      throw new LocSAXException("A global type must have a 'name' attribute.", pType.getLocator());
+    }
+    if (types.containsKey(name)) {
+      throw new LocSAXException("A global type " + name + " is already defined.", pType.getLocator());
+    }
+    types.put(name, pType);
+    pType.setGlobal(true);
+    addChild(pType);
+  }
+
+  public void redefine(XSType pType) throws SAXException {
+    XsQName name = pType.getName();
+    if (name == null) {
+      throw new LocSAXException("A global type must have a 'name' attribute.", pType.getLocator());
+    }
+    Object oldType = types.get(name);
+    if (oldType == null) {
+      throw new LocSAXException("The global type " + name + " cannot be redefined, as it doesn't yet exist.",
+                                   pType.getLocator());
+    }
+    types.put(name, pType);
+    pType.setGlobal(true);
+    replace(oldType, pType);
+  }
+
+  public void add(XSGroup pGroup) throws SAXException {
+    XsQName name = pGroup.getName();
+    if (name == null) {
+      throw new LocSAXException("A global group must have a 'name' attribute.", pGroup.getLocator());
+    }
+    if (groups.containsKey(name)) {
+      throw new LocSAXException("A global group " + name + " is already defined.", pGroup.getLocator());
+    }
+    groups.put(name, pGroup);
+    addChild(pGroup);
+    pGroup.setGlobal(true);
+  }
+
+  public void redefine(XSGroup pGroup) throws SAXException {
+    XsQName name = pGroup.getName();
+    if (name == null) {
+      throw new LocSAXException("A global group must have a 'name' attribute.", pGroup.getLocator());
+    }
+    Object oldGroup = groups.get(name);
+    if (oldGroup == null) {
+      throw new LocSAXException("The global group " + name + " cannot be redefined, as it doesn't yet exist.",
+                                   pGroup.getLocator());
+    }
+    groups.put(name, pGroup);
+    replace(oldGroup, pGroup);
+  }
+
+  public void add(XSAttributeGroup pGroup) throws SAXException {
+    XsQName name = pGroup.getName();
+    if (name == null) {
+      throw new LocSAXException("A global attribute group must have a 'name' attribute.", pGroup.getLocator());
+    }
+    if (attributeGroups.containsKey(name)) {
+      throw new LocSAXException("A global attribute group " + name + " is already defined.", pGroup.getLocator());
+    }
+    attributeGroups.put(name, pGroup);
+    addChild(pGroup);
+  }
+
+  public void redefine(XSAttributeGroup pGroup) throws SAXException {
+    XsQName name = pGroup.getName();
+    if (name == null) {
+      throw new LocSAXException("A global attribute group must have a 'name' attribute.", pGroup.getLocator());
+    }
+    Object oldGroup = attributeGroups.get(name);
+    if (!attributeGroups.containsKey(name)) {
+      throw new LocSAXException("The global attribute group " + name + " cannot be redefined, as it doesn't yet exist.",
+                                   pGroup.getLocator());
+    }
+    attributeGroups.put(name, pGroup);
+    replace(oldGroup, pGroup);
+  }
+
+  public void add(XSAttribute pAttribute) throws SAXException {
+    XsQName name = pAttribute.getName();
+    if (name == null) {
+      throw new LocSAXException("A global attribute must have a 'name' attribute.", pAttribute.getLocator());
+    }
+    if (attributes.containsKey(name)) {
+      throw new LocSAXException("A global attribute " + name + " is already defined.", pAttribute.getLocator());
+    }
+    attributes.put(name, pAttribute);
+    addChild(pAttribute);
+  }
+
+  public void add(XSElement pElement) throws SAXException {
+    XsQName name = pElement.getName();
+    if (name == null) {
+      throw new LocSAXException("A global element must have a 'name' attribute.", pElement.getLocator());
+    }
+    if (elements.containsKey(name)) {
+      throw new LocSAXException("A global element " + name + " is already defined.", pElement.getLocator());
+    }
+    elements.put(name, pElement);
+    addChild(pElement);
+  }
+
+  public void add(XSNotation pNotation) {
+    addChild(pNotation);
+  }
+
+  public Object[] getChilds() {
+    return childs.toArray();
+  }
+
+  protected void validate(Object pChild) throws SAXException {
+    if (pChild instanceof XSObject) {
+      ((XSObject) pChild).validate();
+    } else {
+      throw new IllegalStateException("Unable to validate the child " + pChild +
+                                       ", perhaps you should overwrite the method " +
+                                       getClass().getName() + ".validate(Object).");
+    }
+  }
+
+  protected boolean isValidated() {
+    return isValidated;
+  }
+
+  public void validate() throws SAXException {
+    if (isValidated()) {
+      return;
+    } else {
+      isValidated = true;
+    }
+
+    Object[] myChilds = getChilds();
+    for (int i = 0;  i < myChilds.length;  i++) {
+      validate(myChilds[i]);
+    }
+  }
+
+    public Attributes getOpenAttributes() {
+    	return openAttrs;
+    }
+
+    public XsAnyURI getTargetNamespace() {
+		return syntaxSchema.getTargetNamespace();
+	}
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSSimpleContentTypeImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSSimpleContentTypeImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSSimpleContentTypeImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSSimpleContentTypeImpl.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2003, 2004  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.
+
+ */
+package org.apache.ws.jaxme.xs.impl;
+
+import org.apache.ws.jaxme.xs.XSSimpleContentType;
+import org.apache.ws.jaxme.xs.XSType;
+import org.apache.ws.jaxme.xs.xml.XsObject;
+
+
+/**
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public class XSSimpleContentTypeImpl implements XSSimpleContentType {
+  private final XSType simpleType, complexType;
+  private final XsObject baseType;
+  
+  protected XSSimpleContentTypeImpl(XSType pComplexType, XSType pSimpleType,
+                                     XsObject pBaseType) {
+    if (!pSimpleType.isSimple()) {
+      throw new IllegalStateException("Embedded content type must be simple.");
+    }
+    simpleType = pSimpleType;
+    if (pComplexType.isSimple()) {
+      throw new IllegalStateException("Embedded content type must be simple.");
+    }
+    complexType = pComplexType;
+    baseType = pBaseType;
+  }
+
+  protected XSType getComplexType() { return complexType; }
+  protected XsObject getBaseType() { return baseType; }
+  public XSType getType() { return simpleType; }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSSimpleTypeImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSSimpleTypeImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSSimpleTypeImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSSimpleTypeImpl.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2003, 2004  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.
+
+ */
+package org.apache.ws.jaxme.xs.impl;
+
+import org.apache.ws.jaxme.xs.XSAtomicType;
+import org.apache.ws.jaxme.xs.XSListType;
+import org.apache.ws.jaxme.xs.XSSimpleType;
+import org.apache.ws.jaxme.xs.XSUnionType;
+
+
+/**
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public abstract class XSSimpleTypeImpl implements XSSimpleType {
+  public boolean isAtomic() { return false; }
+  public XSAtomicType getAtomicType() { throw new IllegalStateException("This type is not atomic."); }
+  public boolean isList() { return false; }
+  public XSListType getListType() { throw new IllegalStateException("This type is no list."); }
+  public boolean isUnion() { return false; }
+  public XSUnionType getUnionType() { throw new IllegalStateException("This type is no union."); }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSSimpleTypeRestrictionImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSSimpleTypeRestrictionImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSSimpleTypeRestrictionImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/impl/XSSimpleTypeRestrictionImpl.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2003, 2004  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.
+
+ */
+package org.apache.ws.jaxme.xs.impl;
+
+import org.apache.ws.jaxme.xs.XSEnumeration;
+import org.apache.ws.jaxme.xs.XSSimpleType;
+import org.apache.ws.jaxme.xs.XSType;
+import org.apache.ws.jaxme.xs.xml.XsEEnumeration;
+import org.apache.ws.jaxme.xs.xml.XsEPattern;
+import org.apache.ws.jaxme.xs.xml.XsGSimpleRestrictionModel;
+import org.xml.sax.SAXException;
+
+/**
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public abstract class XSSimpleTypeRestrictionImpl extends XSSimpleTypeImpl {
+  private final XSSimpleType baseType;
+  private final XSType restrictedType;
+  private final XsGSimpleRestrictionModel restriction;
+  private final XSEnumeration[] enumerations;
+
+  protected XSSimpleTypeRestrictionImpl(XSType pParent,
+                                         XSType pRestrictedType,
+                                         XsGSimpleRestrictionModel pRestriction)
+      throws SAXException {
+    restrictedType = pRestrictedType;
+    baseType = pRestrictedType.getSimpleType();
+    restriction = pRestriction;
+
+    XsEEnumeration[] enums = restriction.getEnumerations();
+    if (enums.length == 0) {
+      enumerations = getBaseType().getEnumerations();
+    } else {
+      enumerations = new XSEnumeration[enums.length];
+      for (int i = 0;  i < enums.length;  i++) {
+        enumerations[i] = pParent.getXSSchema().getXSObjectFactory().newXSEnumeration(pParent, enums[i]);
+      }
+    }
+  }
+
+  protected XSSimpleType getBaseType() {
+    return baseType;
+  }
+
+  public boolean isRestriction() { return true; }
+  public XSType getRestrictedType() { return restrictedType; }
+
+  protected XsGSimpleRestrictionModel getRestriction() {
+    return restriction;
+  }
+
+  public String[][] getPattern() {
+    XsEPattern[] patterns = restriction.getPatterns();
+    String[][] base = getBaseType().getPattern();
+    if (patterns.length == 0) {
+      return base;
+    } else {
+      String[][] result;
+      if (base == null) {
+          result = new String[1][];
+      } else {
+	      result = new String[base.length+1][];
+	      for (int i = 0;  i < base.length;  i++) {
+	        result[i+1] = base[i];
+	      }
+      }
+      String[] thisStepsPatterns = new String[patterns.length];
+      for (int i = 0;  i < patterns.length;  i++) {
+        thisStepsPatterns[i] = patterns[i].getValue();
+      }
+      result[0] = thisStepsPatterns;
+      return result;
+    }
+  }
+
+  public XSEnumeration[] getEnumerations() {
+    return enumerations;
+  }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org