KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > amber > field > StubMethod


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.amber.field;
31
32 import com.caucho.bytecode.JClass;
33 import com.caucho.bytecode.JMethod;
34 import com.caucho.config.ConfigException;
35 import com.caucho.java.JavaWriter;
36 import com.caucho.util.L10N;
37 import com.caucho.util.Log;
38
39 import java.io.IOException JavaDoc;
40 import java.util.logging.Logger JavaDoc;
41
42 /**
43  * The stub method is needed in particular to support EJB/CMP and ejbSelect
44  */

45 public class StubMethod {
46   private static final L10N L = new L10N(StubMethod.class);
47   protected static final Logger JavaDoc log = Log.open(StubMethod.class);
48
49   private JMethod _method;
50
51   public StubMethod(JMethod method)
52   {
53     _method = method;
54   }
55
56   /**
57    * Initializes the method.
58    */

59   public void init()
60     throws ConfigException
61   {
62   }
63
64   /**
65    * Generates the stub
66    */

67   public void generate(JavaWriter out)
68     throws IOException JavaDoc
69   {
70     out.println();
71     out.print("public ");
72     out.print(_method.getReturnType().getPrintName());
73     out.print(" " + _method.getName() + "(");
74
75     JClass []paramTypes = _method.getParameterTypes();
76     for (int i = 0; i < paramTypes.length; i++) {
77       if (i != 0)
78     out.print(", ");
79
80       out.print(paramTypes[i].getPrintName());
81       out.print(" a" + i);
82     }
83     out.println(")");
84
85     JClass []exnTypes = _method.getExceptionTypes();
86     for (int i = 0; i < exnTypes.length; i++) {
87       if (i == 0)
88     out.print(" throws ");
89       else
90     out.print(", ");
91
92       out.print(exnTypes[i].getPrintName());
93     }
94     if (exnTypes.length > 0)
95       out.println();
96     
97     out.println("{");
98     JClass retType = _method.getReturnType();
99
100     if ("void".equals(retType.getName())) {
101     }
102     else if (retType.isPrimitive())
103       out.println(" return 0;");
104     else
105       out.println(" return null;");
106     
107     out.println("}");
108   }
109 }
110
Popular Tags