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

net.sf.jsefa.xml.lowlevel.XmlLowLevelIOFactory Maven / Gradle / Ivy

/*
 * 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.xml.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.xml.lowlevel.config.XmlLowLevelConfiguration;
import net.sf.jsefa.xml.lowlevel.config.XmlLowLevelInitialConfigurationParameters;

/**
 * Factory for creating {@link XmlLowLevelDeserializer}s and {@link XmlLowLevelSerializer}s.
 * 
 * This is the abstract base class for concrete factories. Each subclass must provide a static method
 * create(XmlLowLevelConfiguration config) as well as implement the abstract methods.
 * 

* This class provides a static factory method {@link #createFactory(XmlLowLevelConfiguration)} to create an instance of * a concrete XmlLowLevelIOFactory. * * @author Norman Lahme-Huetig * */ public abstract class XmlLowLevelIOFactory implements LowLevelIOFactory { /** * Creates a new XmlLowLevelIOFactory for XmlLowLevelSerializers and * XmlLowLevelDeserializers using the given configuration. * * @param config the configuration object. * @return an XmlLowLevelIOFactory factory * @throws IOFactoryException */ public static XmlLowLevelIOFactory createFactory(XmlLowLevelConfiguration config) { Class ioFactoryClass = null; if (ReflectionUtil.hasClass("net.sf.jsefa.xml.lowlevel.StaxBasedXmlLowLevelIOFactory")) { ioFactoryClass = ReflectionUtil.getClass("net.sf.jsefa.xml.lowlevel.StaxBasedXmlLowLevelIOFactory"); } else if (ReflectionUtil.hasClass("net.sf.jsefa.xml.lowlevel.XmlPullBasedXmlLowLevelIOFactory")) { ioFactoryClass = ReflectionUtil.getClass("net.sf.jsefa.xml.lowlevel.XmlPullBasedXmlLowLevelIOFactory"); } if (ioFactoryClass == null) { throw new IOFactoryException("Failed to create an XmlLowLevelIOFactory"); } Class factoryClass = InitialConfiguration.get( XmlLowLevelInitialConfigurationParameters.LOW_LEVEL_IO_FACTORY_CLASS, ioFactoryClass); Method createMethod = ReflectionUtil.getMethod(factoryClass, "createFactory", XmlLowLevelConfiguration.class); if (createMethod == null) { throw new IOFactoryException("Failed to create an XmlLowLevelIOFactory. 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 XmlLowLevelIOFactory", e); } } /** * {@inheritDoc} */ public abstract XmlLowLevelSerializer createSerializer(); /** * {@inheritDoc} */ public abstract XmlLowLevelDeserializer createDeserializer(); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy