001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.ejb.gen;
031:
032: import com.caucho.java.JavaWriter;
033: import com.caucho.ejb.cfg.*;
034: import com.caucho.util.L10N;
035:
036: import javax.ejb.*;
037: import java.io.IOException;
038:
039: /**
040: * Generates the skeleton for a stateful bean.
041: */
042: public class StatefulGenerator extends SessionGenerator {
043: private static final L10N L = new L10N(StatefulGenerator.class);
044:
045: public StatefulGenerator(String ejbName, ApiClass ejbClass) {
046: super (ejbName, ejbClass);
047: }
048:
049: public boolean isStateless() {
050: return false;
051: }
052:
053: @Override
054: protected View createLocalView(ApiClass api) {
055: return new StatefulLocalView(this , api);
056: }
057:
058: @Override
059: protected View createLocalHomeView(ApiClass api) {
060: return new StatefulLocalHomeView(this , api);
061: }
062:
063: @Override
064: protected View createRemoteHomeView(ApiClass api) {
065: return new StatefulRemoteHomeView(this , api);
066: }
067:
068: @Override
069: protected View createRemoteView(ApiClass api) {
070: return new StatefulRemoteView(this , api);
071: }
072:
073: /**
074: * Generates the stateful session bean
075: */
076: @Override
077: public void generate(JavaWriter out) throws IOException {
078: generateTopComment(out);
079:
080: out.println();
081: out.println("package " + getPackageName() + ";");
082:
083: out.println();
084: out.println("import com.caucho.config.*;");
085: out.println("import com.caucho.ejb.*;");
086: out.println("import com.caucho.ejb.session.*;");
087: out.println();
088: out.println("import javax.ejb.*;");
089: out.println("import javax.transaction.*;");
090:
091: out.println();
092: out.println("public class " + getClassName());
093: out.println(" extends StatefulContext");
094: out.println("{");
095: out.pushDepth();
096:
097: out.println();
098: out.println("public " + getClassName()
099: + "(StatefulServer server)");
100: out.println("{");
101: out.pushDepth();
102:
103: out.println("super(server);");
104:
105: for (View view : getViews()) {
106: view.generateContextHomeConstructor(out);
107: }
108:
109: out.popDepth();
110: out.println("}");
111:
112: out.println();
113: out.println("public " + getClassName() + "(" + getClassName()
114: + " context)");
115: out.println("{");
116: out.pushDepth();
117:
118: out.println("super(context.getStatefulServer());");
119:
120: generateContextObjectConstructor(out);
121:
122: out.popDepth();
123: out.println("}");
124:
125: for (View view : getViews()) {
126: view.generateContextPrologue(out);
127: }
128:
129: generateCreateProvider(out);
130: generateViews(out);
131:
132: out.popDepth();
133: out.println("}");
134: }
135:
136: protected void generateCreateProvider(JavaWriter out)
137: throws IOException {
138: out.println();
139: out.println("@Override");
140: out.println("public StatefulProvider getProvider(Class api)");
141: out.println("{");
142: out.pushDepth();
143:
144: for (View view : getViews()) {
145: StatefulView sView = (StatefulView) view;
146:
147: sView.generateCreateProvider(out, "api");
148: }
149:
150: out.println();
151: out.println("return super.getProvider(api);");
152:
153: out.popDepth();
154: out.println("}");
155: }
156:
157: /**
158: * Creates any additional code in the constructor
159: */
160: public void generateContextObjectConstructor(JavaWriter out)
161: throws IOException {
162: for (View view : getViews()) {
163: view.generateContextObjectConstructor(out);
164: }
165: }
166:
167: protected void generateContext(JavaWriter out) {
168: }
169: }
|