View Javadoc

1   package cz.cuni.amis.pogamut.base.component.bus.exception;
2   
3   import java.util.Set;
4   import java.util.logging.Logger;
5   
6   import cz.cuni.amis.utils.Const;
7   import cz.cuni.amis.utils.exception.PogamutException;
8   
9   public class MoreComponentsForClassException extends PogamutException {
10  
11  	public MoreComponentsForClassException(Class cls, Set components, Object origin) {
12  		super("More than one component registered to handle the request." + Const.NEW_LINE + "Request: " + classToString(cls) + Const.NEW_LINE + "Components: " + componentsToString(components), origin);
13  	}
14  	
15  	public MoreComponentsForClassException(Class cls, Set components, Logger log, Object origin) {
16  		super("More than one component registered to handle the request." + Const.NEW_LINE + "Request: " + classToString(cls) + Const.NEW_LINE + "Components: " + componentsToString(components), log, origin);
17  	}
18  	
19  	private static String classToString(Class request) {
20  		return request.getClass().toString();
21  	}
22  	
23  	private static String componentsToString(Set components) {
24  		StringBuffer sb = new StringBuffer();
25  		boolean first = true;
26  		for (Object component : components) {
27  			if (first) first = false;
28  			else sb.append(", ");
29  			sb.append(component);
30  		}
31  		return sb.toString();
32  	}
33  
34  }