Coverage Report - org.simpleframework.xml.core.Instance
 
Classes in this File Line Coverage Branch Coverage Complexity
Instance
N/A
N/A
1
 
 1  
 /*
 2  
  * Instance.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.core;
 20  
 
 21  
 /**
 22  
  * The <code>Instance</code> object creates a type that is represented 
 23  
  * by an XML element. Typically the <code>getInstance</code> method 
 24  
  * acts as a proxy to the classes new instance method, which takes no 
 25  
  * arguments. Simply delegating to <code>Class.newInstance</code> will 
 26  
  * sometimes not be sufficient, is such cases reflectively acquiring 
 27  
  * the classes constructor may be required in order to pass arguments.
 28  
  * 
 29  
  * @author Niall Gallagher
 30  
  * 
 31  
  * @see org.simpleframework.xml.strategy.Value
 32  
  */
 33  
 interface Instance {
 34  
    
 35  
    /**
 36  
     * This method is used to acquire an instance of the type that
 37  
     * is defined by this object. If for some reason the type can
 38  
     * not be instantiated an exception is thrown from this.
 39  
     * 
 40  
     * @return an instance of the type this object represents
 41  
     */
 42  
    Object getInstance() throws Exception;
 43  
    
 44  
    /**
 45  
     * This method is used acquire the value from the type and if
 46  
     * possible replace the value for the type. If the value can
 47  
     * not be replaced then an exception should be thrown. This 
 48  
     * is used to allow primitives to be inserted into a graph.
 49  
     * 
 50  
     * @param value this is the value to insert as the type
 51  
     * 
 52  
     * @return an instance of the type this object represents
 53  
     */
 54  
    Object setInstance(Object value) throws Exception;
 55  
    
 56  
    /**
 57  
     * This is used to determine if the type is a reference type.
 58  
     * A reference type is a type that does not require any XML
 59  
     * deserialization based on its annotations. Values that are
 60  
     * references could be substitutes objects or existing ones. 
 61  
     * 
 62  
     * @return this returns true if the object is a reference
 63  
     */
 64  
    boolean isReference();
 65  
    
 66  
    /**
 67  
     * This is the type of the object instance that will be created
 68  
     * by the <code>getInstance</code> method. This allows the 
 69  
     * deserialization process to perform checks against the field.
 70  
     * 
 71  
     * @return the type of the object that will be instantiated
 72  
     */
 73  
    Class getType();
 74  
 }