package com.jdblabs.timestamper.core;

import java.io.IOException;
import java.net.URI;

/**
 * A means of loading and persisting a Timeline.
 * @author Jonathan Bernard (jdbernard@gmail.com)
 */
public abstract class TimelineSource {

    protected final URI uri;

    public TimelineSource(URI uri) { this.uri = uri; }

    /**
     * Read the Timeline from the source.
     * @throws IOException
     */
    public abstract Timeline read() throws IOException;

    /**
     * Persist a give timeline to this source.
     * @param t
     * @throws IOException
     */
    public abstract void persist(Timeline t) throws IOException;

    /**
     * Is this source authenticated and ready for IO.
     * @return <code>true</code> if the source is authenticated (or if no
     * authentication is required).
     */
    public abstract boolean isAuthenticated();

    /**
     * Authenticate the client to this source.
     * @throws AuthenticationException
     */
    public abstract void authenticate() throws AuthenticationException;

    /**
     * Get the URI representing this source.
     * @return The {@link java.net.URI} representing this source.
     */
    public URI getURI() {
        return uri;
    }

}
