KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > support > builder > SpoonBuildingManager


1 package spoon.support.builder;
2
3 import java.io.File JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.util.Set JavaDoc;
6
7 import spoon.processing.Builder;
8 import spoon.processing.BuildingException;
9 import spoon.reflect.Factory;
10 import spoon.support.builder.support.CtFolderVirtual;
11
12 public class SpoonBuildingManager implements Builder {
13
14     private boolean build = false;
15
16     CtFolderVirtual source = new CtFolderVirtual();
17
18     CtFolderVirtual templates = new CtFolderVirtual();
19
20     public SpoonBuildingManager() {
21         super();
22     }
23
24     public void addInputSource(CtResource source) throws IOException JavaDoc {
25         if (source.isFile())
26             this.source.addFile((CtFile) source);
27         else
28             this.source.addFolder((CtFolder) source);
29     }
30
31     public void addInputSource(File JavaDoc source) throws IOException JavaDoc {
32         if (FileFactory.isFile(source))
33             this.source.addFile(FileFactory.createFile(source));
34         else
35             this.source.addFolder(FileFactory.createFolder(source));
36     }
37
38     public void addTemplateSource(CtResource source) throws IOException JavaDoc {
39         if (source.isFile())
40             this.templates.addFile((CtFile) source);
41         else
42             this.templates.addFolder((CtFolder) source);
43     }
44
45     public void addTemplateSource(File JavaDoc source) throws IOException JavaDoc {
46         if (FileFactory.isFile(source))
47             this.templates.addFile(FileFactory.createFile(source));
48         else
49             this.templates.addFolder(FileFactory.createFolder(source));
50     }
51
52     public void build(Factory factory) throws BuildingException {
53         if (build)
54             throw new BuildingException("Model already built");
55         build = true;
56
57         factory.setBuilder(this);
58
59         JDTCompiler.javaCompilant = factory.getEnvironment()
60                 .getComplianceLevel();
61
62         try {
63             JDTCompiler.compileSrc(factory, source.getAllJavaFile());
64         } catch (Throwable JavaDoc e) {
65             throw new BuildingException(e.getMessage());
66         }
67
68         try {
69             JDTCompiler.compileTemplate(factory, templates.getAllJavaFile());
70         } catch (Throwable JavaDoc e) {
71             throw new BuildingException(e.getMessage());
72         }
73
74         factory.Template().parseTypes();
75
76     }
77
78     public Set JavaDoc<File JavaDoc> getInputSources() {
79         // TODO Auto-generated method stub
80
return null;
81     }
82
83     public CtFolderVirtual getSource() {
84         return source;
85     }
86
87     public CtFolderVirtual getTemplates() {
88         return templates;
89     }
90
91     public Set JavaDoc<File JavaDoc> getTemplateSources() {
92         // TODO Auto-generated method stub
93
return null;
94     }
95
96 }
97
Popular Tags