1 package net.sf.jpkgmk.pkgmap;
2
3 import java.io.File;
4 import java.io.IOException;
5
6 import net.sf.jpkgmk.FileHandler;
7 import net.sf.jpkgmk.prototype.Prototype;
8
9 import org.apache.commons.logging.Log;
10 import org.apache.commons.logging.LogFactory;
11
12
13
14
15
16
17
18
19
20 public class PkgMapBuilder
21 {
22 private Log log = LogFactory.getLog(PkgMapBuilder.class);
23
24 private PkgMap pkgMap;
25 private File targetDir;
26 private Prototype prototype;
27
28
29
30
31
32
33
34 public PkgMapBuilder(File targetDir, Prototype prototype)
35 {
36 if (targetDir == null) {
37 throw new NullPointerException(
38 "The parameter 'targetDir' must not be null");
39 }
40 if (prototype == null) {
41 throw new NullPointerException(
42 "The parameter 'prototype' must not be null");
43 }
44
45 this.targetDir = targetDir;
46 this.prototype = prototype;
47 }
48
49 public PkgMap getPkgMap()
50 {
51 return this.pkgMap;
52 }
53
54 public File getFile(){
55 FileHandler fileHandler = getPkgMap().getFileHandler(this.targetDir);
56 return fileHandler.getFile();
57 }
58
59 public File clean() {
60 getPkgMap().clean(this.targetDir);
61 return getFile();
62 }
63
64
65
66
67
68
69
70 public File create() throws IOException {
71 log.debug("<entering> create()");
72
73 if(!this.targetDir.isDirectory()) {
74 throw new IllegalStateException("The root target dir '" + this.targetDir + "' does not exist.");
75 }
76
77 if(this.prototype == null) {
78 throw new IllegalStateException("The 'prototype' must not be null at this stage");
79 }
80
81 this.pkgMap = this.prototype.createPackage(this.targetDir);
82
83 pkgMap.create(this.targetDir);
84 return getFile();
85 }
86
87
88 }