/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package reportgen.prototype;
import java.util.LinkedList;
import java.util.List;
import org.jdom.Element;
import reportgen.prototype.context.Context;
import reportgen.utils.ReportException;
/**
*
* @author axe
*/
public class CoreFactoryList {
private static final LinkedList<CoreFactory> lst = new LinkedList<CoreFactory>();
public void register(CoreFactory factory) {
lst.add(factory);
factory.init();
}
public QCore createDefaultCore(Context context) throws ReportException {
if(lst.size() == 0) {
throw new ReportException("Не зарегистрировано ни одного типа выборки");
}
return lst.get(0).getCore(context);
}
public QCore loadCore(Element root, Context context) throws ReportException {
if(lst.size() == 0) {
throw new ReportException("Не зарегистрирован ни один тип выборки");
}
for(CoreFactory factory: lst) {
if(factory.getTitle().equals(root.getName())) {
return factory.loadCore(root, context);
}
}
throw new ReportException("Нeизвестный тип выборки:" + root.getName());
}
public List<String> getCores() {
List<String> res = new LinkedList<String>();
for(CoreFactory factory: lst) {
res.add(factory.getTitle());
}
return res;
}
public QCore createCore(int index, Context ctx) {
return lst.get(index).getCore(ctx);
}
}