diff options
author | ramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-03 06:51:59 +0000 |
---|---|---|
committer | ramkumar <ramkumar@13f79535-47bb-0310-9956-ffa450edef68> | 2009-03-03 06:51:59 +0000 |
commit | c78cbecc4c028236a323c0841490ff537698352b (patch) | |
tree | e14a63f788128c2777f89129c83d85eac3ede2ef /branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java | |
parent | 65c9710b644bd3ef0f5dd21aaa0049f984394c57 (diff) |
Fix for TUSCANY-2875
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@749547 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java | 97 |
1 files changed, 96 insertions, 1 deletions
diff --git a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java index e4f62d3bb2..165dfae8be 100644 --- a/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java +++ b/branches/sca-java-1.x/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java @@ -20,8 +20,10 @@ package org.apache.tuscany.sca.implementation.spring; import java.lang.reflect.Method; import java.util.Hashtable; +import java.util.Enumeration; import java.util.List; +import org.apache.tuscany.sca.assembly.Component; import org.apache.tuscany.sca.assembly.ComponentType; import org.apache.tuscany.sca.assembly.Extensible; import org.apache.tuscany.sca.assembly.Implementation; @@ -29,9 +31,12 @@ import org.apache.tuscany.sca.assembly.Property; import org.apache.tuscany.sca.assembly.Reference; import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.assembly.impl.ImplementationImpl; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.assembly.builder.ComponentPreProcessor; import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl; import org.apache.tuscany.sca.implementation.spring.xml.SpringBeanElement; import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple; +import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.springframework.core.io.Resource; /** @@ -39,7 +44,7 @@ import org.springframework.core.io.Resource; * * @version $Rev: 511195 $ $Date: 2007-02-24 02:29:46 +0000 (Sat, 24 Feb 2007) $ */ -public class SpringImplementation extends ImplementationImpl implements Implementation, Extensible { +public class SpringImplementation extends ImplementationImpl implements Implementation, ComponentPreProcessor, Extensible { // The location attribute which points to the Spring application-context XML file private String location; @@ -51,6 +56,8 @@ public class SpringImplementation extends ImplementationImpl implements Implemen // Mapping of property names to Java class private Hashtable<String, Class> propertyMap; private List<PolicyHandlerTuple> policyHandlerClassNames = null; + // List of unresolved bean property references + private Hashtable<String, Reference> unresolvedBeanRef; // Method marked with @Init annotation private Method initMethod = null; @@ -65,6 +72,7 @@ public class SpringImplementation extends ImplementationImpl implements Implemen setUnresolved(true); serviceMap = new Hashtable<String, SpringBeanElement>(); propertyMap = new Hashtable<String, Class>(); + unresolvedBeanRef = new Hashtable<String, Reference>(); } // end method SpringImplementation /* Returns the location attribute for this Spring implementation */ @@ -182,6 +190,17 @@ public class SpringImplementation extends ImplementationImpl implements Implemen return propertyMap.get(propertyName); } // end method getPropertyClass + public void setUnresolvedBeanRef(String refName, Reference reference) { + if (refName == null || reference == null) + return; + unresolvedBeanRef.put(refName, reference); + return; + } // end method setUnresolvedBeanRef + + public Reference getUnresolvedBeanRef(String refName) { + return unresolvedBeanRef.get(refName); + } // end method getUnresolvedBeanRef + public List<PolicyHandlerTuple> getPolicyHandlerClassNames() { return policyHandlerClassNames; } @@ -189,4 +208,80 @@ public class SpringImplementation extends ImplementationImpl implements Implemen public void setPolicyHandlerClassNames(List<PolicyHandlerTuple> policyHandlerClassNames) { this.policyHandlerClassNames = policyHandlerClassNames; } // end method setPolicyHandlerClassNames + + + /** + * Use preProcess to validate and map the references and properties dynamically + */ + public void preProcess(Component component) { + if (!(component instanceof RuntimeComponent)) + return; + + RuntimeComponent rtc = (RuntimeComponent) component; + + // Check if the SCDL is properly configured for all the services + // exposed by Spring application context, otherwise report a error + /*Enumeration<SpringBeanElement> itr = serviceMap.elements(); + while (itr.hasMoreElements()) { + SpringBeanElement beanElement = itr.nextElement(); + if (!rtc.getServices().contains(beanElement.getId())) { + throw new AssertionError("Configuration Error:"); + } + }*/ + + for (Reference reference : rtc.getReferences()) { + if (unresolvedBeanRef.containsKey(reference.getName())) { + Reference ref = unresolvedBeanRef.get(reference.getName()); + componentType.getReferences().add( + createReference(reference, ref.getInterfaceContract())); + unresolvedBeanRef.remove(reference.getName()); + } + } + + for (Property property : rtc.getProperties()) { + if (unresolvedBeanRef.containsKey(property.getName())) { + componentType.getProperties().add(createProperty(property)); + this.setPropertyClass(property.getName(), property.getClass()); + unresolvedBeanRef.remove(property.getName()); + } + } + + // Check if the SCDL is properly configured for all the SCA references + // used in the Spring application context, otherwise report a error + /*for (Reference reference: componentType.getReferences()) { + if (!rtc.getReferences().contains(reference.getName())) { + throw new AssertionError("Configuration Error:"); + } + }*/ + + // Check if the SCDL is properly configured for all the SCA property + // used in the Spring application context, otherwise report a error + /*for (Property property: componentType.getProperties()) { + if (!rtc.getProperties().contains(property.getName())) { + throw new AssertionError("Configuration Error:"); + } + }*/ + } + + protected Reference createReference(Reference reference, InterfaceContract interfaze) { + Reference newReference; + try { + newReference = (Reference)reference.clone(); + if (newReference.getInterfaceContract() == null) + newReference.setInterfaceContract(interfaze); + } catch (CloneNotSupportedException e) { + throw new AssertionError(e); // should not ever happen + } + return newReference; + } + + protected Property createProperty(Property property) { + Property newProperty; + try { + newProperty = (Property)property.clone(); + } catch (CloneNotSupportedException e) { + throw new AssertionError(e); // should not ever happen + } + return newProperty; + } } |