QualifierWalker.java 5.16 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.kohsuke.rngom.rngparser.digested.DChoicePattern
 *  org.kohsuke.rngom.rngparser.digested.DContainerPattern
 *  org.kohsuke.rngom.rngparser.digested.DElementPattern
 *  org.kohsuke.rngom.rngparser.digested.DOptionalPattern
 *  org.kohsuke.rngom.rngparser.digested.DPattern
 *  org.kohsuke.rngom.rngparser.digested.DPatternVisitor
 *  org.kohsuke.rngom.rngparser.digested.DUnaryPattern
 *  org.kohsuke.rngom.rngparser.nc.NameClass
 *  org.kohsuke.rngom.rngparser.nc.SimpleNameClass
 */
package com.adobe.xmp.schema.rng.parser.traverser;

import com.adobe.xmp.schema.rng.model.Context;
import com.adobe.xmp.schema.rng.model.PropertyInfo;
import com.adobe.xmp.schema.rng.model.SchemaInfo;
import com.adobe.xmp.schema.rng.parser.exceptions.RNGParseException;
import com.adobe.xmp.schema.rng.parser.exceptions.RNGUnexpectedElementFoundException;
import com.adobe.xmp.schema.rng.parser.traverser.BasePatternWalker;
import com.adobe.xmp.schema.rng.parser.traverser.BasePropertyWalker;
import com.adobe.xmp.schema.rng.parser.traverser.PropertyWithQualifierWalker;
import com.adobe.xmp.schema.rng.parser.traverser.SimplePropertyWalker;
import com.adobe.xmp.schema.rng.parser.utils.RNGUtils;
import javax.xml.namespace.QName;
import org.kohsuke.rngom.rngparser.digested.DChoicePattern;
import org.kohsuke.rngom.rngparser.digested.DContainerPattern;
import org.kohsuke.rngom.rngparser.digested.DElementPattern;
import org.kohsuke.rngom.rngparser.digested.DOptionalPattern;
import org.kohsuke.rngom.rngparser.digested.DPattern;
import org.kohsuke.rngom.rngparser.digested.DPatternVisitor;
import org.kohsuke.rngom.rngparser.digested.DUnaryPattern;
import org.kohsuke.rngom.rngparser.nc.NameClass;
import org.kohsuke.rngom.rngparser.nc.SimpleNameClass;

class QualifierWalker
extends BasePatternWalker {
    private boolean isQualifierOptional = false;

    QualifierWalker(PropertyInfo propInfo, Context context) {
        this.relativeDepth = -1;
        this.propertyInfo = propInfo;
        this.context = context;
    }

    public Void onChoice(DChoicePattern p) {
        super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
        Integer n = this.relativeDepth;
        Integer n2 = this.relativeDepth = Integer.valueOf(this.relativeDepth + 1);
        if (this.relativeDepth != 0) {
            throw new RNGUnexpectedElementFoundException("UNexpected choice pattern found while describing property.");
        }
        DElementPattern rdfDesc = this.getRDFDescription(p);
        if (rdfDesc == null) {
            SimplePropertyWalker sw = new SimplePropertyWalker(this.propertyInfo, this.context);
            p.accept((DPatternVisitor)sw);
            return null;
        }
        DPattern child = this.getChild((DUnaryPattern)rdfDesc);
        if (child == null) {
            throw new RNGParseException("rdf:Description should have at least 1 child");
        }
        this.unwrapGroup(child);
        return null;
    }

    public Void onElement(DElementPattern p) {
        Integer n = this.relativeDepth;
        Integer n2 = this.relativeDepth = Integer.valueOf(this.relativeDepth + 1);
        super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
        NameClass name = p.getName();
        QName qName = null;
        if (!(name instanceof SimpleNameClass)) {
            throw new RNGUnexpectedElementFoundException("Expected simple name class");
        }
        SimpleNameClass sName = (SimpleNameClass)name;
        qName = sName.name;
        if (RNGUtils.isElementRDFValue(qName)) {
            BasePropertyWalker basePropWalker = new BasePropertyWalker(this.propertyInfo, this.context);
            this.getChild((DUnaryPattern)p).accept((DPatternVisitor)basePropWalker);
        } else {
            PropertyInfo info = new PropertyInfo("", "", this.context.getCurrentSchemaInfo());
            info.setIsQualifier(true);
            info.setMandatory(!this.isQualifierOptional);
            this.isQualifierOptional = false;
            PropertyWithQualifierWalker propertyWithQualifierWalker = new PropertyWithQualifierWalker(info, this.context);
            p.accept((DPatternVisitor)propertyWithQualifierWalker);
            this.propertyInfo.addChild(info);
        }
        return null;
    }

    public Void onOptional(DOptionalPattern p) {
        super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
        this.isQualifierOptional = true;
        return this.onUnary((DUnaryPattern)p);
    }

    public DElementPattern getRDFDescription(DChoicePattern p) {
        int count = p.countChildren();
        if (count != 2) {
            return null;
        }
        DElementPattern rdfDesc = null;
        DPattern c = this.firstChild((DContainerPattern)p);
        while (c != null) {
            NameClass name;
            super.handleAnnotation(c, this.context, this.propertyInfo);
            if (c.isElement() && (name = ((DElementPattern)c).getName()) instanceof SimpleNameClass && RNGUtils.isElementRDFDesc(((SimpleNameClass)name).name)) {
                rdfDesc = (DElementPattern)c;
                break;
            }
            c = this.getNext(c);
        }
        return rdfDesc;
    }
}