Author: jsdelfino
Date: Tue Mar 18 23:20:35 2008
New Revision: 638720

URL: http://svn.apache.org/viewvc?rev=638720&view=rev
Log:
Minor fixes to bring up tutorial/nodes-jee/catalog-webapp. Look for runtime 
JARs in lib/ in addition to modules/. Use local copies of contribution JARs in 
a WAR if available. Use the correct classloader to load the NodeImplFactory in 
a webapp environment. Packaged the necessary JARs in the tutorial sample 
catalog webapp and fixed the call to a local version of the catalog service in 
the JSP.

Modified:
    
incubator/tuscany/java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCANode2Factory.java
    
incubator/tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
    
incubator/tuscany/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
    
incubator/tuscany/java/sca/modules/workspace-admin/src/main/java/org/apache/tuscany/sca/workspace/admin/launcher/DomainAdminLauncherUtil.java
    
incubator/tuscany/java/sca/tutorial/nodes-jee/catalog-webapp/catalog-web.composite
    incubator/tuscany/java/sca/tutorial/nodes-jee/catalog-webapp/pom.xml
    
incubator/tuscany/java/sca/tutorial/nodes-jee/catalog-webapp/webapp/catalog.jsp

Modified: 
incubator/tuscany/java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCANode2Factory.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCANode2Factory.java?rev=638720&r1=638719&r2=638720&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCANode2Factory.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCANode2Factory.java
 Tue Mar 18 23:20:35 2008
@@ -41,7 +41,7 @@
         SCANode2Factory scaNodeFactory = null;
         
         try {
-            final ClassLoader classLoader = 
SCANode2Factory.class.getClassLoader();
+            final ClassLoader classLoader = 
Thread.currentThread().getContextClassLoader();
             String className =  
"org.apache.tuscany.sca.node.impl.NodeFactoryImpl";  
                             
             Class<?> cls = Class.forName(className, true, classLoader);

Modified: 
incubator/tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java?rev=638720&r1=638719&r2=638720&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
 Tue Mar 18 23:20:35 2008
@@ -21,8 +21,11 @@
 
 import java.io.InputStream;
 import java.net.URL;
+import java.net.URLClassLoader;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -100,7 +103,8 @@
         this.configurationURI = configurationURI;
 
         // Create a node runtime for the domain contributions to run on
-        runtime = new 
ReallySmallRuntime(Thread.currentThread().getContextClassLoader());
+        ClassLoader contextClassLoader =  
Thread.currentThread().getContextClassLoader();
+        runtime = new ReallySmallRuntime(contextClassLoader);
         runtime.start();
         activator = runtime.getCompositeActivator();
         
@@ -121,12 +125,34 @@
         reader.nextTag();
         ConfiguredNodeImplementation configuration = 
configurationProcessor.read(reader);
         is.close();
+        
+        // Find if any contribution JARs already available locally on the 
classpath
+        Map<String, URL> localContributions = new HashMap<String, URL>();
+        collectJARs(localContributions, contextClassLoader);
 
         // Load the specified contributions
         ContributionService contributionService = 
runtime.getContributionService();
         List<Contribution> contributions = new ArrayList<Contribution>();
         for (Contribution contribution: configuration.getContributions()) {
+            
+            // Build contribution URL
             URL contributionURL = new URL(configurationURL, 
contribution.getLocation());
+
+            // Extract contribution file name
+            String file =contributionURL.getPath();
+            int i = file.lastIndexOf('/');
+            if (i != -1 && i < file.length() -1 ) {
+                file = file.substring(i +1);
+                
+                // If we find the local contribution file on the classpath, 
use it in
+                // place of the original contribution URL
+                URL localContributionURL = localContributions.get(file);
+                if (localContributionURL != null) {
+                    contributionURL = localContributionURL;
+                }
+            }
+            
+            // Load the contribution
             logger.log(Level.INFO, "Loading contribution: " + contributionURL);
             
contributions.add(contributionService.contribute(contribution.getURI(), 
contributionURL, false));
         }
@@ -302,4 +328,29 @@
         }
     }    
 
+    /**
+     * Collect JARs on the classpath of a URLClassLoader
+     * @param urls
+     * @param cl
+     */
+    private static void collectJARs(Map<String, URL> urls, ClassLoader cl) {
+        if (cl == null) {
+            return;
+        }
+        
+        // Collect JARs from the URLClassLoader's classpath
+        if (cl instanceof URLClassLoader) {
+            for (URL jarURL: ((URLClassLoader)cl).getURLs()) {
+                String file =jarURL.getPath();
+                int i = file.lastIndexOf('/');
+                if (i != -1 && i < file.length() -1 ) {
+                    file = file.substring(i +1);
+                    urls.put(file, jarURL);
+                }
+            }
+        }
+        
+        // Collect JARs from the parent classloader
+        collectJARs(urls, cl.getParent());
+    }
 }

