Author: bimargulies
Date: Mon Dec 31 04:04:33 2007
New Revision: 607729

URL: http://svn.apache.org/viewvc?rev=607729&view=rev
Log:
Continue to give Aegis a modularity of its own.

Added:
    
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AbstractAegisDataReaderImpl.java
   (with props)
    
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisDataReader.java
   (with props)
    
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisElementDataReader.java
   (with props)
    
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataReader.java
   (with props)
    
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/Messages.properties
   (with props)
Modified:
    
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/databinding/DataReader.java
    
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/databinding/DataWriter.java
    
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java
    
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/DatabindingException.java
    
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/ElementDataReader.java
    
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataReader.java
    
incubator/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java

Modified: 
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/databinding/DataReader.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/databinding/DataReader.java?rev=607729&r1=607728&r2=607729&view=diff
==============================================================================
--- 
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/databinding/DataReader.java
 (original)
+++ 
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/databinding/DataReader.java
 Mon Dec 31 04:04:33 2007
@@ -27,6 +27,11 @@
 import org.apache.cxf.message.Attachment;
 import org.apache.cxf.service.model.MessagePartInfo;
 
+/**
+ * The 'read' side of the data binding abstraction of CXF. A 
DataReader<T> reads objects 
+ * from a source of type T.
+ * @param <T> The type of the source. Each data binding defines the set of 
source types that it supports.
+ */
 public interface DataReader<T> {
     String FAULT = DataReader.class.getName() + "Fault";
     String ENDPOINT = DataReader.class.getName() + "Endpoint";

Modified: 
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/databinding/DataWriter.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/databinding/DataWriter.java?rev=607729&r1=607728&r2=607729&view=diff
==============================================================================
--- 
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/databinding/DataWriter.java
 (original)
+++ 
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/databinding/DataWriter.java
 Mon Dec 31 04:04:33 2007
@@ -26,12 +26,43 @@
 import org.apache.cxf.message.Attachment;
 import org.apache.cxf.service.model.MessagePartInfo;
 
+/**
+ * The 'write' side of the data binding abstraction of CXF. A 
DataWriter&lt;T&gt; serializes
+ * objects to a 'sink' of type T.
+ * @param <T> The type of sink. Each data binding defines the set of sink 
types that it supports.
+ */
 public interface DataWriter<T> {
     String ENDPOINT = DataWriter.class.getName() + "Endpoint";
     
+    /**
+     * Write an object to an output sink.
+     * @param obj the object to write.
+     * @param output the output sink.
+     */
     void write(Object obj, T output);
+    /**
+     * Write an object to an output sink, including extra processing based on 
the WSDL 
+     * service model for a particular message part.
+     * @param obj The object to write.
+     * @param part the message part. 
+     * @param output the output sink.
+     */
     void write(Object obj, MessagePartInfo part, T output);
+    /**
+     * Attach a schema to the writer. If the binding supports validation, it 
will
+     * validate the XML that it produces (assuming that it produces XML). 
+     * @param s the schema.
+     */
     void setSchema(Schema s);
+    /**
+     * Attach a collection of attachments to this writer.
+     * @param attachments
+     */
     void setAttachments(Collection<Attachment> attachments);
+    /**
+     * Set a property for the writer.
+     * @param key property key 
+     * @param value property value.
+     */
     void setProperty(String key, Object value);
 }

Added: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AbstractAegisDataReaderImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AbstractAegisDataReaderImpl.java?rev=607729&view=auto
==============================================================================
--- 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AbstractAegisDataReaderImpl.java
 (added)
+++ 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AbstractAegisDataReaderImpl.java
 Mon Dec 31 04:04:33 2007
@@ -0,0 +1,78 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cxf.aegis;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.validation.Schema;
+
+import org.apache.cxf.common.util.SOAPConstants;
+import org.apache.cxf.databinding.DataReader;
+import org.apache.cxf.interceptor.Fault;
+
+/**
+ * Common implementation of the Aegis data readers.
+ */
+public abstract class AbstractAegisDataReaderImpl implements AegisDataReader {
+    protected Map<String, Object> properties;
+    protected Schema schema;
+    protected AegisContext aegisContext;
+    protected Context context;
+    
+    protected AbstractAegisDataReaderImpl(AegisContext globalContext) {
+        aegisContext = globalContext;
+        context = new Context(globalContext);
+        properties = new HashMap<String, Object>();
+    }  
+    
+    /**
+     * Due to the fact that the element data reader borrows this class, we need
+     * a constructor that takes an existing context.
+     * @param globalContext
+     * @param context
+     */
+    protected AbstractAegisDataReaderImpl(AegisContext globalContext, Context 
context) {
+        aegisContext = globalContext;
+        this.context = context;
+        properties = new HashMap<String, Object>();
+    }  
+        
+    /** [EMAIL PROTECTED]/
+    public void setProperty(String prop, Object value) {
+        if (SOAPConstants.MTOM_ENABLED.equals(prop)) {
+            if (value instanceof String) {
+                context.setMtomEnabled(Boolean.valueOf((String)value));
+            } else if (value instanceof Boolean) {
+                context.setMtomEnabled((Boolean)value);
+            }
+        } else if (DataReader.FAULT.equals(prop)) { 
+            context.setFault((Fault)value);
+        }
+    }
+
+    /** [EMAIL PROTECTED]/
+    public void setSchema(Schema s) {
+    }
+    
+    public Context getContext() {
+        return context;
+    }
+}

Propchange: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AbstractAegisDataReaderImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AbstractAegisDataReaderImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java?rev=607729&r1=607728&r2=607729&view=diff
==============================================================================
--- 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java
 (original)
+++ 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisContext.java
 Mon Dec 31 04:04:33 2007
@@ -24,6 +24,7 @@
 import java.util.Set;
 
 import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
 
 import org.apache.cxf.aegis.type.Configuration;
 import org.apache.cxf.aegis.type.DefaultTypeMappingRegistry;
@@ -90,6 +91,17 @@
         typeMapping  = 
typeMappingRegistry.createTypeMapping(SOAPConstants.XSD, true);
         typeMappingRegistry.register(mappingNamespaceURI, typeMapping);
         processOverrideTypes();
+    }
+    
+    
+    public <Reader extends AbstractAegisDataReaderImpl, Source> 
+    Reader createReader(Class<Reader> readerClass, Class<Source> sourceClass) {
+        if (sourceClass == org.w3c.dom.Element.class) {
+            return readerClass.cast(new AegisElementDataReader(this));
+        } else if (sourceClass == XMLStreamReader.class) {
+            return readerClass.cast(new AegisXMLStreamDataReader(this));
+        }
+        return null; // throw?
     }
     
     /**

Added: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisDataReader.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisDataReader.java?rev=607729&view=auto
==============================================================================
--- 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisDataReader.java
 (added)
+++ 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisDataReader.java
 Mon Dec 31 04:04:33 2007
@@ -0,0 +1,48 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cxf.aegis;
+
+import javax.xml.validation.Schema;
+
+
+/**
+ * Aegis abstraction for reading.
+ * 
+ *  Note that this interface does not include the 'read' method. Since the 
caller of a reader has to know
+ *  the type of the source object, the read method is not specified here in 
the interface, but is provided
+ *  in the specific type. 
+ */
+public interface AegisDataReader {
+    /**
+     * Supply a schema to validate the input. Bindings silently ignore this 
parameter if they
+     * do not support schema validation, or the particular form of validation 
implied by
+     * a particular form of Schema.
+     * @param s
+     */
+    void setSchema(Schema s);
+    /**
+     * Set an arbitrary property on the reader.
+     * [EMAIL PROTECTED] #FAULT} and [EMAIL PROTECTED] #ENDPOINT} specify two 
common properties: the Fault object being read
+     * and the [EMAIL PROTECTED] org.apache.cxf.endpoint.Endpoint}.
+     * @param prop Name of the property.
+     * @param value Value of the property.
+     */
+    void setProperty(String prop, Object value);
+}

Propchange: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisDataReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisDataReader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisElementDataReader.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisElementDataReader.java?rev=607729&view=auto
==============================================================================
--- 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisElementDataReader.java
 (added)
+++ 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisElementDataReader.java
 Mon Dec 31 04:04:33 2007
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cxf.aegis;
+
+import org.w3c.dom.Element;
+
+import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.staxutils.W3CDOMStreamReader;
+
+public class AegisElementDataReader extends AbstractAegisDataReaderImpl {
+
+    protected AegisXMLStreamDataReader reader;
+
+    public AegisElementDataReader(AegisContext globalContext) {
+        super(globalContext);
+        reader = new AegisXMLStreamDataReader(globalContext, context);
+    }
+
+    /**
+     * Convert a DOM element to a type.
+     * @param input
+     * @return
+     */
+    public Object read(Element input) throws Exception {
+        W3CDOMStreamReader sreader = new W3CDOMStreamReader(input);
+        sreader.nextTag(); //advance into the first tag
+        return reader.read(sreader);
+    }
+    
+    public Object read(Element input, Type desiredType) throws Exception {
+        W3CDOMStreamReader sreader = new W3CDOMStreamReader(input);
+        sreader.nextTag(); //advance into the first tag
+        return reader.read(sreader, desiredType);
+    }
+}

Propchange: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisElementDataReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisElementDataReader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataReader.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataReader.java?rev=607729&view=auto
==============================================================================
--- 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataReader.java
 (added)
+++ 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataReader.java
 Mon Dec 31 04:04:33 2007
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cxf.aegis;
+
+import java.util.logging.Logger;
+
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.type.TypeUtil;
+import org.apache.cxf.aegis.xml.stax.ElementReader;
+import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.logging.LogUtils;
+
+public class AegisXMLStreamDataReader extends AbstractAegisDataReaderImpl {
+
+    private static final Logger LOG = 
LogUtils.getL7dLogger(AegisXMLStreamDataReader.class);
+
+    public AegisXMLStreamDataReader(AegisContext globalContext) {
+        super(globalContext);
+    }
+    
+    /**
+     * This constructor is used by the Element data reader to borrow this 
class.
+     * @param globalContext
+     * @param context
+     */
+    public AegisXMLStreamDataReader(AegisContext globalContext, Context 
context) {
+        super(globalContext, context);
+    }
+
+    private void setupReaderPosition(XMLStreamReader reader) throws Exception {
+        if (reader.getEventType() == XMLStreamConstants.START_DOCUMENT) {
+            while (XMLStreamConstants.START_ELEMENT != reader.getEventType()) {
+                reader.nextTag();
+            }
+        }
+        if (reader.getEventType() != XMLStreamConstants.START_ELEMENT) {
+            Message message = new Message("STREAM_BAD_POSITION", LOG);
+            throw new DatabindingException(message.toString());
+            
+        }
+    }
+
+    public Object read(XMLStreamReader reader) throws Exception {
+        return read(reader, null);
+    }
+    
+    public Object read(XMLStreamReader reader, Type desiredType) throws 
Exception {
+        setupReaderPosition(reader);
+        ElementReader elReader = new ElementReader(reader);
+
+        if (elReader.isXsiNil()) {
+            elReader.readToEnd();
+            return null;
+        }
+        
+        Type type = TypeUtil.getReadType(reader, aegisContext, desiredType);
+        
+        if (type == null) {
+            throw new DatabindingException(new Message("NO_MAPPING", LOG));
+        }
+
+        return type.readObject(elReader, context);
+    }
+}

Propchange: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataReader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataReader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/DatabindingException.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/DatabindingException.java?rev=607729&r1=607728&r2=607729&view=diff
==============================================================================
--- 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/DatabindingException.java
 (original)
+++ 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/DatabindingException.java
 Mon Dec 31 04:04:33 2007
@@ -23,6 +23,8 @@
 import java.util.LinkedList;
 import java.util.List;
 
+import org.apache.cxf.common.i18n.Message;
+
 /**
  * 
  * 
@@ -53,6 +55,14 @@
      */
     public DatabindingException(String message, Throwable cause) {
         super(message, cause);
+    }
+    
+    public DatabindingException(Message message) {
+        super(message.toString());
+    }
+
+    public DatabindingException(Message message, Throwable cause) {
+        super(message.toString(), cause);
     }
 
 

Added: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/Messages.properties
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/Messages.properties?rev=607729&view=auto
==============================================================================
--- 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/Messages.properties
 (added)
+++ 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/Messages.properties
 Mon Dec 31 04:04:33 2007
@@ -0,0 +1,25 @@
+#
+#
+#    Licensed to the Apache Software Foundation (ASF) under one
+#    or more contributor license agreements. See the NOTICE file
+#    distributed with this work for additional information
+#    regarding copyright ownership. The ASF licenses this file
+#    to you 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.
+#
+#
+STREAM_BAD_POSITION=The input stream is not positioned at START_DOCUMENT or 
START_ELEMENT.
+STREAM_READ_ERROR=Error reading XML input stream.
+MAPPED_CLASS_NOT_FOUND=Class {0} from service property {1} not found.
+NO_MAPPING=No mapping found for XML input.
+

Propchange: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/Messages.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/Messages.properties
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/Messages.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/ElementDataReader.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/ElementDataReader.java?rev=607729&r1=607728&r2=607729&view=diff
==============================================================================
--- 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/ElementDataReader.java
 (original)
+++ 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/ElementDataReader.java
 Mon Dec 31 04:04:33 2007
@@ -22,34 +22,37 @@
 import java.util.Collection;
 
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
 import javax.xml.validation.Schema;
 
 import org.w3c.dom.Element;
 
+import org.apache.cxf.aegis.AegisElementDataReader;
+import org.apache.cxf.aegis.type.Type;
 import org.apache.cxf.databinding.DataReader;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Attachment;
 import org.apache.cxf.service.model.MessagePartInfo;
-import org.apache.cxf.staxutils.W3CDOMStreamReader;
 
 /**
  * 
  */
 public class ElementDataReader implements DataReader<Element> {
-    XMLStreamDataReader reader;
+    
+    private AegisElementDataReader reader;
+    private AegisDatabinding databinding;
     
     ElementDataReader(AegisDatabinding binding) {
-        reader = new XMLStreamDataReader(binding);
+        databinding = binding;
+        reader = new AegisElementDataReader(binding.getAegisContext()); 
     }
 
-    /** [EMAIL PROTECTED]/
+    /**
+     * [EMAIL PROTECTED]
+     */
     public Object read(Element input) {
         try {
-            W3CDOMStreamReader sreader = new W3CDOMStreamReader(input);
-            sreader.nextTag(); //advance into the first tag
-            return reader.read(sreader);
-        } catch (XMLStreamException e) {
+            return reader.read(input);
+        } catch (Exception e) {
             throw new Fault(e);
         }
     }
@@ -57,38 +60,35 @@
     /** [EMAIL PROTECTED]/
     public Object read(MessagePartInfo part, Element input) {
         try {
-            W3CDOMStreamReader sreader = new W3CDOMStreamReader(input);
-            sreader.nextTag(); //advance into the first tag
-            return reader.read(part, sreader);
-        } catch (XMLStreamException e) {
+            Type type = databinding.getType(part);
+            return reader.read(input, type);
+        } catch (Exception e) {
             throw new Fault(e);
         }
     }
 
     /** [EMAIL PROTECTED]/
-    public Object read(QName name, Element input, Class type) {
+    public Object read(QName name, Element input, Class typeClass) {
         try {
-            W3CDOMStreamReader sreader = new W3CDOMStreamReader(input);
-            sreader.nextTag(); //advance into the first tag
-            return reader.read(name, sreader, type);
-        } catch (XMLStreamException e) {
+            // TODO: pay attention to the typeClass parameter.
+            return reader.read(input);
+        } catch (Exception e) {
             throw new Fault(e);
         }
     }
 
-    /** [EMAIL PROTECTED]/
+    /** 
+     * [EMAIL PROTECTED]
+     * */
     public void setAttachments(Collection<Attachment> attachments) {
-        reader.setAttachments(attachments);
+        reader.getContext().setAttachments(attachments);
     }
 
-    /** [EMAIL PROTECTED]/
     public void setProperty(String prop, Object value) {
         reader.setProperty(prop, value);
     }
 
-    /** [EMAIL PROTECTED]/
     public void setSchema(Schema s) {
         reader.setSchema(s);
     }
-
 }

Modified: 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataReader.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataReader.java?rev=607729&r1=607728&r2=607729&view=diff
==============================================================================
--- 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataReader.java
 (original)
+++ 
incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/XMLStreamDataReader.java
 Mon Dec 31 04:04:33 2007
@@ -19,22 +19,13 @@
 package org.apache.cxf.aegis.databinding;
 
 import java.util.Collection;
-import java.util.logging.Logger;
 
 import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.validation.Schema;
 
-import org.apache.cxf.aegis.Context;
-import org.apache.cxf.aegis.DatabindingException;
+import org.apache.cxf.aegis.AegisXMLStreamDataReader;
 import org.apache.cxf.aegis.type.Type;
-import org.apache.cxf.aegis.type.TypeUtil;
-import org.apache.cxf.aegis.xml.stax.ElementReader;
-import org.apache.cxf.common.i18n.Message;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.SOAPConstants;
 import org.apache.cxf.databinding.DataReader;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.message.Attachment;
@@ -42,124 +33,45 @@
 
 public class XMLStreamDataReader implements DataReader<XMLStreamReader> {
 
-    private static final Logger LOG = 
LogUtils.getL7dLogger(XMLStreamDataReader.class);
-
     private AegisDatabinding databinding;
-
-    private Context context;
+    private AegisXMLStreamDataReader reader;
 
     public XMLStreamDataReader(AegisDatabinding databinding) {
         this.databinding = databinding;
-        this.context = new Context(databinding.getAegisContext());
+        reader = new AegisXMLStreamDataReader(databinding.getAegisContext());
     }
 
     public Object read(MessagePartInfo part, XMLStreamReader input) {
-
         Type type = databinding.getType(part);
-
-        type = TypeUtil.getReadType(input, databinding.getAegisContext(), 
type);
-        
-        if (type == null) {
-            throw new Fault(new Message("NO_MESSAGE_FOR_PART", LOG));
-        }
-        
-        ElementReader elReader = new ElementReader(input);
-        if (elReader.isXsiNil()) {
-            elReader.readToEnd();
-            return null;
-        }
-
         try {
-            return type.readObject(elReader, context);
-        } catch (DatabindingException e) {
-            throw new RuntimeException(e);
+            return reader.read(input, type); 
+        } catch (Exception e) {
+            throw new Fault(e);
         }
     }
 
-    private void setupReaderPosition(XMLStreamReader reader) {
-        if (reader.getEventType() == XMLStreamConstants.START_DOCUMENT) {
-            while (XMLStreamConstants.START_ELEMENT != reader.getEventType()) {
-                try {
-                    reader.nextTag();
-                } catch (XMLStreamException e) {
-                    Message message = new Message("STREAM_READ_ERROR", LOG);
-                    throw new DatabindingException(message.toString(), e);
-                }
-            }
-        }
-        if (reader.getEventType() != XMLStreamConstants.START_ELEMENT) {
-            Message message = new Message("STREAM_BAD_POSITION", LOG);
-            throw new DatabindingException(message.toString());
-            
-        }
+    public Object read(QName name, XMLStreamReader input, Class typeClass) {
+        return read(input);
     }
 
-    public Object read(QName name, XMLStreamReader reader, Class typeClass) {
-        setupReaderPosition(reader);
-        ElementReader elReader = new ElementReader(reader);
-
-        if (elReader.isXsiNil()) {
-            elReader.readToEnd();
-            return null;
-        }
-        
-        
-        Type type = TypeUtil.getReadType(reader, context.getGlobalContext(), 
null);
-        
-        if (type == null) {
-            return null; // throw ?
-        }
-        
-
-        try {
-            return type.readObject(elReader, context);
-        } catch (DatabindingException e) {
-            throw new RuntimeException(e);
-        }
-
-    }
-
-    public Object read(XMLStreamReader reader) {
-        setupReaderPosition(reader);
-        ElementReader elReader = new ElementReader(reader);
-
-        if (elReader.isXsiNil()) {
-            elReader.readToEnd();
-            return null;
-        }
-        
-        
-        Type type = TypeUtil.getReadType(reader, context.getGlobalContext(), 
null);
-        
-        if (type == null) {
-            return null; // throw ?
-        }
-        
-
+    public Object read(XMLStreamReader input) {
         try {
-            return type.readObject(elReader, context);
-        } catch (DatabindingException e) {
-            throw new RuntimeException(e);
+            return reader.read(input, null);
+        } catch (Exception e) {
+            throw new Fault(e);
         }
     }
 
     public void setAttachments(Collection<Attachment> attachments) {
-        context.setAttachments(attachments);
+        reader.getContext().setAttachments(attachments);
     }
 
     public void setProperty(String prop, Object value) {
-        if (SOAPConstants.MTOM_ENABLED.equals(prop)) {
-            if (value instanceof String) {
-                context.setMtomEnabled(Boolean.valueOf((String)value));
-            } else if (value instanceof Boolean) {
-                context.setMtomEnabled((Boolean)value);
-            }
-        } else if (DataReader.FAULT.equals(prop)) { 
-            context.setFault((Fault)value);
-        }
+        reader.setProperty(prop, value);
     }
 
     public void setSchema(Schema s) {
+        reader.setSchema(s);
     }
 
 }

Modified: 
incubator/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java?rev=607729&r1=607728&r2=607729&view=diff
==============================================================================
--- 
incubator/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
 (original)
+++ 
incubator/cxf/trunk/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
 Mon Dec 31 04:04:33 2007
@@ -136,17 +136,11 @@
     }
 
     public void setAttachments(Collection<Attachment> attachments) {
-        // TODO Auto-generated method stub
-        
     }
 
     public void setProperty(String key, Object value) {
-        // TODO Auto-generated method stub
-        
     }
 
     public void setSchema(Schema s) {
-        // TODO Auto-generated method stub
-        
     }
 }


Reply via email to