Coverage Report - org.mule.impl.container.EjbContainerContext
 
Classes in this File Line Coverage Branch Coverage Complexity
EjbContainerContext
71%
15/21
75%
6/8
5.333
 
 1  
 /*
 2  
  * $Id: EjbContainerContext.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.providers.ejb.i18n.EjbMessages;
 14  
 import org.mule.umo.manager.ObjectNotFoundException;
 15  
 import org.mule.util.ClassUtils;
 16  
 
 17  
 import java.lang.reflect.Method;
 18  
 
 19  
 import javax.ejb.EJBHome;
 20  
 import javax.naming.NamingException;
 21  
 
 22  
 /**
 23  
  * <code>EjbContainerContext</code> is a container implementaiton that allows EJB
 24  
  * Session beans to be referenced as Mule managed UMOs
 25  
  */
 26  
 public class EjbContainerContext extends RmiContainerContext
 27  
 {
 28  
     public EjbContainerContext()
 29  
     {
 30  6
         super("ejb");
 31  6
     }
 32  
 
 33  
     protected EjbContainerContext(String name)
 34  
     {
 35  0
         super(name);
 36  0
     }
 37  
 
 38  
     public Object getComponent(Object key) throws ObjectNotFoundException
 39  
     {
 40  10
         Object homeObject = null;
 41  10
         if (key == null)
 42  
         {
 43  2
             throw new ObjectNotFoundException("null");
 44  
         }
 45  
         try
 46  
         {
 47  8
             homeObject = context.lookup(key.toString());
 48  
         }
 49  2
         catch (NamingException e)
 50  
         {
 51  2
             throw new ObjectNotFoundException(key.toString(), e);
 52  6
         }
 53  
 
 54  6
         if (homeObject == null)
 55  
         {
 56  0
             throw new ObjectNotFoundException(key.toString());
 57  
         }
 58  6
         else if (homeObject instanceof EJBHome)
 59  
         {
 60  
 
 61  4
             Method method = ClassUtils.getMethod(homeObject.getClass(), "create", null);
 62  4
             if (method == null)
 63  
             {
 64  0
                 throw new ObjectNotFoundException(key.toString(), new IllegalArgumentException(
 65  
                     EjbMessages.ejbObjectMissingCreate(key).toString()));
 66  
             }
 67  
             try
 68  
             {
 69  4
                 return method.invoke(homeObject, ClassUtils.NO_ARGS);
 70  
             }
 71  0
             catch (Exception e)
 72  
             {
 73  0
                 throw new ObjectNotFoundException(key.toString(), e);
 74  
             }
 75  
         }
 76  
         else
 77  
         {
 78  2
             throw new ObjectNotFoundException(key.toString(), new IllegalArgumentException(
 79  
                 EjbMessages.ejbKeyRefNotValid(key).toString()));
 80  
         }
 81  
     }
 82  
 }