1 package net.sf.jpkgmk.prototype;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.Arrays;
6
7 import net.sf.jpkgmk.pkgmap.PkgMapEntry;
8 import net.sf.jpkgmk.pkgmap.PkgMapEntryDevice;
9 import net.sf.jpkgmk.pkgmap.PkgMapEntryType;
10
11 import org.apache.commons.logging.Log;
12 import org.apache.commons.logging.LogFactory;
13
14
15
16
17
18
19
20
21
22
23 public class AbstractPrototypeEntryDevice extends AbstractPrototypeEntry
24 {
25 private Log log = LogFactory.getLog(AbstractPrototypeEntryDevice.class);
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 public AbstractPrototypeEntryDevice(Integer part, PrototypeEntryType type, String fileClass, String entryPath, Integer major, Integer minor, String mode, String owner, String group, PrototypeEntryCommandDefault entryCommandDefault)
41 {
42 super(part, type, fileClass, entryPath, null, major, minor, mode, owner, group, entryCommandDefault);
43
44 validate();
45 }
46
47 private void validate() {
48
49 if(getEntryPath() == null) {
50 throw new NullPointerException("The parameter 'entryPath' must not be null");
51 }
52 if(getType() == null) {
53 throw new NullPointerException("The parameter 'type' must not be null");
54 }
55 if(getMode() == null) {
56 throw new NullPointerException("The parameter 'mode' must not be null");
57 }
58 if(getOwner() == null) {
59 throw new NullPointerException("The parameter 'owner' must not be null");
60 }
61 if(getGroup() == null) {
62 throw new NullPointerException("The parameter 'group' must not be null");
63 }
64 if(getMajor() == null) {
65 throw new NullPointerException("The parameter 'major' must not be null");
66 }
67 if(getMinor() == null) {
68 throw new NullPointerException("The parameter 'minor' must not be null");
69 }
70 }
71
72
73 @Override
74 protected PkgMapEntry createPkgMapEntry(Integer part,
75 PkgMapEntryType resultType, String entryClass, String entryPath, String entryPathSource,
76 Integer major, Integer minor, String mode, String owner, String group, File basedir) {
77 PkgMapEntryDevice result = new PkgMapEntryDevice(part, resultType, entryClass, entryPath, major, minor, mode, owner, group);
78 return result;
79 }
80
81 @Override
82 protected void create(File targetDir, String entryPathExpanded,
83 String entryPathSourceExpanded) throws IOException {
84 log.debug("<entering> create() - nothing to do here");
85
86 }
87
88 public abstract static class AbstractPrototypeEntryDeviceParser extends AbstractPrototypeEntryParser implements PrototypeEntryParser
89 {
90
91 public AbstractPrototypeEntryDeviceParser()
92 {
93 super();
94 }
95
96 @Override
97 protected PrototypeEntry parseItems(String[] items, Integer part, PrototypeEntryType type, int currentIndex, PrototypeEntryCommandDefault entryCommandDefault)
98 {
99 if(items.length < 5) {
100 throw new IllegalArgumentException("The given array must contain at least 5 items to be a valid device: " + Arrays.asList(items));
101 }
102
103 String fileClass = items[currentIndex++];
104 String path = items[currentIndex++];
105
106 String majorString = items[currentIndex++];
107 String minorString = items[currentIndex++];
108 String mode = getArrayValue(items, currentIndex++);
109 String owner = getArrayValue(items, currentIndex++);
110 String group = getArrayValue(items, currentIndex++);
111
112 Integer major = null;
113 try {
114 major = new Integer(majorString);
115 }
116 catch(NumberFormatException e) {
117 throw new IllegalArgumentException("The parameter major='" + majorString + "' is not a valid integer.");
118 }
119
120 Integer minor = null;
121 try {
122 minor = new Integer(minorString);
123 }
124 catch(NumberFormatException e) {
125 throw new IllegalArgumentException("The parameter major='" + minorString + "' is not a valid integer.");
126 }
127
128 return createEntry(fileClass, path, major, minor, mode, owner, group, entryCommandDefault);
129 }
130
131 protected abstract AbstractPrototypeEntryDevice createEntry(String fileClass, String entryPath,
132 Integer major, Integer minor, String mode, String owner, String group, PrototypeEntryCommandDefault entryCommandDefault);
133
134 }
135
136
137
138 }