summaryrefslogtreecommitdiffstats
path: root/sandbox/rfeng/runtime/embedded/src
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/rfeng/runtime/embedded/src')
-rw-r--r--sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/api/SCARuntime.java249
-rw-r--r--sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/DefaultSCARuntime.java75
-rw-r--r--sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntime.java48
-rw-r--r--sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeImpl.java136
-rw-r--r--sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeInfo.java56
-rw-r--r--sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeInfoImpl.java182
-rw-r--r--sandbox/rfeng/runtime/embedded/src/test/java/calculator/AddService.java25
-rw-r--r--sandbox/rfeng/runtime/embedded/src/test/java/calculator/AddServiceImpl.java30
-rw-r--r--sandbox/rfeng/runtime/embedded/src/test/java/calculator/CalculatorClient.java51
-rw-r--r--sandbox/rfeng/runtime/embedded/src/test/java/calculator/CalculatorService.java35
-rw-r--r--sandbox/rfeng/runtime/embedded/src/test/java/calculator/CalculatorServiceImpl.java70
-rw-r--r--sandbox/rfeng/runtime/embedded/src/test/java/calculator/DivideService.java25
-rw-r--r--sandbox/rfeng/runtime/embedded/src/test/java/calculator/DivideServiceImpl.java30
-rw-r--r--sandbox/rfeng/runtime/embedded/src/test/java/calculator/MultiplyService.java25
-rw-r--r--sandbox/rfeng/runtime/embedded/src/test/java/calculator/MultiplyServiceImpl.java30
-rw-r--r--sandbox/rfeng/runtime/embedded/src/test/java/calculator/SubtractService.java25
-rw-r--r--sandbox/rfeng/runtime/embedded/src/test/java/calculator/SubtractServiceImpl.java30
-rw-r--r--sandbox/rfeng/runtime/embedded/src/test/java/org/apache/tuscany/api/SCARuntimeTestCase.java57
-rw-r--r--sandbox/rfeng/runtime/embedded/src/test/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeImplTestCase.java60
-rw-r--r--sandbox/rfeng/runtime/embedded/src/test/resources/application.composite46
-rw-r--r--sandbox/rfeng/runtime/embedded/src/test/resources/system.composite349
21 files changed, 1634 insertions, 0 deletions
diff --git a/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/api/SCARuntime.java b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/api/SCARuntime.java
new file mode 100644
index 0000000000..8fb945a28a
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/api/SCARuntime.java
@@ -0,0 +1,249 @@
+/*
+ * 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.api;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.osoa.sca.ComponentContext;
+
+/**
+ * SCARuntime is used to start a Tuscany SCA runtime.
+ */
+public abstract class SCARuntime {
+
+ private static SCARuntime instance;
+
+ /**
+ * Read the service name from a configuration file
+ *
+ * @param classLoader
+ * @param name The name of the service class
+ * @return A class name which extends/implements the service class
+ * @throws IOException
+ */
+ private static String getServiceName(ClassLoader classLoader, String name) throws IOException {
+ InputStream is = classLoader.getResourceAsStream("META-INF/services/" + name);
+ if (is == null) {
+ return null;
+ }
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(is));
+ while (true) {
+ String line = reader.readLine();
+ if (line == null) {
+ break;
+ } else if (!line.startsWith("#")) {
+ return line.trim();
+ }
+ }
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns a SCARuntime instance. If the system property
+ * "org.apache.tuscany.api.SCARuntime" is set, its value is used as the name
+ * of the implementation class. Otherwise, if the resource
+ * "META-INF/services/org.apache.tuscany.api.SCARuntime" can be loaded from
+ * the supplied classloader. Otherwise, it will use
+ * "org.apache.tuscany.runtime.embedded.DefaultSCARuntime" as the default.
+ * The named class is loaded from the supplied classloader and instantiated
+ * using its default (no-arg) constructor.
+ *
+ * @return
+ */
+ private static SCARuntime newInstance(final ClassLoader classLoader) {
+
+ try {
+ final String name = SCARuntime.class.getName();
+ String className = AccessController.doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
+ return System.getProperty(name);
+ }
+ });
+
+ if (className == null) {
+ className = getServiceName(classLoader, name);
+ }
+ if (className == null) {
+ className = "org.apache.tuscany.runtime.embedded.DefaultSCARuntime";
+ }
+ Class cls = Class.forName(className, true, classLoader);
+ return (SCARuntime)cls.newInstance(); // NOPMD lresende
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Get an instance of SCA Runtime
+ *
+ * @return The instance
+ */
+ public static synchronized SCARuntime getInstance() { // NOPMD
+ if (instance != null) {
+ return instance;
+ }
+ ClassLoader classLoader = SCARuntime.class.getClassLoader();
+ instance = newInstance(classLoader);
+ return instance;
+ }
+
+ /**
+ * Start the Tuscany runtime using default SCDLs
+ */
+ public static void start() {
+ try {
+ getInstance().startup(null, null, null, null);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Start the SCA Runtime with the given SCDLs
+ *
+ * @param system The URL for the system SCDL
+ * @param extensions An array of URLs for extensions
+ * @param application The URL for the application SCDL
+ */
+ public static void start(URL system, URL[] extensions, URL application, String compositePath) {
+ try {
+ getInstance().startup(system, extensions, application, compositePath);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Start the SCA Runtime with the given SCDL
+ *
+ * @param application The URL for the application SCDL
+ */
+ public static void start(URL application, String compositePath) {
+ try {
+ getInstance().startup(null, null, application, compositePath);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Start the SCA Runtime with the given SCDL
+ *
+ * @param compositePath The path of the application SCDL
+ */
+ public static void start(String compositePath) {
+ try {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ URL applicationURL = cl.getResource(compositePath);
+ getInstance().startup(null, null, applicationURL, compositePath);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Start the SCA Runtime with the given SCDL
+ *
+ * @param compositePath The path of the system SCDL
+ * @param compositePath The path of the application SCDL
+ */
+ public static void start(String system, String compositePath) {
+ try {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ URL systemURL = cl.getResource(system);
+ URL applicationURL = cl.getResource(compositePath);
+ getInstance().startup(systemURL, null, applicationURL, compositePath);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ /**
+ * Get the ComponentContext by name
+ *
+ * @param componentName
+ * @return
+ */
+ public static ComponentContext getComponentContext(String componentName) {
+ return getInstance().getContext(componentName);
+ }
+
+ /**
+ * Get access to a system service
+ *
+ * @param serviceName
+ * @return
+ */
+ protected abstract Object getSystemService(String serviceName);
+
+ /**
+ * Stop the SCA Runtime
+ */
+ public static void stop() {
+ try {
+ getInstance().shutdown();
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ } finally {
+ instance = null;
+ }
+ }
+
+ /**
+ * Look up the ComponentContext by name
+ *
+ * @param componentName
+ * @return
+ */
+ protected abstract ComponentContext getContext(String componentName);
+
+ /**
+ * Start up the runtime
+ *
+ * @param system The URL of the SCDL for tuscany system composite
+ * @param extensions The URLs of the SCDLs for tuscany extension composites
+ * @param application The URL of the SCDL for the application composite
+ * @param compositePath The path of the application composite relative to
+ * the application URL
+ * @throws Exception
+ */
+ protected abstract void startup(URL system, URL[] extensions, URL application, String compositePath)
+ throws Exception;
+
+ /**
+ * Shutdown the runtime
+ *
+ * @throws Exception
+ */
+ protected abstract void shutdown() throws Exception;
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/DefaultSCARuntime.java b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/DefaultSCARuntime.java
new file mode 100644
index 0000000000..1a6ab28cf4
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/DefaultSCARuntime.java
@@ -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.tuscany.runtime.embedded;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.tuscany.api.SCARuntime;
+import org.apache.tuscany.api.TuscanyException;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.ServiceUnavailableException;
+
+/**
+ * Default implementation of SCARuntime.
+ *
+ * @version $Rev$ $Date$
+ */
+@SuppressWarnings("deprecation")
+public class DefaultSCARuntime extends SCARuntime {
+
+ protected SimpleRuntime runtime;
+
+ protected void startup(URL system, URL[] exts, URL applicationSCDL, String compositePath) throws Exception {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ List<URL> extensions = exts == null ? null : Arrays.asList(exts);
+ URI contributionURI = URI.create("/default");
+ SimpleRuntimeInfo runtimeInfo = new SimpleRuntimeInfoImpl(cl, system, extensions, contributionURI,
+ applicationSCDL, compositePath);
+ runtime = new SimpleRuntimeImpl(runtimeInfo);
+
+ try {
+ runtime.start();
+ } catch (TuscanyException e) {
+ throw e;
+ }
+
+ }
+
+ protected void shutdown() throws Exception {
+ runtime.destroy();
+ }
+
+ @Override
+ protected ComponentContext getContext(String componentName) {
+ return runtime.getComponentContext(URI.create(SimpleRuntimeInfo.DEFAULT_COMPOSITE + "/" + componentName));
+ }
+
+ @Override
+ public Object getSystemService(String serviceName) {
+ try {
+ return runtime.getSystemService(Object.class, serviceName);
+ } catch (TargetResolutionException e) {
+ throw new ServiceUnavailableException(e);
+ }
+ }
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntime.java b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntime.java
new file mode 100644
index 0000000000..676d42a3af
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntime.java
@@ -0,0 +1,48 @@
+/*
+ * 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.runtime.embedded;
+
+import org.apache.tuscany.host.runtime.TuscanyRuntime;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+
+/**
+ * A simple runtime to host both Tuscany and application code on the same classpath
+ *
+ * @version $Rev$ $Date$
+ */
+public interface SimpleRuntime extends TuscanyRuntime<SimpleRuntimeInfo> {
+ /**
+ * Start the embedded Tuscany
+ * @return
+ * @throws Exception
+ */
+ Component start() throws Exception;
+
+ /**
+ * Look up system services by name
+ * @param <T>
+ * @param type
+ * @param name
+ * @return
+ * @throws TargetResolutionException
+ */
+ <T> T getSystemService(Class<T> type, String name) throws TargetResolutionException;
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeImpl.java b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeImpl.java
new file mode 100644
index 0000000000..990fa0107f
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeImpl.java
@@ -0,0 +1,136 @@
+/*
+ * 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.runtime.embedded;
+
+import static org.apache.tuscany.runtime.embedded.SimpleRuntimeInfo.DEFAULT_COMPOSITE;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.Collection;
+
+import org.apache.tuscany.api.annotation.LogLevel;
+import org.apache.tuscany.core.component.SimpleWorkContext;
+import org.apache.tuscany.core.implementation.PojoWorkContextTunnel;
+import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
+import org.apache.tuscany.core.runtime.AbstractRuntime;
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.component.ComponentException;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.component.ScopeContainer;
+import org.apache.tuscany.spi.component.ScopeRegistry;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.component.WorkContext;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.ComponentDefinition;
+import org.apache.tuscany.spi.model.CompositeImplementation;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.resolver.ResolutionException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SimpleRuntimeImpl extends AbstractRuntime<SimpleRuntimeInfo> implements SimpleRuntime {
+ private ScopeContainer<URI> container;
+
+ public SimpleRuntimeImpl(SimpleRuntimeInfo runtimeInfo) {
+ super(SimpleRuntimeInfo.class);
+ ClassLoader hostClassLoader = ClassLoader.getSystemClassLoader();
+ setHostClassLoader(hostClassLoader);
+ setApplicationScdl(runtimeInfo.getApplicationSCDL());
+ setSystemScdl(runtimeInfo.getSystemSCDL());
+ setRuntimeInfo(runtimeInfo);
+ }
+
+ public interface SimpleMonitor {
+ @LogLevel("SEVERE")
+ void runError(Exception e);
+ }
+
+ protected Collection<Component> deployExtension(Component parent,
+ URI name,
+ URL extensionSCDL,
+ ClassLoader systemClassLoader) throws LoaderException,
+ BuilderException, ComponentException, ResolutionException {
+
+ SystemCompositeImplementation impl = new SystemCompositeImplementation();
+ impl.setScdlLocation(extensionSCDL);
+ impl.setClassLoader(systemClassLoader);
+ ComponentDefinition<SystemCompositeImplementation> definition
+ = new ComponentDefinition<SystemCompositeImplementation>(name, impl);
+
+ Collection<Component> components = getDeployer().deploy(parent, definition);
+ for (Component component : components) {
+ component.start();
+ }
+ return components;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Component start() throws Exception {
+ initialize();
+
+ ScopeRegistry scopeRegistry = getScopeRegistry();
+ container = scopeRegistry.getScopeContainer(Scope.COMPOSITE);
+
+ /*
+ int i = 0;
+ for (URL ext : runtimeInfo.getExtensionSCDLs()) {
+ URI uri = URI.create("/extensions/extension" + (i++));
+ deployExtension(null, uri, ext, runtimeInfo.getClassLoader());
+ }
+ */
+
+ CompositeImplementation impl = new CompositeImplementation();
+ impl.setScdlLocation(applicationScdl);
+ impl.setClassLoader(runtimeInfo.getClassLoader());
+
+ ComponentDefinition<CompositeImplementation> definition
+ = new ComponentDefinition<CompositeImplementation>(DEFAULT_COMPOSITE, impl);
+ Collection<Component> components = getDeployer().deploy(null, definition);
+ for (Component component : components) {
+ component.start();
+ }
+ container.startContext(DEFAULT_COMPOSITE, DEFAULT_COMPOSITE);
+ getWorkContext().setIdentifier(Scope.COMPOSITE, DEFAULT_COMPOSITE);
+ WorkContext workContext = new SimpleWorkContext();
+ workContext.setIdentifier(Scope.COMPOSITE, DEFAULT_COMPOSITE);
+ PojoWorkContextTunnel.setThreadWorkContext(workContext);
+ return componentManager.getComponent(definition.getUri());
+ }
+
+ @SuppressWarnings("deprecation")
+ public <T> T getSystemService(Class<T> type, String name) throws TargetResolutionException {
+ SCAObject child = componentManager.getComponent(URI.create(name));
+ if (child == null) {
+ return null;
+ }
+ AtomicComponent service = (AtomicComponent)child;
+ return type.cast(service.getTargetInstance());
+ }
+
+ @Override
+ public void destroy() {
+ container.stopContext(DEFAULT_COMPOSITE);
+ getWorkContext().setIdentifier(Scope.COMPOSITE, null);
+ super.destroy();
+ }
+
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeInfo.java b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeInfo.java
new file mode 100644
index 0000000000..740c51a3a3
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeInfo.java
@@ -0,0 +1,56 @@
+/*
+ * 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.runtime.embedded;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+
+import org.apache.tuscany.host.RuntimeInfo;
+import org.apache.tuscany.spi.bootstrap.ComponentNames;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface SimpleRuntimeInfo extends RuntimeInfo {
+ URI DEFAULT_COMPOSITE = ComponentNames.TUSCANY_APPLICATION_ROOT.resolve("default");
+
+ String DEFAULT_SYSTEM_SCDL = "META-INF/tuscany/default-system.composite";
+ String SYSTEM_SCDL = "system.composite";
+ String EXTENSION_SCDL = "META-INF/sca/extension.composite";
+ String SERVICE_SCDL = "META-INF/sca/service.composite";
+ String META_APPLICATION_SCDL = "META-INF/sca/application.composite";
+ String APPLICATION_SCDL = "application.composite";
+
+ ClassLoader getClassLoader();
+
+ String getCompositePath();
+
+ URL getSystemSCDL();
+
+ URL getApplicationSCDL();
+
+ List<URL> getExtensionSCDLs();
+
+ URL getContributionRoot();
+
+ URI getContributionURI();
+
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeInfoImpl.java b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeInfoImpl.java
new file mode 100644
index 0000000000..6839eefc93
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/main/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeInfoImpl.java
@@ -0,0 +1,182 @@
+/*
+ * 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.runtime.embedded;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+
+import org.apache.tuscany.core.util.FileHelper;
+import org.apache.tuscany.host.AbstractRuntimeInfo;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SimpleRuntimeInfoImpl extends AbstractRuntimeInfo implements SimpleRuntimeInfo {
+ private ClassLoader classLoader;
+ private String compositePath;
+
+ private List<URL> extensions;
+ private URL applicationSCDL;
+ private URL systemSCDL;
+
+ private URL contributionURL;
+ private URI contributionURI;
+
+ /**
+ * @param classLoader
+ * @param compositePath
+ * @param extensions
+ * @param applicationSCDL
+ * @param systemSCDL
+ */
+ public SimpleRuntimeInfoImpl(ClassLoader classLoader,
+ URL systemSCDL,
+ List<URL> extensions,
+ URI contributionURI,
+ URL applicationSCDL,
+ String compositePath) {
+ this(classLoader, compositePath);
+ this.extensions = extensions;
+ this.applicationSCDL = applicationSCDL;
+ this.systemSCDL = systemSCDL;
+ this.contributionURI = contributionURI;
+ }
+
+ public SimpleRuntimeInfoImpl(ClassLoader classLoader, String compositePath) {
+ // super(domain, applicationRootDirectory, baseUrl, online, runtimeId);
+ super(URI.create("sca://domain/local"), null, null, false, "simple");
+ if (classLoader != null) {
+ this.classLoader = classLoader;
+ } else {
+ classLoader = Thread.currentThread().getContextClassLoader();
+ }
+ this.compositePath = compositePath != null ? compositePath : APPLICATION_SCDL;
+ getApplicationSCDL();
+ this.contributionURI = URI.create("/default");
+ }
+
+ public ClassLoader getClassLoader() {
+ return classLoader;
+ }
+
+ public String getCompositePath() {
+ return compositePath;
+ }
+
+ public final URL getApplicationSCDL() {
+ if (applicationSCDL == null) {
+ applicationSCDL = classLoader.getResource(compositePath);
+ if (applicationSCDL == null) {
+ applicationSCDL = classLoader.getResource(APPLICATION_SCDL);
+ if (applicationSCDL == null) {
+ applicationSCDL = classLoader.getResource(META_APPLICATION_SCDL);
+ if (applicationSCDL != null) {
+ compositePath = META_APPLICATION_SCDL;
+ }
+ } else {
+ if (compositePath == null) {
+ compositePath = APPLICATION_SCDL;
+ }
+ }
+ if (applicationSCDL == null) {
+ throw new IllegalArgumentException("application SCDL not found: " + APPLICATION_SCDL);
+ }
+ }
+ }
+ return applicationSCDL;
+ }
+
+ public URL getContributionRoot() {
+ if (contributionURL == null) {
+ contributionURL = getContributionLocation(getApplicationSCDL(), compositePath);
+ }
+ return contributionURL;
+ }
+
+ public List<URL> getExtensionSCDLs() {
+ if (extensions == null) {
+ try {
+ List<URL> extensionURLs = new ArrayList<URL>();
+ Enumeration<URL> urls = classLoader.getResources(SERVICE_SCDL);
+ extensionURLs.addAll(Collections.list(urls));
+ urls = classLoader.getResources(EXTENSION_SCDL);
+ extensionURLs.addAll(Collections.list(urls));
+ if (extensions != null) {
+ for (URL ext : extensions) {
+ if (!extensionURLs.contains(ext)) {
+ extensionURLs.add(ext);
+ }
+ }
+ }
+ extensions = extensionURLs;
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+ return extensions;
+ }
+
+ public URL getSystemSCDL() {
+ if (systemSCDL == null) {
+ systemSCDL = classLoader.getResource(SYSTEM_SCDL);
+ if (systemSCDL == null) {
+ systemSCDL = classLoader.getResource(DEFAULT_SYSTEM_SCDL);
+ }
+ }
+ return systemSCDL;
+ }
+
+ private static URL getContributionLocation(URL applicationSCDL, String compositePath) {
+ URL root = null;
+ // "jar:file://....../something.jar!/a/b/c/app.composite"
+ try {
+ String scdlUrl = applicationSCDL.toExternalForm();
+ String protocol = applicationSCDL.getProtocol();
+ if ("file".equals(protocol)) {
+ // directory contribution
+ if (scdlUrl.endsWith(compositePath)) {
+ String location = scdlUrl.substring(0, scdlUrl.lastIndexOf(compositePath));
+ // workaround from evil url/uri form maven
+ root = FileHelper.toFile(new URL(location)).toURI().toURL();
+ }
+
+ } else if ("jar".equals(protocol)) {
+ // jar contribution
+ String location = scdlUrl.substring(4, scdlUrl.lastIndexOf("!/"));
+ // workaround from evil url/uri form maven
+ root = FileHelper.toFile(new URL(location)).toURI().toURL();
+ }
+ } catch (MalformedURLException mfe) {
+ throw new IllegalArgumentException(mfe);
+ }
+
+ return root;
+ }
+
+ public URI getContributionURI() {
+ return contributionURI;
+ }
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/test/java/calculator/AddService.java b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/AddService.java
new file mode 100644
index 0000000000..4eeb30a9c2
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/AddService.java
@@ -0,0 +1,25 @@
+/*
+ * 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 calculator;
+
+public interface AddService {
+
+ double add(double n1, double n2);
+
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/test/java/calculator/AddServiceImpl.java b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/AddServiceImpl.java
new file mode 100644
index 0000000000..8b6fe066a6
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/AddServiceImpl.java
@@ -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 calculator;
+
+/**
+ * An implementation of the Add service
+ */
+public class AddServiceImpl implements AddService {
+
+ public double add(double n1, double n2) {
+ return n1 + n2;
+ }
+
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/test/java/calculator/CalculatorClient.java b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/CalculatorClient.java
new file mode 100644
index 0000000000..37231e53fe
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/CalculatorClient.java
@@ -0,0 +1,51 @@
+/*
+ * 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 calculator;
+
+import org.apache.tuscany.api.SCARuntime;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.ServiceReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CalculatorClient {
+
+ public CalculatorClient() {
+ super();
+ }
+
+ public static void main(String[] args) {
+ // Start the embedded SCA runtime
+ SCARuntime.start();
+
+ // Look up the ComponentContext by name
+ ComponentContext context = SCARuntime.getComponentContext("CalculatorServiceComponent");
+ ServiceReference<CalculatorService> self = context.createSelfReference(CalculatorService.class);
+ CalculatorService calculatorService = self.getService();
+ System.out.println("1.0 x 2.0 = " + calculatorService.multiply(1.0, 2.0));
+ AddService addService = context.getService(AddService.class, "addService");
+ System.out.println("1.0 + 2.0 = " + addService.add(1.0, 2.0));
+
+ // Stop the SCA embedded runtime
+ SCARuntime.stop();
+ }
+
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/test/java/calculator/CalculatorService.java b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/CalculatorService.java
new file mode 100644
index 0000000000..031fa8b912
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/CalculatorService.java
@@ -0,0 +1,35 @@
+/*
+ * 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 calculator;
+
+
+/**
+ * The Calculator service interface.
+ */
+public interface CalculatorService {
+
+ double add(double n1, double n2);
+
+ double subtract(double n1, double n2);
+
+ double multiply(double n1, double n2);
+
+ double divide(double n1, double n2);
+
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/test/java/calculator/CalculatorServiceImpl.java b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/CalculatorServiceImpl.java
new file mode 100644
index 0000000000..3d861f2018
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/CalculatorServiceImpl.java
@@ -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 calculator;
+
+import org.osoa.sca.annotations.Reference;
+
+
+/**
+ * An implementation of the Calculator service.
+ */
+public class CalculatorServiceImpl implements CalculatorService {
+
+ private AddService addService;
+ private SubtractService subtractService;
+ private MultiplyService multiplyService;
+ private DivideService divideService;
+
+ @Reference
+ public void setAddService(AddService addService) {
+ this.addService = addService;
+ }
+
+ @Reference
+ public void setSubtractService(SubtractService subtractService) {
+ this.subtractService = subtractService;
+ }
+
+ @Reference
+ public void setDivideService(DivideService divideService) {
+ this.divideService = divideService;
+ }
+
+ @Reference
+ public void setMultiplyService(MultiplyService multiplyService) {
+ this.multiplyService = multiplyService;
+ }
+
+ public double add(double n1, double n2) {
+ return addService.add(n1, n2);
+ }
+
+ public double subtract(double n1, double n2) {
+ return subtractService.subtract(n1, n2);
+ }
+
+ public double multiply(double n1, double n2) {
+ return multiplyService.multiply(n1, n2);
+ }
+
+ public double divide(double n1, double n2) {
+ return divideService.divide(n1, n2);
+ }
+
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/test/java/calculator/DivideService.java b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/DivideService.java
new file mode 100644
index 0000000000..131c5a8014
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/DivideService.java
@@ -0,0 +1,25 @@
+/*
+ * 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 calculator;
+
+public interface DivideService {
+
+ double divide(double n1, double n2);
+
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/test/java/calculator/DivideServiceImpl.java b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/DivideServiceImpl.java
new file mode 100644
index 0000000000..f7ac0b7287
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/DivideServiceImpl.java
@@ -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 calculator;
+
+/**
+ * An implementation of the Divide service.
+ */
+public class DivideServiceImpl implements DivideService {
+
+ public double divide(double n1, double n2) {
+ return n1 / n2;
+ }
+
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/test/java/calculator/MultiplyService.java b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/MultiplyService.java
new file mode 100644
index 0000000000..a917896aeb
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/MultiplyService.java
@@ -0,0 +1,25 @@
+/*
+ * 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 calculator;
+
+public interface MultiplyService {
+
+ double multiply(double n1, double n2);
+
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/test/java/calculator/MultiplyServiceImpl.java b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/MultiplyServiceImpl.java
new file mode 100644
index 0000000000..b7dca792b2
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/MultiplyServiceImpl.java
@@ -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 calculator;
+
+/**
+ * An implementation of the Multiply service.
+ */
+public class MultiplyServiceImpl implements MultiplyService {
+
+ public double multiply(double n1, double n2) {
+ return n1 * n2;
+ }
+
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/test/java/calculator/SubtractService.java b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/SubtractService.java
new file mode 100644
index 0000000000..e328f024ea
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/SubtractService.java
@@ -0,0 +1,25 @@
+/*
+ * 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 calculator;
+
+public interface SubtractService {
+
+ double subtract(double n1, double n2);
+
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/test/java/calculator/SubtractServiceImpl.java b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/SubtractServiceImpl.java
new file mode 100644
index 0000000000..77b128ab8d
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/test/java/calculator/SubtractServiceImpl.java
@@ -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 calculator;
+
+/**
+ * An implementation of the subtract service.
+ */
+public class SubtractServiceImpl implements SubtractService {
+
+ public double subtract(double n1, double n2) {
+ return n1 - n2;
+ }
+
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/test/java/org/apache/tuscany/api/SCARuntimeTestCase.java b/sandbox/rfeng/runtime/embedded/src/test/java/org/apache/tuscany/api/SCARuntimeTestCase.java
new file mode 100644
index 0000000000..cacbb7162c
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/test/java/org/apache/tuscany/api/SCARuntimeTestCase.java
@@ -0,0 +1,57 @@
+/*
+ * 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.api;
+
+import junit.framework.TestCase;
+
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.ServiceReference;
+
+import calculator.AddService;
+import calculator.CalculatorService;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SCARuntimeTestCase extends TestCase {
+ /**
+ * @throws java.lang.Exception
+ */
+ protected void setUp() throws Exception {
+ SCARuntime.start();
+ }
+
+ public void testStart() throws Exception {
+ ComponentContext context = SCARuntime.getComponentContext("CalculatorServiceComponent");
+ assertNotNull(context);
+ ServiceReference<CalculatorService> self = context.createSelfReference(CalculatorService.class);
+ assertEquals(2.0, self.getService().multiply(1.0, 2.0));
+ AddService service = context.getService(AddService.class, "addService");
+ assertEquals(3.0, service.add(1.0, 2.0));
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ protected void tearDown() throws Exception {
+ SCARuntime.stop();
+ }
+
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/test/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeImplTestCase.java b/sandbox/rfeng/runtime/embedded/src/test/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeImplTestCase.java
new file mode 100644
index 0000000000..1c4b04600d
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/test/java/org/apache/tuscany/runtime/embedded/SimpleRuntimeImplTestCase.java
@@ -0,0 +1,60 @@
+/*
+ * 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.runtime.embedded;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+import org.osoa.sca.ComponentContext;
+
+import calculator.AddService;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SimpleRuntimeImplTestCase extends TestCase {
+ private SimpleRuntime runtime;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ protected void setUp() throws Exception {
+ SimpleRuntimeInfo runtimeInfo = new SimpleRuntimeInfoImpl(getClass().getClassLoader(), "application.composite");
+ runtime = new SimpleRuntimeImpl(runtimeInfo);
+ runtime.start();
+ }
+
+ public void testStart() throws Exception {
+ ComponentContext context = runtime.getComponentContext(URI
+ .create("sca://root.application/default/CalculatorServiceComponent"));
+ assertNotNull(context);
+ AddService service = context.getService(AddService.class, "addService");
+ assertEquals(3.0, service.add(1.0, 2.0));
+ }
+
+ /**
+ * @throws java.lang.Exception
+ */
+ protected void tearDown() throws Exception {
+ runtime.destroy();
+ }
+
+}
diff --git a/sandbox/rfeng/runtime/embedded/src/test/resources/application.composite b/sandbox/rfeng/runtime/embedded/src/test/resources/application.composite
new file mode 100644
index 0000000000..55d4ca889b
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/test/resources/application.composite
@@ -0,0 +1,46 @@
+<?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" name="CalculatorComposite">
+
+ <component name="CalculatorServiceComponent">
+ <implementation.java class="calculator.CalculatorServiceImpl" />
+ <reference name="addService" target="AddServiceComponent" />
+ <reference name="subtractService" target="SubtractServiceComponent" />
+ <reference name="multiplyService" target="MultiplyServiceComponent" />
+ <reference name="divideService" target="DivideServiceComponent" />
+ </component>
+
+ <component name="AddServiceComponent">
+ <implementation.java class="calculator.AddServiceImpl" />
+ </component>
+
+ <component name="SubtractServiceComponent">
+ <implementation.java class="calculator.SubtractServiceImpl" />
+ </component>
+
+ <component name="MultiplyServiceComponent">
+ <implementation.java class="calculator.MultiplyServiceImpl" />
+ </component>
+
+ <component name="DivideServiceComponent">
+ <implementation.java class="calculator.DivideServiceImpl" />
+ </component>
+
+</composite>
diff --git a/sandbox/rfeng/runtime/embedded/src/test/resources/system.composite b/sandbox/rfeng/runtime/embedded/src/test/resources/system.composite
new file mode 100644
index 0000000000..3974e06dd1
--- /dev/null
+++ b/sandbox/rfeng/runtime/embedded/src/test/resources/system.composite
@@ -0,0 +1,349 @@
+<?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.
+-->
+<!--
+ Default system configuration for the launcher environment.
+
+ $Rev: 520623 $ $Date: 2007-03-20 15:17:36 -0700 (Tue, 20 Mar 2007) $
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/sca/system/2.0-alpha"
+ name="org.apache.tuscany.launcher.System" autowire="true">
+
+ <!-- Work manager -->
+ <component name="workManager">
+ <system:implementation.system class="org.apache.tuscany.core.services.work.jsr237.workmanager.ThreadPoolWorkManager" />
+ <property name="poolSize">10</property>
+ </component>
+
+ <component name="workScheduler">
+ <system:implementation.system class="org.apache.tuscany.core.services.work.jsr237.Jsr237WorkScheduler" />
+ </component>
+ <!-- Generator Registry -->
+ <component name="generatorRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.generator.GeneratorRegistryImpl" />
+ </component>
+
+ <component name="javaGenerator">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.java.JavaPhysicalComponentGenerator" />
+ </component>
+
+
+ <!-- JXTA network configurator -->
+ <!-- component name="networkConfigurator">
+ <system:implementation.system
+ class="net.jxta.platform.NetworkConfigurator"/>
+ <property name="principal">principal</property>
+ <property name="password">password</property>
+ </component-->
+
+ <!-- Discovery service -->
+ <!--component name="discoveryService">
+ <system:implementation.system
+ class="org.apache.tuscany.service.discovery.jxta.JxtaDiscoveryService"/>
+ <property name="interval">5000</property>
+ <reference name="configurator" target="networkConfigurator"/>
+ <reference name="workScheduler" target="workScheduler"/>
+ </component-->
+
+ <!-- JMS discovery service -->
+ <!--
+ <component name="discoveryService">
+ <system:implementation.system
+ class="org.apache.tuscany.service.discovery.jms.JmsDiscoveryService"/>
+ <property name="topic">tuscany.federation</property>
+ </component>
+ -->
+
+ <!-- Marshaller registry -->
+ <component name="marshallerRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.marshaller.DefaultModelMarshallerRegistry" />
+ </component>
+
+ <!-- Changeset marshaller -->
+ <component name="changeSetMarshaller">
+ <system:implementation.system class="org.apache.tuscany.core.marshaller.PhysicalChangeSetMarshaller" />
+ </component>
+
+ <!-- Wide definition marshaller -->
+ <component name="wireDefinitionMarshaller">
+ <system:implementation.system class="org.apache.tuscany.core.marshaller.PhysicalWireDefinitionMarshaller" />
+ </component>
+
+ <!-- Operation definition marshaller -->
+ <component name="operationMarshaller">
+ <system:implementation.system class="org.apache.tuscany.core.marshaller.PhysicalOperationDefinitionMarshaller" />
+ </component>
+
+ <!-- Java component definition marshaller -->
+ <component name="javaComponentDefinitionMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalComponentDefinitionMarshaller" />
+ </component>
+
+ <!-- Reflective IF provider definition marshaller -->
+ <component name="reflectiveIfProviderDefinitionMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.extensions.instancefactory.ReflectiveIFProviderDefinitionMarshaller" />
+ </component>
+
+ <!-- Java physical wire source definition marshaller -->
+ <component name="javaWireSourceDefinitionMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalWireSourceDefinitionMarshaller" />
+ </component>
+
+ <!-- Java physical wire target definition marshaller -->
+ <component name="javaWireTargetDefinitionMarshaller">
+ <system:implementation.system
+ class="org.apache.tuscany.core.marshaller.extensions.java.JavaPhysicalWireTargetDefinitionMarshaller" />
+ </component>
+
+ <!-- Builder registry -->
+ <component name="builderRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.builder.physical.DefaultPhysicalComponentBuilderRegistry" />
+ </component>
+ <component name="wireAttacherRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.builder.physical.WireAttacherRegistryImpl" />
+ </component>
+ <component name="providerBuilderRegistry">
+ <system:implementation.system
+ class="org.apache.tuscany.core.component.instancefactory.impl.DefaultIFProviderBuilderRegistry" />
+ </component>
+
+ <component name="reflectiveIFProviderBuilder">
+ <system:implementation.system
+ class="org.apache.tuscany.core.component.instancefactory.impl.ReflectiveIFProviderBuilder" />
+ </component>
+
+ <!-- Java physical component builder -->
+ <component name="javaPhysicalComponentBuilder">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.java.JavaPhysicalComponentBuilder" />
+ </component>
+
+ <!-- Classloader registry -->
+ <!--
+ <component name="classLoaderRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.services.classloading.ClassLoaderRegistryImpl" />
+ </component>
+ -->
+
+ <!-- Federated deployer -->
+ <component name="federateDeployer">
+ <system:implementation.system class="org.apache.tuscany.core.deployer.federation.FederatedDeployer" />
+ </component>
+
+ <!-- Component manager -->
+ <!--
+ <component name="componentManager">
+ <system:implementation.system
+ class="org.apache.tuscany.core.component.ComponentManagerImpl"/>
+ </component>
+ -->
+
+ <!-- Connector -->
+ <!--
+ <component name="connector">
+ <system:implementation.system class="org.apache.tuscany.core.builder.ConnectorImpl" />
+ </component>
+ -->
+
+ <!-- Jetty HTTP service -->
+ <!--
+ <component name="httpService">
+ <system:implementation.system
+ class="org.apache.tuscany.service.jetty.JettyServiceImpl"/>
+ <property name="httpPort">7000</property>
+ </component>
+ -->
+
+ <!-- Console -->
+ <!--
+ <include name="org.apache.tuscany.sca.console"
+ scdlResource="org/apache/tuscany/console/console.scdl"/>
+ -->
+
+ <!-- Assembly service -->
+ <component name="assemblyService">
+ <system:implementation.system class="org.apache.tuscany.core.services.deployment.AssemblyServiceImpl" />
+ </component>
+
+
+ <!--_________________________________________________________________________________________-->
+
+ <!--__________________________Legacy from launcher SCDL _____________________________________-->
+
+ <!--_________________________________________________________________________________________-->
+
+ <!-- Component that provides the Deployer service -->
+ <component name="deployer">
+ <system:implementation.system class="org.apache.tuscany.core.deployer.DeployerImpl" />
+ </component>
+
+ <!-- Work management -->
+ <component name="WorkContext">
+ <system:implementation.system class="org.apache.tuscany.core.component.WorkContextImpl" />
+ </component>
+
+ <!-- Wire service -->
+ <component name="proxyService">
+ <system:implementation.system class="org.apache.tuscany.core.wire.jdk.JDKProxyService" />
+ </component>
+
+ <!-- Store infrastructure -->
+ <component name="store">
+ <system:implementation.system class="org.apache.tuscany.core.services.store.memory.MemoryStore" />
+ </component>
+
+ <!-- Builder and BuilderRegistry -->
+ <component name="builder">
+ <system:implementation.system class="org.apache.tuscany.core.builder.BuilderRegistryImpl" />
+ </component>
+
+ <!-- Resource host registry -->
+ <component name="resourceHostRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.services.host.DelegatingResourceHostRegistry" />
+ </component>
+
+ <!-- Loader and LoaderRegistry -->
+ <component name="loader">
+ <system:implementation.system class="org.apache.tuscany.core.loader.LoaderRegistryImpl" />
+ </component>
+
+ <!-- Introspector and IntrospectionRegistry -->
+ <component name="interfaceProcessorRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.implementation.IntrospectionRegistryImpl" />
+ </component>
+
+ <!-- Connector infrastructure -->
+ <component name="connector">
+ <system:implementation.system class="org.apache.tuscany.core.builder.ConnectorImpl" />
+ </component>
+
+ <component name="wirePostProcessorRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.builder.WirePostProcessorRegistryImpl" />
+ </component>
+
+ <!-- Default scopes -->
+ <component name="scope.stateless">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.StatelessScopeContainer" />
+ </component>
+ <!--
+ <component name="scope.request">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.RequestScopeContainer"/>
+ </component>
+ -->
+ <!--
+ <component name="scope.conversational">
+ <system:implementation.system class="org.apache.tuscany.core.component.scope.ConversationalScopeContainer"/>
+ </component>
+ -->
+
+ <!-- include loader configuration -->
+ <include name="org.apache.tuscany.core.Loader" scdlResource="org/apache/tuscany/core/loader.scdl" />
+
+ <!-- include databinding configuration -->
+ <include name="org.apache.tuscany.core.DataBinding" scdlResource="org/apache/tuscany/core/databinding.scdl" />
+
+ <!-- include implementation processor configuration -->
+ <include name="org.apache.tuscany.core.Implementation" scdlResource="org/apache/tuscany/core/implementation.scdl" />
+
+ <!-- Java interface definition language -->
+ <include name="org.apache.tuscany.core.InterfaceJava" scdlResource="org/apache/tuscany/core/interfaceJava.scdl" />
+
+ <!-- include omposite implementation type -->
+ <include name="org.apache.tuscany.core.Composite" scdlResource="org/apache/tuscany/core/composite.scdl" />
+
+ <!-- System implementation type -->
+ <include name="org.apache.tuscany.core.SystemImplementation"
+ scdlResource="org/apache/tuscany/core/systemImplementation.scdl" />
+
+ <!-- Java implementation type -->
+ <include name="org.apache.tuscany.core.JavaImplementation" scdlResource="org/apache/tuscany/core/javaImplementation.scdl" />
+
+ <!-- service for resolving artifacts using Maven repositories -->
+ <!--
+ <component name="artifactRepository">
+ <system:implementation.system
+ class="org.apache.tuscany.services.maven.MavenArtifactRepository"/>
+ <property name="remoteRepoUrl">
+ http://repo1.maven.org/maven2/,http://people.apache.org/repo/m2-snapshot-repository,http://people.apache.org/repo/m2-incubating-repository/,http://people.apache.org/repo/m1-snapshot-repository/</property>
+ </component>
+ -->
+
+ <component name="policyBuilderRegistry">
+ <system:implementation.system class="org.apache.tuscany.core.policy.PolicyBuilderRegistryImpl" />
+ </component>
+
+ <component name="propertyFactory">
+ <system:implementation.system class="org.apache.tuscany.core.property.PropertyObjectFactoryImpl" />
+ </component>
+
+ <!-- component that scans the extension directory -->
+ <!--
+ <component name="directoryScanExtender" initLevel="90">
+ <system:implementation.system
+ class="org.apache.tuscany.runtime.standalone.host.DirectoryScanExtender"/>
+ <property name="path">extensions</property>
+ </component>
+ -->
+
+ <!-- the local binding -->
+ <component name="localBindingLoader">
+ <system:implementation.system class="org.apache.tuscany.core.binding.local.LocalBindingLoader" />
+ </component>
+
+ <component name="localBindingBuilder">
+ <system:implementation.system class="org.apache.tuscany.core.binding.local.LocalBindingBuilder" />
+ </component>
+
+ <component name="artifactRepository">
+ <system:implementation.system class="org.apache.tuscany.core.services.artifact.LocalMavenRepository" />
+ <property name="repository">.m2/repository</property>
+ </component>
+
+ <!--
+ <component name="launchedLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedLoader"/>
+ </component>
+
+ <component name="launchedComponentLoader">
+ <system:implementation.system
+ class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedComponentTypeLoader"/>
+ </component>
+
+ <component name="launchedComponentBuilder">
+ <system:implementation.system
+ class="org.apache.tuscany.runtime.standalone.host.implementation.launched.LaunchedComponentBuilder"/>
+ </component>
+ -->
+
+ <component name="wiringExceptionFormatter">
+ <system:implementation.system class="org.apache.tuscany.core.builder.WiringExceptionFormatter" />
+ </component>
+
+ <component name="loaderExceptionFormatter">
+ <system:implementation.system class="org.apache.tuscany.core.loader.LoaderExceptionFormatter" />
+ </component>
+
+ <component name="incompatibleServiceContractExceptionFormatter">
+ <system:implementation.system class="org.apache.tuscany.core.wire.IncompatibleServiceContractExceptionFormatter" />
+ </component>
+
+</composite> \ No newline at end of file