| 1 | /* |
| 2 | * This file is part of JON. |
| 3 | * |
| 4 | * JON is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Lesser General Public License as published by |
| 6 | * the Free Software Foundation; either version 3 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * JON is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public License |
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | * Copyright 2007 Michael Doberenz |
| 18 | */ |
| 19 | package org.fuwjax.jon; |
| 20 | |
| 21 | /** |
| 22 | * Indicates that an object relationship could not be followed or maintained. |
| 23 | * @author michaeldoberenz |
| 24 | */ |
| 25 | public class ObjectAccessException extends Exception{ |
| 26 | private static final long serialVersionUID = 1L; |
| 27 | |
| 28 | /** |
| 29 | * The set of possible exception messages for this exception. |
| 30 | * @author michaeldoberenz |
| 31 | */ |
| 32 | public enum Message{ |
| 33 | /** |
| 34 | * Indicates that a null type was used to access a non-null object. |
| 35 | */ |
| 36 | NonNullNotInstanceOfNullType, |
| 37 | /** |
| 38 | * Indicates that an object of an incompatible type was used to access a |
| 39 | * field. |
| 40 | */ |
| 41 | ObjectNotInstanceOfType, |
| 42 | /** |
| 43 | * Indicates that a field is not marked accessible and could not be read |
| 44 | * or modified. |
| 45 | */ |
| 46 | FieldInaccessible, |
| 47 | /** |
| 48 | * Indicates that a literal could not be converted back to a primitive. |
| 49 | */ |
| 50 | PrimitiveParseFailure, |
| 51 | /** |
| 52 | * Indicates that an instance could not be created with |
| 53 | * Class.newInstance(). |
| 54 | */ |
| 55 | NaiveCreationFailed, |
| 56 | /** |
| 57 | * Indicates that a requested field does not exist on the class. |
| 58 | */ |
| 59 | FieldNotFound, |
| 60 | /** |
| 61 | * Indicates that an object could not be allocated by the instantiator. |
| 62 | */ |
| 63 | ObjectNotAllocated, |
| 64 | /** |
| 65 | * Indicates that a constructor was not accessible and could not be used |
| 66 | * by the instantiator. |
| 67 | */ |
| 68 | ConstructorInaccessible, |
| 69 | /** |
| 70 | * Indicates that a factory method was not accessible and could not be |
| 71 | * used to retrieve or create an object instance. |
| 72 | */ |
| 73 | MethodInaccessible, |
| 74 | /** |
| 75 | * Indicates that a factory method failed for one of any number of |
| 76 | * reasons. |
| 77 | */ |
| 78 | MethodFailure, |
| 79 | /** |
| 80 | * Indicates that a literal could not be mapped to a known value. |
| 81 | */ |
| 82 | InvalidLiteral, |
| 83 | /** |
| 84 | * Indicates that a class could not be found from its name. |
| 85 | */ |
| 86 | ClassNotFound; |
| 87 | /** |
| 88 | * Returns an exception of this subtype. |
| 89 | * @return an {@link ObjectAccessException} |
| 90 | */ |
| 91 | public ObjectAccessException exception(){ |
| 92 | return new ObjectAccessException(name()); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Returns an exception of this subtype. |
| 97 | * @param cause the cause of this exception |
| 98 | * @return an {@link ObjectAccessException} |
| 99 | */ |
| 100 | public ObjectAccessException exception(final Throwable cause){ |
| 101 | return new ObjectAccessException(name(), cause); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Creates a new instance with a message <code>message</code>. |
| 107 | * @param message a description of the cause of this exception |
| 108 | * @param cause the cause of this exception |
| 109 | */ |
| 110 | public ObjectAccessException(final String message, final Throwable cause){ |
| 111 | super(message, cause); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Creates a new instance with a message <code>message</code>. |
| 116 | * @param message a description of the cause of this exception |
| 117 | */ |
| 118 | public ObjectAccessException(final String message){ |
| 119 | super(message); |
| 120 | } |
| 121 | } |