| 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.type; |
| 20 | |
| 21 | import org.fuwjax.jon.ClassCastStrategy; |
| 22 | import org.fuwjax.jon.IndirectType; |
| 23 | import org.fuwjax.jon.ObjectAccessException; |
| 24 | import org.fuwjax.jon.ReferenceStrategy; |
| 25 | import org.fuwjax.jon.accessor.Literal; |
| 26 | import org.fuwjax.jon.accessor.LiteralAccessor; |
| 27 | import org.fuwjax.jon.accessor.Symbol; |
| 28 | |
| 29 | /** |
| 30 | * An abstract type for literal values. |
| 31 | * @author michaeldoberenz |
| 32 | */ |
| 33 | public final class IdentifierType extends AbstractIndirectType implements LiteralAccessor{ |
| 34 | /** |
| 35 | * The singleton instance. |
| 36 | */ |
| 37 | public static final IdentifierType DEFAULT = new IdentifierType(); |
| 38 | |
| 39 | private IdentifierType(){ |
| 40 | super(null); |
| 41 | } |
| 42 | |
| 43 | public CharSequence toString(final Object object) throws ObjectAccessException{ |
| 44 | return object.toString(); |
| 45 | } |
| 46 | |
| 47 | public Object createInstance(final CharSequence parse, final Object source) throws ObjectAccessException{ |
| 48 | return parse.toString(); |
| 49 | } |
| 50 | |
| 51 | public ClassCastStrategy getClassCastStrategy(){ |
| 52 | return ClassCastStrategy.NeverCast; |
| 53 | } |
| 54 | |
| 55 | public ReferenceStrategy getReferenceStrategy(){ |
| 56 | return ReferenceStrategy.NeverReference; |
| 57 | } |
| 58 | |
| 59 | public Symbol getSymbolSpec(){ |
| 60 | return Symbol.Literal; |
| 61 | } |
| 62 | |
| 63 | public Literal getLiteral(){ |
| 64 | return Literal.Identifier; |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public IndirectType getActualType(final Object object) throws ClassCastException{ |
| 69 | return this; |
| 70 | } |
| 71 | } |