cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1543229 - in /cxf/branches/2.7.x-fixes: api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
Date Mon, 18 Nov 2013 23:22:35 GMT
Author: dkulp
Date: Mon Nov 18 23:22:34 2013
New Revision: 1543229

URL: http://svn.apache.org/r1543229
Log:
FIx some test failurs.

Modified:
    cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
    cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java

Modified: cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java?rev=1543229&r1=1543228&r2=1543229&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java (original)
+++ cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java Mon
Nov 18 23:22:34 2013
@@ -1237,11 +1237,14 @@ public final class JAXBUtils {
         String superName = "com/sun/xml/" 
             + ("RI".equals(postFix) ? "" : "internal/") 
             + "bind/marshaller/NamespacePrefixMapper";
+        String postFixedName = "org/apache/cxf/jaxb/NamespaceMapper" + postFix;
+        
         FieldVisitor fv;
         MethodVisitor mv;
-        cw.visit(Opcodes.V1_5, 
+
+        cw.visit(Opcodes.V1_6,
                  Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
-                 "org/apache/cxf/jaxb/NamespaceMapper" + postFix, null,
+                 postFixedName, null,
                  superName, null);
 
         cw.visitSource("NamespaceMapper.java", null);
@@ -1250,34 +1253,57 @@ public final class JAXBUtils {
                            "nspref", "Ljava/util/Map;",
                            "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;",
null);
         fv.visitEnd();
+
+        fv = cw.visitField(Opcodes.ACC_PRIVATE, "nsctxt", "[Ljava/lang/String;", null, null);
+        fv.visitEnd();
+
+        fv = cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC,

+                           "EMPTY_STRING", "[Ljava/lang/String;", null, null);
+        fv.visitEnd();
         
-        mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", 
-                            "(Ljava/util/Map;)V", 
-                            "(Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;)V",
null);
+        mv = cw.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null);
         mv.visitCode();
         Label l0 = helper.createLabel();
         mv.visitLabel(l0);
         mv.visitLineNumber(30, l0);
+        mv.visitInsn(Opcodes.ICONST_0);
+        mv.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/String");
+        mv.visitFieldInsn(Opcodes.PUTSTATIC, postFixedName, "EMPTY_STRING", "[Ljava/lang/String;");
+        mv.visitInsn(Opcodes.RETURN);
+        mv.visitMaxs(1, 0);
+        mv.visitEnd();
+
+        mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>",
+                            "(Ljava/util/Map;)V",
+                            "(Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;)V",
null);
+        mv.visitCode();
+        l0 = helper.createLabel();
+        mv.visitLabel(l0);
+        mv.visitLineNumber(32, l0);
         mv.visitVarInsn(Opcodes.ALOAD, 0);
-        mv.visitMethodInsn(Opcodes.INVOKESPECIAL,
-                           superName, "<init>", "()V");
+        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "<init>", "()V");
         Label l1 = helper.createLabel();
         mv.visitLabel(l1);
-        mv.visitLineNumber(31, l1);
+        mv.visitLineNumber(29, l1);
         mv.visitVarInsn(Opcodes.ALOAD, 0);
-        mv.visitVarInsn(Opcodes.ALOAD, 1);
-        mv.visitFieldInsn(Opcodes.PUTFIELD, "org/apache/cxf/jaxb/NamespaceMapper" + postFix,
-                          "nspref", "Ljava/util/Map;");
+        mv.visitFieldInsn(Opcodes.GETSTATIC, postFixedName, "EMPTY_STRING", "[Ljava/lang/String;");
+        mv.visitFieldInsn(Opcodes.PUTFIELD, postFixedName, "nsctxt", "[Ljava/lang/String;");
         Label l2 = helper.createLabel();
         mv.visitLabel(l2);
-        mv.visitLineNumber(32, l2);
-        mv.visitInsn(Opcodes.RETURN);
+        mv.visitLineNumber(33, l2);
+        mv.visitVarInsn(Opcodes.ALOAD, 0);
+        mv.visitVarInsn(Opcodes.ALOAD, 1);
+        mv.visitFieldInsn(Opcodes.PUTFIELD, postFixedName, "nspref", "Ljava/util/Map;");
         Label l3 = helper.createLabel();
         mv.visitLabel(l3);
