diff options
Diffstat (limited to 'sca-java-2.x/trunk')
5 files changed, 72 insertions, 24 deletions
diff --git a/sca-java-2.x/trunk/modules/implementation-widget/pom.xml b/sca-java-2.x/trunk/modules/implementation-widget/pom.xml index aafefaf25e..2f2c209c02 100644 --- a/sca-java-2.x/trunk/modules/implementation-widget/pom.xml +++ b/sca-java-2.x/trunk/modules/implementation-widget/pom.xml @@ -55,6 +55,12 @@ </dependency> <dependency> + <groupId>org.apache.tuscany.sca</groupId> + <artifactId>tuscany-binding-http</artifactId> + <version>2.0-SNAPSHOT</version> + </dependency> + + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.8.1</version> diff --git a/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementation.java b/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementation.java index 3f0480ab78..bcec05ae5a 100644 --- a/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementation.java +++ b/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementation.java @@ -61,11 +61,11 @@ public interface WidgetImplementation extends Implementation { * Get the widget URI * @return the uri */ - String getUri(); + String getWidgetUri(); /** * Set the widget URI, used to automatically add a binding to the widget * @param uri the uri */ - void setUri(String uri); + void setWidgetUri(String uri); } diff --git a/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java b/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java index ab278c4923..9036f90db9 100644 --- a/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java +++ b/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java @@ -29,6 +29,10 @@ 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.assembly.Service; +import org.apache.tuscany.sca.binding.http.HTTPBinding; +import org.apache.tuscany.sca.binding.http.HTTPBindingFactory; import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.ContributionFactory; import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; @@ -40,9 +44,14 @@ 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.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; import org.apache.tuscany.sca.monitor.Monitor; import org.apache.tuscany.sca.monitor.Problem; import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.oasisopen.sca.ServiceRuntimeException; /** * @@ -52,13 +61,19 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; */ public class WidgetImplementationProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<WidgetImplementation> { private ExtensionPointRegistry registry; + private AssemblyFactory assemblyFactory; private ContributionFactory contributionFactory; + private HTTPBindingFactory httpBindingFactory; + private JavaInterfaceFactory javaInterfaceFactory; private WidgetImplementationFactory implementationFactory; public WidgetImplementationProcessor(ExtensionPointRegistry registry) { this.registry = registry; FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); + assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); contributionFactory = modelFactories.getFactory(ContributionFactory.class); + httpBindingFactory = modelFactories.getFactory(HTTPBindingFactory.class); + javaInterfaceFactory = modelFactories.getFactory(JavaInterfaceFactory.class); implementationFactory = modelFactories.getFactory(WidgetImplementationFactory.class); } @@ -89,9 +104,9 @@ public class WidgetImplementationProcessor extends BaseStAXArtifactProcessor imp //throw new ContributionReadException(MSG_LOCATION_MISSING); } - String uri = getURIString(reader, "uri"); - if(uri != null && uri.isEmpty() == false) { - implementation.setUri(uri); + String widgetUri = getURIString(reader, "widgetUri"); + if(widgetUri != null && widgetUri.isEmpty() == false) { + implementation.setWidgetUri(widgetUri); } else { warning(context.getMonitor(), "UocationAttributeMissing", reader); } @@ -152,12 +167,15 @@ public class WidgetImplementationProcessor extends BaseStAXArtifactProcessor imp } //introspect implementation - WidgetImplementationIntrospector widgetIntrospector = - new WidgetImplementationIntrospector(registry, implementation); + WidgetImplementationIntrospector widgetIntrospector = new WidgetImplementationIntrospector(registry, implementation); widgetIntrospector.introspectImplementation(); implementation.setUnresolved(false); + if(implementation.getWidgetUri() != null && implementation.getWidgetUri().isEmpty() == false) { + System.out.println(">>>Adding service to widget " + implementation); + addService(implementation); + } if (implementation.isUnresolved()) { @@ -175,8 +193,8 @@ public class WidgetImplementationProcessor extends BaseStAXArtifactProcessor imp writer.writeAttribute("location", implementation.getLocation()); } - if (implementation.getUri() != null && implementation.getUri().isEmpty() == false) { - writer.writeAttribute("uri", implementation.getUri()); + if (implementation.getWidgetUri() != null && implementation.getWidgetUri().isEmpty() == false) { + writer.writeAttribute("widgetUri", implementation.getWidgetUri()); } writeEnd(writer); @@ -186,6 +204,33 @@ public class WidgetImplementationProcessor extends BaseStAXArtifactProcessor imp * Utility methods */ + private void addService(WidgetImplementation implementation) { + Service widgetService = null; + + // Resource implementation always provide a single service exposing + // the Resource interface, and have no references and properties + widgetService = assemblyFactory.createService(); + widgetService.setName("Widget"); + + // Create the Java interface contract for the Resource service + JavaInterface javaInterface; + try { + javaInterface = javaInterfaceFactory.createJavaInterface(Widget.class); + } catch (InvalidInterfaceException e) { + throw new IllegalArgumentException(e); + } + JavaInterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract(); + interfaceContract.setInterface(javaInterface); + widgetService.setInterfaceContract(interfaceContract); + + HTTPBinding binding = httpBindingFactory.createHTTPBinding(); + binding.setURI(implementation.getWidgetUri()); + widgetService.getBindings().add(binding); + + implementation.getServices().add(widgetService); + + } + private void warning(Monitor monitor, String message, Object model, Object... messageParameters) { if (monitor != null) { Problem problem = diff --git a/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationImpl.java b/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationImpl.java index e2ecbb8fcb..d4df2654ff 100644 --- a/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationImpl.java +++ b/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationImpl.java @@ -23,15 +23,10 @@ import java.net.URL; 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; -import org.apache.tuscany.sca.interfacedef.java.JavaInterface; -import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; @@ -41,12 +36,12 @@ import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; * @version $Rev$ $Date$ */ public class WidgetImplementationImpl extends ImplementationImpl implements WidgetImplementation { - private Service widgetService; + //private Service widgetService; private String location; private URL locationUrl; - private String uri; + private String widgetUri; /** * Constructs a new resource implementation. @@ -59,6 +54,7 @@ public class WidgetImplementationImpl extends ImplementationImpl implements Widg 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(); @@ -76,6 +72,7 @@ public class WidgetImplementationImpl extends ImplementationImpl implements Widg widgetService.setInterfaceContract(interfaceContract); this.getServices().add(widgetService); + */ } public QName getType() { @@ -98,17 +95,17 @@ public class WidgetImplementationImpl extends ImplementationImpl implements Widg this.locationUrl = url; } - public String getUri() { - return this.uri; + public String getWidgetUri() { + return this.widgetUri; } - public void setUri(String uri) { - this.uri = uri; + public void setWidgetUri(String widgetUri) { + this.widgetUri = widgetUri; } @Override public String toString() { - return "Widget : " + getLocation(); + return "WidgetImplementationImpl [location=" + location + ", widgetUri=" + widgetUri + "]"; } @Override diff --git a/sca-java-2.x/trunk/modules/implementation-widget/src/test/java/org/apache/tuscany/sca/implementation/widget/ImplementationWidgetProcessorTestCase.java b/sca-java-2.x/trunk/modules/implementation-widget/src/test/java/org/apache/tuscany/sca/implementation/widget/ImplementationWidgetProcessorTestCase.java index 8e8f016c01..7e66fa7a8f 100644 --- a/sca-java-2.x/trunk/modules/implementation-widget/src/test/java/org/apache/tuscany/sca/implementation/widget/ImplementationWidgetProcessorTestCase.java +++ b/sca-java-2.x/trunk/modules/implementation-widget/src/test/java/org/apache/tuscany/sca/implementation/widget/ImplementationWidgetProcessorTestCase.java @@ -44,7 +44,7 @@ public class ImplementationWidgetProcessorTestCase { "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\" xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.1\" targetNamespace=\"http://binding-rest\" name=\"binding-rest\">" + " <component name=\"WidgetComponent\">" - + " <tuscany:implementation.widget location=\"ui/widget.html\" uri=\"ui/widget\"/>" + + " <tuscany:implementation.widget location=\"ui/widget.html\" widgetUri=\"ui/widget\"/>" + " </component>" + "</composite>"; @@ -77,8 +77,8 @@ public class ImplementationWidgetProcessorTestCase { Assert.assertNotNull(implementation); Assert.assertNotNull(implementation.getLocation()); Assert.assertEquals("ui/widget.html", implementation.getLocation()); - Assert.assertNotNull(implementation.getUri()); - Assert.assertEquals("ui/widget", implementation.getUri()); + Assert.assertNotNull(implementation.getWidgetUri()); + Assert.assertEquals("ui/widget", implementation.getWidgetUri()); } } |