org.apache.ws.jaxme.js

Class JavaSourceFactory

Implemented Interfaces:
JavaSourceResolver

public class JavaSourceFactory
extends java.lang.Object
implements JavaSourceResolver

Factory for generating JavaSource objects.

The factory properties:

are used for finely grained controlled over the generated source files. Methods are provided to access abstract descriptions of the files to be created:

Concrete files (source and otherwise) are created by calling the following construction methods:

Version:
$Id: JavaSourceFactory.java 358952 2005-12-24 22:48:25 +0100 (Sat, 24 Dec 2005) jochen $
Author:
Jochen Wiedmann

Method Summary

JavaSource
getJavaSource(JavaQName pName)
Returns the generated class with the given name or null, if no such class has been generated.
Iterator
getJavaSources()
Returns an iterator to the generated classes.
File
getLocation(File pBaseDir, String pPackage)
Returns a location the given package, relative to the given base directory.
File
getLocation(File pBaseDir, JavaSource pJs)
Returns a location for storing the JavaSource class, relative to the given base directory.
File
getLocation(File pBaseDir, TextFile pTextFile)
Returns a location for storing the TextFile, relative to the given base directory.
Logger
getLogger()
Returns the Logger.
File
getPackageDirectory(File pBaseDir, String pPackageName)
Given a package name and a base directory, returns the package directory.
File
getSourceFile(File pBaseDir, JavaQName pQName)
Given a fully qualified name, returns the name of the corresponding Java file.
TextFile
getTextFile(String pPackageName, String pFileName)
Returns the text file with the given name or null, if no such text file has been generated.
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(String pContents, File pFile)
Verifies whether the given string and the contents of the given file are identical.
protected boolean
isSameFile(String pContents1, String pContents2)
Verifies whether the given strings are identical.
protected boolean
isSameFile(JavaSource pJs, File pFile)
Verifies whether the given Java source and the contents of the given file are identical.
boolean
isSettingReadOnly()
Returns whether the generated files are created in read-only mode.
JavaSource
newJavaSource(JavaQName pName)
Creates a new instance of JavaSource with the given name and default protection.
JavaSource
newJavaSource(JavaQName pName, String pProtection)
Creates a new instance of JavaSource with the given name and protection.
JavaSource
newJavaSource(JavaQName pName, JavaSource.Protection pProtection)
Creates a new instance of JavaSource with the given name and protection.
TextFile
newTextFile(String pPackageName, 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 only, if they have different content.
void
setSettingReadOnly(boolean pSettingReadOnly)
Sets whether the generated files are created in read-only mode.
void
write(File pBaseDir)
Writes all Source files to the FileSystem, relative to the given base directory.
void
write(File pJavaSourceDir, File pResourceDir)
Writes all Source files to the file system, relative to the respective base directory.
void
write(File pBaseDir, JavaSource pJs)
Writes the given JavaSource class to the file system, relative to the given base directory.
void
write(File pBaseDir, TextFile pFile)
Writes the given text file to the file system, relative to the given base directory.
protected void
writeFile(File pFile, String pContents)
Actually creates a file with the given name.
protected void
writeFile(File pFile, JavaSource pJs)
Actually creates a file with the given name.

Method Details

getJavaSource

public JavaSource getJavaSource(JavaQName pName)
Returns the generated class with the given name or null, if no such class has been generated.
Specified by:
getJavaSource in interface JavaSourceResolver

getJavaSources

public Iterator getJavaSources()
Returns an iterator to the generated classes.

getLocation

public File getLocation(File pBaseDir,
                        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 File getLocation(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.

getLocation

public File getLocation(File pBaseDir,
                        TextFile pTextFile)
Returns a location for storing the TextFile, 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.
pTextFile - The text file being created.

getLogger

public Logger getLogger()
Returns the Logger.

getPackageDirectory

public File getPackageDirectory(File pBaseDir,
                                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 File getSourceFile(File pBaseDir,
                          JavaQName pQName)
Given a fully qualified name, returns the name of the corresponding Java file.

getTextFile

public TextFile getTextFile(String pPackageName,
                            String pFileName)
Returns the text file with the given name or null, if no such text file has been generated.

getTextFiles

public Iterator getTextFiles()
Returns an iterator to the generated text files.

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.

isSameFile

protected boolean isSameFile(String pContents,
                             File pFile)
            throws IOException
Verifies whether the given string and the contents of the given file are identical.

isSameFile

protected boolean isSameFile(String pContents1,
                             String pContents2)
Verifies whether the given strings are identical.

isSameFile

protected boolean isSameFile(JavaSource pJs,
                             File pFile)
            throws IOException
Verifies whether the given Java source and the contents of the given file are identical.

isSettingReadOnly

public boolean isSettingReadOnly()
Returns whether the generated files are created in read-only mode.

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,
                                String pProtection)
Creates a new instance of JavaSource with the given name and protection. Shortcut for newJavaSource(pName, JavaSource.Protection.valueOf(pProtection)).

newJavaSource

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

newTextFile

public TextFile newTextFile(String pPackageName,
                            String pFileName)
Creates a new text file.

setLogger

public void setLogger(Logger pLogger)
Sets the Logger to use.

setOverwriteForced

public void setOverwriteForced(boolean pOverwriteForced)
By default the JavaSourceFactory will only overwrite existing files only, if they have different content. If the overwriteForced property is set to true, existing files will always be overwritten.

setSettingReadOnly

public void setSettingReadOnly(boolean pSettingReadOnly)
Sets whether the generated files are created in read-only mode.

write

public void write(File pBaseDir)
            throws IOException
Writes all Source files to the FileSystem, relative to the given base directory.
Parameters:
pBaseDir - The base directory or null for the current directory.

write

public void write(File pJavaSourceDir,
                  File pResourceDir)
            throws IOException
Writes all Source files to the file system, relative to the respective base directory.
Parameters:
pJavaSourceDir - The base directory for Java source files.
pResourceDir - The base directory for resource files.

write

public void write(File pBaseDir,
                  JavaSource pJs)
            throws 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.

write

public void write(File pBaseDir,
                  TextFile pFile)
            throws 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.

writeFile

protected void writeFile(File pFile,
                         String pContents)
            throws IOException
Actually creates a file with the given name.

writeFile

protected void writeFile(File pFile,
                         JavaSource pJs)
            throws IOException
Actually creates a file with the given name.