tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lrese...@apache.org
Subject svn commit: r1350973 - in /tuscany/sca-java-2.x/trunk/modules/implementation-widget: ./ src/main/java/org/apache/tuscany/sca/implementation/widget/ src/main/java/org/apache/tuscany/sca/implementation/widget/impl/ src/test/java/org/apache/tuscany/sca/im...
Date Sat, 16 Jun 2012 18:13:53 GMT
Author: lresende
Date: Sat Jun 16 18:13:53 2012
New Revision: 1350973

URL: http://svn.apache.org/viewvc?rev=1350973&view=rev
Log:
Refactoring widget uri to avoid conflict with sca component uri

Modified:
    tuscany/sca-java-2.x/trunk/modules/implementation-widget/pom.xml
    tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementation.java
    tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java
    tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationImpl.java
    tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/test/java/org/apache/tuscany/sca/implementation/widget/ImplementationWidgetProcessorTestCase.java

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-widget/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-widget/pom.xml?rev=1350973&r1=1350972&r2=1350973&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-widget/pom.xml (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-widget/pom.xml Sat Jun 16 18:13:53 2012
@@ -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>

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementation.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementation.java?rev=1350973&r1=1350972&r2=1350973&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementation.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementation.java
Sat Jun 16 18:13:53 2012
@@ -61,11 +61,11 @@ public interface WidgetImplementation ex
      * 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);
 }

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java?rev=1350973&r1=1350972&r2=1350973&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java
Sat Jun 16 18:13:53 2012
@@ -29,6 +29,10 @@ import javax.xml.stream.XMLStreamExcepti
 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.contributi
 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.Pr
  */
 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 WidgetImplementationProcess
             //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 WidgetImplementationProcess
             }
 
             //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 WidgetImplementationProcess
             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 WidgetImplementationProcess
      * 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 =

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationImpl.java?rev=1350973&r1=1350972&r2=1350973&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationImpl.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/impl/WidgetImplementationImpl.java
Sat Jun 16 18:13:53 2012
@@ -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.interfaced
  * @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 ex
         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 ex
         widgetService.setInterfaceContract(interfaceContract);
         
         this.getServices().add(widgetService);
+        */
     }
 
     public QName getType() {
@@ -98,17 +95,17 @@ public class WidgetImplementationImpl ex
         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

Modified: tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/test/java/org/apache/tuscany/sca/implementation/widget/ImplementationWidgetProcessorTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/test/java/org/apache/tuscany/sca/implementation/widget/ImplementationWidgetProcessorTestCase.java?rev=1350973&r1=1350972&r2=1350973&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/test/java/org/apache/tuscany/sca/implementation/widget/ImplementationWidgetProcessorTestCase.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/test/java/org/apache/tuscany/sca/implementation/widget/ImplementationWidgetProcessorTestCase.java
Sat Jun 16 18:13:53 2012
@@ -44,7 +44,7 @@ public class ImplementationWidgetProcess
         "<?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 ImplementationWidgetProcess
         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());
         
     }    
 }



Mime
View raw message