* Synchronize all methods that call/rely on update().
* Make sure repositories and resources are not null after update() has been called.
This commit is contained in:
hns 2005-07-20 11:42:16 +00:00
parent bea4c3a5b7
commit 37e51812d6
3 changed files with 12 additions and 7 deletions

View file

@ -97,7 +97,7 @@ public abstract class AbstractRepository implements Repository {
* If the name can't be resolved to a resource, a resource object is returned
* for which {@link Resource exists()} returns <code>false<code>.
*/
public Resource getResource(String name) {
public synchronized Resource getResource(String name) {
update();
Resource res = (Resource) resources.get(name);
@ -112,7 +112,7 @@ public abstract class AbstractRepository implements Repository {
/**
* Get an iterator over the resources contained in this repository.
*/
public Iterator getResources() {
public synchronized Iterator getResources() {
update();
return resources.values().iterator();
@ -121,7 +121,7 @@ public abstract class AbstractRepository implements Repository {
/**
* Get an iterator over the sub-repositories contained in this repository.
*/
public Repository[] getRepositories() {
public synchronized Repository[] getRepositories() {
update();
return repositories;
@ -138,7 +138,7 @@ public abstract class AbstractRepository implements Repository {
* Get a deep list of this repository's resources, including all resources
* contained in sub-reposotories.
*/
public List getAllResources() throws IOException {
public synchronized List getAllResources() throws IOException {
update();
ArrayList allResources = new ArrayList();

View file

@ -115,7 +115,7 @@ public class FileRepository extends AbstractRepository {
return directory.lastModified();
}
public long getChecksum() throws IOException {
public synchronized long getChecksum() throws IOException {
// delay checksum check if already checked recently
if (System.currentTimeMillis() > lastChecksumTime + cacheTime) {
@ -141,8 +141,11 @@ public class FileRepository extends AbstractRepository {
public synchronized void update() {
if (!directory.exists()) {
repositories = new Repository[0];
if (resources != null)
if (resources != null) {
resources = new HashMap();
} else {
resources.clear();
}
lastModified = 0;
return;
}

View file

@ -95,7 +95,9 @@ public final class ZipRepository extends AbstractRepository {
}
public synchronized void update() {
if (file.lastModified() != lastModified) {
if (file.lastModified() != lastModified ||
repositories == null ||
resources == null) {
lastModified = file.lastModified();
ZipFile zipfile = null;