All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.jsefa.csv.lowlevel.CsvLowLevelIOFactory Maven / Gradle / Ivy

Go to download

JSefa (Java Simple exchange format api) is a simple library for stream-based serialization of java objects to XML, CSV, FLR or any other format and back again using an iterator-style interface independent of the serialization format. The mapping between java object types and types of the serialization format (e. g. xml complex element types) can be defined either by annotating the java classes or programmatically using a simple API. The current implementation supports XML, CSV and FLR - for XML it is based on JSR 173.

The newest version!
/*
 * 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 CsvLowLevelSerializers and * CsvLowLevelDeserializers 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(); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy