org.exolab.javasource
Class JClass

java.lang.Object
  extended byorg.exolab.javasource.JType
      extended byorg.exolab.javasource.JClass
Direct Known Subclasses:
DescriptorJClass

public class JClass
extends JType

A representation of the Java Source code for a Java Class. This is a useful utility when creating in memory source code. This package was modelled after the Java Reflection API as much as possible to reduce the learning curve.

Version:
$Revision: 1.17 $ $Date: 2001/03/20 02:58:59 $
Author:
Keith Visco

Field Summary
 
Fields inherited from class org.exolab.javasource.JType
Boolean, Byte, Char, Double, Float, Int, Long, Short
 
Constructor Summary
JClass(java.lang.String name)
          Creates a new JClass with the given name
 
Method Summary
 void addConstructor(JConstructor constructor)
          Adds the given Constructor to this classes list of constructors.
 void addField(JField jField)
          Adds the given JField to this JClass
 void addImport(java.lang.String className)
           
 void addInterface(java.lang.String interfaceName)
           
 void addMember(JMember jMember)
          Adds the given JMember to this JClass
 void addMethod(JMethod jMethod)
          Adds the given JMethod to this JClass
 void addMethods(JMethod[] jMethods)
          Adds the given array of JMethods to this JClass
 JConstructor createConstructor()
          Adds a JClass which should be printed in the same source file as this JClass public void addPackageClass(JClass jClass) { if (jClass != null) packageClasses.addElement(jClass); } //-- addPackageClass
 JConstructor getConstructor(int index)
           
 JConstructor[] getConstructors()
           
 JField getField(java.lang.String name)
          Returns the member with the given name, or null if no member was found with the given name
 JField[] getFields()
          Returns an array of all the JFields of this JClass
 java.lang.String getFilename(java.lang.String destDir)
          Returns the name of the file that this JClass would be printed as, given a call to #print.
 JDocComment getJDocComment()
          Returns the Java Doc comment for this JClass
 JMethod getMethod(int index)
           
 JMethod getMethod(java.lang.String name, int startIndex)
           
 JMethod[] getMethods()
          Returns an array of all the JMethods of this JClass
 JModifiers getModifiers()
          Returns the JModifiers which allows the qualifiers to be changed
 java.lang.String getName(boolean stripPackage)
          Returns the name of the class.
 java.lang.String getPackageName()
          Returns the name of the package that this JClass is a member of
 JSourceCode getStaticInitializationCode()
          Returns the JSourceCode for the static initializer of this JClass
 java.lang.String getSuperClass()
          Gets the super Class that this class extends
static boolean isValidClassName(java.lang.String name)
           
 void print()
           
 void print(java.lang.String destDir, java.lang.String lineSeparator)
          Prints the source code for this JClass
 void removeField(JField jField)
          Removes the given JField from this JClass
 void removeField(java.lang.String name)
          Removes the field with the given name from this JClass
 boolean removeImport(java.lang.String className)
           
 void setHeader(JComment comment)
          Sets the header comment for this JClass
 void setPackageName(java.lang.String packageName)
          Allows changing the package name of this JClass
 void setSuperClass(java.lang.String superClass)
          Sets the super Class that this class extends
 
Methods inherited from class org.exolab.javasource.JType
changePackage, createArray, getComponentType, getLocalName, getName, isArray, isPrimitive, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JClass

public JClass(java.lang.String name)
       throws java.lang.IllegalArgumentException
Creates a new JClass with the given name

Parameters:
name - the name of the JClass to create
Throws:
java.lang.IllegalArgumentException - when the given name is not a valid Class name
Method Detail

addImport

public void addImport(java.lang.String className)

addInterface

public void addInterface(java.lang.String interfaceName)

addConstructor

public void addConstructor(JConstructor constructor)
                    throws java.lang.IllegalArgumentException
Adds the given Constructor to this classes list of constructors. The constructor must have been created with this JClass' createConstructor.

Throws:
java.lang.IllegalArgumentException

addField

public void addField(JField jField)
              throws java.lang.IllegalArgumentException
Adds the given JField to this JClass

