Source Code Cross Referenced for ASMStackMapAttribute.java in  » Rule-Engine » drolls-Rule-Engine » org » drools » asm » util » attrs » 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 » Rule Engine » drolls Rule Engine » org.drools.asm.util.attrs 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * ASM: a very small and fast Java bytecode manipulation framework
003:         * Copyright (c) 2000-2005 INRIA, France Telecom
004:         * All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         * 1. Redistributions of source code must retain the above copyright
010:         *    notice, this list of conditions and the following disclaimer.
011:         * 2. Redistributions in binary form must reproduce the above copyright
012:         *    notice, this list of conditions and the following disclaimer in the
013:         *    documentation and/or other materials provided with the distribution.
014:         * 3. Neither the name of the copyright holders nor the names of its
015:         *    contributors may be used to endorse or promote products derived from
016:         *    this software without specific prior written permission.
017:         *
018:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019:         * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020:         * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021:         * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022:         * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023:         * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025:         * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026:         * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027:         * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
028:         * THE POSSIBILITY OF SUCH DAMAGE.
029:         */package org.drools.asm.util.attrs;
030:
031:        import java.util.List;
032:        import java.util.Map;
033:
034:        import org.drools.asm.Attribute;
035:        import org.drools.asm.ClassReader;
036:        import org.drools.asm.Label;
037:        import org.drools.asm.attrs.StackMapAttribute;
038:        import org.drools.asm.attrs.StackMapFrame;
039:        import org.drools.asm.attrs.StackMapType;
040:
041:        /**
042:         * An {@link ASMifiable} {@link StackMapAttribute} sub class.
043:         * 
044:         * @author Eugene Kuleshov
045:         */
046:        public class ASMStackMapAttribute extends StackMapAttribute implements 
047:                ASMifiable, Traceable {
048:            /**
049:             * Length of the attribute used for comparison
050:             */
051:            private int len;
052:
053:            public ASMStackMapAttribute() {
054:                super ();
055:            }
056:
057:            public ASMStackMapAttribute(final List frames, final int len) {
058:                super (frames);
059:                this .len = len;
060:            }
061:
062:            protected Attribute read(final ClassReader cr, final int off,
063:                    final int len, final char[] buf, final int codeOff,
064:                    final Label[] labels) {
065:                final StackMapAttribute attr = (StackMapAttribute) super .read(
066:                        cr, off, len, buf, codeOff, labels);
067:
068:                return new ASMStackMapAttribute(attr.getFrames(), len);
069:            }
070:
071:            public void asmify(final StringBuffer buf, final String varName,
072:                    final Map labelNames) {
073:                final List frames = getFrames();
074:                buf.append("{\n");
075:                buf.append("StackMapAttribute ").append(varName).append("Attr");
076:                buf.append(" = new StackMapAttribute();\n");
077:                if (frames.size() > 0) {
078:                    for (int i = 0; i < frames.size(); i++) {
079:                        asmify((StackMapFrame) frames.get(i), buf, varName
080:                                + "frame" + i, labelNames);
081:                    }
082:                }
083:                buf.append(varName).append(".visitAttribute(").append(varName);
084:                buf.append("Attr);\n}\n");
085:            }
086:
087:            void asmify(final StackMapFrame f, final StringBuffer buf,
088:                    final String varName, final Map labelNames) {
089:                declareLabel(buf, labelNames, f.label);
090:                buf.append("{\n");
091:
092:                buf.append("StackMapFrame ").append(varName).append(
093:                        " = new StackMapFrame();\n");
094:
095:                buf.append(varName).append(".label = ").append(
096:                        labelNames.get(f.label)).append(";\n");
097:
098:                asmifyTypeInfo(buf, varName, labelNames, f.locals, "locals");
099:                asmifyTypeInfo(buf, varName, labelNames, f.stack, "stack");
100:
101:                buf.append("cvAttr.frames.add(").append(varName).append(");\n");
102:                buf.append("}\n");
103:            }
104:
105:            void asmifyTypeInfo(final StringBuffer buf, final String varName,
106:                    final Map labelNames, final List infos, final String field) {
107:                if (infos.size() > 0) {
108:                    buf.append("{\n");
109:                    for (int i = 0; i < infos.size(); i++) {
110:                        final StackMapType typeInfo = (StackMapType) infos
111:                                .get(i);
112:                        final String localName = varName + "Info" + i;
113:                        final int type = typeInfo.getType();
114:                        buf
115:                                .append("StackMapType ")
116:                                .append(localName)
117:                                .append(
118:                                        " = StackMapType.getTypeInfo( StackMapType.ITEM_")
119:                                .append(StackMapType.ITEM_NAMES[type]).append(
120:                                        ");\n");
121:
122:                        switch (type) {
123:                        case StackMapType.ITEM_Object: //
124:                            buf.append(localName).append(".setObject(\"")
125:                                    .append(typeInfo.getObject()).append(
126:                                            "\");\n");
127:                            break;
128:
129:                        case StackMapType.ITEM_Uninitialized: //
130:                            declareLabel(buf, labelNames, typeInfo.getLabel());
131:                            buf.append(localName).append(".setLabel(").append(
132:                                    labelNames.get(typeInfo.getLabel()))
133:                                    .append(");\n");
134:                            break;
135:                        }
136:                        buf.append(varName).append(".").append(field).append(
137:                                ".add(").append(localName).append(");\n");
138:                    }
139:                    buf.append("}\n");
140:                }
141:            }
142:
143:            static void declareLabel(final StringBuffer buf,
144:                    final Map labelNames, final Label l) {
145:                String name = (String) labelNames.get(l);
146:                if (name == null) {
147:                    name = "l" + labelNames.size();
148:                    labelNames.put(l, name);
149:                    buf.append("Label ").append(name).append(
150:                            " = new Label();\n");
151:                }
152:            }
153:
154:            public void trace(final StringBuffer buf, final Map labelNames) {
155:                final List frames = getFrames();
156:                buf.append("[\n");
157:                for (int i = 0; i < frames.size(); i++) {
158:                    final StackMapFrame f = (StackMapFrame) frames.get(i);
159:
160:                    buf.append("    Frame:");
161:                    appendLabel(buf, labelNames, f.label);
162:
163:                    buf.append(" locals[");
164:                    traceTypeInfo(buf, labelNames, f.locals);
165:                    buf.append("]");
166:                    buf.append(" stack[");
167:                    traceTypeInfo(buf, labelNames, f.stack);
168:                    buf.append("]\n");
169:                }
170:                buf.append("  ] length:").append(this .len).append("\n");
171:            }
172:
173:            private void traceTypeInfo(final StringBuffer buf,
174:                    final Map labelNames, final List infos) {
175:                String sep = "";
176:                for (int i = 0; i < infos.size(); i++) {
177:                    final StackMapType t = (StackMapType) infos.get(i);
178:
179:                    buf.append(sep)
180:                            .append(StackMapType.ITEM_NAMES[t.getType()]);
181:                    sep = ", ";
182:                    if (t.getType() == StackMapType.ITEM_Object) {
183:                        buf.append(":").append(t.getObject());
184:                    }
185:                    if (t.getType() == StackMapType.ITEM_Uninitialized) {
186:                        buf.append(":");
187:                        appendLabel(buf, labelNames, t.getLabel());
188:                    }
189:                }
190:            }
191:
192:            protected void appendLabel(final StringBuffer buf,
193:                    final Map labelNames, final Label l) {
194:                String name = (String) labelNames.get(l);
195:                if (name == null) {
196:                    name = "L" + labelNames.size();
197:                    labelNames.put(l, name);
198:                }
199:                buf.append(name);
200:            }
201:
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.