org.apache.ws.jaxme.js

Class JavaSource

public class JavaSource extends IndentationEngineImpl

A class representing a Java source file.
Nested Class Summary
static classJavaSource.Protection
Specifies a java objects protection (default, public, protected, or private).
static classJavaSource.Type
Specifies the type of a java class (interface, or class).
Field Summary
static JavaSource.TypeCLASS
Type of a JavaSource class.
static JavaSource.ProtectionDEFAULT_PROTECTION
Default protection of a class, field or method
static JavaSource.TypeINTERFACE
Type of a JavaSource interface.
static JavaSource.ProtectionPRIVATE
Protection of a class, field or method: private
static JavaSource.ProtectionPROTECTED
Protection of a class, field or method: protected
static JavaSource.ProtectionPUBLIC
Protection of a class, field or method: public
Method Summary
voidaddExtends(JavaQName pExtends)
Sets the class or interface extended by this class or interface.
voidaddExtends(Class pExtends)
Sets the class or interface extended by this class or interface.
voidaddImplements(JavaQName s)
Adds an interface to the list of interfaces being implemented by this class or interface.
voidaddImplements(Class s)
Adds an interface to the list of interfaces being implemented by this class or interface.
voidaddImport(JavaQName s)
Adds a package or class to the list of packages and classes being imported.
voidaddImport(Class s)
Adds a package or class to the list of packages and classes being imported.
voidaddInnerClass(JavaInnerClass pClass)
Adds an inner class.
voidaddRawJavaSource(String pSource)
Adds a piece of raw Java source to the class.
StringasString(JavaQName pQName, boolean pAddIfPossible)
Returns whether the given JavaQName is a local class.
voidclearExtends()
Clears the list of extended classes or interfaces.
voidclearImplements()
Clears the list of implemented interfaces.
voidclearImports()
Clears the list of imports.
voidclearInnerClasses()
Clears the list of inner classes.
voidclearRawJavaSources()
Clears the list of raw Java sources.
JavaClassInitializer[]getClassInitializers()
Returns the static class initializers.
StringgetClassName()
Returns the class or interface name.
JavaCommentgetComment()
Returns the comment describing this class or interface.
JavaConstructorgetConstructor(JavaQName[] pParams)
Returns the constructor with the given signature or null, if there is no such constructor.
IteratorgetConstructorIterator()
Returns an iterator the the classes constructors.
JavaConstructor[]getConstructors()
Returns the list of constructors that this class has.
JavaQName[]getExtends()
Returns the class or interface extended by this class or interface.
JavaSourceFactorygetFactory()
Returns the {@link JavaSourceFactory} that created this instance of JavaSource.
JavaFieldgetField(String pName)
Returns the field with the given name or null, if no such field exists.
JavaField[]getFields()
Returns the list of fields that this class has.
JavaQName[]getImplements()
Returns the list of interfaces being implented by this class or interface.
JavaQName[]getImports()
Returns the list of packages and classes being imported.
JavaInnerClassgetInnerClass(String pName)
Returns the inner class named pName, or null, if no such class exists.
JavaInnerClass[]getInnerClasses()
Returns the array of inner classes.
JavaMethodgetMethod(String pMethodName, JavaQName[] pParams)
Returns the method with the given signature or null, if there is no such method.
IteratorgetMethodIterator()
Returns an iterator to the classes methods.
JavaMethod[]getMethods()
Returns the list of methods that this class has.
StringgetPackageName()
Returns the package name.
JavaSource.ProtectiongetProtection()
Returns the protection.
JavaQNamegetQName()
Returns the JavaSource's JavaQName.
static StringgetQuoted(String s)
Returns a quoted string constant suitable for embedding into Java source.
static StringgetQuotedNoQuotes(String s)
Returns a quoted string constant suitable for embedding into Java source, but without quotes.
String[]getRawJavaSources()
Returns an array with the pieces of raw Java sources.
protected booleangetStatic()
Returns whether this JavaSource is static (for inner classes).
JavaSource.TypegetType()
Returns the JavaSource type.
booleanhasDynamicImports()
Returns, whether the class is automatically adding imports.
booleanisAbstract()
Returns whether class is abstract.
booleanisExtending(JavaQName pClass)
Returns whether the class is extending the given super class or interface.
booleanisExtending(Class pClass)
Returns whether the class is extending the given super class or interface.
booleanisForcingFullyQualifiedName()
Returns, whether class references are always using the fully qualified class name.
booleanisImplementing(JavaQName pClass)
Returns whether the class is implementing the given interface.
booleanisImplementing(Class pClass)
Returns whether the class is implementing the given interface.
booleanisInnerClass()
Returns, whether this is an inner class.
booleanisInterface()
Returns whether this is an interface or not.
voidnewBeanProperty(JavaQName pType, String pName)
Creates a new Java property with the given type and name.
voidnewBeanProperty(Class pClass, String pName)
Shortcut for newBeanProperty(JavaQNameImpl.getInstance(pClass), pName).
voidnewBeanProperty(JavaQName pType, String pFieldName, String pGetMethodName, String pSetMethodName)
Shortcut for
 newJavaField(pFieldName, pType, JavaSource.PRIVATE);
 JavaMethod getMethod = newJavaMethod(pGetMethodName, pType, JavaSource.PUBLIC);
 getMethod.addLine("return this.", pFieldName, ";");
 JavaMethod setMethod = newJavaMethod(pSetMethodName, JavaQNameImpl.VOID, JavaSource.PUBLIC);
 setMethod.addParam(pType, pFieldName);
 setMethod.addLine("this.", pFieldName, " = ", pFieldName, ";");
 
