Author: antelder
Date: Tue Apr 12 08:50:18 2011
New Revision: 1091326
URL: http://svn.apache.org/viewvc?rev=1091326&view=rev
Log:
handle the case where no interface is defined on implementation.web references
by setting the interface from the JSP tag
Modified:
tuscany/sca-java-2.x/trunk/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java
Modified:
tuscany/sca-java-2.x/trunk/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java?rev=1091326&r1=1091325&r2=1091326&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java
(original)
+++
tuscany/sca-java-2.x/trunk/modules/implementation-web-runtime/src/main/java/org/apache/tuscany/sca/implementation/web/runtime/jsp/ReferenceTag.java
Tue Apr 12 08:50:18 2011
@@ -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 TagSup
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 TagSup
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);
+ }
+ }
}