Modified: 
incubator/tuscany/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java?rev=638720&r1=638719&r2=638720&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
 Tue Mar 18 23:20:35 2008
@@ -63,7 +63,8 @@
         }
         URI uri = url.toURI();
             
-        // If the launcher class is in a JAR, add all runtime JARs from the 
same directory
+        // If the launcher class is in a JAR, add all runtime JARs from 
directory containing
+        // that JAR (e.g. the Tuscany modules directory) as well as the ../lib 
directory
         String scheme = uri.getScheme();
         if (scheme.equals("jar")) {
             String path = uri.toString().substring(4);
@@ -75,20 +76,35 @@
     
             File file = new File(uri);
             if (file.exists()) {
-                File directory = file.getParentFile();
-                collectJARFiles(directory, jarURLs);
+                File modulesDirectory = file.getParentFile();
+                if (modulesDirectory != null && modulesDirectory.exists()) {
+
+                    // Collect JAR files in the directory containing the input 
JAR
+                    // (e.g. the Tuscany modules directory)
+                    collectJARFiles(modulesDirectory, jarURLs);
+                    
+                    File homeDirectory = modulesDirectory.getParentFile();
+                    if (homeDirectory != null && homeDirectory.exists()) {
+                        
+                        // Collect JARs from the ../lib directory
+                        File libDirectory = new File(homeDirectory, "lib");
+                        if (libDirectory.exists() && 
!libDirectory.getAbsolutePath().equals(modulesDirectory.getAbsolutePath())) {
+                            collectJARFiles(libDirectory, jarURLs);
+                        }
+                    }
+                }
             }
         }
         
         // Look for a TUSCANY_HOME system property or environment variable
         // Add all the JARs found under $TUSCANY_HOME, $TUSCANY_HOME/modules
         // and $TUSCANY_HOME/lib
