summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/implementation-web-runtime
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2011-04-12 08:50:18 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2011-04-12 08:50:18 +0000
commitfb1ef459f71259a2283c9296006225578d92b7c9 (patch)
tree98e47d1098175f815d6a6cb4621ed1d8c62b927b /sca-java-2.x/trunk/modules/implementation-web-runtime
parent87423aab7566fca6208d26b793a5681ce7cd2954 (diff)
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
Diffstat (limited to 'sca-java-2.x/trunk/modules/implementation-web-runtime')
-rw-r--r--sca-java-2.x/trunk/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java31
1 files changed, 31 insertions, 0 deletions
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 <interface.java> 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);
+ }
+ }
}