Public Member Functions | Static Public Member Functions | Static Public Attributes

org.exolab.javasource.JAnnotation Class Reference

List of all members.

Public Member Functions

 JAnnotation (JAnnotationType annotationType)
JAnnotationType getAnnotationType ()
void setValue (String stringValue)
void setValue (String[] stringValue)
void setValue (JAnnotation annotationValue)
void setValue (JAnnotation[] annotationValues)
void setElementValue (String elementName, String stringValue)
void setElementValue (String elementName, String[] stringValues)
void setElementValue (String elementName, JAnnotation annotationValue)
void setElementValue (String elementName, JAnnotation[] annotationValues)
String getValue ()
JAnnotation getValueAnnotation () throws IllegalStateException
String getElementValue (String elementName) throws IllegalStateException
String[] getElementValueList (String elementName) throws IllegalStateException
Object getElementValueObject (String elementName)
JAnnotation getElementValueAnnotation (String elementName) throws IllegalStateException
JAnnotation[] getElementValueAnnotationList (String elementName) throws IllegalStateException
String[] getElementNames ()
void print (JSourceWriter jsw)

Static Public Member Functions

static void main (String[] args)

Static Public Attributes

static final String value = "value"

Detailed Description

JAnnotation represents a single annotation against a code element. The methods described on the JAnnotatedElement interface are used to associate JAnnotation's with various other objects in this package describing Java code elements.

The print method outputs annotations in various forms (as described in the Java Language Specificaiton Third Edition) based on the methods called.

For "Marker Annotation", construct with the approprite JAnnotationType.

JAnnotationType preliminaryType = new JAnnotationType("Preliminary"); JAnnotation preliminary = new JAnnotation(preliminaryType);

Outputs

()

For "Single Element Annotation", construct as above and call the setValue(value) method to set the value of the "value" element of the annotation type.

