Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Static Package Attributes

org.exolab.javasource.JStructure Class Reference

Inheritance diagram for org.exolab.javasource.JStructure:
org.exolab.javasource.JType org.exolab.javasource.JAnnotatedElement org.exolab.javasource.JAnnotationType org.exolab.javasource.JClass org.exolab.javasource.JInterface org.exolab.castor.builder.util.DescriptorJClass org.exolab.javasource.JClass.JInnerClass

List of all members.

Public Member Functions

abstract void addField (JField jField) throws IllegalArgumentException
abstract void addMember (JMember jMember) throws IllegalArgumentException
void addImport (String className)
void addInterface (String interfaceName)
void addInterface (JInterface jInterface)
abstract JField getField (String name)
abstract JField[] getFields ()
String getFilename (String destDir)
JComment getHeader ()
Enumeration getImports ()
Enumeration getInterfaces ()
JDocComment getJDocComment ()
JModifiers getModifiers ()
String getPackageName ()
String getName (boolean stripPackage)
boolean hasImport (String classname)
boolean removeImport (String className)
void print ()
void print (String destDir, String lineSeparator)
abstract void print (JSourceWriter jsw)
void printHeader (JSourceWriter jsw)
void printImportDeclarations (JSourceWriter jsw)
void printPackageDeclaration (JSourceWriter jsw)
void setHeader (JComment comment)
void setPackageName (String packageName)
void addAnnotation (JAnnotation annotation)
JAnnotation getAnnotation (JAnnotationType annotationType)
JAnnotation[] getAnnotations ()
boolean isAnnotationPresent (JAnnotationType annotationType)
JAnnotation removeAnnotation (JAnnotationType annotationType)
boolean hasAnnotations ()

Static Public Member Functions

static boolean isValidClassName (String name)

Protected Member Functions

 JStructure (String name) throws IllegalArgumentException
void addImport (JAnnotation annotation)
void addImport (JAnnotation[] annotations)
JAnnotatedElementHelper getAnnotatedElementHelper ()
int getInterfaceCount ()

Static Protected Member Functions

static void printlnWithPrefix (String prefix, String source, JSourceWriter jsw)
static String getPackageFromClassName (String className)

Static Package Attributes

static final String DEFAULT_HEADER = "Id$"
static final String version = "Date$"

Detailed Description

This class represents the basic Java "structure" for a Java source file. This is the base class for JClass and JInterface.

This is a useful utility when creating in memory source code. The code in this package was modelled after the Java Reflection API as much as possible to reduce the learning curve.

Author:
Martin Skopp
Keith Visco
Version:
Revision:
1.3
Date:
2004/12/03 18:57:33

Constructor & Destructor Documentation

org.exolab.javasource.JStructure.JStructure ( String  name  )  throws IllegalArgumentException [protected]

Creates a new JStructure with the given name.

Parameters:
name the name of the JStructure.
Exceptions:
IllegalArgumentException when the given name is not a valid Class name.

References org.exolab.javasource.JDocComment.addDescriptor(), org.exolab.javasource.JType.getLocalName(), org.exolab.javasource.JStructure.getPackageFromClassName(), org.exolab.javasource.JStructure.isValidClassName(), and org.exolab.javasource.JStructure.version.


Member Function Documentation

void org.exolab.javasource.JStructure.addAnnotation ( JAnnotation  annotation  ) 

Adds a JAnnotation to this source element. An IllegalArgumentException is thrown if one already exists for the associated JAnnotationType.

Parameters:
annotation 

Implements org.exolab.javasource.JAnnotatedElement.

References org.exolab.javasource.JStructure.addImport().

abstract void org.exolab.javasource.JStructure.addField ( JField  jField  )  throws IllegalArgumentException [pure virtual]

Adds the given JField to this JStructure.

This method is implemented by subclasses and should only accept the proper fields for the subclass otherwise an IllegalArgumentException will be thrown. For example a JInterface will only accept static fields.

Parameters:
jField,the JField to add
Exceptions:
IllegalArgumentException when the given JField has a name of an existing JField

Implemented in org.exolab.javasource.JAnnotationType, org.exolab.javasource.JClass, and org.exolab.javasource.JInterface.

