You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by lr...@apache.org on 2007/05/16 03:52:30 UTC

svn commit: r538401 - in /incubator/tuscany/java/sca/modules: host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/ host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ host-webapp/src/main/java/org/apache/tuscany/sca/weba...

Author: lresende
Date: Tue May 15 18:52:30 2007
New Revision: 538401

URL: http://svn.apache.org/viewvc?view=rev&rev=538401
Log:
Adding support for sca-contribution.xml to defaultSCADomain

Removed:
    incubator/tuscany/java/sca/modules/host-webapp/src/test/java/org/
Modified:
    incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java
    incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java
    incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/webapp/SCADomainHelper.java

Modified: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java?view=diff&rev=538401&r1=538400&r2=538401
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java (original)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java Tue May 15 18:52:30 2007
@@ -45,6 +45,29 @@
     // TODO: Temporary support for SCADomain.connect() API
     private static SCADomain theDomain;
 
+    
+    /**
+     * Returns a new instance of a local SCA domain. The specified deployable
+     * composite defined in sca-contribution.xml will be included in the SCA domain.
+     * 
+     * @param composite the deployable composite to include in the SCA domain.
+     * @return
+     */
+    public static SCADomain newInstance() {
+        return createNewInstance("http://localhost", null);
+    }
+    
+    /**
+     * Returns a new instance of a local SCA domain. The specified deployable
+     * composite will be included in the SCA domain.
+     * 
+     * @param composite the deployable composite to include in the SCA domain.
+     * @return
+     */
+    public static SCADomain newInstance(String composite) {
+        return createNewInstance("http://localhost", ".", composite);
+    }
+    
     /**
      * Returns a new instance of a local SCA domain. The specified deployable
      * composites will be included in the SCA domain.
@@ -77,17 +100,6 @@
     // TODO : this is a temporary implementation to get the capability working
     public static SCADomain connect(String domainURI) {
         return theDomain;
-    }
-
-    /**
-     * Returns a new instance of a local SCA domain. The specified deployable
-     * composite will be included in the SCA domain.
-     * 
-     * @param composite the deployable composite to include in the SCA domain.
-     * @return
-     */
-    public static SCADomain newInstance(String composite) {
-        return createNewInstance("http://localhost", ".", composite);
     }
 
     /**

Modified: incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java?view=diff&rev=538401&r1=538400&r2=538401
==============================================================================
--- incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java (original)
+++ incubator/tuscany/java/sca/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java Tue May 15 18:52:30 2007
@@ -100,7 +100,8 @@
 
         try {
             DefaultModelResolver modelResolver = new DefaultModelResolver(applicationClassLoader);
-            contribution = contributionService.contribute(location, contributionURL, modelResolver, false);
+            String contributionURI = FileHelper.getName(contributionURL.getPath());
+            contribution = contributionService.contribute(contributionURI, contributionURL, modelResolver, false);
         } catch (ContributionException e) {
             throw new ServiceRuntimeException(e);
         } catch (IOException e) {
@@ -113,21 +114,31 @@
         domainComposite.setName(new QName(Constants.SCA_NS, "domain"));
         domainComposite.setURI(domainURI);
 
-        // Include all specified deployable composites in the SCA domain
-        Map<String, Composite> compositeArtifacts = new HashMap<String, Composite>();
-        for (DeployedArtifact artifact : contribution.getArtifacts()) {
-            if (artifact.getModel() instanceof Composite) {
-                compositeArtifacts.put(artifact.getURI(), (Composite)artifact.getModel());
+        //when the deployable composites were specified when initializing the runtime
+        if (composites != null && composites.length > 0 && composites[0].length() > 0) {
+            // Include all specified deployable composites in the SCA domain
+            Map<String, Composite> compositeArtifacts = new HashMap<String, Composite>();
+            for (DeployedArtifact artifact : contribution.getArtifacts()) {
+                if (artifact.getModel() instanceof Composite) {
+                    compositeArtifacts.put(artifact.getURI(), (Composite)artifact.getModel());
+                }
             }
-        }
-        for (String compositePath : composites) {
-            Composite composite = compositeArtifacts.get(compositePath);
-            if (composite == null) {
-                throw new ServiceRuntimeException("Composite not found: " + compositePath);
+            for (String compositePath : composites) {
+                Composite composite = compositeArtifacts.get(compositePath);
+                if (composite == null) {
+                    throw new ServiceRuntimeException("Composite not found: " + compositePath);
+                }
+                domainComposite.getIncludes().add(composite);
+            }            
+        } else {
+            // in this case, a sca-contribution.xml should have been specified
+            for(Composite composite : contribution.getDeployables()) {
+                domainComposite.getIncludes().add(composite);
             }
-            domainComposite.getIncludes().add(composite);
+            
         }
 
+
         // Activate and start the SCA domain composite
         CompositeActivator compositeActivator = runtime.getCompositeActivator();
         try {
@@ -151,7 +162,7 @@
         // Remove the contribution from the in-memory repository
         ContributionService contributionService = runtime.getContributionService();
         try {
-            contributionService.remove(location);
+            contributionService.remove(contribution.getURI());
         } catch (ContributionException e) {
             throw new ServiceRuntimeException(e);
         }
@@ -185,26 +196,46 @@
      */
     private URL getContributionLocation(String contributionPath, String[] composites, ClassLoader classLoader)
         throws MalformedURLException {
-        URI contributionURI = URI.create(contributionPath);
-        if (contributionURI.isAbsolute() || composites.length == 0) {
-            return new URL(contributionPath);
+        if (contributionPath != null && contributionPath.length() > 0) {
+            URI contributionURI = URI.create(contributionPath);
+            if (contributionURI.isAbsolute() || composites.length == 0) {
+                return new URL(contributionPath);
+            }
+        }
+
+        String contributionArtifactPath = null;
+        URL contributionArtifactURL = null;
+        if (composites != null && composites.length > 0 && composites[0].length() > 0) {
+            //here the scaDomain was started with a reference to a composite file
+            contributionArtifactPath = composites[0];
+            contributionArtifactURL = classLoader.getResource(contributionArtifactPath);
+            if (contributionArtifactURL == null) {
+                throw new IllegalArgumentException("Composite not found: " + contributionArtifactPath);
+            }
+        }else {
+            //here the scaDomain was started without any reference to a composite file
+            //we are going to look for a sca-contribution.xml or sca-contribution-generated.xml
+            contributionArtifactPath = Contribution.SCA_CONTRIBUTION_META;
+            contributionArtifactURL = classLoader.getResource(contributionArtifactPath);
+            if( contributionArtifactURL == null ) {
+                contributionArtifactPath = Contribution.SCA_CONTRIBUTION_GENERATED_META;
+                contributionArtifactURL = classLoader.getResource(contributionArtifactPath);
+            }
         }
 
-        String compositePath = composites[0];
-        URL compositeURL = classLoader.getResource(compositePath);
-        if (compositeURL == null) {
-            throw new IllegalArgumentException("Composite not found: " + compositePath);
+        if (contributionArtifactURL == null) {
+            throw new IllegalArgumentException("Can't determine contribution deployables. Either specify a composite file, or use a sca-contribution.xml file to specify the deployables.");
         }
 
         URL contributionURL = null;
         // "jar:file://....../something.jar!/a/b/c/app.composite"
         try {
-            String scdlUrl = compositeURL.toExternalForm();
-            String protocol = compositeURL.getProtocol();
+            String scdlUrl = contributionArtifactURL.toExternalForm();
+            String protocol = contributionArtifactURL.getProtocol();
             if ("file".equals(protocol)) {
                 // directory contribution
-                if (scdlUrl.endsWith(compositePath)) {
-                    String location = scdlUrl.substring(0, scdlUrl.lastIndexOf(compositePath));
+                if (scdlUrl.endsWith(contributionArtifactPath)) {
+                    String location = scdlUrl.substring(0, scdlUrl.lastIndexOf(contributionArtifactPath));
                     // workaround from evil url/uri form maven
                     contributionURL = FileHelper.toFile(new URL(location)).toURI().toURL();
                 }

Modified: incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/webapp/SCADomainHelper.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/webapp/SCADomainHelper.java?view=diff&rev=538401&r1=538400&r2=538401
==============================================================================
--- incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/webapp/SCADomainHelper.java (original)
+++ incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/webapp/SCADomainHelper.java Tue May 15 18:52:30 2007
@@ -19,10 +19,6 @@
 
 package org.apache.tuscany.sca.webapp;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
 import javax.servlet.ServletContext;
 
 import org.apache.tuscany.sca.host.embedded.SCADomain;
@@ -33,7 +29,6 @@
 public class SCADomainHelper {
 
     public static final String SCA_DOMAIN_ATTRIBUTE = "org.apache.tuscany.sca.SCADomain";
-    public static final String DEFAULT_COMPOSITES_DIR = "/WEB-INF/classes";
 
     /**
      * Initializes the SCADomian associated with a webapp context. If a SCADomain
@@ -42,30 +37,9 @@
     public static SCADomain initSCADomain(ServletContext servletContext) {
         SCADomain scaDomain = (SCADomain)servletContext.getAttribute(SCA_DOMAIN_ATTRIBUTE);
         if (scaDomain == null) {
-
-            String[] compositeNames = getDeployableComposites(servletContext);
-            String domainURI = "http://localhost/" + servletContext.getServletContextName().replace(' ', '.');
-            scaDomain = SCADomain.newInstance(domainURI, ".", compositeNames);
-
+            scaDomain = SCADomain.newInstance();
             servletContext.setAttribute(SCA_DOMAIN_ATTRIBUTE, scaDomain);
         }
         return scaDomain;
-    }
-
-    /**
-     * Gets all the composites in the DEFAULT_COMPOSITES_DIR directory.
-     */
-    protected static String[] getDeployableComposites(ServletContext servletContext) {
-        List<String> compositeNames = new ArrayList<String>();
-        Set resources = servletContext.getResourcePaths(DEFAULT_COMPOSITES_DIR);
-        for (Object o : resources) {
-            String resource = o.toString();
-            if (resource.endsWith(".composite")) {
-                String compositeName = resource.substring(resource.lastIndexOf('/')+1);
-                compositeNames.add(compositeName);
-            }
-        }
-
-        return compositeNames.toArray(new String[compositeNames.size()]);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org