~ubuntu-branches/ubuntu/wily/opencollada/wily

« back to all changes in this revision

Viewing changes to xsd2cppsax/src/de/netallied/xsd2cppsax/SubstitutionGroupResolver.java

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2015-05-14 17:23:27 UTC
  • Revision ID: package-import@ubuntu.com-20150514172327-f862u8envms01fra
Tags: upstream-0.1.0~20140703.ddf8f47+dfsg1
ImportĀ upstreamĀ versionĀ 0.1.0~20140703.ddf8f47+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 *   Copyright © 2008-2012 NetAllied Systems GmbH, Ravensburg, Germany. 
 
3
 *       
 
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
 
7
*/
 
8
package de.netallied.xsd2cppsax;
 
9
 
 
10
import java.util.ArrayList;
 
11
import java.util.HashMap;
 
12
import java.util.List;
 
13
import java.util.Map;
 
14
 
 
15
import org.apache.xerces.xs.XSElementDeclaration;
 
16
 
 
17
/**
 
18
 * Traverses XSD in search for substitution groups. Stores elements which may
 
19
 * substitute another one.
 
20
 * 
 
21
 */
 
22
public class SubstitutionGroupResolver extends AbstractStackBasedTraverser {
 
23
 
 
24
    /** Stores found substitution groups. */
 
25
    private Map<XSElementDeclaration, List<XSElementDeclaration>> substitutionGroups = new HashMap<XSElementDeclaration, List<XSElementDeclaration>>();
 
26
 
 
27
    /**
 
28
     * Constructor.
 
29
     */
 
30
    public SubstitutionGroupResolver(Config config) {
 
31
        super(config);
 
32
    }
 
33
 
 
34
    /**
 
35
     * @return Resolved substitution groups.
 
36
     */
 
37
    public Map<XSElementDeclaration, List<XSElementDeclaration>> getSubstitutionGroups() {
 
38
        return substitutionGroups;
 
39
    }
 
40
 
 
41
    /**
 
42
     * {@inheritDoc}
 
43
     * 
 
44
     * @see de.netallied.xsd2cppsax.AbstractXSTraverser#handleElement(com.sun.org.apache.xerces.internal.xs.XSElementDeclaration)
 
45
     */
 
46
    @Override
 
47
    public boolean handleElement(XSElementDeclaration element) {
 
48
        if (!checkStack(element)) {
 
49
            return true;
 
50
        }
 
51
 
 
52
        storeSubstitutesRecursive(element, element.getSubstitutionGroupAffiliation());
 
53
 
 
54
        getElementStack().push(element);
 
55
        super.handleElement(element);
 
56
        getElementStack().pop();
 
57
        return true;
 
58
    }
 
59
 
 
60
    /**
 
61
     * Stores substitute in list corresponding to affiliation.
 
62
     * 
 
63
     * @param substitute
 
64
     *            Element which may substitute affiliation.
 
65
     * @param affiliation
 
66
     *            Element which may be substituted. May be null.
 
67
     */
 
68
    protected void storeSubstitutesRecursive(XSElementDeclaration substitute, XSElementDeclaration affiliation) {
 
69
        if (affiliation != null) {
 
70
            if (!substitutionGroups.containsKey(affiliation)) {
 
71
                substitutionGroups.put(affiliation, new ArrayList<XSElementDeclaration>());
 
72
            }
 
73
            List<XSElementDeclaration> substitutes = substitutionGroups.get(affiliation);
 
74
            substitutes.add(substitute);
 
75
 
 
76
            if (affiliation.getSubstitutionGroupAffiliation() != null) {
 
77
                storeSubstitutesRecursive(substitute, affiliation.getSubstitutionGroupAffiliation());
 
78
            }
 
79
        }
 
80
    }
 
81
}