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.karma.core.KarmaRuntimeException; |
22 |
|
import nl.toolforge.karma.core.Version; |
23 |
|
import nl.toolforge.karma.core.boot.WorkingContext; |
24 |
|
import nl.toolforge.karma.core.location.Location; |
25 |
|
import nl.toolforge.karma.core.location.LocationException; |
26 |
|
import nl.toolforge.karma.core.module.JavaEnterpriseApplicationModule; |
27 |
|
import nl.toolforge.karma.core.module.JavaWebApplicationModule; |
28 |
|
import nl.toolforge.karma.core.module.UntypedModule; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
public final class ModuleFactory { |
37 |
|
|
38 |
57 |
private WorkingContext workingContext = null; |
39 |
|
|
40 |
57 |
public ModuleFactory(WorkingContext workingContext) { |
41 |
57 |
this.workingContext = workingContext; |
42 |
57 |
} |
43 |
|
|
44 |
|
public Module create(ModuleDigester digester, Module.Type moduleType) throws LocationException { |
45 |
|
|
46 |
95 |
if (digester == null) { |
47 |
0 |
throw new IllegalArgumentException("Descriptor cannot be null."); |
48 |
|
} |
49 |
95 |
if (moduleType == null) { |
50 |
0 |
throw new IllegalArgumentException("Module type cannot be null."); |
51 |
|
} |
52 |
|
|
53 |
95 |
Location location = workingContext.getLocationLoader().get(digester.getLocation()); |
54 |
|
|
55 |
95 |
Version version = null; |
56 |
95 |
if (digester.getVersion() != null) { |
57 |
76 |
version = new Version(digester.getVersion()); |
58 |
|
} |
59 |
|
|
60 |
95 |
if (moduleType.equals(Module.JAVA_SOURCE_MODULE)) { |
61 |
0 |
return new SourceModule(digester.getName(), location, version); |
62 |
95 |
} else if (moduleType.equals(Module.JAVA_ENTERPRISE_APPLICATION)) { |
63 |
0 |
return new JavaEnterpriseApplicationModule(digester.getName(), location, version); |
64 |
95 |
} else if (moduleType.equals(Module.JAVA_WEB_APPLICATION)) { |
65 |
0 |
return new JavaWebApplicationModule(digester.getName(), location, version); |
66 |
95 |
} else if (moduleType.equals(Module.LIBRARY_MODULE)) { |
67 |
0 |
return new LibModule(digester.getName(), location, version); |
68 |
95 |
} else if (moduleType.equals(Module.OTHER_MODULE)) { |
69 |
0 |
return new OtherModule(digester.getName(), location, version); |
70 |
95 |
} else if (moduleType.equals(Module.UNKNOWN)) { |
71 |
95 |
return new UntypedModule(digester.getName(), location, version); |
72 |
|
} |
73 |
|
|
74 |
0 |
throw new KarmaRuntimeException("Type mismatch. Could not create module."); |
75 |
|
} |
76 |
|
} |