Clover coverage report - CRISPY - 1.1.1
Coverage timestamp: Mi Nov 15 2006 13:09:46 CET
file stats: LOC: 103   Methods: 4
NCLOC: 70   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
StaticEjbProxy.java 70% 84,4% 100% 82,6%
coverage coverage
 1    /*
 2    * Created on 29.04.2005 from Linke
 3    *
 4    */
 5    package net.sf.crispy.impl;
 6   
 7    import java.beans.BeanInfo;
 8    import java.beans.Introspector;
 9    import java.beans.MethodDescriptor;
 10    import java.lang.reflect.Method;
 11   
 12    import javax.naming.InitialContext;
 13    import javax.naming.NamingException;
 14    import javax.rmi.PortableRemoteObject;
 15   
 16    import net.sf.crispy.InvocationException;
 17    import net.sf.crispy.Property;
 18    import net.sf.crispy.proxy.StaticProxy;
 19   
 20    /**
 21    * Remote call with EJB's (JNDI lookup).
 22    *
 23    * @author Linke
 24    *
 25    */
 26    public class StaticEjbProxy extends StaticProxy {
 27   
 28    private InitialContext initialContext = null;
 29   
 30  18 public StaticEjbProxy () {}
 31   
 32    /**
 33    * Get default url and port. If no url and port is in properties.
 34    *
 35    * @return Default url and port.
 36    */
 37  19 public String getDefaultUrlAndPort() {
 38  19 return null;
 39    }
 40   
 41  19 public Object newInstance (Class pvClass) {
 42  19 return createProxy(pvClass);
 43    }
 44   
 45  19 private Object createProxy (Class pvProxyClass) {
 46    // initialContext einrichten
 47  19 try {
 48  19 initialContext = new InitialContext(getProperties());
 49    } catch (NamingException e) {
 50  0 throw new InvocationException("Exception by the InitialContext", e);
 51    }
 52    // JNDI-Namen fuer lookup
 53  19 String lvJndi = getProperties().getProperty(pvProxyClass.getName());
 54  19 if (lvJndi == null) {
 55  1 throw new InvocationException("For the Class: " + pvProxyClass.getName() + " is no JNDI-Entry.");
 56    }
 57  18 Object lvHome = null;
 58    // JNDI-lookup
 59  18 try {
 60  18 lvHome = initialContext.lookup(lvJndi);
 61    } catch (NamingException e) {
 62  1 throw new InvocationException("Exception by JNDI-lookup: " + lvJndi, e);
 63    }
 64    // HomeInterface bestimmen
 65  17 if (lvHome == null) {
 66  0 throw new InvocationException("For the JNDI-Entry " + lvJndi + " exist no HomeInterface.");
 67    }
 68  17 String lvEjbHomeStr = getProperties().getProperty(pvProxyClass.getName() + Property.EJB_HOME_INTERFACE);
 69  17 try {
 70  17 Class lvEjbHomeClass = Class.forName(lvEjbHomeStr);
 71  15 lvHome = PortableRemoteObject.narrow(lvHome, lvEjbHomeClass);
 72    } catch (Exception e) {
 73  2 throw new InvocationException("Exception by loading HomeInterface: " + lvEjbHomeStr
 74    + " (please check your properties and set the Home-Interface:" +
 75    "ServiceName + Property.EJB_HOME_INTERFACE - Home-Interface)", e);
 76    }
 77  15 if (lvHome == null) {
 78  0 throw new InvocationException("With PortableRemoteObject.narrow can not create the HomeInterface: "
 79    + lvJndi + " " + pvProxyClass.getName());
 80    }
 81    // Bean mit der Methode create() finden und aufrufen
 82  15 try {
 83  15 BeanInfo beanInfo = Introspector.getBeanInfo(lvHome.getClass());
 84  15 MethodDescriptor lvMethodDescriptor[] = beanInfo.getMethodDescriptors();
 85  180 for (int i = 0; i < lvMethodDescriptor.length; i++) {
 86  180 Method lvMethod = lvMethodDescriptor[i].getMethod();
 87  180 if (lvMethod.getName().equals("create")) {
 88  15 setProxyObject(lvMethod.invoke(lvHome, null));
 89  15 setProxyClass(getProxyObject().getClass());
 90  15 return getProxyObject();
 91    }
 92    }
 93    } catch (Exception e) {
 94  0 throw new InvocationException("Exception by Introspector, by search of create()-Method from: "
 95    + lvHome.getClass().getName(), e);
 96    }
 97   
 98  0 return getProxyObject();
 99   
 100    }
 101   
 102   
 103    }