cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r1506442 - in /cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint: AuthorizationPolicyHolder.java HTTPClientPolicyHolder.java HTTPServerPolicyHolder.java HolderUtils.java ProxyAuthorizationPolicyHolder.java
Date Wed, 24 Jul 2013 08:30:05 GMT
Author: ffang
Date: Wed Jul 24 08:30:05 2013
New Revision: 1506442

URL: http://svn.apache.org/r1506442
Log:
[CXF-5148]add a util class to remove duplicated code

Added:
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HolderUtils.java
Modified:
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/AuthorizationPolicyHolder.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HTTPClientPolicyHolder.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HTTPServerPolicyHolder.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/ProxyAuthorizationPolicyHolder.java

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/AuthorizationPolicyHolder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/AuthorizationPolicyHolder.java?rev=1506442&r1=1506441&r2=1506442&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/AuthorizationPolicyHolder.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/AuthorizationPolicyHolder.java
Wed Jul 24 08:30:05 2013
@@ -19,26 +19,17 @@
 package org.apache.cxf.transport.http.blueprint;
 
 import java.io.ByteArrayInputStream;
-import java.util.HashSet;
 import java.util.Set;
-import java.util.logging.Logger;
-
 import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.w3c.dom.Element;
 
-import org.apache.cxf.common.jaxb.JAXBContextCache;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PackageUtils;
+
 import org.apache.cxf.configuration.security.AuthorizationPolicy;
 
 public class AuthorizationPolicyHolder extends AuthorizationPolicy {
-    private static final Logger LOG = LogUtils.getL7dLogger(AuthorizationPolicyHolder.class);
-
+    
     private String parsedElement;
     private AuthorizationPolicy authorizationPolicy;
 
@@ -57,7 +48,9 @@ public class AuthorizationPolicyHolder e
             Element element = docFactory.newDocumentBuilder()
                 .parse(new ByteArrayInputStream(parsedElement.getBytes())).getDocumentElement();
 
-            authorizationPolicy = (AuthorizationPolicy)getJaxbObject(element, AuthorizationPolicy.class);
+            authorizationPolicy = (AuthorizationPolicy)HolderUtils.getJaxbObject(
+                                      element, AuthorizationPolicy.class,
+                                      jaxbContext, jaxbClasses, getClass().getClassLoader());
             this.setAuthorization(authorizationPolicy.getAuthorization());
             this.setAuthorizationType(authorizationPolicy.getAuthorizationType());
             this.setPassword(authorizationPolicy.getPassword());
@@ -80,48 +73,4 @@ public class AuthorizationPolicyHolder e
         this.parsedElement = parsedElement;
     }
 
-    protected Object getJaxbObject(Element parent, Class<?> c) {
-
-        try {
-            Unmarshaller umr = getContext(c).createUnmarshaller();
-            JAXBElement<?> ele = (JAXBElement<?>) umr.unmarshal(parent);
-
-            return ele.getValue();
-        } catch (JAXBException e) {
-            LOG.warning("Unable to parse property due to " + e);
-            return null;
-        }
-    }
-
-    protected synchronized JAXBContext getContext(Class<?> cls) {
-        if (jaxbContext == null || jaxbClasses == null || !jaxbClasses.contains(cls)) {
-            try {
-                Set<Class<?>> tmp = new HashSet<Class<?>>();
-                if (jaxbClasses != null) {
-                    tmp.addAll(jaxbClasses);
-                }
-                JAXBContextCache.addPackage(tmp, PackageUtils.getPackageName(cls), 
-                                            cls == null ? getClass().getClassLoader() : cls.getClassLoader());
-                if (cls != null) {
-                    boolean hasOf = false;
-                    for (Class<?> c : tmp) {
-                        if (c.getPackage() == cls.getPackage() && "ObjectFactory".equals(c.getSimpleName()))
{
-                            hasOf = true;
-                        }
-                    }
-                    if (!hasOf) {
-                        tmp.add(cls);
-                    }
-                }
-                JAXBContextCache.scanPackages(tmp);
-                JAXBContextCache.CachedContextAndSchemas ccs 
-                    = JAXBContextCache.getCachedContextAndSchemas(tmp, null, null, null,
false);
-                jaxbClasses = ccs.getClasses();
-                jaxbContext = ccs.getContext();
-            } catch (JAXBException e) {
-                throw new RuntimeException(e);
-            }
-        }
-        return jaxbContext;
-    }
 }

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HTTPClientPolicyHolder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HTTPClientPolicyHolder.java?rev=1506442&r1=1506441&r2=1506442&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HTTPClientPolicyHolder.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HTTPClientPolicyHolder.java
Wed Jul 24 08:30:05 2013
@@ -19,27 +19,17 @@
 package org.apache.cxf.transport.http.blueprint;
 
 import java.io.ByteArrayInputStream;
