tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r681580 [2/2] - in /tuscany/java/sca/modules/node2-launcher-osgi: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/tuscany/ src/main/java/org/apache/tuscany/sca/ src/main/java/org/apache...
Date Fri, 01 Aug 2008 01:42:30 GMT
Added: tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherUtil.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherUtil.java?rev=681580&view=auto
==============================================================================
--- tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherUtil.java
(added)
+++ tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherUtil.java
Thu Jul 31 18:42:29 2008
@@ -0,0 +1,179 @@
+/*
+ * 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.node.osgi.launcher;
+
+import java.lang.reflect.Constructor;
+import java.util.logging.Level;
+
+/**
+ * Common functions and constants used by the admin components.
+ *
+ * @version $Rev$ $Date$
+ */
+final class NodeLauncherUtil {
+    // private static final Logger logger = Logger.getLogger(NodeLauncherUtil.class.getName());
+
+    private static final String DOMAIN_MANAGER_LAUNCHER_BOOTSTRAP =
+        "org.apache.tuscany.sca.domain.manager.launcher.DomainManagerLauncherBootstrap";
+
+    private static final String NODE_IMPLEMENTATION_DAEMON_BOOTSTRAP =
+        "org.apache.tuscany.sca.implementation.node.launcher.NodeImplementationDaemonBootstrap";
+
+    private static final String NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP =
+        "org.apache.tuscany.sca.implementation.node.launcher.NodeImplementationLauncherBootstrap";
+
+    /**
+     * Collect JAR files under the given directory.
+     * 
+     * @p @param contributions
+     * @throws LauncherException
+     */
+    static Object node(String configurationURI,
+                       String compositeURI,
+                       String compositeContent,
+                       Contribution[] contributions,
+                       ClassLoader contributionClassLoader) throws LauncherException {
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+        try {
+
+            // Use Java reflection to create the node as only the runtime class
+            // loader knows the runtime classes required by the node
+            String className = NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP;
+            Class<?> bootstrapClass;
+            bootstrapClass = Class.forName(className, false, tccl);
+
+            Object bootstrap;
+            if (configurationURI != null) {
+
+                // Construct the node with a configuration URI
+                bootstrap = bootstrapClass.getConstructor(String.class).newInstance(configurationURI);
+
+            } else if (contributionClassLoader != null) {
+
+                // Construct the node with a compositeURI and a classloader
+                Constructor<?> constructor = bootstrapClass.getConstructor(String.class,
ClassLoader.class);
+                bootstrap = constructor.newInstance(compositeURI, contributionClassLoader);
+
+            } else if (compositeContent != null) {
+
+                // Construct the node with a composite URI, the composite content and
+                // the URIs and locations of a list of contributions
+                Constructor<?> constructor =
+                    bootstrapClass.getConstructor(String.class, String.class, String[].class,
String[].class);
+                String[] uris = new String[contributions.length];
+                String[] locations = new String[contributions.length];
+                for (int i = 0; i < contributions.length; i++) {
+                    uris[i] = contributions[i].getURI();
+                    locations[i] = contributions[i].getLocation();
+                }
+                bootstrap = constructor.newInstance(compositeURI, compositeContent, uris,
locations);
+
+            } else {
+
+                // Construct the node with a composite URI and the URIs and
+                // locations of a list of contributions
+                Constructor<?> constructor =
+                    bootstrapClass.getConstructor(String.class, String[].class, String[].class);
+                String[] uris = new String[contributions.length];
+                String[] locations = new String[contributions.length];
+                for (int i = 0; i < contributions.length; i++) {
+                    uris[i] = contributions[i].getURI();
+                    locations[i] = contributions[i].getLocation();
+                }
+                bootstrap = constructor.newInstance(compositeURI, uris, locations);
+            }
+
+            Object node = bootstrapClass.getMethod("getNode").invoke(bootstrap);
+            return node;
+
+        } catch (Exception e) {
+            NodeLauncher.logger.log(Level.SEVERE, "SCA Node could not be created", e);
+            throw new LauncherException(e);
+        } finally {
+            Thread.currentThread().setContextClassLoader(tccl);
+        }
+    }
+
+    /**
+     * Creates a new node daemon.
+     * 
+     * @throws LauncherException
+     */
+    static Object nodeDaemon() throws LauncherException {
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+        try {
+
+            // Use Java reflection to create the node daemon as only the runtime class
+            // loader knows the runtime classes required by the node
+            String className = NODE_IMPLEMENTATION_DAEMON_BOOTSTRAP;
+            Class<?> bootstrapClass;
+            bootstrapClass = Class.forName(className, false, tccl);
+            Object bootstrap = bootstrapClass.getConstructor().newInstance();
+
+            Object nodeDaemon = bootstrapClass.getMethod("getNode").invoke(bootstrap);
+            return nodeDaemon;
+
+        } catch (Exception e) {
+            NodeLauncher.logger.log(Level.SEVERE, "SCA Node Daemon could not be created",
e);
+            throw new LauncherException(e);
+        } finally {
+            Thread.currentThread().setContextClassLoader(tccl);
+        }
+    }
+
+    /**
+     * Creates a new domain manager.
+     * 
+     * @throws LauncherException
+     */
+    static Object domainManager(String rootDirectory) throws LauncherException {
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+        try {
+
+            // Use Java reflection to create the node daemon as only the runtime class
+            // loader knows the runtime classes required by the node
+            String className = DOMAIN_MANAGER_LAUNCHER_BOOTSTRAP;
+            Class<?> bootstrapClass;
+            bootstrapClass = Class.forName(className, false, tccl);
+            Constructor<?> constructor = bootstrapClass.getConstructor(String.class);
+            Object bootstrap = constructor.newInstance(rootDirectory);
+
+            Object domainManager = bootstrapClass.getMethod("getNode").invoke(bootstrap);
+            return domainManager;
+
+        } catch (Exception e) {
+            NodeLauncher.logger.log(Level.SEVERE, "SCA Domain Manager could not be created",
e);
+            throw new LauncherException(e);
+        } finally {
+            Thread.currentThread().setContextClassLoader(tccl);
+        }
+    }
+    
+    static OSGiHost startOSGi() {
+        OSGiHost host = new FelixOSGiHost();
+        host.start();
+        return host;
+    }
+    
+    static void stopOSGi(OSGiHost host) {
+        host.stop();
+    }
+
+}

