CredentialsConfig.java 1.56 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.jcr.Credentials
 */
package com.day.jcr.vault.fs.config;

import com.day.jcr.vault.fs.config.ConfigurationException;
import com.day.jcr.vault.fs.config.SimpleCredentialsConfig;
import javax.jcr.Credentials;
import org.w3c.dom.Element;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;

public abstract class CredentialsConfig {
    public final String type;
    public static final String ATTR_TYPE = "type";
    public static final String ELEM_CREDETIALS = "credentials";

    public CredentialsConfig(String type) {
        this.type = type;
    }

    public static CredentialsConfig load(Element elem) throws ConfigurationException {
        assert (elem.getNodeName().equals("credentials"));
        String type = elem.getAttribute("type");
        if (type == null || type.equals("simple")) {
            return SimpleCredentialsConfig.load(elem);
        }
        throw new ConfigurationException("unknown credentials type: " + type);
    }

    public abstract Credentials getCredentials();

    public void write(ContentHandler handler) throws SAXException {
        AttributesImpl attrs = new AttributesImpl();
        attrs.addAttribute("", "type", "", "CDATA", this.type);
        handler.startElement("", "credentials", "", attrs);
        this.writeInner(handler);
        handler.endElement("", "credentials", "");
    }

    protected abstract void writeInner(ContentHandler var1) throws SAXException;
}