-import java.util.HashSet;
 import java.util.Set;
-import java.util.logging.Logger;
-
 import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.w3c.dom.Element;
 
-import org.apache.cxf.common.jaxb.JAXBContextCache;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
 
 
 public class HTTPClientPolicyHolder extends HTTPClientPolicy {
-    private static final Logger LOG = LogUtils.getL7dLogger(HTTPClientPolicyHolder.class);
-
+    
     private String parsedElement;
     private HTTPClientPolicy clientPolicy;
 
@@ -58,7 +48,8 @@ public class HTTPClientPolicyHolder exte
             Element element = docFactory.newDocumentBuilder()
                 .parse(new ByteArrayInputStream(parsedElement.getBytes())).getDocumentElement();
 
-            clientPolicy = (HTTPClientPolicy)getJaxbObject(element, HTTPClientPolicy.class);
+            clientPolicy = (HTTPClientPolicy)HolderUtils.getJaxbObject(element, HTTPClientPolicy.class,
+                                                           jaxbContext, jaxbClasses, getClass().getClassLoader());
             
             this.setAccept(clientPolicy.getAccept());
             this.setAcceptEncoding(clientPolicy.getAcceptEncoding());
@@ -101,49 +92,5 @@ public class HTTPClientPolicyHolder exte
         this.parsedElement = parsedElement;
     }
 
-    protected Object getJaxbObject(Element parent, Class<?> c) {
-
-        try {
-            Unmarshaller umr = getContext(c).createUnmarshaller();
-            JAXBElement<?> ele = (JAXBElement<?>) umr.unmarshal(parent);
-
-            return ele.getValue();
-        } catch (JAXBException e) {
-            LOG.warning("Unable to parse property due to " + e);
-            return null;
-        }
-    }
-
-    protected synchronized JAXBContext getContext(Class<?> cls) {
-        if (jaxbContext == null || jaxbClasses == null || !jaxbClasses.contains(cls)) {
-            try {
-                Set<Class<?>> tmp = new HashSet<Class<?>>();
-                if (jaxbClasses != null) {
-                    tmp.addAll(jaxbClasses);
-                }
-                JAXBContextCache.addPackage(tmp, PackageUtils.getPackageName(cls), 
-                                            cls == null ? getClass().getClassLoader() : cls.getClassLoader());
-                if (cls != null) {
-                    boolean hasOf = false;
-                    for (Class<?> c : tmp) {
-                        if (c.getPackage() == cls.getPackage() && "ObjectFactory".equals(c.getSimpleName()))
{
-                            hasOf = true;
-                        }
-                    }
-                    if (!hasOf) {
-                        tmp.add(cls);
-                    }
-                }
-                JAXBContextCache.scanPackages(tmp);
-                JAXBContextCache.CachedContextAndSchemas ccs 
-                    = JAXBContextCache.getCachedContextAndSchemas(tmp, null, null, null,
false);
-                jaxbClasses = ccs.getClasses();
-                jaxbContext = ccs.getContext();
-            } catch (JAXBException e) {
-                throw new RuntimeException(e);
-            }
-        }
-        return jaxbContext;
-    }
-    
+        
 }

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HTTPServerPolicyHolder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HTTPServerPolicyHolder.java?rev=1506442&r1=1506441&r2=1506442&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HTTPServerPolicyHolder.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HTTPServerPolicyHolder.java
Wed Jul 24 08:30:05 2013
@@ -19,27 +19,18 @@
 package org.apache.cxf.transport.http.blueprint;
 
 import java.io.ByteArrayInputStream;
-import java.util.HashSet;
 import java.util.Set;
-import java.util.logging.Logger;
 
 import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.w3c.dom.Element;
 
