net.sourceforge.sql2java
Class UserCodeParser

java.lang.Object
  extended by net.sourceforge.sql2java.UserCodeParser

public class UserCodeParser
extends java.lang.Object

Parses an existing source file for special sql2code comment blocks.
Stores the source code that it finds in between those blocks in a hashtable. This allows CodeWriter classes to rewrite existing files while preserving code written by the user.

Version:
$Id: UserCodeParser.java,v 1.3 2007/07/13 13:18:29 kameleono Exp $
Author:
James Cooper

Constructor Summary
UserCodeParser(java.lang.String filename)
          Constructs a new parser, and tells the parser to try to load the given filename.
 
Method Summary
 java.lang.String getBlock(java.lang.String name)
          Returns the comment+code block associated with this name.
 java.lang.String[] getBlockNames()
          Returns an array of the block names parsed in the existing file.
 java.lang.String getFilename()
          Returns the filename associated with this parser.
 boolean hasBlock(java.lang.String name)
          Returns true if there is a block with the given name in the existing file that was parsed, otherwise returns false.
 boolean isNew()
          Returns true if the file to parse did not exist.
 void parse(java.lang.String parsedFileName)
          Parses the file passed in.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserCodeParser

public UserCodeParser(java.lang.String filename)
               throws java.lang.Exception
Constructs a new parser, and tells the parser to try to load the given filename.
If the file does not exist, the parser will simply initialize a new hashtable internally, and the get methods on the parser will return new comment blocks (with nothing in between them).

Parameters:
filename - Full path to the existing file to parse.
Throws:
java.lang.Exception - if the existing file exists, but cannot be read, or if there is an error while reading the file
Method Detail

getFilename

public java.lang.String getFilename()
Returns the filename associated with this parser.


isNew

public boolean isNew()
Returns true if the file to parse did not exist.


parse

public void parse(java.lang.String parsedFileName)
           throws java.lang.Exception
Parses the file passed in.

Throws:
java.lang.Exception

hasBlock

public boolean hasBlock(java.lang.String name)
Returns true if there is a block with the given name in the existing file that was parsed, otherwise returns false.

Parameters:
name - Name of the code block to check for.

getBlock

public java.lang.String getBlock(java.lang.String name)
Returns the comment+code block associated with this name.
If the name is not found in the parsed file, this returns a new comment block with no code inside it.

Parameters:
name - Name of the code block to return.

getBlockNames

public java.lang.String[] getBlockNames()
Returns an array of the block names parsed in the existing file.
If the file did not exist, or if there are no blocks in the file, a zero length array is returned.



Copyright © 2002-2007 . All Rights Reserved.