Author: antelder
Date: Fri May 29 09:42:53 2009
New Revision: 779906

URL: http://svn.apache.org/viewvc?rev=779906&view=rev
Log:
Start adding support for non-webapp contributions. The idea being to enable 
using regular SCA contribution jas/zips/folders as well as webapps and have 
them all in the same sca domain and wiring between each other. None of the 
domain works yet as we need to make more progress on the dynamic doamin 
discussion. Eventually the non-webapp contributions would use the tomcat host 
config facilities so support hot deployment, and there'd be some domain 
management panels in the tuscany webapp to view and modify the domain. Could 
potentially have multiple domains within a tomcat instance though lets leave 
that for now as it adds some complications. Would also be good to get the 
SCAClient API able to talk to the tomcat domain so JSE clients can call sca 
services in tomcat

Added:
    
tuscany/java/sca/distribution/tomcat/tomcat-servlet/src/main/java/org/apache/tuscany/sca/tomcat/
    
tuscany/java/sca/distribution/tomcat/tomcat-servlet/src/main/java/org/apache/tuscany/sca/tomcat/foo/
    
tuscany/java/sca/distribution/tomcat/tomcat-servlet/src/main/java/org/apache/tuscany/sca/tomcat/foo/TuscanyTomcatNode.java
Modified:
    
tuscany/java/sca/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyStandardContext.java
    tuscany/java/sca/distribution/tomcat/tomcat-servlet/pom.xml

Modified: 
tuscany/java/sca/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyStandardContext.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyStandardContext.java?rev=779906&r1=779905&r2=779906&view=diff
==============================================================================
--- 
tuscany/java/sca/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyStandardContext.java
 (original)
+++ 
tuscany/java/sca/distribution/tomcat/tomcat-hook/src/main/java/org/apache/tuscany/sca/tomcat/TuscanyStandardContext.java
 Fri May 29 09:42:53 2009
@@ -45,6 +45,7 @@
     protected static final String TUSCANY_FILTER_NAME = "TuscanyFilter";
     protected static final String TUSCANY_SERVLET_FILTER = 
"org.apache.tuscany.sca.host.webapp.TuscanyServletFilter";
     protected static final String TUSCANY_CONTEXT_LISTENER = 
"org.apache.tuscany.sca.host.webapp.TuscanyContextListener";
+    protected static final String TUSCANY_MANAGER_LISTENER = 
"org.apache.tuscany.sca.tomcat.foo.TuscanyTomcatNode";
 
     private boolean isSCAApp;
 
@@ -65,7 +66,7 @@
         }
 
         ClassLoader parent = getParentClassLoader();
-        if (isSCAApp = isSCAApplication()) {
+        if (isSCAApp = isSCAApplication() || isTuscanyManager()) {
             String sharedProp = 
System.getProperty(TuscanyLifecycleListener.TUSCANY_SHARED_PROP, "false");
             boolean shared = "true".equalsIgnoreCase(sharedProp);
             if (!shared) {
@@ -81,7 +82,11 @@
 
     @Override
     public boolean listenerStart() {
-        if (isSCAApp) {
+        if (isTuscanyManager()) {
+            // this isn't great having the manager app config scattered about 
different modules
+            // but is temp until this is all tidied up in a refactor after the 
basics are working
+            addApplicationListener(TUSCANY_MANAGER_LISTENER);
+        } else if (isSCAApp) {
             enableTuscany();
         }
         return super.listenerStart();
@@ -151,6 +156,10 @@
         return true;
     }
 
+    private boolean isTuscanyManager() {
+        return "/tuscany".equals(getName());
+    }
+
     private static URLClassLoader copy(URLClassLoader classLoader) {
         return new URLClassLoader(classLoader.getURLs(), 
classLoader.getParent());
     }

Modified: tuscany/java/sca/distribution/tomcat/tomcat-servlet/pom.xml
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/distribution/tomcat/tomcat-servlet/pom.xml?rev=779906&r1=779905&r2=779906&view=diff
==============================================================================
--- tuscany/java/sca/distribution/tomcat/tomcat-servlet/pom.xml (original)
+++ tuscany/java/sca/distribution/tomcat/tomcat-servlet/pom.xml Fri May 29 
09:42:53 2009
@@ -39,6 +39,13 @@
         </dependency>
 
         <dependency>
+           <groupId>org.apache.tuscany.sca</groupId>
+           <artifactId>tuscany-node-api</artifactId>
+           <version>2.0-SNAPSHOT</version>
+           <scope>provided</scope>
+        </dependency>
+
+        <dependency>
            <groupId>org.codehaus.swizzle</groupId>
            <artifactId>swizzle-stream</artifactId>
            <version>1.0.2</version>

Added: 
tuscany/java/sca/distribution/tomcat/tomcat-servlet/src/main/java/org/apache/tuscany/sca/tomcat/foo/TuscanyTomcatNode.java
URL: 
http://svn.apache.org/viewvc/tuscany/java/sca/distribution/tomcat/tomcat-servlet/src/main/java/org/apache/tuscany/sca/tomcat/foo/TuscanyTomcatNode.java?rev=779906&view=auto
==============================================================================
--- 
tuscany/java/sca/distribution/tomcat/tomcat-servlet/src/main/java/org/apache/tuscany/sca/tomcat/foo/TuscanyTomcatNode.java
 (added)
+++ 
tuscany/java/sca/distribution/tomcat/tomcat-servlet/src/main/java/org/apache/tuscany/sca/tomcat/foo/TuscanyTomcatNode.java
 Fri May 29 09:42:53 2009
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.    
+ */
+
+package org.apache.tuscany.sca.tomcat.foo;
+
+import java.io.File;
+import java.net.MalformedURLException;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.apache.tuscany.sca.node.Contribution;
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.apache.tuscany.sca.war.Installer;
+
+public class TuscanyTomcatNode implements ServletContextListener {
+
+    protected Node tomcatNode;
+
+    public void contextInitialized(ServletContextEvent arg0) {
+        if (!Installer.isTuscanyHookRunning()) {
+            return;
+        }
+
+        // TODO: this relys on the location of webapp folder, find way to get 
actual catalina base 
+        File tomcatBase = new 
File(arg0.getServletContext().getRealPath("/")).getParentFile().getParentFile();
+
+        File contributionDir = new File(tomcatBase, "sca-contributions");
+        if (!contributionDir.exists()) {
+            return;
+        }
+        File[] contributionFiles = contributionDir.listFiles();
+        if (contributionFiles.length < 1) {
+            return;
+        }
+        
+        Contribution[] nodeContributions = new 
Contribution[contributionFiles.length];
+        for (int i = 0; i<contributionFiles.length; i++) {
+            try {
+                nodeContributions[i] = 
+                    new Contribution(contributionFiles[i].getName(), 
contributionFiles[i].toURI().toURL().toString());
+            } catch (MalformedURLException e) {
+                e.printStackTrace();
+            }
+        }
+
+        tomcatNode = NodeFactory.newInstance().createNode(nodeContributions);
+        tomcatNode.start();
+    }
+
+    public void contextDestroyed(ServletContextEvent arg0) {
+        if (tomcatNode != null) {
+            tomcatNode.stop();
+        }
+    }
+
+}


Reply via email to