KickJava   Java API By Example, From Geeks To Geeks.

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


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.ejb.cfg.EjbEntityBean;
35 import com.caucho.java.JavaWriter;
36 import com.caucho.java.gen.BaseMethod;
37 import com.caucho.java.gen.CallChain;
38 import com.caucho.util.L10N;
39
40 import java.io.IOException JavaDoc;
41
42 /**
43  * Generates the skeleton for a session view.
44  */

45 public class EntityHomeView extends ViewClass {
46   private static L10N L = new L10N(EntityHomeView.class);
47
48   private EjbEntityBean _bean;
49   
50   private JClass _remoteClass;
51   private String JavaDoc _prefix;
52   private String JavaDoc _contextClassName;
53   private boolean _isCMP;
54
55   public EntityHomeView(JClass remoteClass,
56             String JavaDoc contextClassName,
57             String JavaDoc prefix,
58             boolean isCMP)
59   {
60     super(prefix, "Entity" + prefix);
61
62     addInterfaceName(remoteClass.getName());
63
64     _contextClassName = contextClassName;
65     _prefix = prefix;
66
67     setStatic(true);
68     _isCMP = isCMP;
69   }
70
71   /**
72    * Adds a business method.
73    */

74   public void addMethod(BaseMethod method)
75   {
76     addComponent(method);
77   }
78
79   public BaseMethod createCreateMethod(EjbEntityBean bean,
80                        JMethod api,
81                        JMethod create,
82                        JMethod postCreate,
83                        String JavaDoc fullClassName)
84   {
85     EntityCreateMethod method;
86     method = new EntityCreateMethod(bean, api, create,
87                     postCreate, fullClassName);
88
89     EntityCreateCall call = (EntityCreateCall) method.getCall();
90
91     call.setCMP(_isCMP);
92
93     return method;
94   }
95
96   /**
97    * Adds the pool chaining.
98    */

99   public CallChain createPoolChain(CallChain call)
100   {
101     return new EntityPoolChain(call, true);
102   }
103
104   public void generate(JavaWriter out)
105     throws IOException JavaDoc
106   {
107     generateGetter(out);
108
109     out.println();
110     super.generate(out);
111   }
112
113   private void generateGetter(JavaWriter out)
114     throws IOException JavaDoc
115   {
116     if (_prefix.equals("RemoteHome")) {
117       out.println();
118       out.println("public EJBHome createRemoteHomeView()");
119       out.println("{");
120       out.println(" return new RemoteHome(this);");
121       out.println("}");
122       out.println();
123     }
124     else {
125       out.println();
126       out.println("public EJBLocalHome createLocalHome()");
127       out.println("{");
128       out.println(" return new LocalHome(this);");
129       out.println("}");
130       out.println();
131     }
132   }
133        
134   protected void generateClassContent(JavaWriter out)
135     throws IOException JavaDoc
136   {
137     out.println("private " + _contextClassName + " _context;");
138     out.println("private EjbTransactionManager _xaManager;");
139     out.println();
140     out.println(_prefix + "(" + _contextClassName + " context)");
141     out.println("{");
142     out.println(" super(context.getEntityServer());");
143     out.println(" _context = context;");
144     out.println(" _xaManager = _server.getTransactionManager();");
145     out.println("}");
146     out.println();
147     out.println("private " + _contextClassName + " getContext()");
148     out.println("{");
149     out.println(" return _context;");
150     out.println("}");
151
152     out.println();
153     out.println("public Handle getHandle()");
154     out.println("{");
155     out.println(" return getContext().getHandle();");
156     out.println("}");
157
158     out.println();
159     
160     generateComponents(out);
161   }
162 }
163
Popular Tags