1 17 18 19 package org.apache.catalina.util; 20 21 22 import java.util.StringTokenizer ; 23 24 25 46 47 public final class Extension { 48 49 50 52 53 56 private String extensionName = null; 57 58 59 public String getExtensionName() { 60 return (this.extensionName); 61 } 62 63 public void setExtensionName(String extensionName) { 64 this.extensionName = extensionName; 65 } 66 67 71 private String implementationURL = null; 72 73 public String getImplementationURL() { 74 return (this.implementationURL); 75 } 76 77 public void setImplementationURL(String implementationURL) { 78 this.implementationURL = implementationURL; 79 } 80 81 82 86 private String implementationVendor = null; 87 88 public String getImplementationVendor() { 89 return (this.implementationVendor); 90 } 91 92 public void setImplementationVendor(String implementationVendor) { 93 this.implementationVendor = implementationVendor; 94 } 95 96 97 101 private String implementationVendorId = null; 102 103 public String getImplementationVendorId() { 104 return (this.implementationVendorId); 105 } 106 107 public void setImplementationVendorId(String implementationVendorId) { 108 this.implementationVendorId = implementationVendorId; 109 } 110 111 112 116 private String implementationVersion = null; 117 118 public String getImplementationVersion() { 119 return (this.implementationVersion); 120 } 121 122 public void setImplementationVersion(String implementationVersion) { 123 this.implementationVersion = implementationVersion; 124 } 125 126 127 131 private String specificationVendor = null; 132 133 public String getSpecificationVendor() { 134 return (this.specificationVendor); 135 } 136 137 public void setSpecificationVendor(String specificationVendor) { 138 this.specificationVendor = specificationVendor; 139 } 140 141 142 146 private String specificationVersion = null; 147 148 public String getSpecificationVersion() { 149 return (this.specificationVersion); 150 } 151 152 public void setSpecificationVersion(String specificationVersion) { 153 this.specificationVersion = specificationVersion; 154 } 155 156 157 161 private boolean fulfilled = false; 162 163 public void setFulfilled(boolean fulfilled) { 164 this.fulfilled = fulfilled; 165 } 166 167 public boolean isFulfilled() { 168 return fulfilled; 169 } 170 171 173 182 public boolean isCompatibleWith(Extension required) { 183 184 if (extensionName == null) 186 return (false); 187 if (!extensionName.equals(required.getExtensionName())) 188 return (false); 189 190 if (required.getSpecificationVersion() != null) { 192 if (!isNewer(specificationVersion, 193 required.getSpecificationVersion())) 194 return (false); 195 } 196 197 if (required.getImplementationVendorId() != null) { 199 if (implementationVendorId == null) 200 return (false); 201 if (!implementationVendorId.equals(required 202 .getImplementationVendorId())) 203 return (false); 204 } 205 206 if (required.getImplementationVersion() != null) { 208 if (!isNewer(implementationVersion, 209 required.getImplementationVersion())) 210 return (false); 211 } 212 213 return (true); 215 216 } 217 218 221 public String toString() { 222 223 StringBuffer sb = new StringBuffer ("Extension["); 224 sb.append(extensionName); 225 if (implementationURL != null) { 226 sb.append(", implementationURL="); 227 sb.append(implementationURL); 228 } 229 if (implementationVendor != null) { 230 sb.append(", implementationVendor="); 231 sb.append(implementationVendor); 232 } 233 if (implementationVendorId != null) { 234 sb.append(", implementationVendorId="); 235 sb.append(implementationVendorId); 236 } 237 if (implementationVersion != null) { 238 sb.append(", implementationVersion="); 239 sb.append(implementationVersion); 240 } 241 if (specificationVendor != null) { 242 sb.append(", specificationVendor="); 243 sb.append(specificationVendor); 244 } 245 if (specificationVersion != null) { 246 sb.append(", specificationVersion="); 247 sb.append(specificationVersion); 248 } 249 sb.append("]"); 250 return (sb.toString()); 251 252 } 253 254 255 257 258 259 268 private boolean isNewer(String first, String second) 269 throws NumberFormatException { 270 271 if ((first == null) || (second == null)) 272 return (false); 273 if (first.equals(second)) 274 return (true); 275 276 StringTokenizer fTok = new StringTokenizer (first, ".", true); 277 StringTokenizer sTok = new StringTokenizer (second, ".", true); 278 int fVersion = 0; 279 int sVersion = 0; 280 while (fTok.hasMoreTokens() || sTok.hasMoreTokens()) { 281 if (fTok.hasMoreTokens()) 282 fVersion = Integer.parseInt(fTok.nextToken()); 283 else 284 fVersion = 0; 285 if (sTok.hasMoreTokens()) 286 sVersion = Integer.parseInt(sTok.nextToken()); 287 else 288 sVersion = 0; 289 if (fVersion < sVersion) 290 return (false); 291 else if (fVersion > sVersion) 292 return (true); 293 if (fTok.hasMoreTokens()) fTok.nextToken(); 295 if (sTok.hasMoreTokens()) 296 sTok.nextToken(); 297 } 298 299 return (true); 301 } 302 303 304 } 305 | Popular Tags |