You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2008/07/01 21:44:47 UTC

svn commit: r673189 - in /cxf/trunk/rt/databinding/jaxb/src: main/java/org/apache/cxf/jaxb/ main/java/org/apache/cxf/jaxb/io/ test/java/org/apache/cxf/jaxb/

Author: dkulp
Date: Tue Jul  1 12:44:47 2008
New Revision: 673189

URL: http://svn.apache.org/viewvc?rev=673189&view=rev
Log:
[CXF-1677, CXF-1674] Add support to specify unmarshall properties as well as marshal and unmarshal listeners

Modified:
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
    cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
    cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java
    cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java?rev=673189&r1=673188&r2=673189&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java Tue Jul  1 12:44:47 2008
@@ -41,7 +41,9 @@
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
 import javax.xml.bind.SchemaOutputResolver;
+import javax.xml.bind.Unmarshaller;
 import javax.xml.stream.XMLEventReader;
 import javax.xml.stream.XMLEventWriter;
 import javax.xml.stream.XMLStreamReader;
@@ -144,7 +146,10 @@
 
     private Map<String, Object> contextProperties = Collections.emptyMap();
     private Map<String, Object> marshallerProperties = Collections.emptyMap();
-
+    private Map<String, Object> unmarshallerProperties = Collections.emptyMap();
+    private Unmarshaller.Listener unmarshallerListener;
+    private Marshaller.Listener marshallerListener;
+    
     private boolean qualifiedSchemas;
     private Service service;
 
@@ -174,7 +179,7 @@
         context = ctx;
     }
 
-    private NamespacePrefixMapper getNamespacePrefixMapper() {
+    public NamespacePrefixMapper getNamespacePrefixMapper() {
         Map<String, String> mappings = getDeclaredNamespaceMappings();
         if (mappings == null) {
             mappings = Collections.emptyMap();
@@ -197,38 +202,23 @@
 
     @SuppressWarnings("unchecked")
     public <T> DataWriter<T> createWriter(Class<T> c) {
-        Map<String, Object> currentMarshallerProperties = new HashMap<String, Object>();
-        if (!marshallerProperties.containsKey("com.sun.xml.bind.namespacePrefixMapper")) {
-            currentMarshallerProperties.put("com.sun.xml.bind.namespacePrefixMapper",
-                                            getNamespacePrefixMapper());
-        }
-        currentMarshallerProperties.putAll(marshallerProperties);
 
         Integer mtomThresholdInt = new Integer(getMtomThreshold());
         if (c == XMLStreamWriter.class) {
             DataWriterImpl<XMLStreamWriter> r 
-                = new DataWriterImpl<XMLStreamWriter>(
-                    context,
-                    currentMarshallerProperties,
-                    contextClasses);
+                = new DataWriterImpl<XMLStreamWriter>(this);
             r.setMtomThreshold(mtomThresholdInt);
             return (DataWriter<T>)r;
         } else if (c == OutputStream.class) {
-            DataWriterImpl<OutputStream> r = new DataWriterImpl<OutputStream>(context,
-                                                                              currentMarshallerProperties,
-                                                                              contextClasses);
+            DataWriterImpl<OutputStream> r = new DataWriterImpl<OutputStream>(this);
             r.setMtomThreshold(mtomThresholdInt);
             return (DataWriter<T>)r;
         } else if (c == XMLEventWriter.class) {
-            DataWriterImpl<XMLEventWriter> r = new DataWriterImpl<XMLEventWriter>(
-                                                                                  context,
-                                                                                  currentMarshallerProperties,
-                                                                                  contextClasses);
+            DataWriterImpl<XMLEventWriter> r = new DataWriterImpl<XMLEventWriter>(this);
             r.setMtomThreshold(mtomThresholdInt);
             return (DataWriter<T>)r;
         } else if (c == Node.class) {
-            DataWriterImpl<Node> r = new DataWriterImpl<Node>(context, currentMarshallerProperties,
-                                                              contextClasses);
+            DataWriterImpl<Node> r = new DataWriterImpl<Node>(this);
             r.setMtomThreshold(mtomThresholdInt);
             return (DataWriter<T>)r;
         }
@@ -243,11 +233,11 @@
     public <T> DataReader<T> createReader(Class<T> c) {
         DataReader<T> dr = null;
         if (c == XMLStreamReader.class) {
-            dr = (DataReader<T>)new DataReaderImpl<XMLStreamReader>(context, contextClasses);
+            dr = (DataReader<T>)new DataReaderImpl<XMLStreamReader>(this);
         } else if (c == XMLEventReader.class) {
-            dr = (DataReader<T>)new DataReaderImpl<XMLEventReader>(context, contextClasses);
+            dr = (DataReader<T>)new DataReaderImpl<XMLEventReader>(this);
         } else if (c == Node.class) {
-            dr = (DataReader<T>)new DataReaderImpl<Node>(context, contextClasses);
+            dr = (DataReader<T>)new DataReaderImpl<Node>(this);
         }
 
         return dr;
@@ -560,7 +550,11 @@
             }
         }
     }
-
+    
+    public Set<Class<?>> getContextClasses() {
+        return Collections.unmodifiableSet(this.contextClasses);
+    }
+    
     // Now we can not add all the classes that Jaxb needed into JaxbContext,
     // especially when
     // an ObjectFactory is pointed to by an jaxb @XmlElementDecl annotation
@@ -636,6 +630,60 @@
     }
     
     
+    /**
+     * Return a map of properties. These properties are set into the JAXB
+     * Unmarshaller (via Unmarshaller.setProperty(...) when the unmarshaller is
+     * created.
+     * 
+     * @return the map of JAXB unmarshaller properties.
+     */
+    public Map<String, Object> getUnmarshallerProperties() {
+        return unmarshallerProperties;
+    }
+
+    /**
+     * Set a map of JAXB unmarshaller properties. These properties are set into
+     * the JAXB Unmarshaller (via Unmarshaller.setProperty(...) when the unmarshaller
+     * is created.
+     * 
+     * @param unmarshallerProperties map of properties.
+     */
+    public void setUnmarshallerProperties(Map<String, Object> unmarshallerProperties) {
+        this.unmarshallerProperties = unmarshallerProperties;
+    }
+    
+    /**
+     * Returns the Unmarshaller.Listener that will be registered on the Unmarshallers
+     * @return
+     */
+    public Unmarshaller.Listener getUnmarshallerListener() {
+        return unmarshallerListener;
+    }
+
+    /**
+     * Sets the Unmarshaller.Listener that will be registered on the Unmarshallers
+     * @param unmarshallerListener
+     */
+    public void setUnmarshallerListener(Unmarshaller.Listener unmarshallerListener) {
+        this.unmarshallerListener = unmarshallerListener;
+    }
+    /**
+     * Returns the Marshaller.Listener that will be registered on the Marshallers
+     * @return
+     */
+    public Marshaller.Listener getMarshallerListener() {
+        return marshallerListener;
+    }
+
+    /**
+     * Sets the Marshaller.Listener that will be registered on the Marshallers
+     * @param marshallerListener
+     */
+    public void setMarshallerListener(Marshaller.Listener marshallerListener) {
+        this.marshallerListener = marshallerListener;
+    }
+
+    
     public static void clearCaches() {
         synchronized (JAXBCONTEXT_CACHE) {
             JAXBCONTEXT_CACHE.clear();
@@ -644,4 +692,5 @@
             OBJECT_FACTORY_CACHE.clear();
         }
     }
+
 }

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java?rev=673189&r1=673188&r2=673189&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java Tue Jul  1 12:44:47 2008
@@ -33,18 +33,13 @@
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
-import java.util.Map;
-import java.util.ResourceBundle;
 import java.util.Set;
