BasePropertyWalker.java 7.54 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.xmp.schema.model.ArrayType
 *  com.adobe.xmp.schema.model.ArrayType$ArrayForm
 *  org.kohsuke.rngom.rngparser.digested.DChoicePattern
 *  org.kohsuke.rngom.rngparser.digested.DContainerPattern
 *  org.kohsuke.rngom.rngparser.digested.DDataPattern
 *  org.kohsuke.rngom.rngparser.digested.DElementPattern
 *  org.kohsuke.rngom.rngparser.digested.DGroupPattern
 *  org.kohsuke.rngom.rngparser.digested.DPattern
 *  org.kohsuke.rngom.rngparser.digested.DPatternVisitor
 *  org.kohsuke.rngom.rngparser.digested.DTextPattern
 *  org.kohsuke.rngom.rngparser.digested.DUnaryPattern
 *  org.kohsuke.rngom.rngparser.digested.DValuePattern
 */
package com.adobe.xmp.schema.rng.parser.traverser;

import com.adobe.xmp.schema.model.ArrayType;
import com.adobe.xmp.schema.rng.model.Context;
import com.adobe.xmp.schema.rng.model.ParamInfo;
import com.adobe.xmp.schema.rng.model.ParamInfoGroup;
import com.adobe.xmp.schema.rng.model.ParamInfoImpl;
import com.adobe.xmp.schema.rng.model.PropertyInfo;
import com.adobe.xmp.schema.rng.parser.constants.RNGSymbol;
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.ArrayPropertyWalker;
import com.adobe.xmp.schema.rng.parser.traverser.BasePatternWalker;
import com.adobe.xmp.schema.rng.parser.traverser.QualifierWalker;
import com.adobe.xmp.schema.rng.parser.traverser.SimplePropertyWalker;
import com.adobe.xmp.schema.rng.parser.traverser.StructPropertyWalker;
import com.adobe.xmp.schema.rng.parser.utils.RNGUtils;
import java.util.ArrayList;
import java.util.List;
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.DDataPattern;
import org.kohsuke.rngom.rngparser.digested.DElementPattern;
import org.kohsuke.rngom.rngparser.digested.DGroupPattern;
import org.kohsuke.rngom.rngparser.digested.DPattern;
import org.kohsuke.rngom.rngparser.digested.DPatternVisitor;
import org.kohsuke.rngom.rngparser.digested.DTextPattern;
import org.kohsuke.rngom.rngparser.digested.DUnaryPattern;
import org.kohsuke.rngom.rngparser.digested.DValuePattern;

/*
 * This class specifies class file version 49.0 but uses Java 6 signatures.  Assumed Java 6.
 */
class BasePropertyWalker
extends BasePatternWalker {
    BasePropertyWalker(PropertyInfo propertyInfo, Context context) {
        this.relativeDepth = -1;
        this.propertyInfo = propertyInfo;
        this.context = context;
    }

    @Override
    public Void onChoice(DChoicePattern p) {
        ArrayType.ArrayForm arr;
        super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
        int numChild = p.countChildren();
        if (numChild == 1 && p.firstChild() instanceof DChoicePattern) {
            return this.onChoice((DChoicePattern)p.firstChild());
        }
        boolean processed = false;
        if (this.firstChild((DContainerPattern)p) instanceof DElementPattern && (arr = RNGUtils.getArrayForm(RNGUtils.getSimpleName((DElementPattern)this.firstChild((DContainerPattern)p)))) != null) {
            this.propertyInfo.setArrayForm(arr);
            ParamInfoGroup pg = new ParamInfoGroup(ParamInfoGroup.Operator.kOR);
            for (DPattern d : p) {
                super.handleAnnotation(d, this.context, this.propertyInfo);
                if (d instanceof DElementPattern) {
                    Integer[] choice = this.getChoices((DElementPattern)d);
                    pg.push(new ParamInfoImpl(RNGSymbol.constValue.name(), choice));
                    continue;
                }
                throw new RNGUnexpectedElementFoundException("Expected an element pattern while defining closed choice of ordered array of integer.");
            }
            this.propertyInfo.setParamInfos(pg);
            processed = true;
        }
        if (!processed) {
            QualifierWalker qw = new QualifierWalker(this.propertyInfo, this.context);
            p.accept((DPatternVisitor)qw);
        }
        return null;
    }

    @Override
    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);
        QName qName = RNGUtils.getSimpleName(p);
        if (RNGUtils.getArrayForm(qName) != null) {
            this.propertyInfo.setArrayForm(RNGUtils.getArrayForm(qName));
            ArrayPropertyWalker arrayPropertyWalker = new ArrayPropertyWalker(this.propertyInfo, this.context);
            this.getChild((DUnaryPattern)p).accept((DPatternVisitor)arrayPropertyWalker);
        } else if (RNGUtils.isElementRDFDesc(qName)) {
            StructPropertyWalker sw = new StructPropertyWalker(this.propertyInfo, this.context);
            p.accept((DPatternVisitor)sw);
        } else {
            throw new RNGUnexpectedElementFoundException("Expected a array or struct property definition.");
        }
        return null;
    }

    @Override
    public Void onData(DDataPattern p) {
        super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
        SimplePropertyWalker sw = new SimplePropertyWalker(this.propertyInfo, this.context);
        p.accept((DPatternVisitor)sw);
        return null;
    }

    @Override
    public Void onText(DTextPattern p) {
        super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
        SimplePropertyWalker sw = new SimplePropertyWalker(this.propertyInfo, this.context);
        p.accept((DPatternVisitor)sw);
        return null;
    }

    @Override
    public Void onValue(DValuePattern p) {
        super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
        SimplePropertyWalker sw = new SimplePropertyWalker(this.propertyInfo, this.context);
        p.accept((DPatternVisitor)sw);
        return null;
    }

    private void addChoicetoList(List<Integer> choices, DPattern d) {
        DPattern child;
        super.handleAnnotation(d, this.context, this.propertyInfo);
        if (!(d instanceof DElementPattern)) {
            return;
        }
        if (RNGUtils.isElementArrayStart(RNGUtils.getSimpleName((DElementPattern)d)) && (child = this.getChild((DUnaryPattern)((DElementPattern)d))) instanceof DValuePattern) {
            DValuePattern value = (DValuePattern)child;
            Object convertedValue = RNGUtils.convertSimpleRawValue(value.getValue(), value.getType());
            if (convertedValue instanceof Integer) {
                choices.add((Integer)convertedValue);
            } else {
                throw new RNGParseException("Only array of type integers are supported as choice values.");
            }
        }
    }

    private Integer[] getChoices(DElementPattern patt) {
        ArrayList<Integer> choices = new ArrayList<Integer>();
        QName name = RNGUtils.getSimpleName(patt);
        ArrayType.ArrayForm arr = RNGUtils.getArrayForm(name);
        if (arr == null) {
            return null;
        }
        DPattern p = this.getChild((DUnaryPattern)patt);
        if (p instanceof DGroupPattern) {
            super.handleAnnotation(p, this.context, this.propertyInfo);
            for (DPattern d : (DGroupPattern)p) {
                this.addChoicetoList(choices, d);
            }
        } else if (p instanceof DElementPattern) {
            this.addChoicetoList(choices, p);
        }
        return choices.toArray(new Integer[0]);
    }
}