You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by jb...@apache.org on 2007/01/10 23:14:42 UTC

svn commit: r495008 - in /incubator/tuscany/java/sca: kernel/core/src/main/java/org/apache/tuscany/core/runtime/ plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/ runtime/standalone/standalone-host/src/main/java/org/apache/tuscany...

Author: jboynes
Date: Wed Jan 10 14:14:41 2007
New Revision: 495008

URL: http://svn.apache.org/viewvc?view=rev&rev=495008
Log:
refactor AbstractRuntime to implement initialize as a template method
simplify subclasses to remove duplicate initialization code

Modified:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java
    incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java
    incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/StandaloneRuntimeImpl.java
    incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java

Modified: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java?view=diff&rev=495008&r1=495007&r2=495008
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java (original)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/runtime/AbstractRuntime.java Wed Jan 10 14:14:41 2007
@@ -19,26 +19,42 @@
 package org.apache.tuscany.core.runtime;
 
 import java.net.URL;
+import javax.xml.stream.XMLInputFactory;
 
-import org.apache.tuscany.spi.component.CompositeComponent;
-import org.apache.tuscany.spi.component.ComponentException;
-import org.apache.tuscany.spi.deployer.Deployer;
-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.builder.BuilderException;
+import org.osoa.sca.CompositeContext;
+import org.osoa.sca.SCA;
 
+import org.apache.tuscany.core.bootstrap.Bootstrapper;
+import org.apache.tuscany.core.bootstrap.DefaultBootstrapper;
 import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
 import org.apache.tuscany.core.monitor.NullMonitorFactory;
+import org.apache.tuscany.core.launcher.CompositeContextImpl;
 import org.apache.tuscany.host.MonitorFactory;
 import org.apache.tuscany.host.RuntimeInfo;
 import org.apache.tuscany.host.management.ManagementService;
+import org.apache.tuscany.host.runtime.InitializationException;
 import org.apache.tuscany.host.runtime.TuscanyRuntime;
