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

com.venky.swf.db.model.io.ModelIOFactory Maven / Gradle / Ivy

The newest version!
package com.venky.swf.db.model.io;

import java.util.HashMap;
import java.util.Map;

import com.venky.swf.db.model.Model;
import com.venky.swf.integration.FormatHelper;


public class ModelIOFactory {
	private static Map, ModelReaderFactory> readerfactories = new HashMap,ModelReaderFactory>();
	private static Map, ModelWriterFactory> writerfactories = new HashMap,ModelWriterFactory>();
	
	public static  void registerIOFactories(Class formatClass, ModelReaderFactoryreaderFactory, ModelWriterFactory writerFactory){
		readerfactories.put(formatClass, readerFactory);
		writerfactories.put(formatClass,writerFactory);
	}
	@SuppressWarnings("unchecked")
	public static  ModelReader getReader(Class modelClass, Class formatClass){
		ModelReader reader = null; 
		ModelReaderFactory readerFactory = (ModelReaderFactory) readerfactories.get(formatClass);
		if (readerFactory != null){
			reader = (ModelReader) readerFactory.createModelReader(modelClass);
		}
		
		if (reader == null){
			throw new UnsupportedMimeTypeException("No Reader available for Mimetype:" +  FormatHelper.getMimeType(formatClass).toString());
		}
		return reader;
	}
	@SuppressWarnings("unchecked")
	public static   ModelWriter getWriter(Class modelClass, Class formatClass){
		ModelWriter writer = null ;
		ModelWriterFactory writerFactory = (ModelWriterFactory) writerfactories.get(formatClass);
		if (writerFactory != null){
			writer = (ModelWriter)writerFactory.createModelWriter(modelClass);
		}
		
		if (writer == null){
			throw new UnsupportedMimeTypeException("No Writer available for Mimetype:" +  FormatHelper.getMimeType(formatClass).toString());
		}
		return writer;
	}
	public static class UnsupportedMimeTypeException extends RuntimeException {
		private static final long serialVersionUID = 5295876737650879813L;
		public UnsupportedMimeTypeException(String message){
			super(message);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy