Coverage Report - org.simpleframework.xml.core.Creator
 
Classes in this File Line Coverage Branch Coverage Complexity
Creator
N/A
N/A
1
 
 1  
 /*
 2  
  * Instantiator.java April 2009
 3  
  *
 4  
  * Copyright (C) 2009, 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>Instantiator</code> object is used to represent an single
 23  
  * constructor within an object. It contains the actual constructor
 24  
  * as well as the list of parameters. Each instantiator will score its
 25  
  * weight when given a <code>Criteria</code> object. This allows
 26  
  * the deserialization process to find the most suitable one to
 27  
  * use when instantiating an object.
 28  
  * 
 29  
  * @author Niall Gallagher
 30  
  */
 31  
 interface Creator {
 32  
 
 33  
    /**
 34  
     * This is used to instantiate the object using the default no
 35  
     * argument constructor. If for some reason the object can not be
 36  
     * instantiated then this will throw an exception with the reason.
 37  
     * 
 38  
     * @return this returns the object that has been instantiated
 39  
     */
 40  
    Object getInstance() throws Exception; 
 41  
    
 42  
    /**
 43  
     * This is used to instantiate the object using a constructor that
 44  
     * takes deserialized objects as arguments. The object that have
 45  
     * been deserialized can be taken from the <code>Criteria</code>
 46  
     * object which contains the deserialized values.
 47  
     *
 48  
     * @param criteria this contains the criteria to be used
 49  
     * 
 50  
     * @return this returns the object that has been instantiated
 51  
     */
 52  
    Object getInstance(Criteria criteria) throws Exception;
 53  
 
 54  
    /**
 55  
     * This is used to score this <code>Instantiator</code> object so that
 56  
     * it can be weighed amongst other constructors. The instantiator that
 57  
     * scores the highest is the one that is used for insIntantiation.
 58  
     * <p>
 59  
     * If any read only element or attribute is not a parameter in
 60  
     * the constructor then the constructor is discounted. This is
 61  
     * because there is no way to set the read only entity without a
 62  
     * constructor injection in to the instantiated object.
 63  
     * 
 64  
     * @param criteria this contains the criteria to be used
 65  
     * 
 66  
     * @return this returns the score based on the criteria provided
 67  
     */
 68  
    double getScore(Criteria criteria) throws Exception;
 69  
    
 70  
    /**
 71  
     * This is the signature associated with the creator. The signature
 72  
     * contains all the parameters associated with the creator as well
 73  
     * as the constructor that this represents. Exposing the signature
 74  
     * allows the creator to be validated.
 75  
     * 
 76  
     * @return this is the signature associated with the creator
 77  
     */
 78  
    Signature getSignature() throws Exception;
 79  
    
 80  
    /**
 81  
     * This is the type associated with the <code>Creator</code> object.
 82  
     * All instances returned from this creator will be of this type.
 83  
     * 
 84  
     * @return this returns the type associated with this creator
 85  
     */
 86  
    Class getType() throws Exception;
 87  
 }