Source Code Cross Referenced for KeyPattern.java in  » XML » XPath-Saxon » net » sf » saxon » pattern » 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 » XPath Saxon » net.sf.saxon.pattern 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sf.saxon.pattern;
002:
003:        import net.sf.saxon.expr.Expression;
004:        import net.sf.saxon.expr.StaticContext;
005:        import net.sf.saxon.expr.XPathContext;
006:        import net.sf.saxon.expr.PromotionOffer;
007:        import net.sf.saxon.om.DocumentInfo;
008:        import net.sf.saxon.om.Item;
009:        import net.sf.saxon.om.NodeInfo;
010:        import net.sf.saxon.om.SequenceIterator;
011:        import net.sf.saxon.trans.KeyManager;
012:        import net.sf.saxon.trans.XPathException;
013:        import net.sf.saxon.type.ItemType;
014:        import net.sf.saxon.value.AtomicValue;
015:
016:        import java.util.Iterator;
017:
018:        /**
019:         * A KeyPattern is a pattern of the form key(keyname, keyvalue)
020:         */
021:
022:        public final class KeyPattern extends Pattern {
023:
024:            private int keyfingerprint; // the fingerprint of the key name
025:            private Expression keyexp; // the value of the key
026:
027:            /**
028:             * Constructor
029:             * @param namecode the name of the key
030:             * @param key the value of the key: either a StringValue or a VariableReference
031:             */
032:
033:            public KeyPattern(int namecode, Expression key) {
034:                keyfingerprint = namecode & 0xfffff;
035:                keyexp = key;
036:            }
037:
038:            /**
039:             * Type-check the pattern. This is needed for patterns that contain
040:             * variable references or function calls.
041:             * @return the optimised Pattern
042:             */
043:
044:            public Pattern analyze(StaticContext env, ItemType contextItemType)
045:                    throws XPathException {
046:                keyexp = keyexp.typeCheck(env, contextItemType);
047:                return this ;
048:            }
049:
050:            /**
051:             * Get the dependencies of the pattern. The only possible dependency for a pattern is
052:             * on local variables. This is analyzed in those patterns where local variables may appear.
053:             */
054:
055:            public int getDependencies() {
056:                return keyexp.getDependencies();
057:            }
058:
059:            /**
060:             * Iterate over the subexpressions within this pattern
061:             */
062:
063:            public Iterator iterateSubExpressions() {
064:                return keyexp.iterateSubExpressions();
065:            }
066:
067:            /**
068:             * Offer promotion for subexpressions within this pattern. The offer will be accepted if the subexpression
069:             * is not dependent on the factors (e.g. the context item) identified in the PromotionOffer.
070:             * By default the offer is not accepted - this is appropriate in the case of simple expressions
071:             * such as constant values and variable references where promotion would give no performance
072:             * advantage. This method is always called at compile time.
073:             * <p/>
074:             * <p>Unlike the corresponding method on {@link net.sf.saxon.expr.Expression}, this method does not return anything:
075:             * it can make internal changes to the pattern, but cannot return a different pattern. Only certain
076:             * kinds of promotion are applicable within a pattern: specifically, promotions affecting local
077:             * variable references within the pattern.
078:             *
079:             * @param offer details of the offer, for example the offer to move
080:             *              expressions that don't depend on the context to an outer level in
081:             *              the containing expression
082:             * @throws net.sf.saxon.trans.XPathException
083:             *          if any error is detected
084:             */
085:
086:            public void promote(PromotionOffer offer) throws XPathException {
087:                keyexp = keyexp.promote(offer);
088:            }
089:
090:            /**
091:             * Determine whether this Pattern matches the given Node.
092:             * @param e The NodeInfo representing the Element or other node to be tested against the Pattern
093:             * @return true if the node matches the Pattern, false otherwise
094:             */
095:
096:            public boolean matches(NodeInfo e, XPathContext context)
097:                    throws XPathException {
098:                DocumentInfo doc = e.getDocumentRoot();
099:                if (doc == null) {
100:                    return false;
101:                }
102:                KeyManager km = context.getController().getKeyManager();
103:                SequenceIterator iter = keyexp.iterate(context);
104:                while (true) {
105:                    Item it = iter.next();
106:                    if (it == null) {
107:                        return false;
108:                    }
109:                    SequenceIterator nodes = km.selectByKey(keyfingerprint,
110:                            doc, (AtomicValue) it, context);
111:                    while (true) {
112:                        NodeInfo n = (NodeInfo) nodes.next();
113:                        if (n == null) {
114:                            break;
115:                        }
116:                        if (n.isSameNodeInfo(e)) {
117:                            return true;
118:                        }
119:                    }
120:                }
121:            }
122:
123:            /**
124:             * Get a NodeTest that all the nodes matching this pattern must satisfy
125:             */
126:
127:            public NodeTest getNodeTest() {
128:                return AnyNodeTest.getInstance();
129:            }
130:
131:        }
132:
133:        //
134:        // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
135:        // you may not use this file except in compliance with the License. You may obtain a copy of the
136:        // License at http://www.mozilla.org/MPL/
137:        //
138:        // Software distributed under the License is distributed on an "AS IS" basis,
139:        // WITHOUT WARRANTY OF ANY KIND, either express or implied.
140:        // See the License for the specific language governing rights and limitations under the License.
141:        //
142:        // The Original Code is: all this file.
143:        //
144:        // The Initial Developer of the Original Code is Michael H. Kay.
145:        //
146:        // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
147:        //
148:        // Contributor(s): none.
149:        //
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.