1 22 package org.jboss.ejb.plugins.local; 23 24 import javax.ejb.EJBLocalHome ; 25 import javax.ejb.EJBLocalObject ; 26 import javax.ejb.RemoveException ; 27 import java.lang.reflect.InvocationHandler ; 28 import java.lang.reflect.Method ; 29 30 37 public class LocalHomeProxy 38 extends LocalProxy 39 implements InvocationHandler 40 { 41 static final long serialVersionUID = 1762319499924478521L; 42 43 44 protected static final Method REMOVE_BY_PRIMARY_KEY; 45 46 47 protected static final Method REMOVE_OBJECT; 48 49 52 static 53 { 54 try 55 { 56 final Class empty[] = {}; 57 final Class type = EJBLocalHome .class; 58 59 REMOVE_BY_PRIMARY_KEY = type.getMethod("remove", new Class [] {Object .class}); 60 61 REMOVE_OBJECT = EJBLocalObject .class.getMethod("remove", empty); 63 } 64 catch (Exception e) 65 { 66 e.printStackTrace(); 67 throw new ExceptionInInitializerError (e); 68 } 69 } 70 71 public LocalHomeProxy(String jndiName, BaseLocalProxyFactory factory) 72 { 73 super(jndiName, factory); 74 } 75 76 protected Object getId() 77 { 78 return jndiName; 79 } 80 81 90 public Object invoke(final Object proxy, final Method m, 91 Object [] args) 92 throws Throwable 93 { 94 Object retValue = null; 95 96 if (args == null) 97 args = EMPTY_ARGS; 98 99 if (m.equals(TO_STRING)) 101 { 102 retValue = jndiName + "Home"; 103 } 104 else if (m.equals(EQUALS)) 105 { 106 Object temp = invoke(proxy, TO_STRING, args); 108 retValue = new Boolean (temp.equals(jndiName + "Home")); 109 } 110 else if (m.equals(HASH_CODE)) 111 { 112 retValue = new Integer (this.hashCode()); 113 } 114 else if (m.equals(REMOVE_BY_PRIMARY_KEY)) 115 { 116 try 117 { 118 Object id = args[0]; 121 retValue = factory.invoke(id, REMOVE_OBJECT, EMPTY_ARGS); 122 } 123 catch (Exception e) 124 { 125 RemoveException re = new RemoveException (e.getMessage()); 126 re.initCause(e); 127 throw re; 128 } 129 } 130 else 132 { 133 retValue = factory.invokeHome(m, args); 134 } 135 136 return retValue; 137 } 138 } 139 | Popular Tags |