1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package com.gridsystems.nextgrid.api.pom.components;
19
20 import java.net.URI;
21 import java.util.List;
22 import java.util.UUID;
23
24 import nextgrid.api.env.ProcessSelector;
25 import nextgrid.api.env.SelectionException;
26 import nextgrid.api.pom.AbstractProcess;
27 import nextgrid.api.pom.Process;
28
29
30
31
32
33
34 public class DefaultSelector implements ProcessSelector {
35
36
37
38
39 private URI id;
40
41
42
43
44 public DefaultSelector() {
45 this.id = genRandomURI();
46 }
47
48
49
50
51 public URI getId() {
52 return this.id;
53 }
54
55
56
57
58
59 public void select(Process p) throws SelectionException {
60 if (p instanceof AbstractProcess) {
61 AbstractProcess ap = (AbstractProcess)p;
62 List<Process> list = ap.getCandidates();
63 if (list == null || list.size() == 0) {
64 throw new SelectionException("No candidates to select among");
65 } else {
66 ap.setSelected(list.get(0));
67 }
68 }
69 }
70
71
72
73
74 public void setId(URI id) {
75 this.id = id;
76 }
77
78
79
80
81
82
83
84 private static URI genRandomURI() {
85 UUID uuid = UUID.randomUUID();
86 try {
87 return new URI("urn:uuid:" + uuid);
88 } catch (Exception e) {
89 throw new InternalError(e.toString());
90 }
91 }
92 }