Throws:
java.lang.IllegalArgumentException - when the given JField has a name of an existing JField

addMember

public void addMember(JMember jMember)
               throws java.lang.IllegalArgumentException
Adds the given JMember to this JClass

Throws:
java.lang.IllegalArgumentException - when the given JMember has the same name of an existing JField or JMethod respectively.

addMethod

public void addMethod(JMethod jMethod)
               throws java.lang.IllegalArgumentException
Adds the given JMethod to this JClass

Throws:
java.lang.IllegalArgumentException - when the given JMethod has the same name of an existing JMethod.

addMethods

public void addMethods(JMethod[] jMethods)
                throws java.lang.IllegalArgumentException
Adds the given array of JMethods to this JClass

Throws:
java.lang.IllegalArgumentException - when any of the given JMethods has the same name of an existing JMethod.

createConstructor

public JConstructor createConstructor()
Adds a JClass which should be printed in the same source file as this JClass public void addPackageClass(JClass jClass) { if (jClass != null) packageClasses.addElement(jClass); } //-- addPackageClass


getConstructor

public JConstructor getConstructor(int index)

getConstructors

public JConstructor[] getConstructors()

getFilename

public java.lang.String getFilename(java.lang.String destDir)
Returns the name of the file that this JClass would be printed as, given a call to #print.

Parameters:
destDir - the destination directory. This may be null.
Returns:
the name of the file that this JClass would be printed as, given a call to #print.

getJDocComment

public JDocComment getJDocComment()
Returns the Java Doc comment for this JClass

Returns:
the JDocComment for this JClass

getField

public JField getField(java.lang.String name)
Returns the member with the given name, or null if no member was found with the given name

Parameters:
name - the name of the member to return
Returns:
the member with the given name, or null if no member was found with the given name

getFields

public JField[] getFields()
Returns an array of all the JFields of this JClass

Returns:
an array of all the JFields of this JClass

getMethods

public JMethod[] getMethods()
Returns an array of all the JMethods of this JClass

Returns:
an array of all the JMethods of this JClass

getMethod

public JMethod getMethod(java.lang.String name,
                         int startIndex)

getMethod

public JMethod getMethod(int index)

getModifiers

public JModifiers getModifiers()
Returns the JModifiers which allows the qualifiers to be changed

Returns:
the JModifiers for this JClass

getPackageName

public java.lang.String getPackageName()
Returns the name of the package that this JClass is a member of

Returns:
the name of the package that this JClass is a member of, or null if there is no current package name defined

getName

public java.lang.String getName(boolean stripPackage)
Returns the name of the class.

Parameters:
stripPackage - True if you want the package name striped of the name
Returns:
the name of the class. or null if there is no current package name defined

removeImport

public boolean removeImport(java.lang.String className)

getStaticInitializationCode

public JSourceCode getStaticInitializationCode()
Returns the JSourceCode for the static initializer of this JClass

Returns:
the JSourceCode for the static initializer of this JClass

isValidClassName

public static boolean isValidClassName(java.lang.String name)

print

public void print()

print

public void print(java.lang.String destDir,
                  java.lang.String lineSeparator)
Prints the source code for this JClass

Parameters:
lineSeparator - the line separator to use at the end of each line. If null, then the default line separator for the runtime platform will be used.

removeField

public void removeField(java.lang.String name)
Removes the field with the given name from this JClass

Parameters:
name - the name of the field to remove

removeField

public void removeField(JField jField)
Removes the given JField from this JClass


setHeader

public void setHeader(JComment comment)
Sets the header comment for this JClass

Parameters:
comment - the comment to display at the top of the source file when printed

setPackageName

public void setPackageName(java.lang.String packageName)
Allows changing the package name of this JClass

Parameters:
packageName - the package name to use

setSuperClass

public void setSuperClass(java.lang.String superClass)
Sets the super Class that this class extends

Parameters:
superClass - the super Class that this Class extends

getSuperClass

public java.lang.String getSuperClass()
Gets the super Class that this class extends

Returns:
superClass the super Class that this Class extends


Intalio Inc. (C) 1999-2001. All rights reserved http://www.intalio.com