voidnewBeanProperty(Class pClass, String pFieldName, String pGetMethodName, String pSetMethodName)
Shortcut for newBeanProperty(JavaQNameImpl.getInstance(pClass), pFieldName, pGetMethodName, pSetMethodName).
JavaCommentnewComment()
Creates a new Javadoc comment describing this class or interface.
JavaClassInitializernewJavaClassInitializer()
Creates a new instance of JavaClassInitializer.
JavaConstructornewJavaConstructor()
Creates a new JavaConstructor with default protection.
JavaConstructornewJavaConstructor(JavaSource.Protection pProtection)
Creates a new JavaConstructor with the given protection.
JavaConstructornewJavaConstructor(String pProtection)
Creates a new JavaConstructor with the given protection.
JavaConstructornewJavaConstructor(JavaConstructor pConstructor)
Creates a new JavaConstructor with the same parameters, protection and exceptions than the given.
JavaConstructornewJavaConstructor(JavaConstructor pConstructor, boolean pSuper)
Creates a new JavaConstructor with the same signature than the given constructors.
JavaConstructornewJavaConstructor(Constructor pConstructor)
Creates a new JavaConstructor with the signature of the given constructor.
JavaFieldnewJavaField(Field pField)
Creates a new JavaField with the given fields signature.
JavaFieldnewJavaField(String pName, JavaQName pType, JavaSource.Protection pProtection)
Creates a new JavaField with the given name, type and protection.
JavaFieldnewJavaField(String pName, JavaQName pType, String pProtection)
Creates a new JavaField with the given name, type and protection.
JavaFieldnewJavaField(String pName, JavaQName pType)
Creates a new JavaField with the given name, type and default protection.
JavaFieldnewJavaField(String pName, String pType, JavaSource.Protection pProtection)
Creates a new JavaField with the given name, type and protection.
JavaFieldnewJavaField(String pName, String pType, String pProtection)
Creates a new JavaField with the given name, type and protection.
JavaFieldnewJavaField(String pName, String pType)
Creates a new JavaField with the given name, type and default protection.
JavaFieldnewJavaField(String pName, Class pType, JavaSource.Protection pProtection)
Creates a new JavaField with the given name, type and protection.
JavaFieldnewJavaField(String pName, Class pType, String pProtection)
Creates a new JavaField with the given name, type and protection.
JavaFieldnewJavaField(String pName, Class pType)
Creates a new JavaField with the given name, type and default protection.
JavaInnerClassnewJavaInnerClass(String pName)
Creates a new JavaInnerClass with the given name and default protection.
JavaInnerClassnewJavaInnerClass(String pName, JavaSource.Protection pProtection)
Creates a new JavaInnerClass with the given name and protection.
JavaInnerClassnewJavaInnerClass(String pName, String pProtection)
Creates a new JavaInnerClass with the given name and protection.
JavaMethodnewJavaMethod(String pName, String pType)
Creates a new JavaMethod with the given name, return type and default protection.
JavaMethodnewJavaMethod(String pName, String pType, JavaSource.Protection pProtection)
Creates a new JavaMethod with the given name, return type and protection.
JavaMethodnewJavaMethod(String pName, String pType, String pProtection)
Creates a new JavaMethod with the given name, return type and protection.
JavaMethodnewJavaMethod(String pName, JavaQName pType)
Creates a new JavaMethod with the given name, return type and default protection.
JavaMethodnewJavaMethod(String pName, JavaQName pType, JavaSource.Protection pProtection)
Creates a new JavaMethod with the given name, return type and protection.
JavaMethodnewJavaMethod(String pName, JavaQName pType, String pProtection)
Creates a new JavaMethod with the given name, return type and protection.
JavaMethodnewJavaMethod(String pName, Class pType)
Creates a new JavaMethod with the given name, return type and default protection.
JavaMethodnewJavaMethod(String pName, Class pType, JavaSource.Protection pProtection)
Creates a new JavaMethod with the given name, return type and protection.
JavaMethodnewJavaMethod(String pName, Class pType, String pProtection)
Creates a new JavaMethod with the given name, return type and protection.
JavaMethodnewJavaMethod(Method pMethod)
Creates a new JavaMethod with the signature of the given method pMethod.
JavaMethodnewJavaMethod(JavaMethod pMethod)
Creates a new JavaMethod with the given methods name and signature.
voidsetAbstract(boolean isAbstract)
Sets whether this class is abstract.
voidsetDynamicImports(boolean pDynamicImports)
Sets, whether the class is automatically adding imports.
voidsetForcingFullyQualifiedName(boolean pForcingFullyQualifiedName)
Sets, whether class references are always using the fully qualified class name.
voidsetProtection(JavaSource.Protection protection)
Sets the protection; use null for default protection.
voidsetQName(JavaQName pQName)
Sets the JavaSource's JavaQName.
voidsetStatic(boolean pStatic)
Sets whether this JavaSource is static (for inner classes).
voidsetType(JavaSource.Type pType)
Sets the JavaSource type.
StringtoString()
Returns a string representation of this JavaSource file.
voidwrite(IndentationTarget pTarget)
voidwrite(Writer pTarget)
Writes the JavaSource contents into the given Writer.

