Coverage Report - org.mule.impl.container.EjbContainerContext
 
Classes in this File Line Coverage Branch Coverage Complexity
EjbContainerContext
0%
0/21
0%
0/4
5.333
 
 1  
 /*
 2  
  * $Id: EjbContainerContext.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.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  0
         super("ejb");
 31  0
     }
 32  
 
 33  
     protected EjbContainerContext(String name)
 34  
     {
 35  0
         super(name);
 36  0
     }
 37  
 
 38  
     public Object getComponent(Object key) throws ObjectNotFoundException
 39  
     {
 40  0
         Object homeObject = null;
 41  0
         if (key == null)
 42  
         {
 43  0
             throw new ObjectNotFoundException("null");
 44  
         }
 45  
         try
 46  
         {
 47  0
             homeObject = context.lookup(key.toString());
 48  
         }
 49  0
         catch (NamingException e)
 50  
         {
 51  0
             throw new ObjectNotFoundException(key.toString(), e);
 52  0
         }
 53  
 
 54  0
         if (homeObject == null)
 55  
         {
 56  0
             throw new ObjectNotFoundException(key.toString());
 57  
         }
 58  0
         else if (homeObject instanceof EJBHome)
 59  
         {
 60  
 
 61  0
             Method method = ClassUtils.getMethod(homeObject.getClass(), "create", null);
 62  0
             if (method == null)
 63  
             {
 64  0
                 throw new ObjectNotFoundException(key.toString(), new IllegalArgumentException(
 65  
                     EjbMessages.ejbObjectMissingCreate(key).toString()));
 66  
             }
 67  
             try
 68  
             {
 69  0
                 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  0
             throw new ObjectNotFoundException(key.toString(), new IllegalArgumentException(
 79  
                 EjbMessages.ejbKeyRefNotValid(key).toString()));
 80  
         }
 81  
     }
 82  
 }