001/* 002 * acme4j - Java ACME client 003 * 004 * Copyright (C) 2016 Richard "Shred" Körber 005 * http://acme4j.shredzone.org 006 * 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 013 */ 014package org.shredzone.acme4j.exception; 015 016import static java.util.Objects.requireNonNull; 017 018import java.net.URL; 019 020import org.shredzone.acme4j.AcmeResource; 021 022/** 023 * This runtime exception is thrown when an {@link AcmeException} occured while trying to 024 * lazy-load a resource from the ACME server. 025 */ 026public class AcmeLazyLoadingException extends RuntimeException { 027 private static final long serialVersionUID = 1000353433913721901L; 028 029 private final Class<? extends AcmeResource> type; 030 private final URL location; 031 032 /** 033 * Creates a new {@link AcmeLazyLoadingException}. 034 * 035 * @param resource 036 * {@link AcmeResource} to be loaded 037 * @param cause 038 * {@link AcmeException} that was raised 039 */ 040 public AcmeLazyLoadingException(AcmeResource resource, AcmeException cause) { 041 this(requireNonNull(resource).getClass(), requireNonNull(resource).getLocation(), cause); 042 } 043 044 /** 045 * Creates a new {@link AcmeLazyLoadingException}. 046 * 047 * @param type 048 * {@link AcmeResource} type to be loaded 049 * @param location 050 * Resource location 051 * @param cause 052 * {@link AcmeException} that was raised 053 * @since 2.8 054 */ 055 public AcmeLazyLoadingException(Class<? extends AcmeResource> type, URL location, AcmeException cause) { 056 super(requireNonNull(type).getSimpleName() + " " + requireNonNull(location), requireNonNull(cause)); 057 this.type = type; 058 this.location = location; 059 } 060 061 /** 062 * Returns the {@link AcmeResource} type of the resource that could not be loaded. 063 */ 064 public Class<? extends AcmeResource> getType() { 065 return type; 066 } 067 068 /** 069 * Returns the location of the resource that could not be loaded. 070 */ 071 public URL getLocation() { 072 return location; 073 } 074 075}