JAnnotationType copyrightType = new JAnnotationType("Copyright"); JAnnotation copyright = new JAnnotation(copyrightType); copyright.setValue("\"2002 Yoyodyne Propulsion Systems, Inc., All rights reserved."");

Outputs

("2002 Yoyodyne Propulsion Systems, Inc., All rights reserved.")

For "Normal Annotation", construct as above then call the approprite setValue methods that accept an "elementName" parameter.

JAnnotationType requestForEnhancementType = new JAnnotationType("RequestForEnhancement"); JAnnotation requestForEnhancement = new JAnnotation(requestForEnhancementType); requestForEnhancement.setElementValue("id", "2868724"); requestForEnhancement.setElementValue("sysopsis", "\"Provide time-travel functionality""); requestForEnhancement.setElementValue("enginer", ""Mr. Peabody""); requestForEnhancement.setElementValue("date", ""4/1/2004"");

Outputs

( id = 2868724, sysopsis = "Provide time-travel functionality", enginer = "Mr. Peabody", date = "4/1/2004")

"Complex" annotations are also supported via the various setValue methods that take a JAnnotation object.

JAnnotationType nameType = new JAnnotationType("Name"); JAnnotationType authorType = new JAnnotationType("Author"); JAnnotation author = new JAnnotation(authorType); JAnnotation name = new JAnnotation(nameType); name.setElementValue("first", "\"Joe""); name.setElementValue("last", ""Hacker""); author.setValue(name);

Outputs

(( first = "Joe", last = "Hacker"))

Finally annotation elements who's types are arrays are supported via the setValue methods that take arrays.

JAnnotationType endorsersType = new JAnnotationType("Endorsers"); JAnnotation endorsers = new JAnnotation(endorsersType); endorsers.setValue(new String[] { "\"Children"", ""Unscrupulous dentists""});

Outputs

( { "Children", "Unscrupulous dentists" })

Note: Conditional element values are not currently supported. However the setValue methods taking String values can be used to output this construct literally if desired.

Author:
Andrew Fawcett

Constructor & Destructor Documentation

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

Constructs a JAnnotation for the given annotation type

Parameters:
annotationType 

Referenced by org.exolab.javasource.JAnnotation.main().


Member Function Documentation

JAnnotationType org.exolab.javasource.JAnnotation.getAnnotationType (  ) 

Returns the JAnnotationType associated with this JAnnotation

Returns:

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

String [] org.exolab.javasource.JAnnotation.getElementNames (  ) 

Returns the names of the elements set by this annotation

Returns:

References org.exolab.castor.util.OrderedHashMap.keySet().

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

String org.exolab.javasource.JAnnotation.getElementValue ( String  elementName  )  throws IllegalStateException

Returns the given annotation element value

Parameters:
elementName 
Returns:
Exceptions:
IllegalArgumentException when the element value is not a String

References org.exolab.javasource.JAnnotation.getElementValueObject().

JAnnotation org.exolab.javasource.JAnnotation.getElementValueAnnotation ( String  elementName  )  throws IllegalStateException

Returns the given annotation element value as a JAnnotation

Parameters:
elementValue 
Returns:
Exceptions:
IllegalArgumentException when the element value is not a JAnnotation

References org.exolab.javasource.JAnnotation.getElementValueObject().

JAnnotation [] org.exolab.javasource.JAnnotation.getElementValueAnnotationList ( String  elementName  )  throws IllegalStateException

Returns the given annotation element value as a JAnnotation list

Parameters:
elementValue 
Returns:
Exceptions:
IllegalArgumentException when the element value is not a JAnnotation[]

References org.exolab.javasource.JAnnotation.getElementValueObject().

String [] org.exolab.javasource.JAnnotation.getElementValueList ( String  elementName  )  throws IllegalStateException

Returns the given annotation element value as a list

Parameters:
elementName 
Returns:
Exceptions:
IllegalArgumentException when the element value is not a String[]

References org.exolab.javasource.JAnnotation.getElementValueObject().

Object org.exolab.javasource.JAnnotation.getElementValueObject ( String  elementName  ) 
String org.exolab.javasource.JAnnotation.getValue (  ) 

Returns the "value" annotation element value

Returns:
Exceptions:
IllegalStateException when the element value is not a String

References org.exolab.javasource.JAnnotation.getElementValueObject(), and org.exolab.javasource.JAnnotation.value.

JAnnotation org.exolab.javasource.JAnnotation.getValueAnnotation (  )  throws IllegalStateException

Returns the "value" annotation element value as an JAnnotation

Returns:
Exceptions:
IllegalStateException when the element value is not a JAnnotation

References org.exolab.javasource.JAnnotation.getElementValueObject(), and org.exolab.javasource.JAnnotation.value.

static void org.exolab.javasource.JAnnotation.main ( String[]  args  )  [static]
void org.exolab.javasource.JAnnotation.print ( JSourceWriter  jsw  ) 
void org.exolab.javasource.JAnnotation.setElementValue ( String  elementName,
JAnnotation  annotationValue 
)

Sets the given annotation element value as an annotation

Parameters:
elementName 
annotationValue 

References org.exolab.castor.util.OrderedHashMap.put().

void org.exolab.javasource.JAnnotation.setElementValue ( String  elementName,
JAnnotation[]  annotationValues 
)

Sets the given annotation element values as a list of annotation values

Parameters:
elementName 
annotationValue 

References org.exolab.castor.util.OrderedHashMap.put().

void org.exolab.javasource.JAnnotation.setElementValue ( String  elementName,
String[]  stringValues 
)

Sets the given annotation element value as a list

Parameters:
elementName 
stringValue 

References org.exolab.castor.util.OrderedHashMap.put().

void org.exolab.javasource.JAnnotation.setElementValue ( String  elementName,
String  stringValue 
)

Sets the given annotation element value

Parameters:
elementName 
stringValue 

References org.exolab.castor.util.OrderedHashMap.put().

Referenced by org.exolab.javasource.JAnnotation.main().

void org.exolab.javasource.JAnnotation.setValue ( JAnnotation[]  annotationValues  ) 

Sets the "value" annotation element value as a list of annotation values

Parameters:
annotationValue 

References org.exolab.castor.util.OrderedHashMap.put(), and org.exolab.javasource.JAnnotation.value.

void org.exolab.javasource.JAnnotation.setValue ( String  stringValue  ) 

Sets the "value" annotation element value

Parameters:
stringValue 

References org.exolab.castor.util.OrderedHashMap.put(), and org.exolab.javasource.JAnnotation.value.

Referenced by org.exolab.javasource.JAnnotation.main().

void org.exolab.javasource.JAnnotation.setValue ( String[]  stringValue  ) 

Sets the "value" annotation element value as a list

Parameters:
stringValue 

References org.exolab.castor.util.OrderedHashMap.put(), and org.exolab.javasource.JAnnotation.value.

void org.exolab.javasource.JAnnotation.setValue ( JAnnotation  annotationValue  ) 

Sets the "value" annotation element value as an annotation

Parameters:
annotationValue 

References org.exolab.castor.util.OrderedHashMap.put(), and org.exolab.javasource.JAnnotation.value.


Member Data Documentation

final String org.exolab.javasource.JAnnotation.value = "value" [static]

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