All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jlibs.xml.xsd.XSNavigator Maven / Gradle / Ivy

There is a newer version: 3.0.1
Show newest version
/**
 * Copyright 2015 Santhosh Kumar Tekuri
 *
 * The JLibs authors license this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package jlibs.xml.xsd;

import jlibs.core.graph.Navigator;
import jlibs.core.graph.Sequence;
import jlibs.core.graph.sequences.ConcatSequence;
import jlibs.core.graph.sequences.DuplicateSequence;
import jlibs.core.graph.sequences.EmptySequence;
import jlibs.core.graph.visitors.ReflectionVisitor;
import jlibs.xml.xsd.sequences.XSNamedMapSequence;
import jlibs.xml.xsd.sequences.XSNamespaceItemListSequence;
import jlibs.xml.xsd.sequences.XSObjectListSequence;
import org.apache.xerces.xs.*;

import static org.apache.xerces.xs.XSConstants.ELEMENT_DECLARATION;

/**
 * @author Santhosh Kumar T
 */
public class XSNavigator extends ReflectionVisitor implements Navigator{
    @Override
    public Sequence children(Object elem){
        return visit(elem);
    }

    @Override
    protected Sequence getDefault(Object elem){
        return EmptySequence.getInstance();
    }

    protected Sequence process(XSModel model){
        return new XSNamespaceItemListSequence(model.getNamespaceItems());
    }

    protected Sequence process(XSNamespaceItem nsItem){
        return new XSNamedMapSequence(nsItem.getComponents(ELEMENT_DECLARATION));
    }

    protected Sequence process(XSElementDeclaration elem){
        return new DuplicateSequence(elem.getTypeDefinition());
    }

    @SuppressWarnings("unchecked")
    protected Sequence process(XSComplexTypeDefinition complexType){
        Sequence sequence = new XSObjectListSequence(complexType.getAttributeUses());
        if(complexType.getAttributeWildcard()!=null)
            sequence = new ConcatSequence(sequence, new DuplicateSequence(complexType.getAttributeWildcard()));
        if(complexType.getParticle()!=null) // simple content
            sequence = new ConcatSequence(sequence, new DuplicateSequence(complexType.getParticle()));
        return sequence;
    }

    protected Sequence process(XSParticle particle){
        return new DuplicateSequence(particle.getTerm());
    }

    protected Sequence process(XSModelGroup modelGroup){
        return new XSObjectListSequence(modelGroup.getParticles());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy