tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sl...@apache.org
Subject svn commit: r1127474 - in /tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain: CompositeArtifactView.java CompositeArtifactViewImpl.java CompositeView.java CompositeViewImpl.java
Date Wed, 25 May 2011 10:58:30 GMT
Author: slaws
Date: Wed May 25 10:58:30 2011
New Revision: 1127474

URL: http://svn.apache.org/viewvc?rev=1127474&view=rev
Log:
Fiddling about with making the composite artifact path do something

Modified:
    tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeArtifactView.java
    tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeArtifactViewImpl.java
    tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeView.java
    tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeViewImpl.java

Modified: tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeArtifactView.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeArtifactView.java?rev=1127474&r1=1127473&r2=1127474&view=diff
==============================================================================
--- tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeArtifactView.java
(original)
+++ tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeArtifactView.java
Wed May 25 10:58:30 2011
@@ -20,6 +20,7 @@
 package org.apache.tuscany.sca.domain;
 
 import javax.ws.rs.GET;
+import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;

Modified: tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeArtifactViewImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeArtifactViewImpl.java?rev=1127474&r1=1127473&r2=1127474&view=diff
==============================================================================
--- tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeArtifactViewImpl.java
(original)
+++ tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeArtifactViewImpl.java
Wed May 25 10:58:30 2011
@@ -25,6 +25,14 @@ import java.util.List;
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.xml.Utils;
+import org.apache.tuscany.sca.runtime.DomainRegistry;
+
 /**
  * Some hand crafted HTTP code to help me think about what info is missing
  * from the domain registry
@@ -32,33 +40,86 @@ import javax.ws.rs.core.UriInfo;
 public class CompositeArtifactViewImpl implements CompositeArtifactView {
     
     private String domainName;
+    private Composite composite;
+    private String artifacturi;
     
-    public CompositeArtifactViewImpl(String domainName){
+    public CompositeArtifactViewImpl(String domainName, Composite composite, String artifacturi){
         this.domainName = domainName;
+        this.composite = composite;
+        this.artifacturi = artifacturi;
     }
     
     public String get(UriInfo uriInfo){
-        Iterator<PathSegment> pathSegmentsIter = uriInfo.getPathSegments().iterator();
+        if (composite == null){
+            return "<p/>composite not found";
+        }
+        
+        String[] artifactNames = artifacturi.split("/");
+        
+        Component component = null;
+        Service service = null;
+        Reference reference = null;
+        Binding binding = null;
+        
+        // iterate down the artifact uri
+        for (int i=0; i < artifactNames.length; i++){
+            String name = artifactNames[i];
+            
+            if (service != null) {
+                binding = service.getBinding(name);
+                break;
+            } else if (reference != null){
+                binding = reference.getBinding(name);
+                break;
+            }
+            
+            if (component != null) {
+                service = component.getService(name); 
+                reference = component.getReference(name);
+            } 
+            
+            component = composite.getComponent(name);
+        }
+        
+        // not sure how to print out the artifacts
+        if (binding != null){
+            return "<p/><textarea rows=\"40\" cols=\"80\">" +
+                   Utils.modelToXML(binding, true, DomainViewRunner.extensionPointRegistry)
+
+                   "</textarea>";
+        }
+        
+        if (service != null){
+            /* need to register stax processors for this to work
+            return "<p/><textarea rows=\"40\" cols=\"80\">" +
+                   Utils.modelToXML(service, false, DomainViewRunner.extensionPointRegistry)
+
+                   "</textarea>";
+            */
+            return "Service: " + service.toString();
+        }
+        
+        if (reference != null){
+            /* need to register stax processors for this to work
+            return "<p/><textarea rows=\"40\" cols=\"80\">" +
+                    Utils.modelToXML(reference, false, DomainViewRunner.extensionPointRegistry)
+
+                    "</textarea>";
+            */
+            return "Reference: " + reference.toString();
+        }
         
