View Javadoc

1   package net.sf.jpkgmk.pkgmap;
2   
3   import net.sf.jpkgmk.pkgmap.PkgMapEntryComment.PkgMapEntryCommentParser;
4   import net.sf.jpkgmk.pkgmap.PkgMapEntryDevice.PkgMapEntryDeviceParser;
5   import net.sf.jpkgmk.pkgmap.PkgMapEntryFile.PkgMapEntryDirectoryParser;
6   import net.sf.jpkgmk.pkgmap.PkgMapEntryFile.PkgMapEntryFileParser;
7   import net.sf.jpkgmk.pkgmap.PkgMapEntryHeader.PkgMapEntryHeaderParser;
8   import net.sf.jpkgmk.pkgmap.PkgMapEntryInfo.PkgMapEntryInfoParser;
9   import net.sf.jpkgmk.pkgmap.PkgMapEntryLink.PkgMapEntryLinkParser;
10  
11  
12  /**
13   * Enumeration of all pkgmap entry types
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 PkgMapEntryType
21  {
22  	public static final PkgMapEntryType HEADER = new PkgMapEntryType(":", "header of the pkgmap - can occur only once", new PkgMapEntryHeaderParser());
23  	public static final PkgMapEntryType COMMENT = new PkgMapEntryType("#", "comment", new PkgMapEntryCommentParser()) {
24  	    @Override
25  		public boolean matches(String key) {
26  			// A comment can start with '#' followed by the comment directly without whitespace, e.g. "#My beautiful comment"
27  			if(key.startsWith(this.getKey())) {
28  				return true;
29  			}
30  			return false;
31  		}
32  	};
33  
34  	public static final PkgMapEntryType DIRECTORY = new PkgMapEntryType("d", "directory", new PkgMapEntryFileParser());
35  	public static final PkgMapEntryType DIRECTORY_EXCLUSIVE = new PkgMapEntryType("x", "exclusive directory (package specific)", new PkgMapEntryDirectoryParser());
36  	public static final PkgMapEntryType PIPE = new PkgMapEntryType("p", "named pipe", new PkgMapEntryFileParser());
37  	public static final PkgMapEntryType CHARACTER_SPECIAL = new PkgMapEntryType("c", "character special", new PkgMapEntryDeviceParser());
38  	public static final PkgMapEntryType BLOCK_SPECIAL = new PkgMapEntryType("b", "block special", new PkgMapEntryDeviceParser());
39  	public static final PkgMapEntryType SYMBOLIC_LINK = new PkgMapEntryType("s", "symbolic link", new PkgMapEntryLinkParser());
40  	public static final PkgMapEntryType FILE_LINKED = new PkgMapEntryType("l", "linked file", new PkgMapEntryLinkParser());
41  	public static final PkgMapEntryType FILE = new PkgMapEntryType("f", "executable or data file", new PkgMapEntryFileParser());
42  	public static final PkgMapEntryType FILE_EDITABLE = new PkgMapEntryType("e", "editable file", new PkgMapEntryFileParser());
43  	public static final PkgMapEntryType FILE_VOLATILE = new PkgMapEntryType("v", "volatile file (content may change)", new PkgMapEntryFileParser());
44  	public static final PkgMapEntryType FILE_INFO = new PkgMapEntryType("i", "meta-file", new PkgMapEntryInfoParser());
45  	
46  	public static final PkgMapEntryType[] VALUES = new PkgMapEntryType[] {
47  		HEADER, COMMENT, DIRECTORY, DIRECTORY_EXCLUSIVE, PIPE, CHARACTER_SPECIAL, BLOCK_SPECIAL,
48  		SYMBOLIC_LINK, FILE, FILE_EDITABLE, FILE_VOLATILE, FILE_LINKED, FILE_INFO
49  	};
50  	
51  	private String key;
52  	private String description;
53  	private PkgMapEntryParser pkgMapEntryParser;
54  	
55  	/**
56  	 * @param key Key used to identify the type of pkgmap entry - used for starting the line in the pkgmap file
57  	 * @param description
58  	 */
59  	private PkgMapEntryType(String key, String description, PkgMapEntryParser pkgMapEntryParser)
60  	{
61  		this.key = key;
62  		this.description = description;
63  		this.pkgMapEntryParser = pkgMapEntryParser;
64  	}
65  	
66  	public String getKey()
67  	{
68  		return this.key;
69  	}
70  	
71  	public String getDescription() {
72  		return description;
73  	}
74  	
75  	public PkgMapEntryParser getPkgMapEntryParser() {
76  		return pkgMapEntryParser;
77  	}
78  
79  	public boolean matches(String key) {
80  		return this.key.equals(key);
81  	}
82  
83  	@Override
84  	public String toString()
85  	{
86  		StringBuffer sb = new StringBuffer();
87  		sb.append(this.getClass().getName()).append("[");
88  		sb.append("key=").append(key);
89  //		sb.append(", description=").append(description);
90  //		sb.append(", pkgMapEntryParser=").append(pkgMapEntryParser);
91  		sb.append("]");
92  		return sb.toString();
93  	}
94  	
95  	public static PkgMapEntryType findType(String key)
96  	{
97  		for (int i = 0; i < VALUES.length; i++) {
98  			if(VALUES[i].matches(key)) {
99  				return VALUES[i];
100 			}
101 		}
102 		// No type found - return null
103 		return null;
104 	}
105 }