Java Doc for AnnotationsAttribute.java in  » Byte-Code » Javassist » javassist » bytecode » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Byte Code » Javassist » javassist.bytecode 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   javassist.bytecode.AttributeInfo
      javassist.bytecode.AnnotationsAttribute

AnnotationsAttribute
public class AnnotationsAttribute extends AttributeInfo (Code)
A class representing RuntimeVisibleAnnotations_attribute and RuntimeInvisibleAnnotations_attribute.

To obtain an AnnotationAttribute object, invoke getAttribute(AnnotationsAttribute.visibleTag) in ClassFile, MethodInfo, or FieldInfo. The obtained attribute is a runtime visible annotations attribute. If the parameter is AnnotationAttribute.invisibleTag, then the obtained attribute is a runtime invisible one.

For example,

     import javassist.bytecode.annotation.Annotation;
     :
     CtMethod m = ... ;
     MethodInfo minfo = m.getMethodInfo();
     AnnotationsAttribute attr = (AnnotationsAttribute)
     minfo.getAttribute(AnnotationsAttribute.invisibleTag);
     Annotation an = attr.getAnnotation("Author");
     String s = ((StringMemberValue)an.getMemberValue("name")).getValue();
     System.out.println("@Author(name=" + s + ")");
     

This code snippet retrieves an annotation of the type Author from the MethodInfo object specified by minfo. Then, it prints the value of name in Author.

If the annotation type Author is annotated by a meta annotation:

     @Retention(RetentionPolicy.RUNTIME)
     

Then Author is visible at runtime. Therefore, the third statement of the code snippet above must be changed into:

     AnnotationsAttribute attr = (AnnotationsAttribute)
     minfo.getAttribute(AnnotationsAttribute.visibleTag);
     

The attribute tag must be visibleTag instead of invisibleTag.

If the member value of an annotation is not specified, the default value is used as that member value. If so, getMemberValue() in Annotation returns null since the default value is not included in the AnnotationsAttribute. It is included in the AnnotationDefaultAttribute of the method declared in the annotation type.

If you want to record a new AnnotationAttribute object, execute the following snippet:

     ClassFile cf = ... ;
     ConstPool cp = cf.getConstPool();
     AnnotationsAttribute attr
     = new AnnotationsAttribute(cp, AnnotationsAttribute.visibleTag);
     Annotation a = new Annotation("Author", cp);
     a.addMemberValue("name", new StringMemberValue("Chiba", cp));
     attr.setAnnotation(a);
     cf.addAttribute(attr);
     cf.setVersionToJava5();
     

The last statement is necessary if the class file was produced by Javassist or JDK 1.4. Otherwise, it is not necessary.
See Also:   AnnotationDefaultAttribute
See Also:   javassist.bytecode.annotation.Annotation


Inner Class :static class Walker
Inner Class :static class Copier extends Walker
Inner Class :static class Parser extends Walker

Field Summary
final public static  StringinvisibleTag
     The name of the RuntimeInvisibleAnnotations attribute.
final public static  StringvisibleTag
     The name of the RuntimeVisibleAnnotations attribute.

Constructor Summary
public  AnnotationsAttribute(ConstPool cp, String attrname, byte[] info)
     Constructs a Runtime(In)VisisbleAnnotations_attribute.
Parameters:
  cp - constant pool
Parameters:
  attrname - attribute name (visibleTag orinvisibleTag).
Parameters:
  info - the contents of this attribute.
public  AnnotationsAttribute(ConstPool cp, String attrname)
     Constructs an empty Runtime(In)VisisbleAnnotations_attribute.
 AnnotationsAttribute(ConstPool cp, int n, DataInputStream in)
    

Method Summary
public  voidaddAnnotation(Annotation annotation)
     Adds an annotation.
public  AttributeInfocopy(ConstPool newCp, Map classnames)
     Copies this attribute and returns a new copy.
public  AnnotationgetAnnotation(String type)
     Parses the annotations and returns a data structure representing the annotation with the specified type.
public  Annotation[]getAnnotations()
     Parses the annotations and returns a data structure representing that parsed annotations.
public  intnumAnnotations()
     Returns num_annotations.
public  voidsetAnnotation(Annotation annotation)
     Changes the annotations.