-import java.util.logging.Level;
 import java.util.logging.Logger;
 
 
-import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
-import javax.xml.bind.PropertyException;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
@@ -59,7 +54,6 @@
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.stream.StreamResult;
-import javax.xml.validation.Schema;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 
@@ -67,7 +61,6 @@
 import com.sun.xml.bind.api.JAXBRIContext;
 import com.sun.xml.bind.api.TypeReference;
 
-import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.helpers.CastUtils;
@@ -84,41 +77,25 @@
  * Utility functions for JAXB.
  */
 public final class JAXBEncoderDecoder {
-    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXBEncoderDecoder.class);
     private static final Logger LOG = LogUtils.getLogger(JAXBEncoderDecoder.class);
 
     private JAXBEncoderDecoder() {
     }
 
-    private static Marshaller createMarshaller(JAXBContext context, 
-                                               Class<?> cls,
-                                               Map<String, Object> marshallerProperties) throws 
-                                               JAXBException {
-        Marshaller jm = null;
-        if (context == null) {
-            context = JAXBContext.newInstance(cls);
-        }
-
-        jm = context.createMarshaller();
-        jm.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
-        jm.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
-        if (marshallerProperties != null) {
-            for (Map.Entry<String, Object> propEntry : marshallerProperties.entrySet()) {
-                try {
-                    jm.setProperty(propEntry.getKey(), propEntry.getValue());
-                } catch (PropertyException pe) {
-                    LOG.log(Level.INFO, "PropertyException setting Marshaller properties", pe);
-                }
-            }
-        }
-
-        return jm;
-    }
-
     @SuppressWarnings("unchecked")