+import org.apache.tuscany.spi.bootstrap.RuntimeComponent;
+import org.apache.tuscany.spi.bootstrap.ComponentNames;
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.component.ComponentException;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.component.ComponentRegistrationException;
+import org.apache.tuscany.spi.component.SCAObject;
+import org.apache.tuscany.spi.component.AtomicComponent;
+import org.apache.tuscany.spi.component.TargetResolutionException;
+import org.apache.tuscany.spi.deployer.Deployer;
+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.services.management.TuscanyManagementService;
+import org.apache.tuscany.spi.wire.WireService;
 
 /**
  * @version $Rev$ $Date$
  */
 public abstract class AbstractRuntime implements TuscanyRuntime {
+    private final XMLInputFactory xmlFactory;
     private URL systemScdl;
     private String applicationName;
     private URL applicationScdl;
@@ -48,12 +64,19 @@
     private MonitorFactory monitorFactory;
     private ManagementService<?> managementService;
 
+    private RuntimeComponent runtime;
+    private CompositeComponent systemComponent;
+    private CompositeComponent tuscanySystem;
+    private Deployer deployer;
+    private WireService wireService;
+
     protected AbstractRuntime() {
         this(new NullMonitorFactory());
     }
 
     protected AbstractRuntime(MonitorFactory monitorFactory) {
         this.monitorFactory = monitorFactory;
+        xmlFactory = XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory", getClass().getClassLoader());
     }
 
     public URL getSystemScdl() {
@@ -120,6 +143,116 @@
         this.managementService = managementService;
     }
 
+    protected XMLInputFactory getXMLFactory() {
+        return xmlFactory;
+    }
+
+    protected RuntimeComponent getRuntime() {
+        return runtime;
+    }
+
+    protected CompositeComponent getSystemComponent() {
+        return systemComponent;
+    }
+
+    protected CompositeComponent getTuscanySystem() {
+        return tuscanySystem;
+    }
+
+    protected Deployer getDeployer() {
+        return deployer;
+    }
+
+    protected WireService getWireService() {
+        return wireService;
+    }
+
+    public void initialize() throws InitializationException {
+        Bootstrapper bootstrapper = createBootstrapper();
+        runtime = bootstrapper.createRuntime();
+        runtime.start();
+
+        systemComponent = runtime.getSystemComponent();
+        registerSystemComponents();
+        systemComponent.start();
+
+        // deploy the system scdl
+        try {
+            tuscanySystem = deploySystemScdl(bootstrapper.createDeployer(),
+                                             systemComponent,
+                                             ComponentNames.TUSCANY_SYSTEM,
+                                             getSystemScdl(),
+                                             getClass().getClassLoader());
+        } catch (LoaderException e) {
+            throw new InitializationException(e);
+        } catch (BuilderException e) {
+            throw new InitializationException(e);
+        } catch (ComponentException e) {
+            throw new InitializationException(e);
+        }
+        tuscanySystem.start();
+
+        this.deployer = locateDeployer();
+        this.wireService = locateWireService();
+    }
+
+    public void destroy() {
+        this.wireService = null;
+        this.deployer = null;
+        if (tuscanySystem != null) {
+            tuscanySystem.stop();
+            tuscanySystem = null;
+        }
+        if (systemComponent != null) {
+            systemComponent.stop();
+            systemComponent = null;
+        }
+        if (runtime != null) {
+            runtime.stop();
+            runtime = null;
+        }
+    }
+
+
+
+    protected Bootstrapper createBootstrapper() {
+        TuscanyManagementService tms = (TuscanyManagementService) getManagementService();
+        return new DefaultBootstrapper(getMonitorFactory(), xmlFactory, tms);
+    }
+
+    protected void registerSystemComponents() throws InitializationException {
+        try {
+            systemComponent.registerJavaObject(RuntimeInfo.COMPONENT_NAME, RuntimeInfo.class, runtimeInfo);
+            systemComponent.registerJavaObject("MonitorFactory", MonitorFactory.class, getMonitorFactory());
+        } catch (ComponentRegistrationException e) {
+            throw new InitializationException(e);
+        }
+    }
+
+    protected Deployer locateDeployer() throws InitializationException {
+        SCAObject deployerComponent = tuscanySystem.getSystemChild(ComponentNames.TUSCANY_DEPLOYER);
+        if (!(deployerComponent instanceof AtomicComponent)) {
+            throw new InitializationException("Deployer must be an atomic component");
+        }
+        try {
+            return (Deployer)((AtomicComponent)deployerComponent).getTargetInstance();
+        } catch (TargetResolutionException e) {
+            throw new InitializationException(e);
+        }
+    }
+
+    protected WireService locateWireService() throws InitializationException {
+        SCAObject wireServiceComponent = tuscanySystem.getSystemChild(ComponentNames.TUSCANY_WIRE_SERVICE);
+        if (!(wireServiceComponent instanceof AtomicComponent)) {
+            throw new InitializationException("WireService must be an atomic component");
+        }
+        try {
+            return (WireService)((AtomicComponent)wireServiceComponent).getTargetInstance();
+        } catch (TargetResolutionException e) {
+            throw new InitializationException(e);
+        }
+    }
+
     protected CompositeComponent deploySystemScdl(Deployer deployer,
                                                   CompositeComponent parent,
                                                   String name,
@@ -136,6 +269,26 @@
         return (CompositeComponent) deployer.deploy(parent, definition);
     }
 
+    @Deprecated
+    public CompositeContext deployApplication(String name, URL scdlLocation, ClassLoader classLoader)
+        throws InitializationException {
+        try {
+            CompositeComponent application = deployApplicationScdl(getDeployer(),
+                                                                   getRuntime().getRootComponent(),
+                                                                   name,
+                                                                   scdlLocation,
+                                                                   classLoader);
+            application.start();
+            return new CompositeContextImpl(application, getWireService());
+        } catch (LoaderException ex) {
+            throw new InitializationException(ex);
+        } catch (BuilderException ex) {
+            throw new InitializationException(ex);
+        } catch (ComponentException ex) {
+            throw new InitializationException(ex);
+        }
+    }
+
     protected CompositeComponent deployApplicationScdl(Deployer deployer,
                                                        CompositeComponent parent,
                                                        String name,
@@ -150,6 +303,10 @@
             new ComponentDefinition<CompositeImplementation>(name, impl);
 
         return (CompositeComponent) deployer.deploy(parent, definition);
+    }
+
+    public SCA getContext() {
+        throw new UnsupportedOperationException();
     }
 
 }

