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.amber.field;
031:
032: import com.caucho.bytecode.JClass;
033: import com.caucho.bytecode.JMethod;
034: import com.caucho.config.ConfigException;
035: import com.caucho.java.JavaWriter;
036: import com.caucho.util.L10N;
037: import com.caucho.util.Log;
038:
039: import java.io.IOException;
040: import java.util.logging.Logger;
041:
042: /**
043: * The stub method is needed in particular to support EJB/CMP and ejbSelect
044: */
045: public class StubMethod {
046: private static final L10N L = new L10N(StubMethod.class);
047: protected static final Logger log = Log.open(StubMethod.class);
048:
049: private JMethod _method;
050:
051: public StubMethod(JMethod method) {
052: _method = method;
053: }
054:
055: /**
056: * Initializes the method.
057: */
058: public void init() throws ConfigException {
059: }
060:
061: /**
062: * Generates the stub
063: */
064: public void generate(JavaWriter out) throws IOException {
065: out.println();
066: out.print("public ");
067: out.print(_method.getReturnType().getPrintName());
068: out.print(" " + _method.getName() + "(");
069:
070: JClass[] paramTypes = _method.getParameterTypes();
071: for (int i = 0; i < paramTypes.length; i++) {
072: if (i != 0)
073: out.print(", ");
074:
075: out.print(paramTypes[i].getPrintName());
076: out.print(" a" + i);
077: }
078: out.println(")");
079:
080: JClass[] exnTypes = _method.getExceptionTypes();
081: for (int i = 0; i < exnTypes.length; i++) {
082: if (i == 0)
083: out.print(" throws ");
084: else
085: out.print(", ");
086:
087: out.print(exnTypes[i].getPrintName());
088: }
089: if (exnTypes.length > 0)
090: out.println();
091:
092: out.println("{");
093: JClass retType = _method.getReturnType();
094:
095: if ("void".equals(retType.getName())) {
096: } else if (retType.isPrimitive())
097: out.println(" return 0;");
098: else
099: out.println(" return null;");
100:
101: out.println("}");
102: }
103: }
|