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: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.ejb.gen21;
030:
031: import com.caucho.ejb.gen.*;
032: import com.caucho.make.ClassDependency;
033: import com.caucho.vfs.MergePath;
034: import com.caucho.vfs.PersistentDependency;
035:
036: import java.io.IOException;
037: import java.lang.reflect.Method;
038: import java.util.ArrayList;
039:
040: /**
041: * Generator for stubs.
042: */
043: public class JVMHomeStubGenerator extends JVMStubGenerator {
044: protected ArrayList<PersistentDependency> _dependList;
045:
046: /**
047: * Creates an instance of the generator
048: */
049: public JVMHomeStubGenerator(Class remoteHomeClass, boolean isProxy) {
050: _remoteClass = remoteHomeClass;
051:
052: _isProxy = isProxy;
053:
054: if (isProxy)
055: setFullClassName(remoteHomeClass.getName() + "__JVMProxy");
056: else
057: setFullClassName(remoteHomeClass.getName() + "__JVMStub");
058:
059: MergePath mergePath = new MergePath();
060: setSearchPath(mergePath);
061:
062: _dependList = new ArrayList<PersistentDependency>();
063:
064: _dependList.add(new ClassDependency(remoteHomeClass));
065: }
066:
067: /**
068: * Creates the home stub for the home interface
069: */
070: public Class generateStub() throws Exception {
071: Class home = preload();
072: if (home != null)
073: return home;
074:
075: generate();
076:
077: return compile();
078: }
079:
080: /**
081: * Generates the Java source.
082: *
083: * @param methods the methods to generate
084: */
085: public void generateJava() throws IOException {
086: printHeader();
087:
088: Method[] methods = _remoteClass.getMethods();
089: for (int i = 0; i < methods.length; i++) {
090: Method method = methods[i];
091: String methodName = method.getName();
092: Class declaringClass = method.getDeclaringClass();
093:
094: if (declaringClass.getName().startsWith("javax.ejb."))
095: continue;
096:
097: Class[] exns = method.getExceptionTypes();
098: for (int j = 0; j < exns.length; j++) {
099: if (exns[j]
100: .isAssignableFrom(java.rmi.RemoteException.class)) {
101: printMethod(method.getName(), method);
102: break;
103: }
104: }
105: }
106:
107: printDependList(_dependList);
108:
109: printFooter();
110: }
111:
112: /**
113: * Prints the header for a HomeStub
114: */
115: protected void printHeader() throws IOException {
116: if (getPackageName() != null)
117: println("package " + getPackageName() + ";");
118:
119: println();
120: println("import java.io.*;");
121: println("import java.rmi.*;");
122: println("import " + _remoteClass.getName() + ";");
123:
124: println();
125: println("public class " + getClassName());
126: println(" extends com.caucho.ejb.JVMHome");
127: println(" implements " + _remoteClass.getName());
128:
129: println("{");
130: pushDepth();
131: }
132: }
|