Coverage Report - org.mule.impl.container.DescriptorContainerContext
 
Classes in this File Line Coverage Branch Coverage Complexity
DescriptorContainerContext
29%
4/14
17%
1/6
3
 
 1  
 /*
 2  
  * $Id: DescriptorContainerContext.java 7963 2007-08-21 08:53:15Z 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.impl.container;
 12  
 
 13  
 import org.mule.config.i18n.CoreMessages;
 14  
 import org.mule.impl.model.ModelHelper;
 15  
 import org.mule.umo.UMODescriptor;
 16  
 import org.mule.umo.manager.ContainerException;
 17  
 import org.mule.umo.manager.ObjectNotFoundException;
 18  
 
 19  
 import java.io.Reader;
 20  
 
 21  
 /**
 22  
  * Will load the component from the descriptors' own properties.
 23  
  */
 24  
 public class DescriptorContainerContext extends AbstractContainerContext
 25  
 {
 26  
     public static final String DESCRIPTOR_CONTAINER_NAME = "descriptor";
 27  
 
 28  
     public DescriptorContainerContext()
 29  
     {
 30  392
         super(DESCRIPTOR_CONTAINER_NAME);
 31  392
     }
 32  
 
 33  
     public void configure(Reader configuration) throws ContainerException
 34  
     {
 35  0
         throw new UnsupportedOperationException("configure");
 36  
     }
 37  
 
 38  
     public void setName(String name)
 39  
     {
 40  
         // no op
 41  0
     }
 42  
 
 43  
     /**
 44  
      * Queries a component from the underlying container
 45  
      * 
 46  
      * @param key the key fo find the component with. Its up to the individual
 47  
      *            implementation to check the type of this key and look up objects
 48  
      *            accordingly
 49  
      * @return The component found in the container
 50  
      * @throws org.mule.umo.manager.ObjectNotFoundException if the component is not
 51  
      *             found
 52  
      */
 53  
     public Object getComponent(Object key) throws ObjectNotFoundException
 54  
     {
 55  
 
 56  70
         if (key instanceof DescriptorContainerKeyPair)
 57  
         {
 58  0
             DescriptorContainerKeyPair dckp = (DescriptorContainerKeyPair) key;
 59  
 
 60  0
             UMODescriptor d = ModelHelper.getDescriptor(dckp.getDescriptorName());
 61  0
             if (d == null)
 62  
             {
 63  0
                 throw new ObjectNotFoundException(
 64  
                     key.toString(), 
 65  
                     new ContainerException(
 66  
                         CoreMessages.failedToLoad("descriptor: " + dckp.getDescriptorName())));
 67  
             }
 68  0
             Object component = d.getProperties().get(dckp.getKey());
 69  0
             if (component == null)
 70  
             {
 71  0
                 throw new ObjectNotFoundException(dckp.getKey().toString());
 72  
             }
 73  0
             return component;
 74  
         }
 75  
         else
 76  
         {
 77  70
             throw new ObjectNotFoundException(key.toString());
 78  
         }
 79  
     }
 80  
 
 81  
 }