summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x
diff options
context:
space:
mode:
authorslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-11-19 10:03:23 +0000
committerslaws <slaws@13f79535-47bb-0310-9956-ffa450edef68>2010-11-19 10:03:23 +0000
commita1f4429dc7ae29b0fd22493db12372ec65baa4bf (patch)
tree68a106032ac0e273549551294be8fad9cc3e6ff6 /sca-java-2.x
parent4e4495c18bb437c3e8a044ca40248e6024d3d0f9 (diff)
TUSCANY-3791 - synchronize access to DOM and cache result to reduce chance of hitting the synchronization.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1036786 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x')
-rw-r--r--sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java6
-rw-r--r--sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java39
2 files changed, 37 insertions, 8 deletions
diff --git a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java
index e6fc1b4405..5070d0636c 100644
--- a/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java
+++ b/sca-java-2.x/trunk/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java
@@ -45,7 +45,11 @@ public class Node2JAXB extends BaseTransformer<Node, Object> implements PullTran
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);
diff --git a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java
index a190b761e2..acacd23d8f 100644
--- a/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java
+++ b/sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java
@@ -170,14 +170,21 @@ public class JavaPropertyValueObjectFactory implements PropertyValueFactory {
}
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 JavaPropertyValueObjectFactory implements PropertyValueFactory {
+ 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 JavaPropertyValueObjectFactory implements PropertyValueFactory {
+ 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 JavaPropertyValueObjectFactory implements PropertyValueFactory {
+ 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;
}
}