Propchange: tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherUtil.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeMain.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeMain.java?rev=681580&view=auto
==============================================================================
--- tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeMain.java
(added)
+++ tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeMain.java
Thu Jul 31 18:42:29 2008
@@ -0,0 +1,44 @@
+/*
+ * 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.node.osgi.launcher;
+
+
+/**
+ * Main class for this JAR.
+ * With no arguments this class launches the SCA Node Daemon.
+ * With a "domain" argument it launches the SCA domain admin node.
+ * With any other argument it launches an SCA Node. 
+ *  
+ * @version $Rev$ $Date$
+ */
+public class NodeMain {
+
+    public static void main(String[] args) throws Exception {
+        if (args.length != 0) {
+            if (args[0].equals("domain")) {
+                DomainManagerLauncher.main(args);
+            } else {
+                NodeLauncher.main(args);
+            }
+        } else {
+            NodeDaemonLauncher.main(args);
+        }
+    }
+}

Propchange: tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeMain.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeMain.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeServletFilter.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeServletFilter.java?rev=681580&view=auto
==============================================================================
--- tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeServletFilter.java
(added)
+++ tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeServletFilter.java
Thu Jul 31 18:42:29 2008
@@ -0,0 +1,127 @@
+/*
+ * 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.node.osgi.launcher;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * A Servlet filter that forwards service requests to the Servlets registered with
+ * the Tuscany ServletHost.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class NodeServletFilter implements Filter {
+    private static final String NODE_WEB_APP_SERVLET_HOST = "org.apache.tuscany.sca.implementation.node.osgi.webapp.NodeWebAppServletHost";
+
+    private static final long serialVersionUID = 1L;
+
+    private static final Logger logger = Logger.getLogger(NodeServletFilter.class.getName());
+
+    private ClassLoader runtimeClassLoader;
+    private Class<?> servletHostClass;
+    private Object servletHost;
+    private Filter filter;
+
+    public void init(FilterConfig filterConfig) throws ServletException {
+        logger.info("Apache Tuscany SCA WebApp Node starting...");
+
+        try {
+            // Get the Tuscany runtime ClassLoader
+            ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+            
+            try {
+                if (runtimeClassLoader != null) {
+                    Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+                }
+        
+                // Load the Tuscany WebApp Servlet host and get the host instance
+                // for the current webapp
+                String className = NODE_WEB_APP_SERVLET_HOST; 
+                if (runtimeClassLoader != null) {
+                    servletHostClass = Class.forName(className, true, runtimeClassLoader);
+                } else {
+                    servletHostClass = Class.forName(className);
+                }
+                servletHost = servletHostClass.getMethod("servletHost").invoke(null);
+        
+                // Initialize the Servlet host
+                servletHostClass.getMethod("init", FilterConfig.class).invoke(servletHost,
filterConfig);
+    
+                // The Servlet host also implements the filter interface 
+                filter = (Filter)servletHost;
+                
+            } finally {
+                Thread.currentThread().setContextClassLoader(tccl);
+            }
+            
+        } catch (Exception e) {
+            logger.log(Level.SEVERE, "Error Starting SCA WebApp Node", e);
+            throw new ServletException(e);
+        }
+
+        logger.info("SCA WebApp Node started.");
+    }
+
+    public void destroy() {
+        logger.info("Apache Tuscany WebApp Node stopping...");
+        if (servletHost != null) {
+            ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+            try {
+                if (runtimeClassLoader != null) {
+                    Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+                }
+                
+                servletHostClass.getMethod("destroy").invoke(servletHost);
+                
+            } catch (Exception e) {
+                logger.log(Level.SEVERE, "Error Stopping SCA WebApp Node", e);
+            } finally {
+                Thread.currentThread().setContextClassLoader(tccl);
+            }
+        }
+        logger.info("SCA WebApp Node stopped.");
+    }
+
+    public void doFilter(ServletRequest request, ServletResponse response, javax.servlet.FilterChain
chain)
+        throws IOException, ServletException {
+
+        // Delegate to the Servlet host filter
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+        try {
+            if (runtimeClassLoader != null) {
+                Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+            }
+            
+            filter.doFilter(request, response, chain);
+            
+        } finally {
+            Thread.currentThread().setContextClassLoader(tccl);
+        }
+    }
+
+}

Propchange: tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeServletFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeServletFilter.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/OSGiHost.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/OSGiHost.java?rev=681580&view=auto
==============================================================================
--- tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/OSGiHost.java
(added)
+++ tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/OSGiHost.java
Thu Jul 31 18:42:29 2008
@@ -0,0 +1,30 @@
+/*
+ * 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.node.osgi.launcher;
+
+import org.osgi.framework.BundleContext;
+
+/**
+ * SPI to plug in OSGi implementations such as Equinox or Felix
+ */
+public interface OSGiHost {
+    BundleContext start();
+    void stop();
+}

