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

com.nmote.iim4j.serialize.DefaultSerializerFactory Maven / Gradle / Ivy

Go to download

IIM4J allows Java programmers to read, write and process IPTC IIM version 4 files.

The newest version!
/*
 * Copyright (c) Nmote Ltd. 2004-2015. All rights reserved.
 * See LICENSE doc in a root of project folder for additional information.
 */

package com.nmote.iim4j.serialize;

import java.lang.reflect.Constructor;

/**
 * DefaultSerializerFactory is default implementation of SerializerFactory. It
 * is used by IIMDataSetInfoFactory to create {@link Serializer} instances.
 */
public class DefaultSerializerFactory implements SerializerFactory {

	public Serializer create(String spec) {
		String type, def;
		int lparen = spec.indexOf('(');
		if (lparen != -1) {
			type = spec.substring(0, lparen);
			def = spec.substring(lparen + 1, spec.length() - 1);
		} else {
			type = spec;
			def = null;
		}

		Serializer result;
		try {
			// Instantiate serializer
			Class c = Class.forName("com.nmote.iim4j.serialize." + type + "Serializer");
			Constructor constructor = c.getConstructor(new Class[] { String.class });
			result = (Serializer) constructor.newInstance(new Object[] { def });
		} catch (Exception e) {
			e.printStackTrace();
			result = null;
		}
		return result;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy