[Home] DMelt member access. Java source code: de.erichseifert.gral.io.AbstractIOFactory
/*
* GRAL: GRAphing Library for Java(R)
*
* (C) Copyright 2009-2016 Erich Seifert ,
* Michael Seifert
*
* This file is part of GRAL.
*
* GRAL is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRAL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with GRAL. If not, see .
*/
package de.erichseifert.gral.io;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
/**
* Abstract implementation of {@code IOFactory} which provides basic
* functionality.
*
* @param The type of objects which should be produced by this factory
*/
public abstract class AbstractIOFactory implements IOFactory {
private final Map> entries;
/**
* Constructor that creates a new instance and initializes it with the name
* of the corresponding properties file(s).
* @param propFileName File name of the properties file(s)
* @throws IOException if reading the properties file(s) failed
*/
@SuppressWarnings("unchecked")
protected AbstractIOFactory(String propFileName) throws IOException {
entries = new HashMap>();
// Retrieve property-files
Enumeration propFiles;
propFiles = getClass().getClassLoader().getResources(propFileName);
if (!propFiles.hasMoreElements()) {
throw new IOException(MessageFormat.format(
"Property file not found: {0}", propFileName)); //$NON-NLS-1$
}
Properties props = new Properties();
while (propFiles.hasMoreElements()) {
URL propURL = propFiles.nextElement();
InputStream stream = null;
try {
stream = propURL.openStream();
props.load(stream);
} finally {
if (stream != null) {
stream.close();
}
}
// Parse property files and register entries as items
for (Map.Entry