diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-18 22:08:31 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-18 22:08:31 +0000 |
commit | a50e7af29c5695006c4227d4d7e36cf99eff254a (patch) | |
tree | 55d45d6bde1743c8aa52fea8ccbd499e9bacecb1 /java | |
parent | 94a10d9659412aec93dcf1214ac6d57fb7704fc4 (diff) |
Updating implementation.widget to properly resolve targetEndpoints to find binding information and properly generate JavaScript client proxies
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@881960 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
8 files changed, 151 insertions, 74 deletions
diff --git a/java/sca/modules/binding-atom-js-dojo/src/main/java/org/apache/tuscany/sca/binding/atom/js/dojo/AtomBindingJavascriptProxyFactoryImpl.java b/java/sca/modules/binding-atom-js-dojo/src/main/java/org/apache/tuscany/sca/binding/atom/js/dojo/AtomBindingJavascriptProxyFactoryImpl.java index 349f76c437..b67500152e 100644 --- a/java/sca/modules/binding-atom-js-dojo/src/main/java/org/apache/tuscany/sca/binding/atom/js/dojo/AtomBindingJavascriptProxyFactoryImpl.java +++ b/java/sca/modules/binding-atom-js-dojo/src/main/java/org/apache/tuscany/sca/binding/atom/js/dojo/AtomBindingJavascriptProxyFactoryImpl.java @@ -27,7 +27,10 @@ import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.binding.atom.AtomBinding; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; import org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory; public class AtomBindingJavascriptProxyFactoryImpl implements JavascriptProxyFactory { @@ -50,7 +53,17 @@ public class AtomBindingJavascriptProxyFactoryImpl implements JavascriptProxyFac } public String createJavascriptReference(ComponentReference componentReference) throws IOException { - Binding binding = componentReference.getBindings().get(0); + EndpointReference epr = componentReference.getEndpointReferences().get(0); + Endpoint targetEndpoint = epr.getTargetEndpoint(); + if (targetEndpoint.isUnresolved()) { + //force resolution and targetEndpoint binding calculations + //by calling the getInvocationChain + ((RuntimeEndpointReference) epr).getInvocationChains(); + targetEndpoint = epr.getTargetEndpoint(); + } + + Binding binding = targetEndpoint.getBinding(); + URI targetURI = URI.create(binding.getURI()); String targetPath = targetURI.getPath(); diff --git a/java/sca/modules/binding-jsonrpc-js-dojo/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/js/dojo/JSONRPCBindingJavascriptProxyFactoryImpl.java b/java/sca/modules/binding-jsonrpc-js-dojo/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/js/dojo/JSONRPCBindingJavascriptProxyFactoryImpl.java index ee47d2243c..fc4d7a2318 100644 --- a/java/sca/modules/binding-jsonrpc-js-dojo/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/js/dojo/JSONRPCBindingJavascriptProxyFactoryImpl.java +++ b/java/sca/modules/binding-jsonrpc-js-dojo/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/js/dojo/JSONRPCBindingJavascriptProxyFactoryImpl.java @@ -27,7 +27,10 @@ import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBinding; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; import org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory; public class JSONRPCBindingJavascriptProxyFactoryImpl implements JavascriptProxyFactory { @@ -50,7 +53,17 @@ public class JSONRPCBindingJavascriptProxyFactoryImpl implements JavascriptProxy } public String createJavascriptReference(ComponentReference componentReference) throws IOException { - Binding binding = componentReference.getBindings().get(0); + EndpointReference epr = componentReference.getEndpointReferences().get(0); + Endpoint targetEndpoint = epr.getTargetEndpoint(); + if (targetEndpoint.isUnresolved()) { + //force resolution and targetEndpoint binding calculations + //by calling the getInvocationChain + ((RuntimeEndpointReference) epr).getInvocationChains(); + targetEndpoint = epr.getTargetEndpoint(); + } + + Binding binding = targetEndpoint.getBinding(); + URI targetURI = URI.create(binding.getURI()); String targetPath = targetURI.getPath(); diff --git a/java/sca/modules/implementation-widget-runtime-dojo/src/main/java/org/apache/tuscany/sca/implementation/widget/dojo/DojoJavaScriptComponentGeneratorImpl.java b/java/sca/modules/implementation-widget-runtime-dojo/src/main/java/org/apache/tuscany/sca/implementation/widget/dojo/DojoJavaScriptComponentGeneratorImpl.java index 28e8f81810..4aede2806f 100644 --- a/java/sca/modules/implementation-widget-runtime-dojo/src/main/java/org/apache/tuscany/sca/implementation/widget/dojo/DojoJavaScriptComponentGeneratorImpl.java +++ b/java/sca/modules/implementation-widget-runtime-dojo/src/main/java/org/apache/tuscany/sca/implementation/widget/dojo/DojoJavaScriptComponentGeneratorImpl.java @@ -30,8 +30,11 @@ import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.Binding; import org.apache.tuscany.sca.assembly.ComponentProperty; import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.Endpoint; +import org.apache.tuscany.sca.assembly.EndpointReference; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeEndpointReference; import org.apache.tuscany.sca.web.javascript.ComponentJavaScriptGenerator; import org.apache.tuscany.sca.web.javascript.JavascriptProxyFactory; import org.apache.tuscany.sca.web.javascript.JavascriptProxyFactoryExtensionPoint; @@ -39,11 +42,14 @@ import org.w3c.dom.Document; import org.w3c.dom.Element; public class DojoJavaScriptComponentGeneratorImpl implements ComponentJavaScriptGenerator { - private static final QName NAME = new QName("http://tuscany.apache.org/xmlns/sca/1.0", "component.script.generator.dojo"); + private static final QName NAME = new QName("http://tuscany.apache.org/xmlns/sca/1.1", "component.script.generator.dojo"); + + private ExtensionPointRegistry extensionPoints; private JavascriptProxyFactoryExtensionPoint javascriptProxyFactories; public DojoJavaScriptComponentGeneratorImpl(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; this.javascriptProxyFactories = extensionPoints.getExtensionPoint(JavascriptProxyFactoryExtensionPoint.class); } @@ -59,19 +65,29 @@ public class DojoJavaScriptComponentGeneratorImpl implements ComponentJavaScript Map<String, Boolean> bindingClientProcessed = new HashMap<String, Boolean>(); for(ComponentReference reference : component.getReferences()) { - for(Binding binding : reference.getBindings()) { - JavascriptProxyFactory jsProxyFactory = javascriptProxyFactories.getProxyFactory(binding.getClass()); - - String bindingProxyName = jsProxyFactory.getJavascriptProxyFile(); - //check if binding client code was already processed and inject to the generated script - if(bindingProxyName != null) { - Boolean processedFlag = bindingClientProcessed.get(bindingProxyName); - if( processedFlag == null || processedFlag.booleanValue() == false) { - generateJavaScriptBindingProxy(jsProxyFactory, pw); - bindingClientProcessed.put(bindingProxyName, Boolean.TRUE); - } + for(EndpointReference epr : reference.getEndpointReferences()) { + Endpoint targetEndpoint = epr.getTargetEndpoint(); + if (targetEndpoint.isUnresolved()) { + //force resolution and targetEndpoint binding calculations + //by calling the getInvocationChain + ((RuntimeEndpointReference) epr).getInvocationChains(); + targetEndpoint = epr.getTargetEndpoint(); + } + + Binding binding = targetEndpoint.getBinding(); + if (binding != null) { + JavascriptProxyFactory jsProxyFactory = javascriptProxyFactories.getProxyFactory(binding.getClass()); + + String bindingProxyName = jsProxyFactory.getJavascriptProxyFile(); + //check if binding client code was already processed and inject to the generated script + if(bindingProxyName != null) { + Boolean processedFlag = bindingClientProcessed.get(bindingProxyName); + if( processedFlag == null || processedFlag.booleanValue() == false) { + generateJavaScriptBindingProxy(jsProxyFactory, pw); + bindingClientProcessed.put(bindingProxyName, Boolean.TRUE); + } + } } - } } @@ -188,15 +204,22 @@ public class DojoJavaScriptComponentGeneratorImpl implements ComponentJavaScript pw.println("__tus.sca.referenceMap = {};"); for(ComponentReference reference : component.getReferences()) { - Binding binding = reference.getBindings().get(0); - - if (binding != null) { - - String referenceName = reference.getName(); - JavascriptProxyFactory jsProxyFactory = javascriptProxyFactories.getProxyFactory(binding.getClass()); - - pw.println("__tus.sca.referenceMap." + referenceName + " = new " + jsProxyFactory.createJavascriptReference(reference) + ";"); + for(EndpointReference epr : reference.getEndpointReferences()) { + Endpoint targetEndpoint = epr.getTargetEndpoint(); + if (targetEndpoint.isUnresolved()) { + //force resolution and targetEndpoint binding calculations + //by calling the getInvocationChain + ((RuntimeEndpointReference) epr).getInvocationChains(); + targetEndpoint = epr.getTargetEndpoint(); + } + Binding binding = targetEndpoint.getBinding(); + if (binding != null) { + String referenceName = reference.getName(); + JavascriptProxyFactory jsProxyFactory = javascriptProxyFactories.getProxyFactory(binding.getClass()); + + pw.println("__tus.sca.referenceMap." + referenceName + " = new " + jsProxyFactory.createJavascriptReference(reference) + ";"); + } } } diff --git a/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/Widget.java b/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/Widget.java index ff181d35c0..f1c1c36934 100644 --- a/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/Widget.java +++ b/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/Widget.java @@ -22,6 +22,7 @@ package org.apache.tuscany.sca.implementation.widget; import java.io.InputStream; import org.apache.tuscany.sca.data.collection.Collection; +import org.oasisopen.sca.annotation.Remotable; /** * The service interface of widget implementations. This is not an API for application @@ -30,6 +31,8 @@ import org.apache.tuscany.sca.data.collection.Collection; * * @version $Rev$ $Date$ */ + +@Remotable public interface Widget extends Collection<String, InputStream> { } diff --git a/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationIntrospector.java b/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationIntrospector.java index dfffcfd5b5..9bf8c05d73 100644 --- a/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationIntrospector.java +++ b/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationIntrospector.java @@ -26,6 +26,8 @@ import java.util.Scanner; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Property; import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; /** * A HTML Widget Introspector used to introspect references and property @@ -40,9 +42,10 @@ class WidgetImplementationIntrospector { private AssemblyFactory assemblyFactory; private WidgetImplementation widgetImplementation; - WidgetImplementationIntrospector(AssemblyFactory assemblyFactory, WidgetImplementation widgetImplementation) { + WidgetImplementationIntrospector(ExtensionPointRegistry registry, WidgetImplementation widgetImplementation ) { + FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); + this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); this.widgetImplementation = widgetImplementation; - this.assemblyFactory = assemblyFactory; } diff --git a/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java b/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java index f15a060216..d4896b8d0a 100644 --- a/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java +++ b/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java @@ -28,7 +28,6 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; -import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.ContributionFactory; import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; @@ -38,6 +37,7 @@ import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; import org.apache.tuscany.sca.contribution.processor.ProcessorContext; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.Problem; @@ -50,45 +50,17 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; * @version $Rev$ $Date$ */ public class WidgetImplementationProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<WidgetImplementation> { - private AssemblyFactory assemblyFactory; + private ExtensionPointRegistry registry; private ContributionFactory contributionFactory; private WidgetImplementationFactory implementationFactory; - private Monitor monitor; - public WidgetImplementationProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { - assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + public WidgetImplementationProcessor(ExtensionPointRegistry registry) { + this.registry = registry; + FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); contributionFactory = modelFactories.getFactory(ContributionFactory.class); implementationFactory = modelFactories.getFactory(WidgetImplementationFactory.class); - this.monitor = monitor; - } - - /** - * Report a exception. - * - * @param problems - * @param message - * @param model - */ - private void error(String message, Object model, Exception ex) { - if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "impl-widget-validation-messages", Severity.ERROR, model, message, ex); - monitor.problem(problem); - } - } - - /** - * Report a error. - * - * @param problems - * @param message - * @param model - */ - private void error(String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "impl-widget-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); - monitor.problem(problem); - } } + public QName getArtifactType() { // Returns the QName of the XML element processed by this processor @@ -114,7 +86,7 @@ public class WidgetImplementationProcessor extends BaseStAXArtifactProcessor imp implementation.setLocation(location); implementation.setUnresolved(true); } else { - error("LocationAttributeMissing", reader); + error(context.getMonitor(), "LocationAttributeMissing", reader); //throw new ContributionReadException(MSG_LOCATION_MISSING); } @@ -141,17 +113,17 @@ public class WidgetImplementationProcessor extends BaseStAXArtifactProcessor imp //introspect implementation WidgetImplementationIntrospector widgetIntrospector = - new WidgetImplementationIntrospector(assemblyFactory, implementation); + new WidgetImplementationIntrospector(registry, implementation); widgetIntrospector.introspectImplementation(); implementation.setUnresolved(false); } catch (IOException e) { ContributionResolveException ce = new ContributionResolveException(e); - error("ContributionResolveException", resolver, ce); + error(context.getMonitor(), "ContributionResolveException", resolver, ce); //throw ce; } } else { - error("CouldNotResolveLocation", resolver, implementation.getLocation()); + error(context.getMonitor(), "CouldNotResolveLocation", resolver, implementation.getLocation()); //throw new ContributionResolveException("Could not resolve implementation.widget location: " + implementation.getLocation()); } } @@ -167,4 +139,50 @@ public class WidgetImplementationProcessor extends BaseStAXArtifactProcessor imp writeEnd(writer); } + + /** + * Utility methods + */ + + + /** + * Report a error. + * + * @param problems + * @param message + * @param model + */ + private void error(Monitor monitor, String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = + monitor.createProblem(this.getClass().getName(), + "impl-widget-validation-messages", + Severity.ERROR, + model, + message, + (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(Monitor monitor, String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = + monitor.createProblem(this.getClass().getName(), + "impl-widget-validation-messages", + Severity.ERROR, + model, + message, + ex); + monitor.problem(problem); + } + } + } diff --git a/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationFactoryImpl.java b/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationFactoryImpl.java index 626e8f1bc0..960a01d07e 100644 --- a/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationFactoryImpl.java +++ b/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationFactoryImpl.java @@ -19,11 +19,9 @@ package org.apache.tuscany.sca.implementation.widget.impl; -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.implementation.widget.WidgetImplementation; import org.apache.tuscany.sca.implementation.widget.WidgetImplementationFactory; -import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; /** * Factory for the widget implementation model. @@ -32,16 +30,14 @@ import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; */ public class WidgetImplementationFactoryImpl implements WidgetImplementationFactory { - private AssemblyFactory assemblyFactory; - private JavaInterfaceFactory javaFactory; + private ExtensionPointRegistry registry; - public WidgetImplementationFactoryImpl(FactoryExtensionPoint modelFactories) { - assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); - javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); + public WidgetImplementationFactoryImpl(ExtensionPointRegistry registry) { + this.registry = registry; } public WidgetImplementation createWidgetImplementation() { - return new WidgetImplementationImpl(assemblyFactory, javaFactory); + return new WidgetImplementationImpl(registry); } } diff --git a/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationImpl.java b/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationImpl.java index de86aa9196..7bdecc2c3a 100644 --- a/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationImpl.java +++ b/java/sca/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationImpl.java @@ -25,6 +25,8 @@ import javax.xml.namespace.QName; import org.apache.tuscany.sca.assembly.AssemblyFactory; import org.apache.tuscany.sca.assembly.Service; import org.apache.tuscany.sca.assembly.impl.ImplementationImpl; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.FactoryExtensionPoint; import org.apache.tuscany.sca.implementation.widget.Widget; import org.apache.tuscany.sca.implementation.widget.WidgetImplementation; import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; @@ -47,11 +49,14 @@ public class WidgetImplementationImpl extends ImplementationImpl implements Widg /** * Constructs a new resource implementation. */ - WidgetImplementationImpl(AssemblyFactory assemblyFactory, - JavaInterfaceFactory javaFactory) { + WidgetImplementationImpl(ExtensionPointRegistry registry) { super(TYPE); + FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + JavaInterfaceFactory javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); + // Resource implementation always provide a single service exposing // the Resource interface, and have no references and properties widgetService = assemblyFactory.createService(); @@ -67,6 +72,8 @@ public class WidgetImplementationImpl extends ImplementationImpl implements Widg JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract(); interfaceContract.setInterface(javaInterface); widgetService.setInterfaceContract(interfaceContract); + + this.getServices().add(widgetService); } public QName getType() { @@ -99,6 +106,7 @@ public class WidgetImplementationImpl extends ImplementationImpl implements Widg this.locationUrl = url; } + @Override public String toString() { return "Widget : " + getLocation(); |