net.sf.jsefa.csv.lowlevel.CsvLowLevelIOFactory Maven / Gradle / Ivy
Show all versions of jsefa-android Show documentation
/*
* Copyright 2007 the original author or authors.
*
* 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 net.sf.jsefa.csv.lowlevel;
import java.lang.reflect.Method;
import net.sf.jsefa.IOFactoryException;
import net.sf.jsefa.common.config.InitialConfiguration;
import net.sf.jsefa.common.lowlevel.LowLevelIOFactory;
import net.sf.jsefa.common.util.ReflectionUtil;
import net.sf.jsefa.csv.lowlevel.config.CsvLowLevelConfiguration;
import net.sf.jsefa.csv.lowlevel.config.CsvLowLevelInitialConfigurationParameters;
/**
* Factory for creating {@link CsvLowLevelDeserializer}s and {@link CsvLowLevelSerializer}s.
*
* This is the abstract base class for concrete factories. Each subclass must provide a static method
* create(CsvLowLevelConfiguration config)
as well as implement the abstract methods.
*
* This class provides a static factory method {@link #createFactory(CsvLowLevelConfiguration)} to create an
* instance of a concrete CsvLowLevelIOFactory
.
*
* @author Norman Lahme-Huetig
*
*/
public abstract class CsvLowLevelIOFactory implements LowLevelIOFactory {
/**
* Creates a new CsvLowLevelIOFactory
for CsvLowLevelSerializer
s and
* CsvLowLevelDeserializer
s using the given configuration.
*
* @param config the configuration object.
* @return an CsvLowLevelIOFactory
factory
* @throws IOFactoryException
*/
public static CsvLowLevelIOFactory createFactory(CsvLowLevelConfiguration config) {
Class factoryClass = InitialConfiguration.get(
CsvLowLevelInitialConfigurationParameters.LOW_LEVEL_IO_FACTORY_CLASS,
CsvLowLevelIOFactoryImpl.class);
Method createMethod = ReflectionUtil.getMethod(factoryClass, "createFactory",
CsvLowLevelConfiguration.class);
if (createMethod == null) {
throw new IOFactoryException("Failed to create an CsvLowLevelIOFactory. The factory " + factoryClass
+ " does not contain the required static createFactory method.");
}
try {
return ReflectionUtil.callMethod(null, createMethod, config);
} catch (Exception e) {
throw new IOFactoryException("Failed to create an CsvLowLevelIOFactory", e);
}
}
/**
* {@inheritDoc}
*/
public abstract CsvLowLevelSerializer createSerializer();
/**
* {@inheritDoc}
*/
public abstract CsvLowLevelDeserializer createDeserializer();
}