1 package rydeen;
2
3 import java.util.ArrayList;
4 import java.util.Iterator;
5 import java.util.List;
6
7
8
9
10
11
12
13 public abstract class TargetType{
14 private static final List<TargetType> targets = new ArrayList<TargetType>();
15
16
17
18
19 public static final class SuffixTargetType extends StringTargetType{
20 public SuffixTargetType(String name, String... suffix){
21 super(name, suffix);
22 }
23
24 public boolean isType(String fileName){
25 boolean flag = false;
26 if(fileName != null){
27 for(String string: getStrings()){
28 if(fileName.endsWith(string)){
29 flag = true;
30 break;
31 }
32 }
33 }
34 return flag;
35 }
36 }
37
38
39
40
41 public static final class PrefixTargetType extends StringTargetType{
42 public PrefixTargetType(String name, String... prefix){
43 super(name, prefix);
44 }
45
46 public boolean isType(String fileName){
47 boolean flag = false;
48 if(fileName != null){
49 for(String string: getStrings()){
50 if(fileName.startsWith(string)){
51 flag = true;
52 }
53 }
54 }
55 return flag;
56 }
57 }
58
59
60
61
62 private static abstract class StringTargetType extends TargetType{
63 private String[] strings;
64 private String name;
65
66 public StringTargetType(String name, String... strings){
67 this.name = name;
68 this.strings = strings;
69 }
70
71 public String toString(){
72 return name;
73 }
74
75 public String[] getStrings(){
76 return strings;
77 }
78 }
79
80 public static final TargetType APT_FILE = new SuffixTargetType("APT_FILE", ".apt");
81
82 public static final TargetType HTML_FILE = new SuffixTargetType("HTML_FILE", ".html", ".htm");
83
84 public static final TargetType XML_FILE = new SuffixTargetType("XML_FILE", ".xml");
85
86 public static final TargetType CLASS_FILE = new SuffixTargetType("CLASS_FILE", ".class");
87
88 public static final TargetType JAVA_FILE = new SuffixTargetType("JAVA_FILE", ".java");
89
90 public static final TargetType MANIFEST = new PrefixTargetType("MANIFEST", "META-INF/MANIFEST.MF");
91
92 public static final TargetType JNLP_FILE = new SuffixTargetType("JNLP_FILE", ".jnlp");
93
94 public static final TargetType PROPERTIES_FILE = new SuffixTargetType("PROPERTIES_FILE", ".properties");
95
96 public static final TargetType SERVICE_DESCRIPTOR = new PrefixTargetType("SERVICE_DESCRIPTOR", "META-INF/services/");
97
98 public static final TargetType BMP_FILE = new SuffixTargetType("BMP_FILE", ".bmp");
99
100 public static final TargetType GIF_FILE = new SuffixTargetType("GIF_FILE", ".gif");
101
102 public static final TargetType JPG_FILE = new SuffixTargetType("JPG_FILE", ".jpg", ".jpeg", ".jpe");
103
104 public static final TargetType PNG_FILE = new SuffixTargetType("PNG_FILE", ".png");
105
106 public static final TargetType JAR_FILE = new SuffixTargetType("JAR_FILE", ".jar");
107
108 public static final TargetType ZIP_FILE = new SuffixTargetType("ZIP_FILE", ".zip");
109
110 public static final TargetType WAR_FILE = new SuffixTargetType("WAR_FILE", ".war");
111
112 public static final TargetType EAR_FILE = new SuffixTargetType("EAR_FILE", ".ear");
113
114 public static final TargetType TAR_FILE = new SuffixTargetType("TAR_FILE", ".tar");
115
116 public static final TargetType BZIP2_FILE = new SuffixTargetType("BZIP2_FILE", ".bz2");
117
118 public static final TargetType GZIP_FILE = new SuffixTargetType("GZIP_FILE", ".gz");
119
120
121
122 public static final TargetType FILE = new TargetType(){
123 @Override
124 public boolean isType(String fileName){
125 return fileName != null;
126 }
127
128 public String toString(){
129 return "FILE";
130 }
131 };
132
133
134
135
136
137
138 public static Iterator<TargetType> values(){
139 return targets.iterator();
140 }
141
142
143
144
145
146
147
148
149
150
151 public static TargetType getType(String name){
152 if(name == null){
153 throw new NullPointerException();
154 }
155 TargetType target = TargetType.FILE;
156 for(TargetType type: targets){
157 if(type.isType(name)){
158 target = type;
159 break;
160 }
161 }
162 return target;
163 }
164
165
166
167
168
169 protected TargetType(){
170 targets.add(this);
171 };
172
173
174
175
176
177 public abstract boolean isType(String fileName);
178 }