Modified: incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java?view=diff&rev=495008&r1=495007&r2=495008
==============================================================================
--- incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java (original)
+++ incubator/tuscany/java/sca/plugins/plugin.itest/src/main/java/org/apache/tuscany/sca/plugin/itest/MavenEmbeddedRuntime.java Wed Jan 10 14:14:41 2007
@@ -22,47 +22,31 @@
 import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
-import javax.xml.stream.XMLInputFactory;
 
 import org.osoa.sca.SCA;
-import org.osoa.sca.CompositeContext;
 
-import org.apache.tuscany.spi.bootstrap.ComponentNames;
-import org.apache.tuscany.spi.bootstrap.RuntimeComponent;
+import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
+import org.apache.tuscany.core.launcher.CompositeContextImpl;
+import org.apache.tuscany.core.runtime.AbstractRuntime;
+import org.apache.tuscany.host.runtime.InitializationException;
+import org.apache.tuscany.sca.plugin.itest.TuscanyStartMojo.MavenEmbeddedArtifactRepository;
 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.ComponentRegistrationException;
 import org.apache.tuscany.spi.component.CompositeComponent;
-import org.apache.tuscany.spi.component.SCAObject;
 import org.apache.tuscany.spi.component.TargetResolutionException;
 import org.apache.tuscany.spi.deployer.CompositeClassLoader;
 import org.apache.tuscany.spi.deployer.Deployer;
 import org.apache.tuscany.spi.loader.LoaderException;
 import org.apache.tuscany.spi.model.ComponentDefinition;
 import org.apache.tuscany.spi.services.artifact.ArtifactRepository;
-import org.apache.tuscany.spi.services.management.TuscanyManagementService;
-import org.apache.tuscany.spi.wire.WireService;
-
-import org.apache.tuscany.core.bootstrap.Bootstrapper;
-import org.apache.tuscany.core.bootstrap.DefaultBootstrapper;
-import org.apache.tuscany.core.implementation.system.model.SystemCompositeImplementation;
-import org.apache.tuscany.core.launcher.CompositeContextImpl;
-import org.apache.tuscany.core.runtime.AbstractRuntime;
-import org.apache.tuscany.host.MonitorFactory;
-import org.apache.tuscany.host.RuntimeInfo;
-import org.apache.tuscany.host.runtime.InitializationException;
-import org.apache.tuscany.sca.plugin.itest.TuscanyStartMojo.MavenEmbeddedArtifactRepository;
 
 /**
  * @version $Rev$ $Date$
  */
 public class MavenEmbeddedRuntime extends AbstractRuntime {
     private CompositeContextImpl context;
-    private RuntimeComponent runtime;
-    private CompositeComponent systemComponent;
-    private CompositeComponent tuscanySystem;
     private CompositeComponent application;
 
     private ArtifactRepository artifactRepository;
@@ -73,77 +57,39 @@
         extensions.put(extensionName, extentionSCDL);
     }
 
