geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vamsic...@apache.org
Subject svn commit: r570534 [5/7] - in /geronimo/plugins/tuscany: ./ branches/ tags/ trunk/ trunk/geronimo-tuscany-http-jetty/ trunk/geronimo-tuscany-http-jetty/src/ trunk/geronimo-tuscany-http-jetty/src/main/ trunk/geronimo-tuscany-http-jetty/src/main/java/ t...
Date Tue, 28 Aug 2007 19:26:54 GMT
Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/LICENSE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/LICENSE.txt
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/LICENSE.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/NOTICE.txt
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/NOTICE.txt?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/NOTICE.txt (added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/NOTICE.txt Tue Aug 28 12:26:50 2007
@@ -0,0 +1,6 @@
+Apache Geronimo 
+Copyright 2003-2007 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/NOTICE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/NOTICE.txt
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/NOTICE.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/pom.xml?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/pom.xml (added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/pom.xml Tue Aug 28 12:26:50 2007
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+
+<!-- $Rev$ $Date$ -->
+
+<project>
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.geronimo.plugins</groupId>
+		<artifactId>tuscany-parent</artifactId>
+		<version>1.0-SNAPSHOT</version>
+		<relativePath>../pom.xml</relativePath>
+	</parent>
+
+	<artifactId>geronimo-tuscany-http-tomcat</artifactId>
+	<name>Geronimo Plugins :: Tuscany Servlet Host for Geronimo Tomcat</name>
+
+	<dependencies>
+	    <!-- Geronimo dependencies -->
+		<dependency>
+			<groupId>org.apache.geronimo.modules</groupId>
+			<artifactId>geronimo-kernel</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.geronimo.modules</groupId>
+			<artifactId>geronimo-tomcat6</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.tomcat</groupId>
+			<artifactId>catalina</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.tomcat</groupId>
+			<artifactId>coyote</artifactId>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.geronimo.specs</groupId>
+			<artifactId>geronimo-servlet_2.5_spec</artifactId>
+		</dependency>
+
+        <!-- Tuscany dependencies -->
+		<dependency>
+			<groupId>org.apache.tuscany.sca</groupId>
+			<artifactId>tuscany-host-http</artifactId>
+		</dependency>
+	</dependencies>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.5</source>
+					<target>1.5</target>
+				</configuration>
+			</plugin>
+		</plugins>
+
+		<sourceDirectory>src/main/java</sourceDirectory>
+		<testSourceDirectory>src/test</testSourceDirectory>
+		<resources>
+			<resource>
+				<directory>src/main/resources</directory>
+				<filtering>true</filtering>
+			</resource>
+		</resources>
+		<testResources>
+			<testResource>
+				<directory>src/test/resources</directory>
+			</testResource>
+		</testResources>
+	</build>
+
+</project>
+
+

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/GeronimoServletHost.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/GeronimoServletHost.java?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/GeronimoServletHost.java (added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/GeronimoServletHost.java Tue Aug 28 12:26:50 2007
@@ -0,0 +1,224 @@
+/*
+ * 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.geronimo.tuscany.http.tomcat;
+
+import java.io.File;
+import java.net.URI;
+import java.util.concurrent.Executor;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+import org.apache.catalina.Container;
+import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.Wrapper;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.Context;
+import org.apache.catalina.core.StandardContext;
+import org.apache.catalina.core.StandardEngine;
+import org.apache.catalina.core.StandardHost;
+import org.apache.catalina.core.StandardWrapper;
+import org.apache.catalina.loader.WebappLoader;
+import org.apache.catalina.startup.ContextConfig;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.coyote.http11.Http11Protocol;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.InternalKernelException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.KernelRegistry;
+import org.apache.geronimo.kernel.proxy.GeronimoManagedBean;
+import org.apache.geronimo.management.geronimo.NetworkConnector;
+import org.apache.geronimo.tomcat.ObjectRetriever;
+import org.apache.geronimo.tomcat.TomcatContainer;
+import org.apache.geronimo.tomcat.TomcatWebContainer;
+import org.apache.tomcat.util.buf.MessageBytes;
+import org.apache.tomcat.util.http.mapper.MappingData;
+import org.apache.tomcat.util.net.JIoEndpoint;
+import org.apache.tuscany.sca.host.http.DefaultResourceServlet;
+import org.apache.tuscany.sca.host.http.ServletHost;
+import org.apache.tuscany.sca.host.http.ServletMappingException;
+
+
+/**
+ * A Geronimo based implementation of ServletHost. This works only on those 
+ * versions of Geronimo 2.0 that use Tomcat as the Web Container.
+ * Adds contexts to the tomcat host as and when required. In case of existing contexts
+ * it adds the servlets to those contexts provided they were created by this
+ * servlet host implementation. If the context provided in the URL where the service
+ * is exposed is an existing J2EE context then an error is thrown. 
+ * 
+ * @version $Rev$ $Date$
+ */
+@SuppressWarnings("deprecation")
+public class GeronimoServletHost implements ServletHost {
+
+    private static final Log log = LogFactory.getLog(GeronimoServletHost.class);
+    private static final int DEFAULT_PORT = 8080;
+    private Engine engine;
+    private NetworkConnector[] connectors;
+    private Container host;
+    private StandardContext context;
+    private ObjectRetriever engineGbean;
+    private TomcatWebContainer tomcatContainerGbean;
+    private static final String JMX_APP_NAME = "Tuscany Service Context";
+    private static final String JMX_SERVER_NAME = "geronimo";
+    private static final String SEPARATOR = "/";
+    private static final String WILDCARD = "*";
+    private static final String docext = "work";
+    private static final String tomcatEngineGBeanName = "TomcatEngine";
+    private static final String tomcatContainerGBeanName = "TomcatWebContainer";
+    
+    public void init(){
+        log.debug("Start of init() method");
+        Kernel kernel = KernelRegistry.getSingleKernel();
+        try {            
+            tomcatContainerGbean = (TomcatWebContainer)kernel.getGBean(tomcatContainerGBeanName, TomcatWebContainer.class);            
+        } catch (Exception e) {
+            log.fatal("Cannot find GBean named " + tomcatContainerGBeanName,e);
+            throw new IllegalArgumentException("Cannot find GBean named " + tomcatContainerGBeanName,e);
+        }
+        try {
+            engineGbean = (ObjectRetriever) kernel.getGBean(tomcatEngineGBeanName, ObjectRetriever.class);            
+        } catch (Exception e) {
+            log.fatal("Cannot find GBean named " + tomcatEngineGBeanName,e);
+            throw new IllegalArgumentException("Cannot find GBean named " + tomcatEngineGBeanName,e);
+        }
+        
+        this.engine = (Engine) engineGbean.getInternalObject();
+        this.connectors = tomcatContainerGbean.getConnectors();
+        log.debug("End of init() method");
+    }
+
+    public void addServletMapping(String strURI, Servlet servlet) {
+        log.debug("Start of addServletMapping() method");
+        URI uri = URI.create(strURI);
+        boolean validport = false;
+        int port = uri.getPort();
+        if (port == -1) {
+            port = DEFAULT_PORT;
+        }
+        for(int i=0;i<connectors.length; i++){
+            GeronimoManagedBean gmbean = (GeronimoManagedBean)connectors[i];
+            if(gmbean.getStateInstance().isRunning() && port == connectors[i].getPort())    {
+                validport = true;
+                break;
+            }
+        }
+        if(!validport){
+            throw new IllegalArgumentException("Invalid port '" + port + "'.  Do you have a connector configured for that port?");
+        }
+        String path = uri.getPath();
+        path = (path.startsWith(SEPARATOR))?path.substring(1):path;
+        String contextPath = SEPARATOR + (path.indexOf(SEPARATOR) != -1 ? path.substring(0,path.indexOf(SEPARATOR)) : path);
+        String mapping = path.indexOf(SEPARATOR) != -1 ? path.substring(path.indexOf(SEPARATOR)) : SEPARATOR;
+        if(mapping.equals(SEPARATOR)) {
+        	// For url's of kind http://localhost/servicename, use context path "/".
+        	mapping = contextPath;
+        	contextPath = SEPARATOR;
+        }
+        String virtualServer = engine.getDefaultHost();
+        host = engine.findChild(virtualServer);
+        if (host == null) {
+            throw new IllegalArgumentException("Invalid virtual host '" + virtualServer + "'.  Do you have a matching Host entry in the plan?");
+        }
+        
+        context = (StandardContext)((StandardHost)host).map(contextPath);
+        if(context.getName().equals("")) {
+            context = new StandardContext();
+            context.setDocBase(docext + contextPath);
+            context.setJ2EEApplication(JMX_APP_NAME); // FIXME: Different name
+            context.setJ2EEServer(JMX_SERVER_NAME);
+            context.setPath(contextPath);        
+            context.setName(contextPath);
+            context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader()));
+            ContextConfig config = new ContextConfig();
+            ((Lifecycle)context).addLifecycleListener(config); 
+        } else {
+            if(!context.getJ2EEApplication().equals(JMX_APP_NAME)){
+                throw new IllegalArgumentException("This context named '" + context.getName() + "' is already assigned to a J2EE application");
+            }            
+        }
+        ServletWrapper wrapper;
+        if (servlet instanceof DefaultResourceServlet) {            
+            // Optimize the handling of resource requests, use the Tomcat default servlet
+            // instead of our default resource servlet
+            String servletPath = uri.getPath();
+            if (servletPath.endsWith(WILDCARD)) {
+                servletPath = servletPath.substring(0, servletPath.length()-1);
+            }
+            if (servletPath.endsWith(SEPARATOR)) {
+                servletPath = servletPath.substring(0, servletPath.length()-1);
+            }
+            DefaultResourceServlet resourceServlet = (DefaultResourceServlet)servlet;
+            TomcatDefaultServlet defaultServlet = new TomcatDefaultServlet(servletPath, resourceServlet.getDocumentRoot());
+            wrapper = new ServletWrapper(defaultServlet);            
+        } else {
+            wrapper = new ServletWrapper(servlet);
+        }        
+        wrapper.setServletClass(servlet.getClass().getName());        
+        wrapper.setName(mapping);
+        wrapper.addMapping(mapping);
+        wrapper.setLoadOnStartup(0);
+        context.addChild(wrapper);        
+        File temp = new File(new File(System.getProperty("catalina.base")), context.getDocBase());
+        if(!temp.exists()) {
+            temp.mkdirs();
+        }
+        host.addChild(context);        
+        try {
+            context.start();
+        } catch (LifecycleException e) {
+            log.fatal("The context named " + context.getName() + " failed to start",e);
+            throw new IllegalArgumentException("The context named " + context.getName() + " failed to start");
+        }                          
+        log.debug("End of addServletMapping() method");
+    }
+
+    public Servlet removeServletMapping(String uri) {
+        log.debug("Start of removeServletMapping() method");
+        String path = URI.create(uri).getPath();            
+        path = (path.startsWith(SEPARATOR))?path.substring(1):path;
+        String contextPath = SEPARATOR + (path.indexOf(SEPARATOR) != -1 ? path.substring(0,path.indexOf(SEPARATOR)) : path);
+        String mapping = path.indexOf(SEPARATOR) != -1 ? path.substring(path.indexOf(SEPARATOR)) : SEPARATOR;              
+        if(mapping.equals(SEPARATOR)) {
+        	// For url's of kind http://localhost/servicename, use context path "/".
+        	mapping = contextPath;
+        	contextPath = SEPARATOR;
+        }
+        Context context = ((StandardHost)host).map(contextPath);        
+        Container container = context.findChild(mapping);
+        context.removeChild(container);
+        //when to remove the context? Assuming when it has 2 children only i.e. JSP Servlet and DefaultServlet
+        //and it is not the default context
+        if(context.findChildren().length < 3 && !context.getName().equals("")){
+            try{        
+                ((StandardContext)context).stop();
+            }catch(LifecycleException lfe){
+                log.fatal("The context named " + context.getName() + " failed to stop",lfe);
+            }
+            host.removeChild(context);
+        }
+        log.debug("End of removeServletMapping() method");        
+        return ((StandardWrapper)container).getServlet();
+    }
+}

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/GeronimoServletHost.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/GeronimoServletHost.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/GeronimoServletHost.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/ServletWrapper.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/ServletWrapper.java?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/ServletWrapper.java (added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/ServletWrapper.java Tue Aug 28 12:26:50 2007
@@ -0,0 +1,55 @@
+/*
+ * 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.geronimo.tuscany.http.tomcat;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+import org.apache.catalina.core.StandardWrapper;
+
+/**
+ * A servlet wrapper.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class ServletWrapper extends StandardWrapper {
+    private static final long serialVersionUID = 1L;
+
+    private final Servlet servlet;
+
+    public ServletWrapper(Servlet servlet) {
+        this.servlet = servlet;
+    }
+
+    public synchronized Servlet loadServlet() {
+        return servlet;
+    }
+
+    public Servlet getServlet() {
+        return servlet;
+    }
+    
+    public void initServlet() throws ServletException {
+        servlet.init(facade);
+    }
+    
+    public void destroyServlet() {
+        servlet.destroy();
+    }
+}

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/ServletWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/ServletWrapper.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/ServletWrapper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/TomcatDefaultServlet.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/TomcatDefaultServlet.java?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/TomcatDefaultServlet.java (added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/TomcatDefaultServlet.java Tue Aug 28 12:26:50 2007
@@ -0,0 +1,75 @@
+/*
+ * 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.geronimo.tuscany.http.tomcat;
+
+import java.net.URI;
+import java.util.Hashtable;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.catalina.servlets.DefaultServlet;
+import org.apache.naming.resources.FileDirContext;
+import org.apache.naming.resources.ProxyDirContext;
+
+/**
+ * Customizes the Tomcat default servlet.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class TomcatDefaultServlet extends DefaultServlet {
+    private static final long serialVersionUID = -7503581551326796573L;
+    
+    private String documentRoot;
+    private ProxyDirContext proxyDirContext;
+    
+    public TomcatDefaultServlet(String servletPath, String documentRoot) {
+        this.documentRoot = documentRoot;
+        
+        FileDirContext dirContext = new FileDirContext();
+        URI uri = URI.create(this.documentRoot);
+        dirContext.setDocBase(uri.getPath());
+        
+        proxyDirContext = new ProxyDirContext(new Hashtable(), dirContext);
+        resources = proxyDirContext;
+    }
+    
+    @Override
+    public void init() throws ServletException {
+        super.init();
+        resources = proxyDirContext;
+    }
+    
+    @Override
+    public void init(ServletConfig servletConfig) throws ServletException {
+        super.init(servletConfig);
+        resources = proxyDirContext;
+    }
+
+    @Override
+    protected String getRelativePath(HttpServletRequest request) {
+        String path = request.getPathInfo();
+        if (path == null || path.length() == 0) {
+            path = "/";
+        }
+        return path;
+    }
+}

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/TomcatDefaultServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/TomcatDefaultServlet.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/TomcatDefaultServlet.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/module/GeronimoRuntimeModuleActivator.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/module/GeronimoRuntimeModuleActivator.java?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/module/GeronimoRuntimeModuleActivator.java (added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/module/GeronimoRuntimeModuleActivator.java Tue Aug 28 12:26:50 2007
@@ -0,0 +1,61 @@
+/*
+ * 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.geronimo.tuscany.http.tomcat.module;
+
+import java.util.List;
+
+import org.apache.geronimo.tuscany.http.tomcat.GeronimoServletHost;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ModuleActivator;
+import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint;
+
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class GeronimoRuntimeModuleActivator implements ModuleActivator {
+
+    private GeronimoServletHost servletHost;
+
+    public Object[] getExtensionPoints() {
+        return null;
+    }
+
+    public void start(ExtensionPointRegistry extensionPointRegistry) {
+        // Register a Tomcat servlet host
+        ServletHostExtensionPoint servletHosts =
+            extensionPointRegistry.getExtensionPoint(ServletHostExtensionPoint.class);        
+        servletHost = new GeronimoServletHost();  
+        servletHost.init();
+        servletHosts.addServletHost(servletHost);
+    }
+
+    public void stop(ExtensionPointRegistry registry) {
+        ServletHostExtensionPoint servletHosts =
+            registry.getExtensionPoint(ServletHostExtensionPoint.class);
+        List hostList = servletHosts.getServletHosts();
+        for(int i = 0; i < hostList.size(); i++){
+            if(hostList.get(i) instanceof GeronimoServletHost){
+                servletHosts.removeServletHost((GeronimoServletHost)hostList.get(i));
+                return;
+            }
+        }
+    }
+}

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/module/GeronimoRuntimeModuleActivator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/module/GeronimoRuntimeModuleActivator.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/java/org/apache/geronimo/tuscany/http/tomcat/module/GeronimoRuntimeModuleActivator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator (added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany-http-tomcat/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator Tue Aug 28 12:26:50 2007
@@ -0,0 +1,18 @@
+# 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.
+# Implementation class for the ModuleActivator
+org.apache.geronimo.tuscany.http.tomcat.module.GeronimoRuntimeModuleActivator

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany/LICENSE.txt
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany/LICENSE.txt?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany/LICENSE.txt (added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany/LICENSE.txt Tue Aug 28 12:26:50 2007
@@ -0,0 +1,203 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
+

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/LICENSE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/LICENSE.txt
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/LICENSE.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany/NOTICE.txt
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany/NOTICE.txt?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany/NOTICE.txt (added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany/NOTICE.txt Tue Aug 28 12:26:50 2007
@@ -0,0 +1,6 @@
+Apache Geronimo 
+Copyright 2003-2007 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/NOTICE.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/NOTICE.txt
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/NOTICE.txt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany/pom.xml?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany/pom.xml (added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany/pom.xml Tue Aug 28 12:26:50 2007
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+
+<!-- $Rev$ $Date$ -->
+
+<project>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.geronimo.plugins</groupId>
+        <artifactId>tuscany-parent</artifactId>
+        <version>1.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>geronimo-tuscany</artifactId>
+    <name>Geronimo Plugins :: Tuscany</name>
+
+    <dependencies>
+      <!-- Geronimo dependencies -->
+      <dependency>
+        <groupId>org.apache.geronimo.modules</groupId>
+        <artifactId>geronimo-j2ee</artifactId>        
+      </dependency>                          
+      <dependency>
+        <groupId>org.apache.geronimo.modules</groupId>
+        <artifactId>geronimo-kernel</artifactId>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.geronimo.modules</groupId>
+        <artifactId>geronimo-service-builder</artifactId>
+      </dependency>
+
+      <!-- Tuscany dependencies -->
+      <dependency>
+        <groupId>org.apache.tuscany.sca</groupId>
+        <artifactId>tuscany-host-embedded</artifactId>        
+      </dependency>                    
+    </dependencies>    
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin> 
+        </plugins>
+        
+        <sourceDirectory>src/main/java</sourceDirectory>
+        <testSourceDirectory>src/test</testSourceDirectory>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+                <filtering>true</filtering>
+            </resource>
+        </resources>
+        <testResources>
+            <testResource>
+                <directory>src/test/resources</directory>
+            </testResource>
+        </testResources>
+    </build>
+   
+</project>
+

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedRuntimeGBean.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedRuntimeGBean.java?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedRuntimeGBean.java (added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedRuntimeGBean.java Tue Aug 28 12:26:50 2007
@@ -0,0 +1,177 @@
+/*
+* 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.geronimo.tuscany;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.gbean.GBeanLifecycle;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.geronimo.kernel.repository.Repository;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.DeployedArtifact;
+import org.apache.tuscany.sca.contribution.resolver.impl.ModelResolverImpl;
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.apache.tuscany.sca.host.embedded.impl.EmbeddedSCADomain;
+
+
+/**
+ * GBean that is added to a deployed tuscany configuration, which adds the contribution to an EmbeddedSCADomain.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class EmbeddedRuntimeGBean implements GBeanLifecycle, SCADomainInterface {
+    private final static Log log = LogFactory.getLog(EmbeddedRuntimeGBean.class);
+
+    private ClassLoader classLoader;
+    private EmbeddedSCADomainGBean embeddedSCADomainRef;
+    private Contribution contribution;
+    private String contributionRoot;
+    private SCADomain scaDomain;
+    private Collection repositories;
+    private AbstractName abstractName;
+    private String jarFileName;
+    
+    public EmbeddedRuntimeGBean(EmbeddedSCADomainGBean embeddedSCADomainRef, ClassLoader classLoader, Collection repositories, AbstractName abstractName){
+        this.embeddedSCADomainRef = embeddedSCADomainRef;
+        this.classLoader = Thread.currentThread().getContextClassLoader();
+        this.repositories = repositories;
+        this.abstractName = abstractName;
+    }
+    
+    public EmbeddedRuntimeGBean(){
+    }  
+
+    public SCADomain getScaDomain() {
+        return scaDomain;
+    }
+
+    public String getJarFileName() {
+        return jarFileName;
+    }
+
+    public void setJarFileName(String jarFileName) {
+        this.jarFileName = jarFileName;
+    }    
+
+    public void doStart() throws Exception {
+        contributionRoot = SCADomainHelper.getLocation((Repository)repositories.toArray()[0], abstractName, jarFileName);
+        scaDomain = embeddedSCADomainRef.getScaDomain();
+        EmbeddedSCADomain eScaDomain = (EmbeddedSCADomain)scaDomain;
+        ModelResolverImpl modelResolver = new ModelResolverImpl(classLoader);
+        
+        // Add contribution
+        contribution = eScaDomain.getContributionService().contribute(contributionRoot, new URL(contributionRoot), modelResolver, false);
+
+        // Collect the composites
+        List<Composite> composites = new ArrayList<Composite>();
+        for(DeployedArtifact artifact : contribution.getArtifacts()) {
+            if (artifact.getModel() instanceof Composite) {
+                composites.add((Composite)artifact.getModel());
+            }
+        }
+
+        // Add the composites
+        for(Composite composite: composites) {
+            eScaDomain.getDomainComposite().getIncludes().add(composite);
+            eScaDomain.getCompositeBuilder().build(composite); 
+        }
+        
+        // Activate the composites
+        for(Composite composite: composites) {
+            eScaDomain.getCompositeActivator().activate(composite);
+        }
+
+        // Start the composites
+        for(Composite composite: composites) {
+            eScaDomain.getCompositeActivator().start(composite);
+        }
+        
+        scaDomain = eScaDomain;
+        log.debug("EmbeddedRuntimeGBean started. Name=" + abstractName);
+    }
+
+    public void doStop() throws Exception {
+        if (scaDomain != null) {
+            EmbeddedSCADomain eScaDomain = (EmbeddedSCADomain)scaDomain;
+            
+            // Collect the composites
+            List<Composite> composites = new ArrayList<Composite>();
+            for(DeployedArtifact artifact : contribution.getArtifacts()) {
+                if (artifact.getModel() instanceof Composite) {
+                    composites.add((Composite)artifact.getModel());
+                }
+            }
+
+            // Stop the composites
+            for(Composite composite: composites) {
+                eScaDomain.getCompositeActivator().stop(composite);
+            }
+            
+            // Deactivate the composites
+            for(Composite composite: composites) {
+                eScaDomain.getCompositeActivator().deactivate(composite);
+            }
+
+            // Remove the composites
+            for(Composite composite: composites) {
+                eScaDomain.getDomainComposite().getIncludes().remove(composite);
+            }
+
+            // Remove contribution
+            eScaDomain.getContributionService().remove(contributionRoot);
+        }        
+        scaDomain = null;
+        log.debug("EmbeddedRuntimeGBean stopped. Name=" + abstractName);
+    }
+
+    public void doFail() {
+        if (scaDomain != null) {
+            scaDomain.close();
+        }
+        scaDomain = null;
+        log.warn("EmbeddedRuntimeGBean failed. Name=" + abstractName);
+    }
+
+     public static final GBeanInfo GBEAN_INFO;
+        static {
+            GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(EmbeddedRuntimeGBean.class,NameFactory.GERONIMO_SERVICE);
+            infoFactory.addAttribute("classLoader", ClassLoader.class, false);
+            infoFactory.addAttribute("abstractName", AbstractName.class, false);
+            infoFactory.addAttribute("jarFileName", String.class, true, true);
+            infoFactory.addReference("Repository", Repository.class, "Repository");
+            infoFactory.addReference("embeddedSCADomainRef", EmbeddedSCADomainGBean.class);
+            infoFactory.addAttribute("SCADomain", SCADomain.class, false, true);
+            infoFactory.addInterface(SCADomainInterface.class);
+            infoFactory.setConstructor(new String[]{"embeddedSCADomainRef", "classLoader", "Repository", "abstractName"});
+            GBEAN_INFO = infoFactory.getBeanInfo();
+        }
+
+        public static GBeanInfo getGBeanInfo() {
+            return GBEAN_INFO;
+        }
+}

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedRuntimeGBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedRuntimeGBean.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedRuntimeGBean.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedSCADomainGBean.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedSCADomainGBean.java?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedSCADomainGBean.java (added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedSCADomainGBean.java Tue Aug 28 12:26:50 2007
@@ -0,0 +1,91 @@
+/*
+* 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.geronimo.tuscany;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.gbean.GBeanLifecycle;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.apache.tuscany.sca.host.embedded.impl.EmbeddedSCADomain;
+
+/**
+ * GBean that holds an EmbeddedSCADomain to which contribution will be added by tuscany configurations.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class EmbeddedSCADomainGBean implements GBeanLifecycle, SCADomainInterface{
+    private final static Log log = LogFactory.getLog(EmbeddedSCADomainGBean.class);
+    
+    private AbstractName abstractName;
+    private EmbeddedSCADomain scaDomain;
+    private String domainUri;
+    private ClassLoader runtimeClassLoader;
+    
+    public EmbeddedSCADomainGBean(AbstractName abstractName, ClassLoader runtimeClassLoader, String domainUri) {
+        this.abstractName = abstractName;
+        this.runtimeClassLoader = runtimeClassLoader == null ? SCADomain.class.getClassLoader() : runtimeClassLoader;
+        this.domainUri = domainUri;
+    }
+
+    public EmbeddedSCADomainGBean() {
+    }
+    
+    public void doStart() throws Exception {
+        scaDomain = new EmbeddedSCADomain(runtimeClassLoader, domainUri);
+        scaDomain.start();
+        log.debug("EmbeddedSCADomainGBean started. Name=" + abstractName);
+    }
+
+    public void doStop() throws Exception {
+        if(scaDomain != null) {
+            scaDomain.stop();
+        }
+        scaDomain = null;
+        log.debug("EmbeddedSCADomainGBean stopped. Name=" + abstractName);
+    }
+    
+    public void doFail() {
+        scaDomain = null;
+        log.warn("EmbeddedSCADomainGBean failed. Name=" + abstractName);        
+    }
+
+    public SCADomain getScaDomain() {
+        return scaDomain;
+    }
+
+    public static final GBeanInfo GBEAN_INFO;
+    
+    static {
+        GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic(EmbeddedSCADomainGBean.class, NameFactory.GERONIMO_SERVICE);
+        infoFactory.addAttribute("abstractName", AbstractName.class, false);
+        infoFactory.addAttribute("runtimeClassLoader", ClassLoader.class, false);
+        infoFactory.addAttribute("domainUri", String.class, true, true);
+        infoFactory.addInterface(SCADomainInterface.class);
+        infoFactory.setConstructor(new String[]{"abstractName", "runtimeClassLoader", "domainUri"});
+        GBEAN_INFO = infoFactory.getBeanInfo();
+    }
+    
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+}

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedSCADomainGBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedSCADomainGBean.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/EmbeddedSCADomainGBean.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCADomainHelper.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCADomainHelper.java?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCADomainHelper.java (added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCADomainHelper.java Tue Aug 28 12:26:50 2007
@@ -0,0 +1,159 @@
+/*
+ * 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.geronimo.tuscany;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.kernel.repository.Repository;
+
+/**
+ * Utility class to initialize the SCADomain associated with a Module
+ * 
+ * @version $Rev$ $Date$
+ */
+public class SCADomainHelper {
+    private final static Log log = LogFactory.getLog(SCADomainHelper.class);
+
+    /**
+     * Gets all the composites in the Application.
+     * 
+     * @throws IOException
+     */
+    protected static String[] getDeployableComposites(ClassLoader classLoader,
+            Repository repository, AbstractName abstractName, String jarFileName)
+            throws IOException, URISyntaxException {
+        String path = getLocation(repository, abstractName, jarFileName);
+        List<String> compositeNames = new ArrayList<String>();
+        findSCDLInJar(compositeNames, new File(new URI(path)));
+        return compositeNames.toArray(new String[compositeNames.size()]);
+    }
+
+   /**
+    * This method returns the location of directory in which a specified configuration is deployed
+    * 
+    * @param repository Geronimo server's repository
+    * @param abstractName AbstractName of the configuration
+    * @return Directory in which the configuration is deployed
+    */
+    protected static String getLocation(Repository repository, AbstractName abstractName) {
+        return repository.getLocation(abstractName.getArtifact()).toURI().toString();
+    }
+
+    /**
+     * This method returns the location of a jar file under a configuration's directory
+     * 
+     * @param repository Geronimo server's repository
+     * @param abstractName AbstractName of the configuration
+     * @param jarFileName Jar file under the configuration's directory
+     * @return
+     */
+    protected static String getLocation(Repository repository, AbstractName abstractName, String jarFileName) {
+        if (jarFileName != null && jarFileName.length() != -1) {
+            return getLocation(repository, abstractName) + jarFileName;
+        } else {
+            return getLocation(repository, abstractName);
+        }
+    }
+
+    /**
+     * This method finds all composites in a tuscany contribution directory and adds their name to a list
+     * 
+     * @param compositeNames List to add composite names
+     * @param path Path to tuscany contribution directory
+     */
+    protected static void getCompositeNames(List<String> compositeNames, String path) throws URISyntaxException {
+        File file = null;
+        try {
+            file = new File(new URI(path));
+        } catch (URISyntaxException e) {
+            throw e;
+        }
+        int length = file.toURI().getPath().length() + 1;
+        findSCDLInDir(compositeNames, file);
+        String newPath = null;
+        String oldPath = null;
+        for (int i = 0; i < compositeNames.size(); i++) {
+            oldPath = compositeNames.get(i);
+            if (oldPath.length() > length && oldPath.indexOf(file.toURI().getPath()) != -1) {
+                newPath = compositeNames.get(i).substring(length);
+                compositeNames.set(i, newPath);
+            }
+        }
+    }
+
+    /**
+     * This method finds all composites in a tuscany contribution jar and adds their name to a list
+     * 
+     * @param compositeNames List to add composite names
+     * @param file Tuscany contribution jar
+     */
+    private static void findSCDLInJar(List<String> compositeNames, File file) {
+        String name = null;
+        JarFile jar = null;
+        try {
+            jar = new JarFile(file);
+        } catch (IOException e1) {
+            log.error("Problem finding SCDL file.", e1);
+        }
+        for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements();) {
+            JarEntry entry = e.nextElement();
+            name = entry.getName();
+            if (name.endsWith(".composite")) {
+                compositeNames.add(name);
+            }
+        }
+    }
+
+    /**
+     * This method finds all composites in a tuscany contribution directory and adds their name to a list
+     * 
+     * @param compositeNames List to add composite names
+     * @param file Tuscany contribution directory
+     */
+    private static void findSCDLInDir(List<String> compositeNames, File file) throws URISyntaxException {
+        String path = null;
+        File[] files = file.listFiles();
+        if (files != null) {
+            for (int i = 0; i < files.length; i++) {
+                if (files[i].isDirectory()) {
+                    findSCDLInDir(compositeNames, files[i]);
+                } else if (files[i].getName().endsWith(".jar")) {
+                    findSCDLInJar(compositeNames, files[i]);
+                } else {
+                    path = files[i].toURI().getPath();
+                    if (path.endsWith(".composite")) {
+                        compositeNames.add(path);
+                    }
+                }
+            }
+        }
+    }
+}

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCADomainHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCADomainHelper.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCADomainHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCADomainInterface.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCADomainInterface.java?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCADomainInterface.java (added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCADomainInterface.java Tue Aug 28 12:26:50 2007
@@ -0,0 +1,28 @@
+/*
+ * 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.geronimo.tuscany;
+
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface SCADomainInterface {
+    public SCADomain getScaDomain();
+}

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCADomainInterface.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCADomainInterface.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/SCADomainInterface.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyBuilder.java?rev=570534&view=auto
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyBuilder.java (added)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyBuilder.java Tue Aug 28 12:26:50 2007
@@ -0,0 +1,230 @@
+/*
+ * 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.geronimo.tuscany;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.deployment.ConfigurationBuilder;
+import org.apache.geronimo.deployment.DeploymentContext;
+import org.apache.geronimo.deployment.ModuleIDBuilder;
+import org.apache.geronimo.deployment.service.EnvironmentBuilder;
+import org.apache.geronimo.deployment.util.DeploymentUtil;
+import org.apache.geronimo.deployment.xbeans.EnvironmentType;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.gbean.GBeanData;
+import org.apache.geronimo.gbean.GBeanInfo;
+import org.apache.geronimo.gbean.GBeanInfoBuilder;
+import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.Naming;
+import org.apache.geronimo.kernel.config.ConfigurationAlreadyExistsException;
+import org.apache.geronimo.kernel.config.ConfigurationManager;
+import org.apache.geronimo.kernel.config.ConfigurationModuleType;
+import org.apache.geronimo.kernel.config.ConfigurationStore;
+import org.apache.geronimo.kernel.config.ConfigurationUtil;
+import org.apache.geronimo.kernel.config.SimpleConfigurationManager;
+import org.apache.geronimo.kernel.repository.Artifact;
+import org.apache.geronimo.kernel.repository.ArtifactResolver;
+import org.apache.geronimo.kernel.repository.Environment;
+import org.apache.geronimo.kernel.repository.Repository;
+
+/**
+ * Configuration builder for tuscany jars.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class TuscanyBuilder implements ConfigurationBuilder {
+    private final static Log log = LogFactory.getLog(TuscanyBuilder.class);
+
+    private final Environment defaultEnvironment;
+    private final Collection repositories;
+    private final Naming naming;
+    private final ConfigurationManager configurationManager;    
+    private final AbstractNameQuery embeddedSCADomainQuery;
+    private String tuscanyGroupId;
+    
+    private static final String DEFAULT_GROUP_ID = "TuscanyArtifacts";
+    
+    public TuscanyBuilder(Environment defaultEnvironment, Collection repositories, Kernel kernel, ClassLoader classLoader, AbstractNameQuery embeddedSCADomainQuery) {
+        this.defaultEnvironment = defaultEnvironment;
+        this.repositories = repositories;        
+        this.naming = kernel.getNaming();
+        this.configurationManager = ConfigurationUtil.getConfigurationManager(kernel);
+        this.embeddedSCADomainQuery = embeddedSCADomainQuery;
+    }
+    
+    public TuscanyBuilder(){
+        this.defaultEnvironment = null;
+        this.repositories = null;        
+        this.naming = null;
+        this.configurationManager = null;
+        this.embeddedSCADomainQuery = null;
+    }
+
+    public Object getDeploymentPlan(File planFile, JarFile jarFile, ModuleIDBuilder idBuilder) throws DeploymentException {
+        if (planFile == null && jarFile == null) {
+            return null;
+        }
+        
+        // We do not use a geronimo specific plan file any more to identify tuscany artifacts.
+        // Look for any .scdl and .composite files in the jar
+        List<String> probables = new ArrayList<String>();
+        for(Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements(); ){
+            JarEntry entry = e.nextElement();
+            String name = entry.getName();
+            if(name.endsWith(".composite") || name.endsWith(".scdl")){
+                probables.add(name);
+            }
+        }
+        if(!probables.isEmpty()) {
+            return probables; // Return anything non null
+        } else {
+            return null;
+        }
+    }
+
+    public Environment processEnvironment(EnvironmentType environmentType) {
+        return EnvironmentBuilder.buildEnvironment(environmentType, defaultEnvironment);
+    }    
+
+    public Artifact getConfigurationID(Object plan, JarFile module, ModuleIDBuilder idBuilder) throws IOException, DeploymentException {
+        /* We do not use a plan file any more */
+        String artifactId = new File(module.getName()).getName();
+        artifactId = artifactId.substring(0, artifactId.indexOf('.'));
+        Artifact configId = new Artifact(tuscanyGroupId != null ? tuscanyGroupId : DEFAULT_GROUP_ID, artifactId, (String)null, "car");
+        Environment environment = new Environment(configId);
+        idBuilder.resolve(environment, artifactId, "car");
+        if(!environment.getConfigId().isResolved()) {
+            throw new IllegalStateException("Module ID is not fully populated ("+environment.getConfigId()+")");
+        }
+        return environment.getConfigId();
+    }
+
+    public DeploymentContext buildConfiguration(boolean inPlaceDeployment, Artifact configId, Object plan, JarFile jar, 
+        Collection configurationStores, ArtifactResolver artifactResolver, ConfigurationStore targetConfigurationStore) throws IOException, DeploymentException {
+
+        return buildConfiguration(inPlaceDeployment, configId, jar, configurationStores, artifactResolver, targetConfigurationStore);
+    }
+
+    public DeploymentContext buildConfiguration(boolean inPlaceDeployment, Artifact configId, JarFile jar, Collection configurationStores, 
+        ArtifactResolver artifactResolver, ConfigurationStore targetConfigurationStore) throws DeploymentException, IOException {
+        
+        Environment environment = new Environment(configId);
+        EnvironmentBuilder.mergeEnvironments(environment, defaultEnvironment);
+        if(!configId.isResolved()) {
+            throw new IllegalStateException("Module ID should be fully resolved by now (not "+environment.getConfigId()+")");
+        }
+        File outfile;
+        try {
+            outfile = targetConfigurationStore.createNewConfigurationDir(configId);
+        } catch (ConfigurationAlreadyExistsException e) {
+            throw new DeploymentException(e);
+        }
+
+        ConfigurationManager configurationManager = this.configurationManager;
+        if (configurationManager == null) {
+            configurationManager = new SimpleConfigurationManager(configurationStores, artifactResolver, repositories);
+        }
+        AbstractName moduleName = naming.createRootName(configId, configId.toString(), "ServiceModule");
+        DeploymentContext context = new DeploymentContext(outfile,
+                inPlaceDeployment && null != jar ? DeploymentUtil.toFile(jar) : null,
+                environment,
+                moduleName,
+                ConfigurationModuleType.SERVICE,
+                naming,
+                configurationManager,
+                repositories
+        );
+        String jarFileName = "";
+        if(jar != null) {
+            File file = new File(jar.getName());
+            context.addIncludeAsPackedJar(URI.create(file.getName()), jar);
+            jarFileName = file.getName();
+        }
+        try {
+            ClassLoader cl = context.getConfiguration().getConfigurationClassLoader();            
+            addComposite(cl, moduleName, context, jarFileName);
+            return context;
+        } catch (RuntimeException t) {
+            context.close();
+            throw t;
+        } catch (Error e) {
+            context.close();
+            throw e;
+        }
+    }
+
+    public void addComposite(ClassLoader cl, AbstractName moduleName, DeploymentContext context, String jarFileName) throws DeploymentException {
+        GBeanData data = processComposite(cl, moduleName.getArtifact(),  jarFileName);
+        try {
+            context.addGBean(data);
+        } catch (GBeanAlreadyExistsException e) {
+            throw new DeploymentException("Cannot add Tuscany Domain Composite with domain URI'"+data.getAttribute("domainURI")+"' for module "+moduleName+"; a domain composite with that domain URI already exists.");
+        }
+    }
+
+    public GBeanData processComposite(ClassLoader cl, Artifact parentModule, String jarFileName) {
+        GBeanInfo gBeanInfo = GBeanInfo.getGBeanInfo(EmbeddedRuntimeGBean.class.getName(), cl);
+        AbstractName moduleName = naming.createRootName(parentModule, parentModule.toString(), "ServiceModule");
+        AbstractName abstractName = naming.createChildName(moduleName, "EmbeddedRuntime", "GBean");
+        GBeanData data = new GBeanData(abstractName, gBeanInfo);        
+        data.setReferencePattern("embeddedSCADomainRef", embeddedSCADomainQuery);
+        data.setReferencePattern("Repository", new AbstractNameQuery(Repository.class.getName()));
+        data.setAttribute("jarFileName", jarFileName);
+        return data;
+    }    
+
+    public void setTuscanyGroupId(String tuscanyGroupId) {
+    	this.tuscanyGroupId = tuscanyGroupId;
+    }
+
+    public static final GBeanInfo GBEAN_INFO;
+
+    static {
+        GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("Tuscany Builder", TuscanyBuilder.class, "ConfigBuilder");
+
+        infoFactory.addInterface(ConfigurationBuilder.class);
+        infoFactory.addAttribute("defaultEnvironment", Environment.class, true);        
+        infoFactory.addAttribute("embeddedSCADomainQuery", AbstractNameQuery.class, true, true);
+        infoFactory.addAttribute("kernel", Kernel.class, false, false);
+        infoFactory.addAttribute("classLoader",ClassLoader.class,false);
+        infoFactory.addReference("Repository", Repository.class, "Repository");
+        infoFactory.addAttribute("tuscanyGroupId", String.class, true, true);
+        infoFactory.setConstructor(new String[]{"defaultEnvironment", "Repository", "kernel", "classLoader", "embeddedSCADomainQuery"});
+
+        GBEAN_INFO = infoFactory.getBeanInfo();
+    }
+
+    public static GBeanInfo getGBeanInfo() {
+        return GBEAN_INFO;
+    }
+}

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message