svn-gvsig-desktop / branches / org.gvsig.desktop-cvsgis1 / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.spi / src / main / java / org / gvsig / fmap / dal / spi / DataServerExplorerPoolImpl.java @ 45393
History | View | Annotate | Download (4.4 KB)
1 |
package org.gvsig.fmap.dal.spi; |
---|---|
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 DataServerExplorerPoolImpl implements DataServerExplorerPool { |
17 |
|
18 |
|
19 |
private static final String PERSISTENCE_DEFINITION_NAME = "DataServerExplorerPool"; |
20 |
|
21 |
private List<DataServerExplorerPoolEntry> pool; |
22 |
|
23 |
public DataServerExplorerPoolImpl() {
|
24 |
this.pool = new ArrayList(); |
25 |
} |
26 |
|
27 |
@Override
|
28 |
public boolean contains(String name) { |
29 |
DataServerExplorerPoolEntry entry = this.get(name);
|
30 |
return entry!=null; |
31 |
} |
32 |
|
33 |
@Override
|
34 |
public boolean contains(DataServerExplorerPoolEntry entry) { |
35 |
return contains(entry.getName());
|
36 |
} |
37 |
|
38 |
@Override
|
39 |
public boolean isEmpty() { |
40 |
return this.pool.isEmpty(); |
41 |
} |
42 |
|
43 |
@Override
|
44 |
public DataServerExplorerPoolEntry createEntry(String name, String description, DataServerExplorerParameters explorer) { |
45 |
DataServerExplorerPoolEntryImpl entry = new DataServerExplorerPoolEntryImpl(name, description, explorer);
|
46 |
return entry;
|
47 |
} |
48 |
|
49 |
@Override
|
50 |
public void add(String name, DataServerExplorerParameters explorer) { |
51 |
this.add(name, null, explorer); |
52 |
} |
53 |
|
54 |
@Override
|
55 |
public void add(String name, String description, DataServerExplorerParameters explorer) { |
56 |
DataServerExplorerPoolEntry newexplorer = createEntry(name, description, explorer); |
57 |
DataServerExplorerPoolEntry existent = this.get(name);
|
58 |
if( existent!=null ) { |
59 |
newexplorer.copyTo(existent); |
60 |
} else {
|
61 |
this.pool.add(newexplorer);
|
62 |
} |
63 |
} |
64 |
|
65 |
@Override
|
66 |
public void remove(DataServerExplorerPoolEntry entry) { |
67 |
this.remove(entry.getName());
|
68 |
} |
69 |
|
70 |
@Override
|
71 |
public void remove(int explorerIndex) { |
72 |
this.pool.remove(explorerIndex);
|
73 |
} |
74 |
|
75 |
@Override
|
76 |
public void remove(String name) { |
77 |
if( StringUtils.isBlank(name) ) {
|
78 |
return;
|
79 |
} |
80 |
for( int i=0; i<this.pool.size(); i++ ) { |
81 |
DataServerExplorerPoolEntry entry = (DataServerExplorerPoolEntry) this.pool.get(i);
|
82 |
if( name.equalsIgnoreCase(entry.getName()) ) {
|
83 |
this.remove(i);
|
84 |
} |
85 |
} |
86 |
} |
87 |
|
88 |
@Override
|
89 |
public int size() { |
90 |
return this.pool.size(); |
91 |
} |
92 |
|
93 |
@Override
|
94 |
public DataServerExplorerPoolEntry get(int index) { |
95 |
return (DataServerExplorerPoolEntry) this.pool.get(index); |
96 |
} |
97 |
|
98 |
@Override
|
99 |
public DataServerExplorerPoolEntry get(String name) { |
100 |
if( StringUtils.isBlank(name) ) {
|
101 |
return null; |
102 |
} |
103 |
for( int i=0; i<this.pool.size(); i++ ) { |
104 |
DataServerExplorerPoolEntry entry = (DataServerExplorerPoolEntry) this.pool.get(i);
|
105 |
if( name.equalsIgnoreCase(entry.getName()) ) {
|
106 |
return entry;
|
107 |
} |
108 |
} |
109 |
return null; |
110 |
} |
111 |
|
112 |
@Override
|
113 |
public Iterator iterator() { |
114 |
return this.pool.iterator(); |
115 |
} |
116 |
|
117 |
@Override
|
118 |
public void saveToState(PersistentState state) throws PersistenceException { |
119 |
state.set("pool", pool);
|
120 |
} |
121 |
|
122 |
@Override
|
123 |
public void loadFromState(PersistentState state) throws PersistenceException { |
124 |
List l = state.getList("pool"); |
125 |
this.pool = new ArrayList(); |
126 |
this.pool.addAll(l);
|
127 |
} |
128 |
|
129 |
public static void registerPersistenceDefinition() { |
130 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
131 |
if ( manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null ) { |
132 |
DynStruct definition |
133 |
= manager.addDefinition(DataServerExplorerPoolImpl.class, |
134 |
PERSISTENCE_DEFINITION_NAME, PERSISTENCE_DEFINITION_NAME |
135 |
+ " Persistent definition", null, null); |
136 |
|
137 |
definition.addDynFieldList("pool")
|
138 |
.setClassOfItems(DataServerExplorerPoolEntryImpl.class) |
139 |
.setMandatory(true)
|
140 |
.setPersistent(true);
|
141 |
} |
142 |
} |
143 |
|
144 |
} |