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.ejb.cfg.*;
033: import com.caucho.java.JavaWriter;
034: import com.caucho.util.L10N;
035:
036: import javax.ejb.*;
037: import java.io.IOException;
038: import java.lang.reflect.*;
039: import java.util.*;
040:
041: /**
042: * Represents a public interface to a bean, e.g. a local stateful view
043: */
044: abstract public class View {
045: private static final L10N L = new L10N(View.class);
046:
047: protected final BeanGenerator _bean;
048: protected final ApiClass _api;
049:
050: protected View(BeanGenerator bean, ApiClass api) {
051: _bean = bean;
052: _api = api;
053: }
054:
055: /**
056: * Returns the owning bean.
057: */
058: protected BeanGenerator getBean() {
059: return _bean;
060: }
061:
062: /**
063: * Returns the bean's ejbclass
064: */
065: protected ApiClass getEjbClass() {
066: return _bean.getEjbClass();
067: }
068:
069: protected String getViewClassName() {
070: throw new UnsupportedOperationException(getClass().getName());
071: }
072:
073: protected String getBeanClassName() {
074: return getViewClassName();
075: }
076:
077: /**
078: * Returns the API class.
079: */
080: protected ApiClass getApi() {
081: return _api;
082: }
083:
084: /**
085: * Introspects the view
086: */
087: public void introspect() {
088: }
089:
090: /**
091: * Returns the introspected methods
092: */
093: public ArrayList<? extends BusinessMethodGenerator> getMethods() {
094: throw new UnsupportedOperationException(getClass().getName());
095: }
096:
097: /**
098: * Returns any around-invoke method
099: */
100: public Method getAroundInvokeMethod() {
101: return getBean().getAroundInvokeMethod();
102: }
103:
104: /**
105: * Generates prologue for the context.
106: */
107: public void generateContextPrologue(JavaWriter out)
108: throws IOException {
109:
110: }
111:
112: /**
113: * Generates context home's constructor
114: */
115: public void generateContextHomeConstructor(JavaWriter out)
116: throws IOException {
117: }
118:
119: /**
120: * Generates context object's constructor
121: */
122: public void generateContextObjectConstructor(JavaWriter out)
123: throws IOException {
124: }
125:
126: /**
127: * Generates any global destroy
128: */
129: public void generateDestroy(JavaWriter out) throws IOException {
130: }
131:
132: /**
133: * Generates the view code.
134: */
135: abstract public void generate(JavaWriter out) throws IOException;
136:
137: /**
138: * Generates constructor addiontions
139: */
140: public void generateBusinessConstructor(JavaWriter out)
141: throws IOException {
142: HashMap map = new HashMap();
143: for (BusinessMethodGenerator method : getMethods()) {
144: method.generateConstructorTop(out, map);
145: }
146: }
147:
148: /**
149: * Generates prologue additions
150: */
151: public void generateBusinessPrologue(JavaWriter out)
152: throws IOException {
153: generateBusinessPrologue(out, new HashMap());
154: }
155:
156: /**
157: * Generates prologue additions
158: */
159: public void generateBusinessPrologue(JavaWriter out, HashMap map)
160: throws IOException {
161: for (BusinessMethodGenerator method : getMethods()) {
162: method.generatePrologueTop(out, map);
163: }
164: }
165:
166: /**
167: * Generates view's business methods
168: */
169: public void generateBusinessMethods(JavaWriter out)
170: throws IOException {
171: HashMap map = new HashMap();
172: for (BusinessMethodGenerator method : getMethods()) {
173: method.generate(out, map);
174: }
175: }
176:
177: /**
178: * Returns a full method name with arguments.
179: */
180: public static String getFullMethodName(ApiMethod method) {
181: return getFullMethodName(method.getName(), method
182: .getParameterTypes());
183: }
184:
185: /**
186: * Returns a full method name with arguments.
187: */
188: public static String getFullMethodName(Method method) {
189: return getFullMethodName(method.getName(), method
190: .getParameterTypes());
191: }
192:
193: /**
194: * Returns a full method name with arguments.
195: */
196: public static String getFullMethodName(String methodName,
197: Class[] params) {
198: String name = methodName + "(";
199:
200: for (int i = 0; i < params.length; i++) {
201: if (i != 0)
202: name += ", ";
203:
204: name += params[i].getSimpleName();
205: }
206:
207: return name + ")";
208: }
209:
210: }
|