net.sf.jaxme.js
Class JavaSourceFactory

java.lang.Object
  extended bynet.sf.jaxme.js.JavaSourceFactory

public class JavaSourceFactory
extends java.lang.Object

Factory for generating JavaSource objects.

Version:
$Id: JavaSourceFactory.java,v 1.1 2003/05/27 03:17:14 joe Exp $
Author:
Jochen Wiedmann

Constructor Summary
JavaSourceFactory()
           
 
Method Summary
 JavaSource getJavaSource(JavaQName pName)
          Returns the generated class with the given name or null, if no such class has been generated.
 java.util.Iterator getJavaSources()
          Returns an iterator to the generated classes.
 java.io.File getLocation(java.io.File pBaseDir, JavaSource pJs)
          Returns a location for storing the JavaSource class, relative to the given base directory.
 java.io.File getLocation(java.io.File pBaseDir, java.lang.String pPackage)
          Returns a location the given package, relative to the given base directory.
 Logger getLogger()
          Returns the Logger.
 java.io.File getPackageDirectory(java.io.File pBaseDir, java.lang.String pPackageName)
          Given a package name and a base directory, returns the package directory.
 java.io.File getSourceFile(java.io.File pBaseDir, JavaQName pQName)
          Given a fully qualified name, returns the name of the corresponding Java file.
 TextFile getTextFile(java.lang.String pPackageName, java.lang.String pFileName)
          Returns the text file with the given name or null, if no such text file has been generated.
 java.util.Iterator getTextFiles()
          Returns an iterator to the generated text files.
 boolean isOverwriteForced()
          By default the JavaSourceFactory will only overwrite existing files, if they have different content.
protected  boolean isSameFile(JavaSource pJs, java.io.File pFile)
          Verifies whether the given Java source and the contents of the given file are identical.
protected  boolean isSameFile(java.lang.String pContents, java.io.File pFile)
          Verifies whether the given string and the contents of the given file are identical.
protected  boolean isSameFile(java.lang.String pContents1, java.lang.String pContents2)
          Verifies whether the given strings are identical.
 JavaSource newJavaSource(JavaQName pName)
          Creates a new instance of JavaSource with the given name and default protection.
 JavaSource newJavaSource(JavaQName pName, JavaSource.Protection pProtection)
          Creates a new instance of JavaSource with the given name and protection.
 JavaSource newJavaSource(JavaQName pName, java.lang.String pProtection)
          Creates a new instance of JavaSource with the given name and protection.
 TextFile newTextFile(java.lang.String pPackageName, java.lang.String pFileName)
          Creates a new text file.
 void setLogger(Logger pLogger)
          Sets the Logger to use.
 void setOverwriteForced(boolean pOverwriteForced)
          By default the JavaSourceFactory will only overwrite existing files, if they have different content.
 void write(java.io.File pBaseDir)
          Writes all JavaSource classes to the FileSystem, relative to the given base directory.
 void write(java.io.File pBaseDir, JavaSource pJs)
          Writes the given JavaSource class to the file system, relative to the given base directory.
 void write(java.io.File pBaseDir, TextFile pFile)
          Writes the given text file to the file system, relative to the given base directory.
protected  void writeFile(java.io.File pFile, JavaSource pJs)
          Actually creates a file with the given name.
protected  void writeFile(java.io.File pFile, java.lang.String pContents)
          Actually creates a file with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaSourceFactory

public JavaSourceFactory()
Method Detail

setLogger

public void setLogger(Logger pLogger)

Sets the Logger to use.


getLogger

public Logger getLogger()

Returns the Logger.


setOverwriteForced

public void setOverwriteForced(boolean pOverwriteForced)

By default the JavaSourceFactory will only overwrite existing files, if they have different content. If the overwriteForced property is set to true, existing files will always be overwritten.

See Also:
isOverwriteForced()

isOverwriteForced

public boolean isOverwriteForced()

By default the JavaSourceFactory will only overwrite existing files, if they have different content. If the overwriteForced property is set to true, existing files will always be overwritten.

See Also:
setOverwriteForced(boolean)

newJavaSource

public JavaSource newJavaSource(JavaQName pName)

Creates a new instance of JavaSource with the given name and default protection.


newJavaSource

public JavaSource newJavaSource(JavaQName pName,
                                JavaSource.Protection pProtection)

