Source Code Cross Referenced for ForEach.java in  » XML » xalan » org » apache » xalan » xsltc » compiler » 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 » XML » xalan » org.apache.xalan.xsltc.compiler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2004 The Apache Software Foundation.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        /*
017:         * $Id: ForEach.java,v 1.19 2004/02/16 22:24:29 minchau Exp $
018:         */
019:
020:        package org.apache.xalan.xsltc.compiler;
021:
022:        import java.util.Enumeration;
023:        import java.util.Vector;
024:
025:        import org.apache.bcel.generic.BranchHandle;
026:        import org.apache.bcel.generic.ConstantPoolGen;
027:        import org.apache.bcel.generic.GOTO;
028:        import org.apache.bcel.generic.IFGT;
029:        import org.apache.bcel.generic.InstructionHandle;
030:        import org.apache.bcel.generic.InstructionList;
031:        import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
032:        import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
033:        import org.apache.xalan.xsltc.compiler.util.MethodGenerator;
034:        import org.apache.xalan.xsltc.compiler.util.NodeSetType;
035:        import org.apache.xalan.xsltc.compiler.util.NodeType;
036:        import org.apache.xalan.xsltc.compiler.util.ReferenceType;
037:        import org.apache.xalan.xsltc.compiler.util.ResultTreeType;
038:        import org.apache.xalan.xsltc.compiler.util.Type;
039:        import org.apache.xalan.xsltc.compiler.util.TypeCheckError;
040:        import org.apache.xalan.xsltc.compiler.util.Util;
041:
042:        /**
043:         * @author Jacek Ambroziak
044:         * @author Santiago Pericas-Geertsen
045:         * @author Morten Jorgensen
046:         */
047:        final class ForEach extends Instruction {
048:
049:            private Expression _select;
050:            private Type _type;
051:
052:            public void display(int indent) {
053:                indent(indent);
054:                Util.println("ForEach");
055:                indent(indent + IndentIncrement);
056:                Util.println("select " + _select.toString());
057:                displayContents(indent + IndentIncrement);
058:            }
059:
060:            public void parseContents(Parser parser) {
061:                _select = parser.parseExpression(this , "select", null);
062:
063:                parseChildren(parser);
064:
065:                // make sure required attribute(s) have been set
066:                if (_select.isDummy()) {
067:                    reportError(this , parser, ErrorMsg.REQUIRED_ATTR_ERR,
068:                            "select");
069:                }
070:            }
071:
072:            public Type typeCheck(SymbolTable stable) throws TypeCheckError {
073:                _type = _select.typeCheck(stable);
074:
075:                if (_type instanceof  ReferenceType || _type instanceof  NodeType) {
076:                    _select = new CastExpr(_select, Type.NodeSet);
077:                    typeCheckContents(stable);
078:                    return Type.Void;
079:                }
080:                if (_type instanceof  NodeSetType
081:                        || _type instanceof  ResultTreeType) {
082:                    typeCheckContents(stable);
083:                    return Type.Void;
084:                }
085:                throw new TypeCheckError(this );
086:            }
087:
088:            public void translate(ClassGenerator classGen,
089:                    MethodGenerator methodGen) {
090:                final ConstantPoolGen cpg = classGen.getConstantPool();
091:                final InstructionList il = methodGen.getInstructionList();
092:
093:                // Save current node and current iterator on the stack
094:                il.append(methodGen.loadCurrentNode());
095:                il.append(methodGen.loadIterator());
096:
097:                // Collect sort objects associated with this instruction
098:                final Vector sortObjects = new Vector();
099:                Enumeration children = elements();
100:                while (children.hasMoreElements()) {
101:                    final Object child = children.nextElement();
102:                    if (child instanceof  Sort) {
103:                        sortObjects.addElement(child);
104:                    }
105:                }
106:
107:                if ((_type != null) && (_type instanceof  ResultTreeType)) {
108:                    // Store existing DOM on stack - must be restored when loop is done
109:                    il.append(methodGen.loadDOM());
110:
111:                    // <xsl:sort> cannot be applied to a result tree - issue warning
112:                    if (sortObjects.size() > 0) {
113:                        ErrorMsg msg = new ErrorMsg(
114:                                ErrorMsg.RESULT_TREE_SORT_ERR, this );
115:                        getParser().reportError(WARNING, msg);
116:                    }
117:
118:                    // Put the result tree on the stack (DOM)
119:                    _select.translate(classGen, methodGen);
120:                    // Get an iterator for the whole DOM - excluding the root node
121:                    _type.translateTo(classGen, methodGen, Type.NodeSet);
122:                    // Store the result tree as the default DOM
123:                    il.append(SWAP);
124:                    il.append(methodGen.storeDOM());
125:                } else {
126:                    // Compile node iterator
127:                    if (sortObjects.size() > 0) {
128:                        Sort.translateSortIterator(classGen, methodGen,
129:                                _select, sortObjects);
130:                    } else {
131:                        _select.translate(classGen, methodGen);
132:                    }
133:
134:                    if (_type instanceof  ReferenceType == false) {
135:                        il.append(methodGen.loadContextNode());
136:                        il.append(methodGen.setStartNode());
137:                    }
138:                }
139:
140:                // Overwrite current iterator
141:                il.append(methodGen.storeIterator());
142:
143:                // Give local variables (if any) default values before starting loop
144:                initializeVariables(classGen, methodGen);
145:
146:                final BranchHandle nextNode = il.append(new GOTO(null));
147:                final InstructionHandle loop = il.append(NOP);
148:
149:                translateContents(classGen, methodGen);
150:
151:                nextNode.setTarget(il.append(methodGen.loadIterator()));
152:                il.append(methodGen.nextNode());
153:                il.append(DUP);
154:                il.append(methodGen.storeCurrentNode());
155:                il.append(new IFGT(loop));
156:
157:                // Restore current DOM (if result tree was used instead for this loop)
158:                if ((_type != null) && (_type instanceof  ResultTreeType)) {
159:                    il.append(methodGen.storeDOM());
160:                }
161:
162:                // Restore current node and current iterator from the stack
163:                il.append(methodGen.storeIterator());
164:                il.append(methodGen.storeCurrentNode());
165:            }
166:
167:            /**
168:             * The code that is generated by nested for-each loops can appear to some
169:             * JVMs as if it is accessing un-initialized variables. We must add some
170:             * code that pushes the default variable value on the stack and pops it
171:             * into the variable slot. This is done by the Variable.initialize()
172:             * method. The code that we compile for this loop looks like this:
173:             *
174:             *           initialize iterator
175:             *           initialize variables <-- HERE!!!
176:             *           goto   Iterate
177:             *  Loop:    :
178:             *           : (code for <xsl:for-each> contents)
179:             *           :
180:             *  Iterate: node = iterator.next();
181:             *           if (node != END) goto Loop
182:             */
183:            public void initializeVariables(ClassGenerator classGen,
184:                    MethodGenerator methodGen) {
185:                final int n = elementCount();
186:                for (int i = 0; i < n; i++) {
187:                    final Object child = getContents().elementAt(i);
188:                    if (child instanceof  Variable) {
189:                        Variable var = (Variable) child;
190:                        var.initialize(classGen, methodGen);
191:                    }
192:                }
193:            }
194:
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.