public class Compile extends Object
includes=Note that the path separator character, here shown as a semicolon, is machine dependent. For instance, on Windows 95 this character is a semicolon, on UNIX it is a colon.; ;...;
Note 2: If you are directly invoking the main method on this class (not
a subclass), then it will only check that the IDL file is syntactically
correct. It does not generate any files. Only extensions to this
framework generate files, therefore an extension must be invoked if you
want files to be generated.
To Extend the compiler:
You only need to extend the compiler if you want it to generate something
other than what it currently generates.
Step 1 - Implement the generator interfaces:
Each generator interface defines one method: generate (Hashtable, XXXEntry, PrintWriter);
- The Hashtable is the symbol table; each element is a SymtabEntry (or a
subclass of SymtabEntry) and is keyed by its fully qualified name;
- XXXEntry is the appropriate entry for the type to be generated. For
example: AttributeGen defines generate (Hashtable, AttributeEntry, PrintWriter);
ConstGen defines generate (Hashtable, ConstEntry, PrintWriter); etc.
- The PrintWriter is a stream to the file being generated. For the
generators called by the compiler framework, this will be null. The
generator is responsible for creating and opening files. But for
generators that are called by other generators - for instance,
MethodGen.generate will most likely be called by InterfaceGen.generate -
this parameter is provided so that the proper file can be written to.
Step 2 - Implement the GenFactory interface:
All of the generators implemented in Step 1 must be created somehow. There
is an interface for a factory, GenFactory, which must be implemented. The
name of this factory must be set in the extension to the Compile class (see
Step 3, below).
Step 3 - Extend com.sun.tools.corba.se.idl.Factories:
Extend com.sun.tools.corba.se.idl.Factories and override the method genFactory. This
method must return an instance of the factory which you implemented in
step 2. Your extension of this class may also do more, this is only the
minimum. See com.sun.tools.corba.se.idl.Factories for more information.
Step 4 - Extend com.sun.tools.corba.se.idl.Compile:
Your extension of com.sun.tools.corba.se.idl.Compile should contain a minimum of
two methods:
public class MyCompile extends com.sun.tools.corba.se.idl.Compile { protected com.sun.tools.corba.se.idl.Factories factories () { return new MyFactories (); } public static void main (String[] args) { MyCompile compile = new MyCompile (); compile.start (args); } }If you would like a bit more control over the processing of the framework, you can replace compile.start with what it calls. But then you also have to handle the exceptions which start handles for you:
public class MyCompile extends com.sun.tools.corba.se.idl.Compile { ... public static void main (String[] args) { MyCompile compile = new MyCompile (); try { compile.init (args); java.util.Enumeration emitList = compile.parse (); compile.generate (); } catch (com.sun.tools.corba.se.idl.InvalidArgument e) { System.err.println (e); } catch (java.io.IOException e) { System.err.println (e); } } }Note that compile.parse returns an enumeration. This enumerates the SymtabEntry's which should be generated. If the parse method detects errors, it returns null. Note that you do not have to check that `emitList' is valid before calling generate (that's done internally), but if you do any processing between parse and generate, emitList should be checked before executing that code.
Modifier and Type | Field and Description |
---|---|
Arguments |
arguments
This is the repository of emitter arguments.
|
protected Vector |
includeEntries
This is a vector of IncludeEntry's.
|
protected Vector |
includes
This is a vector of strings of the form "IDLfile" or
|
protected Hashtable |
overrideNames
This hashtable contains
|
protected Hashtable |
symbolTable
This is the symbol table.
|
Constructor and Description |
---|
Compile() |
Modifier and Type | Method and Description |
---|---|
protected void |
displayVersion()
Write the version number of this compiler to standard out.
|
protected Factories |
factories() |
protected void |
generate()
Invoke the generators.
|
protected void |
init(String[] args)
Initialize the framework.
|
static void |
main(String[] args) |
protected Enumeration |
parse()
Parse the IDL file and return an enumeration of the symbols to be
generated.
|
protected void |
registerPragma(PragmaHandler handler) |
void |
start(String[] args)
Start the parse/code generation process.
|
public Arguments arguments
protected Hashtable overrideNames
protected Hashtable symbolTable
protected Vector includes
protected Vector includeEntries
public static void main(String[] args)
protected Factories factories()
protected void registerPragma(PragmaHandler handler)
protected void init(String[] args) throws InvalidArgument
InvalidArgument
protected Enumeration parse() throws IOException
IOException
protected void generate() throws IOException
IOException
public void start(String[] args)
protected void displayVersion()
Copyright © 2017 JBoss by Red Hat. All rights reserved.