EMMA Coverage Report (generated Wed Aug 29 00:03:59 CDT 2007)
[all classes][org.fuwjax.jon]

COVERAGE SUMMARY FOR SOURCE FILE [ReferenceStrategy.java]

nameclass, %method, %block, %line, %
ReferenceStrategy.java100% (3/3)100% (10/10)100% (117/117)100% (27/27)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ReferenceStrategy100% (1/1)100% (6/6)100% (81/81)100% (16/16)
<static initializer> 100% (1/1)100% (29/29)100% (4/4)
ReferenceStrategy (String, int): void 100% (1/1)100% (5/5)100% (1/1)
ReferenceStrategy (String, int, ReferenceStrategy$1): void 100% (1/1)100% (5/5)100% (1/1)
read (CachedLexable): Reference 100% (1/1)100% (33/33)100% (12/12)
valueOf (String): ReferenceStrategy 100% (1/1)100% (5/5)100% (1/1)
values (): ReferenceStrategy [] 100% (1/1)100% (4/4)100% (1/1)
     
class ReferenceStrategy$1100% (1/1)100% (2/2)100% (29/29)100% (9/9)
ReferenceStrategy$1 (String, int): void 100% (1/1)100% (6/6)100% (1/1)
write (CachedAppendable, Object): void 100% (1/1)100% (23/23)100% (8/8)
     
class ReferenceStrategy$2100% (1/1)100% (2/2)100% (7/7)100% (2/2)
ReferenceStrategy$2 (String, int): void 100% (1/1)100% (6/6)100% (1/1)
write (CachedAppendable, Object): void 100% (1/1)100% (1/1)100% (1/1)

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 */
19package org.fuwjax.jon;
20 
21import org.fuwjax.jon.accessor.Symbol;
22import org.fuwjax.jon.accessor.Token;
23import org.fuwjax.jon.type.ReferenceType;
24 
25/**
26 * The strategy for determining whether or not a particular {@link IndirectType}
27 * will serialize with a reference.
28 * @author michaeldoberenz
29 */
30public enum ReferenceStrategy{
31        /**
32         * Store <code>object</code> in <code>cache</code> and write the
33         * generated unique id to <code>writer</code>.
34         */
35        AssignedReference{
36                @Override
37                public void write(final CachedAppendable writer, final Object object) throws ReferenceExistsException,
38                      ObjectAccessException, SerialFormatException{
39                        try{
40                                final String reference = writer.store(object);
41                                Symbol.Literal.write(writer, reference, ReferenceType.DEFAULT);
42                                Token.ReferenceAssignment.write(writer);
43                        }catch(ReferenceExistsException e){
44                                Symbol.Literal.write(writer, e.getReference(), ReferenceType.DEFAULT);
45                                throw e;
46                        }
47                }
48        },
49        /**
50         * Do not store or write a reference.
51         */
52        NeverReference{
53                @Override
54                public void write(final CachedAppendable writer, final Object object) throws ReferenceExistsException,
55                      ObjectAccessException, SerialFormatException{
56                        // write nothing
57                }
58        };
59        private static final Reference IGNORED_REFERENCE = new Reference(null);
60 
61        /**
62         * Writes a reference to the appender for the given object from the cache.
63         * @param writer the destination for the reference string
64         * @param object the object whose reference should be written
65         * @throws ReferenceExistsException if <code>object</code> has already been
66         *         stored on <code>writer</code>
67         * @throws ObjectAccessException if an object relationship cannot be followed
68         * @throws SerialFormatException if the JON format cannot be preserved
69         */
70        public abstract void write(final CachedAppendable writer, final Object object) throws ReferenceExistsException,
71              ObjectAccessException, SerialFormatException;
72 
73        /**
74         * Reads a reference id from <code>lexer</code> for the next object and
75         * returns the reference for the id.
76         * @param lexer the source for the reference id
77         * @return the reference corresponding to the reference id
78         * @throws ReferenceExistsException if the reference id has been previously
79         *         reserved
80         * @throws ObjectAccessException if an object relationship cannot be restored
81         * @throws SerialFormatException if the JON format has not been observed
82         */
83        public static Reference read(final CachedLexable lexer) throws ReferenceExistsException, ObjectAccessException,
84              SerialFormatException{
85                String referenceId;
86                final int pos = lexer.getPosition();
87                try{
88                        referenceId = Symbol.Literal.read(lexer, null, ReferenceType.DEFAULT).toString();
89                }catch(SerialFormatException e){
90                        e.assertPosition(pos);
91                        return IGNORED_REFERENCE;
92                }
93                final Reference ref = lexer.reserve(referenceId);
94                try{
95                        Token.ReferenceAssignment.read(lexer);
96                }catch(SerialFormatException e){
97                        throw new ReferenceExistsException(ref);
98                }
99                return ref;
100        }
101}

[all classes][org.fuwjax.jon]
EMMA 2.0.5312 (C) Vladimir Roubtsov