| 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.accessor; |
| 20 | |
| 21 | import org.fuwjax.jon.CachedAppendable; |
| 22 | import org.fuwjax.jon.CachedLexable; |
| 23 | import org.fuwjax.jon.SerialFormatException; |
| 24 | |
| 25 | /** |
| 26 | * The set of tokens in the JON format specification. |
| 27 | * @author michaeldoberenz |
| 28 | */ |
| 29 | public enum Token{ |
| 30 | /** |
| 31 | * indicates the start of a Class Cast symbol. |
| 32 | */ |
| 33 | ClassCastStart('('), |
| 34 | /** |
| 35 | * indicates the end of a Class Cast symbol. |
| 36 | */ |
| 37 | ClassCastStop(')'), |
| 38 | /** |
| 39 | * indicates the start of a Reference Identifier symbol. |
| 40 | */ |
| 41 | ReferenceIdentifierStart('&'), |
| 42 | /** |
| 43 | * used to separate the Reference Identifier symbol from the Serialized |
| 44 | * Object symbol in a Reference Assignment symbol. |
| 45 | */ |
| 46 | ReferenceAssignment('='), |
| 47 | /** |
| 48 | * indicates the start of a Map symbol. |
| 49 | */ |
| 50 | MapStart('{'), |
| 51 | /** |
| 52 | * indicates the end of a Map symbol. |
| 53 | */ |
| 54 | MapStop('}'), |
| 55 | /** |
| 56 | * used to separate the Map Entry symbols in a Map symbol. |
| 57 | */ |
| 58 | EntrySeparator(','), |
| 59 | /** |
| 60 | * used to separate the Map Key symbol from a Map Value symbol in a Map Entry |
| 61 | * symbol. |
| 62 | */ |
| 63 | KeyValueSeparator(':'), |
| 64 | /** |
| 65 | * indicates the start of a List symbol. |
| 66 | */ |
| 67 | ListStart('['), |
| 68 | /** |
| 69 | * indicates the end of a List symbol. |
| 70 | */ |
| 71 | ListStop(']'), |
| 72 | /** |
| 73 | * used to separate the List Element symbols in a List symbol. |
| 74 | */ |
| 75 | ElementSeparator(','), |
| 76 | /** |
| 77 | * indicates the start of an Object symbol. |
| 78 | */ |
| 79 | ObjectStart('{'), |
| 80 | /** |
| 81 | * indicates the end of an Object symbol. |
| 82 | */ |
| 83 | ObjectStop('}'), |
| 84 | /** |
| 85 | * used to separate the Partition symbols in an Object symbol. |
| 86 | */ |
| 87 | PartitionSeparator('|'), |
| 88 | /** |
| 89 | * used to separate the Field symbols in a Partition symbol. |
| 90 | */ |
| 91 | FieldSeparator(','), |
| 92 | /** |
| 93 | * used to separate the Field Name symbol from the Field Value symbol in a |
| 94 | * Field symbol. |
| 95 | */ |
| 96 | NameValueSeparator(':'), |
| 97 | /** |
| 98 | * indicates the start and end of a String symbol. |
| 99 | */ |
| 100 | StringDelimiter('"'); |
| 101 | private char token; |
| 102 | |
| 103 | private Token(final char token){ |
| 104 | this.token = token; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Writes this token to <code>writer</code>. |
| 109 | * @param writer the destination for this write operation |
| 110 | * @throws SerialFormatException if the JON format cannot be preserved |
| 111 | */ |
| 112 | public void write(final CachedAppendable writer) throws SerialFormatException{ |
| 113 | writer.write(token); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Reads a token from <code>lexer</code> and asserts that it is the same as |
| 118 | * this token. |
| 119 | * @param lexer the source for the read |
| 120 | * @throws SerialFormatException if the JON format has not been observed |
| 121 | */ |
| 122 | public void read(final CachedLexable lexer) throws SerialFormatException{ |
| 123 | lexer.read(token); |
| 124 | } |
| 125 | } |