KickJava   Java API By Example, From Geeks To Geeks.

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


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

44 public class SessionHomeView extends ViewClass {
45   private static L10N L = new L10N(SessionHomeView.class);
46
47   private JClass _remoteClass;
48   private String JavaDoc _prefix;
49   private String JavaDoc _contextClassName;
50   private boolean _isStateless;
51
52   public SessionHomeView(JClass remoteClass,
53              String JavaDoc contextClassName,
54              String JavaDoc prefix,
55              boolean isStateless)
56   {
57     super(prefix, isStateless ? "StatelessHome" : "SessionHome");
58
59     addInterfaceName(remoteClass.getName());
60
61     _contextClassName = contextClassName;
62     _prefix = prefix;
63     _isStateless = isStateless;
64
65     setStatic(true);
66   }
67
68   /**
69    * Adds a business method.
70    */

71   public void addMethod(BaseMethod method)
72   {
73     addComponent(method);
74   }
75
76   /**
77    * Adds the pool chaining.
78    */

79   public BaseMethod createCreateMethod(JMethod apiMethod,
80                        JMethod implMethod,
81                        String JavaDoc fullClassName,
82                        String JavaDoc prefix)
83   {
84     if (_isStateless)
85       return new StatelessCreateMethod(apiMethod,
86                        fullClassName,
87                        prefix);
88     else
89       return new SessionCreateMethod(apiMethod,
90                      implMethod,
91                      fullClassName,
92                      prefix);
93   }
94
95   /**
96    * Adds the pool chaining.
97    */

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