1 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 ; 40 41 44 public class EntityFindMethod extends BaseMethod { 45 private static L10N L = new L10N(EntityFindMethod.class); 46 47 private JMethod _apiMethod; 48 private String _contextClassName; 49 private String _prefix; 50 51 public EntityFindMethod(JMethod apiMethod, 52 JMethod implMethod, 53 String contextClassName, 54 String 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 67 public JClass []getParameterTypes() 68 { 69 return _apiMethod.getParameterTypes(); 70 } 71 72 75 public JClass getReturnType() 76 { 77 return _apiMethod.getReturnType(); 78 } 79 80 85 public void generateCall(JavaWriter out, String []args) 86 throws IOException 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 (L.l("trying to create unknown type {0}", _prefix)); 121 } 122 } 123 | Popular Tags |