Package org.jboss.proxy.ejb

Source Code of org.jboss.proxy.ejb.HomeInterceptor

/*     */ package org.jboss.proxy.ejb;
/*     */
/*     */ import java.lang.reflect.Method;
/*     */ import javax.ejb.EJBHome;
/*     */ import javax.ejb.EJBMetaData;
/*     */ import javax.ejb.EJBObject;
/*     */ import javax.ejb.Handle;
/*     */ import javax.ejb.RemoveException;
/*     */ import org.jboss.invocation.Invocation;
/*     */ import org.jboss.invocation.InvocationContext;
/*     */ import org.jboss.invocation.InvocationKey;
/*     */ import org.jboss.invocation.InvocationType;
/*     */ import org.jboss.proxy.Interceptor;
/*     */ import org.jboss.proxy.ejb.handle.HomeHandleImpl;
/*     */
/*     */ public class HomeInterceptor extends GenericEJBInterceptor
/*     */ {
/*     */   private static final long serialVersionUID = 1333656107035759718L;
/*  54 */   protected static final Object[] EMPTY_ARGS = new Object[0];
/*     */   protected static final Method GET_EJB_META_DATA;
/*     */   protected static final Method GET_HOME_HANDLE;
/*     */   protected static final Method REMOVE_BY_HANDLE;
/*     */   protected static final Method REMOVE_BY_PRIMARY_KEY;
/*     */   protected static final Method REMOVE_OBJECT;
/*     */
/*     */   public Object invoke(Invocation invocation)
/*     */     throws Throwable
/*     */   {
/* 115 */     InvocationContext ctx = invocation.getInvocationContext();
/*     */
/* 117 */     Method m = invocation.getMethod();
/*     */
/* 120 */     if (m.equals(TO_STRING))
/*     */     {
/* 122 */       return ctx.getValue(InvocationKey.JNDI_NAME).toString() + "Home";
/*     */     }
/* 124 */     if (m.equals(EQUALS))
/*     */     {
/* 127 */       Object[] args = invocation.getArguments();
/* 128 */       String argsString = args[0] != null ? args[0].toString() : "";
/* 129 */       String thisString = ctx.getValue(InvocationKey.JNDI_NAME).toString() + "Home";
/* 130 */       return new Boolean(thisString.equals(argsString));
/*     */     }
/* 132 */     if (m.equals(HASH_CODE))
/*     */     {
/* 134 */       return new Integer(hashCode());
/*     */     }
/*     */
/* 138 */     if (m.equals(GET_HOME_HANDLE))
/*     */     {
/* 140 */       return new HomeHandleImpl((String)ctx.getValue(InvocationKey.JNDI_NAME));
/*     */     }
/*     */
/* 143 */     if (m.equals(GET_EJB_META_DATA))
/*     */     {
/* 145 */       return ctx.getValue(InvocationKey.EJB_METADATA);
/*     */     }
/* 147 */     if (m.equals(REMOVE_BY_HANDLE))
/*     */     {
/* 150 */       EJBObject object = ((Handle)invocation.getArguments()[0]).getEJBObject();
/*     */
/* 154 */       object.remove();
/*     */
/* 157 */       return Void.TYPE;
/*     */     }
/* 159 */     if (m.equals(REMOVE_BY_PRIMARY_KEY))
/*     */     {
/* 162 */       if (((EJBMetaData)ctx.getValue(InvocationKey.EJB_METADATA)).isSession()) {
/* 163 */         throw new RemoveException("Session beans cannot be removed by primary key.");
/*     */       }
/*     */
/* 168 */       Object id = invocation.getArguments()[0];
/*     */
/* 171 */       invocation.setId(id);
/* 172 */       invocation.setType(InvocationType.REMOTE);
/* 173 */       invocation.setMethod(REMOVE_OBJECT);
/* 174 */       invocation.setArguments(EMPTY_ARGS);
/* 175 */       return getNext().invoke(invocation);
/*     */     }
/*     */
/* 182 */     invocation.setType(InvocationType.HOME);
/*     */
/* 184 */     return getNext().invoke(invocation);
/*     */   }
/*     */
/*     */   static
/*     */   {
/*     */     try
/*     */     {
/*  75 */       Class[] empty = new Class[0];
/*  76 */       Class type = EJBHome.class;
/*     */
/*  78 */       GET_EJB_META_DATA = type.getMethod("getEJBMetaData", empty);
/*  79 */       GET_HOME_HANDLE = type.getMethod("getHomeHandle", empty);
/*  80 */       REMOVE_BY_HANDLE = type.getMethod("remove", new Class[] { Handle.class });
/*     */
/*  83 */       REMOVE_BY_PRIMARY_KEY = type.getMethod("remove", new Class[] { Object.class });
/*     */
/*  88 */       REMOVE_OBJECT = EJBObject.class.getMethod("remove", empty);
/*     */     }
/*     */     catch (Exception e) {
/*  91 */       e.printStackTrace();
/*  92 */       throw new ExceptionInInitializerError(e);
/*     */     }
/*     */   }
/*     */ }

/* Location:           /home/mnovotny/projects/EMBEDDED_JBOSS_BETA3_COMMUNITY/embedded/output/lib/embedded-jboss/lib/jboss-embedded-all.jar
* Qualified Name:     org.jboss.proxy.ejb.HomeInterceptor
* JD-Core Version:    0.6.0
*/
TOP

Related Classes of org.jboss.proxy.ejb.HomeInterceptor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.