KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > ejb > gen > EntityFindMethod


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.ejb.gen;
31
32 import com.caucho.bytecode.JClass;
33 import com.caucho.bytecode.JMethod;
34 import com.caucho.java.JavaWriter;
35 import com.caucho.java.gen.BaseMethod;
36 import com.caucho.java.gen.MethodCallChain;
37 import com.caucho.util.L10N;
38
39 import java.io.IOException JavaDoc;
40
41 /**
42  * Generates the skeleton for the find method.
43  */

44 public class EntityFindMethod extends BaseMethod {
45   private static L10N L = new L10N(EntityFindMethod.class);
46
47   private JMethod _apiMethod;
48   private String JavaDoc _contextClassName;
49   private String JavaDoc _prefix;
50   
51   public EntityFindMethod(JMethod apiMethod,
52               JMethod implMethod,
53               String JavaDoc contextClassName,
54               String JavaDoc prefix)
55   {
56     super(apiMethod,
57       implMethod != null ? new MethodCallChain(implMethod) : null);
58
59     _apiMethod = apiMethod;
60     _contextClassName = contextClassName;
61     _prefix = prefix;
62   }
63
64   /**
65    * Gets the parameter types
66    */

67   public JClass []getParameterTypes()
68   {
69     return _apiMethod.getParameterTypes();
70   }
71
72   /**
73    * Gets the return type.
74    */

75   public JClass getReturnType()
76   {
77     return _apiMethod.getReturnType();
78   }
79
80   /**
81    * Prints the create method
82    *
83    * @param method the create method
84    */

85   public void generateCall(JavaWriter out, String JavaDoc []args)
86     throws IOException JavaDoc
87   {
88     JClass keyType;
89
90     if (getCall() != null) {
91       keyType = getCall().getReturnType();
92       out.print(keyType.getPrintName());
93       out.print(" key;");
94       getCall().generateCall(out, "key", "bean", args);
95     }
96     else {
97       keyType = getParameterTypes()[0];
98       out.print(keyType.getPrintName());
99       out.print(" key;");
100       out.println("key = " + args[0] + ";");
101     }
102     
103     out.println();
104
105     if ("long".equals(keyType.getName()))
106       out.println("Object okey = new Integer(key);");
107     else if ("int".equals(keyType.getName()))
108       out.println("Object okey = new Integer(key);");
109     else
110       out.println("Object okey = key;");
111
112     out.print("return (" + getReturnType().getName() + ") ");
113     out.print("_server.getContext(okey, false)");
114
115     if ("RemoteHome".equals(_prefix))
116       out.println(".getEJBObject();");
117     else if ("LocalHome".equals(_prefix))
118       out.println(".getEJBLocalObject();");
119     else
120       throw new IOException JavaDoc(L.l("trying to create unknown type {0}", _prefix));
121   }
122 }
123
Popular Tags