Clover coverage report - Services for Dentaku - 0.6
Coverage timestamp: Wed Jun 30 2004 19:54:58 EDT
file stats: LOC: 114   Methods: 10
NCLOC: 58   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ContainerManager.java 50% 50% 40% 47.2%
coverage coverage
 1   
 /*
 2   
  * ContainerManager.java
 3   
  * Copyright 2002-2004 Bill2, Inc.
 4   
  *
 5   
  * Licensed under the Apache License, Version 2.0 (the "License");
 6   
  * you may not use this file except in compliance with the License.
 7   
  * You may obtain a copy of the License at
 8   
  *
 9   
  *     http://www.apache.org/licenses/LICENSE-2.0
 10   
  *
 11   
  * Unless required by applicable law or agreed to in writing, software
 12   
  * distributed under the License is distributed on an "AS IS" BASIS,
 13   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14   
  * See the License for the specific language governing permissions and
 15   
  * limitations under the License.
 16   
  */
 17   
 package org.dentaku.services.container;
 18   
 
 19   
 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 20   
 import org.dentaku.services.exception.DentakuException;
 21   
 
 22   
 import java.io.InputStreamReader;
 23   
 import java.io.InputStream;
 24   
 import java.util.ArrayList;
 25   
 import java.util.List;
 26   
 
 27   
 /**
 28   
  * This is all kind of wacked out, but basically it's that way to make it testable with external container insertion
 29   
  */
 30   
 public class ContainerManager {
 31   
     protected DentakuPlexusContainer container;
 32   
     private static ContainerManager instance;
 33   
     protected List configurationResources = new ArrayList();
 34   
 
 35   
     /**
 36   
      * Return a reference to the enclosing plexus container.  If this is not possible, throw a
 37   
      * <code>ContainerException</code>.
 38   
      *
 39   
      * @return PlexusContainer -- the container that Dentaku is running from.
 40   
      * @throws ContainerException if we cannot find a reference to the container.
 41   
      */
 42  9
     public static ContainerManager getInstance() throws ContainerException {
 43  9
         if (instance == null) {
 44  9
             instance = new ContainerManager();
 45   
         }
 46  9
         return instance;
 47   
     }
 48   
 
 49  0
     public static void setInstance(ContainerManager instance) {
 50  0
         ContainerManager.instance = instance;
 51   
     }
 52   
 
 53  9
     public DentakuPlexusContainer getContainer() {
 54  9
         return container;
 55   
     }
 56   
 
 57   
 //    public static void setup(InputStream configurationResource) throws ContainerException {
 58   
 //        InputStreamReader reader = new InputStreamReader(configurationResource);
 59   
 //        XStream xs = new XStream();
 60   
 //        List l = (List)xs.fromXML(reader);
 61   
 //        ArrayList result = new ArrayList();
 62   
 //        for (Iterator it = l.iterator(); it.hasNext();) {
 63   
 //            result.add((InputStreamReader) it.next());
 64   
 //        }
 65   
 //        setup();
 66   
 //    }
 67   
 
 68   
     /**
 69   
      * Build a new plexus container and put it into JNDI
 70   
      *
 71   
      * @throws ContainerException
 72   
      */
 73  9
     public void setup() throws ContainerException {
 74  9
         if (container == null) {
 75  9
             container = new DentakuPlexusContainer();
 76   
         }
 77  9
         try {
 78  9
             container.setConfigurationResources(configurationResources);
 79  9
             container.initialize();
 80  9
             container.start();
 81   
         } catch (Exception e) {
 82  0
             throw new ContainerException(e);
 83   
         }
 84   
     }
 85   
 
 86  0
     public void setup(DentakuPlexusContainer c) {
 87  0
         container = c;
 88   
     }
 89   
 
 90  9
     public void add(InputStreamReader configurationResource) {
 91  9
         configurationResources.add(configurationResource);
 92   
     }
 93   
 
 94  0
     public Object lookup(String key) throws ComponentLookupException {
 95  0
         return container.lookup(key);
 96   
     }
 97   
 
 98  0
     public void dispose() {
 99  0
         container.dispose();
 100  0
         instance = null;
 101   
     }
 102   
 
 103  0
     public static ContainerManager getContainerManager(InputStream configurationStream) throws DentakuException {
 104  0
         ContainerManager containerManager = new ContainerManager();
 105  0
         containerManager.add(new InputStreamReader(configurationStream));
 106  0
         containerManager.setup();
 107  0
         return containerManager;
 108   
     }
 109   
 
 110  0
     public void disposeContainerManager() {
 111  0
         dispose();
 112   
     }
 113   
 }
 114