diff options
author | edwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68> | 2010-05-06 13:30:35 +0000 |
---|---|---|
committer | edwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68> | 2010-05-06 13:30:35 +0000 |
commit | bcb99010d0c100bc1e8007afdad41b7887e75a01 (patch) | |
tree | 9126e34fc426d690b12db12ebb6a697995e5fd7e /sca-java-2.x/trunk | |
parent | e7f3b0a180dbfd57056342dbbeb9c0972e47128d (diff) |
Fixes to databinding-sdo required to enable the module to work under OSGi, as described in TUSCANY-3547
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@941719 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk')
8 files changed, 66 insertions, 12 deletions
diff --git a/sca-java-2.x/trunk/modules/databinding-sdo/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/databinding-sdo/META-INF/MANIFEST.MF index e270921af4..98ea88ea0f 100644 --- a/sca-java-2.x/trunk/modules/databinding-sdo/META-INF/MANIFEST.MF +++ b/sca-java-2.x/trunk/modules/databinding-sdo/META-INF/MANIFEST.MF @@ -7,9 +7,9 @@ Bundle-Version: 2.0.0 Bundle-ManifestVersion: 2
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
Bundle-Description: Apache Tuscany SCA Data Binding for SDO
-Import-Package: commonj.sdo,
- commonj.sdo.helper,
- commonj.sdo.impl,
+Import-Package: commonj.sdo;version="2.1",
+ commonj.sdo.helper;version="2.1",
+ commonj.sdo.impl;version="2.1",
javax.xml.namespace,
javax.xml.parsers,
javax.xml.stream,
@@ -34,3 +34,4 @@ Import-Package: commonj.sdo, Bundle-SymbolicName: org.apache.tuscany.sca.databinding.sdo
Bundle-DocURL: http://www.apache.org/
Bundle-RequiredExecutionEnvironment: J2SE-1.5,JavaSE-1.6
+Require-Bundle: org.apache.tuscany.sca.extensibility
diff --git a/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java b/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java index 8c193151f9..23063317e7 100644 --- a/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java +++ b/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java @@ -24,12 +24,15 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; +import javax.xml.datatype.DatatypeFactory; import javax.xml.namespace.QName; import org.apache.tuscany.sca.common.java.collection.LRUCache; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.databinding.TransformationContext; import org.apache.tuscany.sca.databinding.TransformationException; import org.apache.tuscany.sca.databinding.util.DataTypeHelper; +import org.apache.tuscany.sca.extensibility.ClassLoaderContext; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.util.XMLType; @@ -48,9 +51,21 @@ import commonj.sdo.impl.HelperProvider; */ public final class SDOContextHelper { private static final LRUCache<Object, HelperContext> cache = new LRUCache<Object, HelperContext>(1024); + + private static ExtensionPointRegistry registry = null; + private static HelperContext defaultHelperContext; private SDOContextHelper() { } + + /** + * Static method used to set the registry used to locate the SDO implementation provider + * MUST be called before using any other methods on this class + * @param theRegistry + */ + public static void setRegistry( ExtensionPointRegistry theRegistry ) { + registry = theRegistry; + } // end setRegistry public static HelperContext getHelperContext(TransformationContext context, boolean source) { if (context == null) { @@ -161,10 +176,35 @@ public final class SDOContextHelper { } } - public static HelperContext getDefaultHelperContext() { - // SDOUtil.createHelperContext(); - return HelperProvider.getDefaultContext(); - } + public static HelperContext getDefaultHelperContext( ) { + // Return a chached value if available... + if( defaultHelperContext != null ) return defaultHelperContext; + + // Try to set up TCCL so that SDO Helper Provider service discovery works in OSGi + if( registry == null ) return null; + + ClassLoader oldTccl = + ClassLoaderContext.setContextClassLoader(SDOContextHelper.class.getClassLoader(), + registry.getServiceDiscovery(), + // SDO Helper Provider + "commonj.sdo.impl.HelperProvider" + ); + try { + // Load the HelperProvider (using the new TCCL) and get the default HelperContext + // cache the returned HelperContext... + ClassLoader tccl = Thread.currentThread().getContextClassLoader(); + HelperProvider.setDefaultInstance(tccl); + defaultHelperContext = HelperProvider.getDefaultContext(); + return defaultHelperContext; + } catch (Exception e ){ + e.printStackTrace(); + return null; + } finally { + if (oldTccl != null) { + Thread.currentThread().setContextClassLoader(oldTccl); + } + } // end try + } // end getDefaultHelperContext() public static QName getElement(TransformationContext context) { if (context == null) { diff --git a/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java b/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java index 957ba7679b..0003e7d46f 100644 --- a/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java +++ b/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java @@ -24,6 +24,7 @@ import java.security.PrivilegedAction; import javax.xml.namespace.QName; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.databinding.BaseDataBinding; import org.apache.tuscany.sca.databinding.WrapperHandler; import org.apache.tuscany.sca.databinding.XMLTypeHelper; @@ -52,8 +53,9 @@ public class SDODataBinding extends BaseDataBinding { private WrapperHandler<Object> wrapperHandler; private XMLTypeHelper xmlTypeHelper; - public SDODataBinding() { + public SDODataBinding( ExtensionPointRegistry registry ) { super(NAME, DataObject.class); + SDOContextHelper.setRegistry( registry ); wrapperHandler = new SDOWrapperHandler(); xmlTypeHelper = new SDOTypeHelper(); } diff --git a/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypeHelper.java b/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypeHelper.java index 1634a73563..381249d9bb 100644 --- a/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypeHelper.java +++ b/sca-java-2.x/trunk/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOTypeHelper.java @@ -30,6 +30,7 @@ import javax.xml.namespace.QName; import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.databinding.XMLTypeHelper; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.Interface; @@ -62,7 +63,7 @@ public class SDOTypeHelper implements XMLTypeHelper { // private Map<String, List<Type>> xsdTypesMap = new HashMap<String, List<Type>>(); // private Map<String, List<Type>> typesMap = new HashMap<String, List<Type>>(); - public SDOTypeHelper(ProcessorContext context) { + public SDOTypeHelper( ProcessorContext context ) { super(); this.context=context; //Should we use this.context to get helper objects ??? @@ -71,11 +72,14 @@ public class SDOTypeHelper implements XMLTypeHelper { } //Should we remove this constructor???? otherwise we context gets created public SDOTypeHelper() { - super(); + this(null); + /* + super(); this.context=null; //Should we use this.context to get helper objects ??? typeHelper = SDOContextHelper.getDefaultHelperContext().getTypeHelper(); xsdHelper = SDOContextHelper.getDefaultHelperContext().getXSDHelper(); + */ } public TypeInfo getTypeInfo(Class javaType, Object logical) { QName xmlType = JavaXMLMapper.getXMLType(javaType); diff --git a/sca-java-2.x/trunk/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java b/sca-java-2.x/trunk/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java index ef0d63f941..400b424a97 100644 --- a/sca-java-2.x/trunk/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java +++ b/sca-java-2.x/trunk/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java @@ -23,6 +23,7 @@ import javax.xml.namespace.QName; import junit.framework.TestCase; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; @@ -51,7 +52,7 @@ public class SDODataBindingTestCase extends TestCase { @Override protected void setUp() throws Exception { super.setUp(); - binding = new SDODataBinding(); + binding = new SDODataBinding(new DefaultExtensionPointRegistry()); context = HelperProvider.getDefaultContext(); SdoFactory.INSTANCE.register(context); } diff --git a/sca-java-2.x/trunk/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java b/sca-java-2.x/trunk/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java index 2aaae3c6d8..4d415f2895 100644 --- a/sca-java-2.x/trunk/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java +++ b/sca-java-2.x/trunk/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java @@ -23,6 +23,7 @@ import javax.xml.namespace.QName; import junit.framework.TestCase; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.databinding.TransformationContext; import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; import org.apache.tuscany.sca.interfacedef.DataType; @@ -54,6 +55,7 @@ public abstract class SDOTransformerTestCaseBase extends TestCase { @Override protected void setUp() throws Exception { super.setUp(); + new SDODataBinding(new DefaultExtensionPointRegistry()); helperContext = HelperProvider.getDefaultContext(); SdoFactory.INSTANCE.register(helperContext); diff --git a/sca-java-2.x/trunk/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java b/sca-java-2.x/trunk/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java index 11d8495de8..2326d1b93b 100644 --- a/sca-java-2.x/trunk/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java +++ b/sca-java-2.x/trunk/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java @@ -24,6 +24,7 @@ import javax.xml.namespace.QName; import junit.framework.TestCase; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; import org.apache.tuscany.sca.interfacedef.util.ElementInfo; @@ -46,6 +47,7 @@ public class SDOWrapperHandlerTestCase extends TestCase { @Override public void setUp() throws Exception { + new SDODataBinding(new DefaultExtensionPointRegistry()); context = SDOUtil.createHelperContext(); handler = new SDOWrapperHandler(); } diff --git a/sca-java-2.x/trunk/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java b/sca-java-2.x/trunk/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java index 114c568c38..2beadc5b61 100644 --- a/sca-java-2.x/trunk/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java +++ b/sca-java-2.x/trunk/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java @@ -24,9 +24,11 @@ import javax.xml.stream.XMLStreamReader; import junit.framework.Assert; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sdo.api.SDOUtil; import com.example.ipo.sdo.PurchaseOrderType; import commonj.sdo.helper.XMLDocument; @@ -36,7 +38,7 @@ import commonj.sdo.helper.XMLDocument; * @version $Rev$ $Date$ */ public class XMLDocument2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase { - + @Override protected DataType<?> getSourceDataType() { return new DataTypeImpl<XMLType>(XMLDocument.class.getName(), XMLDocument.class, new XMLType(ORDER_QNAME, null)); |