Coverage Report - org.simpleframework.xml.strategy.ObjectValue
 
Classes in this File Line Coverage Branch Coverage Complexity
ObjectValue
88%
8/9
N/A
1
 
 1  
 /*
 2  
  * ObjectValue.java January 2007
 3  
  *
 4  
  * Copyright (C) 2007, Niall Gallagher <niallg@users.sf.net>
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
 15  
  * implied. See the License for the specific language governing 
 16  
  * permissions and limitations under the License.
 17  
  */
 18  
 
 19  
 package org.simpleframework.xml.strategy;
 20  
 
 21  
 /**
 22  
  * The <code>ObjectValue</code> is an implementation of a value
 23  
  * that represents a object other than an array. Objects described
 24  
  * by this can be instantiated and set in to the internal graph 
 25  
  * so that they can be later retrieved.
 26  
  * 
 27  
  * @author Niall Gallagher
 28  
  * 
 29  
  * @see org.simpleframework.xml.strategy.Allocate
 30  
  */
 31  
 class ObjectValue implements Value {
 32  
    
 33  
    /**
 34  
     * This is the value that has been set for this instance.
 35  
     */
 36  
    private Object value;
 37  
    
 38  
    /**
 39  
     * This is the type that this object is used to represent.
 40  
     */
 41  
    private Class type;
 42  
 
 43  
    /**
 44  
     * Constructor for the <code>ObjectValue</code> object. This is
 45  
     * used to describe an object that can be instantiated by the
 46  
     * deserialization process and set on the internal graph used.
 47  
     * 
 48  
     * @param type this is the type of object that is described
 49  
     */
 50  92792
    public ObjectValue(Class type) {
 51  92792
       this.type = type;
 52  92792
    }        
 53  
    
 54  
    /**
 55  
     * This method is used to acquire an instance of the type that
 56  
     * is defined by this object. If the value has not been set
 57  
     * then this method will return null as this is not a reference.
 58  
     * 
 59  
     * @return an instance of the type this object represents
 60  
     */
 61  
    public Object getValue() {
 62  0
       return value;
 63  
    }
 64  
    
 65  
    /**
 66  
     * This method is used set the value within this object. Once
 67  
     * this is set then the <code>getValue</code> method will return
 68  
     * the object that has been provided for consistency. 
 69  
     * 
 70  
     * @param value this is the value to insert as the type
 71  
     */
 72  
    public void setValue(Object value) {
 73  110388
       this.value = value;
 74  110388
    }
 75  
    
 76  
    /**
 77  
     * This is the type of the object instance this represents. The
 78  
     * type returned by this is used to instantiate an object which
 79  
     * will be set on this value and the internal graph maintained.
 80  
     * 
 81  
     * @return the type of the object that will be instantiated
 82  
     */
 83  
    public Class getType() {
 84  185560
       return type;
 85  
    }
 86  
    
 87  
    /**
 88  
     * This returns zero as this is an object and will typically
 89  
     * not be used to instantiate anything. If the reference is an
 90  
     * an array then this can not be used to instantiate it.
 91  
     * 
 92  
     * @return this returns zero regardless of the value type
 93  
     */
 94  
    public int getLength() {
 95  1
       return 0;
 96  
    }
 97  
    
 98  
    /**
 99  
     * This method always returns false for the default type. This
 100  
     * is because by default all elements encountered within the 
 101  
     * XML are to be deserialized based on there XML annotations.
 102  
     * 
 103  
     * @return this returns false for each type encountered     
 104  
     */
 105  
    public boolean isReference() {
 106  140761
       return false;
 107  
    }
 108  
 }