de.ispsoft.jaxme.generator
Class SourceWriterImpl

java.lang.Object
  extended byde.ispsoft.jaxme.generator.ConfigurableImpl
      extended byde.ispsoft.jaxme.generator.SourceWriterImpl
All Implemented Interfaces:
Configurable, SourceWriter
Direct Known Subclasses:
BeanWriter, ComparatorWriter, DebugWriter, JavaSourceWriter, ParseletWriter, SampleWriter, VisitorWriter, XsdSchemaWriter

public abstract class SourceWriterImpl
extends ConfigurableImpl
implements SourceWriter

A base class for implementing SourceWriters.

Author:
Jochen Wiedmann

Field Summary
protected  java.io.File directory
           
protected  Generator generator
           
protected  java.lang.String javaPackage
           
 
Constructor Summary
SourceWriterImpl()
          Creates a new instance of SourceWriterImpl.
 
Method Summary
 java.io.File getDirectory()
          Returns the directory where the SourceWriter will generate files.
 Generator getGenerator()
          Returns the generator.
 java.lang.String getJavaPackage()
          Sets the default Java package for generated sources.
 java.lang.String getOption(SchemaElement pElement, java.lang.String pName)
          Returns a value for an option.
 java.util.Date getSchemaDate()
          Returns the time and date when the schema was created.
 JavaSource newJavaSource(SchemaComplexElement pElement, java.lang.String pPackage, java.lang.String pClass, java.lang.String pProtection)
          Creates a new JavaSource object.
 void setDirectory(java.io.File pDirectory)
          Sets the directory where the SourceWriter will generate files.
 void setGenerator(Generator g)
          Sets the generator.
 void setJavaPackage(java.lang.String pPackage)
          Sets the default Java package for generated sources.
 void setSchemaDate(java.util.Date pDate)
          Sets the time and date when the schema was created, May be null, if unknown.
 void write(Schema pSchema)
          Called for writing a complete schema.
abstract  void write(SchemaElement pElement)
          Called for writing a single schema element.
 void writeFile(java.io.File pDir, java.lang.String pFileName, java.lang.String pContents)
          Writes a text file.
 void writeJavaSourceFile(java.io.File pDir, JavaSource pJs)
          Writes a JavaSource file.
 
Methods inherited from class de.ispsoft.jaxme.generator.ConfigurableImpl
getOption, getOptions, getOptionValue, setOption
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.ispsoft.jaxme.generator.Configurable
getOption, getOptions, getOptionValue, setOption
 

Field Detail

directory

protected java.io.File directory

javaPackage

protected java.lang.String javaPackage

generator

protected Generator generator
Constructor Detail

SourceWriterImpl

public SourceWriterImpl()
Creates a new instance of SourceWriterImpl.

Method Detail

write

public void write(Schema pSchema)
           throws java.lang.Exception

Called for writing a complete schema.

Specified by:
write in interface SourceWriter
Throws:
java.lang.Exception

write

public abstract void write(SchemaElement pElement)
                    throws java.lang.Exception

Called for writing a single schema element. Concrete subclasses must implement this method.

Specified by:
write in interface SourceWriter
Throws:
java.lang.Exception

getDirectory

public java.io.File getDirectory()

Returns the directory where the SourceWriter will generate files. The actual generation may happen in subdirectories, for example in the case of the JavaGenerator the package structure will be considered.

Specified by:
getDirectory in interface SourceWriter
Returns:
A java.io.File instance matching a directory; unlike the interface specification this will never be null.
See Also:
setDirectory(java.io.File)

setDirectory

public void setDirectory(java.io.File pDirectory)

Sets the directory where the SourceWriter will generate files. The actual generation may happen in subdirectories, for example in the case of the JavaGenerator the package structure will be considered.

Specified by:
setDirectory in interface SourceWriter
Parameters:
pDirectory - The target directory or null (current directory, default)
See Also:
getDirectory()

setJavaPackage

public void setJavaPackage(java.lang.String pPackage)
                    throws java.lang.Exception

Sets the default Java package for generated sources. Probably useful for the JavaSourceWriter only.

Specified by:
setJavaPackage in interface SourceWriter
Throws:
java.lang.Exception

getJavaPackage

public java.lang.String getJavaPackage()
                                throws java.lang.Exception

Sets the default Java package for generated sources. Probably useful for the JavaSourceWriter only.

Specified by:
getJavaPackage in interface SourceWriter
Throws:
java.lang.Exception

getOption

public java.lang.String getOption(SchemaElement pElement,
                                  java.lang.String pName)

Returns a value for an option.


newJavaSource

public JavaSource newJavaSource(SchemaComplexElement pElement,
                                java.lang.String pPackage,
                                java.lang.String pClass,
                                java.lang.String pProtection)

Creates a new JavaSource object.


setSchemaDate

public void setSchemaDate(java.util.Date pDate)

Sets the time and date when the schema was created, May be null, if unknown.

Specified by:
setSchemaDate in interface SourceWriter

getSchemaDate

public java.util.Date getSchemaDate()

Returns the time and date when the schema was created. May be null, if unknown.


setGenerator

public void setGenerator(Generator g)

Sets the generator.


getGenerator

public Generator getGenerator()

Returns the generator.


writeFile

public void writeFile(java.io.File pDir,
                      java.lang.String pFileName,
                      java.lang.String pContents)
               throws java.io.IOException

Writes a text file.

Throws:
java.io.IOException

writeJavaSourceFile

public void writeJavaSourceFile(java.io.File pDir,
                                JavaSource pJs)
                         throws java.io.IOException

Writes a JavaSource file.

Throws:
java.io.IOException