Coverage Report - org.simpleframework.xml.transform.DateFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
DateFactory
100%
6/6
N/A
1
 
 1  
 /*
 2  
  * DateTransform.java May 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.transform;
 20  
 
 21  
 import java.lang.reflect.Constructor;
 22  
 import java.util.Date;
 23  
 
 24  
 /**
 25  
  * The <code>DateFactory</code> object is used to create instances
 26  
  * or subclasses of the <code>Date</code> object. This will create
 27  
  * the instances of the date objects using a constructor that takes
 28  
  * a single <code>long</code> parameter value. 
 29  
  * 
 30  
  * @author Niall Gallagher
 31  
  *
 32  
  * @see org.simpleframework.xml.transform.DateTransform
 33  
  */
 34  
 class DateFactory<T extends Date> {
 35  
    
 36  
    /**
 37  
     * This is used to create instances of the date object required.
 38  
     */
 39  
    private final Constructor<T> factory;
 40  
    
 41  
    /**
 42  
     * Constructor for the <code>DateFactory</code> object. This is
 43  
     * used to create instances of the specified type. All objects
 44  
     * created by this instance must take a single long parameter.
 45  
     * 
 46  
     * @param type this is the date implementation to be created
 47  
     */
 48  
    public DateFactory(Class<T> type) throws Exception {
 49  29
       this(type, long.class);
 50  29
    }
 51  
    
 52  
    /**
 53  
     * Constructor for the <code>DateFactory</code> object. This is
 54  
     * used to create instances of the specified type. All objects
 55  
     * created by this instance must take the specified parameter.
 56  
     * 
 57  
     * @param type this is the date implementation to be created
 58  
     * @param list is basically the list of accepted parameters
 59  
     */
 60  29
    public DateFactory(Class<T> type, Class... list) throws Exception {
 61  29
       this.factory = type.getDeclaredConstructor(list);
 62  29
    }
 63  
    
 64  
    /**
 65  
     * This is used to create instances of the date using a delegate
 66  
     * date. A <code>long</code> parameter is extracted from the 
 67  
     * given date an used to instantiate a date of the required type.
 68  
     * 
 69  
     * @param list this is the type used to provide the long value
 70  
     * 
 71  
     * @return this returns an instance of the required date type
 72  
     */
 73  
    public T getInstance(Object... list) throws Exception {
 74  2040
       return factory.newInstance(list);
 75  
    }
 76  
 }