Field Detail

CLASS

public static final JavaSource.Type CLASS
Type of a JavaSource class.

See Also: INTERFACE JavaSource JavaSource

DEFAULT_PROTECTION

public static final JavaSource.Protection DEFAULT_PROTECTION
Default protection of a class, field or method

INTERFACE

public static final JavaSource.Type INTERFACE
Type of a JavaSource interface.

See Also: CLASS JavaSource JavaSource

PRIVATE

public static final JavaSource.Protection PRIVATE
Protection of a class, field or method: private

PROTECTED

public static final JavaSource.Protection PROTECTED
Protection of a class, field or method: protected

PUBLIC

public static final JavaSource.Protection PUBLIC
Protection of a class, field or method: public

Method Detail

addExtends

public void addExtends(JavaQName pExtends)
Sets the class or interface extended by this class or interface. Null or the empty string disable the "extends" clause.

See Also: JavaSource

addExtends

public void addExtends(Class pExtends)
Sets the class or interface extended by this class or interface. Null or the empty string disable the "extends" clause.

See Also: JavaSource

addImplements

public void addImplements(JavaQName s)
Adds an interface to the list of interfaces being implemented by this class or interface.

See Also: getImplements

addImplements

public void addImplements(Class s)
Adds an interface to the list of interfaces being implemented by this class or interface.

See Also: getImplements

addImport

public void addImport(JavaQName s)
Adds a package or class to the list of packages and classes being imported.

See Also: getImports

addImport

public void addImport(Class s)
Adds a package or class to the list of packages and classes being imported.

See Also: addImport

addInnerClass

public void addInnerClass(JavaInnerClass pClass)
Adds an inner class.

addRawJavaSource

public void addRawJavaSource(String pSource)
Adds a piece of raw Java source to the class.

asString

public String asString(JavaQName pQName, boolean pAddIfPossible)
Returns whether the given JavaQName is a local class. In other words, whether the package name can be omitted when referencing the class.

