00001 package cedar.jetweb.model.paper; 00002 00003 import java.util.Enumeration; 00004 import java.util.Vector; 00005 import java.util.Date; 00006 import java.util.Iterator; 00007 import java.util.Hashtable; 00008 import java.util.Collection; 00009 import java.util.List; 00010 00011 import java.text.DateFormat; 00012 import java.text.SimpleDateFormat; 00013 00014 import java.io.File; 00015 import java.io.FileInputStream; 00016 import java.io.BufferedReader; 00017 import java.io.Serializable; 00018 import java.io.InputStreamReader; 00019 import java.io.IOException; 00020 00021 import cedar.jetweb.JetWebConfig; 00022 import cedar.jetweb.model.MCProcessType; 00023 import cedar.jetweb.model.Collision; 00024 import cedar.jetweb.model.plots.RealPlot; 00025 import cedar.jetweb.model.plots.DataPlot; 00026 import cedar.jetweb.model.plots.JetWebPlotException; 00027 import cedar.jetweb.db.DBPlotManager; 00028 import cedar.jetweb.JetWebException; 00029 00030 import org.apache.commons.io.FileUtils; 00031 00039 public abstract class PaperBank implements Serializable { 00040 00041 private static Hashtable<Integer,Paper> papers = 00042 new Hashtable<Integer,Paper>(); 00043 00044 private static Hashtable<Integer, RealPaper> realPapers_ = 00045 new Hashtable<Integer, RealPaper>(); 00046 00047 private static Hashtable<Integer,RealPlot> plots = new Hashtable<Integer,RealPlot>(); 00048 00049 00051 public static Collection<Paper> getPapers(String accelerator){ 00052 Collection<Paper> accPapers = new Vector<Paper>(); 00053 for (Paper paper : papers.values()){ 00054 if (paper.getAccelerator().equalsIgnoreCase(accelerator)) { 00055 accPapers.add(paper); 00056 } 00057 } 00058 return accPapers; 00059 } 00060 00062 public static Collection<Paper> getPapers(MCProcessType proc) throws JetWebException { 00063 Collection<Paper> procPapers = new Vector<Paper>(); 00064 for (Paper paper : papers.values()){ 00065 if (paper.containsDataFor(proc)) { 00066 procPapers.add(paper); 00067 } 00068 } 00069 return procPapers; 00070 } 00071 00073 public static Collection<Paper> getPapers(Collision coll) throws JetWebException { 00074 Collection<Paper> cPapers = new Vector<Paper>(); 00075 for (Paper paper : papers.values()){ 00076 if (paper.containsDataFor(coll)) { 00077 cPapers.add(paper); 00078 } 00079 } 00080 return cPapers; 00081 } 00082 00083 00085 public static Paper getPaper(DataPlot plot) throws JetWebException { 00086 for (Paper paper : papers.values()){ 00087 if (paper.getPlots().contains(plot)) { 00088 return paper; 00089 } 00090 } 00091 throw new JetWebException("PaperBank: no paper found for plot",plot.toString()); 00092 } 00093 00098 public static Collection<Paper> getPapers(){ 00099 return papers.values(); 00100 } 00101 00102 public static Collection<RealPaper> getRealPapers(){ 00103 return realPapers_.values(); 00104 } 00105 00109 public static int getNPapers(){ 00110 return papers.size(); 00111 } 00112 00118 public static Collection<RealPlot> getAllPlots(){ 00119 return plots.values(); 00120 } 00121 00126 public static Collection<RealPlot> getPlots(Collision coll) throws JetWebException { 00127 00128 Collection<RealPlot> list = new Vector<RealPlot>(); 00129 for (RealPlot plot : plots.values()){ 00130 if (plot.getMCProcessType().getCollision().getId()==coll.getId()){ 00131 list.add(plot); 00132 } 00133 } 00134 return list; 00135 } 00136 00141 public static Collection<RealPlot> getPlots(MCProcessType proc) throws JetWebException { 00142 Collection<RealPlot> list = new Vector<RealPlot>(); 00143 for (RealPlot plot : plots.values()){ 00144 if (plot.getMCProcessType().getId()==proc.getId()){ 00145 list.add(plot); 00146 } 00147 } 00148 return list; 00149 } 00150 00151 00157 public static void getConfig() throws JetWebException { 00158 if (papers.size()>0) { 00159 System.out.println("Already initialised paperBank"); 00160 return; 00161 } 00162 00163 for (Paper paper : DBPlotManager.getPapers()){ 00164 papers.put(paper.getId(),paper); 00165 // Now fill the Hashtable of plots. 00166 for (DataPlot plot : paper.getPlots()){ 00167 plots.put(new Integer(plot.getId()),(RealPlot)plot); 00168 } 00169 } 00170 00171 for(RealPaper paper: DBPlotManager.getRealPapers()){ 00172 realPapers_.put(paper.getId(), paper); 00173 for(RealPlot plot: paper.getPlots()){ 00174 plots.put(new Integer(plot.getId()), plot); 00175 } 00176 } 00177 00178 } 00179 00186 public static void mkdirs(File xmldir){ 00187 00188 if (!xmldir.isDirectory()) { return; } 00189 00190 for (Paper p : papers.values()){ 00191 String name = p.getDirName(); 00192 File dir = new File(xmldir.getPath()+"/"+name); 00193 dir.mkdir(); 00194 } 00195 } 00201 public static void rmdirs(File dir){ 00202 try { 00203 FileUtils.deleteDirectory(dir); 00204 } catch (IOException e) { 00205 System.out.println(e); 00206 } 00207 } 00208 00209 00217 public static Paper getPaper(int id){ 00218 return papers.get(id); 00219 } 00220 00224 public static RealPlot getPlot(int plotId){ 00225 return plots.get(plotId); 00226 } 00227 } 00228 00229 00230 00231 00232 00233 00234 00235 00236 00237 00238 00239 00240 00241 00242 00243 00244 00245
Generated Wed Jan 17 09:14:27 GMT 2007