01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * published by the Free Software Foundation; either version 2.1 of
10: * the License, or (at your option) any later version.
11: *
12: * This software is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this software; if not, write to the Free
19: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21: */
22: package org.jboss.ejb.plugins;
23:
24: import org.jboss.invocation.Invocation;
25: import org.jboss.invocation.InvocationType;
26:
27: import javax.ejb.TimerHandle;
28:
29: /**
30: * This Interceptor validates the incomming arguments and the return value of the call.
31: *
32: * Here is the place where you want to make sure that local object don't pass through
33: * the remote interface.
34: *
35: * @author Thomas.Diesler@jboss.org
36: * @version $Revision: 57209 $
37: */
38: public class CallValidationInterceptor extends AbstractInterceptor {
39: // Constants -----------------------------------------------------
40:
41: // Attributes ----------------------------------------------------
42:
43: // Static --------------------------------------------------------
44:
45: // Constructors --------------------------------------------------
46:
47: // Public --------------------------------------------------------
48:
49: // Interceptor implementation --------------------------------------
50:
51: public Object invokeHome(final Invocation mi) throws Exception {
52: validateArguments(mi);
53: Object obj = getNext().invokeHome(mi);
54: return validateReturnValue(mi, obj);
55: }
56:
57: public Object invoke(final Invocation mi) throws Exception {
58: validateArguments(mi);
59: Object obj = getNext().invoke(mi);
60: return validateReturnValue(mi, obj);
61: }
62:
63: /** Do some validation of the incoming parameters */
64: protected void validateArguments(Invocation mi) {
65: if (mi.getType() == InvocationType.REMOTE) {
66: Object[] params = mi.getArguments();
67: for (int i = 0; i < params.length; i++) {
68: Object obj = params[i];
69: if (obj instanceof TimerHandle)
70: throw new IllegalArgumentException(
71: "Cannot pass TimerHandle through remote interface");
72: }
73: }
74: }
75:
76: /** Do some validation of the return value */
77: protected Object validateReturnValue(Invocation mi, Object retValue) {
78: if (mi.getType() == InvocationType.REMOTE) {
79: if (retValue instanceof TimerHandle)
80: throw new IllegalArgumentException(
81: "Cannot return TimerHandle from remote interface");
82: }
83: return retValue;
84: }
85:
86: }
|