clearExtends

public void clearExtends()
Clears the list of extended classes or interfaces.

clearImplements

public void clearImplements()
Clears the list of implemented interfaces.

clearImports

public void clearImports()
Clears the list of imports.

clearInnerClasses

public void clearInnerClasses()
Clears the list of inner classes.

clearRawJavaSources

public void clearRawJavaSources()
Clears the list of raw Java sources.

getClassInitializers

public JavaClassInitializer[] getClassInitializers()
Returns the static class initializers.

getClassName

public String getClassName()
Returns the class or interface name.

See Also: JavaSource

getComment

public JavaComment getComment()
Returns the comment describing this class or interface.

See Also: JavaSource

getConstructor

public JavaConstructor getConstructor(JavaQName[] pParams)
Returns the constructor with the given signature or null, if there is no such constructor.

getConstructorIterator

public Iterator getConstructorIterator()
Returns an iterator the the classes constructors. This iterator allows to remove constructors.

getConstructors

public JavaConstructor[] getConstructors()
Returns the list of constructors that this class has.

See Also: JavaSource

getExtends

public JavaQName[] getExtends()
Returns the class or interface extended by this class or interface.

See Also: addExtends

getFactory

public JavaSourceFactory getFactory()
Returns the {@link JavaSourceFactory} that created this instance of JavaSource.

getField

public JavaField getField(String pName)
Returns the field with the given name or null, if no such field exists.

getFields

public JavaField[] getFields()
Returns the list of fields that this class has.

See Also: JavaSource

getImplements

public JavaQName[] getImplements()
Returns the list of interfaces being implented by this class or interface.

See Also: addImplements

getImports

public JavaQName[] getImports()
Returns the list of packages and classes being imported.

See Also: addImport

getInnerClass

public JavaInnerClass getInnerClass(String pName)
Returns the inner class named pName, or null, if no such class exists.

getInnerClasses

public JavaInnerClass[] getInnerClasses()
Returns the array of inner classes.

getMethod

public JavaMethod getMethod(String pMethodName, JavaQName[] pParams)
Returns the method with the given signature or null, if there is no such method.

getMethodIterator

public Iterator getMethodIterator()
Returns an iterator to the classes methods. This iterator allows to remove certain methods.

getMethods

public JavaMethod[] getMethods()
Returns the list of methods that this class has.

See Also: JavaSource

getPackageName

public String getPackageName()
Returns the package name. The empty String represents the root package.

getProtection

public JavaSource.Protection getProtection()
Returns the protection.

See Also: JavaSource

getQName

public JavaQName getQName()
Returns the JavaSource's JavaQName.

getQuoted

public static String getQuoted(String s)
Returns a quoted string constant suitable for embedding into Java source.

getQuotedNoQuotes

public static String getQuotedNoQuotes(String s)
Returns a quoted string constant suitable for embedding into Java source, but without quotes.

getRawJavaSources

public String[] getRawJavaSources()
Returns an array with the pieces of raw Java sources.

getStatic

protected boolean getStatic()
Returns whether this JavaSource is static (for inner classes).

getType

public JavaSource.Type getType()
Returns the JavaSource type.

Returns: "class" or "interface"

See Also: JavaSource

hasDynamicImports

public boolean hasDynamicImports()
Returns, whether the class is automatically adding imports.

isAbstract

public boolean isAbstract()
Returns whether class is abstract.

isExtending

public boolean isExtending(JavaQName pClass)
Returns whether the class is extending the given super class or interface.

isExtending

public boolean isExtending(Class pClass)
Returns whether the class is extending the given super class or interface.

isForcingFullyQualifiedName

public boolean isForcingFullyQualifiedName()
Returns, whether class references are always using the fully qualified class name.

isImplementing

public boolean isImplementing(JavaQName pClass)
Returns whether the class is implementing the given interface.

isImplementing

public boolean isImplementing(Class pClass)
Returns whether the class is implementing the given interface.

isInnerClass

public boolean isInnerClass()
Returns, whether this is an inner class.

isInterface

public boolean isInterface()
Returns whether this is an interface or not.

newBeanProperty

