svn-gvsig-desktop / tags / v2_0_0_Build_2057 / extensions / org.gvsig.installer / org.gvsig.installer.lib / org.gvsig.installer.lib.impl / src / main / java / org / gvsig / installer / lib / impl / DefaultDependencies.java @ 39186
History | View | Annotate | Download (2.05 KB)
1 |
package org.gvsig.installer.lib.impl; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Iterator; |
5 |
|
6 |
import org.gvsig.installer.lib.api.Dependencies; |
7 |
import org.gvsig.installer.lib.api.Dependency; |
8 |
import org.gvsig.installer.lib.api.Version; |
9 |
|
10 |
public class DefaultDependencies extends ArrayList implements |
11 |
Dependencies { |
12 |
|
13 |
/**
|
14 |
*
|
15 |
*/
|
16 |
private static final long serialVersionUID = -6743931124069465522L; |
17 |
|
18 |
private Dependency createDependency() {
|
19 |
// InstallerManager manager = InstallerLocator.getInstallerManager();
|
20 |
// return manager.createDependency();
|
21 |
return new DefaultDependency(); |
22 |
} |
23 |
|
24 |
public Dependencies parse(String dependecies) { |
25 |
if (dependecies == null) { |
26 |
this.clear();
|
27 |
return this; |
28 |
} |
29 |
dependecies = dependecies.trim(); |
30 |
if (dependecies.equals("")) { |
31 |
this.clear();
|
32 |
return this; |
33 |
} |
34 |
|
35 |
String[] x = dependecies.split(","); |
36 |
for (int i = 0; i < x.length; i++) { |
37 |
this.add(createDependency().parse(x[i]));
|
38 |
} |
39 |
return this; |
40 |
} |
41 |
|
42 |
@Override
|
43 |
public String toString() { |
44 |
StringBuffer s = null; |
45 |
Iterator<Dependency> it = this.iterator(); |
46 |
while (it.hasNext()) {
|
47 |
if (s == null) { |
48 |
s = new StringBuffer(); |
49 |
} else {
|
50 |
s.append(", ");
|
51 |
} |
52 |
s.append(it.next().toString()); |
53 |
} |
54 |
if (s == null) { |
55 |
return ""; |
56 |
} |
57 |
return s.toString();
|
58 |
} |
59 |
|
60 |
@Override
|
61 |
public boolean contains(Object o) { |
62 |
if (!(o instanceof Dependency)) { |
63 |
return false; |
64 |
} |
65 |
Iterator<Dependency> it = this.iterator(); |
66 |
while (it.hasNext()) {
|
67 |
Dependency dep = it.next(); |
68 |
if (dep.equals(o)) {
|
69 |
return true; |
70 |
} |
71 |
} |
72 |
return false; |
73 |
} |
74 |
|
75 |
public boolean match(String type, String code, Version version) { |
76 |
Iterator<Dependency> it = this.iterator(); |
77 |
while (it.hasNext()) {
|
78 |
Dependency dependency = it.next(); |
79 |
if (dependency.match(type, code, version)) {
|
80 |
return true; |
81 |
} |
82 |
} |
83 |
return false; |
84 |
} |
85 |
|
86 |
public Dependency find(String type, String code, Version version) { |
87 |
Iterator<Dependency> it = this.iterator(); |
88 |
while (it.hasNext()) {
|
89 |
Dependency dependency = it.next(); |
90 |
if (dependency.match(type, code, version)) {
|
91 |
return dependency;
|
92 |
} |
93 |
} |
94 |
return null; |
95 |
} |
96 |
|
97 |
} |