KickJava   Java API By Example, From Geeks To Geeks.

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


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 SessionView 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   private boolean _isStateless;
49   
50   public SessionView(JClass remoteClass,
51              String JavaDoc contextClassName,
52              String JavaDoc prefix,
53              boolean isStateless)
54   {
55     super(prefix, isStateless ? "StatelessObject" : "SessionObject");
56
57     addInterfaceName(remoteClass.getName());
58
59     _contextClassName = contextClassName;
60     _prefix = prefix;
61     _isStateless = isStateless;
62
63     setStatic(true);
64   }
65
66   /**
67    * Adds the pool chaining.
68    */

69   public CallChain createPoolChain(CallChain call)
70   {
71     if (_isStateless)
72       return new StatelessPoolChain(call);
73     else
74       return new SessionPoolChain(call);
75   }
76
77   public void generate(JavaWriter out)
78     throws IOException JavaDoc
79   {
80     generateGetter(out);
81
82     out.println();
83     super.generate(out);
84   }
85
86   private void generateGetter(JavaWriter out)
87     throws IOException JavaDoc
88   {
89     out.println("private " + _prefix + " _view" + _prefix + ";");
90     
91     out.println();
92     if (_prefix.equals("Local"))
93       out.println("public EJBLocalObject getEJBLocalObject()");
94     else
95       out.println("public EJBObject getRemoteView()");
96     
97     out.println("{");
98     out.println(" if (_view" + _prefix + " == null)");
99     out.println(" _view" + _prefix + " = new " + _prefix + "(this);");
100     
101     out.println();
102     out.println(" return _view" + _prefix + ";");
103     out.println("}");
104   }
105        
106   protected void generateClassContent(JavaWriter out)
107     throws IOException JavaDoc
108   {
109     out.println("private final " + _contextClassName + " _context;");
110     out.println("private final EjbTransactionManager _xaManager;");
111     
112     out.println();
113     out.println(_prefix + "(" + _contextClassName + " context)");
114     out.println("{");
115     if (_isStateless)
116       out.println(" super(context.getStatelessServer());");
117     else
118       out.println(" super(context.getSessionServer());");
119     out.println(" _context = context;");
120     out.println(" _xaManager = _server.getTransactionManager();");
121     out.println("}");
122     
123     out.println();
124     out.println("private " + _contextClassName + " getContext()");
125     out.println("{");
126     out.println(" return _context;");
127     out.println("}");
128
129     if (! _isStateless) {
130       out.println();
131       out.println("public String __caucho_getId()");
132       out.println("{");
133       out.println(" return _context.getPrimaryKey();");
134       out.println("}");
135     }
136
137     out.println();
138     generateComponents(out);
139   }
140 }
141
Popular Tags