Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B38771053F for ; Mon, 18 Nov 2013 23:23:00 +0000 (UTC) Received: (qmail 78149 invoked by uid 500); 18 Nov 2013 23:23:00 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 78057 invoked by uid 500); 18 Nov 2013 23:23:00 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 78009 invoked by uid 99); 18 Nov 2013 23:23:00 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Nov 2013 23:23:00 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Nov 2013 23:22:57 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 7122423888E2; Mon, 18 Nov 2013 23:22:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131118232235.7122423888E2@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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;", 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, "", - "(Ljava/util/Map;)V", - "(Ljava/util/Map;)V", null); + mv = cw.visitMethod(Opcodes.ACC_STATIC, "", "()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, "", + "(Ljava/util/Map;)V", + "(Ljava/util/Map;)V", null); + mv.visitCode(); + l0 = helper.createLabel(); + mv.visitLabel(l0); + mv.visitLineNumber(32, l0); mv.visitVarInsn(Opcodes.ALOAD, 0); - mv.visitMethodInsn(Opcodes.INVOKESPECIAL, - superName, "", "()V"); + mv.visitMethodInsn(Opcodes.INVOKESPECIAL, superName, "", "()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;", - 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;", + 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 extends J } final Map nspref = databinding.getDeclaredNamespaceMappings(); - if (nspref != null) { - JAXBUtils.setNamespaceMapper(nspref, marshaller); + final Map 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 propEntry @@ -145,6 +153,25 @@ public class DataWriterImpl extends J return marshaller; } + //REVISIT should this go into JAXBUtils? + private static void setContextualNamespaceDecls(Object mapper, Map 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 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) {