-        mv.visitLocalVariable("this", "Lorg/apache/cxf/jaxb/NamespaceMapper" + postFix +
";", null, l0, l3, 0);
-        mv.visitLocalVariable("nspref", "Ljava/util/Map;",
-                              "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;",

-                              l0, l3, 1);
+        mv.visitLineNumber(34, l3);
+        mv.visitInsn(Opcodes.RETURN);
+        Label l4 = helper.createLabel();
+        mv.visitLabel(l4);
+        mv.visitLocalVariable("this", "L" + postFixedName + ";", null, l0, l4, 0);
+        mv.visitLocalVariable("nspref", 
+                              "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;",

+                              l0, l4, 1);
         mv.visitMaxs(2, 2);
         mv.visitEnd();
 
@@ -1287,11 +1313,9 @@ public final class JAXBUtils {
         mv.visitCode();
         l0 = helper.createLabel();
         mv.visitLabel(l0);
-        mv.visitLineNumber(38, l0);
+        mv.visitLineNumber(39, l0);
         mv.visitVarInsn(Opcodes.ALOAD, 0);
-        mv.visitFieldInsn(Opcodes.GETFIELD, 
-                          "org/apache/cxf/jaxb/NamespaceMapper" + postFix, 
-                          "nspref", "Ljava/util/Map;");
+        mv.visitFieldInsn(Opcodes.GETFIELD, postFixedName, "nspref", "Ljava/util/Map;");
         mv.visitVarInsn(Opcodes.ALOAD, 1);
         mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map", 
                            "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
@@ -1299,34 +1323,72 @@ public final class JAXBUtils {
         mv.visitVarInsn(Opcodes.ASTORE, 4);
         l1 = helper.createLabel();
         mv.visitLabel(l1);
-        mv.visitLineNumber(39, l1);
+        mv.visitLineNumber(40, l1);
         mv.visitVarInsn(Opcodes.ALOAD, 4);
         l2 = helper.createLabel();
         mv.visitJumpInsn(Opcodes.IFNULL, l2);
         l3 = helper.createLabel();
         mv.visitLabel(l3);
-        mv.visitLineNumber(40, l3);
+        mv.visitLineNumber(41, l3);
         mv.visitVarInsn(Opcodes.ALOAD, 4);
         mv.visitInsn(Opcodes.ARETURN);
         mv.visitLabel(l2);
-        mv.visitLineNumber(42, l2);
+        mv.visitLineNumber(43, l2);
+        mv.visitFrame(Opcodes.F_APPEND, 1, new Object[] {"java/lang/String"}, 0, null);
         mv.visitVarInsn(Opcodes.ALOAD, 2);
         mv.visitInsn(Opcodes.ARETURN);
-        Label l4 = helper.createLabel();
+        l4 = helper.createLabel();
         mv.visitLabel(l4);
-        mv.visitLocalVariable("this", "Lorg/apache/cxf/jaxb/NamespaceMapper" + postFix +
";", null, l0, l4, 0);
+        mv.visitLocalVariable("this", "L" + postFixedName + ";", null, l0, l4, 0);
         mv.visitLocalVariable("namespaceUri", "Ljava/lang/String;", null, l0, l4, 1);
         mv.visitLocalVariable("suggestion", "Ljava/lang/String;", null, l0, l4, 2);
         mv.visitLocalVariable("requirePrefix", "Z", null, l0, l4, 3);
         mv.visitLocalVariable("prefix", "Ljava/lang/String;", null, l1, l4, 4);
         mv.visitMaxs(2, 5);
         mv.visitEnd();
+
+        mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "setContextualNamespaceDecls", "([Ljava/lang/String;)V",
null, null);
+        mv.visitCode();
+        l0 = helper.createLabel();
+        mv.visitLabel(l0);
+        mv.visitLineNumber(47, l0);
+        mv.visitVarInsn(Opcodes.ALOAD, 0);
+        mv.visitVarInsn(Opcodes.ALOAD, 1);
+        mv.visitFieldInsn(Opcodes.PUTFIELD, postFixedName, "nsctxt", "[Ljava/lang/String;");
+        l1 = helper.createLabel();
+        mv.visitLabel(l1);
+        mv.visitLineNumber(48, l1);
+        mv.visitInsn(Opcodes.RETURN);
+        l2 = helper.createLabel();
+        mv.visitLabel(l2);
+        mv.visitLocalVariable("this", "L" + postFixedName + ";", null, l0, l2, 0);
+        mv.visitLocalVariable("contextualNamespaceDecls", "[Ljava/lang/String;", null, l0,
l2, 1);
+        mv.visitMaxs(2, 2);
+        mv.visitEnd();
+
+        mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getContextualNamespaceDecls", "()[Ljava/lang/String;",
null, null);
+        mv.visitCode();
+        l0 = helper.createLabel();
+        mv.visitLabel(l0);
+        mv.visitLineNumber(51, l0);
+        mv.visitVarInsn(Opcodes.ALOAD, 0);
+        mv.visitFieldInsn(Opcodes.GETFIELD, postFixedName, "nsctxt", "[Ljava/lang/String;");
+        mv.visitInsn(Opcodes.ARETURN);
+        l1 = helper.createLabel();
+
+        mv.visitLabel(l1);
+        mv.visitLocalVariable("this", "L" + postFixedName + ";", null, l0, l1, 0);
+        
+        mv.visitMaxs(1, 1);
+        mv.visitEnd();
+
         cw.visitEnd();
 
         byte bts[] = cw.toByteArray();
         return helper.loadClass(className,
                                 ref, bts);
     }
