1 /* 2 * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. 3 */ 4 /* 5 * Licensed to the Apache Software Foundation (ASF) under one or more 6 * contributor license agreements. See the NOTICE file distributed with 7 * this work for additional information regarding copyright ownership. 8 * The ASF licenses this file to You under the Apache License, Version 2.0 9 * (the "License"); you may not use this file except in compliance with 10 * the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 package com.sun.org.apache.xerces.internal.impl.xs; 22 23 import com.sun.org.apache.xerces.internal.xni.QName; 24 import com.sun.org.apache.xerces.internal.xs.XSConstants; 25 import com.sun.org.apache.xerces.internal.xs.XSElementDeclaration; 26 import com.sun.org.apache.xerces.internal.xs.XSObjectList; 27 import com.sun.org.apache.xerces.internal.xs.XSSimpleTypeDefinition; 28 import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition; 29 import java.util.ArrayList; 30 import java.util.HashMap; 31 import java.util.List; 32 import java.util.Map; 33 34 /** 35 * To store and validate information about substitutionGroup 36 * 37 * @xerces.internal 38 * 39 * @author Sandy Gao, IBM 40 * 41 * @LastModified: Nov 2017 42 */ 43 public class SubstitutionGroupHandler { 44 45 private static final XSElementDecl[] EMPTY_GROUP = new XSElementDecl[0]; 46 47 // global element declaration resolver 48 private final XSElementDeclHelper fXSElementDeclHelper; 49 50 /** 51 * Default constructor 52 */ 53 public SubstitutionGroupHandler(XSElementDeclHelper elementDeclHelper) { 54 fXSElementDeclHelper = elementDeclHelper; 55 } 56 57 // 3.9.4 Element Sequence Locally Valid (Particle) 2.3.3 58 // check whether one element decl matches an element with the given qname 59 public XSElementDecl getMatchingElemDecl(QName element, XSElementDecl exemplar) { 60 if (element.localpart == exemplar.fName && 61 element.uri == exemplar.fTargetNamespace) { 62 return exemplar; 63 } 64 65 // if the exemplar is not a global element decl, then it's not possible 66 // to be substituted by another element. 67 if (exemplar.fScope != XSConstants.SCOPE_GLOBAL) { 68 return null; 69 } 70 71 // if the decl blocks substitution, return false 72 if ((exemplar.fBlock & XSConstants.DERIVATION_SUBSTITUTION) != 0) { 73 return null; 74 } 75 76 // get the decl for the element 77 XSElementDecl eDecl = fXSElementDeclHelper.getGlobalElementDecl(element); 78 if (eDecl == null) { 79 return null; 80 } 81 | 1 /* 2 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. 3 */ 4 /* 5 * Licensed to the Apache Software Foundation (ASF) under one or more 6 * contributor license agreements. See the NOTICE file distributed with 7 * this work for additional information regarding copyright ownership. 8 * The ASF licenses this file to You under the Apache License, Version 2.0 9 * (the "License"); you may not use this file except in compliance with 10 * the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 package com.sun.org.apache.xerces.internal.impl.xs; 22 23 import com.sun.org.apache.xerces.internal.xni.QName; 24 import com.sun.org.apache.xerces.internal.xs.XSConstants; 25 import com.sun.org.apache.xerces.internal.xs.XSElementDeclaration; 26 import com.sun.org.apache.xerces.internal.xs.XSObjectList; 27 import com.sun.org.apache.xerces.internal.xs.XSSimpleTypeDefinition; 28 import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition; 29 import java.util.ArrayList; 30 import java.util.HashMap; 31 import java.util.List; 32 import java.util.Map; 33 import java.util.Objects; 34 35 /** 36 * To store and validate information about substitutionGroup 37 * 38 * @xerces.internal 39 * 40 * @author Sandy Gao, IBM 41 * 42 * @LastModified: July 2019 43 */ 44 public class SubstitutionGroupHandler { 45 46 private static final XSElementDecl[] EMPTY_GROUP = new XSElementDecl[0]; 47 48 // global element declaration resolver 49 private final XSElementDeclHelper fXSElementDeclHelper; 50 51 /** 52 * Default constructor 53 */ 54 public SubstitutionGroupHandler(XSElementDeclHelper elementDeclHelper) { 55 fXSElementDeclHelper = elementDeclHelper; 56 } 57 58 // 3.9.4 Element Sequence Locally Valid (Particle) 2.3.3 59 // check whether one element decl matches an element with the given qname 60 public XSElementDecl getMatchingElemDecl(QName element, XSElementDecl exemplar) { 61 if (Objects.equals(element.localpart, exemplar.fName) && 62 Objects.equals(element.uri, exemplar.fTargetNamespace)) { 63 return exemplar; 64 } 65 66 // if the exemplar is not a global element decl, then it's not possible 67 // to be substituted by another element. 68 if (exemplar.fScope != XSConstants.SCOPE_GLOBAL) { 69 return null; 70 } 71 72 // if the decl blocks substitution, return false 73 if ((exemplar.fBlock & XSConstants.DERIVATION_SUBSTITUTION) != 0) { 74 return null; 75 } 76 77 // get the decl for the element 78 XSElementDecl eDecl = fXSElementDeclHelper.getGlobalElementDecl(element); 79 if (eDecl == null) { 80 return null; 81 } 82 |