-import org.apache.cxf.common.jaxb.JAXBContextCache;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
 
 
 public class HTTPServerPolicyHolder extends HTTPServerPolicy {
-    private static final Logger LOG = LogUtils.getL7dLogger(HTTPServerPolicyHolder.class);
-
+    
     private String parsedElement;
     private HTTPServerPolicy serverPolicy;
 
@@ -58,7 +49,9 @@ public class HTTPServerPolicyHolder exte
             Element element = docFactory.newDocumentBuilder()
                 .parse(new ByteArrayInputStream(parsedElement.getBytes())).getDocumentElement();
 
-            serverPolicy = (HTTPServerPolicy)getJaxbObject(element, HTTPServerPolicy.class);
+            serverPolicy = (HTTPServerPolicy)HolderUtils.getJaxbObject(
+                               element, HTTPServerPolicy.class,
+                               jaxbContext, jaxbClasses, getClass().getClassLoader());
             this.setCacheControl(serverPolicy.getCacheControl());
             this.setContentEncoding(serverPolicy.getContentEncoding());
             this.setContentLocation(serverPolicy.getContentLocation());
@@ -88,50 +81,6 @@ public class HTTPServerPolicyHolder exte
         this.parsedElement = parsedElement;
     }
 
-    protected Object getJaxbObject(Element parent, Class<?> c) {
-
-        try {
-            Unmarshaller umr = getContext(c).createUnmarshaller();
-            JAXBElement<?> ele = (JAXBElement<?>) umr.unmarshal(parent);
-
-            return ele.getValue();
-        } catch (JAXBException e) {
-            LOG.warning("Unable to parse property due to " + e);
-            return null;
-        }
-    }
-
-    protected synchronized JAXBContext getContext(Class<?> cls) {
-        if (jaxbContext == null || jaxbClasses == null || !jaxbClasses.contains(cls)) {
-            try {
-                Set<Class<?>> tmp = new HashSet<Class<?>>();
-                if (jaxbClasses != null) {
-                    tmp.addAll(jaxbClasses);
-                }
-                JAXBContextCache.addPackage(tmp, PackageUtils.getPackageName(cls), 
-                                            cls == null ? getClass().getClassLoader() : cls.getClassLoader());
-                if (cls != null) {
-                    boolean hasOf = false;
-                    for (Class<?> c : tmp) {
-                        if (c.getPackage() == cls.getPackage() && "ObjectFactory".equals(c.getSimpleName()))
{
-                            hasOf = true;
-                        }
-                    }
-                    if (!hasOf) {
-                        tmp.add(cls);
-                    }
-                }
-                JAXBContextCache.scanPackages(tmp);
-                JAXBContextCache.CachedContextAndSchemas ccs 
-                    = JAXBContextCache.getCachedContextAndSchemas(tmp, null, null, null,
false);
-                jaxbClasses = ccs.getClasses();
-                jaxbContext = ccs.getContext();
-            } catch (JAXBException e) {
-                throw new RuntimeException(e);
-            }
-        }
-        return jaxbContext;
-    }
-   
+    
        
 }