public void newBeanProperty(JavaQName pType, String pName)
Creates a new Java property with the given type and name. Shortcut for
 String upperCaseName = Character.toUpperCase(pName.charAt(0)) +
     pName.substring(1);
 if (JavaQNameImpl.VOID.equals(pType)) {
   newBeanProperty(pType, pName, "is" + upperCaseName, "set" + upperCaseName);
 } else {
   newBeanProperty(pType, pName, "get" + upperCaseName, "set" + upperCaseName);
 }
 

newBeanProperty

public void newBeanProperty(Class pClass, String pName)
Shortcut for newBeanProperty(JavaQNameImpl.getInstance(pClass), pName).

See Also: JavaSource

newBeanProperty

public void newBeanProperty(JavaQName pType, String pFieldName, String pGetMethodName, String pSetMethodName)
Shortcut for
 newJavaField(pFieldName, pType, JavaSource.PRIVATE);
 JavaMethod getMethod = newJavaMethod(pGetMethodName, pType, JavaSource.PUBLIC);
 getMethod.addLine("return this.", pFieldName, ";");
 JavaMethod setMethod = newJavaMethod(pSetMethodName, JavaQNameImpl.VOID, JavaSource.PUBLIC);
 setMethod.addParam(pType, pFieldName);
 setMethod.addLine("this.", pFieldName, " = ", pFieldName, ";");
 

Parameters: pType The property type pFieldName The name of the generated field. The generated field has private access. pGetMethodName The name of the generated get method or null, if no such method is being created. pSetMethodName The name of the generated set method or null, if no such method is being created.

newBeanProperty

public void newBeanProperty(Class pClass, String pFieldName, String pGetMethodName, String pSetMethodName)
Shortcut for newBeanProperty(JavaQNameImpl.getInstance(pClass), pFieldName, pGetMethodName, pSetMethodName).

See Also: JavaSource

newComment

public JavaComment newComment()
Creates a new Javadoc comment describing this class or interface.

See Also: JavaSource

newJavaClassInitializer

public JavaClassInitializer newJavaClassInitializer()
Creates a new instance of JavaClassInitializer.

newJavaConstructor

public JavaConstructor newJavaConstructor()
Creates a new JavaConstructor with default protection.

newJavaConstructor

public JavaConstructor newJavaConstructor(JavaSource.Protection pProtection)
Creates a new JavaConstructor with the given protection.

newJavaConstructor

public JavaConstructor newJavaConstructor(String pProtection)
Creates a new JavaConstructor with the given protection. Equivalent to newJavaConstructor(Protection.valueOf(pProtection)).

newJavaConstructor

public JavaConstructor newJavaConstructor(JavaConstructor pConstructor)
Creates a new JavaConstructor with the same parameters, protection and exceptions than the given. Equivalent to newJavaConstructor(pConstructor, false).

newJavaConstructor

public JavaConstructor newJavaConstructor(JavaConstructor pConstructor, boolean pSuper)
Creates a new JavaConstructor with the same signature than the given constructors. Equivalent to newJavaConstructor(pConstructor, false). If the pSuper argument is true, adds an invocation of the super classes constructor with the same arguments.

newJavaConstructor

public JavaConstructor newJavaConstructor(Constructor pConstructor)
Creates a new JavaConstructor with the signature of the given constructor.

newJavaField

public JavaField newJavaField(Field pField)
Creates a new JavaField with the given fields signature.

newJavaField

public JavaField newJavaField(String pName, JavaQName pType, JavaSource.Protection pProtection)
Creates a new JavaField with the given name, type and protection.

newJavaField

public JavaField newJavaField(String pName, JavaQName pType, String pProtection)
Creates a new JavaField with the given name, type and protection.

newJavaField

public JavaField newJavaField(String pName, JavaQName pType)
Creates a new JavaField with the given name, type and default protection.

newJavaField

public JavaField newJavaField(String pName, String pType, JavaSource.Protection pProtection)
Creates a new JavaField with the given name, type and protection.

newJavaField

public JavaField newJavaField(String pName, String pType, String pProtection)
Creates a new JavaField with the given name, type and protection.

newJavaField

public JavaField newJavaField(String pName, String pType)
Creates a new JavaField with the given name, type and default protection.

newJavaField

public JavaField newJavaField(String pName, Class pType, JavaSource.Protection pProtection)
Creates a new JavaField with the given name, type and protection.

newJavaField

