|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.farrago.catalog.codegen.ProxyGen
public class ProxyGen
ProxyGen generates read-only C++ JNI proxies for MDR-generated Java interfaces (something like a stripped-down JACE). It uses an unholy mix of Java/JMI navel-scrutiny. For an example of its output, see FemGeneratedClasses.h and FemGeneratedMethods.h in //open/fennel/farrago.
To understand this generator, it's important to distinguish among MOF/UML/JMI classes (which are metadata objects), repository-generated Java interfaces, and the C++ proxy classes generated here.
Nested Class Summary | |
---|---|
private static class |
ProxyGen.CppTypeInfo
|
Field Summary | |
---|---|
private Set<Class> |
baseInterfaces
Set containing all base interfaces (represented as Class objects) from which C++ proxies are to inherit. |
private String |
basePrefix
|
private static Comparator<Class> |
classNameComparator
|
private Map<Class,ProxyGen.CppTypeInfo> |
cppTypeMap
Map from Class to corresponding C++ type name as String. |
private Set<Class> |
genEnums
Set containing all interfaces (represented as Class objects) for which C++ enums are to be generated. |
private Set<Class> |
genInterfaces
Set containing all interfaces (represented as Class objects) for which C++ proxies are to be generated. |
private String |
genPrefix
|
private Map<Class,RefClass> |
javaToJmiMap
Map from Class to RefClass for everything in genInterfaces. |
private Map<Class,String> |
javaTypeMap
Map from Class to corresponding Java type String to use in method signatures. |
private static Comparator<Method> |
methodNameComparator
|
private PrintWriter |
pw
PrintWriter used to generate output. |
private Set<Class> |
undefinedInterfaces
Set containing interfaces (represented as Class objects) whose proxy definition has not yet been generated. |
private String |
visitorBaseName
|
private String |
visitorClassName
|
Constructor Summary | |
---|---|
ProxyGen(String genPrefix,
String basePrefix)
Initialize a new ProxyGen. |
Method Summary | |
---|---|
void |
addBaseClasses(RefPackage refPackage)
Adds all classes from a JMI package to the set of interfaces to use as bases. |
void |
addGenClasses(RefPackage refPackage)
Adds all classes from a JMI package to the set of interfaces to be generated. |
private static RefPackage |
findPackage(RefPackage rootPackage,
String qualifiedName)
|
private void |
generateClassDeclaration(Class clazz)
|
void |
generateClassDefinition(Class clazz)
Generates the C++ class definition for one interface. |
void |
generateClassDefinitions(PrintWriter pw)
Generates the C++ code for all class definitions. |
void |
generateClassImplementations(PrintWriter pw)
Generates the C++ code for all method definitions. |
void |
generateEnumDefinitions(PrintWriter pw)
Generates the C++ code for all enumerations. |
void |
generateMethodDeclaration(Method method)
Generates the C++ declaration for one (getter) method. |
void |
generateMethodDefinition(Method method)
Generates the C++ definition for one (getter) method. |
void |
generateSetterMethodDeclaration(Method method)
Generates the C++ declaration for one setter method and its corresponding clear method (if any). |
void |
generateSetterMethodDefinition(Method method)
Generates the C++ definition for one setter method and its corresponding clear method (if any). |
private void |
generateStaticDefinitions(Class clazz)
|
private void |
generateStaticInitialization(Class clazz)
|
private void |
generateVisitDeclaration(Class clazz)
|
private String |
getCppClassName(Class clazz)
Gets the name of the C++ type for a proxy instance. |
private ProxyGen.CppTypeInfo |
getCppParameterTypeInfo(Class<?> parameterType)
|
private String |
getCppRefName(Class clazz)
Gets the name of the C++ type used to return a proxy instance by reference. |
private String |
getCppReturnTypeName(Method method)
|
private String |
getJavaTypeSignature(Class clazz)
|
private boolean |
isGetter(Method method)
Decides whether a Java method is a getter for a JMI attribute. |
private boolean |
isSetter(Method method)
Decides whether a Java method is setter for a JMI attribute that should be proxied. |
static void |
main(String[] args)
Main generator entry point invoked by build.xml (target "generateFemCpp"). |
private RefClass |
toJmiClass(Class clazz)
Finds the JMI class corresponding to a Java interface. |
private static Class[] |
toSortedArray(Collection<Class> collection)
Converts collection into an array of classes sorted by name. |
private static Method[] |
toSortedArray(Method[] methods)
Sorts an array of Methods. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final Comparator<Class> classNameComparator
private static final Comparator<Method> methodNameComparator
private Map<Class,ProxyGen.CppTypeInfo> cppTypeMap
private Map<Class,RefClass> javaToJmiMap
private Map<Class,String> javaTypeMap
private PrintWriter pw
private Set<Class> genInterfaces
private Set<Class> baseInterfaces
private Set<Class> undefinedInterfaces
private Set<Class> genEnums
private String genPrefix
private String basePrefix
private String visitorClassName
private String visitorBaseName
Constructor Detail |
---|
public ProxyGen(String genPrefix, String basePrefix)
Method Detail |
---|
public void addGenClasses(RefPackage refPackage) throws ClassNotFoundException
refPackage
- the source JMI package
ClassNotFoundException
public void addBaseClasses(RefPackage refPackage) throws ClassNotFoundException
refPackage
- the source JMI package
ClassNotFoundException
public void generateClassDefinition(Class clazz)
clazz
- the interfacepublic void generateClassDefinitions(PrintWriter pw)
pw
- outputpublic void generateEnumDefinitions(PrintWriter pw) throws Exception
pw
- output
Exception
public void generateClassImplementations(PrintWriter pw)
pw
- outputprivate static Class[] toSortedArray(Collection<Class> collection)
private static Method[] toSortedArray(Method[] methods)
Class.getDeclaredMethods()
does not guarantee that it returns methods in
any particular order, and in practice the order changes across versions
(vendors?) of javac.
public void generateMethodDeclaration(Method method)
method
- .public void generateSetterMethodDeclaration(Method method)
method
- .public void generateMethodDefinition(Method method)
method
- .public void generateSetterMethodDefinition(Method method)
method
- .public static void main(String[] args) throws Exception
args
- Exception
private static RefPackage findPackage(RefPackage rootPackage, String qualifiedName)
private String getCppClassName(Class clazz)
clazz
- the source Java interface
private String getCppRefName(Class clazz)
clazz
- the source Java interface
private String getCppReturnTypeName(Method method)
private ProxyGen.CppTypeInfo getCppParameterTypeInfo(Class<?> parameterType)
private boolean isGetter(Method method)
method
- the Java method
private boolean isSetter(Method method)
Long
), or String
. We ignore all methods
that don't match.
method
- the Java method
private String getJavaTypeSignature(Class clazz)
private void generateClassDeclaration(Class clazz)
private void generateStaticDefinitions(Class clazz)
private void generateStaticInitialization(Class clazz)
private void generateVisitDeclaration(Class clazz)
private RefClass toJmiClass(Class clazz)
clazz
- the Java interface
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |