View Javadoc

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.PkgMapEntryLink;
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  /**
16   * @author gommma (gommma AT users.sourceforge.net)
17   * @author Last changed by: $Author: gommma $
18   * @version $Revision: 2 $ $Date: 2008-08-20 21:14:19 +0200 (Mi, 20 Aug 2008) $
19   * @since 1.0
20   */
21  public class PrototypeEntrySymbolicLink extends AbstractPrototypeEntry {
22  
23  	/**
24  	 * Constructor taking the mandatory arguments to create a prototype file entry
25  	 * @param entryPath
26  	 */
27  	public PrototypeEntrySymbolicLink(String entryPath)
28  	{
29  		this(null, null, entryPath, null);
30  	}
31  
32  	/**
33  	 * Full constructor taking all arguments supported for this entry type
34  	 * @param fileClass
35  	 * @param entryPath path to the file or directory
36  	 * @param entryPathSource the target path in that this file should have in the package
37  	 */
38  	public PrototypeEntrySymbolicLink(Integer part, String fileClass, String entryPath, String entryPathSource)
39  	{
40  		super(part, PrototypeEntryType.S, fileClass, entryPath, entryPathSource, null, null, null, null);
41  		
42  		// Mandatory parameter check
43  		if(entryPath == null) {
44  			throw new NullPointerException("The parameter 'entryPath' must not be null");
45  		}
46  		if(entryPathSource == null) {
47  			throw new NullPointerException("The parameter 'entryPathSource' must not be null");
48  		}
49  	}
50  
51  	@Override
52  	protected void create(File targetDir, String entryPathExpanded,
53  			String entryPathSourceExpanded) throws IOException {
54  		// nothing to do - link is created at installtime of the package
55  	}
56  
57  	@Override
58  	protected PkgMapEntry createPkgMapEntry(Integer part,
59  			PkgMapEntryType resultType, String entryClass, String entryPath, String entryPathSource,
60  			Integer major, Integer minor, String mode, String owner,
61  			String group, File basedir) {
62  		return new PkgMapEntryLink(part, resultType, entryClass, entryPath, entryPathSource);
63  	}
64  
65  	
66  	public static class PrototypeEntrySymbolicLinkParser extends AbstractPrototypeEntryParser implements PrototypeEntryParser
67  	{
68  
69  		public PrototypeEntrySymbolicLinkParser()
70  		{
71  			super();
72  		}
73  		
74  		@Override
75  		protected PrototypeEntry parseItems(String[] items, Integer part, PrototypeEntryType type, int currentIndex, PrototypeEntryCommandDefault entryCommandDefault)
76  		{
77  			if(items.length < 3) {
78  				throw new IllegalArgumentException("The given array must contain at least 3 items to be a valid link: " + Arrays.asList(items));
79  			}
80  
81  			String fileClass = items[currentIndex++];
82  			String path = items[currentIndex++];
83  			
84  			KeyValuePair keyValue = StringUtil.resolveKeyValue(path);
85  			String entryPath = keyValue.getKey();
86  			String entryPathSource = keyValue.getValue();
87  			
88  			PrototypeEntrySymbolicLink entry = new PrototypeEntrySymbolicLink(part, fileClass, entryPath, entryPathSource);
89  			return entry;
90  		}
91  		
92  	}
93  }