KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > invicta > process > ProjectResolver


1 package net.sf.invicta.process;
2
3 import java.util.Iterator JavaDoc;
4 import java.util.List JavaDoc;
5
6 import net.sf.invicta.InvictaException;
7 import net.sf.invicta.Logger;
8 import net.sf.invicta.api.InvictaProject;
9 import net.sf.invicta.project.ComponentDefinition;
10 import net.sf.invicta.project.InvictaProjectException;
11 import net.sf.invicta.project.ProjectDefinition;
12 import net.sf.invicta.project.ProjectDefinitionLoader;
13 import net.sf.invicta.type.TypeManager;
14
15 /**
16  * Resolves a project definition while creating the API data structure.
17  * Resolving is done using the project definition resolver and type
18  * manager.
19  */

20 public class ProjectResolver {
21     protected List JavaDoc definitionFiles;
22     protected List JavaDoc typeFiles;
23     protected ProjectDefinitionLoader loader;
24     protected TypeManager typeManager;
25     protected ProjectDefinition projectDefinition;
26     protected InvictaProjectImpl project;
27
28     /**
29      *
30      */

31     public ProjectResolver(List JavaDoc definitionFiles, List JavaDoc typeFiles) {
32         super();
33         this.definitionFiles = definitionFiles;
34         this.typeFiles = typeFiles;
35
36         // Create a new project definition loader and type manager.
37
this.loader = new ProjectDefinitionLoader();
38         this.typeManager = new TypeManager(typeFiles);
39     }
40
41     /**
42      * Resolves a project by loading project defintition files, resolving them,
43      * creating typed components that will resolve type definition files and
44      * creating a full project implementation.
45      *
46      * @return An implementation of the InvictaProject API interface.
47      * @throws InvictaException
48      */

49     public InvictaProject resolveProject() throws InvictaException {
50         
51         // Load the project definition from multiple definition files.
52
this.projectDefinition = loadProjectDefinition();
53         
54         // Resolve the loaded project definition.
55
this.projectDefinition.resolve();
56
57         // Create the Invicta project object using the resolved project
58
// definition.
59
this.project = new InvictaProjectImpl(this.projectDefinition);
60         
61         // Create typed components while adding them to the project
62
// object.
63
createTypedComponents();
64                                         
65         Logger.info("Invicta finished resolving project definition.");
66         
67         return project;
68     }
69
70     /**
71      * Creates TypedComponent objects for all components and adds the new
72      * objects to the project object.
73      *
74      * @throws InvictaException
75      */

76     protected void createTypedComponents() throws InvictaException {
77         // Fill the new InvictaProject with InvictaComponents created from
78
// the components of the resolved project definition.
79
for (Iterator JavaDoc iter = this.projectDefinition.getComponentsMap().values().iterator(); iter.hasNext();) {
80             ComponentDefinition componentDefinition = (ComponentDefinition) iter.next();
81             TypedComponent component =
82                     new TypedComponent(this.typeManager,
83                                        componentDefinition, this.project);
84             this.project.addComponent(component);
85         }
86     }
87
88
89     /**
90      * Loads all definition files into a single project definition object.
91      *
92      * @return A loaded unresolved ProjectDefinition object.
93      * @throws InvictaProjectException
94      */

95     protected ProjectDefinition loadProjectDefinition() throws InvictaProjectException {
96         // Load all definition files into a single ProjectDefinition object.
97
ProjectDefinition fullProjDef = new ProjectDefinition();
98         
99         // Go over the list of files and load them.
100
for (Iterator JavaDoc fileIter = this.definitionFiles.iterator(); fileIter.hasNext();) {
101             String JavaDoc fileName = (String JavaDoc) fileIter.next();
102             ProjectDefinition projDef = (ProjectDefinition) this.loader.load(fileName);
103             fullProjDef.putAll(projDef);
104         }
105         return fullProjDef;
106     }
107
108 }
109
Popular Tags