PropertyWithQualifierWalker.java 3.8 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  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
 */
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.SchemaGenerationHandler;
import com.adobe.xmp.schema.rng.parser.exceptions.RNGParseException;
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.utils.RNGUtils;
import javax.xml.namespace.QName;
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;

class PropertyWithQualifierWalker
extends BasePatternWalker {
    private boolean ignoreProperty;

    PropertyWithQualifierWalker(PropertyInfo propertyInfo, Context context) {
        this.relativeDepth = -1;
        this.propertyInfo = propertyInfo;
        this.context = context;
        this.ignoreProperty = false;
    }

    PropertyWithQualifierWalker(Context context) {
        this.relativeDepth = -1;
        this.propertyInfo = new PropertyInfo("", "", context.getCurrentSchemaInfo());
        this.context = context;
        this.ignoreProperty = false;
    }

    public Void onOptional(DOptionalPattern 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 RNGParseException("rng:choice should be topmost element while defining a property");
        }
        this.propertyInfo.setMandatory(false);
        return this.onUnary((DUnaryPattern)p);
    }

    public Void onElement(DElementPattern p) {
        super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
        Integer n = this.relativeDepth;
        Integer n2 = this.relativeDepth = Integer.valueOf(this.relativeDepth + 1);
        if (this.propertyInfo.isMandatory() && this.relativeDepth != 0) {
            throw new RNGParseException("rng:element with property name should be topmost element while defining a property");
        }
        QName qName = RNGUtils.getSimpleName(p);
        String ns = qName.getNamespaceURI();
        String localName = qName.getLocalPart();
        String prefix = qName.getPrefix();
        if (this.context.getCurrentSchemaInfo().getPrefix() == null) {
            this.context.getCurrentSchemaInfo().setPrefix(prefix);
        }
        this.context.getSchemaGenerationHandler().startPropertyConstruction(ns, localName, prefix);
        this.propertyInfo.setName(localName);
        this.propertyInfo.setNS(ns);
        BasePropertyWalker baseProp = new BasePropertyWalker(this.propertyInfo, this.context);
        try {
            this.getChild((DUnaryPattern)p).accept((DPatternVisitor)baseProp);
        }
        catch (RNGParseException ex) {
            if (this.context.getSchemaGenerationHandler().ignoreErrorInConstructingProperty(ns, localName, ex)) {
                this.ignoreProperty = true;
            }
            throw ex;
        }
        return null;
    }

    PropertyInfo getPropInfo() {
        return this.propertyInfo;
    }

    boolean isIgnoreProperty() {
        return this.ignoreProperty;
    }
}