/*
 * Copyright (c) 2011-2013 GoPivotal, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package reactor.convert;

/**
 * @author Jon Brisbin
 */
public class ConversionFailedException extends IllegalStateException {

	private static final long serialVersionUID = -8502594056926933555L;
	private final Class<?> sourceType;
	private final Class<?> targetType;

	ConversionFailedException(Class<?> sourceType, Class<?> targetType) {
		super(String.format("Cannot convert %s to type %s", sourceType.getName(), targetType.getName()));
		this.sourceType = sourceType;
		this.targetType = targetType;
	}

	ConversionFailedException(Throwable cause, Class<?> sourceType, Class<?> targetType) {
		super(String.format("Cannot convert %s to type %s", sourceType.getName(), targetType.getName()), cause);
		this.sourceType = sourceType;
		this.targetType = targetType;
	}

	/**
	 * Returns the type that could not be converted from
	 *
	 * @return the type that could not be converted from
	 */
	public Class<?> getSourceType() {
		return sourceType;
	}

	/**
	 * Returns the type that could not be converted to
	 *
	 * @return the type that could not be converted to
	 */
	public Class<?> getTargetType() {
		return targetType;
	}

}
