| 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 | * Thrown when a reference has already been stored in a {@link CachedAppendable}. |
| 23 | * This exception allows for the retrieval of the identifier generated during |
| 24 | * the previous <code>store</code> call. |
| 25 | * @author michaeldoberenz |
| 26 | */ |
| 27 | public class ReferenceExistsException extends Exception{ |
| 28 | private static final long serialVersionUID = 1L; |
| 29 | private final String reference; |
| 30 | private final Object object; |
| 31 | |
| 32 | /** |
| 33 | * Creates an instance based on the unique identifier <code>reference</code> |
| 34 | * from a prior <code>ReferenceCache.store</code> call. |
| 35 | * @param reference the unique identifier |
| 36 | * @param object the referenced object |
| 37 | */ |
| 38 | public ReferenceExistsException(final String reference, final Object object){ |
| 39 | this.reference = reference; |
| 40 | this.object = object; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Creates an instance from a reference object. |
| 45 | * @param ref the already existing reference |
| 46 | */ |
| 47 | public ReferenceExistsException(final Reference ref){ |
| 48 | this(ref.getName(), ref.getObject()); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Returns the unique identifier. |
| 53 | * @return the unique identifier |
| 54 | */ |
| 55 | public String getReference(){ |
| 56 | return reference; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns the object stored with the reference. |
| 61 | * @return the stored object |
| 62 | */ |
| 63 | public Object getStoredObject(){ |
| 64 | return object; |
| 65 | } |
| 66 | } |