public JavaField newJavaField(String pName, Class pType, String pProtection)
Creates a new JavaField with the given name, type and protection. Equivalent to newJavaField(pName, pType, Protection.valueOf(pProtecttion).

newJavaField

public JavaField newJavaField(String pName, Class pType)
Creates a new JavaField with the given name, type and default protection.

newJavaInnerClass

public JavaInnerClass newJavaInnerClass(String pName)
Creates a new JavaInnerClass with the given name and default protection.

newJavaInnerClass

public JavaInnerClass newJavaInnerClass(String pName, JavaSource.Protection pProtection)
Creates a new JavaInnerClass with the given name and protection.

newJavaInnerClass

public JavaInnerClass newJavaInnerClass(String pName, String pProtection)
Creates a new JavaInnerClass with the given name and protection.

newJavaMethod

public JavaMethod newJavaMethod(String pName, String pType)
Creates a new JavaMethod with the given name, return type and default protection.

newJavaMethod

public JavaMethod newJavaMethod(String pName, String pType, JavaSource.Protection pProtection)
Creates a new JavaMethod with the given name, return type and protection.

newJavaMethod

public JavaMethod newJavaMethod(String pName, String pType, String pProtection)
Creates a new JavaMethod with the given name, return type and protection.

newJavaMethod

public JavaMethod newJavaMethod(String pName, JavaQName pType)
Creates a new JavaMethod with the given name, return type and default protection.

newJavaMethod

public JavaMethod newJavaMethod(String pName, JavaQName pType, JavaSource.Protection pProtection)
Creates a new JavaMethod with the given name, return type and protection.

newJavaMethod

public JavaMethod newJavaMethod(String pName, JavaQName pType, String pProtection)
Creates a new JavaMethod with the given name, return type and protection.

newJavaMethod

public JavaMethod newJavaMethod(String pName, Class pType)
Creates a new JavaMethod with the given name, return type and default protection.

newJavaMethod

public JavaMethod newJavaMethod(String pName, Class pType, JavaSource.Protection pProtection)
Creates a new JavaMethod with the given name, return type and protection.

newJavaMethod

public JavaMethod newJavaMethod(String pName, Class pType, String pProtection)
Creates a new JavaMethod with the given name, return type and protection.

newJavaMethod

public JavaMethod newJavaMethod(Method pMethod)
Creates a new JavaMethod with the signature of the given method pMethod. More precise:
  1. The name of the created method is pMethod.getName().
  2. The return type is set to pMethod.getReturnType().
  3. The protection is set to that of pMethod.
  4. For any class in pMethod.getParameterTypes(), calls {@link JavaMethod#addParam(Class,String)} with the parameter names "p0", "p1", ...
  5. For any exception in pMethod.getExceptionTypes(), calls {@link JavaMethod#addThrows(Class)}.

newJavaMethod

public JavaMethod newJavaMethod(JavaMethod pMethod)
Creates a new JavaMethod with the given methods name and signature. This is useful, for example, if you have an interface and derive an implementation. The following values are not cloned: {@link JavaMethod#isAbstract()}, {@link JavaMethod#isStatic()}, {@link JavaMethod#isFinal()}, and {@link JavaMethod#isSynchronized()}.

setAbstract

public void setAbstract(boolean isAbstract)
Sets whether this class is abstract.

setDynamicImports

public void setDynamicImports(boolean pDynamicImports)
Sets, whether the class is automatically adding imports.

setForcingFullyQualifiedName

public void setForcingFullyQualifiedName(boolean pForcingFullyQualifiedName)
Sets, whether class references are always using the fully qualified class name.

setProtection

public void setProtection(JavaSource.Protection protection)
Sets the protection; use null for default protection.

See Also: JavaSource

setQName

public void setQName(JavaQName pQName)
Sets the JavaSource's JavaQName.

setStatic

public void setStatic(boolean pStatic)
Sets whether this JavaSource is static (for inner classes).

setType

public void setType(JavaSource.Type pType)
Sets the JavaSource type.

Parameters: pType "class" or "interface"

See Also: JavaSource

toString

public String toString()
Returns a string representation of this JavaSource file.

write

public void write(IndentationTarget pTarget)

write

public void write(Writer pTarget)
Writes the JavaSource contents into the given Writer.