1 package net.sf.jpkgmk.prototype;
2
3 import java.io.File;
4 import java.io.FileNotFoundException;
5 import java.io.IOException;
6 import java.util.List;
7
8 import net.sf.jpkgmk.PackageException;
9 import net.sf.jpkgmk.pkgmap.PkgMap;
10 import net.sf.jpkgmk.pkgmap.PkgMapEntry;
11 import net.sf.jpkgmk.util.StringUtil;
12 import net.sf.jpkgmk.util.VariableMap;
13 import net.sf.jpkgmk.util.VariableResolver;
14
15 import org.apache.commons.logging.Log;
16 import org.apache.commons.logging.LogFactory;
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 public class PrototypeEntryCommandInclude extends PrototypeEntryCommand
33 {
34 private Log log = LogFactory.getLog(PrototypeEntryCommandInclude.class);
35 private String includePath;
36 private Prototype prototype;
37
38 public PrototypeEntryCommandInclude(String includePath) {
39 super(CommandType.INCLUDE);
40 this.includePath = includePath;
41 }
42
43 @Override
44 protected String getCommandLinePart() {
45 StringBuffer sb = new StringBuffer();
46 if(!StringUtil.isNullOrEmpty(includePath)) {
47 sb.append(includePath);
48 }
49 return sb.toString();
50 }
51
52 public List<PkgMapEntry> createPkgMapEntry(File basedir, VariableResolver variableResolver) {
53 try {
54 Prototype prototype = getPrototype(variableResolver);
55
56
57
58 PkgMap pkgMap = prototype.createPkgMap(basedir);
59 return pkgMap.getPkgMapEntries();
60 } catch (IOException e) {
61 throw new PackageException("Exception while building nested prototype.", e);
62 }
63 }
64
65 public void create(File basedir, VariableResolver variableResolver) throws IOException {
66 log.debug("<Entering> create(File basedir)");
67 Prototype prototype = getPrototype(variableResolver);
68 prototype.createFiles(basedir);
69 }
70
71
72
73
74
75
76 Prototype getPrototype(VariableResolver variableResolver) throws IOException {
77 if(this.prototype == null) {
78 File prototypeFile = getPrototypeFile(variableResolver);
79 PrototypeParser protoParser = new PrototypeParser();
80 this.prototype = protoParser.parse(prototypeFile);
81
82
83 this.prototype.setVariableMap((VariableMap)variableResolver);
84 }
85 return this.prototype;
86 }
87
88 File getPrototypeFile(VariableResolver variableResolver) throws FileNotFoundException {
89 File prototypeFile = super.resolveFile(this.includePath, variableResolver);
90 return prototypeFile;
91 }
92 }