HibernateUserAdministrationTest now based on the component mechanism.
[utils] / system / general / src / main / java / org / wamblee / system / core / Container.java
index a0130f7cf3420094198d72b616f3b281a1973987..1c19be341d874e10675fb465ee702b5a662845ea 100644 (file)
@@ -195,28 +195,13 @@ public class Container extends AbstractComponent<Scope> {
             // provided interfaces of the container.
             // The code below assumes an exact match.
             if (!(provided.contains(service))) {
-                throw new SystemAssemblyException(getName() + ": Service '"
+                throw new SystemAssemblyException(getQualifiedName() + ": Service '"
                         + service
                         + "' is not provided by any of its components");
             }
         }
     }
 
-    /**
-     * Starts the container. After the container is started, the container
-     * becomes sealed meaning that no further components, required or provided
-     * interfaces may be added.
-     * 
-     * @return Scope.
-     */
-    public Scope start() {
-        checkSealed();
-        validate();
-        Scope scope = super.start(new DefaultScope(new ProvidedInterface[0]));
-        seal();
-        return scope;
-    }
-
     /**
      * Seal the container, meaning that no further components or interfaces may
      * be added.
@@ -233,17 +218,30 @@ public class Container extends AbstractComponent<Scope> {
     public boolean isSealed() {
         return _sealed;
     }
+    
+    /**
+     * Utility method to start with an empty external scope. This is useful for
+     * top-level containers which are not part of another container. 
+     * @return Scope. 
+     */
+    public Scope start() {
+        Scope scope = new DefaultScope(getProvidedInterfaces()); 
+        return super.start(scope);
+    }
 
     @Override
     protected Scope doStart(Scope aExternalScope) {
-        return doStartOptionalDryRun(aExternalScope, false);
+        checkSealed();
+        validate();
+        Scope scope = new DefaultScope(getProvidedInterfaces(), aExternalScope);
+        doStartOptionalDryRun(scope, false);
+        seal();
+        return scope;
     }
 
-    private Scope doStartOptionalDryRun(Scope aExternalScope, boolean aDryRun) {
+    private void doStartOptionalDryRun(Scope aScope, boolean aDryRun) {
         LOG.info("Starting '" + getQualifiedName() + "'");
 
-        Scope scope = new DefaultScope(getProvidedInterfaces(), aExternalScope);
-
         List<Pair<ProvidedInterface,Component>> allProvided = new ArrayList<Pair<ProvidedInterface,Component>>();
         
         addProvidersOfRequiredInterfaces(allProvided);
@@ -256,8 +254,8 @@ public class Container extends AbstractComponent<Scope> {
 
                 // Start the service.
                 if (!aDryRun) {
-                    Object runtime = component.start(scope);
-                    scope.addRuntime(component, runtime);
+                    Object runtime = component.start(aScope);
+                    aScope.addRuntime(component, runtime);
                     started.add(component);
                 }
 
@@ -272,11 +270,10 @@ public class Container extends AbstractComponent<Scope> {
             } catch (RuntimeException e) {
                 LOG.error(getQualifiedName() + ": could not start '"
                         + component.getQualifiedName() + "'", e);
-                stopAlreadyStartedComponents(started, scope);
+                stopAlreadyStartedComponents(started, aScope);
                 throw e;
             }
         }
-        return scope;
     }
 
     private void addProvidersOfRequiredInterfaces(