+    //CHECKSTYLE:ON
     
     public static JAXBContextProxy createJAXBContextProxy(final JAXBContext ctx) {
         return createJAXBContextProxy(ctx, null, null);
@@ -1340,7 +1402,6 @@ public final class JAXBUtils {
         }
         return new SchemaCollectionContextProxy(ctx, collection, defaultNs);
     }
-
     public static JAXBBeanInfo getBeanInfo(JAXBContextProxy context, Class<?> cls)
{
         Object o = context.getBeanInfo(cls);
         if (o == null) {

Modified: cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java?rev=1543229&r1=1543228&r2=1543229&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
Mon Nov 18 23:22:34 2013
@@ -22,8 +22,10 @@ package org.apache.cxf.jaxb.io;
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Array;
+import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -37,6 +39,7 @@ import javax.xml.bind.attachment.Attachm
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.jaxb.JAXBUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.ReflectionUtil;
 import org.apache.cxf.databinding.DataWriter;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxb.JAXBDataBase;
@@ -108,8 +111,13 @@ public class DataWriterImpl<T> extends J
             }
             
             final Map<String, String> nspref = databinding.getDeclaredNamespaceMappings();
-            if (nspref != null) {
-                JAXBUtils.setNamespaceMapper(nspref, marshaller);
+            final Map<String, String> nsctxt = databinding.getContextualNamespaceMap();
+            // set the prefix mapper if either of the prefix map is configured
+            if (nspref != null || nsctxt != null) {
+                Object mapper = JAXBUtils.setNamespaceMapper(nspref != null ? nspref : nsctxt,
marshaller);
+                if (nsctxt != null) {
+                    setContextualNamespaceDecls(mapper, nsctxt);
+                }
             }
             if (databinding.getMarshallerProperties() != null) {
                 for (Map.Entry<String, Object> propEntry 
@@ -145,6 +153,25 @@ public class DataWriterImpl<T> extends J
         return marshaller;
     }
     
+    //REVISIT should this go into JAXBUtils?
+    private static void setContextualNamespaceDecls(Object mapper, Map<String, String>
nsctxt) {
+        try {
+            Method m = ReflectionUtil.getDeclaredMethod(mapper.getClass(), 
+                                                        "setContextualNamespaceDecls", new
Class<?>[]{String[].class});
+            String[] args = new String[nsctxt.size() * 2];
+            int ai = 0;
+            for (Entry<String, String> nsp : nsctxt.entrySet()) {
+                args[ai++] = nsp.getValue();
+                args[ai++] = nsp.getKey();
+            }
+            m.invoke(mapper, new Object[]{args});
+        } catch (Exception e) {
+            // ignore
+            LOG.log(Level.WARNING, "Failed to set the contextual namespace map", e);
+        }
+        
+    }
+
     public void write(Object obj, MessagePartInfo part, T output) {
         boolean honorJaxbAnnotation = honorJAXBAnnotations(part);
         if (part != null && !part.isElement() && part.getTypeClass() != null)
{



Mime
View raw message