void org.exolab.javasource.JStructure.addImport ( JAnnotation  annotation  )  [protected]
void org.exolab.javasource.JStructure.addImport ( JAnnotation[]  annotations  )  [protected]

Adds approprite imports for these JAnnotation's

Parameters:
annotation 

References org.exolab.javasource.JStructure.addImport(), and org.exolab.javasource.JType.getName().

void org.exolab.javasource.JStructure.addInterface ( String  interfaceName  ) 

Adds the given interface to the list of interfaces this JStructure inherits method declarations from, and either implements (JClass) or extends (JInterface).

Parameters:
interfaceName the name of the interface to "inherit" method declarations from.

Referenced by org.exolab.castor.builder.SourceFactory.createSourceCode(), and org.exolab.castor.builder.SourceFactory.createTestableMethods().

void org.exolab.javasource.JStructure.addInterface ( JInterface  jInterface  ) 

Adds the given interface to the list of interfaces this JStructure inherits method declarations from, and either implements (JClass) or extends (JInterface).

Parameters:
jInterface the JInterface to inherit from.

References org.exolab.javasource.JStructure.getName().

abstract void org.exolab.javasource.JStructure.addMember ( JMember  jMember  )  throws IllegalArgumentException [pure virtual]

Adds the given JMember to this JStructure.

This method is implemented by subclasses and should only accept the proper types for the subclass otherwise an IllegalArgumentException will be thrown.

Parameters:
jMember the JMember to add to this JStructure.
Exceptions:
IllegalArgumentException when the given JMember has the same name of an existing JField or JMethod respectively.

Implemented in org.exolab.javasource.JAnnotationType, org.exolab.javasource.JClass, and org.exolab.javasource.JInterface.

JAnnotatedElementHelper org.exolab.javasource.JStructure.getAnnotatedElementHelper (  )  [protected]

Returns the object managing the annotations for this JStructure

Returns:

Referenced by org.exolab.javasource.JInterface.print(), and org.exolab.javasource.JClass.print().

JAnnotation org.exolab.javasource.JStructure.getAnnotation ( JAnnotationType  annotationType  ) 

Retrieves a JAnnotation for the given JAnnotationType, returns null if no annotation has been set.

Parameters:
annotationType 
Returns:
A JAnnotation for the given JAnnotationType

Implements org.exolab.javasource.JAnnotatedElement.

JAnnotation [] org.exolab.javasource.JStructure.getAnnotations (  ) 

Returns a list of JAnnotation's already set on this source element

Returns:
A list of all JAnnotations associated with this source element

Implements org.exolab.javasource.JAnnotatedElement.

Referenced by org.exolab.javasource.JClass.addConstructor(), org.exolab.javasource.JInterface.addMethod(), and org.exolab.javasource.JClass.addMethod().

abstract JField org.exolab.javasource.JStructure.getField ( String  name  )  [pure virtual]

Adds the given JMethodSignature to this JClass

Parameters:
jMethodSig the JMethodSignature to add.
Exceptions:
IllegalArgumentException when the given JMethodSignature conflicts with an existing method signature. Returns the field with the given name, or null if no field was found with the given name.
Parameters:
name the name of the field to return.
Returns:
the field with the given name, or null if no field was found with the given name.

Implemented in org.exolab.javasource.JAnnotationType, org.exolab.javasource.JClass, and org.exolab.javasource.JInterface.

abstract JField [] org.exolab.javasource.JStructure.getFields (  )  [pure virtual]

Returns an array of all the JFields of this JStructure

Returns:
an array of all the JFields of this JStructure

Implemented in org.exolab.javasource.JAnnotationType, org.exolab.javasource.JClass, and org.exolab.javasource.JInterface.

String org.exolab.javasource.JStructure.getFilename ( String  destDir  ) 

Returns the name of the file that this JStructure would be printed to, given a call to print.

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

References org.exolab.javasource.JType.getLocalName().

Referenced by org.exolab.javasource.JStructure.print().

JComment org.exolab.javasource.JStructure.getHeader (  ) 

Returns the JComment header to display at the top of the source file for this JStructure, or null if no header was set.

Returns:
the JComment header or null if none exists.

