GME
13
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 /* 00019 * $Id: XercesElementWildcard.cpp 671133 2008-06-24 11:22:29Z borisk $ 00020 */ 00021 00022 00023 // --------------------------------------------------------------------------- 00024 // Includes 00025 // --------------------------------------------------------------------------- 00026 #include <xercesc/validators/schema/XercesElementWildcard.hpp> 00027 00028 XERCES_CPP_NAMESPACE_BEGIN 00029 00030 // --------------------------------------------------------------------------- 00031 // Local methods 00032 // --------------------------------------------------------------------------- 00033 00040 bool XercesElementWildcard::conflict(SchemaGrammar* const pGrammar, 00041 ContentSpecNode::NodeTypes type1, 00042 QName* q1, 00043 ContentSpecNode::NodeTypes type2, 00044 QName* q2, 00045 SubstitutionGroupComparator* comparator) 00046 { 00047 if (type1 == ContentSpecNode::Leaf && 00048 type2 == ContentSpecNode::Leaf) { 00049 if (comparator->isEquivalentTo(q1, q2) || comparator->isEquivalentTo(q2, q1)) 00050 return true; 00051 } 00052 else if (type1 == ContentSpecNode::Leaf) { 00053 return uriInWildcard(pGrammar, q1, q2->getURI(), type2, comparator); 00054 } 00055 else if (type2 == ContentSpecNode::Leaf) { 00056 return uriInWildcard(pGrammar, q2, q1->getURI(), type1, comparator); 00057 } 00058 else { 00059 return wildcardIntersect(type1, q1->getURI(), type2, q2->getURI()); 00060 } 00061 return false; 00062 } 00063 00064 bool XercesElementWildcard::uriInWildcard(SchemaGrammar* const pGrammar, 00065 QName* qname, 00066 unsigned int wildcard, 00067 ContentSpecNode::NodeTypes wtype, 00068 SubstitutionGroupComparator* comparator) 00069 { 00070 if ((wtype & 0x0f)== ContentSpecNode::Any) { 00071 return true; 00072 } 00073 else if ((wtype & 0x0f)== ContentSpecNode::Any_NS) { 00074 // substitution of "uri" satisfies "wtype:wildcard" 00075 return comparator->isAllowedByWildcard(pGrammar, qname, wildcard, false); 00076 } 00077 else if ((wtype & 0x0f)== ContentSpecNode::Any_Other) { 00078 // substitution of "uri" satisfies "wtype:wildcard" 00079 return comparator->isAllowedByWildcard(pGrammar, qname, wildcard, true); 00080 } 00081 00082 return false; 00083 } 00084 00085 bool XercesElementWildcard::wildcardIntersect(ContentSpecNode::NodeTypes t1, 00086 unsigned int w1, 00087 ContentSpecNode::NodeTypes t2, 00088 unsigned int w2) 00089 { 00090 if (((t1 & 0x0f) == ContentSpecNode::Any) || 00091 ((t2 & 0x0f) == ContentSpecNode::Any)) { 00092 // if either one is "##any", then intersects 00093 return true; 00094 } 00095 else if (((t1 & 0x0f) == ContentSpecNode::Any_NS) && 00096 ((t2 & 0x0f) == ContentSpecNode::Any_NS)) { 00097 // if both are "some_namespace" and equal, then intersects 00098 return w1 == w2; 00099 } 00100 else if (((t1 & 0x0f) == ContentSpecNode::Any_Other) && 00101 ((t2 & 0x0f) == ContentSpecNode::Any_Other)) { 00102 // if both are "##other", then intersects 00103 return true; 00104 } 00105 // Below we assume that empty string has id 1. 00106 // 00107 else if (((t1 & 0x0f) == ContentSpecNode::Any_NS) && 00108 ((t2 & 0x0f) == ContentSpecNode::Any_Other)) 00109 { 00110 return w1 != w2 && w1 != 1; 00111 } 00112 else if (((t1 & 0x0f) == ContentSpecNode::Any_Other) && 00113 ((t2 & 0x0f) == ContentSpecNode::Any_NS)) 00114 { 00115 return w1 != w2 && w2 != 1; 00116 } 00117 return false; 00118 } 00119 00120 XERCES_CPP_NAMESPACE_END