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.gen21;
031:
032: import com.caucho.ejb.gen.*;
033: import com.caucho.ejb.cfg.*;
034: import com.caucho.java.JavaWriter;
035: import com.caucho.java.gen.BaseMethod;
036: import com.caucho.java.gen.CallChain;
037: import com.caucho.util.L10N;
038:
039: import java.io.IOException;
040:
041: /**
042: * Generates the skeleton for a session view.
043: */
044: public class EntityView extends ViewClass {
045: private static L10N L = new L10N(EntityView.class);
046:
047: private ApiClass _remoteClass;
048: private String _prefix;
049: private String _contextClassName;
050:
051: public EntityView(ApiClass remoteClass, String contextClassName,
052: String prefix) {
053: super (prefix, "EntityObject");
054:
055: addInterfaceName(remoteClass.getName());
056:
057: _contextClassName = contextClassName;
058: _prefix = prefix;
059:
060: setStatic(true);
061: }
062:
063: /**
064: * Adds the pool chaining.
065: */
066: public CallChain createPoolChain(CallChain call, BaseMethod method) {
067: return new EntityPoolChain(call, false);
068: }
069:
070: public void generate(JavaWriter out) throws IOException {
071: generateGetter(out);
072:
073: out.println();
074: super .generate(out);
075: }
076:
077: private void generateGetter(JavaWriter out) throws IOException {
078: out.println("private " + _prefix + " _view" + _prefix + ";");
079:
080: out.println();
081: if (_prefix.equals("Local"))
082: out.println("public EJBLocalObject getEJBLocalObject()");
083: else
084: out.println("public EJBObject getRemoteView()");
085:
086: out.println("{");
087: out.println(" if (_view" + _prefix + " == null)");
088: out.println(" _view" + _prefix + " = new " + _prefix
089: + "(this);");
090:
091: out.println();
092: out.println(" return _view" + _prefix + ";");
093: out.println("}");
094: }
095:
096: protected void generateClassContent(JavaWriter out)
097: throws IOException {
098: out.println("private " + _contextClassName + " _context;");
099: out.println("private EjbTransactionManager _xaManager;");
100:
101: out.println();
102: out.println(_prefix + "(" + _contextClassName + " context)");
103: out.println("{");
104: out.println(" _context = context;");
105: out
106: .println(" _xaManager = context.getEntityServer().getTransactionManager();");
107: out.println("}");
108:
109: out.println();
110: out.println("public QEntityContext getEntityContext()");
111: out.println("{");
112: out.println(" return _context;");
113: out.println("}");
114:
115: generateGetBean(out);
116:
117: generateComponents(out);
118: }
119:
120: /**
121: * Generates the get bean code, which is required when the Local getters
122: * aren't expoxed.
123: */
124: protected void generateGetBean(JavaWriter out) throws IOException {
125: out.println();
126: out
127: .println("public Object _caucho_getBean(com.caucho.ejb.xa.TransactionContext trans, boolean doLoad)");
128: out.println("{");
129: out.pushDepth();
130:
131: out.println("return _context._ejb_begin(trans, false, true);");
132:
133: out.popDepth();
134: out.println("}");
135: out.println();
136:
137: out.println("public Object _caucho_getBean()");
138: out.println("{");
139: out.pushDepth();
140:
141: out.println("com.caucho.ejb.xa.TransactionContext trans;");
142: out
143: .println("trans = _context._server.getTransactionManager().getTransactionContext();");
144: out.println("return _context._ejb_begin(trans, false, false);");
145:
146: out.popDepth();
147: out.println("}");
148: }
149: }
|