org.apache.ws.jaxme.js

Class JavaSourceFactory

public class JavaSourceFactory extends 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 21:48:25Z jochen $

Author: Jochen Wiedmann

Method Summary
JavaSourcegetJavaSource(JavaQName pName)

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

IteratorgetJavaSources()

Returns an iterator to the generated classes.

FilegetLocation(File pBaseDir, String pPackage)

Returns a location the given package, relative to the given base directory.

FilegetLocation(File pBaseDir, JavaSource pJs)

Returns a location for storing the JavaSource class, relative to the given base directory.

FilegetLocation(File pBaseDir, TextFile pTextFile)

Returns a location for storing the TextFile, relative to the given base directory.

LoggergetLogger()

Returns the Logger.

FilegetPackageDirectory(File pBaseDir, String pPackageName)

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

FilegetSourceFile(File pBaseDir, JavaQName pQName)

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

TextFilegetTextFile(String pPackageName, String pFileName)

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

IteratorgetTextFiles()

Returns an iterator to the generated text files.

booleanisOverwriteForced()

By default the JavaSourceFactory will only overwrite existing files, if they have different content.

protected booleanisSameFile(JavaSource pJs, File pFile)

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

protected booleanisSameFile(String pContents, File pFile)

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

protected booleanisSameFile(String pContents1, String pContents2)

Verifies whether the given strings are identical.

booleanisSettingReadOnly()

Returns whether the generated files are created in read-only mode.

JavaSourcenewJavaSource(JavaQName pName)

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

JavaSourcenewJavaSource(JavaQName pName, JavaSource.Protection pProtection)

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

JavaSourcenewJavaSource(JavaQName pName, String pProtection)

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

TextFilenewTextFile(String pPackageName, String pFileName)

Creates a new text file.

voidsetLogger(Logger pLogger)

Sets the Logger to use.

voidsetOverwriteForced(boolean pOverwriteForced)

By default the JavaSourceFactory will only overwrite existing files only, if they have different content.

voidsetSettingReadOnly(boolean pSettingReadOnly)

Sets whether the generated files are created in read-only mode.

voidwrite(File pBaseDir, JavaSource pJs)

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

voidwrite(File pBaseDir, TextFile pFile)

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

voidwrite(File pBaseDir)
Writes all Source files to the FileSystem, relative to the given base directory.
voidwrite(File pJavaSourceDir, File pResourceDir)
Writes all Source files to the file system, relative to the respective base directory.
protected voidwriteFile(File pFile, JavaSource pJs)

Actually creates a file with the given name.

protected voidwriteFile(File pFile, String pContents)

Actually creates a file with the given name.

Method Detail

getJavaSource

public JavaSource getJavaSource(JavaQName pName)

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

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.

See Also: JavaSourceFactory

isSameFile

protected boolean isSameFile(JavaSource pJs, File pFile)

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

isSameFile

protected boolean isSameFile(String pContents, File pFile)

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.

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, JavaSource.Protection pProtection)

Creates a new instance of JavaSource with the given name and 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)).

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.

See Also: isOverwriteForced

setSettingReadOnly

public void setSettingReadOnly(boolean pSettingReadOnly)

Sets whether the generated files are created in read-only mode.

write

public void write(File pBaseDir, JavaSource pJs)

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.

See Also: write

write

public void write(File pBaseDir, TextFile pFile)

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.

See Also: write

write

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

writeFile

protected void writeFile(File pFile, JavaSource pJs)

Actually creates a file with the given name.

writeFile

protected void writeFile(File pFile, String pContents)

Actually creates a file with the given name.