You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/03/03 07:27:15 UTC
svn commit: r514092 - in
/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core:
bootstrap/ component/ implementation/composite/ runtime/mini/
Author: rfeng
Date: Fri Mar 2 22:27:14 2007
New Revision: 514092
URL: http://svn.apache.org/viewvc?view=rev&rev=514092
Log:
[sca-integration-branch] Refactor the DefaultSCAContainer to be backed by a mini runtime
Added:
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java (with props)
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntime.java (with props)
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeImpl.java (with props)
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeInfo.java (with props)
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeInfoImpl.java (with props)
Modified:
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/bootstrap/DefaultSCAContainer.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/bootstrap/DefaultSCAContainer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/bootstrap/DefaultSCAContainer.java?view=diff&rev=514092&r1=514091&r2=514092
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/bootstrap/DefaultSCAContainer.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/bootstrap/DefaultSCAContainer.java Fri Mar 2 22:27:14 2007
@@ -18,41 +18,24 @@
*/
package org.apache.tuscany.core.bootstrap;
-import java.net.MalformedURLException;
-import java.net.URI;
import java.net.URL;
-import java.net.URLClassLoader;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
+import java.util.Arrays;
import java.util.List;
import org.apache.tuscany.api.SCAContainer;
import org.apache.tuscany.api.TuscanyException;
-import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
+import org.apache.tuscany.core.component.ComponentContextImpl;
import org.apache.tuscany.core.launcher.CompositeContextImpl;
-import org.apache.tuscany.core.launcher.LauncherImpl;
-import org.apache.tuscany.core.monitor.JavaLoggingMonitorFactory;
-import org.apache.tuscany.core.services.deployment.AssemblyServiceImpl;
-import org.apache.tuscany.core.util.FileHelper;
-import org.apache.tuscany.host.MonitorFactory;
-import org.apache.tuscany.host.deployment.AssemblyService;
-import org.apache.tuscany.host.deployment.ContributionService;
-import org.apache.tuscany.host.runtime.InitializationException;
-import org.apache.tuscany.spi.bootstrap.ComponentNames;
-import org.apache.tuscany.spi.builder.BuilderException;
-import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.core.runtime.mini.SimpleRuntime;
+import org.apache.tuscany.core.runtime.mini.SimpleRuntimeImpl;
+import org.apache.tuscany.core.runtime.mini.SimpleRuntimeInfo;
+import org.apache.tuscany.core.runtime.mini.SimpleRuntimeInfoImpl;
import org.apache.tuscany.spi.component.Component;
-import org.apache.tuscany.spi.component.ComponentException;
import org.apache.tuscany.spi.component.CompositeComponent;
-import org.apache.tuscany.spi.component.SCAObject;
-import org.apache.tuscany.spi.deployer.Deployer;
-import org.apache.tuscany.spi.deployer.DeploymentMonitor;
-import org.apache.tuscany.spi.loader.LoaderException;
-import org.apache.tuscany.spi.model.ComponentDefinition;
-import org.apache.tuscany.spi.wire.WireService;
+import org.apache.tuscany.spi.component.TargetResolutionException;
import org.osoa.sca.ComponentContext;
import org.osoa.sca.CurrentCompositeContext;
+import org.osoa.sca.ServiceUnavailableException;
/**
* Base class for JUnit tests that want to run in an SCA client environment.
@@ -61,183 +44,47 @@
*/
@SuppressWarnings("deprecation")
public class DefaultSCAContainer extends SCAContainer {
- protected CompositeComponent component;
+ protected CompositeComponent application;
protected CompositeContextImpl context;
- protected LauncherImpl launcher;
- protected MonitorFactory monitorFactory;
- // lresende - contribution
- protected AssemblyService assemblyService;
- protected ContributionService contributionService;
+
+ protected SimpleRuntime runtime;
protected void startup(URL system, URL[] exts, URL applicationSCDL, String compositePath) throws Exception {
- if (monitorFactory == null) {
- monitorFactory = new JavaLoggingMonitorFactory();
- }
ClassLoader cl = Thread.currentThread().getContextClassLoader();
- launcher = new LauncherImpl();
- launcher.setApplicationLoader(cl);
-
- if (system == null) {
- system = cl.getResource(SCAContainer.SYSTEM_SCDL);
- if (system == null) {
- system = cl.getResource(SCAContainer.DEFAULT_SYSTEM_SCDL);
- }
- }
+ List<URL> extensions = exts == null ? null : Arrays.asList(exts);
+ SimpleRuntimeInfo runtimeInfo =
+ new SimpleRuntimeInfoImpl(cl, system, extensions, applicationSCDL, compositePath);
+ runtime = new SimpleRuntimeImpl(runtimeInfo);
try {
- CompositeComponent composite = launcher.bootRuntime(system, monitorFactory);
- // lresende - contribution
- AtomicComponent csComponent =
- (AtomicComponent)composite.getSystemChild(ComponentNames.TUSCANY_CONTRIBUTION_SERVICE);
- contributionService = (ContributionService)csComponent.getTargetInstance();
-
- // TODO: Make assembly service a pluggable component?
- this.assemblyService = new AssemblyServiceImpl(contributionService, composite);
- composite.registerJavaObject(ComponentNames.TUSCANY_ASSEMBLY_SERVICE,
- AssemblyService.class,
- assemblyService);
-
- List<URL> extensions = new ArrayList<URL>();
- Enumeration<URL> urls = cl.getResources(SCAContainer.SERVICE_SCDL);
- extensions.addAll(Collections.list(urls));
- urls = cl.getResources(SCAContainer.EXTENSION_SCDL);
- extensions.addAll(Collections.list(urls));
- if (exts != null) {
- for (URL ext : exts) {
- if (!extensions.contains(ext)) {
- extensions.add(ext);
- }
- }
- }
- int i = 0;
- for (URL ext : extensions) {
- deployExtension(composite, "tuscany.extension." + (i++), ext);
- }
-
- SCAObject wireServiceComponent = composite.getSystemChild(ComponentNames.TUSCANY_WIRE_SERVICE);
- if (!(wireServiceComponent instanceof AtomicComponent)) {
- throw new InitializationException("WireService must be an atomic component");
- }
-
- WireService wireService = (WireService)((AtomicComponent)wireServiceComponent).getTargetInstance();
-
- // Start using contribution services
- if (applicationSCDL == null) {
- applicationSCDL = cl.getResource(SCAContainer.APPLICATION_SCDL);
- if (applicationSCDL == null) {
- applicationSCDL = cl.getResource(SCAContainer.META_APPLICATION_SCDL);
- if (applicationSCDL != null) {
- compositePath = SCAContainer.META_APPLICATION_SCDL;
- }
- } else {
- if (compositePath == null) {
- compositePath = SCAContainer.APPLICATION_SCDL;
- }
- }
- if (applicationSCDL == null) {
- throw new RuntimeException("application SCDL not found: " + SCAContainer.APPLICATION_SCDL);
- }
- }
-
- // lresende - contribution
- URL contributionLocation = getContributionLocation(applicationSCDL, compositePath);
- URI contributionId = this.contributionService.contribute(contributionLocation, false);
- URI compositeDefinitionId = contributionId.resolve(compositePath);
-
- component =
- (CompositeComponent)this.assemblyService.addCompositeToDomain(contributionId, compositeDefinitionId);
-
- context = new CompositeContextImpl(component, wireService);
- CurrentCompositeContext.setContext(context);
+ application = runtime.start();
} catch (TuscanyException e) {
- DeploymentMonitor monitor = monitorFactory.getMonitor(DeploymentMonitor.class);
- monitor.deploymentError(e);
throw e;
}
}
- private 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;
- }
-
- /**
- * Sets the monitor factory to use
- *
- * @param monitorFactory the monitor factory to use
- */
- protected void setMonitorFactory(MonitorFactory monitorFactory) {
- this.monitorFactory = monitorFactory;
- }
-
- protected void deployExtension(CompositeComponent composite, String extensionName, URL scdlURL)
- throws LoaderException, BuilderException, ComponentException, InitializationException {
- SystemCompositeImplementation implementation = new SystemCompositeImplementation();
- implementation.setScdlLocation(scdlURL);
- implementation.setClassLoader(new URLClassLoader(new URL[] {scdlURL}, getClass().getClassLoader()));
-
- ComponentDefinition<SystemCompositeImplementation> definition =
- new ComponentDefinition<SystemCompositeImplementation>(extensionName, implementation);
-
- SCAObject child = composite.getSystemChild(ComponentNames.TUSCANY_DEPLOYER);
- if (!(child instanceof AtomicComponent)) {
- throw new InitializationException("Deployer must be an atomic component");
- }
- Deployer deployer = (Deployer)((AtomicComponent)child).getTargetInstance();
- Component component = deployer.deploy(composite, definition);
- component.start();
- }
-
protected void shutdown() throws Exception {
- CurrentCompositeContext.setContext(null);
- component.stop();
- launcher.shutdownRuntime();
+ runtime.destroy();
}
@Override
protected ComponentContext getContext(String componentName) {
- // TODO
- return null;
+ CompositeComponent composite = ((CompositeContextImpl) context).getComposite();
+ Component component = (Component) composite.getChild(componentName);
+ return new ComponentContextImpl(CurrentCompositeContext.getContext(), component);
}
public CompositeComponent getCompsiteComponent() {
- return component;
+ return application;
}
-
- @Override
- public Object getSystemService(String serviceName){
- if(serviceName.equals(ComponentNames.TUSCANY_CONTRIBUTION_SERVICE)) {
- return this.contributionService;
- } else if(serviceName.equals(ComponentNames.TUSCANY_ASSEMBLY_SERVICE)) {
- return this.assemblyService;
- } else {
- return null;
+ @Override
+ public Object getSystemService(String serviceName) {
+ try {
+ return runtime.getSystemService(Object.class, serviceName);
+ } catch (TargetResolutionException e) {
+ throw new ServiceUnavailableException(e);
}
}
}
Added: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java?view=auto&rev=514092
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java Fri Mar 2 22:27:14 2007
@@ -0,0 +1,85 @@
+/*
+ * 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.core.component;
+
+import java.net.URI;
+
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.CompositeContext;
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.ServiceRuntimeException;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+import org.apache.tuscany.spi.component.Component;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentContextImpl implements ComponentContext {
+ private final CompositeContext context;
+ private final Component component;
+
+ public ComponentContextImpl(CompositeContext context, Component component) {
+ this.component = component;
+ this.context = context;
+ }
+
+ public String getURI() {
+ try {
+ return component.getName();
+ } catch (TuscanyRuntimeException e) {
+ throw new ServiceRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ throw new UnsupportedOperationException();
+ }
+
+ public <B> B getService(Class<B> businessInterface, String referenceName) {
+ try {
+ return context.locateService(businessInterface, component.getName() + "/" + referenceName);
+ } catch (TuscanyRuntimeException e) {
+ throw new ServiceRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String referenceName) {
+ throw new UnsupportedOperationException();
+ }
+
+ public <B> B getProperty(Class<B> type, String propertyName) {
+ throw new UnsupportedOperationException();
+ }
+
+ public <B> ServiceReference<B> createSelfReference(Class<B> businessInterface) {
+ return null;
+ }
+
+ public <B> ServiceReference<B> createSelfReference(Class<B> businessInterface, String serviceName) {
+ return null;
+ }
+
+ public RequestContext getRequestContext() {
+ return context.getRequestContext();
+ }
+}
Propchange: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/component/ComponentContextImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java?view=diff&rev=514092&r1=514091&r2=514092
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/implementation/composite/AbstractCompositeContext.java Fri Mar 2 22:27:14 2007
@@ -117,4 +117,8 @@
return wire;
}
+ public CompositeComponent getComposite() {
+ return composite;
+ }
+
}
Added: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntime.java?view=auto&rev=514092
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntime.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntime.java Fri Mar 2 22:27:14 2007
@@ -0,0 +1,32 @@
+/*
+ * 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.core.runtime.mini;
+
+import org.apache.tuscany.host.runtime.TuscanyRuntime;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface SimpleRuntime extends TuscanyRuntime {
+ CompositeComponent start() throws Exception;
+ <T> T getSystemService(Class<T> type, String name) throws TargetResolutionException;
+}
Propchange: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntime.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntime.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeImpl.java?view=auto&rev=514092
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeImpl.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeImpl.java Fri Mar 2 22:27:14 2007
@@ -0,0 +1,138 @@
+/*
+ * 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.core.runtime.mini;
+
+import static org.apache.tuscany.spi.bootstrap.ComponentNames.TUSCANY_ASSEMBLY_SERVICE;
+import static org.apache.tuscany.spi.bootstrap.ComponentNames.TUSCANY_CONTRIBUTION_SERVICE;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.api.annotation.LogLevel;
+import org.apache.tuscany.core.launcher.CompositeContextImpl;
+import org.apache.tuscany.core.monitor.JavaLoggingMonitorFactory;
+import org.apache.tuscany.core.runtime.AbstractRuntime;
+import org.apache.tuscany.core.services.deployment.AssemblyServiceImpl;
+import org.apache.tuscany.host.MonitorFactory;
+import org.apache.tuscany.host.RuntimeInfo;
+import org.apache.tuscany.host.deployment.AssemblyService;
+import org.apache.tuscany.host.deployment.ContributionService;
+import org.apache.tuscany.host.monitor.FormatterRegistry;
+import org.apache.tuscany.host.runtime.InitializationException;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.ComponentRegistrationException;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.osoa.sca.CompositeContext;
+import org.osoa.sca.CurrentCompositeContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SimpleRuntimeImpl extends AbstractRuntime implements SimpleRuntime {
+ protected JavaLoggingMonitorFactory monitorFactory;
+ protected SimpleMonitor monitor;
+ protected CompositeComponent application;
+
+ public SimpleRuntimeImpl(SimpleRuntimeInfo runtimeInfo) {
+ super();
+ monitorFactory = new JavaLoggingMonitorFactory();
+ setMonitorFactory(monitorFactory);
+ monitor = monitorFactory.getMonitor(SimpleMonitor.class);
+ ClassLoader hostClassLoader = ClassLoader.getSystemClassLoader();
+ setHostClassLoader(hostClassLoader);
+ setSystemScdl(runtimeInfo.getSystemSCDL());
+ setRuntimeInfo(runtimeInfo);
+ }
+
+ public interface SimpleMonitor {
+ @LogLevel("SEVERE")
+ void runError(Exception e);
+ }
+
+ public CompositeComponent start() throws Exception {
+ initialize();
+ ContributionService contributionService =
+ getSystemService(ContributionService.class, TUSCANY_CONTRIBUTION_SERVICE);
+ CompositeComponent composite = getTuscanySystem();
+ // TODO: Make assembly service a pluggable component?
+ AssemblyService assemblyService = new AssemblyServiceImpl(contributionService, composite);
+ composite.registerJavaObject(TUSCANY_ASSEMBLY_SERVICE, AssemblyService.class, assemblyService);
+
+ SimpleRuntimeInfo runtimeInfo = (SimpleRuntimeInfo)getRuntimeInfo();
+ int i = 0;
+ for (URL ext : runtimeInfo.getExtensionSCDLs()) {
+ CompositeComponent extensionComponent =
+ deploySystemScdl(getDeployer(), getTuscanySystem(), "tuscany.extension." + (i++), ext, runtimeInfo
+ .getClassLoader());
+ extensionComponent.start();
+ }
+
+ URI contributionId = contributionService.contribute(runtimeInfo.getContributionRoot(), false);
+ URI compositeDefinitionId = contributionId.resolve(runtimeInfo.getCompositePath());
+
+ application =
+ (CompositeComponent)assemblyService.addCompositeToDomain(contributionId, compositeDefinitionId);
+
+ CompositeContext context = new CompositeContextImpl(application, getWireService());
+ CurrentCompositeContext.setContext(context);
+ return application;
+ }
+
+ public <T> T getSystemService(Class<T> type, String name) throws TargetResolutionException {
+ SCAObject child = getTuscanySystem().getSystemChild(name);
+ if (child == null) {
+ return null;
+ }
+ AtomicComponent service = (AtomicComponent)child;
+ return type.cast(service.getTargetInstance());
+ }
+
+ @Override
+ protected void registerSystemComponents() throws InitializationException {
+ try {
+ // initialize the runtime info
+ CompositeComponent parent = getSystemComponent();
+ parent.registerJavaObject("RuntimeInfo", RuntimeInfo.class, getRuntimeInfo());
+
+ // register the monitor factory
+ if (monitorFactory instanceof FormatterRegistry) {
+ List<Class<?>> interfazes = new ArrayList<Class<?>>(2);
+ interfazes.add(MonitorFactory.class);
+ interfazes.add(FormatterRegistry.class);
+ parent.registerJavaObject("MonitorFactory", interfazes, monitorFactory);
+ } else {
+ parent.registerJavaObject("MonitorFactory", MonitorFactory.class, monitorFactory);
+ }
+ } catch (ComponentRegistrationException e) {
+ throw new InitializationException(e);
+ }
+ }
+
+ @Override
+ public void destroy() {
+ CurrentCompositeContext.setContext(null);
+ application.stop();
+ super.destroy();
+ }
+
+}
Propchange: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeInfo.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeInfo.java?view=auto&rev=514092
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeInfo.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeInfo.java Fri Mar 2 22:27:14 2007
@@ -0,0 +1,46 @@
+/*
+ * 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.core.runtime.mini;
+
+import java.net.URL;
+import java.util.List;
+
+import org.apache.tuscany.host.RuntimeInfo;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface SimpleRuntimeInfo extends RuntimeInfo {
+ 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();
+ List<URL> getExtensionSCDLs();
+ URL getContributionRoot();
+
+}
Propchange: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeInfo.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeInfoImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeInfoImpl.java?view=auto&rev=514092
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeInfoImpl.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeInfoImpl.java Fri Mar 2 22:27:14 2007
@@ -0,0 +1,170 @@
+/*
+ * 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.core.runtime.mini;
+
+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;
+
+ /**
+ * @param classLoader
+ * @param compositePath
+ * @param extensions
+ * @param applicationSCDL
+ * @param systemSCDL
+ */
+ public SimpleRuntimeInfoImpl(ClassLoader classLoader,
+ URL systemSCDL,
+ List<URL> extensions,
+ URL applicationSCDL,
+ String compositePath) {
+ this(classLoader, compositePath);
+ this.extensions = extensions;
+ this.applicationSCDL = applicationSCDL;
+ this.systemSCDL = systemSCDL;
+ }
+
+ 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();
+ }
+
+ 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() {
+ return getContributionLocation(getApplicationSCDL(), compositePath);
+ }
+
+ 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;
+ }
+
+}
Propchange: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeInfoImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/mini/SimpleRuntimeInfoImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org
[sca-java-integration-branch] Re: svn commit: r514092
Posted by Jean-Sebastien Delfino <js...@apache.org>.
[snip]
rfeng@apache.org wrote:
> Author: rfeng
> Date: Fri Mar 2 22:27:14 2007
> New Revision: 514092
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=514092
> Log:
> [sca-integration-branch] Refactor the DefaultSCAContainer to be backed by a mini runtime
>
>
>
Now that Raymond has re-based SCAContainer on a mini implementation of
o.a.t.host.runtime.TuscanyRuntime, I'm going to rename it to SCARuntime.
I'll take care of adjusting the test cases and samples as well.
--
Jean-Sebastien
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-dev-help@ws.apache.org