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

org.ioc.commons.flowcontrol.exceptionparser.ExceptionParserManagerImpl Maven / Gradle / Ivy

Go to download

Library which contains some extension classes for the library IOC-Commons. It provides some interface definitions and some tool classes which are non-dependent from the used technology; i.e. the classes and interfaces from this library do not depend on the choosen ioc-commons-implementation library.

There is a newer version: 1.2.1
Show newest version
package org.ioc.commons.flowcontrol.exceptionparser;

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

public class ExceptionParserManagerImpl implements ExceptionParserManager {

	private final Map, ExceptionParserManager.ExceptionParser> registered = new HashMap, ExceptionParserManager.ExceptionParser>();

	@Override
	public  void registerExceptionParser(Class clazz,
			ExceptionParserManager.ExceptionParser parser) throws ExceptionParserAlreadyRegistered {
		if (!registered.containsKey(clazz)) {
			registered.put(clazz, parser);
		} else {
			throw new ExceptionParserAlreadyRegistered();
		}
	}

	@Override
	public  void unregisterExceptionParser(Class exceptionClass) {
		registered.remove(exceptionClass);
	}

	@SuppressWarnings("unchecked")
	@Override
	public  EX fromMessage(Class clazz, String message) {
		ExceptionParserManager.ExceptionParser parser = registered.get(clazz);
		if (parser != null) {
			return (EX) parser.fromMessage(message);
		}
		return null;
	}

	public boolean tryHandleException(Throwable e) {
		boolean handled = false;
		for (ExceptionParserManager.ExceptionParser parser : this.registered.values()) {
			handled |= parser.tryHandleException(e);
			if (handled) {
				break;
			}
		}
		return handled;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy