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
This commit is contained in:
parent
94a10d9659
commit
a50e7af29c
8 changed files with 151 additions and 74 deletions
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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) + ";");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue