Source Code Cross Referenced for Selector.java in  » XML » xerces-2_9_1 » org » apache » xerces » impl » xs » identity » 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 » xerces 2_9_1 » org.apache.xerces.impl.xs.identity 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        package org.apache.xerces.impl.xs.identity;
019:
020:        import org.apache.xerces.impl.xpath.XPathException;
021:        import org.apache.xerces.util.SymbolTable;
022:        import org.apache.xerces.util.XMLChar;
023:        import org.apache.xerces.xni.NamespaceContext;
024:        import org.apache.xerces.xni.QName;
025:        import org.apache.xerces.xni.XMLAttributes;
026:        import org.apache.xerces.xs.ShortList;
027:        import org.apache.xerces.xs.XSTypeDefinition;
028:
029:        /**
030:         * Schema identity constraint selector.
031:         *
032:         * @xerces.internal 
033:         *
034:         * @author Andy Clark, IBM
035:         * @version $Id: Selector.java 572110 2007-09-02 19:04:44Z mrglavas $
036:         */
037:        public class Selector {
038:
039:            //
040:            // Data
041:            //
042:
043:            /** XPath. */
044:            protected final Selector.XPath fXPath;
045:
046:            /** Identity constraint. */
047:            protected final IdentityConstraint fIdentityConstraint;
048:
049:            // the Identity constraint we're the matcher for.  Only
050:            // used for selectors!
051:            protected IdentityConstraint fIDConstraint;
052:
053:            //
054:            // Constructors
055:            //
056:
057:            /** Constructs a selector. */
058:            public Selector(Selector.XPath xpath,
059:                    IdentityConstraint identityConstraint) {
060:                fXPath = xpath;
061:                fIdentityConstraint = identityConstraint;
062:            } // <init>(Selector.XPath,IdentityConstraint)
063:
064:            //
065:            // Public methods
066:            //
067:
068:            /** Returns the selector XPath. */
069:            public org.apache.xerces.impl.xpath.XPath getXPath() {
070:                return fXPath;
071:            } // getXPath():org.apache.xerces.v1.schema.identity.XPath
072:
073:            /** Returns the identity constraint. */
074:            public IdentityConstraint getIDConstraint() {
075:                return fIdentityConstraint;
076:            } // getIDConstraint():IdentityConstraint
077:
078:            // factory method
079:
080:            /** Creates a selector matcher. 
081:             * @param activator     The activator for this selector's fields.
082:             * @param initialDepth  The depth in the document at which this matcher began its life;
083:             *                          used in correctly handling recursive elements.
084:             */
085:            public XPathMatcher createMatcher(FieldActivator activator,
086:                    int initialDepth) {
087:                return new Selector.Matcher(fXPath, activator, initialDepth);
088:            } // createMatcher(FieldActivator):XPathMatcher
089:
090:            //
091:            // Object methods
092:            //
093:
094:            /** Returns a string representation of this object. */
095:            public String toString() {
096:                return fXPath.toString();
097:            } // toString():String
098:
099:            //
100:            // Classes
101:            //
102:
103:            /**
104:             * Schema identity constraint selector XPath expression.
105:             *
106:             * @author Andy Clark, IBM
107:             * @version $Id: Selector.java 572110 2007-09-02 19:04:44Z mrglavas $
108:             */
109:            public static class XPath extends
110:                    org.apache.xerces.impl.xpath.XPath {
111:
112:                //
113:                // Constructors
114:                //
115:
116:                /** Constructs a selector XPath expression. */
117:                public XPath(String xpath, SymbolTable symbolTable,
118:                        NamespaceContext context) throws XPathException {
119:                    super (normalize(xpath), symbolTable, context);
120:                    // verify that an attribute is not selected
121:                    for (int i = 0; i < fLocationPaths.length; i++) {
122:                        org.apache.xerces.impl.xpath.XPath.Axis axis = fLocationPaths[i].steps[fLocationPaths[i].steps.length - 1].axis;
123:                        if (axis.type == XPath.Axis.ATTRIBUTE) {
124:                            throw new XPathException("c-selector-xpath");
125:                        }
126:                    }
127:
128:                } // <init>(String,SymbolTable,NamespacesScope)
129:
130:                private static String normalize(String xpath) {
131:                    // NOTE: We have to prefix the selector XPath with "./" in
132:                    //       order to handle selectors such as "." that select
133:                    //       the element container because the fields could be
134:                    //       relative to that element. -Ac
135:                    //       Unless xpath starts with a descendant node -Achille Fokoue
136:                    //      ... or a '.' or a '/' - NG
137:                    //  And we also need to prefix exprs to the right of | with ./ - NG
138:                    StringBuffer modifiedXPath = new StringBuffer(xpath
139:                            .length() + 5);
140:                    int unionIndex = -1;
141:                    do {
142:                        if (!(XMLChar.trim(xpath).startsWith("/") || XMLChar
143:                                .trim(xpath).startsWith("."))) {
144:                            modifiedXPath.append("./");
145:                        }
146:                        unionIndex = xpath.indexOf('|');
147:                        if (unionIndex == -1) {
148:                            modifiedXPath.append(xpath);
149:                            break;
150:                        }
151:                        modifiedXPath
152:                                .append(xpath.substring(0, unionIndex + 1));
153:                        xpath = xpath.substring(unionIndex + 1, xpath.length());
154:                    } while (true);
155:                    return modifiedXPath.toString();
156:                }
157:
158:            } // class Selector.XPath
159:
160:            /**
161:             * Selector matcher.
162:             *
163:             * @author Andy Clark, IBM
164:             */
165:            public class Matcher extends XPathMatcher {
166:
167:                //
168:                // Data
169:                //
170:
171:                /** Field activator. */
172:                protected final FieldActivator fFieldActivator;
173:
174:                /** Initial depth in the document at which this matcher was created. */
175:                protected final int fInitialDepth;
176:
177:                /** Element depth. */
178:                protected int fElementDepth;
179:
180:                /** Depth at match. */
181:                protected int fMatchedDepth;
182:
183:                //
184:                // Constructors
185:                //
186:
187:                /** Constructs a selector matcher. */
188:                public Matcher(Selector.XPath xpath, FieldActivator activator,
189:                        int initialDepth) {
190:                    super (xpath);
191:                    fFieldActivator = activator;
192:                    fInitialDepth = initialDepth;
193:                } // <init>(Selector.XPath,FieldActivator)
194:
195:                //
196:                // XMLDocumentFragmentHandler methods
197:                //
198:
199:                public void startDocumentFragment() {
200:                    super .startDocumentFragment();
201:                    fElementDepth = 0;
202:                    fMatchedDepth = -1;
203:                } // startDocumentFragment()
204:
205:                /**
206:                 * The start of an element. If the document specifies the start element
207:                 * by using an empty tag, then the startElement method will immediately
208:                 * be followed by the endElement method, with no intervening methods.
209:                 * 
210:                 * @param element    The name of the element.
211:                 * @param attributes The element attributes. 
212:                 *
213:                 */
214:                public void startElement(QName element, XMLAttributes attributes) {
215:                    super .startElement(element, attributes);
216:                    fElementDepth++;
217:                    // activate the fields, if selector is matched
218:                    //int matched = isMatched();
219:
220:                    if (isMatched()) {
221:                        /*            (fMatchedDepth == -1 && ((matched & MATCHED) == MATCHED)) ||
222:                         ((matched & MATCHED_DESCENDANT) == MATCHED_DESCENDANT)) { */
223:                        fMatchedDepth = fElementDepth;
224:                        fFieldActivator.startValueScopeFor(fIdentityConstraint,
225:                                fInitialDepth);
226:                        int count = fIdentityConstraint.getFieldCount();
227:                        for (int i = 0; i < count; i++) {
228:                            Field field = fIdentityConstraint.getFieldAt(i);
229:                            XPathMatcher matcher = fFieldActivator
230:                                    .activateField(field, fInitialDepth);
231:                            matcher.startElement(element, attributes);
232:                        }
233:                    }
234:
235:                } // startElement(QName,XMLAttrList,int)
236:
237:                public void endElement(QName element, XSTypeDefinition type,
238:                        boolean nillable, Object actualValue, short valueType,
239:                        ShortList itemValueType) {
240:                    super .endElement(element, type, nillable, actualValue,
241:                            valueType, itemValueType);
242:                    if (fElementDepth-- == fMatchedDepth) {
243:                        fMatchedDepth = -1;
244:                        fFieldActivator.endValueScopeFor(fIdentityConstraint,
245:                                fInitialDepth);
246:                    }
247:                }
248:
249:                /** Returns the identity constraint. */
250:                public IdentityConstraint getIdentityConstraint() {
251:                    return fIdentityConstraint;
252:                } // getIdentityConstraint():IdentityConstraint
253:
254:                /** get the initial depth at which this selector matched. */
255:                public int getInitialDepth() {
256:                    return fInitialDepth;
257:                } // getInitialDepth():  int
258:
259:            } // class Matcher
260:
261:        } // class Selector
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.