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

COVERAGE SUMMARY FOR SOURCE FILE [AbstractIndirectType.java]

nameclass, %method, %block, %line, %
AbstractIndirectType.java100% (3/3)100% (15/15)100% (97/97)100% (22/22)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AbstractIndirectType100% (1/1)100% (10/10)100% (55/55)100% (16/16)
AbstractIndirectType (Class): void 100% (1/1)100% (6/6)100% (3/3)
createReader (CachedLexable): Reader 100% (1/1)100% (6/6)100% (1/1)
createWriter (CachedAppendable): Writer 100% (1/1)100% (6/6)100% (1/1)
getActualType (Object): IndirectType 100% (1/1)100% (13/13)100% (3/3)
getIndirectType (Class): IndirectType 100% (1/1)100% (5/5)100% (1/1)
getIndirectTypeFor (Object): IndirectType 100% (1/1)100% (5/5)100% (1/1)
getName (): String 100% (1/1)100% (4/4)100% (1/1)
getType (): Class 100% (1/1)100% (3/3)100% (1/1)
init (): void 100% (1/1)100% (1/1)100% (1/1)
setLibrary (IndirectTypeLibrary): void 100% (1/1)100% (6/6)100% (3/3)
     
class AbstractIndirectType$1100% (1/1)100% (2/2)100% (17/17)100% (3/3)
AbstractIndirectType$1 (AbstractIndirectType, CachedAppendable): void 100% (1/1)100% (9/9)100% (1/1)
write (Object): void 100% (1/1)100% (8/8)100% (2/2)
     
class AbstractIndirectType$2100% (1/1)100% (3/3)100% (25/25)100% (3/3)
AbstractIndirectType$2 (AbstractIndirectType, CachedLexable): void 100% (1/1)100% (9/9)100% (1/1)
read (): Object 100% (1/1)100% (8/8)100% (1/1)
read (Object): Object 100% (1/1)100% (8/8)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.type;
20 
21import org.fuwjax.jon.CachedAppendable;
22import org.fuwjax.jon.CachedLexable;
23import org.fuwjax.jon.IndirectType;
24import org.fuwjax.jon.IndirectTypeLibrary;
25import org.fuwjax.jon.ObjectAccessException;
26import org.fuwjax.jon.Reader;
27import org.fuwjax.jon.SerialFormatException;
28import org.fuwjax.jon.Writer;
29import org.fuwjax.jon.accessor.Symbol;
30 
31/**
32 * A base class for {@link IndirectType}.
33 * @author michaeldoberenz
34 */
35public abstract class AbstractIndirectType implements IndirectType{
36        private Class<?> cls;
37        private IndirectTypeLibrary library;
38 
39        /**
40         * Creates a new instance.
41         * @param cls class this indirect type is referencing
42         */
43        protected AbstractIndirectType(final Class<?> cls){
44                this.cls = cls;
45        }
46 
47        /**
48         * Sets the library which contains this type.
49         * @param library the library which produced this type
50         */
51        public final void setLibrary(final IndirectTypeLibrary library){
52                this.library = library;
53                init();
54        }
55 
56        /**
57         * Callback for subclass initialization. Called after this class has been
58         * added to its parent library.
59         */
60        protected void init(){
61                // do nothing by default
62        }
63 
64        public IndirectType getActualType(final Object object) throws ClassCastException{
65                if(cls.equals(object.getClass())){
66                        return this;
67                }
68                return library.getTypeFor(object);
69        }
70 
71        public String getName(){
72                return cls.getCanonicalName();
73        }
74 
75        /**
76         * Returns the class instance backing this indirect type.
77         * @return the class instance backing this indirect type
78         */
79        public Class<?> getType(){
80                return cls;
81        }
82 
83        /**
84         * Deduces the indirect type for <code>type</code> from the library.
85         * @param type the class instance whose indirect type is deduced
86         * @return the deduced indirect type
87         */
88        public IndirectType getIndirectType(final Class<?> type){
89                return library.getType(type);
90        }
91 
92        /**
93         * Deduces the indirect type for the class of <code>object</code> from the
94         * library.
95         * @param object the object whose class the indirect type is deduced from
96         * @return the deduced indirect type
97         */
98        protected IndirectType getIndirectTypeFor(final Object object){
99                return library.getTypeFor(object);
100        }
101 
102        public Writer createWriter(final CachedAppendable appender){
103                return new Writer(){
104                        public void write(final Object object) throws ObjectAccessException, SerialFormatException{
105                                Symbol.Element.write(appender, object, AbstractIndirectType.this);
106                        }
107                };
108        }
109 
110        public Reader createReader(final CachedLexable lexer){
111                return new Reader(){
112                        public Object read() throws ObjectAccessException, SerialFormatException{
113                                return Symbol.Element.read(lexer, null, AbstractIndirectType.this);
114                        }
115 
116                        public Object read(final Object object) throws ObjectAccessException, SerialFormatException{
117                                return Symbol.Element.read(lexer, object, AbstractIndirectType.this);
118                        }
119                };
120        }
121}

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