-        // get past the sca/domain/domainname/composite/compositename segments
-        pathSegmentsIter.next();
-        pathSegmentsIter.next();
-        pathSegmentsIter.next();
-        pathSegmentsIter.next();
-        pathSegmentsIter.next();
-        
-        // now expecting componentname/componentname/componentname/service or reference/binding
       
-        while (pathSegmentsIter.hasNext()){
-            pathSegmentsIter.next();
+        if (component != null){
+            /* need to register stax processors for this to work
+            return "<p/><textarea rows=\"40\" cols=\"80\">" +
+                   Utils.modelToXML(component, false, DomainViewRunner.extensionPointRegistry)
+
+                   "</textarea>";
+            */
+            return "Component: " + component.toString();
         }
         
-        // get list of pairs of artifact type and name
-        return "Yippeeeee! Show the composite artifact at " + uriInfo.getPath();
+        return "artifact " + artifacturi + " not found in composite " + composite.getURI();
     }
     
-    class Artifact {
-        public String type;
-        public String name;
+    public Component findComponent(Composite composite, String name){
+        return composite.getComponent(name);
     }
         
 }
\ No newline at end of file

Modified: tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeView.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeView.java?rev=1127474&r1=1127473&r2=1127474&view=diff
==============================================================================
--- tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeView.java
(original)
+++ tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeView.java
Wed May 25 10:58:30 2011
@@ -41,7 +41,11 @@ public interface CompositeView {
     @Path("{compositename}")                
     public String getComposite(@PathParam("compositename") String compositeName, @Context
UriInfo uriInfo);
     
-    @Path("{compositename}/{compositeartifact}")                
-    public CompositeArtifactView getCompositeArtifact();   
+    // Hack to make it call this with any path added to the end of the composite name
+    // Want the user to be able to do something like
+    // http://localhost:80/sca/domain/mydomain/composite/mycomposite/component1/component2/service1
+    @Path("{compositename}/{artifacturi:.*}")                
+    public CompositeArtifactView getCompositeArtifact(@PathParam("compositename") String
compositeName,
+                                                      @PathParam("artifacturi") String artifacturi);
  
     
 }
\ No newline at end of file

Modified: tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeViewImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeViewImpl.java?rev=1127474&r1=1127473&r2=1127474&view=diff
==============================================================================
--- tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeViewImpl.java
(original)
+++ tuscany/sandbox/slaws/domain-view/src/main/java/org/apache/tuscany/sca/domain/CompositeViewImpl.java
Wed May 25 10:58:30 2011
@@ -51,21 +51,31 @@ public class CompositeViewImpl implement
     }      
     
     public String getComposite(String compositeName, UriInfo uriInfo) {
+        Composite composite = getComposite(compositeName);
+        if(composite != null){
+            return "<p/><textarea rows=\"40\" cols=\"80\">" +
+                   Utils.modelToXML(composite, true, DomainViewRunner.extensionPointRegistry)
+
+                  "</textarea>";
+        } else {
+            return "<p/>composite not found";
+        }
+    }
+    
+    public CompositeArtifactView getCompositeArtifact(String compositeName, String artifacturi){
+        return new CompositeArtifactViewImpl(domainName, getComposite(compositeName), artifacturi);
+    }
+     
+    // utlilities
+    
+    public Composite getComposite(String compositeName){
         DomainRegistry domainRegistry = DomainViewRunner.domainRegistry;
         Composite composite = domainRegistry.getDomainComposite();
         for (Composite tmpComposite : composite.getIncludes()){
             if (tmpComposite.getName().getLocalPart().equals(compositeName)){
-                return "<p/><textarea rows=\"40\" cols=\"80\">" +
-                       Utils.modelToXML(tmpComposite, true, DomainViewRunner.extensionPointRegistry)
+
-                       "</textarea>";
+                return tmpComposite;
             }
         }
         
-        return "<p/>composite not found";
-    } 
-    
-    public CompositeArtifactView getCompositeArtifact(){
-        return new CompositeArtifactViewImpl(domainName);
+        return null;
     }
-        
 }
\ No newline at end of file



Mime
View raw message