diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-08-09 01:08:37 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-08-09 01:08:37 +0000 |
commit | d00035085d6089d942ff3179556e8893e2790b23 (patch) | |
tree | d64185218ef9f3a86f73ee471df99a4e564a2d8a /java/sca/modules/databinding-jaxb/src/main | |
parent | d927ce193627f96cac6b6d7dd83506b5fab1a585 (diff) |
Add a method to ServiceDiscovery to set context classloader for service providers in OSGi
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@802470 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/databinding-jaxb/src/main')
-rw-r--r-- | java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java | 22 |
1 files changed, 6 insertions, 16 deletions
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 a8d99ad0dd..6b32f0844b 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 @@ -52,10 +52,10 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlSeeAlso; import javax.xml.bind.annotation.XmlTransient; import javax.xml.bind.annotation.XmlType; +import javax.xml.datatype.DatatypeFactory; 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; /** @@ -124,25 +124,15 @@ public class JAXBContextCache { return AccessController.doPrivileged(new PrivilegedExceptionAction<JAXBContext>() { public JAXBContext run() throws JAXBException { // 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); - } + ClassLoader tccl = + ServiceDiscovery.getInstance().setContextClassLoader(JAXBContextCache.class.getClassLoader(), + JAXBContext.class.getName(), + DatatypeFactory.class.getName()); try { JAXBContext context = JAXBContext.newInstance(classesToBeBound); return context; } finally { - if (newTccl != tccl) { + if (tccl != null) { Thread.currentThread().setContextClassLoader(tccl); } } |