diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-11-19 10:03:23 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-11-19 10:03:23 +0000 |
commit | a1f4429dc7ae29b0fd22493db12372ec65baa4bf (patch) | |
tree | 68a106032ac0e273549551294be8fad9cc3e6ff6 /sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org | |
parent | 4e4495c18bb437c3e8a044ca40248e6024d3d0f9 (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/trunk/modules/implementation-java-runtime/src/main/java/org')
-rw-r--r-- | sca-java-2.x/trunk/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java | 39 |
1 files changed, 32 insertions, 7 deletions
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; } } |