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 @ 44419
History | View | Annotate | Download (4.33 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 DataServerExplorerPoolEntry createEntry(String name, String description, DataServerExplorerParameters explorer) { |
41 |
DefaultDataServerExplorerPoolEntry entry = new DefaultDataServerExplorerPoolEntry(name, description, explorer);
|
42 |
return entry;
|
43 |
} |
44 |
|
45 |
@Override
|
46 |
public void add(String name, DataServerExplorerParameters explorer) { |
47 |
this.add(name, null, explorer); |
48 |
} |
49 |
|
50 |
@Override
|
51 |
public void add(String name, String description, DataServerExplorerParameters explorer) { |
52 |
DataServerExplorerPoolEntry newexplorer = createEntry(name, description, explorer); |
53 |
DataServerExplorerPoolEntry existent = this.get(name);
|
54 |
if( existent!=null ) { |
55 |
newexplorer.copyTo(existent); |
56 |
} else {
|
57 |
this.pool.add(newexplorer);
|
58 |
} |
59 |
} |
60 |
|
61 |
@Override
|
62 |
public void remove(DataServerExplorerPoolEntry entry) { |
63 |
this.remove(entry.getName());
|
64 |
} |
65 |
|
66 |
@Override
|
67 |
public void remove(int explorerIndex) { |
68 |
this.pool.remove(explorerIndex);
|
69 |
} |
70 |
|
71 |
@Override
|
72 |
public void remove(String name) { |
73 |
if( StringUtils.isBlank(name) ) {
|
74 |
return;
|
75 |
} |
76 |
for( int i=0; i<this.pool.size(); i++ ) { |
77 |
DataServerExplorerPoolEntry entry = (DataServerExplorerPoolEntry) this.pool.get(i);
|
78 |
if( name.equalsIgnoreCase(entry.getName()) ) {
|
79 |
this.remove(i);
|
80 |
} |
81 |
} |
82 |
} |
83 |
|
84 |
@Override
|
85 |
public int size() { |
86 |
return this.pool.size(); |
87 |
} |
88 |
|
89 |
@Override
|
90 |
public DataServerExplorerPoolEntry get(int index) { |
91 |
return (DataServerExplorerPoolEntry) this.pool.get(index); |
92 |
} |
93 |
|
94 |
@Override
|
95 |
public DataServerExplorerPoolEntry get(String name) { |
96 |
if( StringUtils.isBlank(name) ) {
|
97 |
return null; |
98 |
} |
99 |
for( int i=0; i<this.pool.size(); i++ ) { |
100 |
DataServerExplorerPoolEntry entry = (DataServerExplorerPoolEntry) this.pool.get(i);
|
101 |
if( name.equalsIgnoreCase(entry.getName()) ) {
|
102 |
return entry;
|
103 |
} |
104 |
} |
105 |
return null; |
106 |
} |
107 |
|
108 |
@Override
|
109 |
public Iterator iterator() { |
110 |
return this.pool.iterator(); |
111 |
} |
112 |
|
113 |
@Override
|
114 |
public void saveToState(PersistentState state) throws PersistenceException { |
115 |
state.set("pool", pool);
|
116 |
} |
117 |
|
118 |
@Override
|
119 |
public void loadFromState(PersistentState state) throws PersistenceException { |
120 |
List l = state.getList("pool"); |
121 |
this.pool = new ArrayList(); |
122 |
this.pool.addAll(l);
|
123 |
} |
124 |
|
125 |
public static void registerPersistenceDefinition() { |
126 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
127 |
if ( manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null ) { |
128 |
DynStruct definition |
129 |
= manager.addDefinition(DefaultDataServerExplorerPool.class, |
130 |
PERSISTENCE_DEFINITION_NAME, PERSISTENCE_DEFINITION_NAME |
131 |
+ " Persistent definition", null, null); |
132 |
|
133 |
definition.addDynFieldList("pool")
|
134 |
.setClassOfItems(DefaultDataServerExplorerPoolEntry.class) |
135 |
.setMandatory(true)
|
136 |
.setPersistent(true);
|
137 |
} |
138 |
} |
139 |
|
140 |
} |