001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.proxy.ejb;
023:
024: import java.lang.reflect.Method;
025: import java.rmi.RemoteException;
026:
027: import org.jboss.invocation.Invocation;
028: import org.jboss.invocation.InvocationContext;
029: import org.jboss.invocation.InvocationKey;
030: import org.jboss.invocation.InvocationType;
031: import org.jboss.proxy.ejb.handle.StatelessHandleImpl;
032:
033: /**
034: * An EJB stateless session bean proxy class.
035: *
036: * @author <a href="mailto:marc.fleury@jboss.org">Marc Fleury</a>
037: * @version $Revision: 57209 $
038: */
039: public class StatelessSessionInterceptor extends GenericEJBInterceptor {
040: /** Serial Version Identifier. @since 1.4 */
041: private static final long serialVersionUID = -8807189798153718350L;
042:
043: /**
044: * No-argument constructor for externalization.
045: */
046: public StatelessSessionInterceptor() {
047: }
048:
049: // Public --------------------------------------------------------
050:
051: /**
052: * InvocationHandler implementation.
053: *
054: * @throws Throwable Any exception or error thrown while processing.
055: */
056: public Object invoke(Invocation invocation) throws Throwable {
057: InvocationContext ctx = invocation.getInvocationContext();
058: Method m = invocation.getMethod();
059:
060: // Implement local methods
061: if (m.equals(TO_STRING)) {
062: return toString(ctx);
063: } else if (m.equals(EQUALS)) {
064: Object[] args = invocation.getArguments();
065: String argsString = args[0] != null ? args[0].toString()
066: : "";
067: String this String = toString(ctx);
068: return new Boolean(this String.equals(argsString));
069: } else if (m.equals(HASH_CODE)) {
070: // We base the stateless hash on the hash of the proxy...
071: // MF XXX: it could be that we want to return the hash of the name?
072: return new Integer(this .hashCode());
073: }
074: // Implement local EJB calls
075: else if (m.equals(GET_HANDLE)) {
076: return new StatelessHandleImpl((String) ctx
077: .getValue(InvocationKey.JNDI_NAME));
078: } else if (m.equals(GET_PRIMARY_KEY)) {
079: throw new RemoteException(
080: "Call to getPrimaryKey not allowed on session bean");
081: } else if (m.equals(GET_EJB_HOME)) {
082: return getEJBHome(invocation);
083: } else if (m.equals(IS_IDENTICAL)) {
084: // All stateless beans are identical within a home,
085: // if the names are equal we are equal
086: Object[] args = invocation.getArguments();
087: String argsString = args[0].toString();
088: String this String = toString(ctx);
089: return new Boolean(this String.equals(argsString));
090: }
091: // If not taken care of, go on and call the container
092: else {
093: invocation.setType(InvocationType.REMOTE);
094:
095: return getNext().invoke(invocation);
096: }
097: }
098:
099: // Package protected ---------------------------------------------
100:
101: // Protected -----------------------------------------------------
102:
103: // Private -------------------------------------------------------
104: private String toString(InvocationContext ctx) {
105: return ctx.getValue(InvocationKey.JNDI_NAME) + ":Stateless";
106: }
107: }
|