Added: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HolderUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HolderUtils.java?rev=1506442&view=auto
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HolderUtils.java
(added)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/HolderUtils.java
Wed Jul 24 08:30:05 2013
@@ -0,0 +1,90 @@
+/**
+ * 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.transport.http.blueprint;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+import org.w3c.dom.Element;
+
+import org.apache.cxf.common.jaxb.JAXBContextCache;
+import org.apache.cxf.common.util.PackageUtils;
+
+public final class HolderUtils {
+    
+    private HolderUtils() {
+        
+    }
+    
+    
+    public static Object getJaxbObject(Element parent, Class<?> c, 
+                                       JAXBContext jaxbContext, 
+                                       Set<Class<?>> jaxbClasses,
+                                       ClassLoader cl) {
+
+        try {
+            Unmarshaller umr = getContext(c, jaxbContext, jaxbClasses, cl).createUnmarshaller();
+            JAXBElement<?> ele = (JAXBElement<?>) umr.unmarshal(parent);
+
+            return ele.getValue();
+        } catch (JAXBException e) {
+            return null;
+        }
+    }
+
+    public static synchronized JAXBContext getContext(Class<?> cls, 
+                                                      JAXBContext jaxbContext, 
+                                                      Set<Class<?>> jaxbClasses,
+                                                      ClassLoader cl) {
+        if (jaxbContext == null || jaxbClasses == null || !jaxbClasses.contains(cls)) {
+            try {
+                Set<Class<?>> tmp = new HashSet<Class<?>>();
+                if (jaxbClasses != null) {
+                    tmp.addAll(jaxbClasses);
+                }
+                JAXBContextCache.addPackage(tmp, PackageUtils.getPackageName(cls), 
+                                            cls == null ? cl : cls.getClassLoader());
+                if (cls != null) {
+                    boolean hasOf = false;
+                    for (Class<?> c : tmp) {
+                        if (c.getPackage() == cls.getPackage() && "ObjectFactory".equals(c.getSimpleName()))
{
+                            hasOf = true;
+                        }
+                    }
+                    if (!hasOf) {
+                        tmp.add(cls);
+                    }
+                }
+                JAXBContextCache.scanPackages(tmp);
+                JAXBContextCache.CachedContextAndSchemas ccs 
+                    = JAXBContextCache.getCachedContextAndSchemas(tmp, null, null, null,
false);
+                jaxbClasses = ccs.getClasses();
+                jaxbContext = ccs.getContext();
+            } catch (JAXBException e) {
+                throw new RuntimeException(e);
+            }
+        }
+        return jaxbContext;
+    }
+}

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/ProxyAuthorizationPolicyHolder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/ProxyAuthorizationPolicyHolder.java?rev=1506442&r1=1506441&r2=1506442&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/ProxyAuthorizationPolicyHolder.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/blueprint/ProxyAuthorizationPolicyHolder.java
Wed Jul 24 08:30:05 2013
@@ -19,26 +19,17 @@
 package org.apache.cxf.transport.http.blueprint;
 
 import java.io.ByteArrayInputStream;
-import java.util.HashSet;
 import java.util.Set;
-import java.util.logging.Logger;
 
 import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Unmarshaller;
 import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.w3c.dom.Element;
 
-import org.apache.cxf.common.jaxb.JAXBContextCache;
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.configuration.security.ProxyAuthorizationPolicy;
 
 public class ProxyAuthorizationPolicyHolder extends ProxyAuthorizationPolicy {
-    private static final Logger LOG = LogUtils.getL7dLogger(ProxyAuthorizationPolicyHolder.class);
-
+    
     private String parsedElement;
     private ProxyAuthorizationPolicy proxyAuthorizationPolicy;
 
@@ -57,7 +48,9 @@ public class ProxyAuthorizationPolicyHol
             Element element = docFactory.newDocumentBuilder()
                 .parse(new ByteArrayInputStream(parsedElement.getBytes())).getDocumentElement();
 
-            proxyAuthorizationPolicy = (ProxyAuthorizationPolicy)getJaxbObject(element, ProxyAuthorizationPolicy.class);
+            proxyAuthorizationPolicy = (ProxyAuthorizationPolicy)HolderUtils.getJaxbObject(
+                                           element, ProxyAuthorizationPolicy.class,
+                                           jaxbContext, jaxbClasses, getClass().getClassLoader());
             this.setAuthorization(proxyAuthorizationPolicy.getAuthorization());
             this.setAuthorizationType(proxyAuthorizationPolicy.getAuthorizationType());
             this.setPassword(proxyAuthorizationPolicy.getPassword());
@@ -80,48 +73,6 @@ public class ProxyAuthorizationPolicyHol
         this.parsedElement = parsedElement;
     }
 
-    protected Object getJaxbObject(Element parent, Class<?> c) {
-
-        try {
-            Unmarshaller umr = getContext(c).createUnmarshaller();
-            JAXBElement<?> ele = (JAXBElement<?>) umr.unmarshal(parent);
-
-            return ele.getValue();
-        } catch (JAXBException e) {
-            LOG.warning("Unable to parse property due to " + e);
-            return null;
-        }
-    }
-
-    protected synchronized JAXBContext getContext(Class<?> cls) {
-        if (jaxbContext == null || jaxbClasses == null || !jaxbClasses.contains(cls)) {
-            try {
-                Set<Class<?>> tmp = new HashSet<Class<?>>();
-                if (jaxbClasses != null) {
-                    tmp.addAll(jaxbClasses);
-                }
-                JAXBContextCache.addPackage(tmp, PackageUtils.getPackageName(cls), 
-                                            cls == null ? getClass().getClassLoader() : cls.getClassLoader());
-                if (cls != null) {
-                    boolean hasOf = false;
-                    for (Class<?> c : tmp) {
-                        if (c.getPackage() == cls.getPackage() && "ObjectFactory".equals(c.getSimpleName()))
{
-                            hasOf = true;
-                        }
-                    }
-                    if (!hasOf) {
-                        tmp.add(cls);
-                    }
-                }
-                JAXBContextCache.scanPackages(tmp);
-                JAXBContextCache.CachedContextAndSchemas ccs 
-                    = JAXBContextCache.getCachedContextAndSchemas(tmp, null, null, null,
false);
-                jaxbClasses = ccs.getClasses();
-                jaxbContext = ccs.getContext();
-            } catch (JAXBException e) {
-                throw new RuntimeException(e);
-            }
-        }
-        return jaxbContext;
-    }
+   
+    
 }



Mime
View raw message