-    public void initialize() throws InitializationException {
-        ClassLoader bootClassLoader = getClass().getClassLoader();
-
-        // Read optional system monitor factory classname
-        MonitorFactory mf = getMonitorFactory();
-
-        XMLInputFactory xmlFactory = XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory", bootClassLoader);
-
-        TuscanyManagementService managementService = null;
-        Bootstrapper bootstrapper = new DefaultBootstrapper(mf, xmlFactory, managementService);
-        runtime = bootstrapper.createRuntime();
-        runtime.start();
-        systemComponent = runtime.getSystemComponent();
-
-        // register the runtime info provided by the host
-        RuntimeInfo runtimeInfo = getRuntimeInfo();
+    protected void registerSystemComponents() throws InitializationException {
+        super.registerSystemComponents();
         try {
-            systemComponent.registerJavaObject(RuntimeInfo.COMPONENT_NAME, RuntimeInfo.class, runtimeInfo);
-            systemComponent.registerJavaObject(MavenRuntimeInfo.COMPONENT_NAME,
+            getSystemComponent().registerJavaObject(MavenRuntimeInfo.COMPONENT_NAME,
                 MavenRuntimeInfo.class,
-                (MavenRuntimeInfo) runtimeInfo);
+                (MavenRuntimeInfo) getRuntimeInfo());
 
-            // register the monitor factory provided by the host
-            systemComponent.registerJavaObject("MonitorFactory", MonitorFactory.class, mf);
-            systemComponent.registerJavaObject(MavenEmbeddedArtifactRepository.COMPONENT_NAME,
+            getSystemComponent().registerJavaObject(MavenEmbeddedArtifactRepository.COMPONENT_NAME,
                 ArtifactRepository.class,
                 artifactRepository);
         } catch (ComponentRegistrationException e) {
             throw new InitializationException(e);
         }
+    }
 
-        systemComponent.start();
+    public void initialize() throws InitializationException {
+        super.initialize();
 
         try {
-            // deploy the system scdl
-            Deployer deployer = bootstrapper.createDeployer();
-            tuscanySystem = deploySystemScdl(deployer,
-                systemComponent,
-                ComponentNames.TUSCANY_SYSTEM,
-                getSystemScdl(),
-                bootClassLoader);
-            tuscanySystem.start();
-
-            // switch to the system deployer
-            SCAObject deployerComponent = tuscanySystem.getSystemChild(ComponentNames.TUSCANY_DEPLOYER);
-            if (!(deployerComponent instanceof AtomicComponent)) {
-                throw new InitializationException("Deployer must be an atomic component");
-            }
-            deployer = (Deployer) ((AtomicComponent) deployerComponent).getTargetInstance();
-
-            SCAObject wireServiceComponent = tuscanySystem.getSystemChild(ComponentNames.TUSCANY_WIRE_SERVICE);
-            if (!(wireServiceComponent instanceof AtomicComponent)) {
-                throw new InitializationException("WireService must be an atomic component");
-            }
-            WireService wireService = (WireService) ((AtomicComponent) wireServiceComponent).getTargetInstance();
-
             for (Object extensionName : extensions.keySet()) {
-                deployExtension(tuscanySystem, deployer, (String) extensionName, (URL) extensions.get(extensionName));
+                deployExtension(getTuscanySystem(), getDeployer(), (String) extensionName, (URL) extensions.get(extensionName));
             }
 
-            application = deployApplicationScdl(deployer,
-                runtime.getRootComponent(),
+            application = deployApplicationScdl(getDeployer(),
+                getRuntime().getRootComponent(),
                 getApplicationName(),
                 getApplicationScdl(),
                 getApplicationClassLoader());
             application.start();
 
-            context = new CompositeContextImpl(application, wireService);
+            context = new CompositeContextImpl(application, getWireService());
         } catch (LoaderException e) {
-            // FIXME do something with this
-            e.printStackTrace();
+            throw new InitializationException(e);
         } catch (BuilderException e) {
             throw new InitializationException(e);
         } catch (TargetResolutionException e) {
@@ -174,29 +120,13 @@
         component.start();
     }
 
-    @Deprecated
-    public CompositeContext deployApplication(String name, URL scdlLocation, ClassLoader classLoader) throws InitializationException {
-        throw new UnsupportedOperationException();
-    }
-
     public void destroy() {
         context = null;
         if (application != null) {
             application.stop();
             application = null;
         }
-        if (tuscanySystem != null) {
-            tuscanySystem.stop();
-            tuscanySystem = null;
-        }
-        if (systemComponent != null) {
-            systemComponent.stop();
-            systemComponent = null;
-        }
-        if (runtime != null) {
-            runtime.stop();
-            runtime = null;
-        }
+        super.destroy();
     }
 
     public SCA getContext() {

Modified: incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/StandaloneRuntimeImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/StandaloneRuntimeImpl.java?view=diff&rev=495008&r1=495007&r2=495008
==============================================================================
--- incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/StandaloneRuntimeImpl.java (original)
+++ incubator/tuscany/java/sca/runtime/standalone/standalone-host/src/main/java/org/apache/tuscany/runtime/standalone/host/StandaloneRuntimeImpl.java Wed Jan 10 14:14:41 2007
@@ -18,144 +18,23 @@
  */
 package org.apache.tuscany.runtime.standalone.host;
 
-import java.net.URL;
-import javax.xml.stream.XMLInputFactory;
-
-import org.osoa.sca.SCA;
-import org.osoa.sca.CompositeContext;
-
-import org.apache.tuscany.spi.bootstrap.ComponentNames;
-import org.apache.tuscany.spi.bootstrap.RuntimeComponent;
-import org.apache.tuscany.spi.builder.BuilderException;
-import org.apache.tuscany.spi.component.AtomicComponent;
-import org.apache.tuscany.spi.component.ComponentException;
-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.deployer.Deployer;
-import org.apache.tuscany.spi.loader.LoaderException;
-import org.apache.tuscany.spi.services.management.TuscanyManagementService;
-import org.apache.tuscany.spi.wire.WireService;
-
-import org.apache.tuscany.core.bootstrap.Bootstrapper;
-import org.apache.tuscany.core.bootstrap.DefaultBootstrapper;
-import org.apache.tuscany.core.launcher.CompositeContextImpl;
 import org.apache.tuscany.core.runtime.AbstractRuntime;
-import org.apache.tuscany.host.MonitorFactory;
-import org.apache.tuscany.host.RuntimeInfo;
 import org.apache.tuscany.host.runtime.InitializationException;
 import org.apache.tuscany.runtime.standalone.StandaloneRuntimeInfo;
+import org.apache.tuscany.spi.component.ComponentRegistrationException;
 
 /**
  * @version $Rev$ $Date$
  */
 public class StandaloneRuntimeImpl extends AbstractRuntime {
-    private RuntimeComponent runtime;
-    private CompositeComponent systemComponent;
-    private CompositeComponent tuscanySystem;
-    private Deployer deployer;
-    private WireService wireService;
-
-    public void initialize() throws InitializationException {
-        ClassLoader bootClassLoader = getClass().getClassLoader();
-
-        // Read optional system monitor factory classname
-        MonitorFactory mf = getMonitorFactory();
-
-        XMLInputFactory xmlFactory = XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory", bootClassLoader);
-
-        TuscanyManagementService managementService = (TuscanyManagementService)getManagementService();
-        Bootstrapper bootstrapper = new DefaultBootstrapper(mf, xmlFactory, managementService);
-        runtime = bootstrapper.createRuntime();
-        runtime.start();
-        systemComponent = runtime.getSystemComponent();
-
-        // register the runtime info provided by the host
-        RuntimeInfo runtimeInfo = getRuntimeInfo();
+    protected void registerSystemComponents() throws InitializationException {
+        super.registerSystemComponents();
         try {
-            systemComponent.registerJavaObject(RuntimeInfo.COMPONENT_NAME, RuntimeInfo.class, runtimeInfo);
-            systemComponent.registerJavaObject(StandaloneRuntimeInfo.COMPONENT_NAME,
-                                               StandaloneRuntimeInfo.class,
-                                               (StandaloneRuntimeInfo)runtimeInfo);
-
-            // register the monitor factory provided by the host
-            systemComponent.registerJavaObject("MonitorFactory", MonitorFactory.class, mf);
+            getSystemComponent().registerJavaObject(StandaloneRuntimeInfo.COMPONENT_NAME,
+                                                    StandaloneRuntimeInfo.class,
+                                                    (StandaloneRuntimeInfo) getRuntimeInfo());
         } catch (ComponentRegistrationException e) {
             throw new InitializationException(e);
         }
-
-        systemComponent.start();
-
-        try {
-            // deploy the system scdl
-            Deployer deployer = bootstrapper.createDeployer();
-            tuscanySystem =
-                deploySystemScdl(deployer,
-                                 systemComponent,
-                                 ComponentNames.TUSCANY_SYSTEM,
-                                 getSystemScdl(),
-                                 bootClassLoader);
-            tuscanySystem.start();
-
-            // switch to the system deployer
-            SCAObject deployerComponent = tuscanySystem.getSystemChild(ComponentNames.TUSCANY_DEPLOYER);
-            if (!(deployerComponent instanceof AtomicComponent)) {
-                throw new InitializationException("Deployer must be an atomic component");
-            }
-            this.deployer = (Deployer)((AtomicComponent)deployerComponent).getTargetInstance();
-
-            SCAObject wireServiceComponent = tuscanySystem.getSystemChild(ComponentNames.TUSCANY_WIRE_SERVICE);
-            if (!(wireServiceComponent instanceof AtomicComponent)) {
-                throw new InitializationException("WireService must be an atomic component");
-            }
-            wireService = (WireService)((AtomicComponent)wireServiceComponent).getTargetInstance();
-        } catch (LoaderException ex) {
-            throw new InitializationException(ex);
-        } catch (BuilderException ex) {
-            throw new InitializationException(ex);
-        } catch (ComponentException ex) {
-            throw new InitializationException(ex);
-        }
-    }
-
-
-    @Deprecated
-    public CompositeContext deployApplication(String name, URL scdlLocation, ClassLoader classLoader)
-        throws InitializationException {
-        try {
-            CompositeComponent application = deployApplicationScdl(deployer,
-                                                                   runtime.getRootComponent(),
-                                                                   name,
-                                                                   scdlLocation,
-                                                                   classLoader);
-            application.start();
-            return new CompositeContextImpl(application, wireService);
-        } catch (LoaderException ex) {
-            throw new InitializationException(ex);
-        } catch (BuilderException ex) {
-            throw new InitializationException(ex);
-        } catch (ComponentException ex) {
-            throw new InitializationException(ex);
-        }
     }
-
-    public void destroy() {
-        if (tuscanySystem != null) {
-            tuscanySystem.stop();
-            tuscanySystem = null;
-        }
-        if (systemComponent != null) {
-            systemComponent.stop();
-            systemComponent = null;
-        }
-        if (runtime != null) {
-            runtime.stop();
-            runtime = null;
-        }
-    }
-
-    public SCA getContext() {
-        throw new UnsupportedOperationException();
-    }
-
 }

Modified: incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java?view=diff&rev=495008&r1=495007&r2=495008
==============================================================================
--- incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java (original)
+++ incubator/tuscany/java/sca/runtime/webapp/webapp-host/src/main/java/org/apache/tuscany/runtime/webapp/WebappRuntimeImpl.java Wed Jan 10 14:14:41 2007
@@ -19,27 +19,11 @@
 package org.apache.tuscany.runtime.webapp;
 
 import java.util.StringTokenizer;
-import java.net.URL;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpSessionEvent;
-import javax.xml.stream.XMLInputFactory;
 
 import org.osoa.sca.SCA;
-import org.osoa.sca.CompositeContext;
 
-import org.apache.tuscany.spi.bootstrap.ComponentNames;
-import org.apache.tuscany.spi.bootstrap.RuntimeComponent;
-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.deployer.Deployer;
-import org.apache.tuscany.spi.event.EventPublisher;
-import org.apache.tuscany.spi.services.management.TuscanyManagementService;
-import org.apache.tuscany.spi.wire.WireService;
-
-import org.apache.tuscany.core.bootstrap.Bootstrapper;
-import org.apache.tuscany.core.bootstrap.DefaultBootstrapper;
 import org.apache.tuscany.core.component.event.HttpRequestEnded;
 import org.apache.tuscany.core.component.event.HttpRequestStart;
 import org.apache.tuscany.core.component.event.HttpSessionEnd;
@@ -48,10 +32,13 @@
 import org.apache.tuscany.core.component.event.RequestStart;
 import org.apache.tuscany.core.launcher.CompositeContextImpl;
 import org.apache.tuscany.core.runtime.AbstractRuntime;
-import org.apache.tuscany.host.MonitorFactory;
-import org.apache.tuscany.host.RuntimeInfo;
 import org.apache.tuscany.host.runtime.InitializationException;
 import org.apache.tuscany.host.servlet.ServletRequestInjector;
+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.event.EventPublisher;
 
 /**
  * Bootstrapper for the Tuscany runtime in a web application host. This listener manages one runtime per servlet
@@ -59,12 +46,12 @@
  * <p/>
  * The bootstrapper launches the runtime, booting system extensions and applications, according to the servlet
  * parameters defined in {@link Constants}. When the runtime is instantiated, it is placed in the servlet context with
- * the attribute {@link Constants.RUNTIME_PARAM}. The runtime implements {@link WebappRuntime} so that filters and
+ * the attribute {@link Constants#RUNTIME_PARAM}. The runtime implements {@link WebappRuntime} so that filters and
  * servlets loaded in the parent web app classloader may pass events and requests to it.
  * <p/>
  * By default, the top-most application composite component will be returned when "non-managed" web application code
  * such as JSPs call {@link org.osoa.sca.CurrentCompositeContext}. If a composite deeper in the hierarchy should be
- * returned instead, the <code>web.xml</code> must contain an entry for {@link Constants.CURRENT_COMPOSITE_PATH_PARAM}
+ * returned instead, the <code>web.xml</code> must contain an entry for {@link Constants#CURRENT_COMPOSITE_PATH_PARAM}
  * whose value is a component path expression using '/' as a delimeter such as foo/bar/baz.
  *
  * @version $$Rev$$ $$Date$$
@@ -76,9 +63,6 @@
 
     private ServletRequestInjector requestInjector;
     private CompositeContextImpl context;
-    private RuntimeComponent runtime;
-    private CompositeComponent systemComponent;
-    private CompositeComponent tuscanySystem;
     private CompositeComponent application;
 
     public ServletContext getServletContext() {
@@ -89,79 +73,33 @@
         this.servletContext = servletContext;
     }
 
-    public void initialize() throws InitializationException {
-        ClassLoader bootClassLoader = getClass().getClassLoader();
-
-        // Read optional system monitor factory classname
-        MonitorFactory mf = getMonitorFactory();
-
-        XMLInputFactory xmlFactory = XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory", bootClassLoader);
-
-        TuscanyManagementService managementService = null;
-        Bootstrapper bootstrapper = new DefaultBootstrapper(mf, xmlFactory, managementService);
-        
-        runtime = bootstrapper.createRuntime();
-        runtime.start();
-        systemComponent = runtime.getSystemComponent();
-
+    protected void registerSystemComponents() throws InitializationException {
+        super.registerSystemComponents();
         try {
-            // register the runtime info provided by the host
-            // FIXME andyp@bea.com -- autowire appears to need an exact type match,
-            // hence the need to register this twice
-            systemComponent.registerJavaObject(RuntimeInfo.COMPONENT_NAME,
-                RuntimeInfo.class,
-                getRuntimeInfo());
-            systemComponent.registerJavaObject(WebappRuntimeInfo.COMPONENT_NAME,
-                WebappRuntimeInfo.class,
-                (WebappRuntimeInfo) getRuntimeInfo());
-
-            // register the monitor factory provided by the host
-            systemComponent.registerJavaObject("MonitorFactory", MonitorFactory.class, mf);
+            getSystemComponent().registerJavaObject(WebappRuntimeInfo.COMPONENT_NAME,
+                                                    WebappRuntimeInfo.class,
+                                                    (WebappRuntimeInfo) getRuntimeInfo());
         } catch (ComponentRegistrationException e) {
             throw new InitializationException(e);
         }
+    }
 
-        systemComponent.start();
-
-        if (getSystemScdl() == null) {
-            throw new TuscanyInitException("Could not find system SCDL");
-        }
+    public void initialize() throws InitializationException {
+        super.initialize();
 
         try {
-            // deploy the system scdl
-            Deployer deployer = bootstrapper.createDeployer();
-            tuscanySystem = deploySystemScdl(deployer,
-                systemComponent,
-                ComponentNames.TUSCANY_SYSTEM,
-                getSystemScdl(),
-                bootClassLoader);
-            tuscanySystem.start();
-
-            SCAObject host = tuscanySystem.getSystemChild("servletHost");
+            SCAObject host = getTuscanySystem().getSystemChild("servletHost");
             if (!(host instanceof AtomicComponent)) {
                 throw new InitializationException("Servlet host must be an atomic component");
             }
             requestInjector = (ServletRequestInjector) ((AtomicComponent) host).getTargetInstance();
 
-            // switch to the system deployer
-            SCAObject child = tuscanySystem.getSystemChild(ComponentNames.TUSCANY_DEPLOYER);
-            if (!(child instanceof AtomicComponent)) {
-                throw new InitializationException("Deployer must be an atomic component");
-            }
-            deployer = (Deployer) ((AtomicComponent) child).getTargetInstance();
-
-            SCAObject wireServiceComponent = tuscanySystem.getSystemChild(ComponentNames.TUSCANY_WIRE_SERVICE);
-            if (!(wireServiceComponent instanceof AtomicComponent)) {
-                throw new InitializationException("WireService must be an atomic component");
-            }
-            WireService wireService = (WireService) ((AtomicComponent) wireServiceComponent).getTargetInstance();
-
             if (getApplicationScdl() == null) {
                 throw new TuscanyInitException("Could not find application SCDL");
             }
-            runtime.getRootComponent().start();
-            application = deployApplicationScdl(deployer,
-                runtime.getRootComponent(),
+            getRuntime().getRootComponent().start();
+            application = deployApplicationScdl(getDeployer(),
+                getRuntime().getRootComponent(),
                 getApplicationName(),
                 getApplicationScdl(),
                 getHostClassLoader());
@@ -178,36 +116,18 @@
                     current = (CompositeComponent) o;
                 }
             }
-            context = new CompositeContextImpl(current, wireService);
+            context = new CompositeContextImpl(current, getWireService());
         } catch (Exception e) {
             throw new ServletLauncherInitException(e);
         }
     }
 
-    @Deprecated
-    public CompositeContext deployApplication(String name, URL scdlLocation, ClassLoader classLoader)
-        throws InitializationException {
-        throw new UnsupportedOperationException("Not yet implemented");
-    }
-
     public void destroy() {
-        context = null;
         if (application != null) {
             application.stop();
             application = null;
         }
-        if (tuscanySystem != null) {
-            tuscanySystem.stop();
-            tuscanySystem = null;
-        }
-        if (systemComponent != null) {
-            systemComponent.stop();
-            systemComponent = null;
-        }
-        if (runtime != null) {
-            runtime.stop();
-            runtime = null;
-        }
+        super.destroy();
     }
 
     public SCA getContext() {



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org