package pt.ist.renderers.utils; import java.util.HashMap; import java.util.Map; import java.util.Properties; import pt.ist.renderers.exceptions.NoRendererException; import org.apache.commons.collections.Predicate; public class RendererRegistry { private ClassHierarchyTable> renderersTable; public RendererRegistry() { super(); this.renderersTable = new ClassHierarchyTable>(); } public void registerRenderer(Class type, String layout, Class renderer, Properties defaultProperties) { Map layoutsTable = this.renderersTable.getUnspecific(type); if (layoutsTable == null) { this.renderersTable.put(type, new HashMap()); layoutsTable = this.renderersTable.getUnspecific(type); } layoutsTable.put(layout, new RendererDescription(renderer, defaultProperties)); } public RendererDescription getRenderDescription(Class objectType, final String layout) { Map layoutsTable = renderersTable.get(objectType, new Predicate() { public boolean evaluate(Object table) { Map layoutsTable = (Map) table; return layoutsTable.get(layout) != null; } }); if (layoutsTable == null) { throw new NoRendererException(objectType, layout); } return layoutsTable.get(layout); } public RendererDescription getExactRenderDescription(Class objectType, String layout) { Map layoutsTable = renderersTable.getUnspecific(objectType); if (layoutsTable == null) { throw new NoRendererException(objectType, layout); } return layoutsTable.get(layout); } }