-    public static void marshall(JAXBContext context, Schema schema, Object elValue, MessagePartInfo part,
-                                Object source, AttachmentMarshaller am,
-                                Map<String, Object> marshallerProperties) {
+    public static void marshall(Marshaller marshaller, 
+                                Object elValue, 
+                                MessagePartInfo part,
+                                Object source) {
+        try {
+            // The Marshaller.JAXB_FRAGMENT will tell the Marshaller not to
+            // generate the xml declaration.
+            marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
+            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
+        } catch (javax.xml.bind.PropertyException e) {
+            // intentionally empty.
+        }
+        
         Class<?> cls = null;
         if (part != null) {
             cls = part.getTypeClass();
@@ -134,24 +111,11 @@
         }
 
         try {
-            Marshaller u = createMarshaller(context, cls, marshallerProperties);
-            try {
-                // The Marshaller.JAXB_FRAGMENT will tell the Marshaller not to
-                // generate the xml declaration.
-                u.setProperty(Marshaller.JAXB_FRAGMENT, true);
-                u.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
-            } catch (javax.xml.bind.PropertyException e) {
-                // intentionally empty.
-            }
             Object mObj = elValue;
             QName elName = null;
             if (part != null) {
                 elName = part.getConcreteName();
             }
-            u.setSchema(schema);
-            if (am != null) {
-                u.setAttachmentMarshaller(am);
-            }
 
             if (null != elName) {
 
@@ -164,7 +128,7 @@
                         && ((XmlSchemaSimpleType)el.getSchemaType()).
                         getContent() instanceof XmlSchemaSimpleTypeList) {
                         mObj = Arrays.asList((Object[])mObj);
-                        writeObject(u, source, new JAXBElement(elName, cls, mObj));
+                        writeObject(marshaller, source, new JAXBElement(elName, cls, mObj));
                     } else if (part.getMessageInfo().getOperation().isUnwrapped()
                                && (mObj.getClass().isArray() || mObj instanceof List)
                                && el.getMaxOccurs() != 1) {
@@ -182,32 +146,33 @@
                         int len = Array.getLength(objArray);
                         for (int x = 0; x < len; x++) {
                             Object o = Array.get(objArray, x);
-                            writeObject(u, source, new JAXBElement(elName, cls == null ? o.getClass() : cls,
+                            writeObject(marshaller, source, 
+                                        new JAXBElement(elName, cls == null ? o.getClass() : cls,
                                                                    o));
                         }
                     } else {
-                        writeObject(u, source, new JAXBElement(elName, cls, mObj));
+                        writeObject(marshaller, source, new JAXBElement(elName, cls, mObj));
                     }
                 } else if (byte[].class == cls && part.getTypeQName() != null
                            && part.getTypeQName().getLocalPart().equals("hexBinary")) {
                     mObj = new HexBinaryAdapter().marshal((byte[])mObj);
-                    writeObject(u, source, new JAXBElement(elName, String.class, mObj));
+                    writeObject(marshaller, source, new JAXBElement(elName, String.class, mObj));
                 } else {
-                    writeObject(u, source, new JAXBElement(elName, cls, mObj));
+                    writeObject(marshaller, source, new JAXBElement(elName, cls, mObj));
                 }
             } else {
-                writeObject(u, source, mObj);
+                writeObject(marshaller, source, mObj);
             }
         } catch (Fault ex) {
             throw (Fault)ex.fillInStackTrace();
         } catch (Exception ex) {
             if (ex instanceof javax.xml.bind.MarshalException) {
                 javax.xml.bind.MarshalException marshalEx = (javax.xml.bind.MarshalException)ex;
-                Message faultMessage = new Message("MARSHAL_ERROR", BUNDLE, marshalEx.getLinkedException()
+                Message faultMessage = new Message("MARSHAL_ERROR", LOG, marshalEx.getLinkedException()
                     .getMessage());
                 throw new Fault(faultMessage, ex);
             } else {
-                throw new Fault(new Message("MARSHAL_ERROR", BUNDLE, ex.getMessage()), ex);
+                throw new Fault(new Message("MARSHAL_ERROR", LOG, ex.getMessage()), ex);
             }
         }
     }
@@ -238,17 +203,17 @@
             } else if (source instanceof Node) {
                 bridge.marshal(elValue, (Node)source);
             } else {
-                throw new Fault(new Message("UNKNOWN_SOURCE", BUNDLE, source.getClass().getName()));
+                throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
             }
         } catch (Exception ex) {
             ex.printStackTrace();
             if (ex instanceof javax.xml.bind.MarshalException) {
                 javax.xml.bind.MarshalException marshalEx = (javax.xml.bind.MarshalException)ex;
-                Message faultMessage = new Message("MARSHAL_ERROR", BUNDLE, marshalEx.getLinkedException()
+                Message faultMessage = new Message("MARSHAL_ERROR", LOG, marshalEx.getLinkedException()
                     .getMessage());
                 throw new Fault(faultMessage, ex);
             } else {
-                throw new Fault(new Message("MARSHAL_ERROR", BUNDLE, ex.getMessage()), ex);
+                throw new Fault(new Message("MARSHAL_ERROR", LOG, ex.getMessage()), ex);
             }
         }
 
@@ -277,16 +242,16 @@
             } else if (source instanceof Node) {
                 return bridge.unmarshal((Node)source, am);
             } else {
-                throw new Fault(new Message("UNKNOWN_SOURCE", BUNDLE, source.getClass().getName()));
+                throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
             }
         } catch (Exception ex) {
             if (ex instanceof javax.xml.bind.MarshalException) {
                 javax.xml.bind.MarshalException marshalEx = (javax.xml.bind.MarshalException)ex;
-                Message faultMessage = new Message("MARSHAL_ERROR", BUNDLE, marshalEx.getLinkedException()
+                Message faultMessage = new Message("MARSHAL_ERROR", LOG, marshalEx.getLinkedException()
                     .getMessage());
                 throw new Fault(faultMessage, ex);
             } else {
-                throw new Fault(new Message("MARSHAL_ERROR", BUNDLE, ex.getMessage()), ex);
+                throw new Fault(new Message("MARSHAL_ERROR", LOG, ex.getMessage()), ex);
             }
         }
 
@@ -294,9 +259,8 @@
     
 
     @SuppressWarnings("unchecked")
-    public static void marshallException(JAXBContext context, Schema schema, Exception elValue,
-                                         MessagePartInfo part, Object source, AttachmentMarshaller am,
-                                         Map<String, Object> marshallerProperties) {
+    public static void marshallException(Marshaller marshaller, Exception elValue,
+                                         MessagePartInfo part, Object source) {
         XMLStreamWriter writer = getStreamWriter(source);
         QName qn = part.getElementQName();
         try {
@@ -316,23 +280,11 @@
                 namespace = null;
             }
             
-            
-            Marshaller u = createMarshaller(context, cls, marshallerProperties);
-            try {
-                // override anything the user asked us to set.
-                // The Marshaller.JAXB_FRAGMENT will tell the Marshaller not to
-                // generate the xml declaration.
-                u.setProperty(Marshaller.JAXB_FRAGMENT, true);
-                u.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
-            } catch (javax.xml.bind.PropertyException e) {
-                // intentionally empty.
-            }
-
             for (Field f : cls.getDeclaredFields()) {
                 if (JAXBContextInitializer.isFieldAccepted(f, accessType)) {
                     QName fname = new QName(namespace, f.getName());
                     f.setAccessible(true);
-                    writeObject(u, writer, new JAXBElement(fname, String.class, f.get(elValue)));
+                    writeObject(marshaller, writer, new JAXBElement(fname, String.class, f.get(elValue)));
                 }
             }
             for (Method m : cls.getMethods()) {
@@ -341,20 +293,21 @@
                     String name = m.getName().substring(idx);
                     name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
                     QName mname = new QName(namespace, name);
-                    writeObject(u, writer, new JAXBElement(mname, String.class, m.invoke(elValue)));
+                    writeObject(marshaller, writer, new JAXBElement(mname, String.class, m.invoke(elValue)));
                 }
             }
 
             writer.writeEndElement();
             writer.flush();
         } catch (Exception e) {
-            throw new Fault(new Message("MARSHAL_ERROR", BUNDLE, e.getMessage()), e);
+            throw new Fault(new Message("MARSHAL_ERROR", LOG, e.getMessage()), e);
         }
     }
 
     @SuppressWarnings("unchecked")
