You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2010/11/19 11:03:23 UTC
svn commit: r1036786 - in /tuscany/sca-java-2.x/trunk/modules:
databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/
implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/
Author: slaws
Date: Fri Nov 19 10:03:23 2010
New Revision: 1036786
URL: http://svn.apache.org/viewvc?rev=1036786&view=rev
Log:
TUSCANY-3971 - synchronize access to DOM and cache result to reduce chance of hitting the synchronization.
Modified:
tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java
tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java
Modified: tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java?rev=1036786&r1=1036785&r2=1036786&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java Fri Nov 19 10:03:23 2010
@@ -45,7 +45,11 @@ public class Node2JAXB extends BaseTrans
try {
JAXBContext jaxbContext = contextHelper.createJAXBContext(context, false);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
- Object result = unmarshaller.unmarshal(source, JAXBContextHelper.getJavaType(context.getTargetDataType()));
+ Object result;
+ // TUSCANY-3971
+ synchronized(source){
+ result = unmarshaller.unmarshal(source, JAXBContextHelper.getJavaType(context.getTargetDataType()));
+ }
return JAXBContextHelper.createReturnValue(jaxbContext, context.getTargetDataType(), result);
} catch (Exception e) {
throw new TransformationException(e);
Modified: tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java?rev=1036786&r1=1036785&r2=1036786&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java Fri Nov 19 10:03:23 2010
@@ -170,14 +170,21 @@ public class JavaPropertyValueObjectFact
}
class ObjectFactoryImpl extends ObjectFactoryImplBase {
+ private Object result = null;
+
public ObjectFactoryImpl(Property property, Object propertyValue, Class<?> javaType) {
super(property, propertyValue, javaType);
}
public Object getInstance() throws ObjectCreationException {
+ // TUSCANY-3791
+ if (result != null){
+ return result;
+ }
+
if (isSimpleType) {
try {
- return simpleTypeMapper.toJavaObject(property.getXSDType(), (String)propertyValue, null);
+ result = simpleTypeMapper.toJavaObject(property.getXSDType(), (String)propertyValue, null);
} catch (NumberFormatException ex) {
throw new ObjectCreationException("Failed to create instance for property " + property.getName()
+ " with value "
@@ -188,19 +195,26 @@ public class JavaPropertyValueObjectFact
+ propertyValue, ex);
}
} else {
- return mediator.mediate(propertyValue, sourceDataType, targetDataType, null);
- // return null;
+ result = mediator.mediate(propertyValue, sourceDataType, targetDataType, null);
}
+ return result;
}
}
class ListObjectFactoryImpl extends ObjectFactoryImplBase {
+ private List result = null;
+
public ListObjectFactoryImpl(Property property, List<?> propertyValues, Class<?> javaType) {
super(property, propertyValues, javaType);
}
@SuppressWarnings("unchecked")
public List<?> getInstance() throws ObjectCreationException {
+ // TUSCANY-3791
+ if (result != null){
+ return result;
+ }
+
if (isSimpleType) {
List<Object> values = new ArrayList<Object>();
for (String aValue : (List<String>)propertyValue) {
@@ -222,24 +236,33 @@ public class JavaPropertyValueObjectFact
+ propertyValue, ex);
}
}
- return values;
+ result = values;
} else {
List instances = new ArrayList();
for (Node aValue : (List<Node>)propertyValue) {
instances.add(mediator.mediate(aValue, sourceDataType, targetDataType, null));
}
- return instances;
+ result = instances;
}
+
+ return result;
}
}
class ArrayObjectFactoryImpl extends ObjectFactoryImplBase {
+ private Object result = null;
+
public ArrayObjectFactoryImpl(Property property, List<?> propertyValues, Class<?> javaType) {
super(property, propertyValues, javaType);
}
@SuppressWarnings("unchecked")
public Object getInstance() throws ObjectCreationException {
+ // TUSCANY-3791
+ if (result != null){
+ return result;
+ }
+
if (isSimpleType) {
int count = 0;
Object values = Array.newInstance(javaType, ((List<Object>)propertyValue).size());
@@ -262,15 +285,17 @@ public class JavaPropertyValueObjectFact
+ propertyValue, ex);
}
}
- return values;
+ result = values;
} else {
Object instances = Array.newInstance(javaType, ((List<Object>)propertyValue).size());
int count = 0;
for (Node aValue : (List<Node>)propertyValue) {
Array.set(instances, count++, mediator.mediate(aValue, sourceDataType, targetDataType, null));
}
- return instances;
+ result = instances;
}
+
+ return result;
}
}