Creates a new instance of JavaSource with the given name and protection.


newJavaSource

public JavaSource newJavaSource(JavaQName pName,
                                java.lang.String pProtection)

Creates a new instance of JavaSource with the given name and protection. Shortcut for newJavaSource(pName, JavaSource.Protection.valueOf(pProtection)).


getJavaSources

public java.util.Iterator getJavaSources()

Returns an iterator to the generated classes.


getTextFiles

public java.util.Iterator getTextFiles()

Returns an iterator to the generated text files.


getJavaSource

public JavaSource getJavaSource(JavaQName pName)

Returns the generated class with the given name or null, if no such class has been generated.


getTextFile

public TextFile getTextFile(java.lang.String pPackageName,
                            java.lang.String pFileName)

Returns the text file with the given name or null, if no such text file has been generated.


getPackageDirectory

public java.io.File getPackageDirectory(java.io.File pBaseDir,
                                        java.lang.String pPackageName)

Given a package name and a base directory, returns the package directory.

Parameters:
pBaseDir - The base directory, where to create sources; may be null (current directory).
Returns:
Package directory; null is a valid value and indicates the current directory.

getSourceFile

public java.io.File getSourceFile(java.io.File pBaseDir,
                                  JavaQName pQName)

Given a fully qualified name, returns the name of the corresponding Java file.


getLocation

public java.io.File getLocation(java.io.File pBaseDir,
                                java.lang.String pPackage)

Returns a location the given package, relative to the given base directory. For example, if you have the base directory c:\temp and the package com.mycompany.demo, this would yield new File("c:\temp\com\mycompany\demo").

Parameters:
pBaseDir - The base directory or null for the current directory.
pPackage - The JavaSource being stored; null or the empty string for the root package
Returns:
Directory related to the package; this may be null, if the base directory was null and the package was the root package

getLocation

public java.io.File getLocation(java.io.File pBaseDir,
                                JavaSource pJs)

Returns a location for storing the JavaSource class, relative to the given base directory. For example, if you have the base directory c:\temp and the class Sample in package com.mycompany.demo, this would yield new File("c:\temp\com\mycompany\demo\Sample.java").

Parameters:
pBaseDir - The base directory or null for the current directory.
pJs - The JavaSource being stored.

isSameFile

protected boolean isSameFile(JavaSource pJs,
                             java.io.File pFile)
                      throws java.io.IOException

Verifies whether the given Java source and the contents of the given file are identical.

Throws:
java.io.IOException

isSameFile

protected boolean isSameFile(java.lang.String pContents,
                             java.io.File pFile)
                      throws java.io.IOException

Verifies whether the given string and the contents of the given file are identical.

Throws:
java.io.IOException

isSameFile

protected boolean isSameFile(java.lang.String pContents1,
                             java.lang.String pContents2)

Verifies whether the given strings are identical.


writeFile

protected void writeFile(java.io.File pFile,
                         JavaSource pJs)
                  throws java.io.IOException

Actually creates a file with the given name.

Throws:
java.io.IOException

writeFile

protected void writeFile(java.io.File pFile,
                         java.lang.String pContents)
                  throws java.io.IOException

Actually creates a file with the given name.

Throws:
java.io.IOException

write

public void write(java.io.File pBaseDir,
                  JavaSource pJs)
           throws java.io.IOException

Writes the given JavaSource class to the file system, relative to the given base directory.

Parameters:
pBaseDir - The base directory or null for the current directory.
pJs - The JavaSource being stored.
Throws:
java.io.IOException
See Also:
JavaSource.write(Writer)

write

public void write(java.io.File pBaseDir,
                  TextFile pFile)
           throws java.io.IOException

Writes the given text file to the file system, relative to the given base directory.

Parameters:
pBaseDir - The base directory or null for the current directory.
pFile - The text file being stored.
Throws:
java.io.IOException
See Also:
JavaSource.write(Writer)

write

public void write(java.io.File pBaseDir)
           throws java.io.IOException

Writes all JavaSource classes to the FileSystem, relative to the given base directory.

Parameters:
pBaseDir - The base directory or null for the current directory.
Throws:
java.io.IOException

newTextFile

public TextFile newTextFile(java.lang.String pPackageName,
                            java.lang.String pFileName)

Creates a new text file.