-        String home = System.getProperty(NodeLauncherUtil.TUSCANY_HOME);
+        String home = System.getProperty(TUSCANY_HOME);
         if (home == null || home.length() == 0) {
-            home = System.getenv(NodeLauncherUtil.TUSCANY_HOME);
+            home = System.getenv(TUSCANY_HOME);
         }
         if (home != null && home.length() != 0) {
-            NodeLauncherUtil.logger.info(NodeLauncherUtil.TUSCANY_HOME + ": " 
+ home);
+            logger.info(TUSCANY_HOME + ": " + home);
             File homeDirectory = new File(home);
             if (homeDirectory.exists()) {
                 

Modified: 
incubator/tuscany/java/sca/modules/workspace-admin/src/main/java/org/apache/tuscany/sca/workspace/admin/launcher/DomainAdminLauncherUtil.java
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/workspace-admin/src/main/java/org/apache/tuscany/sca/workspace/admin/launcher/DomainAdminLauncherUtil.java?rev=638720&r1=638719&r2=638720&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/modules/workspace-admin/src/main/java/org/apache/tuscany/sca/workspace/admin/launcher/DomainAdminLauncherUtil.java
 (original)
+++ 
incubator/tuscany/java/sca/modules/workspace-admin/src/main/java/org/apache/tuscany/sca/workspace/admin/launcher/DomainAdminLauncherUtil.java
 Tue Mar 18 23:20:35 2008
@@ -63,7 +63,8 @@
         }
         URI uri = url.toURI();
             
-        // If the launcher class is in a JAR, add all runtime JARs from the 
same directory
+        // If the launcher class is in a JAR, add all runtime JARs from 
directory containing
+        // that JAR (e.g. the Tuscany modules directory) as well as the ../lib 
directory
         String scheme = uri.getScheme();
         if (scheme.equals("jar")) {
             String path = uri.toString().substring(4);
@@ -75,20 +76,35 @@
     
             File file = new File(uri);
             if (file.exists()) {
-                File directory = file.getParentFile();
-                collectJARFiles(directory, jarURLs);
+                File modulesDirectory = file.getParentFile();
+                if (modulesDirectory != null && modulesDirectory.exists()) {
+
+                    // Collect JAR files in the directory containing the input 
JAR
+                    // (e.g. the Tuscany modules directory)
+                    collectJARFiles(modulesDirectory, jarURLs);
+                    
+                    File homeDirectory = modulesDirectory.getParentFile();
+                    if (homeDirectory != null && homeDirectory.exists()) {
+                        
+                        // Collect JARs from the ../lib directory
+                        File libDirectory = new File(homeDirectory, "lib");
+                        if (libDirectory.exists() && 
!libDirectory.getAbsolutePath().equals(modulesDirectory.getAbsolutePath())) {
+                            collectJARFiles(libDirectory, jarURLs);
+                        }
+                    }
+                }
             }
         }
         
         // Look for a TUSCANY_HOME system property or environment variable
         // Add all the JARs found under $TUSCANY_HOME, $TUSCANY_HOME/modules
         // and $TUSCANY_HOME/lib
-        String home = System.getProperty(DomainAdminLauncherUtil.TUSCANY_HOME);
+        String home = System.getProperty(TUSCANY_HOME);
         if (home == null || home.length() == 0) {
-            home = System.getenv(DomainAdminLauncherUtil.TUSCANY_HOME);
+            home = System.getenv(TUSCANY_HOME);
         }
         if (home != null && home.length() != 0) {
-            
DomainAdminLauncherUtil.logger.info(DomainAdminLauncherUtil.TUSCANY_HOME + ": " 
+ home);
+            logger.info(TUSCANY_HOME + ": " + home);
             File homeDirectory = new File(home);
             if (homeDirectory.exists()) {
                 
@@ -113,7 +129,7 @@
         if (!jarURLs.isEmpty()) {
             
             // Return a classloader configured with the runtime JARs
-            ClassLoader classLoader = new URLClassLoader(jarURLs.toArray(new 
URL[0]), Object.class.getClassLoader());
+            ClassLoader classLoader = new URLClassLoader(jarURLs.toArray(new 
URL[0]), parentClassLoader);
             return classLoader;
             
         } else {

Modified: 
incubator/tuscany/java/sca/tutorial/nodes-jee/catalog-webapp/catalog-web.composite
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tutorial/nodes-jee/catalog-webapp/catalog-web.composite?rev=638720&r1=638719&r2=638720&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/tutorial/nodes-jee/catalog-webapp/catalog-web.composite
 (original)
+++ 
incubator/tuscany/java/sca/tutorial/nodes-jee/catalog-webapp/catalog-web.composite
 Tue Mar 18 23:20:35 2008
@@ -32,4 +32,12 @@
         </reference>   
     </component>     
 
+    <component name="LocalFruitsCatalog">
+        <implementation.java class="services.FruitsCatalogImpl"/>
+        <property name="currencyCode">USD</property>
+        <reference name="currencyConverter" target="CloudCurrencyConverter">
+               <binding.ws/>
+        </reference>   
+    </component>     
+
 </composite>

Modified: incubator/tuscany/java/sca/tutorial/nodes-jee/catalog-webapp/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tutorial/nodes-jee/catalog-webapp/pom.xml?rev=638720&r1=638719&r2=638720&view=diff
==============================================================================
--- incubator/tuscany/java/sca/tutorial/nodes-jee/catalog-webapp/pom.xml 
(original)
+++ incubator/tuscany/java/sca/tutorial/nodes-jee/catalog-webapp/pom.xml Tue 
Mar 18 23:20:35 2008
@@ -41,21 +41,20 @@
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-sca-api</artifactId>
             <version>1.2-incubating-SNAPSHOT</version>
-            <scope>provided</scope>
+            <scope>runtime</scope>
         </dependency>
 
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tuscany-node2-api</artifactId>
             <version>1.2-incubating-SNAPSHOT</version>
-            <scope>provided</scope>
+            <scope>runtime</scope>
         </dependency>
 
         <dependency>
             <groupId>org.apache.tuscany.sca</groupId>
             <artifactId>tutorial-assets</artifactId>
             <version>1.2-incubating-SNAPSHOT</version>
-            <scope>provided</scope>
         </dependency>
         
         <dependency>

Modified: 
incubator/tuscany/java/sca/tutorial/nodes-jee/catalog-webapp/webapp/catalog.jsp
URL: 
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/tutorial/nodes-jee/catalog-webapp/webapp/catalog.jsp?rev=638720&r1=638719&r2=638720&view=diff
==============================================================================
--- 
incubator/tuscany/java/sca/tutorial/nodes-jee/catalog-webapp/webapp/catalog.jsp 
(original)
+++ 
incubator/tuscany/java/sca/tutorial/nodes-jee/catalog-webapp/webapp/catalog.jsp 
Tue Mar 18 23:20:35 2008
@@ -27,7 +27,7 @@
   
   SCAClient client = (SCAClient) 
application.getAttribute("org.apache.tuscany.sca.node.SCAClient");
    
-  Catalog catalog = (Catalog)client.getService(Catalog.class, 
"WebFruitsCatalog");
+  Catalog catalog = (Catalog)client.getService(Catalog.class, 
"LocalFruitsCatalog");
   Item[] items = catalog.get();
   
 %>
@@ -40,7 +40,7 @@
 
 <table border="0">
 
-<% for (Item item: items) { %>>
+<% for (Item item: items) { %>
 
     <tr><td><%=item.getName() %></td><td><%=item.getPrice() %></td></tr>
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to