cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r607956 - in /incubator/cxf/trunk/rt/databinding/aegis/src: main/java/org/apache/cxf/aegis/ main/java/org/apache/cxf/aegis/type/ test/java/org/apache/cxf/aegis/standalone/
Date Wed, 02 Jan 2008 01:21:23 GMT
Author: bimargulies
Date: Tue Jan  1 17:21:17 2008
New Revision: 607956

URL: http://svn.apache.org/viewvc?rev=607956&view=rev
Log:
Start to sketch in the write side. More to the point, get rid of the silly exercise in overparameterization
in the AegisContext.

Added:
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AbstractAegisIoImpl.java
      - copied, changed from r607763, incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AbstractAegisDataReaderImpl.java
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisIo.java
      - copied, changed from r607763, incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisDataReader.java
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisReader.java
  (with props)
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisWriter.java
  (with props)
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataWriter.java
  (with props)
Removed:
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AbstractAegisDataReaderImpl.java
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisDataReader.java
Modified:
    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/AegisElementDataReader.java
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataReader.java
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
    incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/StandaloneReadTest.java

Copied: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AbstractAegisIoImpl.java
(from r607763, 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/AbstractAegisIoImpl.java?p2=incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AbstractAegisIoImpl.java&p1=incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AbstractAegisDataReaderImpl.java&r1=607763&r2=607956&rev=607956&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AbstractAegisDataReaderImpl.java
(original)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AbstractAegisIoImpl.java
Tue Jan  1 17:21:17 2008
@@ -29,15 +29,15 @@
 import org.apache.cxf.interceptor.Fault;
 
 /**
- * Common implementation of the Aegis data readers.
+ * Common implementation of the Aegis data readers and writer.
  */
-public abstract class AbstractAegisDataReaderImpl implements AegisDataReader {
+public abstract class AbstractAegisIoImpl  {
     protected Map<String, Object> properties;
     protected Schema schema;
     protected AegisContext aegisContext;
     protected Context context;
     
-    protected AbstractAegisDataReaderImpl(AegisContext globalContext) {
+    protected AbstractAegisIoImpl(AegisContext globalContext) {
         aegisContext = globalContext;
         context = new Context(globalContext);
         properties = new HashMap<String, Object>();
@@ -49,7 +49,7 @@
      * @param globalContext
      * @param context
      */
-    protected AbstractAegisDataReaderImpl(AegisContext globalContext, Context context) {
+    protected AbstractAegisIoImpl(AegisContext globalContext, Context context) {
         aegisContext = globalContext;
         this.context = context;
         properties = new HashMap<String, Object>();

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=607956&r1=607955&r2=607956&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
Tue Jan  1 17:21:17 2008
@@ -110,14 +110,14 @@
     }
     
     
-    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?
+    public AegisReader<org.w3c.dom.Element>
+    createDomElementReader() {
+        return new AegisElementDataReader(this);
+    }
+    
+    public AegisReader<XMLStreamReader>
+    createXMLStreamReader() {
+        return new AegisXMLStreamDataReader(this);
     }
     
     /**

Modified: 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=607956&r1=607955&r2=607956&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisElementDataReader.java
(original)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisElementDataReader.java
Tue Jan  1 17:21:17 2008
@@ -24,8 +24,8 @@
 import org.apache.cxf.aegis.type.Type;
 import org.apache.cxf.staxutils.W3CDOMStreamReader;
 
-public class AegisElementDataReader extends AbstractAegisDataReaderImpl {
-
+public class AegisElementDataReader extends AbstractAegisIoImpl 
+                                    implements AegisReader<Element> {
     protected AegisXMLStreamDataReader reader;
 
     public AegisElementDataReader(AegisContext globalContext) {

Copied: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisIo.java
(from r607763, 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/AegisIo.java?p2=incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisIo.java&p1=incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisDataReader.java&r1=607763&r2=607956&rev=607956&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisDataReader.java
(original)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisIo.java
Tue Jan  1 17:21:17 2008
@@ -29,7 +29,7 @@
  *  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 {
+public interface AegisIo {
     /**
      * 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

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisReader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisReader.java?rev=607956&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisReader.java
(added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisReader.java
Tue Jan  1 17:21:17 2008
@@ -0,0 +1,45 @@
+/**
+ * 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.apache.cxf.aegis.type.Type;
+
+/**
+ * Interface for Aegis readers.
+ * @param <ReaderT>
+ */
+public interface AegisReader<ReaderT> extends AegisIo {
+
+    /**
+     * Read an object. 
+     * @param reader the source.
+     * @return
+     * @throws Exception
+     */
+    Object read(ReaderT reader) throws Exception;
+    /**
+     * Read an object expecting a particular input type.
+     * @param reader the source.
+     * @param desiredType the expected input type.
+     * @return
+     * @throws Exception
+     */
+    Object read(ReaderT reader, Type desiredType) throws Exception;
+
+}

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

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

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisWriter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisWriter.java?rev=607956&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisWriter.java
(added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisWriter.java
Tue Jan  1 17:21:17 2008
@@ -0,0 +1,45 @@
+/**
+ * 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.namespace.QName;
+
+import org.apache.cxf.aegis.type.Type;
+
+/**
+ * Interface for Aegis writers.
+ * @param <SinkT>
+ */
+public interface AegisWriter<SinkT> extends AegisIo {
+    /**
+     * Write an object to the sink.
+     * @param obj The object.
+     * @param elementName The element QName.
+     * @param optional true to omit for null. (minOccurs=0)
+     * @param output The output sink.
+     * @param aegisType The aegis type to use. Null is allowed, but only if
+     * obj is not null. 
+     * @throws Exception
+     */
+    void write(Object obj, 
+               QName elementName,
+               boolean optional,
+               SinkT output, 
+               Type aegisType) throws Exception;
+}

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

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

Modified: 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=607956&r1=607955&r2=607956&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataReader.java
(original)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataReader.java
Tue Jan  1 17:21:17 2008
@@ -28,7 +28,7 @@
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
 
-public class AegisXMLStreamDataReader extends AbstractAegisDataReaderImpl {
+public class AegisXMLStreamDataReader extends AbstractAegisIoImpl implements AegisReader<XMLStreamReader>
{
 
     private static final Logger LOG = LogUtils.getL7dLogger(AegisXMLStreamDataReader.class);
 
@@ -58,10 +58,12 @@
         }
     }
 
+    /** {@inheritDoc}*/
     public Object read(XMLStreamReader reader) throws Exception {
         return read(reader, null);
     }
     
+    /** {@inheritDoc}*/
     public Object read(XMLStreamReader reader, Type desiredType) throws Exception {
         setupReaderPosition(reader);
         ElementReader elReader = new ElementReader(reader);

Added: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataWriter.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataWriter.java?rev=607956&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataWriter.java
(added)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/AegisXMLStreamDataWriter.java
Tue Jan  1 17:21:17 2008
@@ -0,0 +1,83 @@
+/**
+ * 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.namespace.QName;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.type.TypeUtil;
+import org.apache.cxf.aegis.xml.MessageWriter;
+import org.apache.cxf.aegis.xml.stax.ElementWriter;
+import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.logging.LogUtils;
+
+public class AegisXMLStreamDataWriter extends AbstractAegisIoImpl implements AegisWriter<XMLStreamWriter>
{
+
+    private static final Logger LOG = LogUtils.getL7dLogger(AegisXMLStreamDataWriter.class);
+
+    AegisXMLStreamDataWriter(AegisContext globalContext) {
+        super(globalContext);
+    }
+    
+    /**
+     * Write an object to the output.
+     * @param obj The object to write.
+     * @param elementName the QName of the XML Element.
+     * @param optional set this for minOccurs = 0. It omits null elements.
+     * @param output the output stream
+     * @param aegisType the aegis type.
+     * @throws Exception
+     */
+    public void write(Object obj, 
+                      QName elementName,
+                      boolean optional,
+                      XMLStreamWriter output, 
+                      Type aegisType) throws Exception {
+        
+        if (obj == null && aegisType == null && !optional) {
+            Message message = new Message("WRITE_NEEDS_TYPE", LOG);
+            throw new DatabindingException(message);
+        }
+        
+        if (obj != null) {
+            aegisType = TypeUtil.getWriteType(aegisContext, obj, aegisType);
+        }
+        
+        if (obj == null) {
+            if (optional) { // minOccurs = 0
+                return;
+            }
+            if (aegisType.isNillable() && aegisType.isWriteOuter()) {
+                ElementWriter writer = new ElementWriter(output);
+                MessageWriter w2 = writer.getElementWriter(elementName);
+                w2.writeXsiNil();
+                w2.close();
+                return;
+            }
+        }
+        
+        ElementWriter writer = new ElementWriter(output);
+        MessageWriter w2 = writer.getElementWriter(elementName);
+        aegisType.writeObject(obj, w2, context);
+        w2.close();
+    }
+}

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

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

Modified: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java?rev=607956&r1=607955&r2=607956&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
(original)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/TypeUtil.java
Tue Jan  1 17:21:17 2008
@@ -140,4 +140,17 @@
         return type;
     }
 
+    public static Type getWriteTypeStandalone(AegisContext globalContext, Object value, Type
type) {
+        if (type != null) {
+            return getWriteType(globalContext, value, type);
+        }
+        
+        TypeMapping tm;
+        tm = globalContext.getTypeMapping();
+        // don't use this for null!
+        type = tm.getType(value.getClass());
+
+        return type;
+    }
+
 }

Modified: incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/StandaloneReadTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/StandaloneReadTest.java?rev=607956&r1=607955&r2=607956&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/StandaloneReadTest.java
(original)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/test/java/org/apache/cxf/aegis/standalone/StandaloneReadTest.java
Tue Jan  1 17:21:17 2008
@@ -25,7 +25,7 @@
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.cxf.aegis.AegisContext;
-import org.apache.cxf.aegis.AegisXMLStreamDataReader;
+import org.apache.cxf.aegis.AegisReader;
 import org.apache.cxf.aegis.services.SimpleBean;
 import org.apache.cxf.test.TestUtilities;
 import org.junit.Before;
@@ -50,8 +50,7 @@
         context = new AegisContext();
         context.initialize();
         XMLStreamReader streamReader = testUtilities.getResourceAsXMLStreamReader("stringElement.xml");
-        AegisXMLStreamDataReader reader = 
-            context.createReader(AegisXMLStreamDataReader.class, XMLStreamReader.class);
+        AegisReader<XMLStreamReader> reader = context.createXMLStreamReader();
         Object something = reader.read(streamReader);
         assertTrue("ball-of-yarn".equals(something));
     }
@@ -66,8 +65,7 @@
         context.initialize();
         XMLStreamReader streamReader = 
             testUtilities.getResourceAsXMLStreamReader("simpleBean1.xml");
-        AegisXMLStreamDataReader reader = 
-            context.createReader(AegisXMLStreamDataReader.class, XMLStreamReader.class);
+        AegisReader<XMLStreamReader> reader = context.createXMLStreamReader();
         Object something = reader.read(streamReader);
         assertTrue(something instanceof SimpleBean);
         SimpleBean simpleBean = (SimpleBean) something;



Mime
View raw message