KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > ejb > gen > JVMHomeStubGenerator


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.ejb.gen;
30
31 import com.caucho.make.ClassDependency;
32 import com.caucho.vfs.MergePath;
33 import com.caucho.vfs.PersistentDependency;
34
35 import java.io.IOException JavaDoc;
36 import java.lang.reflect.Method JavaDoc;
37 import java.util.ArrayList JavaDoc;
38
39 /**
40  * Generator for stubs.
41  */

42 public class JVMHomeStubGenerator extends JVMStubGenerator {
43   protected ArrayList JavaDoc<PersistentDependency> _dependList;
44
45   /**
46    * Creates an instance of the generator
47    */

48   public JVMHomeStubGenerator(Class JavaDoc remoteHomeClass, boolean isProxy)
49   {
50     _remoteClass = remoteHomeClass;
51
52     _isProxy = isProxy;
53
54     if (isProxy)
55       setFullClassName(remoteHomeClass.getName() + "__JVMProxy");
56     else
57       setFullClassName(remoteHomeClass.getName() + "__JVMStub");
58     
59     MergePath mergePath = new MergePath();
60     setSearchPath(mergePath);
61
62     _dependList = new ArrayList JavaDoc<PersistentDependency>();
63
64     _dependList.add(new ClassDependency(remoteHomeClass));
65   }
66   
67   /**
68    * Creates the home stub for the home interface
69    */

70   public Class JavaDoc generateStub()
71     throws Exception JavaDoc
72   {
73     Class JavaDoc home = preload();
74     if (home != null)
75       return home;
76
77     generate();
78     
79     return compile();
80   }
81
82   /**
83    * Generates the Java source.
84    *
85    * @param methods the methods to generate
86    */

87   public void generateJava()
88     throws IOException JavaDoc
89   {
90     printHeader();
91     
92     Method JavaDoc []methods = _remoteClass.getMethods();
93     for (int i = 0; i < methods.length; i++) {
94       Method JavaDoc method = methods[i];
95       String JavaDoc methodName = method.getName();
96       Class JavaDoc declaringClass = method.getDeclaringClass();
97
98       if (declaringClass.getName().startsWith("javax.ejb."))
99         continue;
100
101       Class JavaDoc []exns = method.getExceptionTypes();
102       for (int j = 0; j < exns.length; j++) {
103         if (exns[j].isAssignableFrom(java.rmi.RemoteException JavaDoc.class)) {
104           printMethod(method.getName(), method);
105           break;
106         }
107       }
108     }
109     
110     printDependList(_dependList);
111
112     printFooter();
113   }
114
115   /**
116    * Prints the header for a HomeStub
117    */

118   protected void printHeader()
119     throws IOException JavaDoc
120   {
121     if (getPackageName() != null)
122       println("package " + getPackageName() + ";");
123
124     println();
125     println("import java.io.*;");
126     println("import java.rmi.*;");
127     println("import " + _remoteClass.getName() + ";");
128     
129     println();
130     println("public class " + getClassName());
131     println(" extends com.caucho.ejb.JVMHome");
132     println(" implements " + _remoteClass.getName());
133     
134     println("{");
135     pushDepth();
136   }
137 }
138
Popular Tags