KickJava   Java API By Example, From Geeks To Geeks.

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


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

42 public class EntityView extends ViewClass {
43   private static L10N L = new L10N(SessionView.class);
44
45   private JClass _remoteClass;
46   private String JavaDoc _prefix;
47   private String JavaDoc _contextClassName;
48   
49   public EntityView(JClass remoteClass,
50             String JavaDoc contextClassName,
51             String JavaDoc prefix)
52   {
53     super(prefix, "EntityObject");
54
55     addInterfaceName(remoteClass.getName());
56
57     _contextClassName = contextClassName;
58     _prefix = prefix;
59
60     setStatic(true);
61   }
62
63   /**
64    * Adds the pool chaining.
65    */

66   public CallChain createPoolChain(CallChain call)
67   {
68     return new EntityPoolChain(call, false);
69   }
70
71   public void generate(JavaWriter out)
72     throws IOException JavaDoc
73   {
74     generateGetter(out);
75
76     out.println();
77     super.generate(out);
78   }
79
80   private void generateGetter(JavaWriter out)
81     throws IOException JavaDoc
82   {
83     out.println("private " + _prefix + " _view" + _prefix + ";");
84     
85     out.println();
86     if (_prefix.equals("Local"))
87       out.println("public EJBLocalObject getEJBLocalObject()");
88     else
89       out.println("public EJBObject getRemoteView()");
90     
91     out.println("{");
92     out.println(" if (_view" + _prefix + " == null)");
93     out.println(" _view" + _prefix + " = new " + _prefix + "(this);");
94     
95     out.println();
96     out.println(" return _view" + _prefix + ";");
97     out.println("}");
98   }
99        
100   protected void generateClassContent(JavaWriter out)
101     throws IOException JavaDoc
102   {
103     out.println("private " + _contextClassName + " _context;");
104     out.println("private EjbTransactionManager _xaManager;");
105     
106     out.println();
107     out.println(_prefix + "(" + _contextClassName + " context)");
108     out.println("{");
109     out.println(" _context = context;");
110     out.println(" _xaManager = context.getEntityServer().getTransactionManager();");
111     out.println("}");
112     
113     out.println();
114     out.println("public QEntityContext getEntityContext()");
115     out.println("{");
116     out.println(" return _context;");
117     out.println("}");
118
119     generateGetBean(out);
120
121     generateComponents(out);
122   }
123
124   /**
125    * Generates the get bean code, which is required when the Local getters
126    * aren't expoxed.
127    */

128   protected void generateGetBean(JavaWriter out)
129     throws IOException JavaDoc
130   {
131     out.println();
132     out.println("public Object _caucho_getBean(com.caucho.ejb.xa.TransactionContext trans, boolean doLoad)");
133     out.println("{");
134     out.pushDepth();
135
136     out.println("return _context._ejb_begin(trans, false, true);");
137
138     out.popDepth();
139     out.println("}");
140     out.println();
141     
142     out.println("public Object _caucho_getBean()");
143     out.println("{");
144     out.pushDepth();
145
146     out.println("com.caucho.ejb.xa.TransactionContext trans;");
147     out.println("trans = _context._server.getTransactionManager().getTransactionContext();");
148     out.println("return _context._ejb_begin(trans, false, false);");
149
150     out.popDepth();
151     out.println("}");
152   }
153 }
154
Popular Tags