Referenced by org.exolab.javasource.JStructure.printHeader().

Enumeration org.exolab.javasource.JStructure.getImports (  ) 

Returns an Enumeration of imported package and class names for this JStructure.

Returns:
the Enumeration of imports. May be empty.

Referenced by org.exolab.javasource.JCompUnit.getImports(), and org.exolab.javasource.JClass.print().

int org.exolab.javasource.JStructure.getInterfaceCount (  )  [protected]
Enumeration org.exolab.javasource.JStructure.getInterfaces (  ) 

Returns an Enumeration of interface names that this JStructure inherits from.

Returns:
the Enumeration of interface names for this JStructure. May be empty.

Referenced by org.exolab.javasource.JInterface.print(), and org.exolab.javasource.JClass.print().

JModifiers org.exolab.javasource.JStructure.getModifiers (  ) 

Returns an array of all the JMethodSignatures of this JInterface.

Returns:
an array of all the JMethodSignatures of this JInterface. Returns the JMethodSignature with the given name, and occuring at or after the given starting index.
Parameters:
name the name of the JMethodSignature to return.
startIndex the starting index to begin searching from.
Returns:
the JMethodSignature, or null if not found. Returns the JMethodSignature at the given index.
Parameters:
index the index of the JMethodSignature to return.
Returns:
the JMethodSignature at the given index. Returns the JModifiers which allows the qualifiers to be changed.
the JModifiers for this JStructure.

Referenced by org.exolab.javasource.JClass.addMethod(), org.exolab.castor.builder.SourceFactory.createSourceCode(), org.exolab.javasource.JInterface.print(), org.exolab.javasource.JClass.print(), org.exolab.javasource.JAnnotationType.print(), and org.exolab.javasource.JCompUnit.printStructures().

static String org.exolab.javasource.JStructure.getPackageFromClassName ( String  className  )  [static, protected]

Returns the package name from the given class name

Referenced by org.exolab.javasource.JStructure.addImport(), and org.exolab.javasource.JStructure.JStructure().

String org.exolab.javasource.JStructure.getPackageName (  ) 

Returns the name of the package that this JStructure is a member of.

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

Referenced by org.exolab.javasource.JClass.createInnerClass(), and org.exolab.javasource.JCompUnit.JCompUnit().

boolean org.exolab.javasource.JStructure.hasAnnotations (  ) 

Returns true if annotations have been added to this source element

Returns:
Returns true if annotations have been added to this source element

Implements org.exolab.javasource.JAnnotatedElement.

boolean org.exolab.javasource.JStructure.hasImport ( String  classname  ) 

Returns true if the given classname exists in the imports of this JStructure

Parameters:
classname the class name to check for
Returns:
true if the given classname exists in the imports list

Referenced by org.exolab.javasource.JClass.print().

boolean org.exolab.javasource.JStructure.isAnnotationPresent ( JAnnotationType  annotationType  ) 

Returns true if a JAnnotation exists for the given JAnnotationType

Parameters:
annotationType 
Returns:
True if a JAnnotation has been added for the given JAnnotationType

Implements org.exolab.javasource.JAnnotatedElement.

static boolean org.exolab.javasource.JStructure.isValidClassName ( String  name  )  [static]
void org.exolab.javasource.JStructure.print ( String  destDir,
String  lineSeparator 
)

Prints the source code for this JStructure to the destination directory. Sub-directories will be created if necessary for the package.

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.

References org.exolab.javasource.JSourceWriter.close(), org.exolab.javasource.JStructure.getFilename(), org.exolab.javasource.JType.getLocalName(), org.exolab.javasource.JStructure.print(), and org.exolab.javasource.JSourceWriter.setLineSeparator().

void org.exolab.javasource.JStructure.print (  ) 

Prints the source code for this JStructure in the current working directory. Sub-directories will be created if necessary for the package.

Referenced by org.exolab.javasource.JStructure.print(), org.exolab.javasource.JInterface.print(), and org.exolab.javasource.JClass.print().

abstract void org.exolab.javasource.JStructure.print ( JSourceWriter  jsw  )  [pure virtual]

Prints the source code for this JStructure to the given JSourceWriter.

