KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > share > configbean > J2EEVersion


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * J2EEVersion.java
21  *
22  * Created on February 18, 2004, 2:36 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean;
26
27 /**
28  * Enumerated types for various J2EE versions.
29  *
30  * Be careful with the compareTo method of this class. It is there for comparing
31  * like versions (e.g. servlet 2.3 versus 2.4) only, but there is no type safety
32  * to prevent doing dumb things like comparing J2EE 1.4 with servlet 2.3.
33  *
34  * Perhaps I can think of a better design in the next version.
35  *
36  * @author Peter Williams
37  */

38 public final class J2EEVersion extends J2EEBaseVersion {
39
40     /** Represents J2EE version 1.3
41      */

42     public static final J2EEVersion J2EE_1_3 = new J2EEVersion(
43             "1.3", 1300, // NOI18N
44
"1.3", 1300); // NOI18N
45

46     /** Represents J2EE version 1.4
47      */

48     public static final J2EEVersion J2EE_1_4 = new J2EEVersion(
49             "1.4", 1400, // NOI18N
50
"1.4", 1400); // NOI18N
51

52     /** Represents JavaEE version 5.0
53      */

54     public static final J2EEVersion JAVAEE_5_0 = new J2EEVersion(
55             "5.0", 5000, // NOI18N
56
"5.0", 5000); // NOI18N
57

58     /** -----------------------------------------------------------------------
59      * Implementation
60      */

61     
62     /** Creates a new instance of J2EEVersion
63      */

64     private J2EEVersion(String JavaDoc version, int nv, String JavaDoc specVersion, int nsv) {
65         super(version, nv, specVersion, nsv, "", ""); // NOI18N
66
}
67     
68     /** Comparator implementation that works only on J2EEVersion objects
69      *
70      * @param obj J2EEVersion to compare with.
71      * @return -1, 0, or 1 if this version is less than, equal to, or greater
72      * than the version passed in as an argument.
73      * @throws ClassCastException if obj is not a J2EEVersion object.
74      */

75     public int compareTo(Object JavaDoc obj) {
76         J2EEVersion target = (J2EEVersion) obj;
77         return numericCompare(target);
78     }
79         
80     public static J2EEVersion getJ2EEVersion(String JavaDoc version) {
81         J2EEVersion result = null;
82         
83         if(J2EE_1_3.toString().equals(version)) {
84             result = J2EE_1_3;
85         } else if(J2EE_1_4.toString().equals(version)) {
86             result = J2EE_1_4;
87         }
88         
89         return result;
90     }
91 }
92
Popular Tags