2
* Copyright © 2008-2012 NetAllied Systems GmbH, Ravensburg, Germany.
4
* Licensed under the MIT Open Source License,
5
* for details please see LICENSE file or the website
6
* http://www.opensource.org/licenses/mit-license.php
8
package de.netallied.xsd2cppsax;
10
import java.util.ArrayList;
11
import java.util.HashMap;
12
import java.util.List;
15
import org.apache.xerces.xs.XSElementDeclaration;
18
* Traverses XSD in search for substitution groups. Stores elements which may
19
* substitute another one.
22
public class SubstitutionGroupResolver extends AbstractStackBasedTraverser {
24
/** Stores found substitution groups. */
25
private Map<XSElementDeclaration, List<XSElementDeclaration>> substitutionGroups = new HashMap<XSElementDeclaration, List<XSElementDeclaration>>();
30
public SubstitutionGroupResolver(Config config) {
35
* @return Resolved substitution groups.
37
public Map<XSElementDeclaration, List<XSElementDeclaration>> getSubstitutionGroups() {
38
return substitutionGroups;
44
* @see de.netallied.xsd2cppsax.AbstractXSTraverser#handleElement(com.sun.org.apache.xerces.internal.xs.XSElementDeclaration)
47
public boolean handleElement(XSElementDeclaration element) {
48
if (!checkStack(element)) {
52
storeSubstitutesRecursive(element, element.getSubstitutionGroupAffiliation());
54
getElementStack().push(element);
55
super.handleElement(element);
56
getElementStack().pop();
61
* Stores substitute in list corresponding to affiliation.
64
* Element which may substitute affiliation.
66
* Element which may be substituted. May be null.
68
protected void storeSubstitutesRecursive(XSElementDeclaration substitute, XSElementDeclaration affiliation) {
69
if (affiliation != null) {
70
if (!substitutionGroups.containsKey(affiliation)) {
71
substitutionGroups.put(affiliation, new ArrayList<XSElementDeclaration>());
73
List<XSElementDeclaration> substitutes = substitutionGroups.get(affiliation);
74
substitutes.add(substitute);
76
if (affiliation.getSubstitutionGroupAffiliation() != null) {
77
storeSubstitutesRecursive(substitute, affiliation.getSubstitutionGroupAffiliation());