cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [3/5] cxf git commit: [CXF-5770] If vlidation-event-handler is a string, load it as a class
Date Fri, 24 Mar 2017 14:46:39 GMT
[CXF-5770] If vlidation-event-handler is a string, load it as a class


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/bee6f221
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/bee6f221
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/bee6f221

Branch: refs/heads/master
Commit: bee6f221450179d4e680bc8abc1e7dd39347bea7
Parents: a42362e
Author: Daniel Kulp <dkulp@apache.org>
Authored: Thu Mar 23 13:43:53 2017 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Fri Mar 24 10:03:08 2017 -0400

----------------------------------------------------------------------
 .../java/org/apache/cxf/jaxb/JAXBDataBase.java  | 35 ++++++++++++++++++++
 .../org/apache/cxf/jaxb/io/DataReaderImpl.java  |  7 +---
 .../org/apache/cxf/jaxb/io/DataWriterImpl.java  |  8 +----
 3 files changed, 37 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/bee6f221/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBase.java
----------------------------------------------------------------------
diff --git a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBase.java b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBase.java
index 2501ea4..404fe15 100644
--- a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBase.java
+++ b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBase.java
@@ -23,8 +23,11 @@ import java.lang.annotation.Annotation;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import javax.xml.bind.JAXBContext;
+import javax.xml.bind.ValidationEventHandler;
 import javax.xml.bind.annotation.XmlAttachmentRef;
 import javax.xml.bind.annotation.XmlList;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@@ -32,9 +35,12 @@ import javax.xml.bind.attachment.AttachmentMarshaller;
 import javax.xml.bind.attachment.AttachmentUnmarshaller;
 import javax.xml.validation.Schema;
 
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.jaxb.attachment.JAXBAttachmentMarshaller;
 import org.apache.cxf.jaxb.attachment.JAXBAttachmentUnmarshaller;
 import org.apache.cxf.message.Attachment;
+import org.apache.cxf.message.Message;
 import org.apache.cxf.service.model.AbstractMessageContainer;
 import org.apache.cxf.service.model.MessageInfo;
 import org.apache.cxf.service.model.MessagePartInfo;
@@ -44,6 +50,7 @@ import org.apache.cxf.service.model.OperationInfo;
  *
  */
 public abstract class JAXBDataBase {
+    static final Logger LOG = LogUtils.getL7dLogger(JAXBDataBase.class);
 
     protected JAXBContext context;
     protected Schema schema;
@@ -152,6 +159,34 @@ public abstract class JAXBDataBase {
         Boolean b = (Boolean)part.getProperty("honor.jaxb.annotations");
         return b == null ? false : b;
     }
+    
+    protected ValidationEventHandler getValidationEventHandler(String cn) {
+        try {
+            return (ValidationEventHandler)ClassLoaderUtils.loadClass(cn, getClass()).newInstance();
+        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException
e) {
+            LOG.log(Level.INFO, "Could not create validation event handler", e);
+        }
+        return null;
+    }
+    
+    protected ValidationEventHandler getValidationEventHandler(Message m, String property)
{
+        Object value = m.getContextualProperty(property);
+        ValidationEventHandler veventHandler = null;
+        if (value instanceof String) {
+            veventHandler = getValidationEventHandler((String)value);
+        } else {
+            veventHandler = (ValidationEventHandler)value;
+        }
+        if (veventHandler == null) {
+            value = m.getContextualProperty(JAXBDataBinding.VALIDATION_EVENT_HANDLER);
+            if (value instanceof String) {
+                veventHandler = getValidationEventHandler((String)value);
+            } else {
+                veventHandler = (ValidationEventHandler)value;
+            }
+        }
+        return veventHandler;
+    }
 
 
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/bee6f221/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
----------------------------------------------------------------------
diff --git a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
index 10da669..38e9174 100644
--- a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
+++ b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
@@ -91,12 +91,7 @@ public class DataReaderImpl<T> extends JAXBDataBase implements DataReader<T>
{
             unwrapJAXBElement = Boolean.TRUE.equals(value);
         } else 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(
-                    JAXBDataBinding.READER_VALIDATION_EVENT_HANDLER);
-            if (veventHandler == null) {
-                veventHandler = (ValidationEventHandler)m.getContextualProperty(
-                        JAXBDataBinding.VALIDATION_EVENT_HANDLER);
-            }
+            veventHandler = getValidationEventHandler(m, JAXBDataBinding.READER_VALIDATION_EVENT_HANDLER);
             if (veventHandler == null) {
                 veventHandler = databinding.getValidationEventHandler();
             }

http://git-wip-us.apache.org/repos/asf/cxf/blob/bee6f221/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
----------------------------------------------------------------------
diff --git a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
index a2de176..ebc78ec 100644
--- a/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
+++ b/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
@@ -73,13 +73,7 @@ public class DataWriterImpl<T> extends JAXBDataBase implements DataWriter<T>
{
     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(
-                    JAXBDataBinding.WRITER_VALIDATION_EVENT_HANDLER);
-
-            if (veventHandler == null) {
-                veventHandler = (ValidationEventHandler)m.getContextualProperty(
-                    "jaxb-validation-event-handler");
-            }
+            veventHandler = getValidationEventHandler(m, JAXBDataBinding.WRITER_VALIDATION_EVENT_HANDLER);
             if (veventHandler == null) {
                 veventHandler = databinding.getValidationEventHandler();
             }


Mime
View raw message