/*
* jFin, open source derivatives trade processing
*
* Copyright (C) 2005, 2006, 2007 Morgan Brown Consultancy Ltd.
*
* This file is part of jFin.
*
* jFin is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* jFin is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public License along
* with jFin; if not, write to the Free Software Foundation, Inc., 51 Franklin
* St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.jfin.date.holiday;
import org.jfin.date.Period;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Factory class for providing a layer of abstraction from the actual
* implementation of the HolidayCalendar.
*
* The default HolidayCalendarFactory only provides for "WE" or weekends. It is
* expected that integrators will want to reuse an existing service within their
* organisation to provide an authoratitive reference of holiday calendars.
*
* It is not within the scope of jFin to provide this data.
*
* Use -HolidayCalendarFactory=ImplementationClass to use a different
* implementation from the default.
*
* If you wish to use more than one concrete implementation of the
* HolidayCalendarFactory within the same JVM use the static newInstance(String
* holidayCalendarFactoryClassName) method.
*/
public abstract class HolidayCalendarFactory
{
private static Logger logger = Logger
.getLogger("org.jfin.date.holiday.HolidayCalendarFactory");
public static String defaultHolidayCalendarFactoryClassName = "org.jfin.date.holiday.defaultimpl.HolidayCalendarFactoryImpl";
public static String defaultHolidayCalendarFactoryClassNameParameter = "jfin.HolidayCalendarFactory";
/**
* Get a new instance of the concrete implementation of the
* HolidayCalendarFactory based upon the System parameter
* jfin.HolidayCalendarFactory.
*
* If this parameter does not exist then it returns the default concrete
* implementation
* org.jfin.date.holiday.defaultimpl.HolidayCalendarFactoryImpl.
*
* @return The new HolidayCalendarFactory instance
*/
public static HolidayCalendarFactory newInstance()
{
logger.info("Constructing new default holiday calendar provider.");
String holidayCalendarFactoryClassName = System
.getProperty(defaultHolidayCalendarFactoryClassNameParameter);
if (holidayCalendarFactoryClassName == null)
{
logger.info("No system property "
+ defaultHolidayCalendarFactoryClassNameParameter
+ " provided, using "
+ defaultHolidayCalendarFactoryClassName);
holidayCalendarFactoryClassName = defaultHolidayCalendarFactoryClassName;
} else
{
logger.info("Found system property "
+ defaultHolidayCalendarFactoryClassNameParameter + ": "
+ holidayCalendarFactoryClassName);
}
return newInstance(holidayCalendarFactoryClassName);
}
/**
*
* Create a concrete instance of a HolidayCalendarFactory based upon:
*
*
* - The class name in the system property jfin.HolidayCalendarFactory
*
- And if this doesn't exist:
*
- Default to
* org.jfin.date.test.holiday.defaultimpl.HolidayCalendarFactoryImpl
*
*
* @return The default HolidayCalendarProvider
*/
public static HolidayCalendarFactory newInstance(
String holidayCalendarFactoryClassName)
{
try
{
logger.info("Attempting to instantiate "
+ holidayCalendarFactoryClassName);
Class holidayCalendarProviderClass = Class
.forName(holidayCalendarFactoryClassName);
HolidayCalendarFactory holidayCalendarFactory = (HolidayCalendarFactory) holidayCalendarProviderClass
.newInstance();
return holidayCalendarFactory;
} catch (ClassNotFoundException e)
{
logger
.log(
Level.SEVERE,
"Cannot create a holidayCalendarProvider with class "
+ holidayCalendarFactoryClassName
+ ". Check that this class exists within the classpath.",
e);
throw new HolidayCalendarException(e);
} catch (InstantiationException e)
{
logger
.log(
Level.SEVERE,
"Cannot create a holidayCalendarProvider with class "
+ holidayCalendarFactoryClassName
+ ". Check that this class implements a default constructor.",
e);
throw new HolidayCalendarException(e);
} catch (IllegalAccessException e)
{
logger
.log(
Level.SEVERE,
"Cannot create a holidayCalendarProvider with class "
+ holidayCalendarFactoryClassName
+ ". Check that this class implements a public default constructor.",
e);
throw new HolidayCalendarException(e);
} catch (ClassCastException e)
{
logger
.log(
Level.SEVERE,
"Cannot create a holidayCalendarProvider with class "
+ holidayCalendarFactoryClassName
+ ". Check that this class extends HolidayCalendarFactory.",
e);
throw new HolidayCalendarException(e);
}
}
/**
*
* Get the HolidayCalendar that represents the locale.
*
*
* @param locale
* @return The HolidayCalendar for the given Locale
* @throws HolidayCalendarException
*/
public abstract HolidayCalendar getHolidayCalendar(String locale);
/**
*
* Get the HolidayCalendar that represents the locales provided as an array
* of Strings.
*
*
* @param locale
* @param c
* @return The holiday calendar
*/
public abstract HolidayCalendar getHolidayCalendar(String locale, Class c);
/**
*
* Get the HolidayCalendar that represents the locales provided as an array
* of Strings.
*
*
* @param locales
* @param c the type of the HolidayCalendar to return
* @return The holiday calendar
*/
public HolidayCalendar getHolidayCalendar(String[] locales, Class c)
{
if (locales.length == 1)
{
return getHolidayCalendar(locales[0]);
}
HolidayCalendarSet holidayCalendarSet = new HolidayCalendarSet();
for (int i = 0; i < locales.length; i++)
{
HolidayCalendar holidayCalendar = getHolidayCalendar(locales[i]);
holidayCalendarSet.addHolidayCalendar(holidayCalendar);
}
return holidayCalendarSet;
}
public HolidayCalendar getHolidayCalendar(String[] locales) {
return getHolidayCalendar(locales, Period.class);
}
public abstract String[] getAvailableLocales();
}
Ads help maintain this website.