source: icXML/icXML-devel/src/xercesc/validators/schema/XercesElementWildcard.cpp @ 2734

Last change on this file since 2734 was 2722, checked in by cameron, 7 years ago

Original Xerces files with import mods for icxercesc

File size: 4.6 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: XercesElementWildcard.cpp 671133 2008-06-24 11:22:29Z borisk $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  Includes
25// ---------------------------------------------------------------------------
26#include <xercesc/validators/schema/XercesElementWildcard.hpp>
27
28XERCES_CPP_NAMESPACE_BEGIN
29
30// ---------------------------------------------------------------------------
31//  Local methods
32// ---------------------------------------------------------------------------
33
34/**
35 * XercesElementWildcard is used to check whether two element declarations conflict
36 */
37/**
38 * Check whether two element declarations conflict
39 */
40bool XercesElementWildcard::conflict(SchemaGrammar* const pGrammar,
41                                     ContentSpecNode::NodeTypes   type1,
42                                     QName*                       q1,
43                                     ContentSpecNode::NodeTypes   type2,
44                                     QName*                       q2,
45                                     SubstitutionGroupComparator* comparator)
46{
47    if (type1 == ContentSpecNode::Leaf &&
48        type2 == ContentSpecNode::Leaf) {
49        if (comparator->isEquivalentTo(q1, q2) || comparator->isEquivalentTo(q2, q1))
50            return true;
51    }
52    else if (type1 == ContentSpecNode::Leaf) {
53        return uriInWildcard(pGrammar, q1, q2->getURI(), type2, comparator);
54    }
55    else if (type2 == ContentSpecNode::Leaf) {
56        return uriInWildcard(pGrammar, q2, q1->getURI(), type1, comparator);
57    }
58    else {
59        return wildcardIntersect(type1, q1->getURI(), type2, q2->getURI());
60    }
61    return false;
62}
63
64bool XercesElementWildcard::uriInWildcard(SchemaGrammar* const         pGrammar,
65                                          QName*                       qname,
66                                          unsigned int                 wildcard,
67                                          ContentSpecNode::NodeTypes   wtype,
68                                          SubstitutionGroupComparator* comparator)
69{
70    if ((wtype & 0x0f)== ContentSpecNode::Any) {
71        return true;
72    }
73    else if ((wtype & 0x0f)== ContentSpecNode::Any_NS) {
74        // substitution of "uri" satisfies "wtype:wildcard"
75        return comparator->isAllowedByWildcard(pGrammar, qname, wildcard, false);
76    }
77    else if ((wtype & 0x0f)== ContentSpecNode::Any_Other) {
78        // substitution of "uri" satisfies "wtype:wildcard"
79        return comparator->isAllowedByWildcard(pGrammar, qname, wildcard, true);
80    }
81
82    return false;
83}
84
85bool XercesElementWildcard::wildcardIntersect(ContentSpecNode::NodeTypes t1,
86                                              unsigned int               w1,
87                                              ContentSpecNode::NodeTypes t2,
88                                              unsigned int               w2)
89{
90    if (((t1 & 0x0f) == ContentSpecNode::Any) ||
91        ((t2 & 0x0f) == ContentSpecNode::Any)) {
92        // if either one is "##any", then intersects
93        return true;
94    }
95    else if (((t1 & 0x0f) == ContentSpecNode::Any_NS) &&
96             ((t2 & 0x0f) == ContentSpecNode::Any_NS)) {
97        // if both are "some_namespace" and equal, then intersects
98        return w1 == w2;
99    }
100    else if (((t1 & 0x0f) == ContentSpecNode::Any_Other) &&
101             ((t2 & 0x0f) == ContentSpecNode::Any_Other)) {
102        // if both are "##other", then intersects
103        return true;
104    }
105    // Below we assume that empty string has id 1.
106    //
107    else if (((t1 & 0x0f) == ContentSpecNode::Any_NS) &&
108             ((t2 & 0x0f) == ContentSpecNode::Any_Other))
109    {
110      return w1 != w2 && w1 != 1;
111    }
112    else if (((t1 & 0x0f) == ContentSpecNode::Any_Other) &&
113             ((t2 & 0x0f) == ContentSpecNode::Any_NS))
114    {
115      return w1 != w2 && w2 != 1;
116    }
117    return false;
118}
119
120XERCES_CPP_NAMESPACE_END
Note: See TracBrowser for help on using the repository browser.