All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.shredzone.acme4j.AcmeResource Maven / Gradle / Ivy

/*
 * acme4j - Java ACME client
 *
 * Copyright (C) 2016 Richard "Shred" Körber
 *   http://acme4j.shredzone.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */
package org.shredzone.acme4j;

import java.io.Serializable;
import java.net.URI;
import java.util.Objects;

/**
 * A generic ACME resource.
 */
public abstract class AcmeResource implements Serializable {
    private static final long serialVersionUID = -7930580802257379731L;

    private transient Session session;
    private URI location;

    /**
     * Create a new {@link AcmeResource}.
     *
     * @param session
     *            {@link Session} the resource is bound with
     */
    protected AcmeResource(Session session) {
        rebind(session);
    }

    /**
     * Gets the {@link Session} this resource is bound with.
     */
    protected Session getSession() {
        if (session == null) {
            throw new IllegalStateException("Use rebind() to bind this resource to a session.");
        }

        return session;
    }

    /**
     * Sets a new {@link Session}.
     */
    protected void setSession(Session session) {
        this.session = Objects.requireNonNull(session, "session");
    }

    /**
     * Sets the resource's location.
     */
    protected void setLocation(URI location) {
        this.location = Objects.requireNonNull(location, "location");
    }

    /**
     * Rebinds this resource to a {@link Session}.
     * 

* Sessions are not serialized, because they contain volatile session data and also a * private key. After de-serialization of an {@link AcmeResource}, use this method to * rebind it to a {@link Session}. * * @param session * {@link Session} to bind this resource to */ public void rebind(Session session) { if (this.session != null) { throw new IllegalStateException("Resource is already bound to a session"); } setSession(session); } /** * Gets the resource's location. */ public URI getLocation() { return location; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy