View Javadoc

1   package net.sf.jpkgmk.pkgmap;
2   
3   import net.sf.jpkgmk.util.ArrayUtil;
4   
5   import org.apache.commons.logging.Log;
6   import org.apache.commons.logging.LogFactory;
7   
8   
9   /**
10   * @author gommma (gommma AT users.sourceforge.net)
11   * @author Last changed by: $Author: gommma $
12   * @version $Revision: 2 $ $Date: 2008-08-20 21:14:19 +0200 (Mi, 20 Aug 2008) $
13   * @since 1.0
14   */
15  public class PkgMapEntryFile extends AbstractPkgMapEntry implements PkgMapEntry
16  {
17  
18  	private Log log = LogFactory.getLog(PkgMapEntryFile.class);
19  
20  	
21  	/**
22  	 * @param part
23  	 * @param type
24  	 * @param entryClass optional parameter. Can be null
25  	 * @param path
26  	 * @param mode
27  	 * @param owner
28  	 * @param group
29  	 */
30  	public PkgMapEntryFile(Integer part, PkgMapEntryType type, String entryClass, String entryPath, String mode, String owner, String group)
31  	{
32  		super(part, type, entryClass, entryPath, null, null, null, mode, owner, group);
33  
34  		validate();
35  	}
36  
37  	public void validate()
38  	{
39  		log.debug("<entering> validate()");
40  		
41  		if(getType() == null) {
42  			throw new NullPointerException("The parameter 'type' must not be null");
43  		}
44  
45  		if (getEntryClass() == null) {
46  			throw new NullPointerException("The parameter 'entryClass' must not be null");
47  		}
48  		if(getEntryPath()==null) {
49  			throw new NullPointerException("The parameter 'entryPath' must not be null");
50  		}
51  		if(getMode()==null) {
52  			throw new NullPointerException("The parameter 'mode' must not be null");
53  		}
54  		if(getOwner()==null) {
55  			throw new NullPointerException("The parameter 'owner' must not be null");
56  		}
57  		if(getGroup()==null) {
58  			throw new NullPointerException("The parameter 'group' must not be null");
59  		}
60  	}
61  
62  	
63  	public static class PkgMapEntryFileParser extends AbstractPkgMapEntryParser
64  	{
65  		@Override
66  		protected PkgMapEntry parseItems(String[] items, Integer part, PkgMapEntryType type, int currentIndex)
67  		{			
68  			String fileClass = items[currentIndex++];
69  			String path = items[currentIndex++];
70  
71  			String mode = ArrayUtil.getArrayValue(items, currentIndex++);
72  			String owner = ArrayUtil.getArrayValue(items, currentIndex++);
73  			String group = ArrayUtil.getArrayValue(items, currentIndex++);
74  
75  			Long size = ArrayUtil.getArrayValueAsLong(items, currentIndex++);
76  			Long chksum = ArrayUtil.getArrayValueAsLong(items, currentIndex++);
77  			Long modtime = ArrayUtil.getArrayValueAsLong(items, currentIndex++);
78  
79  			return createPkgMapEntry(part, type, fileClass, path, mode, owner, group, size, chksum, modtime);
80  		}
81  
82  		protected PkgMapEntry createPkgMapEntry(Integer part,
83  				PkgMapEntryType type, String fileClass, String path,
84  				String mode, String owner, String group, Long size,
85  				Long chksum, Long modtime) {
86  			PkgMapEntryFile result = new PkgMapEntryFile(part, type, fileClass, path, mode, owner, group);
87  			result.setFilesize(size);
88  			result.setChecksum(chksum);
89  			result.setModtime(modtime);
90  			return result;
91  		}
92  
93  		
94  	}
95  
96  
97  	public static class PkgMapEntryDirectoryParser extends PkgMapEntryFileParser
98  	{
99  
100 		@Override
101 		protected PkgMapEntry createPkgMapEntry(Integer part,
102 				PkgMapEntryType type, String fileClass, String path,
103 				String mode, String owner, String group, Long size,
104 				Long chksum, Long modtime) {
105 			PkgMapEntryFile result = new PkgMapEntryFile(part, type, fileClass, path, mode, owner, group);
106 			return result;
107 		}
108 
109 
110 		
111 	}
112 
113 }