001: /*
002: * LICENSE INFORMATION
003: * Copyright 2005-2007 by FZI (http://www.fzi.de).
004: * Licensed under a BSD license (http://www.opensource.org/licenses/bsd-license.php)
005: * <OWNER> = Max Völkel
006: * <ORGANIZATION> = FZI Forschungszentrum Informatik Karlsruhe, Karlsruhe, Germany
007: * <YEAR> = 2007
008: *
009: * Project information at http://semweb4j.org/rdf2go
010: */
011: package org.ontoware.rdf2go.util;
012:
013: /**
014: * Thrown when an rdf2go adapter cannot convert from one class to another.
015: * The source object that cannot be conveted and the target class that
016: * was the goal of the conversion are passed.
017: *
018: *
019: * @author sauermann <leo.sauermann@dfki.de>
020: */
021: public class ConversionException extends RuntimeException {
022:
023: /**
024: *
025: */
026: private static final long serialVersionUID = -1866748054068895807L;
027: Object sourceObject;
028: Class<?> targetClass;
029:
030: /**
031: * default constructor
032: */
033: public ConversionException() {
034: //empty default constructor
035: }
036:
037: /**
038: * constructor, with an injected message
039: *
040: * @param message
041: */
042: public ConversionException(String message) {
043: super (message);
044: }
045:
046: /**
047: * @param cause
048: */
049: public ConversionException(Throwable cause) {
050: super (cause);
051: }
052:
053: /**
054: * @param message
055: * @param cause
056: */
057: public ConversionException(String message, Throwable cause) {
058: super (message, cause);
059: }
060:
061: /**
062: * Generate a new conversion exception. The exception will start with
063: * a string automatically generated from using the toString of the source
064: * object and the targetclass. You can give a message or leave it empty.
065: * @param message
066: * @param sourceObject
067: * @param targetClass
068: */
069: public ConversionException(String message, Object sourceObject,
070: Class<?> targetClass) {
071: super (generateMessage(message, sourceObject, targetClass));
072: this .sourceObject = sourceObject;
073: this .targetClass = targetClass;
074: }
075:
076: /**
077: * generate the error message
078: */
079: protected static String generateMessage(String message,
080: Object sourceObject2, Class<?> targetClass2) {
081:
082: return "Could not convert '"
083: + sourceObject2
084: + "' "
085: + ((sourceObject2 == null) ? "" : "of class "
086: + sourceObject2.getClass().getName())
087: + " to target class " + targetClass2
088: + ((message != null) ? ": " + message : "");
089: }
090:
091: /**
092: *
093: * @return the source object that could not be converted.
094: */
095: public Object getSourceObject() {
096: return this .sourceObject;
097: }
098:
099: /**
100: *
101: * @return the target class that should be converted to
102: */
103: public Class<?> getTargetClass() {
104: return this.targetClass;
105: }
106:
107: }
|