1   package debugger.resources.pr;
2   
3   import gate.Gate;
4   import gate.ProcessingResource;
5   import gate.jape.SinglePhaseTransducer;
6   
7   import java.util.*;
8   
9   /**
10   * Copyright (c) Ontos AG (http://www.ontosearch.com).
11   * This class is part of JAPE Debugger component for
12   * GATE (Copyright (c) "The University of Sheffield" see http://gate.ac.uk/) <br>
13   * @author Andrey Shafirin, Vladimir Karasev
14   */
15  
16  public class PRRoot {
17      private ArrayList prs;
18  
19      public PRRoot() {
20          if (null == Gate.getCreoleRegister()) {
21              prs = new ArrayList();
22          } else {
23              prs = new ArrayList();
24              List prInstances;
25              prInstances = Gate.getCreoleRegister().getPublicPrInstances();
26              List list = new ArrayList(prInstances);
27              Collections.sort(list, new Comparator() {
28                  public int compare(Object o1, Object o2) {
29                      String name1 = ((ProcessingResource) o1).getName();
30                      String name2 = ((ProcessingResource) o2).getName();
31                      return name1.compareToIgnoreCase(name2);
32                  }
33              });
34              for (Iterator iterator = list.iterator(); iterator.hasNext();) {
35                  ProcessingResource pr = (ProcessingResource) iterator.next();
36                  prs.add(new PrModel(pr));
37              }
38          }
39      }
40  
41      public ArrayList getPRs() {
42          return prs;
43      }
44  
45      public PhaseModel getPhase(SinglePhaseTransducer spt) {
46          for (int i = 0; i < prs.size(); i++) {
47              PrModel prModel = (PrModel) prs.get(i);
48              if (prModel.getPhase(spt) != null) {
49                  return prModel.getPhase(spt);
50              }
51          }
52          return null;
53      }
54  
55  }
56