You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2008/10/28 01:56:33 UTC
svn commit: r708410 - in /cxf/trunk: common/common/
common/common/src/main/java/org/apache/cxf/common/util/
common/common/src/main/java/org/apache/cxf/jaxb/ parent/
rt/core/src/test/java/org/apache/cxf/configuration/spring/
rt/databinding/jaxb/ rt/data...
Author: dkulp
Date: Mon Oct 27 17:56:32 2008
New Revision: 708410
URL: http://svn.apache.org/viewvc?rev=708410&view=rev
Log:
BUNCH of updates to get all the jaxb RUNTIME parts (including DynamicClient) working with the JAXB implementationbuilt into Java6 as well as the shipped version. tooling still requires shipped xjc/impl at this point.
Added:
cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ReflectionInvokationHandler.java (with props)
cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/NamespaceMapper.java (with props)
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBBeanInfo.java (with props)
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextProxy.java (with props)
Modified:
cxf/trunk/common/common/pom.xml
cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java
cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
cxf/trunk/parent/pom.xml
cxf/trunk/rt/core/src/test/java/org/apache/cxf/configuration/spring/ConfigurerImplTest.java
cxf/trunk/rt/databinding/jaxb/pom.xml
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/TypeClassInitializer.java
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java
cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java
cxf/trunk/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xsd
cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIConduitTest.java
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
cxf/trunk/tools/wsdlto/misc/src/main/java/org/apache/cxf/tools/misc/processor/AbstractWSDLToProcessor.java
Modified: cxf/trunk/common/common/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/pom.xml?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/common/common/pom.xml (original)
+++ cxf/trunk/common/common/pom.xml Mon Oct 27 17:56:32 2008
@@ -74,7 +74,7 @@
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
- <scope>test</scope>
+ <scope>provided</scope>
</dependency>
<dependency>
Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ASMHelper.java Mon Oct 27 17:56:32 2008
@@ -122,7 +122,12 @@
public ClassWriter createClassWriter() {
ClassWriter newCw = null;
if (!oldASM) {
- Class<ClassWriter> cls = ClassWriter.class;
+ Class<ClassWriter> cls;
+ try {
+ cls = ClassWriter.class;
+ } catch (NoClassDefFoundError error) {
+ return null;
+ }
try {
// ASM 1.5.x/2.x
Constructor<ClassWriter> cons = cls.getConstructor(new Class<?>[] {Boolean.TYPE});
@@ -182,7 +187,7 @@
super(parent);
}
public Class<?> lookupDefinedClass(String name) {
- return defined.get(name);
+ return defined.get(name.replace('/', '.'));
}
public Class<?> defineClass(String name, byte bytes[]) {
@@ -201,7 +206,7 @@
}
Class<?> ret = super.defineClass(name.replace('/', '.'), bytes, 0, bytes.length);
- defined.put(name, ret);
+ defined.put(name.replace('/', '.'), ret);
return ret;
}
}
Added: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ReflectionInvokationHandler.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ReflectionInvokationHandler.java?rev=708410&view=auto
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ReflectionInvokationHandler.java (added)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ReflectionInvokationHandler.java Mon Oct 27 17:56:32 2008
@@ -0,0 +1,113 @@
+/**
+ * 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.common.util;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+import java.lang.reflect.Proxy;
+import java.util.Iterator;
+
+/**
+ *
+ */
+public class ReflectionInvokationHandler implements InvocationHandler {
+ private Object target;
+
+ public ReflectionInvokationHandler(Object obj) {
+ target = obj;
+ }
+
+ public Object getTarget() {
+ return target;
+ }
+
+ /** {@inheritDoc}*/
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ WrapReturn wr = method.getAnnotation(WrapReturn.class);
+ try {
+ Method m = target.getClass().getMethod(method.getName(), method.getParameterTypes());
+ m.setAccessible(true);
+ return wrapReturn(wr, m.invoke(target, args));
+ } catch (NoSuchMethodException e) {
+ for (Method m2 : target.getClass().getMethods()) {
+ if (m2.getName().equals(method.getName())
+ && m2.getParameterTypes().length == method.getParameterTypes().length) {
+ boolean found = true;
+ for (int x = 0; x < m2.getParameterTypes().length; x++) {
+ if (args[x] != null
+ && !m2.getParameterTypes()[x].isInstance(args[x])) {
+ found = false;
+ }
+ }
+ if (found) {
+ m2.setAccessible(true);
+ return wrapReturn(wr, m2.invoke(target, args));
+ }
+ }
+ }
+ throw e;
+ }
+ }
+ private static Object wrapReturn(WrapReturn wr, Object t) {
+ if (wr == null || t == null) {
+ return t;
+ }
+ if (wr.iterator()) {
+ return new WrapperIterator(wr.value(), (Iterator)t);
+ }
+ return createProxyWrapper(t, wr.value());
+ }
+
+ public static final <T> T createProxyWrapper(Object target, Class<T> inf) {
+ InvocationHandler h = new ReflectionInvokationHandler(target);
+ return inf.cast(Proxy.newProxyInstance(inf.getClassLoader(), new Class[] {inf}, h));
+ }
+
+ @Target(ElementType.METHOD)
+ @Retention(RetentionPolicy.RUNTIME)
+ public static @interface WrapReturn {
+ Class<?> value();
+ boolean iterator() default false;
+ }
+
+ private static class WrapperIterator implements Iterator {
+ Class<?> cls;
+ Iterator internal;
+ public WrapperIterator(Class<?> c, Iterator it) {
+ internal = it;
+ cls = c;
+ }
+ public boolean hasNext() {
+ return internal.hasNext();
+ }
+ public Object next() {
+ Object obj = internal.next();
+ return createProxyWrapper(obj, cls);
+ }
+ public void remove() {
+ internal.remove();
+ }
+ }
+}
Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ReflectionInvokationHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/common/util/ReflectionInvokationHandler.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java Mon Oct 27 17:56:32 2008
@@ -19,23 +19,57 @@
package org.apache.cxf.jaxb;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.Type;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.StringTokenizer;
-import java.util.concurrent.Future;
+import java.util.logging.Level;
+import java.util.logging.Logger;
-import javax.xml.ws.AsyncHandler;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.PropertyException;
+import javax.xml.bind.attachment.AttachmentMarshaller;
+import javax.xml.bind.attachment.AttachmentUnmarshaller;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.stream.StreamResult;
import javax.xml.ws.Holder;
-import javax.xml.ws.Response;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+import org.xml.sax.InputSource;
+
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.ASMHelper;
+import org.apache.cxf.common.util.ReflectionInvokationHandler;
+import org.apache.cxf.common.util.ReflectionInvokationHandler.WrapReturn;
import org.apache.cxf.helpers.JavaUtils;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.Label;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+
+
public final class JAXBUtils {
public enum IdentifierType {
@@ -65,7 +99,8 @@
private static final Map<String, String> BUILTIN_DATATYPES_MAP;
private static final Map<String, Class<?>> HOLDER_TYPES_MAP;
-
+ private static final Logger LOG = LogUtils.getL7dLogger(JAXBUtils.class, "CommonUtilityMessages");
+
static {
BUILTIN_DATATYPES_MAP = new HashMap<String, String>();
BUILTIN_DATATYPES_MAP.put("string", "java.lang.String");
@@ -225,23 +260,6 @@
return packageName.toString();
}
- public static boolean isAsync(Method method) {
- return method.getName().endsWith("Async")
- && (method.getReturnType().equals(Response.class) || method.getReturnType().equals(Future.class));
- }
-
- public static boolean isAsyncPolling(Method method) {
- return method.getName().endsWith("Async")
- && (method.getReturnType().equals(Response.class));
- }
-
- public static boolean isAsyncCallback(Method method) {
- Class[] paramTypes = method.getParameterTypes();
- return method.getName().endsWith("Async")
- && (method.getReturnType().equals(Future.class)
- && AsyncHandler.class.isAssignableFrom(paramTypes[paramTypes.length - 1]));
- }
-
private static String normalizePackageNamePart(String name) {
StringBuffer sname = new StringBuffer(name.toLowerCase());
@@ -476,4 +494,337 @@
return cls;
}
+ public static JAXBContext createRIContext(Class<?> clss[], String defaultNS) throws JAXBException {
+ try {
+ Class<?> cls;
+ Map<String, Object> map = new HashMap<String, Object>();
+ try {
+ cls = Class.forName("com.sun.xml.bind.v2.ContextFactory");
+ if (defaultNS != null) {
+ map.put("com.sun.xml.bind.defaultNamespaceRemap", defaultNS);
+ }
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ cls = Class.forName("com.sun.xml.internal.bind.v2.ContextFactory");
+ if (defaultNS != null) {
+ map.put("com.sun.xml.internal.bind.defaultNamespaceRemap", defaultNS);
+ }
+ }
+ Method meth = cls.getMethod("createContext", clss.getClass(), Map.class);
+ return (JAXBContext)meth.invoke(null, clss, map);
+ } catch (Exception e) {
+ throw new JAXBException(e);
+ }
+ }
+ public static void setNamespaceWrapper(final Map<String, String> nspref,
+ Marshaller marshaller) throws PropertyException {
+ Object mapper = null;
+ if (marshaller.getClass().getName().contains(".internal.")) {
+ mapper = createNamespaceWrapper(nspref);
+ if (mapper == null) {
+ LOG.log(Level.INFO, "Could not create namespace mapper for JDK internal"
+ + " JAXB implementation.");
+ } else {
+ marshaller.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper",
+ mapper);
+ }
+ } else {
+ try {
+ Class<?> cls = Class.forName("org.apache.cxf.jaxb.NamespaceMapper");
+ mapper = cls.getConstructor(Map.class).newInstance(nspref);
+ } catch (Exception ex) {
+ LOG.log(Level.INFO, "Could not create NamespaceMapper", ex);
+ }
+ marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper",
+ mapper);
+ }
+ }
+ public static BridgeWrapper createBridge(Set<Class<?>> ctxClasses,
+ QName qname,
+ Class<?> refcls,
+ Annotation anns[]) throws JAXBException {
+ try {
+ Class<?> cls;
+ String pkg = "com.sun.xml.bind.";
+ try {
+ cls = Class.forName("com.sun.xml.bind.api.JAXBRIContext");
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ cls = Class.forName("com.sun.xml.internal.bind.api.JAXBRIContext");
+ pkg = "com.sun.xml.internal.bind.";
+ }
+ Class<?> refClass = Class.forName(pkg + "api.TypeReference");
+ Object ref = refClass.getConstructor(QName.class,
+ Type.class,
+ anns.getClass()).newInstance(qname, refcls, anns);
+ List<Object> typeRefs = new ArrayList<Object>();
+ typeRefs.add(ref);
+ List<Class<?>> clses = new ArrayList<Class<?>>(ctxClasses);
+ clses.add(refClass.getField("type").get(ref).getClass());
+ clses.add(refcls);
+
+ Object ctx = null;
+ for (Method m : cls.getDeclaredMethods()) {
+ if (m.getName().equals("newInstance")
+ && m.getParameterTypes().length == 6) {
+ ctx = m.invoke(null, clses.toArray(new Class[clses.size()]),
+ typeRefs, null, null, true, null);
+
+ }
+ }
+
+ Object bridge = ctx.getClass().getMethod("createBridge", refClass).invoke(ctx, ref);
+ return ReflectionInvokationHandler.createProxyWrapper(bridge,
+ BridgeWrapper.class);
+ } catch (Exception ex) {
+ throw new JAXBException(ex);
+ }
+ }
+ public static interface BridgeWrapper {
+
+ Object unmarshal(XMLStreamReader source, AttachmentUnmarshaller am) throws JAXBException;
+
+ Object unmarshal(InputStream source) throws JAXBException;
+
+ Object unmarshal(Node source, AttachmentUnmarshaller am) throws JAXBException;
+
+ void marshal(Object elValue, XMLStreamWriter source, AttachmentMarshaller m) throws JAXBException;
+
+ void marshal(Object elValue, StreamResult s1) throws JAXBException;
+
+ void marshal(Object elValue, Node source, AttachmentMarshaller am) throws JAXBException;
+ }
+
+
+ public static SchemaCompiler createSchemaCompiler() throws JAXBException {
+ try {
+ Class<?> cls;
+ Object sc = null;
+ try {
+ cls = Class.forName("com.sun.tools.xjc.api.XJC");
+ sc = cls.getMethod("createSchemaCompiler").invoke(null);
+ } catch (Throwable e) {
+ // TODO Auto-generated catch block
+ cls = Class.forName("com.sun.tools.internal.xjc.api.XJC");
+ sc = cls.getMethod("createSchemaCompiler").invoke(null);
+ }
+
+ return ReflectionInvokationHandler.createProxyWrapper(sc,
+ SchemaCompiler.class);
+ } catch (Exception ex) {
+ throw new JAXBException(ex);
+ }
+ }
+ public static Object createFileCodeWriter(File f) throws JAXBException {
+ try {
+ Class<?> cls;
+ try {
+ cls = Class.forName("com.sun.codemodel.writer.FileCodeWriter");
+ } catch (ClassNotFoundException e) {
+ // TODO Auto-generated catch block
+ cls = Class.forName("com.sun.codemodel.internal.writer.FileCodeWriter");
+ }
+ return cls.getConstructor(File.class).newInstance(f);
+ } catch (Exception ex) {
+ throw new JAXBException(ex);
+ }
+ }
+ public static Class<?> getParamClass(SchemaCompiler sc, String method) {
+ Object o = ((ReflectionInvokationHandler)Proxy.getInvocationHandler(sc)).getTarget();
+ for (Method m : o.getClass().getMethods()) {
+ if (m.getName().equals(method) && m.getParameterTypes().length == 1) {
+ return m.getParameterTypes()[0];
+ }
+ }
+ return null;
+ }
+ public static interface SchemaCompiler {
+
+ void setErrorListener(Object elForRun);
+
+ void setClassNameAllocator(Object allocator);
+
+ @WrapReturn(S2JJAXBModel.class)
+ S2JJAXBModel bind();
+
+ void parseSchema(InputSource source);
+
+ void parseSchema(String key, Element el);
+
+ @WrapReturn(Options.class)
+ Options getOptions();
+ }
+ public static interface S2JJAXBModel {
+
+ @WrapReturn(JCodeModel.class)
+ JCodeModel generateCode(Object object, Object elForRun);
+
+ @WrapReturn(Mapping.class)
+ Mapping get(QName qn);
+
+ @WrapReturn(TypeAndAnnotation.class)
+ TypeAndAnnotation getJavaType(QName typeQName);
+ }
+ public static interface Mapping {
+ @WrapReturn(TypeAndAnnotation.class)
+ TypeAndAnnotation getType();
+ }
+ public static interface TypeAndAnnotation {
+ @WrapReturn(JType.class)
+ JType getTypeClass();
+ }
+ public static interface JType {
+ boolean isArray();
+
+ @WrapReturn(JType.class)
+ JType elementType();
+
+ boolean isPrimitive();
+
+ String binaryName();
+
+ String fullName();
+
+ String name();
+
+ @WrapReturn(value = JType.class, iterator = true)
+ Iterator<JType> classes();
+ }
+ public static interface Options {
+
+ void addGrammar(InputSource is);
+
+ void addBindFile(InputSource is);
+
+ String getBuildID();
+ }
+ public static interface JCodeModel {
+
+ void build(Object writer) throws IOException;
+
+ @WrapReturn(value = JPackage.class, iterator = true)
+ Iterator<JPackage> packages();
+ }
+ public static interface JPackage {
+
+ String name();
+
+ @WrapReturn(value = JDefinedClass.class, iterator = true)
+ Iterator<JDefinedClass> classes();
+ }
+ public static interface JDefinedClass {
+ String name();
+
+ String fullName();
+ }
+
+ private static synchronized Object createNamespaceWrapper(Map<String, String> map) {
+ ASMHelper helper = new ASMHelper();
+ String className = "org.apache.cxf.jaxb.NamespaceMapperInternal";
+ Class<?> cls = helper.findClass(className, JAXBUtils.class);
+ if (cls == null) {
+ ClassWriter cw = helper.createClassWriter();
+ if (cw == null) {
+ return null;
+ }
+ cls = createNamespaceWrapperInternal(helper, cw);
+ }
+ try {
+ return cls.getConstructor(Map.class).newInstance(map);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+ private static Class<?> createNamespaceWrapperInternal(ASMHelper helper, ClassWriter cw) {
+ String className = "org.apache.cxf.jaxb.NamespaceMapperInternal";
+ FieldVisitor fv;
+ MethodVisitor mv;
+ cw.visit(Opcodes.V1_5,
+ Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_SUPER,
+ "org/apache/cxf/jaxb/NamespaceMapperInternal", null,
+ "com/sun/xml/internal/bind/marshaller/NamespacePrefixMapper", null);
+
+ cw.visitSource("NamespaceMapper.java", null);
+
+ fv = cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL,
+ "nspref", "Ljava/util/Map;",
+ "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;", 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.visitCode();
+ Label l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitLineNumber(30, l0);
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
+ mv.visitMethodInsn(Opcodes.INVOKESPECIAL,
+ "com/sun/xml/internal/bind/marshaller/NamespacePrefixMapper", "<init>", "()V");
+ Label l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitLineNumber(31, l1);
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
+ mv.visitVarInsn(Opcodes.ALOAD, 1);
+ mv.visitFieldInsn(Opcodes.PUTFIELD, "org/apache/cxf/jaxb/NamespaceMapperInternal",
+ "nspref", "Ljava/util/Map;");
+ Label l2 = new Label();
+ mv.visitLabel(l2);
+ mv.visitLineNumber(32, l2);
+ mv.visitInsn(Opcodes.RETURN);
+ Label l3 = new Label();
+ mv.visitLabel(l3);
+ mv.visitLocalVariable("this", "Lorg/apache/cxf/jaxb/NamespaceMapperInternal;", null, l0, l3, 0);
+ mv.visitLocalVariable("nspref", "Ljava/util/Map;",
+ "Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;",
+ l0, l3, 1);
+ mv.visitMaxs(2, 2);
+ mv.visitEnd();
+
+ mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getPreferredPrefix",
+ "(Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/String;",
+ null, null);
+ mv.visitCode();
+ l0 = new Label();
+ mv.visitLabel(l0);
+ mv.visitLineNumber(38, l0);
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
+ mv.visitFieldInsn(Opcodes.GETFIELD,
+ "org/apache/cxf/jaxb/NamespaceMapperInternal",
+ "nspref", "Ljava/util/Map;");
+ mv.visitVarInsn(Opcodes.ALOAD, 1);
+ mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Map",
+ "get", "(Ljava/lang/Object;)Ljava/lang/Object;");
+ mv.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/String");
+ mv.visitVarInsn(Opcodes.ASTORE, 4);
+ l1 = new Label();
+ mv.visitLabel(l1);
+ mv.visitLineNumber(39, l1);
+ mv.visitVarInsn(Opcodes.ALOAD, 4);
+ l2 = new Label();
+ mv.visitJumpInsn(Opcodes.IFNULL, l2);
+ l3 = new Label();
+ mv.visitLabel(l3);
+ mv.visitLineNumber(40, l3);
+ mv.visitVarInsn(Opcodes.ALOAD, 4);
+ mv.visitInsn(Opcodes.ARETURN);
+ mv.visitLabel(l2);
+ mv.visitLineNumber(42, l2);
+ mv.visitVarInsn(Opcodes.ALOAD, 2);
+ mv.visitInsn(Opcodes.ARETURN);
+ Label l4 = new Label();
+ mv.visitLabel(l4);
+ mv.visitLocalVariable("this", "Lorg/apache/cxf/jaxb/NamespaceMapperInternal;", 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();
+ cw.visitEnd();
+
+ byte bts[] = cw.toByteArray();
+ return helper.loadClass(className,
+ JAXBUtils.class, bts);
+ }
}
Added: cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/NamespaceMapper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/NamespaceMapper.java?rev=708410&view=auto
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/NamespaceMapper.java (added)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/NamespaceMapper.java Mon Oct 27 17:56:32 2008
@@ -0,0 +1,43 @@
+/**
+ * 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;
+
+import java.util.Map;
+
+import com.sun.xml.bind.marshaller.NamespacePrefixMapper;
+
+
+public final class NamespaceMapper extends NamespacePrefixMapper {
+ private final Map<String, String> nspref;
+
+ public NamespaceMapper(Map<String, String> nspref) {
+ this.nspref = nspref;
+ }
+
+ public String getPreferredPrefix(String namespaceUri,
+ String suggestion,
+ boolean requirePrefix) {
+ String prefix = nspref.get(namespaceUri);
+ if (prefix != null) {
+ return prefix;
+ }
+ return suggestion;
+ }
+}
\ No newline at end of file
Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/NamespaceMapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/NamespaceMapper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/parent/pom.xml?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/parent/pom.xml (original)
+++ cxf/trunk/parent/pom.xml Mon Oct 27 17:56:32 2008
@@ -795,6 +795,10 @@
<groupId>javax.xml.bind</groupId>
<artifactId>jsr173_api</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-impl</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
Modified: cxf/trunk/rt/core/src/test/java/org/apache/cxf/configuration/spring/ConfigurerImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/configuration/spring/ConfigurerImplTest.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/test/java/org/apache/cxf/configuration/spring/ConfigurerImplTest.java (original)
+++ cxf/trunk/rt/core/src/test/java/org/apache/cxf/configuration/spring/ConfigurerImplTest.java Mon Oct 27 17:56:32 2008
@@ -23,11 +23,10 @@
import java.math.BigInteger;
import javax.xml.bind.DatatypeConverter;
+import javax.xml.bind.DatatypeConverterInterface;
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
import javax.xml.namespace.QName;
-import com.sun.xml.bind.DatatypeConverterImpl;
-
import org.apache.cxf.bus.spring.BusApplicationContext;
import org.apache.cxf.configuration.Configurable;
import org.junit.Assert;
@@ -38,7 +37,19 @@
public class ConfigurerImplTest extends Assert {
static {
- DatatypeConverter.setDatatypeConverter(DatatypeConverterImpl.theInstance);
+ Class<?> cls;
+ try {
+ try {
+ cls = Class.forName("com.sun.xml.bind.DatatypeConverterImpl");
+ } catch (ClassNotFoundException e) {
+ cls = Class.forName("com.sun.xml.internal.bind.DatatypeConverterImpl");
+ }
+ DatatypeConverterInterface convert = (DatatypeConverterInterface)cls.getField("theInstance")
+ .get(null);
+ DatatypeConverter.setDatatypeConverter(convert);
+ } catch (Exception ex) {
+ //ignore;
+ }
}
@Test
Modified: cxf/trunk/rt/databinding/jaxb/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/pom.xml?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/pom.xml (original)
+++ cxf/trunk/rt/databinding/jaxb/pom.xml Mon Oct 27 17:56:32 2008
@@ -147,11 +147,17 @@
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
</dependency>
+ <dependency>
+ <groupId>asm</groupId>
+ <artifactId>asm</artifactId>
+ <optional>true</optional>
+ </dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jaxws_2.1_spec</artifactId>
Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/DynamicClientFactory.java Mon Oct 27 17:56:32 2008
@@ -51,21 +51,11 @@
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
-import com.sun.codemodel.JCodeModel;
-import com.sun.codemodel.JDefinedClass;
-import com.sun.codemodel.JPackage;
-import com.sun.codemodel.writer.FileCodeWriter;
-import com.sun.tools.xjc.Options;
-import com.sun.tools.xjc.api.ClassNameAllocator;
-import com.sun.tools.xjc.api.ErrorListener;
-import com.sun.tools.xjc.api.S2JJAXBModel;
-import com.sun.tools.xjc.api.SchemaCompiler;
-import com.sun.tools.xjc.api.XJC;
-
import org.apache.cxf.Bus;
import org.apache.cxf.bus.CXFBusFactory;
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.ReflectionInvokationHandler;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.endpoint.ClientImpl;
@@ -73,6 +63,12 @@
import org.apache.cxf.endpoint.SimpleEndpointImplFactory;
import org.apache.cxf.helpers.FileUtils;
import org.apache.cxf.jaxb.JAXBDataBinding;
+import org.apache.cxf.jaxb.JAXBUtils;
+import org.apache.cxf.jaxb.JAXBUtils.JCodeModel;
+import org.apache.cxf.jaxb.JAXBUtils.JDefinedClass;
+import org.apache.cxf.jaxb.JAXBUtils.JPackage;
+import org.apache.cxf.jaxb.JAXBUtils.S2JJAXBModel;
+import org.apache.cxf.jaxb.JAXBUtils.SchemaCompiler;
import org.apache.cxf.resource.URIResolver;
import org.apache.cxf.service.Service;
import org.apache.cxf.service.factory.ServiceConstructionException;
@@ -200,12 +196,21 @@
//all SI's should have the same schemas
Collection<SchemaInfo> schemas = svc.getServiceInfos().get(0).getSchemas();
- SchemaCompiler compiler = XJC.createSchemaCompiler();
- ErrorListener elForRun = new InnerErrorListener(wsdlUrl);
+ SchemaCompiler compiler;
+ try {
+ compiler = JAXBUtils.createSchemaCompiler();
+ } catch (JAXBException e1) {
+ throw new IllegalStateException("Unable to create schema compiler", e1);
+ }
+ Object elForRun = ReflectionInvokationHandler
+ .createProxyWrapper(new InnerErrorListener(wsdlUrl),
+ JAXBUtils.getParamClass(compiler, "setErrorListener"));
+
compiler.setErrorListener(elForRun);
- ClassNameAllocator allocator
- = new ClassNameAllocatorImpl();
+ Object allocator = ReflectionInvokationHandler
+ .createProxyWrapper(new ClassNameAllocatorImpl(),
+ JAXBUtils.getParamClass(compiler, "setClassNameAllocator"));
compiler.setClassNameAllocator(allocator);
@@ -239,9 +244,9 @@
throw new IllegalStateException("Unable to create working directory " + src.getPath());
}
try {
- FileCodeWriter writer = new FileCodeWriter(src);
+ Object writer = JAXBUtils.createFileCodeWriter(src);
codeModel.build(writer);
- } catch (IOException e) {
+ } catch (Exception e) {
throw new IllegalStateException("Unable to write generated Java files for schemas: "
+ e.getMessage(), e);
}
@@ -303,7 +308,6 @@
return client;
}
- @SuppressWarnings("deprecation")
private void addBindingFiles(List<String> bindingFiles, SchemaCompiler compiler) {
if (bindingFiles != null) {
for (String s : bindingFiles) {
@@ -366,7 +370,6 @@
}
- @SuppressWarnings("deprecation")
private void addSchemas(String wsdlUrl, Collection<SchemaInfo> schemas, SchemaCompiler compiler) {
int num = 1;
for (SchemaInfo schema : schemas) {
@@ -386,7 +389,7 @@
num++;
}
- if (simpleBindingEnabled && isJaxb21()) {
+ if (simpleBindingEnabled && isJaxb21(compiler)) {
String id = "/org/apache/cxf/endpoint/dynamic/simple-binding.xjb";
LOG.info("Loading the JAXB 2.1 simple binding for client.");
InputSource source = new InputSource(getClass().getResourceAsStream(id));
@@ -395,8 +398,8 @@
}
}
- private boolean isJaxb21() {
- String id = Options.getBuildID();
+ private boolean isJaxb21(SchemaCompiler sc) {
+ String id = sc.getOptions().getBuildID();
StringTokenizer st = new StringTokenizer(id, ".");
String minor = null;
@@ -537,7 +540,7 @@
}
}
- private class InnerErrorListener implements ErrorListener {
+ private class InnerErrorListener {
private String url;
@@ -605,7 +608,7 @@
- private static class ClassNameAllocatorImpl implements ClassNameAllocator {
+ public static class ClassNameAllocatorImpl {
private final Set<String> typesClassNames = new HashSet<String>();
public ClassNameAllocatorImpl() {
Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/TypeClassInitializer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/TypeClassInitializer.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/TypeClassInitializer.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/endpoint/dynamic/TypeClassInitializer.java Mon Oct 27 17:56:32 2008
@@ -19,20 +19,19 @@
package org.apache.cxf.endpoint.dynamic;
import java.lang.reflect.Array;
+import java.util.Iterator;
import java.util.logging.Logger;
import javax.xml.namespace.QName;
-import com.sun.codemodel.JDefinedClass;
-import com.sun.codemodel.JType;
-import com.sun.tools.xjc.api.Mapping;
-import com.sun.tools.xjc.api.S2JJAXBModel;
-import com.sun.tools.xjc.api.TypeAndAnnotation;
-
import org.apache.cxf.common.classloader.ClassLoaderUtils;
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.PrimitiveUtils;
+import org.apache.cxf.jaxb.JAXBUtils.JType;
+import org.apache.cxf.jaxb.JAXBUtils.Mapping;
+import org.apache.cxf.jaxb.JAXBUtils.S2JJAXBModel;
+import org.apache.cxf.jaxb.JAXBUtils.TypeAndAnnotation;
import org.apache.cxf.service.ServiceModelVisitor;
import org.apache.cxf.service.factory.ServiceConstructionException;
import org.apache.cxf.service.model.MessagePartInfo;
@@ -92,21 +91,24 @@
mapping = model.get(op.getOutput().getMessagePart(0).getElementQName());
}
if (mapping != null) {
- jType = mapping.getType().getTypeClass();
- if (jType instanceof JDefinedClass) {
- JDefinedClass jdType = (JDefinedClass)jType;
- for (JType jt : jdType.listClasses()) {
+ jType = mapping.getType().getTypeClass();
+ try {
+ Iterator<JType> i = jType.classes();
+ while (i.hasNext()) {
+ JType jt = i.next();
if (jt.name().equalsIgnoreCase(part.getElementQName().getLocalPart())) {
jType = jt;
}
}
+ } catch (Throwable t) {
+ //ignore, JType is a type that doesn't have a classes method
}
}
}
if (jType == null) {
- throw new ServiceConstructionException(new Message("NO_JAXB_CLASS", LOG, name));
+ throw new ServiceConstructionException(new Message("NO_JAXB_CLASSMapping", LOG, name));
}
Class cls;
Added: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBBeanInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBBeanInfo.java?rev=708410&view=auto
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBBeanInfo.java (added)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBBeanInfo.java Mon Oct 27 17:56:32 2008
@@ -0,0 +1,36 @@
+/**
+ * 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;
+
+import java.util.Collection;
+
+import javax.xml.namespace.QName;
+
+public interface JAXBBeanInfo {
+
+ boolean isElement();
+
+ Collection<QName> getTypeNames();
+
+ String getElementNamespaceURI(Object object);
+
+ String getElementLocalName(Object object);
+
+}
Propchange: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBBeanInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBBeanInfo.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextProxy.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextProxy.java?rev=708410&view=auto
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextProxy.java (added)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextProxy.java Mon Oct 27 17:56:32 2008
@@ -0,0 +1,29 @@
+/**
+ * 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;
+
+/**
+ *
+ */
+public interface JAXBContextProxy {
+
+ Object getBeanInfo(Class<?> cls);
+
+}
Propchange: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextProxy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextProxy.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java Mon Oct 27 17:56:32 2008
@@ -58,10 +58,6 @@
import org.w3c.dom.Document;
import org.w3c.dom.Node;
-import com.sun.xml.bind.marshaller.NamespacePrefixMapper;
-import com.sun.xml.bind.v2.ContextFactory;
-import com.sun.xml.bind.v2.runtime.JAXBContextImpl;
-
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.CacheMap;
@@ -184,27 +180,6 @@
context = ctx;
}
- public NamespacePrefixMapper getNamespacePrefixMapper() {
- Map<String, String> mappings = getDeclaredNamespaceMappings();
- if (mappings == null) {
- mappings = Collections.emptyMap();
- }
-
- final Map<String, String> closedMappings = mappings;
-
- NamespacePrefixMapper mapper = new NamespacePrefixMapper() {
- @Override
- public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
- String prefix = closedMappings.get(namespaceUri);
- if (prefix != null) {
- return prefix;
- }
- return suggestion;
- }
- };
- return mapper;
- }
-
@SuppressWarnings("unchecked")
public <T> DataWriter<T> createWriter(Class<T> c) {
@@ -344,14 +319,14 @@
r.getSystemId());
}
- JAXBContextImpl riContext;
- if (context instanceof JAXBContextImpl) {
- riContext = (JAXBContextImpl)context;
+ JAXBContext riContext;
+ if (context.getClass().getName().contains("com.sun.xml.")) {
+ riContext = context;
} else {
// fall back if we're using another jaxb implementation
try {
- riContext = (JAXBContextImpl)ContextFactory.createContext(contextClasses
- .toArray(new Class[contextClasses.size()]), null);
+ riContext = JAXBUtils.createRIContext(contextClasses
+ .toArray(new Class[contextClasses.size()]), tns);
} catch (JAXBException e) {
throw new ServiceConstructionException(e);
}
@@ -424,7 +399,55 @@
}
}
- // try and read any jaxb.index files that are with the other classes.
+ scanPackages(classes);
+ addWsAddressingTypes(classes);
+
+ for (Class<?> clz : classes) {
+ if (clz.getName().endsWith("ObjectFactory")
+ && checkObjectFactoryNamespaces(clz)) {
+ // kind of a hack, but ObjectFactories may be created with empty
+ // namespaces
+ defaultNs = null;
+ }
+ }
+
+ Map<String, Object> map = new HashMap<String, Object>();
+ if (defaultNs != null) {
+ map.put("com.sun.xml.bind.defaultNamespaceRemap", defaultNs);
+ }
+
+ if (contextProperties != null) {
+ // add any specified context properties into the properties map
+ map.putAll(contextProperties);
+ }
+
+ CachedContextAndSchemas cachedContextAndSchemas = null;
+ synchronized (JAXBCONTEXT_CACHE) {
+ cachedContextAndSchemas = JAXBCONTEXT_CACHE.get(classes);
+ }
+ if (cachedContextAndSchemas == null) {
+ JAXBContext ctx;
+ try {
+ ctx = JAXBContext.newInstance(classes.toArray(new Class[classes.size()]), map);
+ } catch (JAXBException ex) {
+ if (map.containsKey("com.sun.xml.bind.defaultNamespaceRemap")) {
+ map.put("com.sun.xml.internal.bind.defaultNamespaceRemap",
+ map.remove("com.sun.xml.bind.defaultNamespaceRemap"));
+ ctx = JAXBContext.newInstance(classes.toArray(new Class[classes.size()]), map);
+ } else {
+ throw ex;
+ }
+ }
+ cachedContextAndSchemas = new CachedContextAndSchemas(ctx);
+ synchronized (JAXBCONTEXT_CACHE) {
+ JAXBCONTEXT_CACHE.put(classes, cachedContextAndSchemas);
+ }
+ }
+
+ return cachedContextAndSchemas;
+ }
+ private void scanPackages(Set<Class<?>> classes) {
+ // try and read any jaxb.index files that are with the other classes.
// This should
// allow loading of extra classes (such as subclasses for inheritance
// reasons)
@@ -503,40 +526,6 @@
}
}
classes.addAll(objectFactories);
- addWsAddressingTypes(classes);
-
- for (Class<?> clz : classes) {
- if (clz.getName().endsWith("ObjectFactory")
- && checkObjectFactoryNamespaces(clz)) {
- // kind of a hack, but ObjectFactories may be created with empty
- // namespaces
- defaultNs = null;
- }
- }
-
- Map<String, Object> map = new HashMap<String, Object>();
- if (defaultNs != null) {
- map.put("com.sun.xml.bind.defaultNamespaceRemap", defaultNs);
- }
-
- if (contextProperties != null) {
- // add any specified context properties into the properties map
- map.putAll(contextProperties);
- }
-
- CachedContextAndSchemas cachedContextAndSchemas = null;
- synchronized (JAXBCONTEXT_CACHE) {
- cachedContextAndSchemas = JAXBCONTEXT_CACHE.get(classes);
- }
- if (cachedContextAndSchemas == null) {
- JAXBContext ctx = JAXBContext.newInstance(classes.toArray(new Class[classes.size()]), map);
- cachedContextAndSchemas = new CachedContextAndSchemas(ctx);
- synchronized (JAXBCONTEXT_CACHE) {
- JAXBCONTEXT_CACHE.put(classes, cachedContextAndSchemas);
- }
- }
-
- return cachedContextAndSchemas;
}
private boolean checkObjectFactoryNamespaces(Class<?> clz) {
Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBEncoderDecoder.java Mon Oct 27 17:56:32 2008
@@ -21,6 +21,7 @@
import java.io.InputStream;
import java.io.OutputStream;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
@@ -58,10 +59,6 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import com.sun.xml.bind.api.Bridge;
-import com.sun.xml.bind.api.JAXBRIContext;
-import com.sun.xml.bind.api.TypeReference;
-
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.helpers.CastUtils;
@@ -180,22 +177,17 @@
}
}
//TODO: cache the JAXBRIContext
- @SuppressWarnings("unchecked")
- public static void marshalWithBridge(TypeReference ref,
+ public static void marshalWithBridge(QName qname,
+ Class<?> cls,
+ Annotation anns[],
Set<Class<?>> ctxClasses,
Object elValue,
Object source, AttachmentMarshaller am) {
- List<TypeReference> typeRefs = new ArrayList<TypeReference>();
- typeRefs.add(ref);
- List<Class<?>> clses = new ArrayList<Class<?>>(ctxClasses);
- clses.add(ref.type.getClass());
try {
- JAXBRIContext riContext = JAXBRIContext.newInstance(clses.toArray(new Class[clses.size()]),
- typeRefs, null, null, true, null);
- Bridge bridge = riContext.createBridge(ref);
+ JAXBUtils.BridgeWrapper bridge = JAXBUtils.createBridge(ctxClasses, qname, cls, anns);
if (source instanceof XMLStreamWriter) {
- bridge.marshal(elValue, (XMLStreamWriter)source);
+ bridge.marshal(elValue, (XMLStreamWriter)source, am);
} else if (source instanceof OutputStream) {
//the namespace is missing when marshal the xsd:QName type
//to the OutputStream directly
@@ -204,7 +196,7 @@
bridge.marshal(elValue, s1);
((OutputStream)source).write(sw.toString().getBytes());
} else if (source instanceof Node) {
- bridge.marshal(elValue, (Node)source);
+ bridge.marshal(elValue, (Node)source, am);
} else {
throw new Fault(new Message("UNKNOWN_SOURCE", LOG, source.getClass().getName()));
}
@@ -223,22 +215,19 @@
}
// TODO: cache the JAXBRIContext
- public static Object unmarshalWithBridge(TypeReference ref,
+ public static Object unmarshalWithBridge(QName qname,
+ Class<?> cls,
+ Annotation anns[],
Set<Class<?>> ctxClasses,
Object source,
AttachmentUnmarshaller am) {
- List<TypeReference> typeRefs = new ArrayList<TypeReference>();
- typeRefs.add(ref);
- List<Class<?>> clses = new ArrayList<Class<?>>(ctxClasses);
- clses.add(ref.type.getClass());
+
try {
- JAXBRIContext riContext = JAXBRIContext.newInstance(clses.toArray(new Class[clses.size()]),
- typeRefs, null, null, true, null);
- Bridge bridge = riContext.createBridge(ref);
+ JAXBUtils.BridgeWrapper bridge = JAXBUtils.createBridge(ctxClasses, qname, cls, anns);
if (source instanceof XMLStreamReader) {
//DOMUtils.writeXml(StaxUtils.read((XMLStreamReader)source), System.out);
- return bridge.unmarshal((XMLStreamReader)source);
+ return bridge.unmarshal((XMLStreamReader)source, am);
} else if (source instanceof InputStream) {
return bridge.unmarshal((InputStream)source);
} else if (source instanceof Node) {
Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBSchemaInitializer.java Mon Oct 27 17:56:32 2008
@@ -27,17 +27,16 @@
import java.util.Iterator;
import java.util.logging.Logger;
+import javax.xml.bind.JAXBContext;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.namespace.QName;
-import com.sun.xml.bind.v2.runtime.JAXBContextImpl;
-import com.sun.xml.bind.v2.runtime.JaxBeanInfo;
-
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.ReflectionInvokationHandler;
import org.apache.cxf.common.xmlschema.SchemaCollection;
import org.apache.cxf.common.xmlschema.XmlSchemaTools;
import org.apache.cxf.interceptor.Fault;
@@ -62,19 +61,29 @@
private static final Logger LOG = LogUtils.getLogger(JAXBSchemaInitializer.class);
private SchemaCollection schemas;
- private JAXBContextImpl context;
+ private JAXBContextProxy context;
private final boolean qualifiedSchemas;
public JAXBSchemaInitializer(ServiceInfo serviceInfo,
SchemaCollection col,
- JAXBContextImpl context,
+ JAXBContext context,
boolean q) {
super(serviceInfo);
schemas = col;
- this.context = context;
+ this.context = ReflectionInvokationHandler.createProxyWrapper(context, JAXBContextProxy.class);
this.qualifiedSchemas = q;
}
+ public JAXBBeanInfo getBeanInfo(Class<?> cls) {
+ return getBeanInfo(context, cls);
+ }
+ public static JAXBBeanInfo getBeanInfo(JAXBContextProxy context, Class<?> cls) {
+ Object o = context.getBeanInfo(cls);
+ if (o == null) {
+ return null;
+ }
+ return ReflectionInvokationHandler.createProxyWrapper(o, JAXBBeanInfo.class);
+ }
@Override
public void begin(MessagePartInfo part) {
// Check to see if the WSDL information has been filled in for us.
@@ -93,7 +102,7 @@
clazz = clazz.getComponentType();
}
- JaxBeanInfo<?> beanInfo = context.getBeanInfo(clazz);
+ JAXBBeanInfo beanInfo = getBeanInfo(clazz);
if (beanInfo == null) {
Annotation[] anns = (Annotation[])part.getProperty("parameter.annotations");
XmlJavaTypeAdapter jta = findFromTypeAdapter(clazz, anns);
@@ -159,7 +168,7 @@
}
private XmlJavaTypeAdapter findFromTypeAdapter(Class<?> clazz, Annotation[] anns) {
- JaxBeanInfo<?> ret = null;
+ JAXBBeanInfo ret = null;
if (anns != null) {
for (Annotation a : anns) {
if (XmlJavaTypeAdapter.class.isAssignableFrom(a.annotationType())) {
@@ -180,7 +189,7 @@
return null;
}
- private JaxBeanInfo<?> findFromTypeAdapter(Class<? extends XmlAdapter> aclass) {
+ private JAXBBeanInfo findFromTypeAdapter(Class<? extends XmlAdapter> aclass) {
Class<?> c2 = aclass;
Type sp = c2.getGenericSuperclass();
while (!XmlAdapter.class.equals(c2) && c2 != null) {
@@ -190,13 +199,13 @@
if (sp instanceof ParameterizedType) {
Type tp = ((ParameterizedType)sp).getActualTypeArguments()[0];
if (tp instanceof Class) {
- return context.getBeanInfo((Class<?>)tp);
+ return getBeanInfo((Class<?>)tp);
}
}
return null;
}
- private QName getTypeName(JaxBeanInfo<?> beanInfo) {
+ private QName getTypeName(JAXBBeanInfo beanInfo) {
Iterator<QName> itr = beanInfo.getTypeNames().iterator();
if (!itr.hasNext()) {
return null;
@@ -218,7 +227,7 @@
if (isFromWrapper && clazz.isArray() && !Byte.TYPE.equals(clazz.getComponentType())) {
clazz = clazz.getComponentType();
}
- JaxBeanInfo<?> beanInfo = context.getBeanInfo(clazz);
+ JAXBBeanInfo beanInfo = getBeanInfo(clazz);
if (beanInfo == null) {
if (Exception.class.isAssignableFrom(clazz)) {
QName name = (QName)part.getMessageInfo().getProperty("elementName");
@@ -290,7 +299,7 @@
if (cls != cl2) {
QName name = (QName)fault.getProperty("elementName");
part.setElementQName(name);
- JaxBeanInfo<?> beanInfo = context.getBeanInfo(cls);
+ JAXBBeanInfo beanInfo = getBeanInfo(cls);
if (beanInfo == null) {
throw new Fault(new Message("NO_BEAN_INFO", LOG, cls.getName()));
}
@@ -353,7 +362,7 @@
m.getDeclaringClass().getMethod("set" + m.getName().substring(beginIdx),
m.getReturnType());
- JaxBeanInfo<?> beanInfo = context.getBeanInfo(m.getReturnType());
+ JAXBBeanInfo beanInfo = getBeanInfo(m.getReturnType());
if (beanInfo != null) {
el = new XmlSchemaElement();
el.setName(m.getName().substring(beginIdx));
@@ -443,7 +452,7 @@
for (Field f : cls.getDeclaredFields()) {
if (JAXBContextInitializer.isFieldAccepted(f, accessType)) {
//map field
- JaxBeanInfo<?> beanInfo = context.getBeanInfo(f.getType());
+ JAXBBeanInfo beanInfo = getBeanInfo(f.getType());
if (beanInfo != null) {
addElement(seq, beanInfo, new QName(namespace, f.getName()));
}
@@ -452,7 +461,7 @@
for (Method m : cls.getMethods()) {
if (JAXBContextInitializer.isMethodAccepted(m, accessType)) {
//map field
- JaxBeanInfo<?> beanInfo = context.getBeanInfo(m.getReturnType());
+ JAXBBeanInfo beanInfo = getBeanInfo(m.getReturnType());
if (beanInfo != null) {
int idx = m.getName().startsWith("get") ? 3 : 2;
String name = m.getName().substring(idx);
@@ -464,7 +473,7 @@
part.setProperty(JAXBDataBinding.class.getName() + ".CUSTOM_EXCEPTION", Boolean.TRUE);
}
- public void addElement(XmlSchemaSequence seq, JaxBeanInfo<?> beanInfo, QName name) {
+ public void addElement(XmlSchemaSequence seq, JAXBBeanInfo beanInfo, QName name) {
XmlSchemaElement el = new XmlSchemaElement();
el.setName(name.getLocalPart());
XmlSchemaTools.setElementQName(el, name);
Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataReaderImpl.java Mon Oct 27 17:56:32 2008
@@ -29,8 +29,6 @@
import javax.xml.bind.Unmarshaller;
import javax.xml.namespace.QName;
-import com.sun.xml.bind.api.TypeReference;
-
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.databinding.DataReader;
@@ -98,8 +96,10 @@
//annotated with @XmlList,@XmlAttachmentRef,@XmlJavaTypeAdapter
//TODO:Cache the JAXBRIContext
QName qname = new QName(null, part.getConcreteName().getLocalPart());
- TypeReference typeReference = new TypeReference(qname, part.getTypeClass(), anns);
- return JAXBEncoderDecoder.unmarshalWithBridge(typeReference,
+
+ return JAXBEncoderDecoder.unmarshalWithBridge(qname,
+ part.getTypeClass(),
+ anns,
databinding.getContextClasses(),
reader,
getAttachmentUnmarshaller());
Modified: cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/io/DataWriterImpl.java Mon Oct 27 17:56:32 2008
@@ -19,6 +19,7 @@
package org.apache.cxf.jaxb.io;
+
import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.util.Collection;
@@ -34,8 +35,6 @@
import javax.xml.bind.attachment.AttachmentMarshaller;
import javax.xml.namespace.QName;
-import com.sun.xml.bind.api.TypeReference;
-
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.databinding.DataWriter;
@@ -43,6 +42,7 @@
import org.apache.cxf.jaxb.JAXBDataBase;
import org.apache.cxf.jaxb.JAXBDataBinding;
import org.apache.cxf.jaxb.JAXBEncoderDecoder;
+import org.apache.cxf.jaxb.JAXBUtils;
import org.apache.cxf.jaxb.attachment.JAXBAttachmentMarshaller;
import org.apache.cxf.service.model.MessagePartInfo;
import org.apache.ws.commons.schema.XmlSchemaElement;
@@ -107,8 +107,11 @@
if (databinding.getValidationEventHandler() != null) {
marshaller.setEventHandler(databinding.getValidationEventHandler());
}
- marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper",
- databinding.getNamespacePrefixMapper());
+
+ final Map<String, String> nspref = databinding.getDeclaredNamespaceMappings();
+ if (nspref != null) {
+ JAXBUtils.setNamespaceWrapper(nspref, marshaller);
+ }
if (databinding.getMarshallerProperties() != null) {
for (Map.Entry<String, Object> propEntry
: databinding.getMarshallerProperties().entrySet()) {
@@ -169,9 +172,10 @@
//annotated with @XmlList,@XmlAttachmentRef,@XmlJavaTypeAdapter
//TODO:Cache the JAXBRIContext
QName qname = new QName(null, part.getConcreteName().getLocalPart());
- TypeReference typeReference = new TypeReference(qname, part.getTypeClass(), anns);
- JAXBEncoderDecoder.marshalWithBridge(typeReference,
+ JAXBEncoderDecoder.marshalWithBridge(qname,
+ part.getTypeClass(),
+ anns,
databinding.getContextClasses(),
obj,
output,
Modified: cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java Mon Oct 27 17:56:32 2008
@@ -43,12 +43,10 @@
import org.w3c.dom.Node;
-import com.sun.xml.bind.api.JAXBRIContext;
-import com.sun.xml.bind.v2.runtime.JAXBContextImpl;
-
import org.apache.cxf.Bus;
import org.apache.cxf.binding.BindingFactoryManager;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.ReflectionInvokationHandler;
import org.apache.cxf.databinding.DataReader;
import org.apache.cxf.databinding.DataWriter;
import org.apache.cxf.helpers.CastUtils;
@@ -183,17 +181,15 @@
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(ObjectFactory.class);
JAXBContext ctx = db.createJAXBContext(classes);
- if (ctx instanceof JAXBContextImpl) {
- JAXBContextImpl rictx = (JAXBContextImpl)ctx;
- assertNotNull(rictx.getBeanInfo(TestJAXBClass.class));
- }
+ JAXBContextProxy ctxp = ReflectionInvokationHandler.createProxyWrapper(ctx, JAXBContextProxy.class);
+ assertNotNull(JAXBSchemaInitializer.getBeanInfo(ctxp, TestJAXBClass.class));
}
@Test
public void testContextProperties() throws Exception {
JAXBDataBinding db = new JAXBDataBinding();
Map<String, Object> contextProperties = new HashMap<String, Object>();
- contextProperties.put(JAXBRIContext.DEFAULT_NAMESPACE_REMAP, "uri:ultima:thule");
+ contextProperties.put("com.sun.xml.bind.defaultNamespaceRemap", "uri:ultima:thule");
db.setContextProperties(contextProperties);
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(UnqualifiedBean.class);
@@ -217,7 +213,7 @@
nsMap.put("uri:ultima:thule", "greenland");
db.setNamespaceMap(nsMap);
Map<String, Object> contextProperties = new HashMap<String, Object>();
- contextProperties.put(JAXBRIContext.DEFAULT_NAMESPACE_REMAP, "uri:ultima:thule");
+ contextProperties.put("com.sun.xml.bind.defaultNamespaceRemap", "uri:ultima:thule");
db.setContextProperties(contextProperties);
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(QualifiedBean.class);
Modified: cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java (original)
+++ cxf/trunk/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBEncoderDecoderTest.java Mon Oct 27 17:56:32 2008
@@ -25,6 +25,8 @@
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
@@ -46,8 +48,6 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-import com.sun.xml.bind.marshaller.NamespacePrefixMapper;
-
import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.jaxb_form.ObjectWithQualifiedElementElement;
@@ -182,18 +182,9 @@
@Test
public void testCustomNamespaces() throws Exception {
- NamespacePrefixMapper mapper = new NamespacePrefixMapper() {
-
- @Override
- public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
- if ("http://apache.org/hello_world_soap_http/types".equals(namespaceUri)) {
- return "Omnia";
- } else if ("http://cxf.apache.org/jaxb_form".equals(namespaceUri)) {
- return "Gallia";
- }
- return suggestion;
- }
- };
+ Map<String, String> mapper = new HashMap<String, String>();
+ mapper.put("http://apache.org/hello_world_soap_http/types", "Omnia");
+ mapper.put("http://cxf.apache.org/jaxb_form", "Gallia");
ObjectWithQualifiedElementElement testObject = new ObjectWithQualifiedElementElement();
testObject.setString1("twine");
testObject.setString2("cord");
@@ -209,8 +200,7 @@
opFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
XMLEventWriter writer = opFactory.createXMLEventWriter(stringWriter);
Marshaller m = context.createMarshaller();
- m.setProperty("com.sun.xml.bind.namespacePrefixMapper", mapper);
-
+ JAXBUtils.setNamespaceWrapper(mapper, m);
JAXBEncoderDecoder.marshall(m, testObject, part, writer);
writer.flush();
writer.close();
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java Mon Oct 27 17:56:32 2008
@@ -92,7 +92,6 @@
return PF;
}
- @SuppressWarnings("unchecked")
public <T> ContextResolver<T> createContextResolver(Type contextType,
Message m) {
// TODO : get media type from message
Modified: cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java (original)
+++ cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/SwAOutInterceptor.java Mon Oct 27 17:56:32 2008
@@ -30,7 +30,9 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import javax.activation.DataHandler;
@@ -46,9 +48,6 @@
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
-import com.sun.xml.bind.v2.runtime.JAXBContextImpl;
-import com.sun.xml.bind.v2.util.DataSourceSource;
-
import org.apache.cxf.attachment.AttachmentImpl;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
@@ -72,18 +71,8 @@
public class SwAOutInterceptor extends AbstractSoapInterceptor {
private static final Logger LOG = LogUtils.getL7dLogger(SwAOutInterceptor.class);
- private static final boolean HAS_SWA_REF_METHOD;
- static {
- Class<?> cls = JAXBContextImpl.class;
- Method m = null;
- try {
- m = cls.getMethod("hasSwaRef", new Class[0]);
- } catch (Exception e) {
- //ignore
- }
- HAS_SWA_REF_METHOD = m != null;
- }
+ private static final Map<String, Method> SWA_REF_METHOD = new ConcurrentHashMap<String, Method>();
AttachmentOutInterceptor attachOut = new AttachmentOutInterceptor();
@@ -92,6 +81,23 @@
addAfter(HolderOutInterceptor.class.getName());
addBefore(WrapperClassOutInterceptor.class.getName());
}
+
+ private boolean callSWARefMethod(JAXBContext ctx) {
+ Method m = SWA_REF_METHOD.get(ctx.getClass().getName());
+ if (m == null && !SWA_REF_METHOD.containsKey(ctx.getClass().getName())) {
+ try {
+ m = ctx.getClass().getMethod("hasSwaRef", new Class[0]);
+ } catch (Exception e) {
+ //ignore
+ }
+ SWA_REF_METHOD.put(ctx.getClass().getName(), m);
+ }
+ try {
+ return (Boolean)m.invoke(ctx);
+ } catch (Exception e) {
+ return false;
+ }
+ }
public void handleMessage(SoapMessage message) throws Fault {
Exchange ex = message.getExchange();
@@ -206,20 +212,13 @@
}
private boolean hasSwaRef(JAXBDataBinding db) {
JAXBContext context = db.getContext();
- if (HAS_SWA_REF_METHOD
- && context instanceof JAXBContextImpl) {
- return ((JAXBContextImpl)context).hasSwaRef();
- }
-
- return false;
+ return callSWARefMethod(context);
}
private DataSource createDataSource(Source o, String ct) {
DataSource ds = null;
- if (o instanceof DataSourceSource) {
- ds = (DataSource) o;
- } else if (o instanceof StreamSource) {
+ if (o instanceof StreamSource) {
StreamSource src = (StreamSource)o;
try {
if (src.getInputStream() != null) {
Modified: cxf/trunk/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xsd
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xsd?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xsd (original)
+++ cxf/trunk/rt/transports/http/src/main/resources/schemas/wsdl/http-conf.xsd Mon Oct 27 17:56:32 2008
@@ -57,7 +57,7 @@
<xs:documentation>
When set to false, exceptions will be thrown when an error is encountered
receiving a request from the client. When set to true these errors will
- be suppressed.
+ be suppressed. The default is false.
</xs:documentation>
</xs:annotation>
</xs:attribute>
@@ -67,7 +67,7 @@
<xs:documentation>
When set to false, exceptions will be thrown when an error is encountered
sending a reply from to client. When set to true these errors will be
- suppressed.
+ suppressed. The default is false.
</xs:documentation>
</xs:annotation>
</xs:attribute>
@@ -81,7 +81,7 @@
after each reply is sent, even if the client requests the server to keep
the connection alive. Keep-Alive improves performance for the client
requesting such behavior, but can limit overall scalability of the server
- for handling many clients.
+ for handling many clients. The Default is true.
</xs:documentation>
</xs:annotation>
</xs:attribute>
@@ -100,7 +100,7 @@
<xs:annotation>
<xs:documentation>
Most commonly used to specify no-cache, however the standard supports a
- dozen or so caching related directives for responses
+ dozen or so caching related directives for responses.
</xs:documentation>
</xs:annotation>
Modified: cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIConduitTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIConduitTest.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIConduitTest.java (original)
+++ cxf/trunk/rt/transports/jbi/src/test/java/org/apache/cxf/transport/jbi/JBIConduitTest.java Mon Oct 27 17:56:32 2008
@@ -23,7 +23,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.util.logging.Logger;
@@ -68,13 +67,10 @@
LOG.info("test send");
JBIConduit conduit = setupJBIConduit(true, false);
Message message = new MessageImpl();
- Member method = control.createMock(Member.class);
- message.put(Method.class.getName(), method);
-
- EasyMock.expect(method.getDeclaringClass()).andStubReturn(
- (Class<?>)org.apache.hello_world_soap_http.Greeter.class);
-
-
+
+ Class<org.apache.hello_world_soap_http.Greeter> greeterCls
+ = org.apache.hello_world_soap_http.Greeter.class;
+ message.put(Method.class.getName(), greeterCls.getMethod("sayHi"));
Exchange exchange = new ExchangeImpl();
exchange.setOneWay(false);
Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxws/ClientServerTest.java Mon Oct 27 17:56:32 2008
@@ -51,8 +51,6 @@
import org.w3c.dom.Document;
import org.w3c.dom.Node;
-import com.sun.xml.bind.api.JAXBRIContext;
-
import org.apache.cxf.Bus;
import org.apache.cxf.binding.soap.Soap11;
import org.apache.cxf.bus.CXFBusFactory;
@@ -891,7 +889,7 @@
// that would actually notice the difference. At least it ensures that
// specifying the property does not explode.
Map<String, Object> jaxbContextProperties = new HashMap<String, Object>();
- jaxbContextProperties.put(JAXBRIContext.DEFAULT_NAMESPACE_REMAP, "uri:ultima:thule");
+ jaxbContextProperties.put("com.sun.xml.bind.defaultNamespaceRemap", "uri:ultima:thule");
dcf.setJaxbContextProperties(jaxbContextProperties);
client = dcf.createClient(wsdlUrl, serviceName, portName);
client.invoke("greetMe", "test");
Modified: cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java (original)
+++ cxf/trunk/tools/wsdlto/databinding/jaxb/src/main/java/org/apache/cxf/tools/wsdlto/databinding/jaxb/JAXBDataBinding.java Mon Oct 27 17:56:32 2008
@@ -62,9 +62,9 @@
import com.sun.tools.xjc.api.Mapping;
import com.sun.tools.xjc.api.Property;
import com.sun.tools.xjc.api.S2JJAXBModel;
+import com.sun.tools.xjc.api.SchemaCompiler;
import com.sun.tools.xjc.api.TypeAndAnnotation;
import com.sun.tools.xjc.api.XJC;
-import com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl;
import org.apache.cxf.common.i18n.Message;
@@ -128,7 +128,7 @@
public void initialize(ToolContext c) throws ToolException {
this.context = c;
- SchemaCompilerImpl schemaCompiler = (SchemaCompilerImpl)XJC.createSchemaCompiler();
+ SchemaCompiler schemaCompiler = XJC.createSchemaCompiler();
ClassCollector classCollector = context.get(ClassCollector.class);
ClassNameAllocatorImpl allocator
@@ -237,7 +237,7 @@
initialized = true;
}
- private void addSchemas(Options opts, SchemaCompilerImpl schemaCompiler,
+ private void addSchemas(Options opts, SchemaCompiler schemaCompiler,
Map<String, Element> schemaLists) {
for (String key : schemaLists.keySet()) {
Element ele = schemaLists.get(key);
@@ -268,7 +268,7 @@
// TODO this can be repaced with schemaCompiler.getOptions() once we
// move to a version => 2.0.3 for jaxb-xjc
- private Options getOptions(SchemaCompilerImpl schemaCompiler) throws ToolException {
+ private Options getOptions(SchemaCompiler schemaCompiler) throws ToolException {
try {
Field delegateField = schemaCompiler.getClass().getDeclaredField("opts");
delegateField.setAccessible(true);
Modified: cxf/trunk/tools/wsdlto/misc/src/main/java/org/apache/cxf/tools/misc/processor/AbstractWSDLToProcessor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wsdlto/misc/src/main/java/org/apache/cxf/tools/misc/processor/AbstractWSDLToProcessor.java?rev=708410&r1=708409&r2=708410&view=diff
==============================================================================
--- cxf/trunk/tools/wsdlto/misc/src/main/java/org/apache/cxf/tools/misc/processor/AbstractWSDLToProcessor.java (original)
+++ cxf/trunk/tools/wsdlto/misc/src/main/java/org/apache/cxf/tools/misc/processor/AbstractWSDLToProcessor.java Mon Oct 27 17:56:32 2008
@@ -45,7 +45,7 @@
import org.apache.cxf.wsdl.WSDLManager;
import org.apache.cxf.wsdl11.WSDLDefinitionBuilder;
-public class AbstractWSDLToProcessor implements Processor, com.sun.tools.xjc.api.ErrorListener {
+public class AbstractWSDLToProcessor implements Processor {
protected static final Logger LOG = LogUtils.getL7dLogger(AbstractWSDLToProcessor.class);
protected static final String WSDL_FILE_NAME_EXT = ".wsdl";