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.ParseException;
8   import net.sf.jpkgmk.pkgmap.PkgMapEntry;
9   import net.sf.jpkgmk.pkgmap.PkgMapEntryPipe;
10  import net.sf.jpkgmk.pkgmap.PkgMapEntryType;
11  
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 PrototypeEntryPipe extends AbstractPrototypeEntry {
21  
22  	/**
23  	 * Constructor taking the mandatory arguments to create a prototype file entry
24  	 * @param entryPath
25  	 */
26  	public PrototypeEntryPipe(String entryPath)
27  	{
28  		this(null, null, entryPath, null, null, null, null);
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 mode
37  	 * @param owner
38  	 * @param group
39  	 * @param entryCommandDefault
40  	 */
41  	public PrototypeEntryPipe(Integer part, String fileClass, String entryPath, String mode, String owner, String group, PrototypeEntryCommandDefault entryCommandDefault)
42  	{
43  		super(part, PrototypeEntryType.P, fileClass, entryPath, null, mode, owner, group, entryCommandDefault);
44  		
45  		// Mandatory parameter check
46  		if(entryPath == null) {
47  			throw new NullPointerException("The parameter 'entryPath' must not be null");
48  		}
49  		if (getFileClass() == null) {
50  			throw new NullPointerException("The parameter 'fileClass' must not be null");
51  		}
52  
53  	}
54  
55  	@Override
56  	protected void create(File targetDir, String entryPathExpanded,
57  			String entryPathSourceExpanded) throws IOException {
58  		// nothing to do here - the pipe is created at the specific location during the package installation via "pkgadd"
59  	}
60  
61  	@Override
62  	protected PkgMapEntry createPkgMapEntry(Integer part,
63  			PkgMapEntryType resultType, String entryClass, String entryPath, String entryPathSource,
64  			Integer major, Integer minor, String mode, String owner,
65  			String group, File basedir) {
66  		return new PkgMapEntryPipe(part, entryClass, entryPath, mode, owner, group);
67  	}
68  
69  	
70  	
71  	public static class PrototypeEntryPipeParser extends AbstractPrototypeEntryParser
72  	{
73  
74  		public PrototypeEntryPipeParser()
75  		{
76  			super();
77  		}
78  		
79  		@Override
80  		protected PrototypeEntry parseItems(String[] items, Integer part, PrototypeEntryType type, int currentIndex, PrototypeEntryCommandDefault entryCommandDefault)
81  		{
82  			
83  			if(items.length < 3) {
84  				throw new ParseException("No valid pipe entry line '" + Arrays.asList(items) + "'. Example: 'p none /usr/mypipe'");
85  			}
86  
87  			String fileClass = items[currentIndex++];
88  			String path = items[currentIndex++];
89  
90  			String mode = getArrayValue(items, currentIndex++);
91  			String owner = getArrayValue(items, currentIndex++);
92  			String group = getArrayValue(items, currentIndex++);
93  			
94  			PrototypeEntryPipe entry = new PrototypeEntryPipe(part, fileClass, path, mode, owner, group, entryCommandDefault);
95  			return entry;
96  		}
97  		
98  	}
99  }