You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2008/08/06 23:06:35 UTC

svn commit: r683412 - in /tuscany/java/sca/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl: CompositeConfigurationServiceImpl.java DeployedCompositeCollectionImpl.java

Author: jsdelfino
Date: Wed Aug  6 14:06:34 2008
New Revision: 683412

URL: http://svn.apache.org/viewvc?rev=683412&view=rev
Log:
Removed obsolete method from DeployedCompositeCollection component implementation. Improved CompositeConfigurationService, added the ability to return the configuration of a nested composite.

Modified:
    tuscany/java/sca/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeConfigurationServiceImpl.java
    tuscany/java/sca/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployedCompositeCollectionImpl.java

Modified: tuscany/java/sca/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeConfigurationServiceImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeConfigurationServiceImpl.java?rev=683412&r1=683411&r2=683412&view=diff
==============================================================================
--- tuscany/java/sca/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeConfigurationServiceImpl.java (original)
+++ tuscany/java/sca/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/CompositeConfigurationServiceImpl.java Wed Aug  6 14:06:34 2008
@@ -118,6 +118,7 @@
     private AssemblyFactory assemblyFactory;
     private WorkspaceFactory workspaceFactory;
     private URLArtifactProcessor<Contribution> contributionProcessor;
+    private StAXArtifactProcessorExtensionPoint staxProcessors;
     private StAXArtifactProcessor<Composite> compositeProcessor;
     private XMLOutputFactory outputFactory;
     private ContributionDependencyBuilder contributionDependencyBuilder;
@@ -148,7 +149,7 @@
         workspaceFactory = modelFactories.getFactory(WorkspaceFactory.class);
         
         // Get and initialize artifact processors
-        StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+        staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
         compositeProcessor = (StAXArtifactProcessor<Composite>)staxProcessors.getProcessor(Composite.class);
         StAXArtifactProcessor<Object> staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, monitor);
 
@@ -174,18 +175,38 @@
         
         // Get the request path
         String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8");
-        String key = path.startsWith("/")? path.substring(1) : path;
+        String key;
+        if (path.startsWith("/")) {
+            if (path.length() > 1) {
+                key = path.substring(1);
+            } else {
+                key ="";
+            }
+        } else {
+            key =path;
+        }
         logger.fine("get " + key);
         
-        // Expect a key in the form
-        // composite:contributionURI;namespace;localName
+        // Expect a key in the form composite:contributionURI;namespace;localName or
+        // a path in the form componentName/componentName/...
         // and return the corresponding resolved composite
-        
-        // Extract the composite qname from the key
-        QName qname = compositeQName(key);
+        String requestedContributionURI = null;
+        QName requestedCompositeName = null;
+        String[] requestedComponentPath = null;
+        if (key.startsWith("composite:")) {
+            
+            // Extract the composite qname from the key
+            requestedContributionURI = contributionURI(key);
+            requestedCompositeName = compositeQName(key);
+            
+        } else if (key.length() != 0) {
+            
+            // Extract the path to the requested component from the key
+            requestedComponentPath = key.split("/");
+        }
         
         // Somewhere to store the composite we expect to write out at the end
-        Composite compositeConfiguration = null;
+        Composite requestedComposite = null;
 
         // Create a domain composite model
         Composite domainComposite = assemblyFactory.createComposite();
@@ -261,14 +282,16 @@
                 response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
             }
             
-            // store away the composite we are generating the deployable XML for. 
-            if (qname.equals(deployable.getName())){
-                compositeConfiguration = deployable;
+            // Store away the requested composite  
+            if (requestedCompositeName != null) {
+                if (requestedContributionURI.equals(contributionURI) && requestedCompositeName.equals(deployable.getName())){
+                    requestedComposite = deployable;
+                }
             }
         }
         
-        // Composite not found
-        if (compositeConfiguration == null) {
+        // The requested composite was not found
+        if (requestedCompositeName != null && requestedComposite == null) {
             response.sendError(HttpServletResponse.SC_NOT_FOUND, key);
             return;
         }
@@ -325,30 +348,85 @@
             response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
             return;
         }        
