Revision 20624 trunk/libraries/libFMap_data/src/org/gvsig/data/ResourceManager.java
ResourceManager.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.security.KeyException; |
4 | 4 |
import java.util.HashMap; |
5 |
import java.util.Iterator; |
|
5 | 6 |
import java.util.Map; |
6 | 7 |
|
7 |
import org.gvsig.util.observer.Observable;
|
|
8 |
import org.gvsig.data.exception.DataException;
|
|
8 | 9 |
import org.gvsig.util.observer.IObservable; |
9 | 10 |
import org.gvsig.util.observer.IObserver; |
11 |
import org.gvsig.util.observer.Observable; |
|
10 | 12 |
|
11 | 13 |
|
12 | 14 |
public class ResourceManager implements IObservable{ |
... | ... | |
24 | 26 |
return resourceManager; |
25 | 27 |
} |
26 | 28 |
|
27 |
public synchronized Resource addResource(Resource resource) { |
|
29 |
public synchronized Resource addResource(Resource resource) throws DataException {
|
|
28 | 30 |
// Busca si el recurso no esta y de |
29 | 31 |
// ser asi lo aƱade. |
30 | 32 |
// En todo caso incrementa las referencias. |
... | ... | |
41 | 43 |
return res; |
42 | 44 |
} |
43 | 45 |
|
44 |
public synchronized void remove(Resource resource) throws KeyException { |
|
46 |
public synchronized void remove(Resource resource) throws KeyException, DataException {
|
|
45 | 47 |
remove(resource.getKey()); |
46 | 48 |
} |
47 | 49 |
|
48 |
public synchronized void remove(String key) throws KeyException { |
|
49 |
// Decrementa las referencias y lo elimina |
|
50 |
// si esta a 0 lo elimina. |
|
50 |
public synchronized void remove(String key) throws KeyException, DataException { |
|
51 |
Resource res = (Resource)this.resources.get(key); |
|
52 |
if (res == null){ |
|
53 |
throw new KeyException(key); |
|
54 |
} |
|
55 |
res.unref(); |
|
56 |
if (res.getRefencesCount() < 1){ |
|
57 |
this.resources.remove(key); |
|
58 |
res.dispose(); |
|
59 |
} |
|
60 |
res = null; |
|
51 | 61 |
|
52 | 62 |
} |
53 | 63 |
|
... | ... | |
55 | 65 |
return (Resource)this.resources.get(key); |
56 | 66 |
} |
57 | 67 |
|
68 |
public Iterator iterator(){ |
|
69 |
return this.resources.values().iterator(); |
|
70 |
} |
|
71 |
|
|
58 | 72 |
/* (non-Javadoc) |
59 | 73 |
* @see org.gvsig.data.IObservable#addObserver(org.gvsig.data.IObserver) |
60 | 74 |
*/ |
Also available in: Unified diff