001/* -*- mode: Java; c-basic-offset: 2; indent-tabs-mode: nil; coding: utf-8-unix -*- 002 * 003 * Copyright © 2017 MicroBean. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 014 * implied. See the License for the specific language governing 015 * permissions and limitations under the License. 016 */ 017package org.microbean.configuration; 018 019import java.io.Serializable; // for javadoc only 020 021import java.lang.reflect.Type; 022 023import org.microbean.configuration.api.ConfigurationException; 024 025import org.microbean.configuration.spi.Converter; // for javadoc only 026 027/** 028 * A {@link ConfigurationException} that indicates that a {@linkplain 029 * Converter#getType() suitable} {@link Converter} could not be found 030 * for a given {@link Type}. 031 * 032 * @author <a href="https://about.me/lairdnelson" 033 * target="_parent">Laird Nelson</a> 034 * 035 * @see Converter#getType() 036 */ 037public class NoSuchConverterException extends ConfigurationException { 038 039 040 /* 041 * Static fields. 042 */ 043 044 045 /** 046 * The version of this class for {@linkplain Serializable 047 * serialization} purposes. 048 */ 049 private static final long serialVersionUID = 1L; 050 051 052 /* 053 * Instance fields. 054 */ 055 056 057 /** 058 * The {@link Type} for which a {@linkplain Converter#getType() 059 * suitable} {@link Converter} could not be found. 060 * 061 * <p>This field may be {@code null}.</p> 062 * 063 * @see Converter#getType() 064 */ 065 private final Type type; 066 067 068 /* 069 * Constructors. 070 */ 071 072 073 /** 074 * Creates a new {@link NoSuchConverterException}. 075 */ 076 public NoSuchConverterException() { 077 super(); 078 this.type = null; 079 } 080 081 /** 082 * Creates a new {@link NoSuchConverterException}. 083 * 084 * @param type the {@link Type} for which a {@linkplain 085 * Converter#getType() suitable} {@link Converter} could not be 086 * found; may be {@code null} 087 * 088 * @see #getType() 089 */ 090 public NoSuchConverterException(final Type type) { 091 super(type == null ? null : type.toString(), null); 092 this.type = type; 093 } 094 095 /** 096 * Creates a new {@link NoSuchConverterException}. 097 * 098 * @param message the error message; may be {@code null} 099 * 100 * @param cause the {@link Throwable} that caused this {@link 101 * NoSuchConverterException} to be created; may be {@code null} 102 * 103 * @param type the {@link Type} for which a {@linkplain 104 * Converter#getType() suitable} {@link Converter} could not be 105 * found; may be {@code null} 106 * 107 * @see #getType() 108 */ 109 public NoSuchConverterException(final String message, final Throwable cause, final Type type) { 110 super(message, cause); 111 this.type = type; 112 } 113 114 115 /* 116 * Instance methods. 117 */ 118 119 120 /** 121 * Returns the {@link Type} for which a {@linkplain Converter#getType() 122 * suitable} {@link Converter} could not be found. 123 * 124 * <p>This method may return {@code null}.</p> 125 * 126 * @return the {@link Type} for which a {@linkplain 127 * Converter#getType() suitable} {@link Converter} could not be 128 * found, or {@code null} 129 * 130 * @see Converter#getType() 131 */ 132 public final Type getType() { 133 return this.type; 134 } 135 136}