1 /******************************************************************************* 2 * Copyright 2013 André Rouél and Dominik Seichter 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16 package net.sf.qualitytest.exception; 17 18 import javax.annotation.Nullable; 19 20 /** 21 * Thrown to indicate that a class does not have a public constructor and therefore blueprinting is not available. 22 * 23 * @author André Rouél 24 * @author Dominik Seichter 25 */ 26 public class NoPublicConstructorException extends BlueprintException { 27 28 private static final long serialVersionUID = 5632735367544191025L; 29 30 /** 31 * Default message to indicate that a given class has no public constructor. 32 */ 33 protected static final String DEFAULT_MESSAGE = "The given class has no public constructor."; 34 35 /** 36 * Message to indicate that a given class has no public constructor. 37 */ 38 protected static final String MESSAGE_WITH_NAME = "The given class '%s' has no public constructor."; 39 40 /** 41 * Returns the formatted string {@link NoPublicConstructorException#MESSAGE_WITH_NAME} with the given 42 * {@code argumentName}. 43 * 44 * @param className 45 * the name of the passed class 46 * @return a formatted string of message with the given argument name 47 */ 48 private static String format(@Nullable final String className) { 49 if (className != null) { 50 return String.format(MESSAGE_WITH_NAME, className); 51 } else { 52 return DEFAULT_MESSAGE; 53 } 54 } 55 56 /** 57 * Constructs an {@code NoPublicConstructorException} with the default message 58 * {@link NoPublicConstructorException#DEFAULT_MESSAGE}. 59 */ 60 public NoPublicConstructorException() { 61 super(DEFAULT_MESSAGE); 62 } 63 64 /** 65 * Constructs an {@code NoPublicConstructorException} with the message 66 * {@link NoPublicConstructorException#MESSAGE_WITH_NAME} including the given name of the class as string 67 * representation. 68 * 69 * @param className 70 * the name of the passed class 71 */ 72 public NoPublicConstructorException(@Nullable final String className) { 73 super(format(className)); 74 } 75 76 /** 77 * Constructs a new exception with the message {@link NoPublicConstructorException#MESSAGE_WITH_NAME} including the 78 * given name as string representation and cause. 79 * 80 * @param className 81 * the name of the passed class 82 * @param cause 83 * the cause (which is saved for later retrieval by the {@link Throwable#getCause()} method). (A 84 * {@code null} value is permitted, and indicates that the cause is nonexistent or unknown.) 85 */ 86 public NoPublicConstructorException(@Nullable final String className, @Nullable final Throwable cause) { 87 super(format(className), cause); 88 } 89 90 /** 91 * Constructs a new exception with the default message {@link NoPublicConstructorException#DEFAULT_MESSAGE}. 92 * 93 * @param cause 94 * the cause (which is saved for later retrieval by the {@link Throwable#getCause()} method). (A 95 * {@code null} value is permitted, and indicates that the cause is nonexistent or unknown.) 96 */ 97 public NoPublicConstructorException(@Nullable final Throwable cause) { 98 super(DEFAULT_MESSAGE, cause); 99 } 100 }