-        
-        // Rebuild the requested composite from the domain composite
-        // we have to reverse the flattening that went on when the domain
-        // composite was built
-        List<Component> tempComponentList = new ArrayList<Component>();
-        tempComponentList.addAll(compositeConfiguration.getComponents());
-        compositeConfiguration.getComponents().clear();
-        for (Component inputComponent : tempComponentList){
-            for (Component deployComponent : domainComposite.getComponents()){
-                if (deployComponent.getName().equals(inputComponent.getName())){
-                    compositeConfiguration.getComponents().add(deployComponent);
+
+        // Return the requested composite
+        if (requestedComposite != null) {
+            
+            // Rebuild the requested composite from the domain composite
+            // we have to reverse the flattening that went on when the domain
+            // composite was built
+            List<Component> tempComponentList = new ArrayList<Component>();
+            tempComponentList.addAll(requestedComposite.getComponents());
+            requestedComposite.getComponents().clear();
+            for (Component inputComponent : tempComponentList){
+                for (Component deployComponent : domainComposite.getComponents()){
+                    if (deployComponent.getName().equals(inputComponent.getName())){
+                        requestedComposite.getComponents().add(deployComponent);
+                    }
                 }
             }
+            
+        } else if (requestedComponentPath != null) {
+            
+            // If a component path was specified, walk the path to get to the requested
+            // component and the composite that implements it
+            Composite nestedComposite = domainComposite;
+            for (String componentName: requestedComponentPath) {
+                Component component = null;
+                for (Component c: nestedComposite.getComponents()) {
+                    if (componentName.equals(c.getName())) {
+                        component = c;
+                        break;
+                    }
+                }
+                if (component == null) {
+                    response.sendError(HttpServletResponse.SC_NOT_FOUND, key);
+                    return;
+                } else {
+                    if (component.getImplementation() instanceof Composite) {
+                        nestedComposite = (Composite)component.getImplementation();
+                    } else {
+                        response.sendError(HttpServletResponse.SC_NOT_FOUND, key);
+                        return;
+                    }
+                }
+            }
+            
+            // Return the nested composite
+            requestedComposite = nestedComposite;
+            
+        } else {
+            
+            
+            // Return the whole domain composite
+            requestedComposite = domainComposite;
         }
         
-        // Write the deployable composite
+        // Write the composite in the requested format
+        StAXArtifactProcessor<Composite> processor;
+        String queryString = request.getQueryString();
+        if (queryString != null && queryString.startsWith("format=")) {
+            String format = queryString.substring(7);
+            int s = format.indexOf(';');
+            QName formatName = new QName(format.substring(0, s), format.substring(s +1));
+            processor = (StAXArtifactProcessor<Composite>)staxProcessors.getProcessor(formatName);
+            if (processor == null) {
+                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, new IllegalArgumentException(queryString).toString());
+                return;
+            }
+        } else {
+            processor = compositeProcessor;
+        }
         try {
             response.setContentType("text/xml");
             XMLStreamWriter writer = outputFactory.createXMLStreamWriter(response.getOutputStream());
-            compositeProcessor.write(compositeConfiguration, writer);
+            processor.write(requestedComposite, writer);
         } catch (Exception e) {
             response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
             return;
         }
+        
+        
     }
 
     /**

Modified: tuscany/java/sca/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployedCompositeCollectionImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployedCompositeCollectionImpl.java?rev=683412&r1=683411&r2=683412&view=diff
==============================================================================
--- tuscany/java/sca/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployedCompositeCollectionImpl.java (original)
+++ tuscany/java/sca/modules/domain-manager/src/main/java/org/apache/tuscany/sca/domain/manager/impl/DeployedCompositeCollectionImpl.java Wed Aug  6 14:06:34 2008
@@ -30,25 +30,14 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.logging.Logger;
 
-import javax.servlet.Servlet;
-import javax.servlet.ServletException;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -86,10 +75,8 @@
  * @version $Rev$ $Date$
  */
 @Scope("COMPOSITE")
-@Service(interfaces={ItemCollection.class,LocalItemCollection.class, Servlet.class})
-public class DeployedCompositeCollectionImpl extends HttpServlet implements ItemCollection, LocalItemCollection {
-    private static final long serialVersionUID = -3477992129462720901L;
-
+@Service(interfaces={ItemCollection.class,LocalItemCollection.class})
+public class DeployedCompositeCollectionImpl implements ItemCollection, LocalItemCollection {
     private static final Logger logger = Logger.getLogger(DeployedCompositeCollectionImpl.class.getName());
 
     @Property
@@ -188,54 +175,6 @@
         throw new NotFoundException(key);
     }
     
-    @Override
-    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-
-        // Expect a key in the form
-        // composite:contributionURI;namespace;localName
-        // and return the corresponding source file
-        
-        // Get the request path
-        String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8");
-        String key = path.startsWith("/")? path.substring(1) : path;
-        logger.fine("get " + key);
-        
-        // Get the item describing the composite
-        Item item;
-        try {
-            item = deployableCollection.get(key);
-        } catch (NotFoundException e) {
-            response.sendError(HttpServletResponse.SC_NOT_FOUND, key);
-            return;
-        }
-
-        // Read the composite file and write to response
-        String uri = item.getAlternate();
-        InputStream is;
-        try {
-            URLConnection connection = new URL(uri).openConnection();
-            connection.setUseCaches(false);
-            connection.connect();
-            is = connection.getInputStream();
-        } catch (FileNotFoundException ex) {
-            response.sendError(HttpServletResponse.SC_NOT_FOUND, key);
-            return;
-        }
-
-        response.setContentType("text/xml");
-        ServletOutputStream os = response.getOutputStream();
-        byte[] buffer = new byte[4096];
-        for (;;) {
-            int n = is.read(buffer);
-            if (n < 0) {
-                break;
-            }
-            os.write(buffer, 0, n);
-        }
-        is.close();
-        os.flush();
-    }
-
     public String post(String key, Item item) {
         logger.fine("post " + key);