KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > savant > Workflow


1 /*
2  * Copyright (c) 2003-2004, Inversoft, All Rights Reserved
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.savant;
8
9
10 import java.io.File JavaDoc;
11 import java.util.ArrayList JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.List JavaDoc;
14
15
16 /**
17  * <p>
18  * This class is the workflow that is used when attemping to
19  * fetch artifacts.
20  * </p>
21  *
22  * @author Brian Pontarelli
23  */

24 public class Workflow {
25
26     private List JavaDoc processes = new ArrayList JavaDoc();
27
28
29     /**
30      * Constructs a new <code>WorkflowType</code>.
31      */

32     public Workflow() {
33     }
34
35
36     /**
37      * Add a new process to the list of processes that compose this workflow.
38      *
39      * @param process The new process
40      */

41     public void addProcess(Process JavaDoc process) {
42         processes.add(process);
43     }
44
45     /**
46      * Attempts to resolve the artifact dependencies for the given artifact by
47      * first checking the local cache and then using the process's in order until
48      * it is found.
49      */

50     public void resolveArtifactDependencies(Artifact artifact,
51             LocalCacheStore localCache)
52     throws SavantException {
53         boolean done = localCache.resolveArtifactDependencies(artifact);
54         if (!done) {
55             Iterator JavaDoc iter = processes.iterator();
56             Process JavaDoc process;
57             while (iter.hasNext()) {
58                 process = (Process JavaDoc) iter.next();
59                 done = process.resolveArtifactDependencies(artifact, localCache);
60                 if (done) {
61                     break;
62                 }
63             }
64         }
65     }
66
67     /**
68      * This first checks the local cache for the artifact. If it doesn't find it
69      * there, it loops over all the processes until the artifact is found or not.
70      * It is the responsibility of the {@link Process} object that finds the
71      * artifact to copy it to the local cache.
72      *
73      * @param artifact The artifact to locate
74      * @param localCache The local cache where the artifact is cached
75      * @return The artifact if found or null
76      * @throws SavantException If any process in the workflow fails
77      */

78     public File JavaDoc findArtifact(Artifact artifact, LocalCacheStore localCache)
79     throws SavantException {
80         File JavaDoc file = localCache.find(artifact);
81         if (file != null) {
82             return file;
83         }
84
85         Iterator JavaDoc iter = processes.iterator();
86         Process JavaDoc process;
87         while (iter.hasNext()) {
88             process = (Process JavaDoc) iter.next();
89             file = process.fetch(artifact, localCache);
90             if (file != null) {
91                 break;
92             }
93         }
94
95         return file;
96     }
97
98     /**
99      * Validates the process objects.
100      */

101     public void validate() throws SavantException {
102         Iterator JavaDoc iter = processes.iterator();
103         Process JavaDoc process;
104         while (iter.hasNext()) {
105             process = (Process JavaDoc) iter.next();
106             process.validate();
107         }
108     }
109 }
Popular Tags