001: /* DDSteps - Data Driven JUnit Test Steps
002: * Copyright (C) 2006 Jayway AB
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License version 2.1 as published by the Free Software Foundation.
007: *
008: * This library is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, visit
015: * http://www.opensource.org/licenses/lgpl-license.php
016: */
017: package org.ddsteps.dataset.support;
018:
019: import org.ddsteps.dataset.CachingDataSetLoader;
020: import org.ddsteps.dataset.DataSetLoader;
021: import org.ddsteps.dataset.DecoratingDataSetLoader;
022: import org.ddsteps.dataset.excel.ExcelDataSetLoader;
023: import org.ddsteps.dataset.transform.PropertyPlaceholderTransformer;
024: import org.ddsteps.dataset.transform.TransformFactory;
025:
026: /**
027: * Factory class for getting DataSetLoader singletons when you are NOT using
028: * Spring. If you do use Spring, just create singleton beans in your context.
029: *
030: * @author adamskogman
031: *
032: */
033: public class DataSetLoaderFactory {
034:
035: /**
036: * Lazy Singleton.
037: * <p>
038: * Just Excel
039: */
040: protected static DataSetLoader excelDataSetLoader;
041:
042: /**
043: * Lazy singleton.
044: * <p>
045: * Decorating -> Excel
046: */
047: private static DecoratingDataSetLoader decoratingExcelDataSetLoader;
048:
049: /**
050: * Lazy singleton.
051: * <p>
052: * Cache -> Decorating -> Excel
053: */
054: private static DataSetLoader cachingDecoratingExcelDataSetLoader;
055:
056: /**
057: * Returns a singleton for the (@link
058: * org.ddsteps.dataset.excel.ExcelDataSetLoader).
059: *
060: * @return Never null.
061: */
062: public static synchronized DataSetLoader getExcelDataSetLoader() {
063: if (excelDataSetLoader == null) {
064: excelDataSetLoader = new ExcelDataSetLoader();
065: }
066: return excelDataSetLoader;
067: }
068:
069: /**
070: * Returns a singleton decorating excel dataset loader.
071: *
072: * By default it decorates with a (@link
073: * org.ddsteps.dataset.transform.PropertyPlaceholderTransformer) as
074: * DataValueTransformer.
075: *
076: * @return Never null.
077: */
078: public static synchronized DecoratingDataSetLoader getPropertyPlaceholderExcelDataSetLoader() {
079: if (decoratingExcelDataSetLoader == null) {
080: decoratingExcelDataSetLoader = new DecoratingDataSetLoader(
081: getExcelDataSetLoader());
082:
083: PropertyPlaceholderTransformer placeholderTransformer = TransformFactory
084: .createPropertyReplacementTransformer();
085: decoratingExcelDataSetLoader
086: .setDataValueTransformer(placeholderTransformer);
087:
088: }
089: return decoratingExcelDataSetLoader;
090: }
091:
092: /**
093: * Returns a singleton for a caching, property placeholder replacing excel
094: * data set loader.
095: *
096: * The default is to replace ${foo} expressions with values from
097: * ddsteps-palceholders.properties.
098: *
099: * @see PropertyPlaceholderTransformer
100: *
101: * @return Never null.
102: */
103: public static synchronized DataSetLoader getCachingPropertyPlaceholderExcelDataSetLoader() {
104: if (cachingDecoratingExcelDataSetLoader == null) {
105: cachingDecoratingExcelDataSetLoader = new CachingDataSetLoader(
106: getPropertyPlaceholderExcelDataSetLoader());
107: }
108: return cachingDecoratingExcelDataSetLoader;
109: }
110:
111: }
|