jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/identity/Field.java
author joehw
Mon, 13 Oct 2014 14:09:03 -0700
changeset 27111 7a491d709b83
parent 25868 686eef1e7a79
permissions -rw-r--r--
8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
27111
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
     6
 * Licensed to the Apache Software Foundation (ASF) under one or more
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
     7
 * contributor license agreements.  See the NOTICE file distributed with
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
     8
 * this work for additional information regarding copyright ownership.
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
     9
 * The ASF licenses this file to You under the Apache License, Version 2.0
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
    10
 * (the "License"); you may not use this file except in compliance with
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
    11
 * the License.  You may obtain a copy of the License at
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *      http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
package com.sun.org.apache.xerces.internal.impl.xs.identity;
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
import com.sun.org.apache.xerces.internal.impl.xpath.XPathException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import com.sun.org.apache.xerces.internal.impl.xs.util.ShortListImpl;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import com.sun.org.apache.xerces.internal.util.SymbolTable;
27111
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
    27
import com.sun.org.apache.xerces.internal.util.XMLChar;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xerces.internal.xs.ShortList;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xerces.internal.xs.XSComplexTypeDefinition;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xerces.internal.xs.XSConstants;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 * Schema identity constraint field.
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * @xerces.internal
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 * @author Andy Clark, IBM
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
public class Field {
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
    // Data
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
    /** Field XPath. */
27111
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
    48
    protected final Field.XPath fXPath;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
    /** Identity constraint. */
27111
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
    52
    protected final IdentityConstraint fIdentityConstraint;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
    // Constructors
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
    /** Constructs a field. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
    public Field(Field.XPath xpath,
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
                 IdentityConstraint identityConstraint) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
        fXPath = xpath;
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
        fIdentityConstraint = identityConstraint;
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
    } // <init>(Field.XPath,IdentityConstraint)
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    // Public methods
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    /** Returns the field XPath. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
    public com.sun.org.apache.xerces.internal.impl.xpath.XPath getXPath() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
        return fXPath;
27111
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
    72
    } // getXPath():org.apache.xerces.impl.v1.schema.identity.XPath
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
    /** Returns the identity constraint. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
    public IdentityConstraint getIdentityConstraint() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
        return fIdentityConstraint;
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
    } // getIdentityConstraint():IdentityConstraint
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
    // factory method
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
    /** Creates a field matcher. */
27111
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
    82
    public XPathMatcher createMatcher(ValueStore store) {
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
    83
        return new Field.Matcher(fXPath, store);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
    } // createMatcher(ValueStore):XPathMatcher
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
    // Object methods
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
    /** Returns a string representation of this object. */
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
    public String toString() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
        return fXPath.toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
    } // toString():String
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
    // Classes
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
     * Field XPath.
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
     * @author Andy Clark, IBM
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
    public static class XPath
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
        extends com.sun.org.apache.xerces.internal.impl.xpath.XPath {
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
        // Constructors
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
        /** Constructs a field XPath expression. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
        public XPath(String xpath,
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
                     SymbolTable symbolTable,
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
                     NamespaceContext context) throws XPathException {
27111
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   115
            super(fixupXPath(xpath), symbolTable, context);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
            // verify that only one attribute is selected per branch
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
            for (int i=0;i<fLocationPaths.length;i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
                for(int j=0; j<fLocationPaths[i].steps.length; j++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
                    com.sun.org.apache.xerces.internal.impl.xpath.XPath.Axis axis =
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
                        fLocationPaths[i].steps[j].axis;
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
                    if (axis.type == XPath.Axis.ATTRIBUTE &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
                            (j < fLocationPaths[i].steps.length-1)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
                        throw new XPathException("c-fields-xpaths");
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
        } // <init>(String,SymbolTable,NamespacesContext)
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
27111
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   130
        /** Fixup XPath expression. Avoid creating a new String if possible. */
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   131
        private static String fixupXPath(String xpath) {
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   132
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   133
            final int end = xpath.length();
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   134
            int offset = 0;
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   135
            boolean whitespace = true;
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   136
            char c;
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   137
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   138
            // NOTE: We have to prefix the field XPath with "./" in
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   139
            //       order to handle selectors such as "@attr" that
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   140
            //       select the attribute because the fields could be
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   141
            //       relative to the selector element. -Ac
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   142
            //       Unless xpath starts with a descendant node -Achille Fokoue
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   143
            //      ... or a / or a . - NG
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   144
            for (; offset < end; ++offset) {
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   145
                c = xpath.charAt(offset);
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   146
                if (whitespace) {
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   147
                    if (!XMLChar.isSpace(c)) {
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   148
                        if (c == '.' || c == '/') {
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   149
                            whitespace = false;
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   150
                        }
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   151
                        else if (c != '|') {
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   152
                            return fixupXPath2(xpath, offset, end);
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   153
                        }
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   154
                    }
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   155
                }
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   156
                else if (c == '|') {
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   157
                    whitespace = true;
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   158
                }
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   159
            }
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   160
            return xpath;
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   161
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   162
        } // fixupXPath(String):String
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   163
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   164
        private static String fixupXPath2(String xpath, int offset, final int end) {
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   165
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   166
            StringBuffer buffer = new StringBuffer(end + 2);
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   167
            for (int i = 0; i < offset; ++i) {
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   168
                buffer.append(xpath.charAt(i));
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   169
            }
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   170
            buffer.append("./");
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   171
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   172
            boolean whitespace = false;
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   173
            char c;
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   174
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   175
            for (; offset < end; ++offset) {
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   176
                c = xpath.charAt(offset);
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   177
                if (whitespace) {
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   178
                    if (!XMLChar.isSpace(c)) {
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   179
                        if (c == '.' || c == '/') {
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   180
                            whitespace = false;
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   181
                        }
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   182
                        else if (c != '|') {
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   183
                            buffer.append("./");
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   184
                            whitespace = false;
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   185
                        }
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   186
                    }
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   187
                }
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   188
                else if (c == '|') {
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   189
                    whitespace = true;
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   190
                }
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   191
                buffer.append(c);
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   192
            }
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   193
            return buffer.toString();
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   194
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   195
        } // fixupXPath2(String, int, int):String
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   196
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
    } // class XPath
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
     * Field matcher.
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
     *
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
     * @author Andy Clark, IBM
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
    protected class Matcher
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
        extends XPathMatcher {
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
        // Data
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
27111
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   211
        /** Value store for data values. */
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   212
        protected final ValueStore fStore;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
27111
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   214
        /** A flag indicating whether the field is allowed to match a value. */
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   215
        protected boolean fMayMatch = true;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
        // Constructors
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
        /** Constructs a field matcher. */
27111
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   222
        public Matcher(Field.XPath xpath, ValueStore store) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
            super(xpath);
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
            fStore = store;
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
        } // <init>(Field.XPath,ValueStore)
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
        // XPathHandler methods
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
        /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
         * This method is called when the XPath handler matches the
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
         * XPath expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
         */
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
        protected void matched(Object actualValue, short valueType, ShortList itemValueType, boolean isNil) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
            super.matched(actualValue, valueType, itemValueType, isNil);
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
            if(isNil && (fIdentityConstraint.getCategory() == IdentityConstraint.IC_KEY)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
                String code = "KeyMatchesNillable";
12458
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   239
                fStore.reportError(code,
d601e4bba306 7160380: Sync JDK8 with JAXP 1.4.5
joehw
parents: 12457
diff changeset
   240
                    new Object[]{fIdentityConstraint.getElementName(), fIdentityConstraint.getIdentityConstraintName()});
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
            }
