### Eclipse Workspace Patch 1.0
#P cxf
Index: systests/databinding/src/test/java/org/apache/cxf/systest/jaxb/validators/CustomValidatorJAXBTest.java
===================================================================
--- systests/databinding/src/test/java/org/apache/cxf/systest/jaxb/validators/CustomValidatorJAXBTest.java	(revision 0)
+++ systests/databinding/src/test/java/org/apache/cxf/systest/jaxb/validators/CustomValidatorJAXBTest.java	(revision 0)
@@ -0,0 +1,67 @@
+/**
+ * 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.systest.jaxb.validators;
+
+import org.apache.cxf.testutil.common.TestUtil;
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+/**
+ * 
+ */
+@ContextConfiguration(locations = { "classpath:jaxbCustomValidators.xml" })
+public class CustomValidatorJAXBTest extends AbstractJUnit4SpringContextTests {
+    static final String PORT = TestUtil.getPortNumber(CustomValidatorJAXBTest.class);
+   
+    @Test
+    public void cleanTest() {
+        HelloWorld client = (HelloWorld)applicationContext
+                .getBean("testClient", HelloWorld.class);
+        
+        PassedObject hi = client.sayHi(new PassedObject("John", "Doe"));
+        Assert.assertTrue("Expected: 'Hello John Doe' Actual: " + hi.getName(),
+                "Hello John Doe".equals(hi.getName()));
+        
+    }
+    
+    @Test
+    public void sendNullTest() {
+        HelloWorld client = (HelloWorld)applicationContext
+                .getBean("testClient", HelloWorld.class);
+        
+        PassedObject hi = client.sayHi(new PassedObject());
+        Assert.assertTrue("Expected: 'Hello null null' Actual: '" + hi.getName() + "'",
+                "Hello null null".equals(hi.getName()));
+        
+    }
+    
+    @Test
+    public void returnNullTest() {
+        HelloWorld client = (HelloWorld)applicationContext
+                .getBean("testClient", HelloWorld.class);
+        
+        PassedObject hi = client.returnNull(new PassedObject("John", "Doe"));
+        Assert.assertTrue("Expected: 'Hello null' Actual: '" + hi.getName() + "'",
+                "Hello null".equals(hi.getName()));
+        
+    }
+}
Index: systests/databinding/src/test/java/org/apache/cxf/systest/jaxb/validators/HelloWorld.java
===================================================================
--- systests/databinding/src/test/java/org/apache/cxf/systest/jaxb/validators/HelloWorld.java	(revision 0)
+++ systests/databinding/src/test/java/org/apache/cxf/systest/jaxb/validators/HelloWorld.java	(revision 0)
@@ -0,0 +1,33 @@
+/**
+ * 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.systest.jaxb.validators;
+
+import javax.jws.WebMethod;
+import javax.jws.WebParam;
+
+@javax.jws.WebService(targetNamespace = "aNamespace")
+public interface HelloWorld {
+    
+    @WebMethod(operationName = "sayHi")
+    PassedObject sayHi(@WebParam(name = "text") PassedObject name);
+
+    @WebMethod(operationName = "returnNull")
+    PassedObject returnNull(@WebParam(name = "text") PassedObject name);
+}
+
Index: systests/databinding/src/test/java/org/apache/cxf/systest/jaxb/validators/HelloWorldImpl.java
===================================================================
--- systests/databinding/src/test/java/org/apache/cxf/systest/jaxb/validators/HelloWorldImpl.java	(revision 0)
+++ systests/databinding/src/test/java/org/apache/cxf/systest/jaxb/validators/HelloWorldImpl.java	(revision 0)
@@ -0,0 +1,33 @@
+/**
+ * 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.systest.jaxb.validators;
+
+@javax.jws.WebService(endpointInterface = "org.apache.cxf.systest.jaxb.validators.HelloWorld")
+public class HelloWorldImpl implements HelloWorld {
+
+    public PassedObject sayHi(PassedObject name) {
+        return new PassedObject("Hello", name.getName());
+    }
+    
+    public PassedObject returnNull(PassedObject name) {
+        return new PassedObject("Hello", null);
+    }
+    
+}
+
Index: systests/databinding/src/test/java/org/apache/cxf/systest/jaxb/validators/MyCustomHandler.java
===================================================================
--- systests/databinding/src/test/java/org/apache/cxf/systest/jaxb/validators/MyCustomHandler.java	(revision 0)
+++ systests/databinding/src/test/java/org/apache/cxf/systest/jaxb/validators/MyCustomHandler.java	(revision 0)
@@ -0,0 +1,37 @@
+/**
+ * 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.systest.jaxb.validators;
+
+import javax.xml.bind.ValidationEvent;
+import javax.xml.bind.ValidationEventHandler;
+
+public class MyCustomHandler implements ValidationEventHandler {
+
+    private boolean used;
+    public boolean getUsed() {
+        return used;
+    }
+    
+    public boolean handleEvent(ValidationEvent event) {
+        used = true;
+        return true;
+    }
+
+}
\ No newline at end of file
Index: systests/databinding/src/test/java/org/apache/cxf/systest/jaxb/validators/PassedObject.java
===================================================================
--- systests/databinding/src/test/java/org/apache/cxf/systest/jaxb/validators/PassedObject.java	(revision 0)
+++ systests/databinding/src/test/java/org/apache/cxf/systest/jaxb/validators/PassedObject.java	(revision 0)
@@ -0,0 +1,55 @@
+/**
+ * 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.systest.jaxb.validators;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+@XmlType(name = "UserType", propOrder = { "firstName", "lastName" })
+@XmlAccessorType(XmlAccessType.FIELD)
+public class PassedObject {
+
+    @XmlElement(required = true, nillable = false)
+    private String firstName;
+
+    @XmlElement(required = true, nillable = false)
+    private String lastName;
+
+    public PassedObject() { }
+
+    public PassedObject(String firstName, String lastName) {
+        this.firstName = firstName;
+        this.lastName = lastName;
+    }
+
+    public String getFirstName() {
+        return firstName;
+    }
+
+    public String getLastName() {
+        return lastName;
+    }
+
+    public String getName() {
+        return firstName + " " + lastName;
+    }
+
+}
Index: systests/databinding/src/test/resources/jaxbCustomValidators.xml
===================================================================
--- systests/databinding/src/test/resources/jaxbCustomValidators.xml	(revision 0)
+++ systests/databinding/src/test/resources/jaxbCustomValidators.xml	(revision 0)
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xmlns:jaxws="http://cxf.apache.org/jaxws"
+	xmlns:http="http://cxf.apache.org/transports/http/configuration"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+						http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
+						http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd">
+
+	<!-- Services -->
+	<jaxws:server 
+		id="testServer" 
+		serviceClass="org.apache.cxf.systest.jaxb.validators.HelloWorld"
+		address="http://localhost:9000/Hello">
+		<jaxws:serviceBean>
+			<bean class="org.apache.cxf.systest.jaxb.validators.HelloWorldImpl"/>
+		</jaxws:serviceBean>
+		<jaxws:properties>
+            <entry key="schema-validation-enabled" value="true" />
+            <entry key="jaxb-validation-event-handler">
+                <bean class="org.apache.cxf.systest.jaxb.validators.MyCustomHandler"></bean>
+            </entry>
+            <entry key="jaxb-writer-validation-event-handler">
+                <bean class="org.apache.cxf.systest.jaxb.validators.MyCustomHandler"></bean>
+            </entry>
+        </jaxws:properties>
+	</jaxws:server>
+	
+	<!-- Client Proxy -->
+	<jaxws:client 
+		id="testClient" 
+		serviceClass="org.apache.cxf.systest.jaxb.validators.HelloWorld"
+		address="http://localhost:9000/Hello">
+	</jaxws:client>
+	
+				
+</beans>
Index: rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
===================================================================
--- rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java	(revision 18090)
+++ rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java	(working copy)
@@ -50,6 +50,7 @@
 public class DataWriterImpl<T> extends JAXBDataBase implements DataWriter<T> {
     private static final Logger LOG = LogUtils.getLogger(JAXBDataBinding.class);
 
+    ValidationEventHandler veventHandler;
     private JAXBDataBinding databinding;
     
     public DataWriterImpl(JAXBDataBinding binding) {
@@ -60,6 +61,18 @@
     public void write(Object obj, T output) {
         write(obj, null, output);
     }
+    
+    public void setProperty(String prop, Object value) {
+        if (prop.equals(org.apache.cxf.message.Message.class.getName())) {
+            org.apache.cxf.message.Message m = (org.apache.cxf.message.Message)value;
+            veventHandler = (ValidationEventHandler)m.getContextualProperty(
+                    "jaxb-writer-validation-event-handler");
+            if (veventHandler == null) {
+                veventHandler = databinding.getValidationEventHandler();
+            }            
+        }
+    }
+    
     private static class MtomValidationHandler implements ValidationEventHandler {
         ValidationEventHandler origHandler;
         JAXBAttachmentMarshaller marshaller;
@@ -104,7 +117,8 @@
             marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
             marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
             marshaller.setListener(databinding.getMarshallerListener());
-            if (databinding.getValidationEventHandler() != null) {
+            marshaller.setEventHandler(veventHandler);
+            if (veventHandler == null && databinding.getValidationEventHandler() != null) {
                 marshaller.setEventHandler(databinding.getValidationEventHandler());
             }
             
Index: rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/resources/SetPropertyValidationFailureReq.xml
===================================================================
--- rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/resources/SetPropertyValidationFailureReq.xml	(revision 0)
+++ rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/resources/SetPropertyValidationFailureReq.xml	(revision 0)
@@ -0,0 +1,22 @@
+<!--
+  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.
+-->
+<ns4:greetMe xmlns:ns4="http://apache.org/hello_world_soap_http/types">
+    <ns4:requestType>TestSOAPInputPMessage</ns4:requestType>
+    <ns4:somethingElse>bla bla bla</ns4:somethingElse>
+</ns4:greetMe>
Index: rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/MyCustomHandler.java
===================================================================
--- rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/MyCustomHandler.java	(revision 0)
+++ rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/MyCustomHandler.java	(revision 0)
@@ -0,0 +1,37 @@
+/**
+ * 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.jaxb.io;
+
+import javax.xml.bind.ValidationEvent;
+import javax.xml.bind.ValidationEventHandler;
+
+public class MyCustomHandler implements ValidationEventHandler {
+
+    private boolean used;
+    public boolean getUsed() {
+        return used;
+    }
+    
+    public boolean handleEvent(ValidationEvent event) {
+        used = true;
+        return true;
+    }
+
+}
\ No newline at end of file
Index: rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataReaderTest.java
===================================================================
--- rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataReaderTest.java	(revision 18090)
+++ rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataReaderTest.java	(working copy)
@@ -57,6 +57,32 @@
     }
 
     @Test
+    public void testSetProperty() throws Exception {
+        JAXBDataBinding db = getDataBinding(GreetMe.class);
+    
+        reader = getTestReader("../resources/SetPropertyValidationFailureReq.xml");
+        assertNotNull(reader);
+        
+        DataReaderImpl<XMLStreamReader> dr = (DataReaderImpl)db.createReader(XMLStreamReader.class);
+        assertNotNull(dr);
+        
+        // Build message to set custom event handler
+        org.apache.cxf.message.Message message = new org.apache.cxf.message.MessageImpl();
+        message.put("jaxb-validation-event-handler", new MyCustomHandler());
+        message.put("unwrap.jaxb.element", true);
+    
+        dr.setProperty("org.apache.cxf.message.Message", message);        
+        
+        // Should fail if custom handler doesn't skip formatting error
+        Object val = dr.read(reader);
+        assertTrue(val instanceof GreetMe);
+        assertEquals("TestSOAPInputPMessage", ((GreetMe)val).getRequestType());
+        
+        // Check handler used
+        assertTrue(((MyCustomHandler)dr.veventHandler).getUsed());
+    }
+    
+    @Test
     public void testReadWrapper() throws Exception {
         JAXBDataBinding db = getDataBinding(GreetMe.class);
         
Index: rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataWriterTest.java
===================================================================
--- rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataWriterTest.java	(revision 18090)
+++ rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/io/XMLStreamDataWriterTest.java	(working copy)
@@ -62,6 +62,35 @@
     public void tearDown() throws Exception {
         baos.close();
     }
+    
+    @Test
+    public void testSetProperty() throws Exception {
+        JAXBDataBinding db = getTestWriterFactory();
+               
+        DataWriterImpl<XMLStreamWriter> dw = (DataWriterImpl)db.createWriter(XMLStreamWriter.class);
+        assertNotNull(dw);
+        
+        // Build message to set custom event handler
+        org.apache.cxf.message.Message message = new org.apache.cxf.message.MessageImpl();
+        message.put("jaxb-writer-validation-event-handler", new MyCustomHandler());
+    
+        dw.setProperty("org.apache.cxf.message.Message", message);     
+        
+        // Write Stuff
+        TradePriceData val = new TradePriceData();
+        val.setTickerSymbol("This is a symbol");
+        val.setTickerPrice(1.0f);
+        
+        QName elName = new QName("http://apache.org/hello_world_doc_lit_bare/types", "inout");
+        MessagePartInfo part = new MessagePartInfo(elName, null);
+        part.setElement(true);
+        part.setElementQName(elName);
+        dw.write(val, part, streamWriter);
+        streamWriter.flush();
+        
+        // Test MyCustomHandler
+        assertTrue(((MyCustomHandler)dw.veventHandler).getUsed());       
+    }
 
     @Test
     public void testWriteRPCLit1() throws Exception {
