summaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rw-r--r--java/sca/modules/databinding-jaxb/META-INF/MANIFEST.MF1
-rw-r--r--java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java40
-rw-r--r--java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java10
3 files changed, 37 insertions, 14 deletions
diff --git a/java/sca/modules/databinding-jaxb/META-INF/MANIFEST.MF b/java/sca/modules/databinding-jaxb/META-INF/MANIFEST.MF
index 9c9095b4eb..274579ba03 100644
--- a/java/sca/modules/databinding-jaxb/META-INF/MANIFEST.MF
+++ b/java/sca/modules/databinding-jaxb/META-INF/MANIFEST.MF
@@ -38,6 +38,7 @@ Import-Package: javax.activation,
org.apache.tuscany.sca.databinding.jaxb;version="2.0.0",
org.apache.tuscany.sca.databinding.util;version="2.0.0",
org.apache.tuscany.sca.databinding.xml;version="2.0.0",
+ org.apache.tuscany.sca.extensibility;version="2.0.0",
org.apache.tuscany.sca.interfacedef;version="2.0.0",
org.apache.tuscany.sca.interfacedef.impl;version="2.0.0",
org.apache.tuscany.sca.interfacedef.util;version="2.0.0",
diff --git a/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
index 4eaaf3db7f..ba94239a31 100644
--- a/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
+++ b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
@@ -55,6 +55,8 @@ import javax.xml.bind.annotation.XmlType;
import javax.xml.transform.Source;
import org.apache.tuscany.sca.databinding.util.LRUCache;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
/**
* @version $Rev$ $Date$
@@ -116,12 +118,34 @@ public class JAXBContextCache {
upool = new Pool<JAXBContext, Unmarshaller>();
defaultContext = getDefaultJAXBContext();
}
-
+
private static JAXBContext newJAXBContext(final Class<?>... classesToBeBound) throws JAXBException {
try {
return AccessController.doPrivileged(new PrivilegedExceptionAction<JAXBContext>() {
public JAXBContext run() throws JAXBException {
- return JAXBContext.newInstance(classesToBeBound);
+ // Try to set up TCCL so that JAXBContext service discovery works in OSGi
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ ClassLoader newTccl = tccl;
+ try {
+ ServiceDeclaration sd =
+ ServiceDiscovery.getInstance().getServiceDeclaration(JAXBContext.class.getName());
+ if (sd != null) {
+ newTccl = sd.loadClass().getClassLoader();
+ }
+ } catch (Exception e) {
+ // Ignore
+ }
+ if (newTccl != tccl) {
+ Thread.currentThread().setContextClassLoader(newTccl);
+ }
+ try {
+ JAXBContext context = JAXBContext.newInstance(classesToBeBound);
+ return context;
+ } finally {
+ if (newTccl != tccl) {
+ Thread.currentThread().setContextClassLoader(newTccl);
+ }
+ }
}
});
} catch (PrivilegedActionException e) {
@@ -129,18 +153,6 @@ public class JAXBContextCache {
}
}
- private static JAXBContext newJAXBContext(final String contextPath, final ClassLoader classLoader)
- throws JAXBException {
- try {
- return AccessController.doPrivileged(new PrivilegedExceptionAction<JAXBContext>() {
- public JAXBContext run() throws JAXBException {
- return JAXBContext.newInstance(contextPath, classLoader);
- }
- });
- } catch (PrivilegedActionException e) {
- throw (JAXBException)e.getException();
- }
- }
public static JAXBContext getDefaultJAXBContext() {
try {
diff --git a/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java
index 58c8bdc175..830e8c5e23 100644
--- a/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java
+++ b/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java
@@ -37,6 +37,7 @@ import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchema;
+import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlType;
import javax.xml.namespace.QName;
@@ -100,6 +101,15 @@ public final class JAXBContextHelper {
return createJAXBContext(dataType);
}
+
+ private Class<?>[] getSeeAlso(Class<?> interfaze) {
+ XmlSeeAlso seeAlso = interfaze.getAnnotation(XmlSeeAlso.class);
+ if (seeAlso == null) {
+ return null;
+ } else {
+ return seeAlso.value();
+ }
+ }
public static JAXBContext createJAXBContext(DataType dataType) throws JAXBException {
return createJAXBContext(findClasses(dataType));