1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package nl.toolforge.karma.core.manifest;
20
21 import nl.toolforge.core.util.file.XMLFilenameFilter;
22 import nl.toolforge.karma.core.boot.WorkingContext;
23 import nl.toolforge.karma.core.location.LocationException;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 import java.io.File;
28 import java.util.ArrayList;
29 import java.util.Arrays;
30 import java.util.Collection;
31 import java.util.HashSet;
32 import java.util.prefs.Preferences;
33
34 /***
35 * Class that collects all manifests for a <code>WorkingContext</code>.
36 *
37 * @author D.A. Smedes
38 * @version $Id: ManifestCollector.java,v 1.17 2004/11/03 20:54:15 asmedes Exp $
39 */
40 public class ManifestCollector {
41
42 private static Log logger = LogFactory.getLog(ManifestCollector.class);
43
44 private Collection manifests = new ArrayList();
45 private WorkingContext workingContext = null;
46
47 public ManifestCollector(WorkingContext workingContext) {
48 this.workingContext = workingContext;
49 }
50
51 /***
52 * Returns a collection of manifest file names, located in the the manifest store.
53 *
54 * @return
55 */
56 public Collection getAllManifests() {
57 File manifestStore = workingContext.getConfiguration().getManifestStore().getModule().getBaseDir();
58
59 Object[] mList = manifestStore.list(new XMLFilenameFilter());
60
61 if (mList == null) {
62 return new ArrayList();
63 }
64 manifests = Arrays.asList(mList);
65 if (manifests.size() == 0) {
66 return new ArrayList();
67 }
68
69 return manifests;
70 }
71
72 public synchronized void refresh() {
73 init();
74 }
75
76 /***
77 * Retrieves the last used manifest or <code>null</code> when none was found.
78 *
79 * @return The last used manifest.
80 * @throws ManifestException When the manifest referred to by {@link Manifest.HISTORY_KEY} could not be loaded.
81 */
82 public Manifest loadManifestFromHistory() throws LocationException, ManifestException {
83
84 String contextManifest = workingContext.getContextManifestPreference();
85
86 String manifestId = Preferences.userRoot().get(contextManifest, null);
87 if (manifestId != null) {
88
89 ManifestFactory manifestFactory = new ManifestFactory();
90 ManifestLoader loader = new ManifestLoader(workingContext);
91 Manifest manifest = manifestFactory.create(workingContext, loader.load(manifestId));
92
93 return manifest;
94 }
95
96 return null;
97 }
98
99 private synchronized void init() {
100 manifests = new HashSet();
101 }
102 }