gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.lib / src / main / java / org / gvsig / tools / packageutils / impl / DefaultDependencies.java @ 718
History | View | Annotate | Download (2.49 KB)
1 |
package org.gvsig.tools.packageutils.impl; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Iterator; |
5 |
|
6 |
import org.gvsig.tools.ToolsLocator; |
7 |
import org.gvsig.tools.packageutils.Dependencies; |
8 |
import org.gvsig.installer.lib.api.Dependency; |
9 |
import org.gvsig.tools.packageutils.PackageManager; |
10 |
import org.gvsig.installer.lib.api.Version; |
11 |
|
12 |
public class DefaultDependencies extends ArrayList implements |
13 |
Dependencies { |
14 |
|
15 |
/**
|
16 |
*
|
17 |
*/
|
18 |
private static final long serialVersionUID = -6743931124069465522L; |
19 |
|
20 |
private Dependency createDependency() {
|
21 |
PackageManager manager = ToolsLocator.getPackageManager(); |
22 |
return manager.createDependency();
|
23 |
} |
24 |
|
25 |
public Object clone() { |
26 |
PackageManager manager = ToolsLocator.getPackageManager(); |
27 |
Dependencies other = manager.createDependencies(); |
28 |
Iterator it = this.iterator(); |
29 |
while( it.hasNext() ) {
|
30 |
Dependency dependency = (Dependency) it.next(); |
31 |
try {
|
32 |
other.add(dependency.clone()); |
33 |
} catch (CloneNotSupportedException e) { |
34 |
// This exception can by done
|
35 |
} |
36 |
} |
37 |
return other;
|
38 |
} |
39 |
|
40 |
|
41 |
public org.gvsig.installer.lib.api.Dependencies parse(String dependecies) { |
42 |
if (dependecies == null) { |
43 |
this.clear();
|
44 |
return this; |
45 |
} |
46 |
dependecies = dependecies.trim(); |
47 |
if (dependecies.equals("")) { |
48 |
this.clear();
|
49 |
return this; |
50 |
} |
51 |
|
52 |
String[] x = dependecies.split(","); |
53 |
for (int i = 0; i < x.length; i++) { |
54 |
this.add(createDependency().parse(x[i]));
|
55 |
} |
56 |
return this; |
57 |
} |
58 |
|
59 |
public String toString() { |
60 |
StringBuffer s = null; |
61 |
Iterator it = this.iterator(); |
62 |
while (it.hasNext()) {
|
63 |
if (s == null) { |
64 |
s = new StringBuffer(); |
65 |
} else {
|
66 |
s.append(", ");
|
67 |
} |
68 |
s.append(it.next().toString()); |
69 |
} |
70 |
if (s == null) { |
71 |
return ""; |
72 |
} |
73 |
return s.toString();
|
74 |
} |
75 |
|
76 |
public boolean contains(Object o) { |
77 |
if (!(o instanceof Dependency)) { |
78 |
return false; |
79 |
} |
80 |
Iterator it = this.iterator(); |
81 |
while (it.hasNext()) {
|
82 |
Dependency dep = (Dependency) it.next(); |
83 |
if (dep.equals(o)) {
|
84 |
return true; |
85 |
} |
86 |
} |
87 |
return false; |
88 |
} |
89 |
|
90 |
public boolean match(String type, String code, Version version) { |
91 |
Iterator it = this.iterator(); |
92 |
while (it.hasNext()) {
|
93 |
Dependency dependency = (Dependency) it.next(); |
94 |
if (dependency.match(type, code, version)) {
|
95 |
return true; |
96 |
} |
97 |
} |
98 |
return false; |
99 |
} |
100 |
|
101 |
public Dependency find(String type, String code, Version version) { |
102 |
Iterator it = this.iterator(); |
103 |
while (it.hasNext()) {
|
104 |
Dependency dependency = (Dependency) it.next(); |
105 |
if (dependency.match(type, code, version)) {
|
106 |
return dependency;
|
107 |
} |
108 |
} |
109 |
return null; |
110 |
} |
111 |
|
112 |
} |