-    public static Exception unmarshallException(JAXBContext context, Schema schema, Object source,
-                                                MessagePartInfo part, AttachmentUnmarshaller au) {
+    public static Exception unmarshallException(Unmarshaller u, 
+                                                Object source,
+                                                MessagePartInfo part) {
         XMLStreamReader reader;
         if (source instanceof XMLStreamReader) {
             reader = (XMLStreamReader)source;
@@ -367,12 +320,12 @@
                 // ignore
             }
         } else {
-            throw new Fault(new Message("UNKNOWN_SOURCE", BUNDLE, source.getClass().getName()));
+            throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
         }
         try {
             QName qn = part.getElementQName();
             if (!qn.equals(reader.getName())) {
-                throw new Fault(new Message("ELEMENT_NAME_MISMATCH", BUNDLE, qn, reader.getName()));
+                throw new Fault(new Message("ELEMENT_NAME_MISMATCH", LOG, qn, reader.getName()));
             }
 
             Class<?> cls = part.getTypeClass();
@@ -391,15 +344,6 @@
             }
             XmlAccessType accessType = accessorType != null
                 ? accessorType.value() : XmlAccessType.PUBLIC_MEMBER;
-            Unmarshaller u = createUnmarshaller(context, cls);
-            try {
-                // The Marshaller.JAXB_FRAGMENT will tell the Marshaller not to
-                // generate the xml declaration.
-                u.setProperty(Marshaller.JAXB_FRAGMENT, true);
-                u.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
-            } catch (javax.xml.bind.PropertyException e) {
-                // intentionally empty.
-            }
             reader.nextTag();
             while (reader.getEventType() == XMLStreamReader.START_ELEMENT) {
                 QName q = reader.getName();
@@ -425,7 +369,7 @@
             }
             return (Exception)obj;
         } catch (Exception e) {
-            throw new Fault(new Message("MARSHAL_ERROR", BUNDLE, e.getMessage()), e);
+            throw new Fault(new Message("MARSHAL_ERROR", LOG, e.getMessage()), e);
         }
     }
 
@@ -439,7 +383,7 @@
         } else if (source instanceof XMLEventWriter) {
             u.marshal(mObj, (XMLEventWriter)source);
         } else {
-            throw new Fault(new Message("UNKNOWN_SOURCE", BUNDLE, source.getClass().getName()));
+            throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
         }
     }
 
@@ -451,65 +395,32 @@
         } else if (source instanceof Node) {
             return new W3CDOMStreamWriter((Element)source);
         }
-        throw new Fault(new Message("UNKNOWN_SOURCE", BUNDLE, source.getClass().getName()));
+        throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
     }
 
-    public static void marshall(JAXBContext context, Schema schema, Object elValue, Object source,
-                                Map<String, Object> marshallerProperties) {
-        marshall(context, schema, elValue, null, source, null, marshallerProperties);
-    }
 
     @SuppressWarnings("unchecked")
