View Javadoc

1   package net.sf.jpkgmk.prototype;
2   
3   import java.io.File;
4   import java.util.Arrays;
5   
6   import net.sf.jpkgmk.ParseException;
7   import net.sf.jpkgmk.pkgmap.PkgMapEntry;
8   import net.sf.jpkgmk.pkgmap.PkgMapEntryInfo;
9   import net.sf.jpkgmk.pkgmap.PkgMapEntryType;
10  import net.sf.jpkgmk.util.StringUtil;
11  import net.sf.jpkgmk.util.StringUtil.KeyValuePair;
12  
13  
14  /**
15   * @author gommma (gommma AT users.sourceforge.net)
16   * @author Last changed by: $Author: gommma $
17   * @version $Revision: 2 $ $Date: 2008-08-20 21:14:19 +0200 (Mi, 20 Aug 2008) $
18   * @since 1.0
19   */
20  public class PrototypeEntryInfo extends PrototypeEntryFile {
21  
22  	/**
23  	 * Constructor taking the mandatory arguments to create a prototype file entry
24  	 * @param entryPath
25  	 */
26  	public PrototypeEntryInfo(String entryPath)
27  	{
28  		this(null, entryPath, null);
29  	}
30  
31  	/**
32  	 * Full constructor taking all arguments supported for this entry type
33  	 * @param part The part number of this entry
34  	 * @param entryPath the target path that this file/directory should have in the created package
35  	 * @param entryPathSource path to the local source file
36  	 */
37  	public PrototypeEntryInfo(Integer part, String entryPath, String entryPathSource)
38  	{
39  		super(part, PrototypeEntryType.I, null, entryPath, entryPathSource, null, null, null, null);
40  
41  		// Mandatory parameter check
42  		if(entryPath == null) {
43  			throw new NullPointerException("The parameter 'value' must not be null");
44  		}
45  	}
46  
47  
48  	@Override
49  	protected PkgMapEntry createPkgMapEntry(Integer part,
50  			PkgMapEntryType resultType, String entryClass, String entryPath, String entryPathSource,
51  			Integer major, Integer minor, String mode, String owner,
52  			String group, File basedir) {
53  		return new PkgMapEntryInfo(part, entryPath);
54  	}
55  
56  
57  	public static class PrototypeEntryInfoParser extends AbstractPrototypeEntryParser implements PrototypeEntryParser
58  	{
59  
60  		public PrototypeEntryInfoParser()
61  		{
62  			super();
63  		}
64  		
65  		@Override
66  		protected PrototypeEntry parseItems(String[] items, Integer part, PrototypeEntryType type, int currentIndex, PrototypeEntryCommandDefault entryCommandDefault)
67  		{
68  			
69  			if(items.length < 2) {
70  				throw new ParseException("No valid info entry line '" + Arrays.asList(items) + "'. Example: 'i /usr/wrap=/bla/my/path'");
71  			}
72  
73  //			String path = items[1];
74  			KeyValuePair keyValuePair = StringUtil.resolveKeyValue(items[currentIndex++]);
75  			String entryPath = keyValuePair.getKey();
76  			String entryPathSource = keyValuePair.getValue();
77  
78  			PrototypeEntry entry = new PrototypeEntryInfo(part, entryPath, entryPathSource);
79  			return entry;
80  		}
81  		
82  	}
83  
84  }