001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.ejb.cfg;
031:
032: import com.caucho.ejb.cfg21.EjbHomeView;
033: import com.caucho.bytecode.JClass;
034: import com.caucho.bytecode.JMethod;
035: import com.caucho.config.ConfigException;
036: import com.caucho.log.Log;
037: import com.caucho.util.L10N;
038:
039: import javax.ejb.CreateException;
040: import java.util.logging.Logger;
041:
042: /**
043: * Configuration for a particular view.
044: */
045: public class EjbSessionHomeView extends EjbHomeView {
046: private static final Logger log = Log
047: .open(EjbSessionHomeView.class);
048: private static final L10N L = new L10N(EjbSessionHomeView.class);
049:
050: /**
051: * Creates a new entity bean configuration.
052: */
053: public EjbSessionHomeView(EjbBean bean, ApiClass apiClass,
054: String prefix) throws ConfigException {
055: super (bean, apiClass, prefix);
056: }
057:
058: /**
059: * Introspects an ejb method.
060: */
061: protected EjbMethod introspectEJBMethod(ApiMethod method)
062: throws ConfigException {
063: ApiClass apiClass = getApiClass();
064: String methodName = method.getName();
065: Class[] paramTypes = method.getParameterTypes();
066:
067: if (methodName.startsWith("ejbCreate")) {
068: String createName = "c" + methodName.substring(4);
069:
070: ApiMethod apiMethod = EjbBean.getMethod(apiClass,
071: createName, paramTypes);
072:
073: /*
074: if (apiMethod == null)
075: throw errorMissingMethod(apiClass, createName, method);
076: */
077: if (apiMethod == null) {
078: log.config(errorMissingMethod(apiClass, createName,
079: method).getMessage());
080: return null;
081: }
082:
083: validateException(apiMethod, CreateException.class);
084:
085: return new EjbCreateMethod(this , apiMethod, method);
086: }
087:
088: if (!methodName.startsWith("ejb"))
089: return null;
090: else if (methodName.equals("ejbRemove"))
091: return null;
092: else if (methodName.startsWith("ejbCreate"))
093: return null;
094: else if (methodName.startsWith("ejbPostCreate"))
095: return null;
096: else if (methodName.startsWith("ejbActivate"))
097: return null;
098: else if (methodName.startsWith("ejbPassivate"))
099: return null;
100: // XXX: check
101: else if (methodName.startsWith("ejbDestroy"))
102: return null;
103: else
104: throw error(L
105: .l(
106: "{0}: '{1}' must not start with 'ejb'. The EJB spec reserves all methods starting with ejb.",
107: method.getDeclaringClass().getName(),
108: getFullMethodName(method)));
109: }
110:
111: /**
112: * Introspects a method in the view api which does not exist in
113: * implementation bean.
114: */
115: protected EjbMethod introspectApiMethod(ApiMethod apiMethod)
116: throws ConfigException {
117: String apiName = apiMethod.getName();
118:
119: if (apiName.equals("create"))
120: throw errorMissingMethod(getImplClass(), "ejbCreate",
121: apiMethod);
122: else
123: return super.introspectApiMethod(apiMethod);
124: }
125: }
|