ResultFindController.java from GridBlocks at Krugle
Show ResultFindController.java syntax highlighted
/*
* Copyright (c) 2005
* Helsinki Institute of Physics
* see LICENSE file for details
*
* ResultFindController.java
* Created on 1.8.2005
*/
package fi.hip.gb.portlet.results;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* Facade to find results. Uses result finders to do the work
*
* @author Antti Ahvenlampi
* @version $Id: ResultFindController.java 480 2005-08-15 15:57:49Z ahvenlam $
*/
public class ResultFindController {
private static ResultFindController rfc = null;
private List resultFinders = null;
/**
* Constructs ResultFindController singleton and
* makes instance of each result finder
*
* @param rfClassNames
*/
private ResultFindController(List rfClassNames) {
resultFinders = new ArrayList();
Iterator it = rfClassNames.iterator();
while(it.hasNext()) {
String className = (String)it.next();
try {
ResultFinder rf = (ResultFinder)Class.forName(className).newInstance();
resultFinders.add(rf);
} catch(ClassNotFoundException e) {
// TODO: proper exception handling
System.out.println(e);
} catch(InstantiationException e) {
System.out.println(e);
} catch(IllegalAccessException e) {
System.out.println(e);
}
}
}
/**
* @return ResultFindController singleton
*/
public static ResultFindController getInstance() {
return rfc;
}
/**
* Initialize ResultFindController
*
* @param rfClassNames
* @return true if there is at least one result finder else false
*/
public static boolean init(List rfClassNames) {
rfc = new ResultFindController(rfClassNames);
if(rfc.resultFinders.size() == 0) {
rfc.resultFinders = null;
return false;
}
return true;
}
/**
* Lists all the results that all the result finders can find.
* Then sorts them by id in ascending order.
*
* @return list of the job results
* @throws ResultException
*/
public List findResults() throws ResultException {
ArrayList results = new ArrayList();
Iterator it = resultFinders.iterator();
while(it.hasNext()) {
ResultFinder rf = (ResultFinder)it.next();
results.addAll(rf.findResults());
}
Collections.sort(results, new ResultComparator());
return results;
}
/**
* Finds a result with a corresponding id. It just iterates
* through the result finders to find it.
*
* @param id
* @return result
*/
public Result findResult(Long id) {
Result result = null;
Iterator it = resultFinders.iterator();
while(it.hasNext() && result == null) {
ResultFinder rf = (ResultFinder)it.next();
result = rf.findResult(id);
}
return result;
}
}
See more files for this project here