001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: BaseInvocationParameter01.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.tests.common.ejbs.base.invocationcontext;
025:
026: import java.lang.reflect.Method;
027:
028: import javax.interceptor.AroundInvoke;
029: import javax.interceptor.InvocationContext;
030:
031: import org.ow2.easybeans.tests.common.helper.InvocationContextHelper;
032: import org.ow2.easybeans.tests.common.interceptors.invocationcontext.ComplexObject00;
033: import org.ow2.util.log.Log;
034: import org.ow2.util.log.LogFactory;
035:
036: /**
037: * Used to manipulate the invocation context object.
038: * @author Eduardo Studzinski Estima de Castro
039: * @author Gisele Pinheiro Souza
040: */
041: public class BaseInvocationParameter01 implements
042: ItfInvocationParameter00 {
043:
044: /**
045: * Logger.
046: */
047: private Log logger = LogFactory
048: .getLog(BaseInvocationParameter01.class);
049:
050: /**
051: * Intercepts the method and modifies the method parameters.
052: * @param ic contains attributes of invocation, the first
053: * parameter of the intercepted method must be a list.
054: * @return method's invocation result
055: * @throws Exception if invocation fails
056: */
057: @SuppressWarnings("unused")
058: @AroundInvoke
059: private Object intercept(final InvocationContext ic)
060: throws Exception {
061: Method mIC = ic.getMethod();
062:
063: if (mIC.toString().contains("getObjects00")) {
064: //Sets all parameters to null.
065: return InvocationContextHelper.setParametersNull(ic);
066: } else if (mIC.toString().contains("getObjects01")) {
067: //Do not modify the parameters.
068: return InvocationContextHelper.getParametersArray(ic);
069: } else if (mIC.toString().contains("getObjects02")) {
070: //Modify the parameters.
071: return InvocationContextHelper.modifyParameters(ic);
072: } else {
073: throw new Exception("Invalid method to intercept.");
074: }
075: }
076:
077: /**
078: * Returns objects passed as parameters with null references. There is an interceptor
079: * that sets to null the parameters reference.
080: * @param objCP complex object
081: * @return array with the objects passed as parameters.
082: * @throws Exception if a problem occurs.
083: */
084: public Object[] getObjects00(ComplexObject00 objCP)
085: throws Exception {
086: Object[] arObjs = { objCP };
087: logger.debug("after interceptors, parameters: {0}", objCP);
088: return arObjs;
089: }
090:
091: /**
092: * Returns objects passed as parameters without modification. There is an interceptor
093: * that creates a new array to return, but it doesn't modify the objects passed as parameters.
094: * @param objCP complex object
095: * @return array with the objects passed as parameters.
096: * @throws Exception if a problem occurs.
097: */
098: public Object[] getObjects01(ComplexObject00 objCP)
099: throws Exception {
100: Object[] arObjs = { objCP };
101: logger.debug("after interceptors, parameters: {0}, {1}", objCP);
102: return arObjs;
103: }
104:
105: /**
106: * Returns objects passed as parameters with modifications.
107: * There is an interceptor that modifies the parameters.
108: * @param objCP complex object
109: * @return array with the objects passed as parameters.
110: * @throws Exception if a problem occurs.
111: */
112: public Object[] getObjects02(ComplexObject00 objCP)
113: throws Exception {
114: Object[] arObjs = { objCP };
115: logger.debug("after interceptors, parameters: {0}", objCP);
116: return arObjs;
117: }
118:
119: }
|