27111
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   242
            fStore.addValue(Field.this, fMayMatch, actualValue, convertToPrimitiveKind(valueType), convertToPrimitiveKind(itemValueType));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
            // once we've stored the value for this field, we set the mayMatch
27111
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   244
            // member to false so that in the same scope, we don't match any more
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
            // values (and throw an error instead).
27111
7a491d709b83 8036951: Xerces Update: XMLSchemaValidator.java and XMLSchemaLoader.java
joehw
parents: 25868
diff changeset
   246
            fMayMatch = false;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
        } // matched(String)
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
        private short convertToPrimitiveKind(short valueType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
            /** Primitive datatypes. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
            if (valueType <= XSConstants.NOTATION_DT) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
                return valueType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
            /** Types derived from string. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
            if (valueType <= XSConstants.ENTITY_DT) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
                return XSConstants.STRING_DT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
            /** Types derived from decimal. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
            if (valueType <= XSConstants.POSITIVEINTEGER_DT) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
                return XSConstants.DECIMAL_DT;
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
            /** Other types. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
            return valueType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
        private ShortList convertToPrimitiveKind(ShortList itemValueType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
            if (itemValueType != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
                int i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
                final int length = itemValueType.getLength();
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
                for (i = 0; i < length; ++i) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
                    short type = itemValueType.item(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
                    if (type != convertToPrimitiveKind(type)) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
                        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
                if (i != length) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
                    final short [] arr = new short[length];
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
                    for (int j = 0; j < i; ++j) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
                        arr[j] = itemValueType.item(j);
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
                    for(; i < length; ++i) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
                        arr[i] = convertToPrimitiveKind(itemValueType.item(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
                    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
                    return new ShortListImpl(arr, arr.length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
            return itemValueType;
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
        protected void handleContent(XSTypeDefinition type, boolean nillable, Object actualValue, short valueType, ShortList itemValueType) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
            if (type == null ||
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
               type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE &&
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
               ((XSComplexTypeDefinition) type).getContentType()
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
                != XSComplexTypeDefinition.CONTENTTYPE_SIMPLE) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
                    // the content must be simpleType content
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
                    fStore.reportError( "cvc-id.3", new Object[] {
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
                            fIdentityConstraint.getName(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
                            fIdentityConstraint.getElementName()});
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
            fMatchedString = actualValue;
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
            matched(fMatchedString, valueType, itemValueType, nillable);
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
        } // handleContent(XSElementDecl, String)
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
    } // class Matcher
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
} // class Field