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 [7/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/jaxb/impl/JAXBXsObjectFactoryImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/impl/JAXBXsObjectFactoryImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/impl/JAXBXsObjectFactoryImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/impl/JAXBXsObjectFactoryImpl.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,74 @@
+/*
+ * 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.jaxb.impl;
+
+import org.apache.ws.jaxme.xs.jaxb.*;
+import org.apache.ws.jaxme.xs.xml.XsEAppinfo;
+import org.apache.ws.jaxme.xs.xml.XsESchema;
+import org.apache.ws.jaxme.xs.xml.XsObject;
+import org.apache.ws.jaxme.xs.xml.impl.XsObjectFactoryImpl;
+
+/**
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public class JAXBXsObjectFactoryImpl extends XsObjectFactoryImpl implements JAXBXsObjectFactory {
+  public JAXBProperty.BaseType newBaseType(XsObject pParent) {
+    return new JAXBPropertyImpl.BaseTypeImpl(pParent);
+  }
+  public JAXBClass newJAXBClass(XsObject pParent) {
+    return new JAXBClassImpl(pParent);
+  }
+  public JAXBGlobalBindings newJAXBGlobalBindings(XsObject pParent) {
+    return new JAXBGlobalBindingsImpl(pParent);
+  }
+  public JAXBJavadoc newJAXBJavadoc(XsObject pParent) {
+    return new JAXBJavadocImpl(pParent);
+  }
+  public JAXBJavaType newJAXBJavaType(XsObject pParent) {
+    return new JAXBJavaTypeImpl(pParent);
+  }
+  public JAXBJavaType.JAXBGlobalJavaType newJAXBGlobalJavaType(XsObject pParent) {
+    return new JAXBJavaTypeImpl.JAXBGlobalJavaTypeImpl(pParent);
+  }
+  public JAXBSchemaBindings.NameXmlTransform newNameXmlTransform(XsObject pParent) {
+    return new JAXBSchemaBindingsImpl.NameXmlTransformImpl(pParent);
+  }
+  public JAXBSchemaBindings.NameTransformation newNameTransformation(XsObject pParent) {
+    return new JAXBSchemaBindingsImpl.NameXmlTransformImpl.NameTransformationImpl(pParent);
+  }
+  public JAXBSchemaBindings.Package newPackage(XsObject pParent) {
+    return new JAXBSchemaBindingsImpl.PackageImpl(pParent);
+  }
+  public JAXBProperty newJAXBProperty(XsObject pParent) {
+    return new JAXBPropertyImpl(pParent);
+  }
+  public JAXBSchemaBindings newJAXBSchemaBindings(XsObject pParent) {
+    return new JAXBSchemaBindingsImpl(pParent);
+  }
+  public JAXBTypesafeEnumClass newJAXBTypesafeEnumClass(XsObject pParent) {
+    return new JAXBTypesafeEnumClassImpl(pParent);
+  }
+  public JAXBTypesafeEnumMember newJAXBTypesafeEnumMember(XsObject pParent) {
+    return new JAXBTypesafeEnumMemberImpl(pParent);
+  }
+  public XsEAppinfo newXsEAppinfo(XsObject pParent) {
+    return new JAXBAppinfoImpl(pParent);
+  }
+  public XsESchema newXsESchema() {
+    return new JAXBXsSchemaImpl(getContext());
+  }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/impl/JAXBXsObjectImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/impl/JAXBXsObjectImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/impl/JAXBXsObjectImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/impl/JAXBXsObjectImpl.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,37 @@
+/*
+ * 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.jaxb.impl;
+
+import org.apache.ws.jaxme.xs.jaxb.JAXBXsObjectFactory;
+import org.apache.ws.jaxme.xs.xml.XsObject;
+import org.apache.ws.jaxme.xs.xml.impl.XsObjectImpl;
+
+
+/**
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public abstract class JAXBXsObjectImpl extends XsObjectImpl {
+  /** <p>Creates a new instance of JAXBXsObjectImpl.</p>
+   */
+  public JAXBXsObjectImpl(XsObject pParent) {
+    super(pParent);
+  }
+
+  protected JAXBXsObjectFactory getJAXBXsObjectFactory() {
+    return (JAXBXsObjectFactory) getObjectFactory();
+  }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/impl/JAXBXsSchemaImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/impl/JAXBXsSchemaImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/impl/JAXBXsSchemaImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/impl/JAXBXsSchemaImpl.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,121 @@
+/*
+ * 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.jaxb.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.ws.jaxme.xs.jaxb.*;
+import org.apache.ws.jaxme.xs.jaxb.JAXBSchemaBindings;
+import org.apache.ws.jaxme.xs.jaxb.JAXBXsObjectFactory;
+import org.apache.ws.jaxme.xs.parser.XSContext;
+import org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
+import org.apache.ws.jaxme.xs.xml.XsEAnnotation;
+import org.apache.ws.jaxme.xs.xml.XsEAppinfo;
+import org.apache.ws.jaxme.xs.xml.impl.XsESchemaImpl;
+import org.xml.sax.SAXException;
+
+
+/**
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public class JAXBXsSchemaImpl extends XsESchemaImpl implements JAXBXsSchema {
+  private JAXBSchemaBindings schemaBindings;
+  private String jaxbVersion;
+  private String[] jaxbExtensionBindingPrefixes;
+
+  public void setJaxbVersion(String pVersion) {
+    jaxbVersion = pVersion;
+  }
+
+  public void setJaxbExtensionBindingPrefixes(String pExtensionBindingPrefixes) {
+    List result = new ArrayList();
+    for (StringTokenizer st = new StringTokenizer(pExtensionBindingPrefixes);  st.hasMoreTokens();  ) {
+      result.add(st.nextToken());
+    }
+    jaxbExtensionBindingPrefixes = (String[]) result.toArray(new String[result.size()]);
+  }
+
+  public String[] getJaxbExtensionBindingPrefixes() {
+    return jaxbExtensionBindingPrefixes == null ? new String[0] : jaxbExtensionBindingPrefixes;
+  }
+
+  public String getJaxbVersion() {
+    return jaxbVersion;
+  }
+
+  /** <p>Creates a new instance of JAXBXsSchemaImpl.</p>
+   */
+  public JAXBXsSchemaImpl(XSContext pContext) {
+    super(pContext);
+  }
+
+  public void validate() throws SAXException {
+    if (isValidated()) {
+      return;
+    }
+    super.validate();
+    Object[] childs = getChilds();
+    for (int i = 0;  i < childs.length;  i++) {
+      if (!(childs[i] instanceof XsEAnnotation)) {
+        continue;
+      }
+      XsEAnnotation annotation = (XsEAnnotation) childs[i];
+      XsEAppinfo[] appinfos = annotation.getAppinfos();
+      for (int j = 0;  j < appinfos.length;  j++) {
+        Object[] appinfoChilds = appinfos[j].getChilds();
+        for (int k = 0;  k < appinfoChilds.length;  k++) {
+          if (!(appinfoChilds[k] instanceof JAXBSchemaBindings)) {
+            continue;
+          }
+          if (schemaBindings == null) {
+            schemaBindings = (JAXBSchemaBindings) appinfoChilds[k];
+          } else {
+            throw new LocSAXException("A schema must have at most a single instance of 'schemaBindings'",
+                                       appinfos[j].getLocator());
+          }
+        }
+      }
+    }
+
+    if (schemaBindings == null) {
+      schemaBindings = ((JAXBXsObjectFactory) getObjectFactory()).newJAXBSchemaBindings(this);
+    }
+  }
+
+  public JAXBSchemaBindings getJAXBSchemaBindings() {
+    return schemaBindings;
+  }
+
+  public boolean setAttribute(String pQName, String pNamespaceURI, String pLocalName,
+                                String pValue) throws SAXException {
+    if (JAXBParser.JAXB_SCHEMA_URI.equals(pNamespaceURI)) {
+      if ("version".equals(pLocalName)) {
+        setJaxbVersion(pValue);
+        return true;
+      } else if ("extensionBindingPrefixes".equals(pLocalName)) {
+        setJaxbExtensionBindingPrefixes(pValue);
+        return true;
+      } else {
+        throw new LocSAXException("Invalid attribute: " + pQName, getLocator());
+      }
+    } else {
+      return super.setAttribute(pQName, pNamespaceURI, pLocalName, pValue);
+    }
+  }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/impl/package.html
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/impl/package.html?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/impl/package.html (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/impl/package.html Fri Nov 24 04:14:48 2006
@@ -0,0 +1,30 @@
+<!--
+
+ Copyright 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.
+
+-->
+<html>
+    <head>
+        <title>
+Package Documentation for org.apache.ws.jaxme.xs.impl Package
+    </title>
+</head>
+    <body bgcolor="white">
+        <p>
+Basic implementation of the JAXB specialization of the JaxMeXS parser 
+for XML Schema.
+    </p>
+</body>
+</html>

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/package.html
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/package.html?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/package.html (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/jaxb/package.html Fri Nov 24 04:14:48 2006
@@ -0,0 +1,29 @@
+<!--
+
+ Copyright 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.
+
+-->
+<html>
+    <head>
+        <title>
+Package Documentation for org.apache.ws.jaxme.xs.impl Package
+    </title>
+</head>
+    <body bgcolor="white">
+        <p>
+Specialization of the JaxMeXS parser for XML Schema for the needs of JAXB.
+    </p>
+</body>
+</html>

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/package.html
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/package.html?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/package.html (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/package.html Fri Nov 24 04:14:48 2006
@@ -0,0 +1,30 @@
+<!--
+
+ Copyright 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.
+
+-->
+<html>
+    <head>
+        <title>
+Package Documentation for org.apache.ws.jaxme.xs Package
+    </title>
+</head>
+    <body bgcolor="white">
+        <p>
+Contains <a href='http://ws.apache.org/jaxme/xs/'>JaxMeXS</a>: the <code>JaxMe</code>
+parser for XML Schema.
+    </p>
+</body>
+</html>

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/AttributeSetter.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/AttributeSetter.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/AttributeSetter.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/AttributeSetter.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,37 @@
+/*
+ * 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.parser;
+
+import org.xml.sax.SAXException;
+
+
+/** <p>The attribute setter is used by the {@link org.apache.ws.jaxme.xs.parser.XsSAXParser}
+ * to pass an attributes value to the bean. The main purpose of this
+ * interface is the ability to choose a custom attribtue setter.</p>
+ * <p>The default attribute setter is
+ * {@link org.apache.ws.jaxme.xs.parser.impl.AttributeSetterImpl}.</p>
+ *
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public interface AttributeSetter {
+  /** <p>Sets the attribute with the given namespace URI and local
+   * name to the given value.</p>
+   */
+  public void setAttribute(String pQName,
+                            String pNamespaceURI, String pLocalName, String pValue)
+    throws SAXException;
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/ChildSetter.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/ChildSetter.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/ChildSetter.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/ChildSetter.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,38 @@
+/*
+ * 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.parser;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+/** <p>Implementations of this interface are responsible for the handling
+ * of child elements.</p>
+ *
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public interface ChildSetter {
+  /** <p>Returns a ContentHandler, which is able to handle the given child
+   * element.</p>
+   *
+   * @param pNamespaceURI The child elements namespace URI
+   * @param pLocalName The child elements local name
+   * @param pQName The child elements fully qualified name
+   * @see org.apache.ws.jaxme.xs.XSParser#getContext()
+   */
+  public ContentHandler getChildHandler(String pQName, String pNamespaceURI,
+                                         String pLocalName) throws SAXException;
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/DOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/DOMBuilder.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/DOMBuilder.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/DOMBuilder.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,178 @@
+/*
+ * 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.parser;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.Node;
+import org.w3c.dom.ProcessingInstruction;
+import org.w3c.dom.Text;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+
+/** <p>Converts a stream of SAX events into a DOM node.</p>
+ *
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ * @version $Id: DOMBuilder.java 231785 2004-02-16 23:39:59Z jochen $
+ */
+public class DOMBuilder implements ContentHandler {
+  private Node currentNode;
+  private Element result;
+  private Locator locator;
+  private Document factory;
+
+  /** <p>Creates a new instance of DOMBuilder, which creates
+   * a new document. The document is available via
+   * {@link #getDocument()}.</p>
+   */
+  public DOMBuilder() throws ParserConfigurationException {
+    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+    dbf.setValidating(false);
+    dbf.setNamespaceAware(true);
+    DocumentBuilder db = dbf.newDocumentBuilder();
+    currentNode = factory = db.newDocument();
+  }
+
+  /** <p>Creates a new instance of DOMBuilder, which creates
+   * a new element node in the given node. The created node
+   * is available via {@link #getResult()}.</p>
+   */
+  public DOMBuilder(Node pTarget) {
+    if (pTarget == null) {
+      throw new NullPointerException("Target node must not be null.");
+    }
+    factory = pTarget.getOwnerDocument();
+    currentNode = pTarget;
+  }
+
+  /** <p>Returns the document being used as object factory. In the case
+   * of the empty constructor, this is a new document. Otherwise it is
+   * the target nodes owner document.</p>
+   */
+  public Document getDocument() {
+    return factory;
+  }
+
+  /** <p>Returns the result element. In the case of the default constructor,
+   * this is the document element. Otherwise it is added to the target node
+   * via {@link org.w3c.dom.Node#appendChild(org.w3c.dom.Node)}.<(p>
+   */
+  public Element getResult() {
+    return result;
+  }
+
+  /** <p>Sets the Locator.</p>
+   */
+  public void setDocumentLocator(Locator pLocator) {
+    locator = pLocator;
+  }
+
+  /** <p>Returns the Locator.</p>
+   */
+  public Locator getDocumentLocator() {
+    return locator;
+  }
+
+  /**
+   * @see org.xml.sax.ContentHandler#startDocument()
+   */
+  public void startDocument() throws SAXException {
+  }
+
+  /**
+   * @see org.xml.sax.ContentHandler#endDocument()
+   */
+  public void endDocument() throws SAXException {
+  }
+
+  public void startPrefixMapping(String prefix, String uri)
+    throws SAXException {
+  }
+
+  public void endPrefixMapping(String prefix) throws SAXException {
+  }
+
+  public void startElement(String pNamespaceURI, String pLocalName,
+                            String pQName, Attributes pAttr) throws SAXException {
+    Document doc = getDocument();
+    Element element;
+    if (pNamespaceURI == null  ||  pNamespaceURI.length() == 0) {
+      element = doc.createElement(pQName);
+    } else {
+      element = doc.createElementNS(pNamespaceURI, pQName);
+    }
+    if (pAttr != null) {
+      for (int i = 0;  i < pAttr.getLength();  i++) {
+        String uri = pAttr.getURI(i);
+        String qName = pAttr.getQName(i);
+        String value = pAttr.getValue(i);
+        if (uri == null  ||  uri.length() == 0) {
+          element.setAttribute(qName, value);
+        } else {
+          element.setAttributeNS(uri, qName, value);
+        }
+      }
+    }
+
+    currentNode.appendChild(element);
+    currentNode = element;
+    if (result == null) {
+      result = element;
+    }
+  }
+
+  public void endElement(String namespaceURI, String localName, String qName)
+      throws SAXException {
+    currentNode = currentNode.getParentNode();
+  }
+
+  public void characters(char[] ch, int start, int length)
+      throws SAXException {
+    Node node = currentNode.getLastChild();
+    String s = new String(ch, start, length);
+    if (node != null  &&  node.getNodeType() == Node.TEXT_NODE) {
+      ((Text) node).appendData(s);
+    } else {
+      Text text = getDocument().createTextNode(s);
+      currentNode.appendChild(text);
+    }
+  }
+
+  public void ignorableWhitespace(char[] ch, int start, int length)
+      throws SAXException {
+    characters(ch, start, length);
+  }
+
+  public void processingInstruction(String pTarget, String pData)
+      throws SAXException {
+    ProcessingInstruction pi = getDocument().createProcessingInstruction(pTarget, pData);
+    currentNode.appendChild(pi);
+  }
+
+  public void skippedEntity(String pName) throws SAXException {
+    EntityReference entity = getDocument().createEntityReference(pName);
+    currentNode.appendChild(entity);
+  }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/TextSetter.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/TextSetter.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/TextSetter.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/TextSetter.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,38 @@
+/*
+ * 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.parser;
+
+import org.xml.sax.SAXException;
+
+/** <p>Interface of an object which is setting character data as
+ * a bean property. The default implementation,
+ * {@link org.apache.ws.jaxme.xs.parser.impl.TextSetterImpl}, is converting any
+ * SAX event of type {@link org.xml.sax.ContentHandler#characters(char[], int, int)}
+ * into a call of the method <code>addText(String)</code> on the
+ * bean.</p>
+ *
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public interface TextSetter {
+  /** <p>Called for any {@link org.xml.sax.ContentHandler#characters(char[], int, int)}
+   * event. Note, that this implies in particular, that the method may be called
+   * multiple times, even for a single block of text.</p>
+   *
+   * @param pText The text being set.
+   */
+  public void addText(String pText) throws SAXException; 
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/XSContext.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/XSContext.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/XSContext.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/XSContext.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,104 @@
+/*
+ * 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.parser;
+
+import org.apache.ws.jaxme.xs.*;
+import org.apache.ws.jaxme.xs.impl.XSLogicalParser;
+import org.apache.ws.jaxme.xs.xml.XsObjectFactory;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.helpers.NamespaceSupport;
+
+/** <p>This interface provides access to the parsers context.</p>
+ *
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public interface XSContext {
+  /** <p>Returns the parsers object factory for syntax elements.</p>
+   */
+  public XsObjectFactory getXsObjectFactory();
+  /** <p>Sets the parsers object factory for syntax elements.</p>
+   */
+  public void setXsObjectFactory(XsObjectFactory pFactory);
+
+  /** <p>Returns the parsers object factory for logical elements.</p>
+   */
+  public XSObjectFactory getXSObjectFactory();
+  /** <p>Sets the parsers object factory for logical elements.</p>
+   */
+  public void setXSObjectFactory(XSObjectFactory pFactory);
+
+  /** <p>Returns the {@link AttributeSetter}, which is used to
+   * configure properties.</p>
+   */
+  public AttributeSetter getAttributeSetter();
+  /** <p>Sets the AttributeSetter, which is used to
+   * configure properties.</p>
+   */
+  public void setAttributeSetter(AttributeSetter pSetter);
+
+  /** <p>Returns the {@link ChildSetter}, which is used to create
+   * child elements.</p>
+   */
+  public ChildSetter getChildSetter();
+  /** <p>Sets the ChildSetter, which is used to create
+   * child elements.</p>
+   */
+  public void setChildSetter(ChildSetter pSetter);
+
+  /** <p>Returns the {@link TextSetter}, used to add text sections.</p>
+   */
+  public TextSetter getTextSetter();
+  /** <p>Sets the TextSetter, used to add text sections.</p>
+   */
+  public void setTextSetter(TextSetter pSetter);
+
+  /** <p>Returns the currently running {@link XSParser} or null,
+   * if no such instance is available.</p>
+   */
+  public XSLogicalParser getXSLogicalParser();
+  /** <p>Sets the currently active instance of {@link XSParser}, if any.
+   * Returns null, if no such instance is available.</p>
+   */
+  public void setXSLogicalParser(XSLogicalParser pParser);
+
+  /** <p>Returns the {@link XSSchema}, which is currently being parsed,
+   * if any.</p>
+   */
+  public XSSchema getXSSchema();
+
+  /** <p>Returns the locator, used for error messages.</p>
+   */
+  public Locator getLocator();    
+  /** <p>Sets the locator, used for error messages.</p>
+   */
+  public void setLocator(Locator pLocator);
+
+  /** <p>Returns the namespace handler.</p>
+   */
+  public NamespaceSupport getNamespaceSupport();
+  /** <p>Sets the namespace handler.</p>
+   */
+  public void setNamespaceSupport(NamespaceSupport pNamespaceSupport);
+
+  /** <p>Sets the currently active instance of {@link XsSAXParser}.</p>
+   */
+  public ContentHandler getCurrentContentHandler();
+  /** <p>Sets the currently active instance of {@link XsSAXParser}.</p>
+   */
+  public void setCurrentContentHandler(ContentHandler pParser);
+}
\ No newline at end of file

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/XsObjectCreator.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/XsObjectCreator.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/XsObjectCreator.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/XsObjectCreator.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,42 @@
+/*
+ * 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.parser;
+
+import org.apache.ws.jaxme.xs.xml.XsObject;
+import org.apache.ws.jaxme.xs.xml.XsQName;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+
+/** <p>Interface of a an object creating beans.</p>
+ *
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public interface XsObjectCreator {
+  /** <p>Asks the bean creator whether he is willing to create a bean
+   * for the given namespace URI and local name. The bean creator
+   * may do either of the following:
+   * <ol>
+   *   <li>Return a new bean.</li>
+   *   <li>Return null in order to indicate, that the bean creator
+   *     delegates the decision to the next bean creator.</li>
+   *   <li>Throw a SAX Exception in order to indicate that the
+   *     combination of namespace URI and local name is invalid.</p>
+   * </ol>
+   */
+  public XsObject newBean(XsObject pParent, Locator pLocator, XsQName pQName) throws SAXException;
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/XsSAXParser.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/XsSAXParser.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/XsSAXParser.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/XsSAXParser.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,41 @@
+/*
+ * 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.parser;
+
+import org.xml.sax.ContentHandler;
+
+
+/**
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public interface XsSAXParser extends ContentHandler {
+  /** <p>Returns the bean configured by the XsSAXParser.</p>
+   */
+  public Object getBean();
+
+  /** <p>Returns the current elements fully qualified name.</p>
+   */
+  public String getQName();
+
+  /** <p>Returns the current elements namespace URI.</p>
+   */
+  public String getNamespaceURI();
+
+  /** <p>Returns the current elements local name.</p>
+   */
+  public String getLocalName();
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/AbstractXsSAXParser.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/AbstractXsSAXParser.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/AbstractXsSAXParser.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/AbstractXsSAXParser.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,322 @@
+/*
+ * 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.parser.impl;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.UndeclaredThrowableException;
+
+import org.apache.ws.jaxme.xs.parser.AttributeSetter;
+import org.apache.ws.jaxme.xs.parser.ChildSetter;
+import org.apache.ws.jaxme.xs.parser.XSContext;
+import org.apache.ws.jaxme.xs.parser.XsSAXParser;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+
+/**
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public abstract class AbstractXsSAXParser implements ContentHandler, XsSAXParser {
+  private final static Class[] ZERO_CLASSES = new Class[0];
+  private final static Object[] ZERO_OBJECTS = new Object[0];
+  
+  private Object bean;
+  private int level;
+  private String qName, namespaceURI, localName;
+  private ContentHandler childHandler;
+
+  protected abstract XSContext getData();
+
+  public AbstractXsSAXParser(Object pBean) {
+    bean = pBean;
+  }
+
+  public Object getBean() {
+    return bean;
+  }
+
+  public void setQName(String pQName) {
+    qName = pQName;
+  }
+
+  public void setNamespaceURI(String pNamespaceURI) {
+    namespaceURI = pNamespaceURI;
+  }
+
+  public String getNamespaceURI() {
+    return namespaceURI;
+  }
+
+  public void setLocalName(String pLocalName) {
+    localName = pLocalName;
+  }
+
+  public String getLocalName() {
+    return localName;
+  }
+
+  public String getQName() {
+    return qName;
+  }
+
+  public ContentHandler getChildHandler() {
+    return childHandler;
+  }
+
+  public void startPrefixMapping(String pPrefix, String pURI)
+      throws SAXException {
+    if (childHandler == null) {
+      getData().getNamespaceSupport().declarePrefix(pPrefix, pURI);
+    } else {
+      childHandler.startPrefixMapping(pPrefix, pURI);
+    }
+  }
+
+  public void endPrefixMapping(String pPrefix) throws SAXException {
+    if (childHandler != null) {
+      childHandler.endPrefixMapping(pPrefix);
+    }
+  }
+
+  public void startDocument() throws SAXException {
+    getData().getNamespaceSupport().pushContext();
+  }
+
+  public void endDocument() throws SAXException {
+    getData().getNamespaceSupport().popContext();
+  }
+
+  public void characters(char[] pBuffer, int pOffset, int pLen) throws SAXException {
+    if (childHandler == null) {
+      try {
+        getData().getTextSetter().addText(new String(pBuffer, pOffset, pLen));
+      } catch (SAXException e) {
+        throw e;
+      } catch (RuntimeException e) {
+        Exception ex = e;
+        for (;;) {
+          UndeclaredThrowableException te = null;
+          Throwable t;
+          if (ex instanceof UndeclaredThrowableException) {
+            te = ((UndeclaredThrowableException) ex);
+            t = te.getUndeclaredThrowable();
+          } else if (ex instanceof InvocationTargetException) {
+            t = ((InvocationTargetException) ex).getTargetException();
+          } else {
+            break;
+          }
+          if (t instanceof Exception) {
+            ex = (Exception) t;
+          } else {
+            if (te == null) {
+              te = new UndeclaredThrowableException(t);
+            }
+            t.printStackTrace();
+            throw te;
+          }
+        }
+        throw new LocSAXException(ex.getClass().getName() + ": " + ex.getMessage(),
+                                   getData().getLocator(), ex);
+      }
+    } else {
+      childHandler.characters(pBuffer, pOffset, pLen);
+    }
+  }
+
+  public void ignorableWhitespace(char[] pBuffer, int pOffset, int pLen)
+      throws SAXException {
+    if (childHandler == null) {
+      characters(pBuffer, pOffset, pLen);
+    } else {
+      childHandler.ignorableWhitespace(pBuffer, pOffset, pLen);
+    }
+  }
+
+  public void skippedEntity(String pEntity) throws SAXException {
+    if (childHandler == null) {
+      throw new LocSAXException("Unable to skip entities: " + pEntity,
+                                 getData().getLocator());
+    } else {
+      skippedEntity(pEntity);
+    }
+  }
+
+  public void processingInstruction(String pTarget, String pData)
+      throws SAXException {
+    if (childHandler != null) {
+      childHandler.processingInstruction(pTarget, pData);
+    }
+  }
+
+  public void startElement(String pNamespaceURI, String pLocalName, String pQName, Attributes pAttr)
+      throws SAXException {
+    switch (++level) {
+      case 1:
+        setQName(pQName);
+        setNamespaceURI(pNamespaceURI);
+        setLocalName(pLocalName);
+        if (pAttr != null) {
+          for (int i = 0;  i < pAttr.getLength();  i++) {
+            try {
+              AttributeSetter attrSetter = getData().getAttributeSetter();
+              attrSetter.setAttribute(pAttr.getQName(i), pAttr.getURI(i),
+                                      pAttr.getLocalName(i), pAttr.getValue(i));
+            } catch (SAXException e) {
+              throw e;
+            } catch (RuntimeException e) {
+              Exception ex = e;
+              for (;;) {
+                UndeclaredThrowableException te = null;
+                Throwable t;
+                if (ex instanceof UndeclaredThrowableException) {
+                  te = ((UndeclaredThrowableException) ex);
+                  t = te.getUndeclaredThrowable();
+                } else if (ex instanceof InvocationTargetException) {
+                  t = ((InvocationTargetException) ex).getTargetException();
+                } else {
+                  break;
+                }
+                if (t instanceof Exception) {
+                  ex = (Exception) t;
+                } else {
+                  if (te == null) {
+                    te = new UndeclaredThrowableException(t);
+                  }
+                  t.printStackTrace();
+                  throw te;
+                }
+              }
+              throw new LocSAXException(ex.getClass().getName() + ": " + ex.getMessage(),
+                                         getData().getLocator(), ex);
+            }
+          }
+        }
+        break;
+      case 2:
+        try {
+          ChildSetter childSetter = getData().getChildSetter();
+          childHandler = childSetter.getChildHandler(pQName, pNamespaceURI, pLocalName);
+        } catch (SAXException e) {
+          throw e;
+        } catch (RuntimeException e) {
+          Exception ex = e;
+          for (;;) {
+            UndeclaredThrowableException te = null;
+            Throwable t;
+            if (ex instanceof UndeclaredThrowableException) {
+              te = ((UndeclaredThrowableException) ex);
+              t = te.getUndeclaredThrowable();
+            } else if (ex instanceof InvocationTargetException) {
+              t = ((InvocationTargetException) ex).getTargetException();
+            } else {
+              break;
+            }
+            if (t instanceof Exception) {
+              ex = (Exception) t;
+            } else {
+              if (te == null) {
+                te = new UndeclaredThrowableException(t);
+              }
+              t.printStackTrace();
+              throw te;
+            }
+          }
+          throw new LocSAXException(ex.getClass().getName() + ": " + ex.getMessage(),
+                                     getData().getLocator(), ex);
+        }
+        getData().setCurrentContentHandler(childHandler);
+        childHandler.startDocument();
+        childHandler.startElement(pNamespaceURI, pLocalName, pQName, pAttr);
+        break;
+      default:
+        childHandler.startElement(pNamespaceURI, pLocalName, pQName, pAttr);
+        break;
+    }
+  }
+
+  public void endElement(String pNamespaceURI, String pLocalName, String pQName)
+      throws SAXException {
+    switch (level--) {
+      case 1:
+        Object o = getBean();
+        if (o != null) {
+          Method m = null;
+          try {
+            m = o.getClass().getMethod("validate", ZERO_CLASSES);
+          } catch (NoSuchMethodException e) {
+          }
+          if (m != null) {
+            try {
+              m.invoke(o, ZERO_OBJECTS);
+            } catch (RuntimeException e) {
+              throw new LocSAXException(e.getClass().getName() + ": " + e.getMessage(),
+                                         getData().getLocator(), e);
+            } catch (InvocationTargetException e) {
+              Throwable t = e.getTargetException();
+              if (t instanceof SAXException) {
+                throw (SAXException) t;
+              } else if (t instanceof RuntimeException) {
+                throw new LocSAXException(t.getClass().getName() + ": " + t.getMessage(),
+                                           getData().getLocator(),
+                                           (RuntimeException) t);
+              } else if (t instanceof Exception) {
+                throw new LocSAXException("Failed to invoke method validate() " +
+                                           " of class " + m.getDeclaringClass() +
+                                           " with argument " + o.getClass().getName() + ": " +
+                                           t.getClass().getName() + ", " + t.getMessage(),
+                                           getData().getLocator(),
+                                           (Exception) t);
+              } else {
+                throw new LocSAXException("Failed to invoke method validate() " +
+                                           " of class " + m.getDeclaringClass() +
+                                           " with argument " + o.getClass().getName() + ": " +
+                                           t.getClass().getName() + ", " + t.getMessage(),
+                                           getData().getLocator(), e);
+              }
+            } catch (IllegalAccessException e) {
+              throw new LocSAXException("Failed to invoke method validate() " +
+                                           " of class " + m.getDeclaringClass() +
+                                           " with argument " + o.getClass().getName() + ": IllegalAccessException, " +
+                                           e.getMessage(),
+                                           getData().getLocator(), e); 
+
+            }
+          }
+        }
+        break;
+      case 2:
+        childHandler.endElement(pNamespaceURI, pLocalName, pQName);
+        childHandler.endDocument();
+        getData().setCurrentContentHandler(this);
+        childHandler = null;
+        break;
+      default:
+        childHandler.endElement(pNamespaceURI, pLocalName, pQName);
+        break;
+    }
+  }
+
+  public void setDocumentLocator(Locator pLocator) {
+    getData().setLocator(pLocator);
+    if (childHandler != null) {
+      childHandler.setDocumentLocator(pLocator);
+    }
+  }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/AttributeSetterImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/AttributeSetterImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/AttributeSetterImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/AttributeSetterImpl.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,345 @@
+/*
+ * 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.parser.impl;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.UndeclaredThrowableException;
+
+import org.apache.ws.jaxme.xs.XSParser;
+import org.apache.ws.jaxme.xs.parser.*;
+import org.xml.sax.SAXException;
+
+
+/** <p>Default implementation of the {@link org.apache.ws.jaxme.xs.parser.AttributeSetter}
+ * interface.</p>
+ *
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public class AttributeSetterImpl implements AttributeSetter {
+  static final Class[] ONE_STRING_CLASS = new Class[]{String.class};
+  private static final Class[] FOUR_STRING_CLASSES =
+    new Class[]{String.class, String.class, String.class, String.class};
+
+  protected XSContext getData() {
+    XSContext result = XSParser.getRunningInstance().getContext();
+    if (result == null) {
+      throw new IllegalStateException("Parser data is not set.");
+    }
+    return result;
+  }
+
+  /** <p>This method configures the bean <code>pBean</code> as follows:
+   * <ol>
+   *    <li>If the bean has a method
+   *      <code>setAttribute(String, String, String)</code>, it is invoked
+   *      with the following arguments:
+   *      <ul>
+   *        <li>The attributes namespace URI (empty string for the default
+   *          namespace),</li>
+   *        <li>the attributes local name,</li>
+   *        <li>and the property value</li>
+   *      </ul>
+   *    </li>
+   *    <li>Otherwise invokes its own method {@link #setProperty(Object, String, String, String)}.</li>
+   * </ol>
+   */
+  public void setAttribute(String pQName, String pNamespaceURI, String pLocalName, String pValue)
+      throws SAXException {
+    XsSAXParser handler = ((XsSAXParser) getData().getCurrentContentHandler());
+    if (handler == null) {
+      throw new IllegalStateException("Current XsSAXParser is null.");
+    }
+    Object bean = ((XsSAXParser) getData().getCurrentContentHandler()).getBean();
+    try {
+      Method m = bean.getClass().getMethod("setAttribute", FOUR_STRING_CLASSES);
+      if (Modifier.isPublic(m.getModifiers())) {
+        Object[] o = new Object[]{pQName, pNamespaceURI, pLocalName, pValue};
+        Object result = invokeMethod(bean, m, pQName, o);
+        if (!boolean.class.equals(m.getReturnType())  ||  ((Boolean) result).booleanValue()) {
+          return;
+        }
+      }
+    } catch (NoSuchMethodException e) {
+    }
+
+    if (!setProperty(bean, pQName, pLocalName, pValue)) {
+      throw new IllegalStateException("Unknown attribute of " + bean.getClass().getName() + ": " + pQName);
+    }
+  }
+
+
+  /** <p>This method invokes the beans <code>pBean</code> method <code>pMethod</code>,
+   * setting the attribute <code>pName</code> to the value <code>pArgs</code>.</p>
+   */
+  protected Object invokeMethod(Object pBean, Method pMethod, String pName, Object[] pArgs) throws SAXException {
+    try {
+      return pMethod.invoke(pBean, pArgs);
+    } catch (InvocationTargetException e) {
+      Throwable t = e.getTargetException();
+      if (t instanceof SAXException) {
+        throw (SAXException) t;
+      } else if (t instanceof RuntimeException) {
+        throw (RuntimeException) t;
+      } else {
+        throw new UndeclaredThrowableException(t);
+      }
+    } catch (IllegalAccessException e) {
+      StringBuffer sb = new StringBuffer("Failed to invoke method ");
+      sb.append(pMethod.getName()).append(" of class ").append(pBean.getClass().getName());
+      sb.append(" with argument ");
+      for (int i = 0;  i < pArgs.length;  i++) {
+        if (i > 0) {
+          sb.append(", ");
+        }
+        sb.append(pArgs[i]);
+      }
+      sb.append(": ").append(e.getClass().getName()).append(", ").append(e.getMessage());
+      throw new IllegalStateException(sb.toString());
+    }
+  }
+
+  private interface ParameterClass {
+    public Object matches(Class pClass);
+    public void invoke(AttributeSetterImpl pAttributeSetter, Object pBean, String pValue,
+                        Method pMethod, Object pMethodObject, String pQName)
+      throws SAXException;
+  }
+
+  private static class StringClass implements ParameterClass {
+    public Object matches(Class pClass) {
+      return String.class.equals(pClass) ? Boolean.TRUE : null;
+    }
+    public void invoke(AttributeSetterImpl pAttributeSetter, Object pBean, String pValue,
+                        Method pMethod, Object pMethodObject, String pQName) throws SAXException {
+      pAttributeSetter.invokeMethod(pBean, pMethod, pQName, new Object[]{pValue});
+    }
+  }
+
+  private static class ValueOfParameterClass implements ParameterClass {
+    public Object matches(Class pClass) {
+      try {
+        Method valueOfMethod = pClass.getMethod("valueOf", ONE_STRING_CLASS);
+        if (Modifier.isPublic(valueOfMethod.getModifiers())  &&  !void.class.equals(valueOfMethod.getReturnType())) {
+          return valueOfMethod;
+        }
+      } catch (NoSuchMethodException e) {
+      }
+      return null;
+    }
+    public void invoke(AttributeSetterImpl pAttributeSetter, Object pBean, String pValue,
+                        Method pMethod, Object pMethodObject, String pQName) throws SAXException {
+      Method m = (Method) pMethodObject; 
+      Object o;
+      try {
+        o = m.invoke(null, new Object[]{pValue});
+      } catch (InvocationTargetException e) {
+        throw new IllegalArgumentException("Illegal argument for attribute '" + pQName + "': " + pValue +
+                                            "; " + e.getTargetException().getClass().getName() +
+                                            ", " + e.getTargetException().getMessage());
+      } catch (IllegalAccessException e) {
+        throw new IllegalStateException("Invalid access to method " + m.getName() + " of class " +
+                                         pBean.getClass() + ": IllegalAccessException, " + e.getMessage());
+      }
+      pAttributeSetter.invokeMethod(pBean, pMethod, pQName, new Object[]{o});
+    }
+  }
+
+  private static class StringConstructorClass implements ParameterClass {
+    public Object matches(Class pClass) {
+      try {
+        Constructor con = pClass.getConstructor(ONE_STRING_CLASS);
+        if (Modifier.isPublic(con.getModifiers())) {
+          return con;
+        }
+      } catch (NoSuchMethodException e) {
+      }
+      return null;
+    }
+    public void invoke(AttributeSetterImpl pAttributeSetter, Object pBean, String pValue,
+                        Method pMethod, Object pMethodObject, String pQName) throws SAXException {
+      Constructor con = (Constructor) pMethodObject; 
+      Object o;
+      try {
+        o = con.newInstance(new Object[]{pValue});
+      } catch (InvocationTargetException e) {
+        throw new IllegalArgumentException("Illegal argument for attribute '" + pQName + "': " + pValue +
+                                            "; " + e.getTargetException().getClass().getName() +
+                                            ", " + e.getTargetException().getMessage());
+      } catch (InstantiationException e) {
+        throw new IllegalStateException("Invalid access to constructor " + pBean.getClass().getName() +
+                                         "(): " + e.getClass().getName() + ", " + e.getMessage());
+      } catch (IllegalAccessException e) {
+        throw new IllegalStateException("Invalid access to constructor " + pBean.getClass().getName() +
+                                         "(): " + e.getClass().getName() + ", " + e.getMessage());
+      }
+      pAttributeSetter.invokeMethod(pBean, pMethod, pQName, new Object[]{o});
+    }
+  }
+
+  private static class PrimitiveParameterClass extends StringConstructorClass {
+    private final Class primitiveClass;
+    private final Class nonPrimitiveClass;
+    private final Constructor stringConstructor;
+    private PrimitiveParameterClass(Class pPrimitiveClass, Class pNonPrimitiveClass) {
+      primitiveClass = pPrimitiveClass;
+      nonPrimitiveClass = pNonPrimitiveClass;
+      try {
+        stringConstructor = pNonPrimitiveClass.getConstructor(ONE_STRING_CLASS);
+      } catch (NoSuchMethodException e) {
+        throw new IllegalStateException("The primitive class " + pNonPrimitiveClass.getName() +
+                                         " doesn't have a string valued constructor!");
+      }
+    }
+    public Object matches(Class pClass) {
+      return (primitiveClass.equals(pClass) || nonPrimitiveClass.equals(pClass)) ? stringConstructor : null;
+    }
+  }
+
+  private static class CharacterClass implements ParameterClass {
+    public Object matches(Class pClass) {
+      return (Character.TYPE.equals(pClass)  ||  Character.class.equals(pClass)) ? Boolean.TRUE : null;
+    }
+
+    public void invoke(AttributeSetterImpl pAttributeSetter, Object pBean, String pValue, Method pMethod, Object pMethodObject, String pQName) throws SAXException {
+      if (pValue.length() != 1) {
+        throw new IllegalArgumentException("Invalid value for '" + pQName +"': " + pValue +
+                                            "; must have exactly one character.");
+      }
+      pAttributeSetter.invokeMethod(pBean, pMethod, pQName, new Object[]{new Character(pValue.charAt(0))});
+    }
+  }
+
+  private static class BooleanClass implements ParameterClass {
+    public Object matches(Class pClass) {
+      return (Boolean.TYPE.equals(pClass)  ||  Boolean.class.equals(pClass)) ? Boolean.TRUE : null;
+    }
+
+    public void invoke(AttributeSetterImpl pAttributeSetter, Object pBean, String pValue, Method pMethod, Object pMethodObject, String pQName) throws SAXException {
+      Boolean b = ("true".equals(pValue) || "1".equals(pValue)) ? Boolean.TRUE : Boolean.FALSE;
+      pAttributeSetter.invokeMethod(pBean, pMethod, pQName, new Object[]{b});
+    }
+  }
+
+  private static final ParameterClass[] knownClasses = new ParameterClass[]{
+    new BooleanClass(),
+    new StringClass(),
+    new ValueOfParameterClass(),
+    new StringConstructorClass(),
+    new CharacterClass(),
+    new PrimitiveParameterClass(long.class, Long.class),
+    new PrimitiveParameterClass(int.class, Integer.class),
+    new PrimitiveParameterClass(short.class, Short.class),
+    new PrimitiveParameterClass(byte.class, Byte.class),
+    new PrimitiveParameterClass(double.class, Double.class),
+    new PrimitiveParameterClass(float.class, Float.class),
+    new CharacterClass(),
+  };
+
+  /** <p>This method is invoked from within {@link #setAttribute(String, String, String, String)}.
+   * It configures the bean <code>pBean</code> as follows;
+   * <ol>
+   *    <li>If the bean has a method <code>setProperty(String)</code>
+   *      this method is invoked with the attribute value.</li>
+   *   <li>If the bean has a method <code>setProperty(T)</code>, and
+   *     the class <code>T</code> has either of a method
+   *     <code>public static T valueOf(String)</code> or a constructor
+   *     <code>public T(String)</code> (in that order), then the method
+   *     <code>setProperty(T)</code> is invoked with the value obtained
+   *     by an invocation of the method <code>valueOf()</code>, or
+   *     the constructor, respectively. Note, that this applies in
+   *     particular to the classes {@link Long}, {@link Integer},
+   *     {@link Short}, {@link Byte}, {@link Double}, {@link Float},
+   *     <code>java.math.BigInteger</code>, <code>java.math.BigDecimal</code>,
+   *     {@link java.io.File}, and {@link java.lang.StringBuffer}.</li>
+   *    <li>If the bean has a method <code>setProperty(boolean)</code>,
+   *      the method will be invoked with the value <i>true</i>
+   *      (the value specified in the XML file is either of
+   *      <code>true</code>, or <code>1</code>, otherwise with the
+   *      value <code>false</code>.</li>
+   *   <li>If the bean has a method <code>setProperty(char)</code>,
+   *     or <code>setProperty(Character)</code>, the method will be
+   *     invoked with the first character of the value specified in
+   *     the XML file. If the value contains zero or multiple characters,
+   *     an {@link IllegalArgumentException} is thrown.</li>
+   *   <li>If the bean has either of the following methods, in that order:
+   *     <ul>
+   *       <li><code>setProperty(long)</code></li>
+   *       <li><code>setProperty(int)</code></li>
+   *       <li><code>setProperty(short)</code></li>
+   *       <li><code>setProperty(byte)</code></li>
+   *       <li><code>setProperty(double)</code></li>
+   *       <li><code>setProperty(float)</code></li>
+   *     </ul>
+   *     then the property value is converted into the respective type
+   *     and the method is invoked. An {@link IllegalArgumentException}
+   *     is thrown, if the conversion fails.</li>
+   *   <li>If the bean has a method <code>java.lang.Class</code>, the
+   *     <code>XsSAXParser</code> will interpret the value given in the
+   *     XML file as a Java class name and load the named class from its
+   *     class loader. If the class cannot be loaded, it will also try
+   *     to use the current threads context class loader. An
+   *     exception is thrown, if neither of the class loaders can
+   *     load the class.</li>
+   * </ol>
+   * </p>
+   *
+   * @return True, if a method for setting the property was found. Otherwise
+   *   false.
+   */
+  protected boolean setProperty(Object pBean, String pQName, String pName, String pValue)
+      throws SAXException {
+    Class c = pBean.getClass();
+    String s = "set" + Character.toUpperCase(pName.charAt(0)) + pName.substring(1);
+    int parameterClassNum = knownClasses.length;
+    Method[] methods = c.getMethods();
+    Method method = null;
+    Object methodObject = null;
+    for (int i = 0;  i < methods.length;  i++) {
+      Method m = methods[i];
+      if (!s.equals(m.getName())  ||  !Modifier.isPublic(m.getModifiers())) {
+        continue;
+      }
+
+      Class[] params = m.getParameterTypes();
+      if (params.length != 1) {
+        continue;
+      }
+
+      Class paramsClass = params[0];
+      for (int j = 0;  j < parameterClassNum;  j++) {
+        ParameterClass parameterClass = knownClasses[j];
+        Object o = parameterClass.matches(paramsClass);
+        if (o != null) {
+          parameterClassNum = j;
+          method = m;
+          methodObject = o;
+          break;
+        }
+      }
+    }
+
+    if (method == null) {
+      return false;
+    } else {
+      knownClasses[parameterClassNum].invoke(this, pBean, pValue, method, methodObject, pQName);
+      return true;
+    }
+  }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/ChildSetterImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/ChildSetterImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/ChildSetterImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/ChildSetterImpl.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,122 @@
+/*
+ * 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.parser.impl;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.UndeclaredThrowableException;
+
+import org.apache.ws.jaxme.xs.XSParser;
+import org.apache.ws.jaxme.xs.parser.*;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+
+/** <p>Default implementation of a {@link org.apache.ws.jaxme.xs.parser.ChildSetter}.</p>
+ *
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public class ChildSetterImpl implements ChildSetter {
+  private static final Class[] GETCHILDHANDLER_CLASSES = new Class[]{String.class, String.class, String.class};
+  private static final Class[] ZERO_CLASSES = new Class[]{};
+  private static final Object[] ZERO_OBJECTS = new Object[]{};
+
+  private XSContext getData() {
+    return XSParser.getRunningInstance().getContext();
+  }
+
+  /** <p>This method invokes the beans <code>pBean</code> method <code>pMethod</code> with
+   * the argument array pArgs, returning a child handler for the element <code>pQName</code>.</p>
+   */
+  protected Object invokeMethod(Object pBean, Method pMethod, String pName, Object[] pArgs) throws SAXException {
+    try {
+      return pMethod.invoke(pBean, pArgs);
+    } catch (InvocationTargetException e) {
+      Throwable t = e.getTargetException();
+      if (t instanceof RuntimeException) {
+        throw (RuntimeException) t;
+      } else if (t instanceof SAXException) {
+        throw (SAXException) t;
+      } else {
+        throw new UndeclaredThrowableException(t);
+      }
+    } catch (IllegalAccessException e) {
+      throw new IllegalStateException("Failed to invoke method " + pMethod.getName() +
+                                       " of class " + pMethod.getDeclaringClass() +
+                                       " with argument " + pBean + ": IllegalAccessException, " +
+                                       e.getMessage()); 
+    }
+  }
+
+
+  public ContentHandler getChildHandler(String pQName,
+                                         String pNamespaceURI, String pLocalName) throws SAXException {
+    final XsSAXParser xsSAXParser = (XsSAXParser) getData().getCurrentContentHandler();
+    if (xsSAXParser == null) {
+      throw new NullPointerException("No XsSAXParser registered.");
+    }
+    final Object bean = xsSAXParser.getBean();
+    final Class beanClass = bean.getClass();
+    try {
+      Method m = beanClass.getMethod("getChildHandler", GETCHILDHANDLER_CLASSES);
+      if (Modifier.isPublic(m.getModifiers())  &&
+          ContentHandler.class.isAssignableFrom(m.getReturnType())) {
+        Object result = (ContentHandler) invokeMethod(bean, m, pQName, new Object[]{pQName, pNamespaceURI, pLocalName});
+        if (result != null) {
+          return (ContentHandler) result;
+        }
+      }
+    } catch (NoSuchMethodException e) {
+    }
+
+    final ContentHandler result = getChildHandler(xsSAXParser, pQName, pLocalName);
+    if (result == null) {
+      throw new LocSAXException("Unknown child element '" + pQName + "' for bean " + bean.getClass().getName(),
+                                 getData().getLocator());
+    }
+    return result;
+  }
+
+  /** <p>Creates a new instance of {@link XsSAXParser}, inheriting most properties from
+   * its parent parser.</p>
+   */
+  protected ContentHandler newXsSAXParser(XsSAXParser pParent, Object pBean) {
+    return getData().getXsObjectFactory().newXsSAXParser(pBean);
+  }
+
+  protected ContentHandler getChildHandler(ContentHandler pParent, String pQName, String pLocalName)
+      throws SAXException {
+    final XsSAXParser xsSAXParser = (XsSAXParser) pParent;
+    final Object bean = xsSAXParser.getBean();
+    final Class beanClass = bean.getClass();
+    final String s = Character.toUpperCase(pLocalName.charAt(0)) + pLocalName.substring(1);
+    try {
+      Method m = beanClass.getMethod("create" + s, ZERO_CLASSES);
+      if (Modifier.isPublic(m.getModifiers())  &&
+         !void.class.equals(m.getReturnType())) {
+        Object result = invokeMethod(bean, m, pQName, ZERO_OBJECTS);
+        return newXsSAXParser(xsSAXParser, result);
+      }
+    } catch (NoSuchMethodException e) {
+    } catch (SAXException e) {
+      throw e;
+    }
+
+    return null;
+  }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/LocSAXException.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/LocSAXException.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/LocSAXException.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/LocSAXException.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,112 @@
+/*
+ * 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.parser.impl;
+
+import java.io.PrintStream;
+import java.io.PrintWriter;
+
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+
+/** <p>The <code>locatable SAXException</code>, a subclass of the SAXParseException,
+ * provides a human readable representation of the location.</p>
+ *
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public class LocSAXException extends SAXParseException {
+  public static String formatMsg(String pMsg, String pPublicId, String pSystemId, int pLineNumber, int pColNumber) {
+    StringBuffer sb = new StringBuffer();
+    if (pSystemId != null) {
+      sb.append(pSystemId);
+    }
+    if (pLineNumber != -1) {
+      if (sb.length() > 0) {
+        sb.append(", ");
+      }
+      sb.append("line ").append(pLineNumber);
+    }
+    if (pColNumber != -1) {
+      if (sb.length() > 0) {
+        sb.append(", ");
+      }
+      sb.append("column ").append(pColNumber);
+    }
+    if (sb.length() == 0) {
+      return "" + pMsg;
+    } else {
+      return "At " + sb + ": " + pMsg;
+    }
+  }
+
+  private static String formatMsg(String pMsg, Locator pLocator) {
+    if (pLocator == null) {
+      return pMsg;
+    } else {
+      return formatMsg(pMsg, pLocator.getPublicId(), pLocator.getSystemId(), pLocator.getLineNumber(), pLocator.getColumnNumber());
+    }
+  }
+
+  public LocSAXException(String pMsg, String pPublicId, String pSystemId,
+                                int pLineNumber, int pColumnNumber, Exception pException) {
+    super(formatMsg(pMsg, pPublicId, pSystemId, pLineNumber, pColumnNumber),
+           pPublicId, pSystemId, pLineNumber, pColumnNumber, pException);
+  }
+
+  public LocSAXException(String pMsg, String pPublicId, String pSystemId,
+                                int pLineNumber, int pColumnNumber) {
+    super(formatMsg(pMsg, pPublicId, pSystemId, pLineNumber, pColumnNumber),
+           pPublicId, pSystemId, pLineNumber, pColumnNumber);
+  }
+
+  public LocSAXException(String pMsg, Locator pLocator, Exception pException) {
+    super(formatMsg(pMsg, pLocator), pLocator, pException);
+  }
+
+  public LocSAXException(String pMsg, Locator pLocator) {
+    super(formatMsg(pMsg, pLocator), pLocator);
+  }
+
+  public void printStackTrace(PrintStream pStream) {
+    super.printStackTrace(pStream);
+    Exception e = getException();
+    while (e != null) {
+      pStream.println("Caused by:");
+      e.printStackTrace(pStream);
+      if (e instanceof SAXException) {
+        e = ((SAXException) e).getException();
+      } else {
+        e = null;
+      }
+    }
+  }
+
+  public void printStackTrace(PrintWriter pWriter) {
+    super.printStackTrace(pWriter);
+    Exception e = getException();
+    while (e != null) {
+      pWriter.println("Caused by:");
+      e.printStackTrace(pWriter);
+      if (e instanceof SAXException) {
+        e = ((SAXException) e).getException();
+      } else {
+        e = null;
+      }
+    }
+  }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/TextSetterImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/TextSetterImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/TextSetterImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/TextSetterImpl.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,73 @@
+/*
+ * 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.parser.impl;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.UndeclaredThrowableException;
+
+import org.apache.ws.jaxme.xs.XSParser;
+import org.apache.ws.jaxme.xs.parser.XSContext;
+import org.apache.ws.jaxme.xs.parser.TextSetter;
+import org.apache.ws.jaxme.xs.parser.XsSAXParser;
+import org.xml.sax.SAXException;
+
+
+/**
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public class TextSetterImpl implements TextSetter {
+  private static final Class[] ONE_STRING_CLASS = new Class[]{String.class};
+
+  protected XSContext getData() {
+    return XSParser.getRunningInstance().getContext();
+  }
+
+  protected boolean isIgnorable(String pText) {
+    for (int i = 0;  i < pText.length();  i++) {
+      if (!Character.isWhitespace(pText.charAt(i))) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  public void addText(String pText) throws SAXException {
+    XsSAXParser handler = (XsSAXParser) getData().getCurrentContentHandler();
+    Object bean = handler.getBean();
+    try {
+      Method m = bean.getClass().getMethod("addText", ONE_STRING_CLASS);
+      m.invoke(bean, new Object[]{pText});
+    } catch (NoSuchMethodException f) {
+      if (isIgnorable(pText)) {
+        return;
+      }
+      throw new IllegalStateException("Embedded text is not supported in the '" + handler.getQName() + "' element:" + pText);
+    } catch (IllegalAccessException e) {
+      throw new IllegalStateException("Embedded text is not supported in the '" + handler.getQName() + "' element:" + pText);
+    } catch (InvocationTargetException e) {
+      Throwable t = e.getTargetException();
+      if (t instanceof RuntimeException) {
+        throw (RuntimeException) t;
+      } else if (t instanceof SAXException) {
+        throw (SAXException) t;
+      } else {
+        throw new UndeclaredThrowableException(t);
+      }
+    }
+  }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/XSContextImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/XSContextImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/XSContextImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/XSContextImpl.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,76 @@
+/*
+ * 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.parser.impl;
+
+import org.apache.ws.jaxme.xs.*;
+import org.apache.ws.jaxme.xs.impl.*;
+import org.apache.ws.jaxme.xs.parser.*;
+import org.apache.ws.jaxme.xs.parser.AttributeSetter;
+import org.apache.ws.jaxme.xs.parser.ChildSetter;
+import org.apache.ws.jaxme.xs.parser.TextSetter;
+import org.apache.ws.jaxme.xs.xml.XsObjectFactory;
+import org.apache.ws.jaxme.xs.xml.impl.XsObjectFactoryImpl;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.helpers.NamespaceSupport;
+
+
+/**
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+/** <p>This class provides access to the parsers internal data. The
+ * <code>Context</code> instance is stored as a thread local element, thus
+ * accessible via a static method.</p>
+ */
+public class XSContextImpl implements XSContext {
+  public static final XsObjectFactory DEFAULT_OBJECT_FACTORY = new XsObjectFactoryImpl();
+  public static final XSObjectFactory DEFAULT_XS_OBJECT_FACTORY = new XSObjectFactoryImpl();
+  public static final AttributeSetter DEFAULT_ATTRIBUTE_SETTER = new AttributeSetterImpl();
+  public static final ChildSetter DEFAULT_CHILD_SETTER = new ChildSetterImpl();
+  public static final TextSetter DEFAULT_TEXT_SETTER = new TextSetterImpl();
+
+  private XsObjectFactory objectFactory = DEFAULT_OBJECT_FACTORY;
+  private XSObjectFactory xSObjectFactory = DEFAULT_XS_OBJECT_FACTORY;
+  private AttributeSetter attributeSetter = DEFAULT_ATTRIBUTE_SETTER;
+  private ChildSetter childSetter = DEFAULT_CHILD_SETTER;
+  private TextSetter textSetter = DEFAULT_TEXT_SETTER;
+  private XSLogicalParser xsParser;
+  private Locator locator;
+  private NamespaceSupport namespaceSupport = new NamespaceSupport();
+  private ContentHandler currentContentHandler;
+
+  public XsObjectFactory getXsObjectFactory() { return objectFactory; }
+  public void setXsObjectFactory(XsObjectFactory pFactory) { objectFactory = pFactory; }
+  public XSObjectFactory getXSObjectFactory() { return xSObjectFactory; }
+  public void setXSObjectFactory(XSObjectFactory pFactory) { xSObjectFactory = pFactory; }
+  public AttributeSetter getAttributeSetter() { return attributeSetter; }
+  public void setAttributeSetter(AttributeSetter pAttributeSetter) { attributeSetter = pAttributeSetter; }
+  public ChildSetter getChildSetter() { return childSetter; }
+  public void setChildSetter(ChildSetter pChildSetter) { childSetter = pChildSetter; }
+  public TextSetter getTextSetter() { return textSetter; }
+  public void setTextSetter(TextSetter pTextSetter) { textSetter = pTextSetter; }
+  public XSLogicalParser getXSLogicalParser() { return xsParser; }
+  public void setXSLogicalParser(XSLogicalParser pParser) { xsParser = pParser; }
+  public XSSchema getXSSchema() { return getXSLogicalParser().getSchema(); }
+  public Locator getLocator() { return locator; }
+  public void setLocator(Locator pLocator) { locator = pLocator; }
+  public void setNamespaceSupport(NamespaceSupport pNamespaceSupport) { namespaceSupport = pNamespaceSupport; }
+  public NamespaceSupport getNamespaceSupport() { return namespaceSupport; }
+
+  public void setCurrentContentHandler(ContentHandler pHandler) { currentContentHandler = pHandler; }
+  public ContentHandler getCurrentContentHandler() { return currentContentHandler; }
+}
\ No newline at end of file

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/XsSAXParserImpl.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/XsSAXParserImpl.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/XsSAXParserImpl.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/XsSAXParserImpl.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.parser.impl;
+
+import org.apache.ws.jaxme.xs.parser.XSContext;
+
+/**
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public class XsSAXParserImpl extends AbstractXsSAXParser {
+  private final XSContext data = new XSContextImpl();
+
+  /** <p>Creates a new instance of XsSAXParserImpl.java.</p>
+   */
+  public XsSAXParserImpl(Object pBean) {
+    super(pBean);
+  }
+
+  protected XSContext getData() { return data; }
+}

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/package.html
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/package.html?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/package.html (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/impl/package.html Fri Nov 24 04:14:48 2006
@@ -0,0 +1,30 @@
+<!--
+
+ Copyright 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.
+
+-->
+<html>
+    <head>
+        <title>
+Package Documentation for org.apache.ws.jaxme.xs.parser.impl Package
+    </title>
+</head>
+    <body bgcolor="white">
+        <p>
+Implementations of adapters from xml parser mechanisms to the 
+generic schema construction framework.
+    </p>
+</body>
+</html>

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/package.html
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/package.html?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/package.html (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/parser/package.html Fri Nov 24 04:14:48 2006
@@ -0,0 +1,29 @@
+<!--
+
+ Copyright 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.
+
+-->
+<html>
+    <head>
+        <title>
+Package Documentation for org.apache.ws.jaxme.xs.parser Package
+    </title>
+</head>
+    <body bgcolor="white">
+        <p>
+Adapters from xml parser mechanisms to the generic schema construction framework.
+    </p>
+</body>
+</html>

Added: webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/types/AbstractAtomicType.java
URL: http://svn.apache.org/viewvc/webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/types/AbstractAtomicType.java?view=auto&rev=478855
==============================================================================
--- webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/types/AbstractAtomicType.java (added)
+++ webservices/jaxme/branches/MAVEN/jaxme-xs/src/main/java/org/apache/ws/jaxme/xs/types/AbstractAtomicType.java Fri Nov 24 04:14:48 2006
@@ -0,0 +1,44 @@
+/*
+ * 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.types;
+
+import org.apache.ws.jaxme.xs.XSAtomicType;
+
+
+/**
+ * @author <a href="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
+ */
+public abstract class AbstractAtomicType extends AbstractSimpleType implements XSAtomicType {
+	private static final String[] ZERO_PATTERNS = new String[0];
+	public boolean isAtomic() { return true; }
+
+  public XSAtomicType getAtomicType() { return this; }
+
+  public Long getFractionDigits() { return null; }
+  public Long getLength() { return null; }
+  public String getMaxExclusive() { return null; }
+  public String getMaxInclusive() { return null; }
+  public Long getMaxLength() { return null; }
+  public String getMinExclusive() { return null; }
+  public String getMinInclusive() { return null; }
+  public Long getMinLength() { return null; }
+  public Long getTotalDigits() { return null; }
+  public boolean isReplacing() { return false; }
+  public boolean isCollapsing() { return false; }
+  public boolean isBuiltin() { return true; }
+  	public String[] getPatterns() { return ZERO_PATTERNS; }
+}



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