public  voidsetAnnotations(Annotation[] annotations)
     Changes the annotations represented by this object according to the given array of Annotation objects.
public  StringtoString()
     Returns a string representation of this object.

Field Detail
invisibleTag
final public static String invisibleTag(Code)
The name of the RuntimeInvisibleAnnotations attribute.



visibleTag
final public static String visibleTag(Code)
The name of the RuntimeVisibleAnnotations attribute.




Constructor Detail
AnnotationsAttribute
public AnnotationsAttribute(ConstPool cp, String attrname, byte[] info)(Code)
Constructs a Runtime(In)VisisbleAnnotations_attribute.
Parameters:
  cp - constant pool
Parameters:
  attrname - attribute name (visibleTag orinvisibleTag).
Parameters:
  info - the contents of this attribute. It does notinclude attribute_name_index orattribute_length.



AnnotationsAttribute
public AnnotationsAttribute(ConstPool cp, String attrname)(Code)
Constructs an empty Runtime(In)VisisbleAnnotations_attribute. A new annotation can be later added to the created attribute by setAnnotations().
Parameters:
  cp - constant pool
Parameters:
  attrname - attribute name (visibleTag orinvisibleTag).
See Also:   AnnotationsAttribute.setAnnotations(Annotation[])



AnnotationsAttribute
AnnotationsAttribute(ConstPool cp, int n, DataInputStream in) throws IOException(Code)

Parameters:
  n - the attribute name.




Method Detail
addAnnotation
public void addAnnotation(Annotation annotation)(Code)
Adds an annotation. If there is an annotation with the same type, it is removed before the new annotation is added.
Parameters:
  annotation - the added annotation.



copy
public AttributeInfo copy(ConstPool newCp, Map classnames)(Code)
Copies this attribute and returns a new copy.



getAnnotation
public Annotation getAnnotation(String type)(Code)
Parses the annotations and returns a data structure representing the annotation with the specified type. See also getAnnotations() as to the returned data structure.
Parameters:
  type - the annotation type. null if the specified annotation type is not included.
See Also:   AnnotationsAttribute.getAnnotations()



getAnnotations
public Annotation[] getAnnotations()(Code)
Parses the annotations and returns a data structure representing that parsed annotations. Note that changes of the node values of the returned tree are not reflected on the annotations represented by this object unless the tree is copied back to this object by setAnnotations().
See Also:   AnnotationsAttribute.setAnnotations(Annotation[])



numAnnotations
public int numAnnotations()(Code)
Returns num_annotations.



setAnnotation
public void setAnnotation(Annotation annotation)(Code)
Changes the annotations. A call to this method is equivalent to:
    setAnnotations(new Annotation[] { annotation })

Parameters:
  annotation - the data structure representingthe new annotation.



setAnnotations
public void setAnnotations(Annotation[] annotations)(Code)
Changes the annotations represented by this object according to the given array of Annotation objects.
Parameters:
  annotations - the data structure representing thenew annotations.



toString
public String toString()(Code)
Returns a string representation of this object.



Fields inherited from javassist.bytecode.AttributeInfo
protected ConstPool constPool(Code)(Java Doc)
byte[] info(Code)(Java Doc)
int name(Code)(Java Doc)

Methods inherited from javassist.bytecode.AttributeInfo
public AttributeInfo copy(ConstPool newCp, Map classnames)(Code)(Java Doc)
static LinkedList copyAll(LinkedList list, ConstPool cp)(Code)(Java Doc)
public byte[] get()(Code)(Java Doc)
public ConstPool getConstPool()(Code)(Java Doc)
static int getLength(LinkedList list)(Code)(Java Doc)
public String getName()(Code)(Java Doc)
public int length()(Code)(Java Doc)
static AttributeInfo lookup(LinkedList list, String name)(Code)(Java Doc)
static AttributeInfo read(ConstPool cp, DataInputStream in) throws IOException(Code)(Java Doc)
static synchronized void remove(LinkedList list, String name)(Code)(Java Doc)
public void set(byte[] newinfo)(Code)(Java Doc)
void write(DataOutputStream out) throws IOException(Code)(Java Doc)
static void writeAll(LinkedList list, DataOutputStream out) throws IOException(Code)(Java Doc)

Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.