From fb1ef459f71259a2283c9296006225578d92b7c9 Mon Sep 17 00:00:00 2001 From: antelder Date: Tue, 12 Apr 2011 08:50:18 +0000 Subject: handle the case where no interface is defined on implementation.web references by setting the interface from the JSP tag git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1091326 13f79535-47bb-0310-9956-ffa450edef68 --- .../web/runtime/jsp/ReferenceTag.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'sca-java-2.x/trunk/modules/implementation-web-runtime/src/main') diff --git a/sca-java-2.x/trunk/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java b/sca-java-2.x/trunk/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java index b4655e3d95..5ba08ab56b 100644 --- a/sca-java-2.x/trunk/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java +++ b/sca-java-2.x/trunk/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java @@ -24,6 +24,13 @@ import javax.servlet.jsp.JspException; import javax.servlet.jsp.PageContext; import javax.servlet.jsp.tagext.TagSupport; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; import org.apache.tuscany.sca.runtime.RuntimeComponent; import org.oasisopen.sca.ServiceReference; @@ -61,6 +68,12 @@ public class ReferenceTag extends TagSupport { throw new JspException("Reference '" + name + "' type class not found: " + type); } + try { + setInterfaceContract(component, typeClass); + } catch (InvalidInterfaceException e) { + throw new JspException("Exception creating interface", e); + } + ServiceReference sr = component.getComponentContext().getServiceReference(typeClass, name); if (sr == null) { throw new JspException("Reference '" + name + "' undefined"); @@ -94,4 +107,22 @@ public class ReferenceTag extends TagSupport { public void setType(String type) { this.type = type; } + + /** + * Implementation.web components currently don't use introspection to find the component type so unless an interface + * is explicitly defined on a refererence with then the InterfaceContract will be null. This will + * check for that and set the InterfaceContract from the Java class of the JSP tag. + */ + private void setInterfaceContract(RuntimeComponent component, Class typeClass) throws InvalidInterfaceException { + ComponentReference ref = component.getReference(name); + if (ref.getInterfaceContract() == null) { + ExtensionPointRegistry epr = component.getComponentContext().getExtensionPointRegistry(); + FactoryExtensionPoint fep = epr.getExtensionPoint(FactoryExtensionPoint.class); + JavaInterfaceFactory jif = fep.getFactory(JavaInterfaceFactory.class); + JavaInterface javaIface = jif.createJavaInterface(typeClass); + InterfaceContract interfaceContract = jif.createJavaInterfaceContract(); + interfaceContract.setInterface(javaIface); + ref.setInterfaceContract(interfaceContract); + } + } } -- cgit v1.2.3