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.cfg21.EjbEntityBean;
033: import com.caucho.ejb.gen.*;
034: import com.caucho.ejb.gen21.EntityCreateMethod;
035: import com.caucho.ejb.gen21.EntityCreateCall;
036: import com.caucho.ejb.cfg.*;
037: import com.caucho.java.JavaWriter;
038: import com.caucho.java.gen.BaseMethod;
039: import com.caucho.java.gen.CallChain;
040: import com.caucho.util.L10N;
041:
042: import java.io.IOException;
043:
044: /**
045: * Generates the skeleton for a session view.
046: */
047: public class EntityHomeView extends ViewClass {
048: private static L10N L = new L10N(EntityHomeView.class);
049:
050: private EjbEntityBean _bean;
051:
052: private ApiClass _remoteClass;
053: private String _prefix;
054: private String _contextClassName;
055: private boolean _isCMP;
056:
057: public EntityHomeView(ApiClass remoteClass,
058: String contextClassName, String prefix, boolean isCMP) {
059: super (prefix, "Entity" + prefix);
060:
061: addInterfaceName(remoteClass.getName());
062:
063: _contextClassName = contextClassName;
064: _prefix = prefix;
065:
066: setStatic(true);
067: _isCMP = isCMP;
068: }
069:
070: /**
071: * Adds a business method.
072: */
073: public void addMethod(BaseMethod method) {
074: addComponent(method);
075: }
076:
077: public BaseMethod createCreateMethod(EjbEntityBean bean,
078: ApiMethod api, ApiMethod create, ApiMethod postCreate,
079: String fullClassName) {
080: EntityCreateMethod method;
081: method = new EntityCreateMethod(bean, api, create, postCreate,
082: fullClassName);
083:
084: EntityCreateCall call = (EntityCreateCall) method.getCall();
085:
086: call.setCMP(_isCMP);
087:
088: return method;
089: }
090:
091: /**
092: * Adds the pool chaining.
093: */
094: public CallChain createPoolChain(CallChain call, BaseMethod method) {
095: return new EntityPoolChain(call, true);
096: }
097:
098: public void generate(JavaWriter out) throws IOException {
099: generateGetter(out);
100:
101: out.println();
102: super .generate(out);
103: }
104:
105: private void generateGetter(JavaWriter out) throws IOException {
106: if (_prefix.equals("RemoteHome")) {
107: out.println();
108: out.println("public EJBHome createRemoteHomeView()");
109: out.println("{");
110: out.println(" return new RemoteHome(this);");
111: out.println("}");
112: out.println();
113: } else {
114: out.println();
115: out.println("public EJBLocalHome createLocalHome()");
116: out.println("{");
117: out.println(" return new LocalHome(this);");
118: out.println("}");
119: out.println();
120: }
121: }
122:
123: protected void generateClassContent(JavaWriter out)
124: throws IOException {
125: out.println("private " + _contextClassName + " _context;");
126: out.println("private EjbTransactionManager _xaManager;");
127: out.println();
128: out.println(_prefix + "(" + _contextClassName + " context)");
129: out.println("{");
130: out.println(" super(context.getEntityServer());");
131: out.println(" _context = context;");
132: out.println(" _xaManager = _server.getTransactionManager();");
133: out.println("}");
134: out.println();
135: out.println("private " + _contextClassName + " getContext()");
136: out.println("{");
137: out.println(" return _context;");
138: out.println("}");
139:
140: out.println();
141: out.println("public Handle getHandle()");
142: out.println("{");
143: out.println(" return getContext().getHandle();");
144: out.println("}");
145:
146: out.println();
147:
148: generateComponents(out);
149: }
150: }
|