diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/databinding-sdo/src')
7 files changed, 62 insertions, 9 deletions
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)); |