Parameters:
jsw the JSourceWriter to print to.

Implemented in org.exolab.javasource.JAnnotationType, org.exolab.javasource.JClass, and org.exolab.javasource.JInterface.

void org.exolab.javasource.JStructure.printImportDeclarations ( JSourceWriter  jsw  ) 
static void org.exolab.javasource.JStructure.printlnWithPrefix ( String  prefix,
String  source,
JSourceWriter  jsw 
) [static, protected]

Prints the given source string to the JSourceWriter using the given prefix at the beginning of each new line.

Parameters:
prefix the prefix for each new line.
source the source code to print
jsw the JSourceWriter to print to.

References org.exolab.javasource.JSourceWriter.write(), and org.exolab.javasource.JSourceWriter.writeln().

void org.exolab.javasource.JStructure.printPackageDeclaration ( JSourceWriter  jsw  ) 
JAnnotation org.exolab.javasource.JStructure.removeAnnotation ( JAnnotationType  annotationType  ) 

Removes the JAnnotation from this source element for the given JAnnotationType, throws a IllegalArgumentException if no JAnnotation has been added.

Parameters:
annotation 
Returns:
The JAnnotation that was associated with this source element

Implements org.exolab.javasource.JAnnotatedElement.

boolean org.exolab.javasource.JStructure.removeImport ( String  className  ) 
void org.exolab.javasource.JStructure.setHeader ( JComment  comment  ) 

Prints the source code for this JStructure to the given JSourceWriter.

Parameters:
jsw the JSourceWriter to print to.

public abstract void print(JSourceWriter jsw);

StringBuffer buffer = new StringBuffer();

printHeader(); printPackageDeclaration(); printImportDeclarations();

------------/

  • Java Doc -/ ------------/

jdc.print(jsw);

-- print class information -- we need to add some JavaDoc API adding comments

buffer.setLength(0);

if (modifiers.isPrivate()) { buffer.append("private "); } else if (modifiers.isPublic()) { buffer.append("public "); }

if (modifiers.isAbstract()) { buffer.append("abstract "); }

buffer.append("interface "); buffer.append(getLocalName()); buffer.append(' '); if (interfaces.size() > 0) { boolean endl = false; if (interfaces.size() > 1) { jsw.writeln(buffer.toString()); buffer.setLength(0); endl = true; } buffer.append("extends "); for (int i = 0; i < interfaces.size(); i++) { if (i > 0) buffer.append(", "); buffer.append(interfaces.elementAt(i)); } if (endl) { jsw.writeln(buffer.toString()); buffer.setLength(0); } else buffer.append(' '); }

buffer.append('{'); jsw.writeln(buffer.toString()); buffer.setLength(0); jsw.writeln();

jsw.indent();

-- print method signatures

if (methods.size() > 0) { jsw.writeln(); jsw.writeln(" //-----------/"); jsw.writeln(" //- Methods -/"); jsw.writeln("//-----------/"); jsw.writeln(); }

for (int i = 0; i < methods.size(); i++) { JMethodSignature signature = (JMethodSignature) methods.elementAt(i); signature.print(jsw); jsw.writeln(';'); }

jsw.unindent(); jsw.writeln('}'); jsw.flush(); jsw.close(); } //-- printSource Sets the header comment for this JStructure

Parameters:
comment the comment to display at the top of the source file when printed
void org.exolab.javasource.JStructure.setPackageName ( String  packageName  ) 

Allows changing the package name of this JStructure

Parameters:
packageName the package name to use

Reimplemented in org.exolab.javasource.JClass.JInnerClass.

References org.exolab.javasource.JType.changePackage().


Member Data Documentation

final String org.exolab.javasource.JStructure.DEFAULT_HEADER = "Id$" [static, package]

The Id for Source control systems I needed to separate this line to prevent CVS from expanding it here! ;-)

Referenced by org.exolab.javasource.JStructure.printHeader().

final String org.exolab.javasource.JStructure.version = "Date$" [static, package]

The source control version for listed in the JavaDoc I needed to separate this line to prevent CVS from expanding it here! ;-)

Referenced by org.exolab.javasource.JStructure.JStructure().


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations Properties