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.cfg.*;
033: import com.caucho.java.gen.BaseMethod;
034: import com.caucho.java.gen.ClassComponent;
035: import com.caucho.java.gen.DependencyComponent;
036: import com.caucho.java.gen.GenClass;
037: import com.caucho.util.L10N;
038: import com.caucho.vfs.PersistentDependency;
039:
040: import java.util.ArrayList;
041:
042: /**
043: * Assembles the generator structure.
044: */
045: abstract public class BeanAssembler {
046: private static final L10N L = new L10N(BeanAssembler.class);
047:
048: private EjbBean _bean;
049:
050: protected GenClass _genClass;
051: protected GenClass _beanClass;
052:
053: protected DependencyComponent _dependency;
054:
055: public BeanAssembler(EjbBean bean, String fullClassName) {
056: _bean = bean;
057: _genClass = new GenClass(fullClassName);
058: _dependency = new DependencyComponent();
059: _genClass.addComponent(_dependency);
060: }
061:
062: /**
063: * Returns the short classname.
064: */
065: public String getShortClassName() {
066: return _genClass.getClassName();
067: }
068:
069: /**
070: * Returns assembled class.
071: */
072: public GenClass getAssembledGenerator() {
073: return _genClass;
074: }
075:
076: /**
077: * Adds an import.
078: */
079: public void addImport(String importName) {
080: _genClass.addImport(importName);
081: }
082:
083: /**
084: * Adds the header component.
085: */
086: public void addHeaderComponent(ApiClass beanClass,
087: String contextClassName, String implClassName) {
088: }
089:
090: /**
091: * Adds the bean method
092: */
093: public void addMethod(BaseMethod method) {
094: addComponent(method);
095: }
096:
097: /**
098: * Adds the bean method
099: */
100: public void addComponent(ClassComponent component) {
101: }
102:
103: /**
104: * Adds a dependency
105: */
106: public void addDependency(PersistentDependency depend) {
107: _dependency.addDependency(depend);
108: }
109:
110: /**
111: * Creates the home view.
112: */
113: abstract public ViewClass createHomeView(ApiClass homeClass,
114: String fullClassName, String viewPrefix);
115:
116: /**
117: * Creates the home view.
118: */
119: public final ViewClass createView(ApiClass homeClass,
120: String fullClassName, String viewPrefix) {
121: ArrayList<ApiClass> apiList = new ArrayList<ApiClass>();
122: apiList.add(homeClass);
123:
124: return createView(apiList, fullClassName, viewPrefix, "");
125: }
126:
127: /**
128: * Creates the home view.
129: */
130: abstract public ViewClass createView(ArrayList<ApiClass> apiList,
131: String fullClassName, String viewPrefix, String viewSuffix);
132:
133: /**
134: * Creates the home view.
135: */
136: abstract public ViewClass createRemoteView(
137: ArrayList<ApiClass> apiList, String fullClassName,
138: String viewPrefix, String viewSuffix);
139:
140: /**
141: * Checks for the existence of a method.
142: */
143: public static boolean hasMethod(ApiClass cl, String methodName,
144: Class[] args) {
145: return cl.getMethod(methodName, args) != null;
146: }
147: }
|