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.config.*;
033: import com.caucho.ejb.cfg.*;
034: import com.caucho.java.JavaWriter;
035: import com.caucho.util.L10N;
036:
037: import javax.ejb.*;
038: import java.io.IOException;
039: import java.lang.reflect.*;
040: import java.util.*;
041:
042: /**
043: * Represents a public interface to a stateful bean, e.g. a stateful view
044: */
045: public class MessageView extends View {
046: private static final L10N L = new L10N(MessageView.class);
047:
048: private MessageGenerator _messageBean;
049:
050: private ArrayList<BusinessMethodGenerator> _businessMethods = new ArrayList<BusinessMethodGenerator>();
051:
052: public MessageView(MessageGenerator bean, ApiClass api) {
053: super (bean, api);
054:
055: _messageBean = bean;
056: }
057:
058: public MessageGenerator getMessageBean() {
059: return _messageBean;
060: }
061:
062: public String getContextClassName() {
063: return getMessageBean().getClassName();
064: }
065:
066: public String getViewClassName() {
067: return getMessageBean().getClassName();
068: }
069:
070: /**
071: * Returns the introspected methods
072: */
073: public ArrayList<? extends BusinessMethodGenerator> getMethods() {
074: return _businessMethods;
075: }
076:
077: /**
078: * Introspects the APIs methods, producing a business method for
079: * each.
080: */
081: @Override
082: public void introspect() {
083: ApiClass implClass = getEjbClass();
084: ApiClass apiClass = getApi();
085:
086: for (ApiMethod apiMethod : apiClass.getMethods()) {
087: if (apiMethod.getDeclaringClass().equals(Object.class))
088: continue;
089: if (apiMethod.getDeclaringClass().getName().startsWith(
090: "javax.ejb.")
091: && !apiMethod.getName().equals("remove"))
092: continue;
093:
094: int index = _businessMethods.size();
095:
096: BusinessMethodGenerator bizMethod = createMethod(apiMethod,
097: index);
098:
099: if (bizMethod != null) {
100: bizMethod.introspect(bizMethod.getApiMethod(),
101: bizMethod.getImplMethod());
102:
103: _businessMethods.add(bizMethod);
104: }
105: }
106: }
107:
108: /**
109: * Generates the view code.
110: */
111: public void generate(JavaWriter out) throws IOException {
112: HashMap map = new HashMap();
113: map.put("caucho.ejb.xa", "done");
114:
115: /* ejb/0fbm
116: for (BusinessMethodGenerator bizMethod : _businessMethods) {
117: bizMethod.generatePrologueTop(out, map);
118: }
119: */
120:
121: for (BusinessMethodGenerator bizMethod : _businessMethods) {
122: bizMethod.generate(out, map);
123: }
124: }
125:
126: protected BusinessMethodGenerator createMethod(ApiMethod apiMethod,
127: int index) {
128: ApiMethod implMethod = findImplMethod(apiMethod);
129:
130: if (implMethod == null)
131: return null;
132:
133: BusinessMethodGenerator bizMethod = new MessageMethod(this ,
134: apiMethod, implMethod.getMethod(), index);
135:
136: return bizMethod;
137: }
138:
139: protected ApiMethod findImplMethod(ApiMethod apiMethod) {
140: ApiMethod implMethod = getEjbClass().getMethod(apiMethod);
141:
142: if (implMethod != null)
143: return implMethod;
144:
145: throw ConfigException
146: .create(
147: apiMethod.getMethod(),
148: L
149: .l(
150: "api method has no corresponding implementation in '{0}'",
151: getEjbClass().getName()));
152: }
153: }
|