svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / fmap / dal / impl / DefaultDataServerExplorerPool.java @ 41491
History | View | Annotate | Download (3.95 KB)
1 |
package org.gvsig.fmap.dal.impl; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Iterator; |
5 |
import java.util.List; |
6 |
import org.apache.commons.lang3.StringUtils; |
7 |
import org.gvsig.fmap.dal.DataServerExplorerParameters; |
8 |
import org.gvsig.fmap.dal.DataServerExplorerPool; |
9 |
import org.gvsig.fmap.dal.DataServerExplorerPoolEntry; |
10 |
import org.gvsig.tools.ToolsLocator; |
11 |
import org.gvsig.tools.dynobject.DynStruct; |
12 |
import org.gvsig.tools.persistence.PersistenceManager; |
13 |
import org.gvsig.tools.persistence.PersistentState; |
14 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
15 |
|
16 |
public class DefaultDataServerExplorerPool implements DataServerExplorerPool { |
17 |
|
18 |
|
19 |
private static final String PERSISTENCE_DEFINITION_NAME = "DataServerExplorerPool"; |
20 |
|
21 |
private List pool; |
22 |
|
23 |
public DefaultDataServerExplorerPool() {
|
24 |
this.pool = new ArrayList(); |
25 |
} |
26 |
|
27 |
public boolean contains(String name) { |
28 |
DataServerExplorerPoolEntry entry = this.get(name);
|
29 |
return entry!=null; |
30 |
} |
31 |
|
32 |
public boolean contains(DataServerExplorerPoolEntry entry) { |
33 |
return contains(entry.getName());
|
34 |
} |
35 |
|
36 |
public boolean isEmpty() { |
37 |
return this.pool.isEmpty(); |
38 |
} |
39 |
|
40 |
public void add(String name, DataServerExplorerParameters explorer) { |
41 |
this.add(name, null, explorer); |
42 |
} |
43 |
|
44 |
public void add(String name, String description, DataServerExplorerParameters explorer) { |
45 |
DefaultDataServerExplorerPoolEntry newexplorer = new DefaultDataServerExplorerPoolEntry(name, description, explorer);
|
46 |
DataServerExplorerPoolEntry existent = this.get(name);
|
47 |
if( existent!=null ) { |
48 |
newexplorer.copyTo(existent); |
49 |
} else {
|
50 |
this.pool.add(newexplorer);
|
51 |
} |
52 |
} |
53 |
|
54 |
public void remove(DataServerExplorerPoolEntry entry) { |
55 |
this.remove(entry.getName());
|
56 |
} |
57 |
|
58 |
public void remove(int explorerIndex) { |
59 |
this.pool.remove(explorerIndex);
|
60 |
} |
61 |
|
62 |
public void remove(String name) { |
63 |
if( StringUtils.isBlank(name) ) {
|
64 |
return;
|
65 |
} |
66 |
for( int i=0; i<this.pool.size(); i++ ) { |
67 |
DataServerExplorerPoolEntry entry = (DataServerExplorerPoolEntry) this.pool.get(i);
|
68 |
if( name.equalsIgnoreCase(entry.getName()) ) {
|
69 |
this.remove(i);
|
70 |
} |
71 |
} |
72 |
} |
73 |
|
74 |
public int size() { |
75 |
return this.pool.size(); |
76 |
} |
77 |
|
78 |
public DataServerExplorerPoolEntry get(int index) { |
79 |
return (DataServerExplorerPoolEntry) this.pool.get(index); |
80 |
} |
81 |
|
82 |
public DataServerExplorerPoolEntry get(String name) { |
83 |
if( StringUtils.isBlank(name) ) {
|
84 |
return null; |
85 |
} |
86 |
for( int i=0; i<this.pool.size(); i++ ) { |
87 |
DataServerExplorerPoolEntry entry = (DataServerExplorerPoolEntry) this.pool.get(i);
|
88 |
if( name.equalsIgnoreCase(entry.getName()) ) {
|
89 |
return entry;
|
90 |
} |
91 |
} |
92 |
return null; |
93 |
} |
94 |
|
95 |
public Iterator iterator() { |
96 |
return this.pool.iterator(); |
97 |
} |
98 |
|
99 |
public void saveToState(PersistentState state) throws PersistenceException { |
100 |
state.set("pool", pool);
|
101 |
} |
102 |
|
103 |
public void loadFromState(PersistentState state) throws PersistenceException { |
104 |
List l = state.getList("pool"); |
105 |
this.pool = new ArrayList(); |
106 |
this.pool.addAll(l);
|
107 |
} |
108 |
|
109 |
public static void registerPersistenceDefinition() { |
110 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
111 |
if ( manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null ) { |
112 |
DynStruct definition |
113 |
= manager.addDefinition(DefaultDataServerExplorerPool.class, |
114 |
PERSISTENCE_DEFINITION_NAME, PERSISTENCE_DEFINITION_NAME |
115 |
+ " Persistent definition", null, null); |
116 |
|
117 |
definition.addDynFieldList("pool")
|
118 |
.setClassOfItems(DefaultDataServerExplorerPoolEntry.class) |
119 |
.setMandatory(true)
|
120 |
.setPersistent(true);
|
121 |
} |
122 |
} |
123 |
|
124 |
} |