Propchange: tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/OSGiHost.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/OSGiHost.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorld.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorld.java?rev=681580&view=auto
==============================================================================
--- tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorld.java (added)
+++ tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorld.java Thu Jul
31 18:42:29 2008
@@ -0,0 +1,30 @@
+/*
+ * 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 hello;
+
+import org.osoa.sca.annotations.Remotable;
+
+/**
+ * HelloWorld interface
+ */
+@Remotable
+public interface HelloWorld {
+    String hello(String name);
+}

Propchange: tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorld.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorld.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorldImpl.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorldImpl.java?rev=681580&view=auto
==============================================================================
--- tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorldImpl.java (added)
+++ tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorldImpl.java Thu
Jul 31 18:42:29 2008
@@ -0,0 +1,30 @@
+/*
+ * 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 hello;
+
+/**
+ * HelloWorldImpl
+ */
+public class HelloWorldImpl implements HelloWorld {
+    public String hello(String name) {
+        System.out.println("Hello: " + name);
+        return "Hello, " + name;
+    }
+}

Propchange: tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorldImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorldImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHostTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHostTestCase.java?rev=681580&view=auto
==============================================================================
--- tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHostTestCase.java
(added)
+++ tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHostTestCase.java
Thu Jul 31 18:42:29 2008
@@ -0,0 +1,95 @@
+/*
+ * 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.node.osgi.launcher;
+
+import java.util.Dictionary;
+import java.util.Enumeration;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+
+
+/**
+ * 
+ */
+public class FelixOSGiHostTestCase {
+    @Test
+    public void testStartThenStop() {
+        FelixOSGiHost host = new FelixOSGiHost();
+        BundleContext context = host.start();
+        Assert.assertNotNull(context);
+        for (Bundle b : context.getBundles()) {
+            System.out.println(toString(b, false));
+        }
+        host.stop();
+    }
+
+    @Test
+    public void testStartTwice() {
+        FelixOSGiHost host = new FelixOSGiHost();
+        host.start();
+        try {
+            host.start();
+            Assert.fail();
+        } catch (IllegalStateException e) {
+            Assert.assertTrue(IllegalStateException.class.isInstance(e.getCause()));
+        } finally {
+            host.stop();
+        }
+    }
+
+    public static String toString(Bundle b, boolean verbose) {
+        StringBuffer sb = new StringBuffer();
+        sb.append(b.getBundleId()).append(" ").append(b.getSymbolicName());
+        int s = b.getState();
+        if ((s & Bundle.UNINSTALLED) != 0) {
+            sb.append(" UNINSTALLED");
+        }
+        if ((s & Bundle.INSTALLED) != 0) {
+            sb.append(" INSTALLED");
+        }
+        if ((s & Bundle.RESOLVED) != 0) {
+            sb.append(" RESOLVED");
+        }
+        if ((s & Bundle.STARTING) != 0) {
+            sb.append(" STARTING");
+        }
+        if ((s & Bundle.STOPPING) != 0) {
+            sb.append(" STOPPING");
+        }
+        if ((s & Bundle.ACTIVE) != 0) {
+            sb.append(" ACTIVE");
+        }
+
+        sb.append(" ").append(b.getLocation());
+        if (verbose) {
+            Dictionary<Object, Object> dict = b.getHeaders();
+            Enumeration<Object> keys = dict.keys();
+            while (keys.hasMoreElements()) {
+                Object key = keys.nextElement();
+                sb.append(" ").append(key).append("=").append(dict.get(key));
+            }
+        }
+        return sb.toString();
+    }
+}

