Source Code Cross Referenced for AnnotationDefaultAttribute.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 Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Javassist, a Java-bytecode translator toolkit.
003:         * Copyright (C) 1999-2006 Shigeru Chiba. All Rights Reserved.
004:         *
005:         * The contents of this file are subject to the Mozilla Public License Version
006:         * 1.1 (the "License"); you may not use this file except in compliance with
007:         * the License.  Alternatively, the contents of this file may be used under
008:         * the terms of the GNU Lesser General Public License Version 2.1 or later.
009:         *
010:         * Software distributed under the License is distributed on an "AS IS" basis,
011:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
012:         * for the specific language governing rights and limitations under the
013:         * License.
014:         */
015:
016:        package javassist.bytecode;
017:
018:        import javassist.CtClass;
019:        import javassist.bytecode.annotation.AnnotationsWriter;
020:        import javassist.bytecode.annotation.MemberValue;
021:
022:        import java.io.ByteArrayOutputStream;
023:        import java.io.DataInputStream;
024:        import java.io.IOException;
025:        import java.util.Map;
026:
027:        /**
028:         * A class representing <code>AnnotationDefault_attribute</code>.
029:         *
030:         * <p>For example, if you declare the following annotation type:
031:         *
032:         * <ul><pre>
033:         * &#64;interface Author {
034:         *   String name() default "Shakespeare";
035:         *   int age() default 99;
036:         * }
037:         * </pre></ul>
038:         *
039:         * <p>The defautl values of <code>name</code> and <code>age</code>
040:         * are stored as annotation default attributes in <code>Author.class</code>.
041:         * The following code snippet obtains the default value of <code>name</code>:
042:         * 
043:         * <ul><pre>
044:         * ClassPool pool = ...
045:         * CtClass cc = pool.get("Author");
046:         * CtMethod cm = cc.getDeclaredMethod("age");
047:         * MethodInfo minfo = cm.getMethodInfo();
048:         * AnnotationDefaultAttribute ada
049:         *         = (AnnotationDefaultAttribute)
050:         *           minfo.getAttribute(AnnotationDefaultAttribute.tag);
051:         * MemberValue value = ada.getDefaultValue());    // default value of age
052:         * </pre></ul>
053:         *
054:         * <p>If the following statement is executed after the code above,
055:         * the default value of age is set to 80:
056:         *
057:         * <ul><pre>
058:         * ada.setDefaultValue(new IntegerMemberValue(minfo.getConstPool(), 80));
059:         * </pre></ul>
060:         *
061:         * @see AnnotationsAttribute
062:         * @see javassist.bytecode.annotation.MemberValue
063:         */
064:
065:        public class AnnotationDefaultAttribute extends AttributeInfo {
066:            /**
067:             * The name of the <code>AnnotationDefault</code> attribute.
068:             */
069:            public static final String tag = "AnnotationDefault";
070:
071:            /**
072:             * Constructs an <code>AnnotationDefault_attribute</code>.
073:             *
074:             * @param cp            constant pool
075:             * @param info          the contents of this attribute.  It does not
076:             *                      include <code>attribute_name_index</code> or
077:             *                      <code>attribute_length</code>.
078:             */
079:            public AnnotationDefaultAttribute(ConstPool cp, byte[] info) {
080:                super (cp, tag, info);
081:            }
082:
083:            /**
084:             * Constructs an empty <code>AnnotationDefault_attribute</code>.
085:             * The default value can be set by <code>setDefaultValue()</code>.
086:             *
087:             * @param cp            constant pool
088:             * @see #setDefaultValue(javassist.bytecode.annotation.MemberValue)
089:             */
090:            public AnnotationDefaultAttribute(ConstPool cp) {
091:                this (cp, new byte[] { 0, 0 });
092:            }
093:
094:            /**
095:             * @param n     the attribute name.
096:             */
097:            AnnotationDefaultAttribute(ConstPool cp, int n, DataInputStream in)
098:                    throws IOException {
099:                super (cp, n, in);
100:            }
101:
102:            /**
103:             * Copies this attribute and returns a new copy.
104:             */
105:            public AttributeInfo copy(ConstPool newCp, Map classnames) {
106:                AnnotationsAttribute.Copier copier = new AnnotationsAttribute.Copier(
107:                        info, constPool, newCp, classnames);
108:                try {
109:                    copier.memberValue(0);
110:                    return new AnnotationDefaultAttribute(newCp, copier.close());
111:                } catch (Exception e) {
112:                    throw new RuntimeException(e.toString());
113:                }
114:            }
115:
116:            /**
117:             * Obtains the default value represented by this attribute.
118:             */
119:            public MemberValue getDefaultValue() {
120:                try {
121:                    return new AnnotationsAttribute.Parser(info, constPool)
122:                            .parseMemberValue();
123:                } catch (Exception e) {
124:                    throw new RuntimeException(e.toString());
125:                }
126:            }
127:
128:            /**
129:             * Changes the default value represented by this attribute.
130:             *
131:             * @param value         the new value.
132:             * @see javassist.bytecode.annotation.Annotation#createMemberValue(ConstPool, CtClass)
133:             */
134:            public void setDefaultValue(MemberValue value) {
135:                ByteArrayOutputStream output = new ByteArrayOutputStream();
136:                AnnotationsWriter writer = new AnnotationsWriter(output,
137:                        constPool);
138:                try {
139:                    value.write(writer);
140:                    writer.close();
141:                } catch (IOException e) {
142:                    throw new RuntimeException(e); // should never reach here.
143:                }
144:
145:                set(output.toByteArray());
146:
147:            }
148:
149:            /**
150:             * Returns a string representation of this object.
151:             */
152:            public String toString() {
153:                return getDefaultValue().toString();
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.