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