SimplePropertyWalker.java 6.84 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.kohsuke.rngom.rngparser.digested.DAnnotation
 *  org.kohsuke.rngom.rngparser.digested.DChoicePattern
 *  org.kohsuke.rngom.rngparser.digested.DContainerPattern
 *  org.kohsuke.rngom.rngparser.digested.DDataPattern
 *  org.kohsuke.rngom.rngparser.digested.DDataPattern$Param
 *  org.kohsuke.rngom.rngparser.digested.DPattern
 *  org.kohsuke.rngom.rngparser.digested.DTextPattern
 *  org.kohsuke.rngom.rngparser.digested.DValuePattern
 */
package com.adobe.xmp.schema.rng.parser.traverser;

import com.adobe.xmp.schema.rng.model.Context;
import com.adobe.xmp.schema.rng.model.DatatypeInfo;
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.annotation.AnnotationsFactory;
import com.adobe.xmp.schema.rng.parser.annotation.RNGAnnotation;
import com.adobe.xmp.schema.rng.parser.annotation.RNGLabelAnnotation;
import com.adobe.xmp.schema.rng.parser.constants.RNGSymbol;
import com.adobe.xmp.schema.rng.parser.exceptions.RNGElementNotSupportedException;
import com.adobe.xmp.schema.rng.parser.exceptions.RNGParseException;
import com.adobe.xmp.schema.rng.parser.traverser.BasePatternWalker;
import java.util.List;
import org.kohsuke.rngom.rngparser.digested.DAnnotation;
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.DPattern;
import org.kohsuke.rngom.rngparser.digested.DTextPattern;
import org.kohsuke.rngom.rngparser.digested.DValuePattern;

class SimplePropertyWalker
extends BasePatternWalker {
    SimplePropertyWalker(PropertyInfo propertyInfo, Context context) {
        this.relativeDepth = -1;
        this.propertyInfo = propertyInfo;
        this.context = context;
    }

    public Void onText(DTextPattern p) {
        Integer n = this.relativeDepth;
        Integer n2 = this.relativeDepth = Integer.valueOf(this.relativeDepth + 1);
        super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
        if (this.relativeDepth == 0) {
            this.propertyInfo.setRawDataType(new DatatypeInfo("text", true));
            return null;
        }
        return super.onText(p);
    }

    public Void onData(DDataPattern p) {
        Integer n = this.relativeDepth;
        Integer n2 = this.relativeDepth = Integer.valueOf(this.relativeDepth + 1);
        super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
        if (this.relativeDepth == 0) {
            String type = p.getType();
            this.propertyInfo.setRawDataType(new DatatypeInfo(type, true));
            this.propertyInfo.setParamInfos(this.createParamInfoGroup(p));
            return null;
        }
        return super.onData(p);
    }

    public Void onValue(DValuePattern p) {
        super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
        String type = p.getType();
        this.propertyInfo.setRawDataType(new DatatypeInfo(type, true));
        this.propertyInfo.setParamInfos(this.createParamInfoGroup(p));
        return null;
    }

    public Void onChoice(DChoicePattern p) {
        super.handleAnnotation((DPattern)p, this.context, this.propertyInfo);
        ParamInfoGroup paramInfoGroup = this.createParamInfoGroup(p);
        paramInfoGroup.setChoice(true);
        this.propertyInfo.setParamInfos(paramInfoGroup);
        return null;
    }

    private ParamInfoGroup createParamInfoGroup(DChoicePattern p) {
        ParamInfoGroup paramInfoGroup = new ParamInfoGroup(ParamInfoGroup.Operator.kOR);
        DPattern c = this.firstChild((DContainerPattern)p);
        while (c != null) {
            super.handleAnnotation(c, this.context, this.propertyInfo);
            ParamInfoGroup pg = null;
            if (c instanceof DValuePattern) {
                pg = this.createParamInfoGroup((DValuePattern)c);
            } else if (c instanceof DDataPattern) {
                pg = this.createParamInfoGroup((DDataPattern)c);
            } else if (c instanceof DTextPattern) {
                pg = this.createParamInfoGroup((DTextPattern)c);
            } else if (c instanceof DChoicePattern) {
                pg = this.createParamInfoGroup((DChoicePattern)c);
            } else {
                throw new RNGElementNotSupportedException("Only value, data, text and choice elements are supported as choices for simple property types");
            }
            paramInfoGroup.push(pg);
            c = this.getNext(c);
        }
        return paramInfoGroup;
    }

    private ParamInfoGroup createParamInfoGroup(DValuePattern p) {
        ParamInfoGroup paramInfoGroup = new ParamInfoGroup(ParamInfoGroup.Operator.kAND);
        RNGAnnotation[] annots = AnnotationsFactory.createAnnotationArray(p.getAnnotation());
        String label = null;
        if (annots != null) {
            for (RNGAnnotation annot : annots) {
                if (!(annot instanceof RNGLabelAnnotation)) continue;
                RNGLabelAnnotation lAnnot = (RNGLabelAnnotation)annot;
                label = lAnnot.getLabel();
            }
        }
        paramInfoGroup.push(new ParamInfoImpl(RNGSymbol.constValue.name(), p.getValue(), p.getType(), label));
        return paramInfoGroup;
    }

    private ParamInfoGroup createParamInfoGroup(DDataPattern p) {
        ParamInfoGroup paramInfoGroup = new ParamInfoGroup(ParamInfoGroup.Operator.kAND);
        List pList = p.getParams();
        if (pList.isEmpty()) {
            ParamInfoImpl i = null;
            if ("integer".equals(p.getType())) {
                i = ParamInfoImpl.PARAM_ALL_INTEGER;
            } else if ("double".equals(p.getType())) {
                i = ParamInfoImpl.PARAM_ALL_DOUBLE;
            } else if ("boolean".equals(p.getType())) {
                i = ParamInfoImpl.PARAM_ALL_BOOLEAN;
            } else if ("text".equals(p.getType())) {
                i = ParamInfoImpl.PARAM_ALL_TEXT;
            } else if ("date".equals(p.getType())) {
                i = ParamInfoImpl.PARAM_ALL_TEXT;
            } else {
                throw new RNGParseException("Found unexpected data type as values for rng:choice.");
            }
            paramInfoGroup.push(i);
        } else {
            for (DDataPattern.Param param : pList) {
                ParamInfoImpl i = new ParamInfoImpl(param.getName(), param.getValue());
                paramInfoGroup.push(i);
            }
        }
        return paramInfoGroup;
    }

    private ParamInfoGroup createParamInfoGroup(DTextPattern p) {
        ParamInfoGroup paramInfoGroup = new ParamInfoGroup(ParamInfoGroup.Operator.kAND);
        ParamInfoImpl i = ParamInfoImpl.PARAM_ALL_TEXT;
        paramInfoGroup.push(i);
        return paramInfoGroup;
    }
}