-    public static void marshallNullElement(JAXBContext context, Schema schema, Object source,
-                                           MessagePartInfo part, Map<String, Object> marshallerProperties) {
+    public static void marshallNullElement(Marshaller marshaller,
+                                           Object source,
+                                           MessagePartInfo part) {
         Class<?> clazz = part != null ? (Class)part.getTypeClass() : null;
         try {
-            Marshaller u = createMarshaller(context, clazz, marshallerProperties);
-            u.setSchema(schema);
-            try {
-                // The Marshaller.JAXB_FRAGMENT will tell the Marshaller not to
-                // generate the xml declaration.
-                u.setProperty(Marshaller.JAXB_FRAGMENT, true);
-                u.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
-            } catch (javax.xml.bind.PropertyException e) {
-                // intentionally empty.
-            }
-            writeObject(u, source, new JAXBElement(part.getElementQName(), clazz, null));
+            writeObject(marshaller, source, new JAXBElement(part.getElementQName(), clazz, null));
         } catch (JAXBException e) {
-            throw new Fault(new Message("MARSHAL_ERROR", BUNDLE, e.getMessage()), e);
+            throw new Fault(new Message("MARSHAL_ERROR", LOG, e.getMessage()), e);
         }
     }
 
-    public static void marshall(JAXBContext context, Schema schema, Object elValue, MessagePartInfo part,
-                                Object source, Map<String, Object> marshallerProperties) {
-        marshall(context, schema, elValue, part, source, null, marshallerProperties);
-    }
-
-    private static Unmarshaller createUnmarshaller(JAXBContext context, Class<?> cls) throws JAXBException {
-        Unmarshaller um = null;
-        if (context == null) {
-            if (cls == null) {
-                throw new IllegalStateException("A JAXBContext or Class to unmarshal must be provided!");
-            }
-            context = JAXBContext.newInstance(cls);
-        }
-
-        um = context.createUnmarshaller();
-
-        return um;
-    }
-
-    public static Object unmarshall(JAXBContext context, Schema schema, Object source) {
-        return unmarshall(context, schema, source, null, null, true);
-    }
 
     @SuppressWarnings("unchecked")
-    public static Object unmarshall(JAXBContext context, Schema schema, Object source, MessagePartInfo part,
-                                    AttachmentUnmarshaller au, boolean unwrap) {
+    public static Object unmarshall(Unmarshaller u, 
+                                    Object source, 
+                                    MessagePartInfo part,
+                                    boolean unwrap) {
         Class<?> clazz = part != null ? (Class)part.getTypeClass() : null;
         if (clazz != null && Exception.class.isAssignableFrom(clazz) && part != null
             && Boolean.TRUE.equals(part.getProperty(JAXBDataBinding.class.getName() + ".CUSTOM_EXCEPTION"))) {
-            return unmarshallException(context, schema, source, part, au);
+            return unmarshallException(u, source, part);
         }
 
         QName elName = part != null ? part.getConcreteName() : null;
@@ -521,7 +432,7 @@
                 && ((XmlSchemaSimpleType)el.getSchemaType()).getContent() 
                 instanceof XmlSchemaSimpleTypeList) {
 
-                Object obj = unmarshall(context, schema, source, elName, null, au, unwrap);
+                Object obj = unmarshall(u, source, elName, null, unwrap);
                 if (clazz.isArray() && obj instanceof List) {
                     return ((List)obj).toArray((Object[])Array.newInstance(clazz.getComponentType(),
                                                                            ((List)obj).size()));
@@ -530,8 +441,8 @@
                 return obj;
             } else if (part.getMessageInfo().getOperation().isUnwrapped() && el.getMaxOccurs() != 1) {
                 // must read ourselves....
-                List<Object> ret = unmarshallArray(context, schema, source, elName, clazz.getComponentType(),
-                                                   au, createList(part));
+                List<Object> ret = unmarshallArray(u, source, elName, clazz.getComponentType(),
+                                                   createList(part));
                 Object o = ret;
                 if (!isList(part)) {
                     if (clazz.getComponentType().isPrimitive()) {
@@ -548,11 +459,11 @@
         } else if (byte[].class == clazz && part != null && part.getTypeQName() != null
                    && part.getTypeQName().getLocalPart().equals("hexBinary")) {
 
-            String obj = (String)unmarshall(context, schema, source, elName, String.class, au, unwrap);
+            String obj = (String)unmarshall(u, source, elName, String.class, unwrap);
             return new HexBinaryAdapter().unmarshal(obj);
         }
 
-        Object o = unmarshall(context, schema, source, elName, clazz, au, unwrap);
+        Object o = unmarshall(u, source, elName, clazz, unwrap);
         if (o != null && o.getClass().isArray() && isList(part)) {
             List<Object> ret = createList(part);
             ret.addAll(Arrays.asList((Object[])o));
@@ -597,16 +508,11 @@
         return false;
     }
 
-    public static Object unmarshall(JAXBContext context, Schema schema, Object source, QName elName,
-                                    Class<?> clazz, AttachmentUnmarshaller au, boolean unwrap) {
+    public static Object unmarshall(Unmarshaller u, Object source, QName elName,
+                                    Class<?> clazz, boolean unwrap) {
         Object obj = null;
 
         try {
-            Unmarshaller u = createUnmarshaller(context, clazz);
-            u.setSchema(schema);
-            if (au != null) {
-                u.setAttachmentUnmarshaller(au);
-            }
             boolean unmarshalWithClass = true;
 
             if (clazz == null
@@ -631,7 +537,7 @@
                 obj = unmarshalWithClass ? u.unmarshal((XMLEventReader)source, clazz) : u
                     .unmarshal((XMLEventReader)source);
             } else {
-                throw new Fault(new Message("UNKNOWN_SOURCE", BUNDLE, source.getClass().getName()));
+                throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
             }
         } catch (Fault ex) {
             ex.fillInStackTrace();
@@ -640,14 +546,14 @@
             if (ex instanceof javax.xml.bind.UnmarshalException) {
                 javax.xml.bind.UnmarshalException unmarshalEx = (javax.xml.bind.UnmarshalException)ex;
                 if (unmarshalEx.getLinkedException() != null) {
-                    throw new Fault(new Message("UNMARSHAL_ERROR", BUNDLE, 
+                    throw new Fault(new Message("UNMARSHAL_ERROR", LOG, 
                                             unmarshalEx.getLinkedException().getMessage()), ex);
                 } else {
-                    throw new Fault(new Message("UNMARSHAL_ERROR", BUNDLE, 
+                    throw new Fault(new Message("UNMARSHAL_ERROR", LOG, 
                                                 unmarshalEx.getMessage()), ex);                    
                 }
             } else {
-                throw new Fault(new Message("UNMARSHAL_ERROR", BUNDLE, ex.getMessage()), ex);
+                throw new Fault(new Message("UNMARSHAL_ERROR", LOG, ex.getMessage()), ex);
             }
         }
         return unwrap ? getElementValue(obj) : obj;
@@ -681,22 +587,17 @@
         throw new IllegalArgumentException("Cannot get Class object from unknown Type");
     }
 
-    public static List<Object> unmarshallArray(JAXBContext context, Schema schema, Object source,
-                                               QName elName, Class<?> clazz, AttachmentUnmarshaller au,
+    public static List<Object> unmarshallArray(Unmarshaller u, Object source,
+                                               QName elName, Class<?> clazz,
                                                List<Object> ret) {
         try {
-            Unmarshaller u = createUnmarshaller(context, clazz);
-            u.setSchema(schema);
-            if (au != null) {
-                u.setAttachmentUnmarshaller(au);
-            }
             XMLStreamReader reader;
             if (source instanceof XMLStreamReader) {
                 reader = (XMLStreamReader)source;
             } else if (source instanceof Element) {
                 reader = StaxUtils.createXMLStreamReader((Element)source);
             } else {
-                throw new Fault(new Message("UNKNOWN_SOURCE", BUNDLE, source.getClass().getName()));
+                throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
             }
             while (reader.getName().equals(elName)) {
                 Object obj = u.unmarshal(reader, clazz);
@@ -716,10 +617,10 @@
         } catch (Exception ex) {
             if (ex instanceof javax.xml.bind.UnmarshalException) {
                 javax.xml.bind.UnmarshalException unmarshalEx = (javax.xml.bind.UnmarshalException)ex;
-                throw new Fault(new Message("UNMARSHAL_ERROR", BUNDLE, unmarshalEx.getLinkedException()
+                throw new Fault(new Message("UNMARSHAL_ERROR", LOG, unmarshalEx.getLinkedException()
                     .getMessage()), ex);
             } else {
-                throw new Fault(new Message("UNMARSHAL_ERROR", BUNDLE, ex.getMessage()), ex);
+                throw new Fault(new Message("UNMARSHAL_ERROR", LOG, ex.getMessage()), ex);
             }
         }
     }

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java?rev=673189&r1=673188&r2=673189&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java Tue Jul  1 12:44:47 2008
@@ -20,28 +20,69 @@
 package org.apache.cxf.jaxb.io;
 
 import java.lang.annotation.Annotation;
-import java.util.Set;
-
-import javax.xml.bind.JAXBContext;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.PropertyException;
+import javax.xml.bind.Unmarshaller;
 import javax.xml.namespace.QName;
 
 import com.sun.xml.bind.api.TypeReference;
 
+import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.databinding.DataReader;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxb.JAXBDataBase;
+import org.apache.cxf.jaxb.JAXBDataBinding;
 import org.apache.cxf.jaxb.JAXBEncoderDecoder;
 import org.apache.cxf.service.model.MessagePartInfo;
 
 public class DataReaderImpl<T> extends JAXBDataBase implements DataReader<T> {
-    Set<Class<?>> contextClasses;
-    public DataReaderImpl(JAXBContext ctx, Set<Class<?>> contextClasses) {
-        super(ctx);
-        this.contextClasses = contextClasses;
+    private static final Logger LOG = LogUtils.getLogger(JAXBDataBinding.class);
+    JAXBDataBinding databinding;
+    
+    public DataReaderImpl(JAXBDataBinding binding) {
+        super(binding.getContext());
+        databinding = binding;
     }
 
     public Object read(T input) {
         return read(null, input);
     }
+    
+    private Unmarshaller createUnmarshaller() {
+        try {
+            Unmarshaller um = null;
+            um = context.createUnmarshaller();
+            if (databinding.getUnmarshallerListener() != null) {
+                um.setListener(databinding.getUnmarshallerListener());
+            }
+            if (databinding.getUnmarshallerProperties() != null) {
+                for (Map.Entry<String, Object> propEntry 
+                    : databinding.getUnmarshallerProperties().entrySet()) {
+                    try {
+                        um.setProperty(propEntry.getKey(), propEntry.getValue());
+                    } catch (PropertyException pe) {
+                        LOG.log(Level.INFO, "PropertyException setting Marshaller properties", pe);
+                    }
+                }
+            }
+            um.setSchema(schema);
+            um.setAttachmentUnmarshaller(getAttachmentUnmarshaller());
+            return um;
+        } catch (JAXBException ex) {
+            if (ex instanceof javax.xml.bind.UnmarshalException) {
+                javax.xml.bind.UnmarshalException unmarshalEx = (javax.xml.bind.UnmarshalException)ex;
+                throw new Fault(new Message("UNMARSHAL_ERROR", LOG, unmarshalEx.getLinkedException()
+                    .getMessage()), ex);
+            } else {
+                throw new Fault(new Message("UNMARSHAL_ERROR", LOG, ex.getMessage()), ex);
+            }
+        }
+    }
 
     public Object read(MessagePartInfo part, T reader) {
         boolean honorJaxbAnnotation = false;
@@ -56,18 +97,19 @@
             QName qname = new QName(null, part.getConcreteName().getLocalPart());
             TypeReference typeReference = new TypeReference(qname, part.getTypeClass(), anns);
             return JAXBEncoderDecoder.unmarshalWithBridge(typeReference, 
-                                                          contextClasses,
+                                                          databinding.getContextClasses(),
                                                           reader,
                                                           getAttachmentUnmarshaller());
         }
         
-        return JAXBEncoderDecoder.unmarshall(getJAXBContext(), getSchema(), reader, part, 
-                                             getAttachmentUnmarshaller(), unwrapJAXBElement);
+        return JAXBEncoderDecoder.unmarshall(createUnmarshaller(), reader, part, 
+                                             unwrapJAXBElement);
     }
 
     public Object read(QName name, T input, Class type) {
-        return JAXBEncoderDecoder.unmarshall(getJAXBContext(), getSchema(), input, name, type, 
-                                             getAttachmentUnmarshaller(), unwrapJAXBElement);
+        return JAXBEncoderDecoder.unmarshall(createUnmarshaller(), input,
+                                             name, type, 
+                                             unwrapJAXBElement);
     }
 
 }

Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java?rev=673189&r1=673188&r2=673189&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java Tue Jul  1 12:44:47 2008
@@ -20,16 +20,23 @@
 package org.apache.cxf.jaxb.io;
 
 import java.lang.annotation.Annotation;
-import java.util.Collections;
+import java.lang.reflect.Array;
+import java.util.Collection;
 import java.util.Map;
-import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
-import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.PropertyException;
 import javax.xml.namespace.QName;
 
 import com.sun.xml.bind.api.TypeReference;
 
+import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.databinding.DataWriter;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxb.JAXBDataBase;
 import org.apache.cxf.jaxb.JAXBDataBinding;
 import org.apache.cxf.jaxb.JAXBEncoderDecoder;
@@ -37,26 +44,70 @@
 import org.apache.ws.commons.schema.XmlSchemaElement;
 
 public class DataWriterImpl<T> extends JAXBDataBase implements DataWriter<T> {
-    private Set<Class<?>> contextClasses;
-    private Map<String, Object> marshallerProperties = Collections.emptyMap();
-    
-    public DataWriterImpl(JAXBContext ctx, Set<Class<?>> contextClasses) {
-        super(ctx);
-        this.contextClasses = contextClasses;
-    }
+    private static final Logger LOG = LogUtils.getLogger(JAXBDataBinding.class);
+
+    private JAXBDataBinding databinding;
     
-    public DataWriterImpl(JAXBContext ctx, 
-                          Map<String, Object> marshallerProperties,
-                          Set<Class<?>> contextClasses) {
-        super(ctx);
-        this.marshallerProperties = marshallerProperties;
-        this.contextClasses = contextClasses;
+    public DataWriterImpl(JAXBDataBinding binding) {
+        super(binding.getContext());
+        databinding = binding;
     }
     
     public void write(Object obj, T output) {
         write(obj, null, output);
     }
     
+    public Marshaller createMarshaller(Object elValue, MessagePartInfo part) {
+        Class<?> cls = null;
+        if (part != null) {
+            cls = part.getTypeClass();
+        }
+
+        if (cls == null) {
+            cls = null != elValue ? elValue.getClass() : null;
+        }
+
+        if (cls != null && cls.isArray() && elValue instanceof Collection) {
+            Collection<?> col = (Collection<?>)elValue;
+            elValue = col.toArray((Object[])Array.newInstance(cls.getComponentType(), col.size()));
+        }
+        Marshaller marshaller;
+        try {
+            
+            marshaller = context.createMarshaller();
+            marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
+            marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
+            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
+            marshaller.setListener(databinding.getMarshallerListener());
+            
+            marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper",
+                                   databinding.getNamespacePrefixMapper());
+            if (databinding.getMarshallerProperties() != null) {
+                for (Map.Entry<String, Object> propEntry 
+                    : databinding.getMarshallerProperties().entrySet()) {
+                    try {
+                        marshaller.setProperty(propEntry.getKey(), propEntry.getValue());
+                    } catch (PropertyException pe) {
+                        LOG.log(Level.INFO, "PropertyException setting Marshaller properties", pe);
+                    }
+                }
+            }
+            
+            marshaller.setSchema(schema);
+            marshaller.setAttachmentMarshaller(getAttachmentMarshaller());
+        } catch (JAXBException ex) {
+            if (ex instanceof javax.xml.bind.MarshalException) {
+                javax.xml.bind.MarshalException marshalEx = (javax.xml.bind.MarshalException)ex;
+                Message faultMessage = new Message("MARSHAL_ERROR", LOG, marshalEx.getLinkedException()
+                    .getMessage());
+                throw new Fault(faultMessage, ex);
+            } else {
+                throw new Fault(new Message("MARSHAL_ERROR", LOG, ex.getMessage()), ex);
+            }
+        }
+        return marshaller;
+    }
+    
     public void write(Object obj, MessagePartInfo part, T output) {
         boolean honorJaxbAnnotation = false;
         if (part != null && part.getProperty("honor.jaxb.annotations") != null) {
@@ -70,27 +121,31 @@
                 && part != null
                 && Boolean.TRUE.equals(part.getProperty(JAXBDataBinding.class.getName() 
                                                         + ".CUSTOM_EXCEPTION"))) {
-                JAXBEncoderDecoder.marshallException(getJAXBContext(), getSchema(), (Exception)obj,
-                                                     part, output, getAttachmentMarshaller(),
-                                                     marshallerProperties);                
+                JAXBEncoderDecoder.marshallException(createMarshaller(obj, part),
+                                                     (Exception)obj,
+                                                     part, 
+                                                     output);                
             } else {
                 Annotation[] anns = getJAXBAnnotation(part);
                 if (!honorJaxbAnnotation || anns.length == 0) {
-                    JAXBEncoderDecoder.marshall(getJAXBContext(), getSchema(), obj, part, output,
-                                                getAttachmentMarshaller(), marshallerProperties);
+                    JAXBEncoderDecoder.marshall(createMarshaller(obj, part), obj, part, output);
                 } else if (honorJaxbAnnotation && anns.length > 0) {
                     //RpcLit will use the JAXB Bridge to marshall part message when it is 
                     //annotated with @XmlList,@XmlAttachmentRef,@XmlJavaTypeAdapter
                     //TODO:Cache the JAXBRIContext
                     QName qname = new QName(null, part.getConcreteName().getLocalPart());
                     TypeReference typeReference = new TypeReference(qname, part.getTypeClass(), anns);
-                    JAXBEncoderDecoder.marshalWithBridge(typeReference, contextClasses, obj, 
-                                                         output, getAttachmentMarshaller());
+                    
+                    JAXBEncoderDecoder.marshalWithBridge(typeReference, 
+                                                         databinding.getContextClasses(), 
+                                                         obj, 
+                                                         output, 
+                                                         getAttachmentMarshaller());
                 }
             }
         } else if (obj == null && needToRender(obj, part)) {
-            JAXBEncoderDecoder.marshallNullElement(getJAXBContext(), getSchema(), output, part,
-                                                   marshallerProperties);
+            JAXBEncoderDecoder.marshallNullElement(createMarshaller(obj, part),
+                                                   output, part);
         }
     }
 
@@ -101,15 +156,5 @@
         }
         return false;
     }
-
-    public Map<String, Object> getMarshallerProperties() {
-        return marshallerProperties;
-    }
-
-    public void setMarshallerProperties(Map<String, Object> marshallerProperties) {
-        this.marshallerProperties = marshallerProperties;
-    }
-    
-
     
 }

Modified: cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java?rev=673189&r1=673188&r2=673189&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java Tue Jul  1 12:44:47 2008
@@ -242,6 +242,6 @@
         writer.write(bean, xmlWriter);
         xmlWriter.flush();
         String xml = stringWriter.toString();
-        assertTrue(xml.contains("greenland=\"uri:ultima:thule"));
+        assertTrue(xml, xml.contains("greenland=\"uri:ultima:thule"));
     }
 }

Modified: cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java?rev=673189&r1=673188&r2=673189&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java Tue Jul  1 12:44:47 2008
@@ -25,13 +25,11 @@
 import java.io.StringWriter;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
 
 import javax.xml.XMLConstants;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
+import javax.xml.bind.Marshaller;
 import javax.xml.bind.Unmarshaller;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLEventReader;
@@ -82,8 +80,6 @@
     JAXBContext context;
     Schema schema;
     
-    private Map<String, Object> emptyMarshallerProperties = Collections.emptyMap();
-    
     @Before
     public void setUp() throws Exception {
         
@@ -119,7 +115,7 @@
 
         Node node;
         try {
-            JAXBEncoderDecoder.marshall(context, null, null, part, elNode, emptyMarshallerProperties);
+            JAXBEncoderDecoder.marshall(context.createMarshaller(), null, part, elNode);
             fail("Should have thrown a Fault");
         } catch (Fault ex) {
             //expected - not a valid object
@@ -130,7 +126,7 @@
         QName elName = new QName(wrapperAnnotation.targetNamespace(),
                                  wrapperAnnotation.localName());
         part.setElementQName(elName);
-        JAXBEncoderDecoder.marshall(context, null, obj, part, elNode, emptyMarshallerProperties);
+        JAXBEncoderDecoder.marshall(context.createMarshaller(), obj, part, elNode);
         node = elNode.getLastChild();
         //The XML Tree Looks like
         //<GreetMe><requestType>Hello</requestType></GreetMe>
@@ -147,11 +143,12 @@
         //stringStruct.setArg0("hello");
         stringStruct.setArg1("world");
         // Marshal without the schema should work.
-        JAXBEncoderDecoder.marshall(context, null, stringStruct, part,  elNode, emptyMarshallerProperties);
+        JAXBEncoderDecoder.marshall(context.createMarshaller(), stringStruct, part,  elNode);
         try {
+            Marshaller m = context.createMarshaller();
+            m.setSchema(schema);
             // Marshal with the schema should get an exception.
-            JAXBEncoderDecoder.marshall(context, schema, stringStruct, part,  elNode, 
-                                        emptyMarshallerProperties);
+            JAXBEncoderDecoder.marshall(m, stringStruct, part,  elNode);
             fail("Marshal with schema should have thrown a Fault");
         } catch (Fault ex) {
             //expected - not a valid object
@@ -174,7 +171,7 @@
         XMLOutputFactory opFactory = XMLOutputFactory.newInstance();
         opFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
         XMLEventWriter writer = opFactory.createXMLEventWriter(stringWriter);
-        JAXBEncoderDecoder.marshall(context, null, testObject, part, writer, emptyMarshallerProperties);
+        JAXBEncoderDecoder.marshall(context.createMarshaller(), testObject, part, writer);
         writer.flush();
         writer.close();
         String xmlResult = stringWriter.toString();
@@ -185,7 +182,6 @@
     
     @Test
     public void testCustomNamespaces() throws Exception {
-        Map<String, Object> marshallProps = new HashMap<String, Object>();
         NamespacePrefixMapper mapper = new NamespacePrefixMapper() {
 
             @Override
@@ -198,7 +194,6 @@
                 return suggestion;
             } 
         };
-        marshallProps.put("com.sun.xml.bind.namespacePrefixMapper", mapper);
         ObjectWithQualifiedElementElement testObject = new ObjectWithQualifiedElementElement();
         testObject.setString1("twine");
         testObject.setString2("cord");
@@ -213,7 +208,10 @@
         XMLOutputFactory opFactory = XMLOutputFactory.newInstance();
         opFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
         XMLEventWriter writer = opFactory.createXMLEventWriter(stringWriter);
-        JAXBEncoderDecoder.marshall(context, null, testObject, part, writer, marshallProps);
+        Marshaller m = context.createMarshaller();
+        m.setProperty("com.sun.xml.bind.namespacePrefixMapper", mapper);
+        
+        JAXBEncoderDecoder.marshall(m, testObject, part, writer);
         writer.flush();
         writer.close();
         String xmlResult = stringWriter.toString();
@@ -239,7 +237,7 @@
 
         //STARTDOCUMENT/ENDDOCUMENT is not required
         //writer.add(eFactory.createStartDocument("utf-8", "1.0"));        
-        JAXBEncoderDecoder.marshall(context, null, obj, part, writer, emptyMarshallerProperties);
+        JAXBEncoderDecoder.marshall(context.createMarshaller(), obj, part, writer);
         //writer.add(eFactory.createEndDocument());
         writer.flush();
         writer.close();
@@ -277,7 +275,7 @@
         //Remove START_DOCUMENT & START_ELEMENT pertaining to Envelope and Body Tags.
 
         part.setTypeClass(GreetMe.class);
-        Object val = JAXBEncoderDecoder.unmarshall(context, null, reader, part, null, true);
+        Object val = JAXBEncoderDecoder.unmarshall(context.createUnmarshaller(), reader, part, true);
         assertNotNull(val);
         assertTrue(val instanceof GreetMe);
         assertEquals("TestSOAPInputPMessage", 
@@ -297,8 +295,8 @@
         Document doc = DOMUtils.createDocument();
         Element elNode = doc.createElementNS(elName.getNamespaceURI(), 
                                              elName.getLocalPart());
-        JAXBEncoderDecoder.marshall(context, null, 
-                                    new String("TestSOAPMessage"), part,  elNode, emptyMarshallerProperties);
+        JAXBEncoderDecoder.marshall(context.createMarshaller(), 
+                                    new String("TestSOAPMessage"), part,  elNode);
         
         assertNotNull(elNode.getChildNodes());
         assertEquals("TestSOAPMessage", elNode.getFirstChild().getFirstChild().getNodeValue());
@@ -324,8 +322,8 @@
         elNode.appendChild(rtEl);
         rtEl.appendChild(doc.createTextNode("Hello Test"));
 
-        Object obj = JAXBEncoderDecoder.unmarshall(context, null,
-                         elNode, part, null, true);
+        Object obj = JAXBEncoderDecoder.unmarshall(context.createUnmarshaller(),
+                         elNode, part, true);
         assertNotNull(obj);
 
         //Add a Node and then test
@@ -335,7 +333,7 @@
         part.setTypeClass(String.class);
         Node n = null;
         try {
-            JAXBEncoderDecoder.unmarshall(context, null, n, part, null, true);
+            JAXBEncoderDecoder.unmarshall(context.createUnmarshaller(), n, part, true);
             fail("Should have received a Fault");
         } catch (Fault pe) {
             //Expected Exception
@@ -364,14 +362,16 @@
         rtEl.appendChild(doc.createTextNode("World"));
         
         // Should unmarshal without problems when no schema used.
-        obj = JAXBEncoderDecoder.unmarshall(context, null, elNode, part, null, true);
+        obj = JAXBEncoderDecoder.unmarshall(context.createUnmarshaller(), elNode, part, true);
         assertNotNull(obj);
         assertEquals(StringStruct.class,  obj.getClass());
         assertEquals("World", ((StringStruct)obj).getArg1());
         
         try {
             // unmarshal with schema should raise exception.
-            obj = JAXBEncoderDecoder.unmarshall(context, schema, elNode, part, null, true);
+            Unmarshaller m = context.createUnmarshaller();
+            m.setSchema(schema);
+            obj = JAXBEncoderDecoder.unmarshall(m, elNode, part, true);
             fail("Should have thrown a Fault");
         } catch (Fault ex) {
             // expected - schema validation should fail.
@@ -390,7 +390,10 @@
         elNode.appendChild(rtEl);
         rtEl.appendChild(doc.createTextNode("Hello Test"));
        
-        Object obj = JAXBEncoderDecoder.unmarshall(context, null, elNode);
+        Object obj = JAXBEncoderDecoder.unmarshall(context.createUnmarshaller(), 
+                                                   elNode,
+                                                   null,
+                                                   true);
         assertNotNull(obj);
         assertEquals(GreetMe.class,  obj.getClass());
         assertEquals("Hello Test", ((GreetMe)obj).getRequestType());
@@ -408,7 +411,7 @@
 
         //STARTDOCUMENT/ENDDOCUMENT is not required
         //writer.add(eFactory.createStartDocument("utf-8", "1.0"));        
-        JAXBEncoderDecoder.marshall(context, null, obj, writer, emptyMarshallerProperties);
+        JAXBEncoderDecoder.marshall(context.createMarshaller(), obj, null, writer);
         //writer.add(eFactory.createEndDocument());
         writer.flush();
         writer.close();