Propchange: tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHostTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHostTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherTestCase.java?rev=681580&view=auto
==============================================================================
--- tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherTestCase.java
(added)
+++ tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherTestCase.java
Thu Jul 31 18:42:29 2008
@@ -0,0 +1,70 @@
+/*
+ * 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.node.osgi.launcher;
+
+import hello.HelloWorld;
+
+import java.lang.reflect.Method;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * 
+ */
+public class NodeLauncherTestCase {
+    private static OSGiHost host;
+
+    @BeforeClass
+    public static void setUp() {
+        System.setProperty("TUSCANY_HOME", "target/tuscany");
+        host = NodeLauncherUtil.startOSGi();
+    }
+
+    @AfterClass
+    public static void tearDown() {
+        if (host != null) {
+            NodeLauncherUtil.stopOSGi(host);
+        }
+
+    }
+
+    @Test
+    public void testLaunch() throws Exception {
+        NodeLauncher launcher = NodeLauncher.newInstance();
+        Object node = launcher.createNodeFromClassLoader("HelloWorld.composite", getClass().getClassLoader());
+        Method start = node.getClass().getMethod("start");
+        start.invoke(node);
+
+        Method getService = node.getClass().getMethod("getService", Class.class, String.class);
+        HelloWorld hw = (HelloWorld)getService.invoke(node, HelloWorld.class, "HelloWorld");
+        hw.hello("OSGi");
+
+        Method stop = node.getClass().getMethod("stop");
+        stop.invoke(node);
+    }
+    
+    @Test
+    public void testLaunchDomain() throws Exception {
+        DomainManagerLauncher.main(new String[] {});
+    }
+
+}

Propchange: tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/java/sca/modules/node2-launcher-osgi/src/test/resources/HelloWorld.composite
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/node2-launcher-osgi/src/test/resources/HelloWorld.composite?rev=681580&view=auto
==============================================================================
--- tuscany/java/sca/modules/node2-launcher-osgi/src/test/resources/HelloWorld.composite (added)
+++ tuscany/java/sca/modules/node2-launcher-osgi/src/test/resources/HelloWorld.composite Thu
Jul 31 18:42:29 2008
@@ -0,0 +1,30 @@
+<?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.    
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+    xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
+	targetNamespace="http://sample/composite"
+	xmlns:sc="http://sample/composite"
+	name="HelloWorld">
+
+    <component name="HelloWorld">
+        <implementation.java class="hello.HelloWorldImpl"/>
+    </component>
+
+</composite>



Mime
View raw message