You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2008/06/13 22:27:55 UTC
svn commit: r667641 - in /incubator/tuscany/java/sca:
modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/
modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/
modules/databinding-jaxb/src...
Author: rfeng
Date: Fri Jun 13 13:27:55 2008
New Revision: 667641
URL: http://svn.apache.org/viewvc?rev=667641&view=rev
Log:
Cache the databinding context in Operation/DataType
Added:
incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/
incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/DataTypeHelper.java (with props)
incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/LRUCache.java (with props)
Modified:
incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java
incubator/tuscany/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
incubator/tuscany/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java
incubator/tuscany/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBContextCacheTestCase.java
incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java
incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java
incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLGroupDataBinding.java
incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedDataTypeImpl.java
incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java
incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java
incubator/tuscany/java/sca/samples/quote-xquery/src/main/java/xquery/quote/PropertiesQuoteJoin.java
incubator/tuscany/java/sca/samples/quote-xquery/src/main/java/xquery/quote/QuoteJoin.java
Modified: incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java?rev=667641&r1=667640&r2=667641&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java (original)
+++ incubator/tuscany/java/sca/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java Fri Jun 13 13:27:55 2008
@@ -151,7 +151,7 @@
// Introspect the wrapper data type
if (operation.getWrapper() != null) {
org.apache.tuscany.sca.databinding.DataBinding dbObj =
- dataBindingRegistry.getDataBinding(operation.getDataBinding());
+ dataBindingRegistry.getDataBinding(db);
WrapperHandler handler = dbObj == null ? null : dbObj.getWrapperHandler();
if (handler != null) {
WrapperInfo wrapper = operation.getWrapper();
Modified: incubator/tuscany/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java?rev=667641&r1=667640&r2=667641&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java (original)
+++ incubator/tuscany/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextCache.java Fri Jun 13 13:27:55 2008
@@ -24,18 +24,13 @@
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
-import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
import java.util.Set;
import java.util.UUID;
-import java.util.WeakHashMap;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
@@ -44,6 +39,8 @@
import javax.xml.bind.annotation.XmlSchema;
import javax.xml.transform.Source;
+import org.apache.tuscany.sca.databinding.util.LRUCache;
+
/**
* @version $Rev$ $Date$
*/
@@ -95,9 +92,9 @@
}
public JAXBContextCache(int contextSize, int marshallerSize, int unmarshallerSize) {
- cache = new LRUCache<Object, JAXBContext>(new WeakHashMap<Object, JAXBContext>(), contextSize);
- upool = new LRUCache<JAXBContext, Unmarshaller>(new WeakHashMap<JAXBContext, Unmarshaller>(), unmarshallerSize);
- mpool = new LRUCache<JAXBContext, Marshaller>(new WeakHashMap<JAXBContext, Marshaller>(), marshallerSize);
+ cache = new LRUCache<Object, JAXBContext>(contextSize);
+ upool = new LRUCache<JAXBContext, Unmarshaller>(unmarshallerSize);
+ mpool = new LRUCache<JAXBContext, Marshaller>(marshallerSize);
commonContext = getCommonJAXBContext();
}
@@ -288,72 +285,4 @@
}
}
- public static class LRUCache<K, V> {
- private Map<K, V> cache;
- private List<K> keyQueue;
- private int queueSizeThreshold;
-
- public LRUCache(int queueSizeThreshold) {
- super();
- this.cache = new HashMap<K, V>();
- this.keyQueue = new ArrayList<K>();
- this.queueSizeThreshold = queueSizeThreshold;
- }
-
- public LRUCache(Map<K, V> cache, int queueSizeThreshold) {
- super();
- this.cache = cache;
- this.keyQueue = new ArrayList<K>(cache.keySet());
- this.queueSizeThreshold = queueSizeThreshold;
- }
-
- public V get(K key) {
- V value = cache.get(key);
- if (value != null) {
- // Move the most recently used key to the front of the queue
- if (!key.equals(keyQueue.get(0))) {
- keyQueue.remove(key);
- keyQueue.add(0, key);
- }
- }
- return value;
- }
-
- public void put(K key, V value) {
- if (cache.containsKey(key)) {
- // Adjust the key usage
- if (!key.equals(keyQueue.get(0))) {
- keyQueue.remove(key);
- keyQueue.add(0, key);
- }
- } else {
- if (keyQueue.size() >= queueSizeThreshold) {
- // Remove the least recently used key
- K last = keyQueue.remove(keyQueue.size() - 1);
- keyQueue.add(0, key);
- cache.remove(last);
- } else {
- keyQueue.add(0, key);
- }
- }
- cache.put(key, value);
- }
-
- public V remove(K key) {
- V data = cache.remove(key);
- keyQueue.remove(key);
- return data;
- }
-
- public void clear() {
- cache.clear();
- keyQueue.clear();
- }
-
- public Map<K, V> getCache() {
- return Collections.unmodifiableMap(cache);
- }
-
- }
-
}
Modified: incubator/tuscany/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java?rev=667641&r1=667640&r2=667641&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java (original)
+++ incubator/tuscany/java/sca/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java Fri Jun 13 13:27:55 2008
@@ -48,7 +48,7 @@
import org.apache.tuscany.sca.databinding.TransformationContext;
import org.apache.tuscany.sca.databinding.TransformationException;
import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl;
-import org.apache.tuscany.sca.databinding.jaxb.JAXBContextCache.LRUCache;
+import org.apache.tuscany.sca.databinding.util.LRUCache;
import org.apache.tuscany.sca.interfacedef.DataType;
import org.apache.tuscany.sca.interfacedef.Interface;
import org.apache.tuscany.sca.interfacedef.Operation;
@@ -62,10 +62,9 @@
*/
// FIXME: [rfeng] We probably should turn this into a pluggable system service
public class JAXBContextHelper {
- // TODO: Do we need to set them for source and target?
- public static final String JAXB_CLASSES = "jaxb.classes";
+ // public static final String JAXB_CLASSES = "jaxb.classes";
- public static final String JAXB_CONTEXT_PATH = "jaxb.contextPath";
+ // public static final String JAXB_CONTEXT_PATH = "jaxb.contextPath";
private static final JAXBContextCache cache = new JAXBContextCache();
@@ -90,7 +89,14 @@
// per interface, operation or parameter
Operation op = source ? tContext.getSourceOperation() : tContext.getTargetOperation();
if (op != null) {
- return createJAXBContext(getDataTypes(op, true));
+ synchronized (op) {
+ JAXBContext context = op.getInputType().getMetaData(JAXBContext.class);
+ if (context == null) {
+ context = createJAXBContext(getDataTypes(op, true));
+ op.getInputType().setMetaData(JAXBContext.class, context);
+ }
+ return context;
+ }
}
// For property transformation, the operation can be null
Modified: incubator/tuscany/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBContextCacheTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBContextCacheTestCase.java?rev=667641&r1=667640&r2=667641&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBContextCacheTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBContextCacheTestCase.java Fri Jun 13 13:27:55 2008
@@ -32,7 +32,7 @@
import junit.framework.Assert;
import org.apache.tuscany.sca.databinding.jaxb.JAXBContextCache;
-import org.apache.tuscany.sca.databinding.jaxb.JAXBContextCache.LRUCache;
+import org.apache.tuscany.sca.databinding.util.LRUCache;
import org.junit.Test;
import com.example.ipo.jaxb.Address;
@@ -67,15 +67,15 @@
@Test
public void testLRUCache() {
- JAXBContextCache.LRUCache<String, String> cache = new LRUCache<String, String>(3);
+ LRUCache<String, String> cache = new LRUCache<String, String>(3);
cache.put("1", "A");
- Assert.assertEquals(1, cache.getCache().size());
+ Assert.assertEquals(1, cache.size());
cache.put("2", "B");
- Assert.assertEquals(2, cache.getCache().size());
+ Assert.assertEquals(2, cache.size());
cache.put("3", "C");
- Assert.assertEquals(3, cache.getCache().size());
+ Assert.assertEquals(3, cache.size());
cache.put("4", "D");
- Assert.assertEquals(3, cache.getCache().size());
+ Assert.assertEquals(3, cache.size());
String data = cache.get("1");
Assert.assertNull(data);
data = cache.get("2");
Modified: incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java?rev=667641&r1=667640&r2=667641&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java (original)
+++ incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java Fri Jun 13 13:27:55 2008
@@ -22,18 +22,20 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
import javax.xml.namespace.QName;
-import org.apache.tuscany.sca.databinding.DataBinding;
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.databinding.util.LRUCache;
import org.apache.tuscany.sca.interfacedef.DataType;
import org.apache.tuscany.sca.interfacedef.Operation;
-import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
import org.apache.tuscany.sca.interfacedef.util.XMLType;
import org.apache.tuscany.sdo.api.SDOUtil;
+import commonj.sdo.DataObject;
import commonj.sdo.Type;
import commonj.sdo.helper.HelperContext;
import commonj.sdo.helper.TypeHelper;
@@ -45,6 +47,8 @@
* @version $Rev$ $Date$
*/
public final class SDOContextHelper {
+ private static final LRUCache<Object, HelperContext> cache = new LRUCache<Object, HelperContext>(1024);
+
private SDOContextHelper() {
}
@@ -53,18 +57,21 @@
return getDefaultHelperContext();
}
- HelperContext helperContext = (HelperContext)context.getMetadata().get(HelperContext.class.getName());
- if (helperContext != null) {
- return helperContext;
- }
+ HelperContext helperContext = null;
Operation op = source ? context.getSourceOperation() : context.getTargetOperation();
if (op == null) {
+ DataType<?> dt = source ? context.getSourceDataType() : context.getTargetDataType();
+
+ helperContext = dt.getMetaData(HelperContext.class);
+ if (helperContext != null) {
+ return helperContext;
+ }
helperContext = SDOUtil.createHelperContext();
- boolean found = register(helperContext, context.getSourceDataType());
- found = register(helperContext, context.getTargetDataType()) || found;
+ boolean found = register(helperContext, dt);
if (!found) {
helperContext = getDefaultHelperContext();
}
+ dt.setMetaData(HelperContext.class, helperContext);
return helperContext;
} else {
return getHelperContext(op);
@@ -77,27 +84,29 @@
return getDefaultHelperContext();
}
- HelperContext helperContext = SDOUtil.createHelperContext();
+ HelperContext helperContext = op.getInputType().getMetaData(HelperContext.class);
+ if (helperContext != null) {
+ return helperContext;
+ }
+
+ // Use the default HelperContext until a type is registered later on
+ helperContext = getDefaultHelperContext();
+
+ /*
+ List<DataType> dataTypes = DataTypeHelper.getDataTypes(op, false);
boolean found = false;
- if (op != null) {
- found = register(helperContext, op.getInputType()) || found;
- found = register(helperContext, op.getOutputType()) || found;
- WrapperInfo wrapper = op.getWrapper();
- if (wrapper != null) {
- found = register(helperContext, wrapper.getInputWrapperClass()) || found;
- found = register(helperContext, wrapper.getOutputWrapperClass()) || found;
- }
- for (DataType<DataType> ft : op.getFaultTypes()) {
- found = register(helperContext, ft.getLogical()) || found;
+ for (DataType d : dataTypes) {
+ if (register(helperContext, d)) {
+ found = true;
}
}
if (!found) {
helperContext = getDefaultHelperContext();
}
-
+ */
+ op.getInputType().setMetaData(HelperContext.class, helperContext);
return helperContext;
-
}
/**
@@ -109,25 +118,10 @@
if (dataType == null) {
return false;
}
- String db = dataType.getDataBinding();
+ Set<Class<?>> classes = DataTypeHelper.findClasses(dataType);
boolean found = false;
- if (DataBinding.IDL_INPUT.equals(db) || DataBinding.IDL_OUTPUT.equals(db)
- || DataBinding.IDL_FAULT.equals(db)
- || SDODataBinding.NAME.equals(db)) {
- Class javaType = dataType.getPhysical();
- found = register(helperContext, javaType);
- if (dataType.getLogical() instanceof DataType) {
- DataType logical = (DataType)dataType.getLogical();
- found = register(helperContext, logical.getPhysical()) || found;
- }
- if (dataType.getLogical() instanceof List) {
- List types = (List)dataType.getLogical();
- for (Object type : types) {
- if (type instanceof DataType) {
- found = register(helperContext, ((DataType)type)) || found;
- }
- }
- }
+ for (Class<?> cls : classes) {
+ found = register(helperContext, dataType.getPhysical()) || found;
}
return found;
}
@@ -138,16 +132,16 @@
* @param javaType
*/
- private static boolean register(HelperContext helperContext, Class javaType) {
- if (javaType == null) {
+ public static boolean register(HelperContext helperContext, Class javaType) {
+ if (javaType == null || DataObject.class == javaType) {
return false;
}
try {
Type type = helperContext.getTypeHelper().getType(javaType);
if (type != null && (!type.isDataType())) {
- Method method = type.getClass().getMethod("getEPackage", new Class[] {});
+ Method method = type.getClass().getMethod("getEPackage");
Object factory = method.invoke(type, new Object[] {});
- method = factory.getClass().getMethod("register", new Class[] {HelperContext.class});
+ method = factory.getClass().getMethod("register", HelperContext.class);
method.invoke(factory, new Object[] {helperContext});
return true;
}
Modified: incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java?rev=667641&r1=667640&r2=667641&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java (original)
+++ incubator/tuscany/java/sca/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java Fri Jun 13 13:27:55 2008
@@ -31,13 +31,13 @@
import org.apache.tuscany.sca.interfacedef.DataType;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.apache.tuscany.sdo.api.SDOUtil;
import commonj.sdo.DataObject;
import commonj.sdo.Type;
import commonj.sdo.helper.CopyHelper;
import commonj.sdo.helper.HelperContext;
import commonj.sdo.helper.XMLDocument;
-import commonj.sdo.impl.HelperProvider;
/**
* SDO Databinding
@@ -61,33 +61,48 @@
}
@Override
- public boolean introspect(DataType dataType, Operation operation) {
- Class javaType = dataType.getPhysical();
+ public boolean introspect(DataType dataType, final Operation operation) {
+ final Class javaType = dataType.getPhysical();
// Allow privileged access to read system properties. Requires PropertyPermission
// java.specification.version read in security policy.
- HelperContext context = AccessController.doPrivileged(new PrivilegedAction<HelperContext>() {
+ final HelperContext context = AccessController.doPrivileged(new PrivilegedAction<HelperContext>() {
public HelperContext run() {
- return HelperProvider.getDefaultContext();
+ return SDOContextHelper.getHelperContext(operation);
}
});
- // FIXME: Need a better to test dynamic SDO
- if (DataObject.class.isAssignableFrom(javaType)) {
- // Dynamic SDO
- dataType.setDataBinding(getName());
- if (dataType.getLogical() == null) {
- dataType.setLogical(XMLType.UNKNOWN);
- }
- return true;
- }
- // FIXME: We need to access HelperContext
+
Type type = context.getTypeHelper().getType(javaType);
if (type == null) {
+ // FIXME: Need a better to test dynamic SDO
+ if (DataObject.class.isAssignableFrom(javaType)) {
+ // Dynamic SDO
+ dataType.setDataBinding(getName());
+ if (dataType.getLogical() == null) {
+ dataType.setLogical(XMLType.UNKNOWN);
+ }
+ return true;
+ }
return false;
- }
+ }
if (type.isDataType()) {
// FIXME: Ignore simple types?
return false;
}
+
+ // Found a SDO type, replace the default context with a private one
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ if (context == SDOContextHelper.getDefaultHelperContext()) {
+ HelperContext newContext = SDOUtil.createHelperContext();
+ SDOContextHelper.register(newContext, javaType);
+ if (operation != null) {
+ operation.getInputType().setMetaData(HelperContext.class, newContext);
+ }
+ }
+ return null;
+ }
+ });
+
String namespace = type.getURI();
String name = context.getXSDHelper().getLocalName(type);
QName xmlType = new QName(namespace, name);
@@ -98,6 +113,7 @@
elementName = ((XMLType)logical).getElementName();
}
dataType.setLogical(new XMLType(elementName, xmlType));
+
return true;
}
@@ -113,13 +129,13 @@
@Override
public XMLTypeHelper getXMLTypeHelper() {
- return new SDOTypeHelper();
- // return xmlTypeHelper;
+ // return new SDOTypeHelper();
+ return xmlTypeHelper;
}
@Override
public Object copy(Object arg, DataType dataType, Operation operation) {
- HelperContext context = HelperProvider.getDefaultContext();
+ HelperContext context = SDOContextHelper.getHelperContext(operation);
CopyHelper copyHelper = context.getCopyHelper();
if (arg instanceof XMLDocument) {
XMLDocument document = (XMLDocument)arg;
Added: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/DataTypeHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/DataTypeHelper.java?rev=667641&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/DataTypeHelper.java (added)
+++ incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/DataTypeHelper.java Fri Jun 13 13:27:55 2008
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.util;
+
+import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.lang.reflect.WildcardType;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataTypeHelper {
+ private DataTypeHelper() {
+ }
+
+ /**
+ * Find all classes referenced by this data type though java generics
+ * @param d
+ * @return
+ */
+ public static Set<Class<?>> findClasses(DataType d) {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+ Set<Type> visited = new HashSet<Type>();
+ findClasses(d, classes, visited);
+ return classes;
+ }
+
+ private static void findClasses(DataType d, Set<Class<?>> classes, Set<Type> visited) {
+ if (d == null) {
+ return;
+ }
+ classes.add(d.getPhysical());
+ if (d.getPhysical() != d.getGenericType()) {
+ findClasses(d.getGenericType(), classes, visited);
+ }
+ }
+
+ /**
+ * Find referenced classes in the generic type
+ * @param type
+ * @param classSet
+ * @param visited
+ */
+ private static void findClasses(Type type, Set<Class<?>> classSet, Set<Type> visited) {
+ if (visited.contains(type) || type == null) {
+ return;
+ }
+ visited.add(type);
+ if (type instanceof Class) {
+ Class<?> cls = (Class<?>)type;
+ if (!cls.isInterface()) {
+ classSet.add(cls);
+ }
+ return;
+ } else if (type instanceof ParameterizedType) {
+ ParameterizedType pType = (ParameterizedType)type;
+ findClasses(pType.getRawType(), classSet, visited);
+ for (Type t : pType.getActualTypeArguments()) {
+ findClasses(t, classSet, visited);
+ }
+ } else if (type instanceof TypeVariable) {
+ TypeVariable<?> tv = (TypeVariable<?>)type;
+ for (Type t : tv.getBounds()) {
+ findClasses(t, classSet, visited);
+ }
+ } else if (type instanceof GenericArrayType) {
+ GenericArrayType gType = (GenericArrayType)type;
+ findClasses(gType, classSet, visited);
+ } else if (type instanceof WildcardType) {
+ WildcardType wType = (WildcardType)type;
+ for (Type t : wType.getLowerBounds()) {
+ findClasses(t, classSet, visited);
+ }
+ for (Type t : wType.getUpperBounds()) {
+ findClasses(t, classSet, visited);
+ }
+ }
+ }
+
+ /**
+ * Get all the data types in the interface
+ * @param intf The interface
+ * @param useWrapper Use wrapper classes?
+ * @return A list of DataTypes
+ */
+ public static List<DataType> getDataTypes(Interface intf, boolean useWrapper) {
+ List<DataType> dataTypes = new ArrayList<DataType>();
+ for (Operation op : intf.getOperations()) {
+ getDataTypes(dataTypes, op, useWrapper);
+ }
+ return dataTypes;
+ }
+
+ /**
+ * Get all the data types in the operation
+ * @param op The operaiton
+ * @param useWrapper Use wrapper classes?
+ * @return A list of DataTypes
+ */
+ public static List<DataType> getDataTypes(Operation op, boolean useWrapper) {
+ List<DataType> dataTypes = new ArrayList<DataType>();
+ getDataTypes(dataTypes, op, useWrapper);
+ return dataTypes;
+ }
+
+ private static void getDataTypes(List<DataType> dataTypes, Operation op, boolean useWrapper) {
+ WrapperInfo wrapper = op.getWrapper();
+ if (useWrapper && wrapper != null) {
+ DataType dt1 = wrapper.getInputWrapperType();
+ if (dt1 != null) {
+ dataTypes.add(dt1);
+ }
+ DataType dt2 = wrapper.getOutputWrapperType();
+ if (dt2 != null) {
+ dataTypes.add(dt2);
+ }
+ }
+ // FIXME: [rfeng] We may need to find the referenced classes in the child types
+ // else
+ {
+ for (DataType dt1 : op.getInputType().getLogical()) {
+ dataTypes.add(dt1);
+ }
+ DataType dt2 = op.getOutputType();
+ if (dt2 != null) {
+ dataTypes.add(dt2);
+ }
+ }
+ for (DataType<DataType> dt3 : op.getFaultTypes()) {
+ DataType dt4 = dt3.getLogical();
+ if (dt4 != null) {
+ dataTypes.add(dt4);
+ }
+ }
+ }
+
+}
Propchange: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/DataTypeHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/DataTypeHelper.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/LRUCache.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/LRUCache.java?rev=667641&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/LRUCache.java (added)
+++ incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/LRUCache.java Fri Jun 13 13:27:55 2008
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.util;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * A Simple LRU Cache
+ *
+ * @version $Revision$
+ * @param <K>
+ * @param <V>
+ */
+
+public class LRUCache<K, V> extends LinkedHashMap<K, V> {
+ private static final long serialVersionUID = -342098639681884413L;
+ protected int maxCacheSize = 4096;
+
+ /**
+ * Default constructor for an LRU Cache The default capacity is 10000
+ */
+ public LRUCache() {
+ this(0, 4096, 0.75f, true);
+ }
+
+ /**
+ * Constructs a LRUCache with a maximum capacity
+ *
+ * @param maximumCacheSize
+ */
+ public LRUCache(int maximumCacheSize) {
+ this(0, maximumCacheSize, 0.75f, true);
+ }
+
+ /**
+ * Constructs an empty <tt>LRUCache</tt> instance with the specified
+ * initial capacity, maximumCacheSize,load factor and ordering mode.
+ *
+ * @param initialCapacity the initial capacity.
+ * @param maximumCacheSize
+ * @param loadFactor the load factor.
+ * @param accessOrder the ordering mode - <tt>true</tt> for access-order,
+ * <tt>false</tt> for insertion-order.
+ * @throws IllegalArgumentException if the initial capacity is negative or
+ * the load factor is non-positive.
+ */
+
+ public LRUCache(int initialCapacity, int maximumCacheSize, float loadFactor, boolean accessOrder) {
+ super(initialCapacity, loadFactor, accessOrder);
+ this.maxCacheSize = maximumCacheSize;
+ }
+
+ /**
+ * @return Returns the maxCacheSize.
+ */
+ public int getMaxCacheSize() {
+ return maxCacheSize;
+ }
+
+ /**
+ * @param maxCacheSize The maxCacheSize to set.
+ */
+ public void setMaxCacheSize(int maxCacheSize) {
+ this.maxCacheSize = maxCacheSize;
+ }
+
+ protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
+ return size() > maxCacheSize;
+ }
+}
Propchange: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/LRUCache.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/LRUCache.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLGroupDataBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLGroupDataBinding.java?rev=667641&r1=667640&r2=667641&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLGroupDataBinding.java (original)
+++ incubator/tuscany/java/sca/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLGroupDataBinding.java Fri Jun 13 13:27:55 2008
@@ -28,11 +28,10 @@
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
-import javax.xml.transform.Result;
-import javax.xml.transform.Source;
import org.apache.tuscany.sca.databinding.impl.GroupDataBinding;
import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
@@ -44,14 +43,15 @@
public class XMLGroupDataBinding extends GroupDataBinding {
public XMLGroupDataBinding() {
- super(new Class[] {InputStream.class, OutputStream.class, Reader.class, Writer.class, Source.class,
- Result.class, InputSource.class, ContentHandler.class, XMLStreamReader.class,
+ super(new Class[] {InputStream.class, OutputStream.class, Reader.class, Writer.class,
+ // Source.class, Result.class,
+ InputSource.class, ContentHandler.class, XMLStreamReader.class,
XMLStreamWriter.class, XMLEventReader.class, XMLEventWriter.class});
}
@Override
protected Object getLogical(Class<?> markerType, Operation operation) {
- return null;
+ return XMLType.UNKNOWN;
}
}
Modified: incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedDataTypeImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedDataTypeImpl.java?rev=667641&r1=667640&r2=667641&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedDataTypeImpl.java (original)
+++ incubator/tuscany/java/sca/modules/interface-java-jaxws/src/main/java/org/apache/tuscany/sca/interfacedef/java/jaxws/GeneratedDataTypeImpl.java Fri Jun 13 13:27:55 2008
@@ -21,6 +21,8 @@
import java.lang.reflect.Method;
import java.lang.reflect.Type;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import javax.xml.namespace.QName;
@@ -39,7 +41,7 @@
private Class<?> physical;
private XMLType logical;
- private Object metaData;
+ private Map<Class<?>, Object> metaDataMap;
private Method method;
private String wrapperClassName;
private String wrapperNamespace;
@@ -127,12 +129,14 @@
return super.clone();
}
- public Object getMetaData() {
- return metaData;
+ public <T> T getMetaData(Class<T> type) {
+ return metaDataMap == null ? null : type.cast(metaDataMap.get(type));
}
- public void setMetaData(Object metaData) {
- this.metaData = metaData;
+ public <T> void setMetaData(Class<T> type, T metaData) {
+ if (metaDataMap == null) {
+ metaDataMap = new ConcurrentHashMap<Class<?>, Object>();
+ }
+ metaDataMap.put(type, metaData);
}
-
}
Modified: incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java?rev=667641&r1=667640&r2=667641&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java (original)
+++ incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java Fri Jun 13 13:27:55 2008
@@ -105,13 +105,15 @@
/**
* Get the databinding-specific metadata
+ * @param type The java type of the metadata
* @return the databinding-specific metadata
*/
- Object getMetaData();
+ <T> T getMetaData(Class<T> type);
/**
* Set the databinding-specific metadata
+ * @param type The java type of the metadata
* @param metaData the databinding-specific metadata, such as SDO's commonj.sdo.Type or
* JAXB's javax.xml.bind.JAXBContext
*/
- void setMetaData(Object metaData);
+ <T> void setMetaData(Class<T> type, T metaData);
}
Modified: incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java?rev=667641&r1=667640&r2=667641&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java (original)
+++ incubator/tuscany/java/sca/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java Fri Jun 13 13:27:55 2008
@@ -19,6 +19,8 @@
package org.apache.tuscany.sca.interfacedef.impl;
import java.lang.reflect.Type;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import org.apache.tuscany.sca.interfacedef.DataType;
@@ -44,7 +46,7 @@
private Class<?> physical;
private Type genericType;
private L logical;
- private Object metaData;
+ private Map<Class<?>, Object> metaDataMap;
/**
* Construct a data type specifying the physical and logical types.
@@ -204,11 +206,14 @@
return true;
}
- public Object getMetaData() {
- return metaData;
+ public <T> T getMetaData(Class<T> type) {
+ return metaDataMap == null ? null : type.cast(metaDataMap.get(type));
}
- public void setMetaData(Object metaData) {
- this.metaData = metaData;
+ public <T> void setMetaData(Class<T> type, T metaData) {
+ if (metaDataMap == null) {
+ metaDataMap = new ConcurrentHashMap<Class<?>, Object>();
+ }
+ metaDataMap.put(type, metaData);
}
}
Modified: incubator/tuscany/java/sca/samples/quote-xquery/src/main/java/xquery/quote/PropertiesQuoteJoin.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/quote-xquery/src/main/java/xquery/quote/PropertiesQuoteJoin.java?rev=667641&r1=667640&r2=667641&view=diff
==============================================================================
--- incubator/tuscany/java/sca/samples/quote-xquery/src/main/java/xquery/quote/PropertiesQuoteJoin.java (original)
+++ incubator/tuscany/java/sca/samples/quote-xquery/src/main/java/xquery/quote/PropertiesQuoteJoin.java Fri Jun 13 13:27:55 2008
@@ -18,10 +18,15 @@
*/
package xquery.quote;
+import javax.xml.ws.RequestWrapper;
+import javax.xml.ws.ResponseWrapper;
+
import org.example.quote.Quote;
import org.osoa.sca.annotations.Remotable;
@Remotable
public interface PropertiesQuoteJoin {
+ @RequestWrapper(className="xquery.quote.joinPriceAndAvailQuotes")
+ @ResponseWrapper(className="xquery.quote.joinPriceAndAvailQuotesResponse")
public Quote joinPriceAndAvailQuotes();
}
Modified: incubator/tuscany/java/sca/samples/quote-xquery/src/main/java/xquery/quote/QuoteJoin.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/quote-xquery/src/main/java/xquery/quote/QuoteJoin.java?rev=667641&r1=667640&r2=667641&view=diff
==============================================================================
--- incubator/tuscany/java/sca/samples/quote-xquery/src/main/java/xquery/quote/QuoteJoin.java (original)
+++ incubator/tuscany/java/sca/samples/quote-xquery/src/main/java/xquery/quote/QuoteJoin.java Fri Jun 13 13:27:55 2008
@@ -18,6 +18,9 @@
*/
package xquery.quote;
+import javax.xml.ws.RequestWrapper;
+import javax.xml.ws.ResponseWrapper;
+
import org.example.avail.AvailQuote;
import org.example.price.PriceQuote;
import org.example.quote.Quote;
@@ -25,5 +28,7 @@
@Remotable
public interface QuoteJoin {
+ @RequestWrapper(className="xquery.quote.joinPriceAndAvailQuotes")
+ @ResponseWrapper(className="xquery.quote.joinPriceAndAvailQuotesResponse")
public Quote joinPriceAndAvailQuotes(PriceQuote priceQuote, AvailQuote availQuote, float taxRate);
}