Coverage Report - org.mule.registry.impl.AbstractLibrary
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractLibrary
0%
0/39
0%
0/4
1.917
 
 1  
 /*
 2  
  * $Id: AbstractLibrary.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.registry.impl;
 12  
 
 13  
 import org.mule.registry.Library;
 14  
 import org.mule.registry.Registry;
 15  
 import org.mule.registry.RegistryComponent;
 16  
 import org.mule.registry.RegistryDescriptor;
 17  
 import org.mule.registry.RegistryException;
 18  
 import org.mule.util.FileUtils;
 19  
 
 20  
 import java.util.ArrayList;
 21  
 import java.util.Collection;
 22  
 import java.util.Iterator;
 23  
 import java.util.List;
 24  
 
 25  
 public abstract class AbstractLibrary extends AbstractEntry implements Library
 26  
 {
 27  
 
 28  
     protected List components;
 29  
     protected List classPathElements;
 30  
     protected boolean isClassLoaderParentFirst;
 31  
     protected RegistryDescriptor descriptor;
 32  
 
 33  
     protected AbstractLibrary(Registry registry)
 34  
     {
 35  0
         super(registry);
 36  0
         this.components = new ArrayList();
 37  0
     }
 38  
 
 39  
     /*
 40  
      * (non-Javadoc)
 41  
      * 
 42  
      * @see org.mule.jbi.registry.Library#getReferringComponents()
 43  
      */
 44  
     public RegistryComponent[] getComponents()
 45  
     {
 46  0
         Collection c = new ArrayList();
 47  0
         for (Iterator it = this.components.iterator(); it.hasNext();)
 48  
         {
 49  0
             String ref = (String)it.next();
 50  0
             RegistryComponent comp = getRegistry().getComponent(ref);
 51  0
             c.add(comp);
 52  
         }
 53  0
         return (RegistryComponent[])c.toArray(new RegistryComponent[c.size()]);
 54  
     }
 55  
 
 56  
     public void addComponent(RegistryComponent component)
 57  
     {
 58  0
         this.components.add(component.getName());
 59  0
     }
 60  
 
 61  
     public void removeComponent(RegistryComponent component)
 62  
     {
 63  0
         this.components.remove(component.getName());
 64  0
     }
 65  
 
 66  
     /*
 67  
      * (non-Javadoc)
 68  
      * 
 69  
      * @see org.mule.jbi.registry.mule.AbstractEntry#checkDescriptor()
 70  
      */
 71  
     protected void checkDescriptor() throws RegistryException
 72  
     {
 73  0
         super.checkDescriptor();
 74  
         // Check that it is a service assembly
 75  0
         if (!getDescriptor().isSharedLibrary())
 76  
         {
 77  0
             throw new RegistryException("shared library should be set");
 78  
         }
 79  0
     }
 80  
 
 81  
     /*
 82  
      * (non-Javadoc)
 83  
      * 
 84  
      * @see javax.jbi.management.LifeCycleMBean#start()
 85  
      */
 86  
     public synchronized void install() throws RegistryException
 87  
     {
 88  0
         if (!getCurrentState().equals(UNKNOWN))
 89  
         {
 90  0
             throw new RegistryException("Illegal status: " + getCurrentState());
 91  
         }
 92  
         try
 93  
         {
 94  0
             doInstall();
 95  
         }
 96  0
         catch (Exception e)
 97  
         {
 98  0
             throw new RegistryException(e);
 99  0
         }
 100  
         // Set current state
 101  0
         setCurrentState(SHUTDOWN);
 102  0
     }
 103  
 
 104  
     /*
 105  
      * (non-Javadoc)
 106  
      * 
 107  
      * @see javax.jbi.management.LifeCycleMBean#start()
 108  
      */
 109  
     public synchronized void uninstall() throws RegistryException
 110  
     {
 111  0
         if (!getCurrentState().equals(SHUTDOWN))
 112  
         {
 113  0
             throw new RegistryException("Illegal status: " + getCurrentState());
 114  
         }
 115  
         try
 116  
         {
 117  0
             doUninstall();
 118  
         }
 119  0
         catch (Exception e)
 120  
         {
 121  0
             throw new RegistryException(e);
 122  0
         }
 123  0
         FileUtils.deleteTree(FileUtils.newFile(getInstallRoot()));
 124  0
         getRegistry().removeLibrary(this);
 125  0
         setCurrentState(UNKNOWN);
 126  0
     }
 127  
 
 128  
     /*
 129  
      * (non-Javadoc)
 130  
      * 
 131  
      * @see org.mule.jbi.registry.Library#getClassPathElements()
 132  
      */
 133  
     public List getClassPathElements()
 134  
     {
 135  0
         return this.classPathElements;
 136  
     }
 137  
 
 138  
     /*
 139  
      * (non-Javadoc)
 140  
      * 
 141  
      * @see org.mule.jbi.registry.Library#isClassLoaderParentFirst()
 142  
      */
 143  
     public boolean isClassLoaderParentFirst()
 144  
     {
 145  0
         return this.isClassLoaderParentFirst;
 146  
     }
 147  
 
 148  
     public void setDescriptor(RegistryDescriptor descriptor)
 149  
     {
 150  0
         this.descriptor = descriptor;
 151  0
     }
 152  
 
 153  
     protected abstract void doInstall() throws Exception;
 154  
 
 155  
     protected abstract void doUninstall() throws Exception;
 156  
 }