You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ga...@apache.org on 2008/06/17 05:35:50 UTC
svn commit: r668384 - in /webservices/axis2/trunk/java/modules:
jaxws-integration/test/org/apache/axis2/jaxws/type_substitution/tests/
jaxws/src/org/apache/axis2/datasource/jaxb/
jaxws/src/org/apache/axis2/jaxws/marshaller/factory/ jaxws/src/org/apache...
Author: gawor
Date: Mon Jun 16 20:35:50 2008
New Revision: 668384
URL: http://svn.apache.org/viewvc?rev=668384&view=rev
Log:
set default namespace property on JAXBContext (AXIS2-3854)
Modified:
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/type_substitution/tests/TypeSubstitutionTests.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/factory/MethodMarshallerFactory.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedMethodMarshaller.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedPlusMethodMarshaller.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBContextFromClasses.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/type_substitution/tests/TypeSubstitutionTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/type_substitution/tests/TypeSubstitutionTests.java?rev=668384&r1=668383&r2=668384&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/type_substitution/tests/TypeSubstitutionTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/type_substitution/tests/TypeSubstitutionTests.java Mon Jun 16 20:35:50 2008
@@ -70,9 +70,8 @@
TestLogger.logger.debug(">> Response [" + body + "]");
- // XXX: the xsi:type attribute values should have namespace apparently
- QName expectedXsiType1 = new QName(/*NS,*/ "fuji");
- QName expectedXsiType2 = new QName(/*NS,*/ "freyburg");
+ QName expectedXsiType1 = new QName(NS, "fuji");
+ QName expectedXsiType2 = new QName(NS, "freyburg");
Iterator iter;
SOAPElement element;
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java?rev=668384&r1=668383&r2=668384&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java Mon Jun 16 20:35:50 2008
@@ -50,6 +50,8 @@
import java.lang.reflect.Method;
import java.security.PrivilegedAction;
import java.text.ParseException;
+import java.util.HashMap;
+import java.util.Map;
import java.util.TreeSet;
/*
@@ -84,6 +86,7 @@
// Please don't use "by java type" processing to get around errors.
private Class processType = null;
private boolean isxmlList =false;
+ private String defaultNamespace;
/**
* Full Constructor JAXBDSContext (most performant)
@@ -158,8 +161,13 @@
}
Holder<JAXBUtils.CONSTRUCTION_TYPE> constructType =
new Holder<JAXBUtils.CONSTRUCTION_TYPE>();
+ Map<String, Object> properties = null;
+ if (this.defaultNamespace != null) {
+ properties = new HashMap<String, Object>();
+ properties.put("com.sun.xml.bind.defaultNamespaceRemap", this.defaultNamespace);
+ }
jc =
- JAXBUtils.getJAXBContext(contextPackages, constructType, contextPackagesKey, cl);
+ JAXBUtils.getJAXBContext(contextPackages, constructType, contextPackagesKey, cl, properties);
constructionType = constructType.value;
autoJAXBContext = new WeakReference<JAXBContext>(jc);
} else {
@@ -170,6 +178,14 @@
return jc;
}
+ public void setDefaultNamespace(String namespace) {
+ this.defaultNamespace = namespace;
+ }
+
+ public String getDefaultNamespace() {
+ return this.defaultNamespace;
+ }
+
/** @return RPC Declared Type */
public Class getProcessType() {
return processType;
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/factory/MethodMarshallerFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/factory/MethodMarshallerFactory.java?rev=668384&r1=668383&r2=668384&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/factory/MethodMarshallerFactory.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/factory/MethodMarshallerFactory.java Mon Jun 16 20:35:50 2008
@@ -209,7 +209,7 @@
Holder<JAXBUtils.CONSTRUCTION_TYPE> holder = new Holder<JAXBUtils.CONSTRUCTION_TYPE>();
try {
JAXBContext context = JAXBUtils.getJAXBContext(marshalDesc.getPackages(), holder,
- marshalDesc.getPackagesKey(), cl);
+ marshalDesc.getPackagesKey(), cl, null);
} catch (JAXBException e) {
throw ExceptionFactory.makeWebServiceException(e);
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedMethodMarshaller.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedMethodMarshaller.java?rev=668384&r1=668383&r2=668384&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedMethodMarshaller.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedMethodMarshaller.java Mon Jun 16 20:35:50 2008
@@ -108,6 +108,7 @@
// In usage=WRAPPED, there will be a single JAXB block inside the body.
// Get this block
JAXBBlockContext blockContext = new JAXBBlockContext(packages, packagesKey);
+ blockContext.setDefaultNamespace(ed.getTargetNamespace());
JAXBBlockFactory factory =
(JAXBBlockFactory)FactoryRegistry.getFactory(JAXBBlockFactory.class);
Block block = message.getBodyBlock(blockContext, factory);
@@ -226,6 +227,7 @@
// In usage=WRAPPED, there will be a single JAXB block inside the body.
// Get this block
JAXBBlockContext blockContext = new JAXBBlockContext(packages, packagesKey);
+ blockContext.setDefaultNamespace(ed.getTargetNamespace());
JAXBBlockFactory factory =
(JAXBBlockFactory)FactoryRegistry.getFactory(JAXBBlockFactory.class);
Block block = message.getBodyBlock(blockContext, factory);
@@ -389,9 +391,10 @@
// Put the object into the message
JAXBBlockFactory factory =
(JAXBBlockFactory)FactoryRegistry.getFactory(JAXBBlockFactory.class);
-
+ JAXBBlockContext blockContext = new JAXBBlockContext(packages, packagesKey);
+ blockContext.setDefaultNamespace(ed.getTargetNamespace());
Block block = factory.createFrom(object,
- new JAXBBlockContext(packages, packagesKey),
+ blockContext,
wrapperQName);
m.setBodyBlock(block);
@@ -489,9 +492,10 @@
// Put the object into the message
JAXBBlockFactory factory =
(JAXBBlockFactory)FactoryRegistry.getFactory(JAXBBlockFactory.class);
-
+ JAXBBlockContext blockContext = new JAXBBlockContext(packages, packagesKey);
+ blockContext.setDefaultNamespace(ed.getTargetNamespace());
Block block = factory.createFrom(object,
- new JAXBBlockContext(packages, packagesKey),
+ blockContext,
wrapperQName);
m.setBodyBlock(block);
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedPlusMethodMarshaller.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedPlusMethodMarshaller.java?rev=668384&r1=668383&r2=668384&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedPlusMethodMarshaller.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedPlusMethodMarshaller.java Mon Jun 16 20:35:50 2008
@@ -149,6 +149,7 @@
// In usage=WRAPPED, there will be a single JAXB block inside the body.
// Get this block
JAXBBlockContext blockContext = new JAXBBlockContext(packages, packagesKey);
+ blockContext.setDefaultNamespace(ed.getTargetNamespace());
JAXBBlockFactory factory =
(JAXBBlockFactory)FactoryRegistry.getFactory(JAXBBlockFactory.class);
Block block = message.getBodyBlock(blockContext, factory);
@@ -310,7 +311,8 @@
// In usage=WRAPPED, there will be a single JAXB block inside the body.
// Get this block
- JAXBBlockContext blockContext = new JAXBBlockContext(packages, packagesKey);
+ JAXBBlockContext blockContext = new JAXBBlockContext(packages, packagesKey);
+ blockContext.setDefaultNamespace(ed.getTargetNamespace());
JAXBBlockFactory factory =
(JAXBBlockFactory)FactoryRegistry.getFactory(JAXBBlockFactory.class);
Block block = message.getBodyBlock(blockContext, factory);
@@ -545,9 +547,10 @@
// Put the object into the message
JAXBBlockFactory factory =
(JAXBBlockFactory)FactoryRegistry.getFactory(JAXBBlockFactory.class);
-
+ JAXBBlockContext blockContext = new JAXBBlockContext(packages, packagesKey);
+ blockContext.setDefaultNamespace(ed.getTargetNamespace());
Block block = factory.createFrom(object,
- new JAXBBlockContext(packages, packagesKey),
+ blockContext,
wrapperQName); // The factory will get the qname from the value
m.setBodyBlock(block);
@@ -673,8 +676,10 @@
// Put the object into the message
JAXBBlockFactory factory =
(JAXBBlockFactory)FactoryRegistry.getFactory(JAXBBlockFactory.class);
+ JAXBBlockContext blockContext = new JAXBBlockContext(packages, packagesKey);
+ blockContext.setDefaultNamespace(ed.getTargetNamespace());
Block block = factory.createFrom(object,
- new JAXBBlockContext(packages, packagesKey),
+ blockContext,
wrapperQName); // The factory will get the qname from the value
m.setBodyBlock(block);
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBContextFromClasses.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBContextFromClasses.java?rev=668384&r1=668383&r2=668384&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBContextFromClasses.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBContextFromClasses.java Mon Jun 16 20:35:50 2008
@@ -39,6 +39,7 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
+import java.util.Map;
/**
* This class provides a utility method, newInstance, which
@@ -69,7 +70,8 @@
* @throws JAXBException
*/
public static JAXBContext newInstance(Class[] classArray,
- ClassLoader cl)
+ ClassLoader cl,
+ Map<String, ?> properties)
throws JAXBException {
JAXBContext jaxbContext = null;
try {
@@ -81,7 +83,7 @@
" input classes.");
}
}
- jaxbContext = _newInstance(classArray, cl);
+ jaxbContext = _newInstance(classArray, cl, properties);
} catch (Throwable t) {
// Try finding the best set of classes
ArrayList<Class> original = new ArrayList<Class>();
@@ -89,7 +91,7 @@
original.add(classArray[i]);
}
ArrayList<Class> best = new ArrayList<Class>();
- jaxbContext = findBestSet(original, cl, best);
+ jaxbContext = findBestSet(original, cl, best, properties);
}
@@ -106,7 +108,8 @@
* @throws Throwable
*/
private static JAXBContext _newInstance(final Class[] classArray,
- final ClassLoader cl)
+ final ClassLoader cl,
+ final Map<String, ?> properties)
throws Throwable {
JAXBContext jaxbContext;
try {
@@ -120,7 +123,7 @@
ClassLoader savedClassLoader = currentThread.getContextClassLoader();
try {
currentThread.setContextClassLoader(cl);
- return JAXBContext.newInstance(classArray);
+ return JAXBContext.newInstance(classArray, properties);
} finally {
currentThread.setContextClassLoader(savedClassLoader);
}
@@ -179,7 +182,8 @@
*/
static JAXBContext findBestSet(List<Class> original,
ClassLoader cl,
- List<Class> best) {
+ List<Class> best,
+ Map<String, ?> properties) {
JAXBContext jc = null;
Class[] clsArray = new Class[0];
@@ -194,7 +198,7 @@
best.addAll(primary);
if (best.size() > 0) {
try {
- jc = _newInstance(best.toArray(clsArray), cl);
+ jc = _newInstance(best.toArray(clsArray), cl, properties);
} catch (Throwable t) {
return null;
}
@@ -212,7 +216,7 @@
Class cls = secondary.get(i);
best.add(cls);
try {
- jc = _newInstance(best.toArray(clsArray), cl);
+ jc = _newInstance(best.toArray(clsArray), cl, properties);
} catch (Throwable t) {
if (log.isDebugEnabled()) {
log.debug("The following class is not a JAXB class: " +
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java?rev=668384&r1=668383&r2=668384&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/message/databinding/JAXBUtils.java Mon Jun 16 20:35:50 2008
@@ -105,7 +105,7 @@
*/
public static JAXBContext getJAXBContext(TreeSet<String> contextPackages) throws JAXBException {
return getJAXBContext(contextPackages, new Holder<CONSTRUCTION_TYPE>(),
- contextPackages.toString(), null);
+ contextPackages.toString(), null, null);
}
/**
@@ -123,14 +123,14 @@
public static JAXBContext getJAXBContext(TreeSet<String> contextPackages, ClassLoader
cacheKey) throws JAXBException {
return getJAXBContext(contextPackages, new Holder<CONSTRUCTION_TYPE>(),
- contextPackages.toString(), cacheKey);
+ contextPackages.toString(), cacheKey, null);
}
public static JAXBContext getJAXBContext(TreeSet<String> contextPackages,
Holder<CONSTRUCTION_TYPE> constructionType,
String key)
throws JAXBException {
- return getJAXBContext(contextPackages, constructionType, key, null);
+ return getJAXBContext(contextPackages, constructionType, key, null, null);
}
/**
@@ -148,7 +148,8 @@
public static JAXBContext getJAXBContext(TreeSet<String> contextPackages,
Holder<CONSTRUCTION_TYPE> constructionType,
String key,
- ClassLoader cacheKey)
+ ClassLoader cacheKey,
+ Map<String, ?> properties)
throws JAXBException {
// JAXBContexts for the same class can be reused and are supposed to be thread-safe
if (log.isDebugEnabled()) {
@@ -221,13 +222,13 @@
TreeSet<String> validContextPackages = new TreeSet<String>(contextPackages);
ClassLoader tryCl = cl;
- contextValue = createJAXBContextValue(validContextPackages, cl);
+ contextValue = createJAXBContextValue(validContextPackages, cl, properties);
// If we don't get all the classes, try the cached classloader
if (cacheKey != null && validContextPackages.size() != contextPackages.size()) {
tryCl = cacheKey;
validContextPackages = new TreeSet<String>(contextPackages);
- contextValue = createJAXBContextValue(validContextPackages, cacheKey);
+ contextValue = createJAXBContextValue(validContextPackages, cacheKey, properties);
}
synchronized (jaxbMap) {
// Add the context value with the original package set
@@ -287,7 +288,8 @@
* @throws JAXBException
*/
private static JAXBContextValue createJAXBContextValue(TreeSet<String> contextPackages,
- ClassLoader cl) throws JAXBException {
+ ClassLoader cl,
+ Map<String, ?> properties) throws JAXBException {
JAXBContextValue contextValue = null;
if (log.isDebugEnabled()) {
@@ -436,7 +438,7 @@
//Lets add all common array classes
addCommonArrayClasses(fullList);
Class[] classArray = fullList.toArray(new Class[0]);
- JAXBContext context = JAXBContext_newInstance(classArray, cl);
+ JAXBContext context = JAXBContext_newInstance(classArray, cl, properties);
if (context != null) {
contextValue = new JAXBContextValue(context, CONSTRUCTION_TYPE.BY_CLASS_ARRAY);
}
@@ -1028,7 +1030,8 @@
* @throws Exception
*/
private static JAXBContext JAXBContext_newInstance(final Class[] classArray,
- final ClassLoader cl)
+ final ClassLoader cl,
+ Map<String, ?> properties)
throws JAXBException {
// NOTE: This method must remain private because it uses AccessController
JAXBContext jaxbContext = null;
@@ -1043,7 +1046,7 @@
}
// Get JAXBContext from classes
- jaxbContext = JAXBContextFromClasses.newInstance(classArray, cl);
+ jaxbContext = JAXBContextFromClasses.newInstance(classArray, cl, properties);
return jaxbContext;
}