AnnotationsFactory.java 2.91 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  org.kohsuke.rngom.rngparser.digested.DAnnotation
 *  org.kohsuke.rngom.rngparser.digested.DAnnotation$Attribute
 */
package com.adobe.xmp.schema.rng.parser.annotation;

import com.adobe.xmp.schema.rng.parser.annotation.RNGAnnotation;
import com.adobe.xmp.schema.rng.parser.annotation.RNGDecorationAnnotation;
import com.adobe.xmp.schema.rng.parser.annotation.RNGLabelAnnotation;
import com.adobe.xmp.schema.rng.parser.annotation.RNGSchemaAnnotation;
import com.adobe.xmp.schema.rng.parser.annotation.RNGTypeAnnotation;
import java.util.List;
import org.kohsuke.rngom.rngparser.digested.DAnnotation;
import org.w3c.dom.Element;

public class AnnotationsFactory {
    private static final String SCHEMA = "schema";
    private static final String NAMESPACE = "namespace";
    private static final String DECORATION = "decoration";
    private static final String PROPERTY = "property";
    private static final String TYPE = "type";
    private static final String LABEL = "label";

    public static RNGAnnotation[] createAnnotationArray(DAnnotation annot) {
        if (annot == null || annot == DAnnotation.EMPTY) {
            return null;
        }
        List list = annot.getChildren();
        if (list == null || list.size() == 0) {
            DAnnotation.Attribute tAttr = annot.getAttribute("http://ns.adobe.com/xmp/schema/info/", "type");
            if (tAttr != null) {
                return new RNGAnnotation[]{new RNGTypeAnnotation(annot)};
            }
            DAnnotation.Attribute lAttr = annot.getAttribute("http://ns.adobe.com/xmp/schema/info/", "label");
            if (lAttr != null) {
                return new RNGAnnotation[]{new RNGLabelAnnotation(annot)};
            }
            return null;
        }
        if (list.size() == 0) {
            return null;
        }
        RNGAnnotation[] arr = new RNGAnnotation[list.size()];
        int idx = 0;
        for (Element e : list) {
            arr[idx++] = AnnotationsFactory.createAnnotation(e);
        }
        return arr;
    }

    public static RNGAnnotation createAnnotation(Element element) {
        if (element == null) {
            return null;
        }
        if ("http://ns.adobe.com/xmp/schema/info/".equals(element.getNamespaceURI())) {
            if ("schema".equals(element.getLocalName()) || "namespace".equals(element.getLocalName())) {
                return new RNGSchemaAnnotation(element);
            }
            if ("decoration".equals(element.getLocalName()) || "property".equals(element.getLocalName())) {
                return new RNGDecorationAnnotation(element);
            }
            if ("type".equals(element.getLocalName())) {
                return new RNGTypeAnnotation(element);
            }
            if ("label".equals(element.getLocalName())) {
                return new RNGLabelAnnotation(element);
            }
        }
        return null;
    }
}