|
From: Richard G C. <pim...@us...> - 2004-07-28 15:18:14
|
Update of /cvsroot/openorb/OpenORB/src/compiler/org/openorb/compiler/rmi/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29014/OpenORB/src/compiler/org/openorb/compiler/rmi/parser Modified Files: JavaParser.java MappingAPI.java Log Message: refactoring + more verbose output Index: JavaParser.java =================================================================== RCS file: /cvsroot/openorb/OpenORB/src/compiler/org/openorb/compiler/rmi/parser/JavaParser.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- JavaParser.java 22 Jul 2004 12:25:44 -0000 1.14 +++ JavaParser.java 28 Jul 2004 15:18:05 -0000 1.15 @@ -10,8 +10,10 @@ import java.io.FileNotFoundException; -import java.util.Hashtable; -import java.util.Vector; +import java.util.Map; +import java.util.List; +import java.util.HashMap; +import java.util.ArrayList; import org.openorb.compiler.CompilerHost; @@ -24,6 +26,8 @@ import org.openorb.compiler.rmi.RmiCompilerProperties; +import org.openorb.compiler.orb.Configurator; + /** * This class builds the java data tree needed for the generation of * idl code. @@ -37,25 +41,25 @@ * Compilation tree vector. This vector holds all the sub-trees * created by all JavaParser instances. */ - private Vector m_compilationTreeVector = null; + private List m_compilationTreeVector; /** Classes that have been already processed. */ - private Vector m_alreadyProcessedClasses = null; + private List m_alreadyProcessedClasses; /** Association between the Java name and the IDL linked mapping. */ - private Hashtable m_mappingNames = null; + private Map m_mappingNames; - private RmiCompilerProperties m_rcp = null; + private RmiCompilerProperties m_rcp; - private CompilerHost m_ch = null; + private CompilerHost m_ch; /** The root node of the IDL tree. A per instance variable. */ - private IdlObject m_idlTreeRoot = null; + private IdlObject m_idlTreeRoot; - private IdlParser m_idlparser = null; + private IdlParser m_idlparser; /** The current parsed class. */ - private Class m_currentClass = null; + private Class m_currentClass; /** * Constructor. @@ -68,8 +72,9 @@ * @param alreadyProcessedClasses A vector of classes that have already been processed * by this JavaParser tree. */ - public JavaParser( RmiCompilerProperties rcp, CompilerHost ch, - Vector compilationTreeVector, Hashtable mappingNames, Vector alreadyProcessedClasses ) + public JavaParser( final RmiCompilerProperties rcp, final CompilerHost ch, + final List compilationTreeVector, final Map mappingNames, + final List alreadyProcessedClasses ) { m_ch = ch; m_rcp = rcp; @@ -91,7 +96,7 @@ } else { - m_alreadyProcessedClasses = new Vector(); + m_alreadyProcessedClasses = new ArrayList(); } if ( mappingNames != null ) @@ -100,7 +105,7 @@ } else { - m_mappingNames = new Hashtable(); + m_mappingNames = new HashMap(); } if ( compilationTreeVector != null ) @@ -109,30 +114,23 @@ } else { - m_compilationTreeVector = new Vector(); + m_compilationTreeVector = new ArrayList(); } // The IdlRoot is a new instance for each JavaParser instance - m_compilationTreeVector.addElement( getIdlTreeRoot() ); + m_compilationTreeVector.add( getIdlTreeRoot() ); // add the standard mappings only once if ( compilationTreeVector != null && mappingNames != null && alreadyProcessedClasses != null ) { - m_mappingNames.put( new String( "java.lang.Object" ), - new String( "::java::lang::_Object" ) ); - m_mappingNames.put( new String( "org.omg.CORBA.Object" ), - new String( "::CORBA::Object" ) ); - m_mappingNames.put( new String( "java.rmi.Remote" ), - new String( "::java::rmi::Remote" ) ); - m_mappingNames.put( new String( "java.io.Serializable" ), - new String( "::java::io::Serializable" ) ); - m_mappingNames.put( new String( "java.io.Externalizable" ), - new String( "::java::io::Externalizable" ) ); - m_mappingNames.put( new String( "java.lang.Class" ), - new String( "::javax::rmi::CORBA::ClassDesc" ) ); - m_mappingNames.put( new String( "java.lang.String" ), - new String( "::CORBA::WStringValue" ) ); + m_mappingNames.put( "java.lang.Object", "::java::lang::_Object" ); + m_mappingNames.put( "org.omg.CORBA.Object", "::CORBA::Object" ); + m_mappingNames.put( "java.rmi.Remote", "::java::rmi::Remote" ); + m_mappingNames.put( "java.io.Serializable", "::java::io::Serializable" ); + m_mappingNames.put( "java.io.Externalizable", "::java::io::Externalizable" ); + m_mappingNames.put( "java.lang.Class", "::javax::rmi::CORBA::ClassDesc" ); + m_mappingNames.put( "java.lang.String", "::CORBA::WStringValue" ); } } @@ -141,7 +139,7 @@ * * @return The compilation tree vector. */ - public Vector getCompilationTree() + public List getCompilationTree() { return m_compilationTreeVector; } @@ -151,17 +149,17 @@ * * @return The already processed classes vector. */ - public Vector getAlreadyProcessedClasses() + public List getAlreadyProcessedClasses() { return m_alreadyProcessedClasses; } /** - * Return the Hashtable of Java - IDL name mappings. + * Return the Map of Java - IDL name mappings. * - * @return The Hashtable of Java - IDL name mappings. + * @return The Map of Java - IDL name mappings. */ - public Hashtable getMappingNames() + public Map getMappingNames() { return m_mappingNames; } @@ -186,7 +184,7 @@ * * @param new_idl_root The root of the parsing tree. */ - public void setIdlTreeRoot( IdlObject new_idl_root ) + public void setIdlTreeRoot( final IdlObject new_idl_root ) { m_idlTreeRoot = new_idl_root; } @@ -196,7 +194,7 @@ * * @param newClass The new class to be parsed. */ - public void setCurrentClass( Class newClass ) + public void setCurrentClass( final Class newClass ) { m_currentClass = newClass; } @@ -218,15 +216,16 @@ * @param limit ??? * @return The object if one was found, null otherwise. */ - public IdlObject returnObject( String scope, boolean limit ) + public IdlObject returnObject( final String scope, final boolean limit ) { - for ( int i = 0; i < m_compilationTreeVector.size(); i++ ) + final int size = m_compilationTreeVector.size(); + for ( int i = 0; i < size; i++ ) { - IdlObject obj = ( IdlObject ) m_compilationTreeVector.elementAt( i ); - obj = obj.returnObject( scope, limit ); - if ( obj != null ) + final IdlObject obj = ( IdlObject ) m_compilationTreeVector.get( i ); + final IdlObject newObj = obj.returnObject( scope, limit ); + if ( newObj != null ) { - return obj; + return newObj; } } return null; @@ -238,7 +237,7 @@ * @param java_file_name The name of the file to parse. * @return The IdlObject representing the parsed class. */ - public IdlObject parse_java( String java_file_name ) + public IdlObject parse_java( final String java_file_name ) { return parse_java( java_file_name, false ); } @@ -251,15 +250,16 @@ * and try to get the remote interface in this case. * @return The IdlObject representing the parsed class. */ - public IdlObject parse_java( String java_file_name, boolean check_implements ) + public IdlObject parse_java( final String java_file_name, final boolean check_implements ) { - display( "JavaParser::parse_java" ); + display( "JavaParser::parse_java((String)[", java_file_name, + "], (boolean)[", ( check_implements ? "true" : "flase" ), "])" ); // Loading the class try { m_currentClass = load_class( java_file_name ); } - catch ( ClassNotFoundException cnfe ) + catch ( final ClassNotFoundException cnfe ) { System.out.println( "<!> Class not found exception raised : " + java_file_name ); // TODO: compile when the class can't be found @@ -269,7 +269,7 @@ // *** Check whether we ar running on the impl instead of the interface if ( check_implements && !m_currentClass.isInterface() ) { - Class[] clzs = m_currentClass.getInterfaces(); + final Class[] clzs = m_currentClass.getInterfaces(); Class remclz = null; // *** search for a remote interface for ( int i = 0; i < clzs.length; i++ ) @@ -292,12 +292,11 @@ if ( remclz != null ) { m_currentClass = remclz; - java_file_name = remclz.getName(); } else { System.out.println( "Error: No interface java.rmi.Remote found: " - + m_currentClass ); + + m_currentClass ); return null; } } @@ -314,30 +313,54 @@ * * @exception ClassNotFoundException If no class was found. */ - public Class load_class( String filename ) - throws ClassNotFoundException + public Class load_class( final String filename ) throws ClassNotFoundException { - display( "JavaParser::load_class" ); - Class myLocClass = null; + display( "JavaParser::load_class((String)[", filename, "])" ); try { - myLocClass = m_rcp.getClassloader().loadClass( filename ); + final Class myLocClass = m_rcp.getClassloader().loadClass( filename ); + display( "Class " + filename + " loaded." ); + return myLocClass; } - catch ( ClassNotFoundException cnfe ) + catch ( final ClassNotFoundException cnfe ) { display( "class loader type = " + m_rcp.getClassloader().getClass().getName() ); display( cnfe.toString() ); throw cnfe; } - display( "Class " + filename + " loaded." ); - return myLocClass; } - private void display( String s ) + private void display( final String arg0 ) { if ( m_rcp.getM_verbose() ) { - m_ch.display( s ); + m_ch.display( arg0 ); + } + } + + private void display( final String arg0, final Object arg1, final Object arg2 ) + { + if ( m_rcp.getM_verbose() ) + { + m_ch.display( arg0 + arg1 + arg2 ); + } + } + + private void display( final String arg0, final Object arg1, final Object arg2, + final Object arg3, final Object arg4 ) + { + if ( m_rcp.getM_verbose() ) + { + m_ch.display( arg0 + arg1 + arg2 + arg3 + arg4 ); + } + } + + private void display( final String arg0, final Object arg1, final Object arg2, + final Object arg3, final Object arg4, final Object arg5, final Object arg6 ) + { + if ( m_rcp.getM_verbose() ) + { + m_ch.display( arg0 + arg1 + arg2 + arg3 + arg4 + arg5 + arg6 ); } } @@ -346,11 +369,12 @@ * * @param c The class to parse. */ - public void parse_class( Class c ) + public void parse_class( final Class c ) { - display( "JavaParser::parse_class" ); + display( "JavaParser::parse_class((Class)[", c, "])" ); MappingAPI locMappingAPI = new MappingAPI( m_rcp, m_ch, this ); - IdlObject locIdlObj = null; + + final IdlObject locIdlObj; // *** Map the package *** if ( !c.isInterface() && c.isArray() ) { @@ -364,8 +388,7 @@ // *** Checks the class type (interface or object class) *** if ( c.isInterface() ) { - display( "*** Interface " + c.getName() - + " detected." ); + display( "*** Interface " + c.getName() + " detected." ); locMappingAPI.map_interface( c, locIdlObj ); } else @@ -385,14 +408,13 @@ * @param configurator The configuration class with all the settings. * @param include The vector with included classes. */ - public void load_standard_idl( org.openorb.compiler.orb.Configurator configurator, - Vector include ) + public void load_standard_idl( final Configurator configurator, final List include ) { - m_compilationTreeVector.addElement( add_idl_file( include, configurator, + m_compilationTreeVector.add( add_idl_file( include, configurator, "_std_java.idl" ) ); - m_compilationTreeVector.addElement( add_idl_file( include, configurator, + m_compilationTreeVector.add( add_idl_file( include, configurator, "orb.idl" ) ); - m_compilationTreeVector.addElement( add_idl_file( include, configurator, + m_compilationTreeVector.add( add_idl_file( include, configurator, "_std_javax.idl" ) ); } @@ -402,21 +424,21 @@ * @param vect The vector with idl files to include. * @param include The vector with already compiled classes. */ - public void add_idl_files( Vector vect, Vector include ) + public void add_idl_files( final List vect, final List include ) { - int locSize = vect.size(); + final int locSize = vect.size(); IdlObject compilationGraph = null; - IdlParser idlparser = new IdlParser( m_rcp ); + final IdlParser idlparser = new IdlParser( m_rcp ); for ( int i = 0; i < locSize; i++ ) { - String idl_file_name = ( String ) vect.elementAt( i ); + final String idl_file_name = ( String ) vect.get( i ); display( "adding idl file " + idl_file_name ); try { compilationGraph = idlparser.compile_idl( idl_file_name ); } - catch ( FileNotFoundException e ) + catch ( final FileNotFoundException e ) { System.err.println( "Impossible to add " + idl_file_name + ":" + e.toString() ); } @@ -427,9 +449,10 @@ // Add to the graph compilation tree if ( compilationGraph != null ) { - m_compilationTreeVector.addElement( compilationGraph ); + m_compilationTreeVector.add( compilationGraph ); // Add as an include - MappingAPI m_api = new MappingAPI( m_rcp, m_ch, this ); + final MappingAPI m_api = new MappingAPI( m_rcp, m_ch, this ); + m_api.add_idl_object_as_first( m_idlTreeRoot, new IdlInclude( m_idlTreeRoot, idl_file_name.substring( 0, idl_file_name.lastIndexOf( '.' ) ) ) ); @@ -450,8 +473,8 @@ * @param idl_file_name The file name to include. * @return The tree as a result of parsing the file idl_file_name. */ - public IdlObject add_idl_file( Vector include, - org.openorb.compiler.orb.Configurator configurator, String idl_file_name ) + public IdlObject add_idl_file( final List include, final Configurator configurator, + final String idl_file_name ) { // -- Add RMI IDL Directory -- //String directory = configurator.getProperties().getStringProperty("compiler.idl.rmi", @@ -466,12 +489,12 @@ IdlObject compilationGraph = null; - IdlParser idlparser = new IdlParser( m_rcp ); + final IdlParser idlparser = new IdlParser( m_rcp ); try { compilationGraph = idlparser.compile_idl( idl_file_name ); } - catch ( FileNotFoundException e ) + catch ( final FileNotFoundException e ) { System.err.println( e.toString() ); } Index: MappingAPI.java =================================================================== RCS file: /cvsroot/openorb/OpenORB/src/compiler/org/openorb/compiler/rmi/parser/MappingAPI.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- MappingAPI.java 10 Feb 2004 21:02:41 -0000 1.15 +++ MappingAPI.java 28 Jul 2004 15:18:05 -0000 1.16 @@ -13,8 +13,17 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.Hashtable; -import java.util.Vector; +import java.util.Map; +import java.util.HashMap; +import java.util.List; +import java.util.ArrayList; +import java.util.StringTokenizer; + [...1948 lines suppressed...] - private String process_special_changes( String name ) + private String process_special_changes( final String name ) { if ( name.equals( "java_lang_Class" ) ) { @@ -3483,10 +3642,11 @@ * @param idlObj The parent idl object * @param sub_idlObj The sub idl object to add to the parent */ - public void add_idl_object_as_first( IdlObject idlObj, - IdlObject sub_idlObj ) + public void add_idl_object_as_first( final IdlObject idlObj, + final IdlObject sub_idlObj ) { - display( "MappingAPI::add_idl_object_as_first" ); + display( "MappingAPI::add_idl_object_as_first((IdlObject)[", idlObj, + "], (IdlObject)[", sub_idlObj, "])" ); idlObj._list.insertElementAt( sub_idlObj, 0 ); } } |