org.simpleframework.xml.transform.DateFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simple-xml Show documentation
Show all versions of simple-xml Show documentation
Simple is a high performance XML serialization and configuration framework for Java
The newest version!
/*
* DateTransform.java May 2007
*
* Copyright (C) 2007, Niall Gallagher
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package org.simpleframework.xml.transform;
import java.lang.reflect.Constructor;
import java.util.Date;
/**
* The DateFactory
object is used to create instances
* or subclasses of the Date
object. This will create
* the instances of the date objects using a constructor that takes
* a single long
parameter value.
*
* @author Niall Gallagher
*
* @see org.simpleframework.xml.transform.DateTransform
*/
class DateFactory {
/**
* This is used to create instances of the date object required.
*/
private final Constructor factory;
/**
* Constructor for the DateFactory
object. This is
* used to create instances of the specified type. All objects
* created by this instance must take a single long parameter.
*
* @param type this is the date implementation to be created
*/
public DateFactory(Class type) throws Exception {
this(type, long.class);
}
/**
* Constructor for the DateFactory
object. This is
* used to create instances of the specified type. All objects
* created by this instance must take the specified parameter.
*
* @param type this is the date implementation to be created
* @param list is basically the list of accepted parameters
*/
public DateFactory(Class type, Class... list) throws Exception {
this.factory = type.getDeclaredConstructor(list);
}
/**
* This is used to create instances of the date using a delegate
* date. A long
parameter is extracted from the
* given date an used to instantiate a date of the required type.
*
* @param list this is the type used to provide the long value
*
* @return this returns an instance of the required date type
*/
public T getInstance(Object... list) throws Exception {
return factory.newInstance(list);
}
}