KickJava   Java API By Example, From Geeks To Geeks.

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


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  * J2EEBaseVersion.java
21  *
22  * Created on February 25, 2004, 2:36 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.share.configbean;
26
27 /**
28  * Base class to relate enumerated types of various J2EE versions.
29  *
30  * @author Peter Williams
31  */

32 public abstract class J2EEBaseVersion implements Comparable JavaDoc {
33
34     /** -----------------------------------------------------------------------
35      * Implementation
36      */

37     // This is the module version id, string and numeric form.
38
private final String JavaDoc j2eeModuleVersion; // e.g. "2.5" (servlet 2.5), "3.0" (ejb 3.0), etc.
39
private final int numericModuleVersion;
40     
41     // this is the j2ee/javaee spec version, string and numeric form.
42
private final String JavaDoc j2eeSpecVersion; // e.g. "1.4" (j2ee 1.4), "5.0" (javaee 5)
43
private final int numericSpecVersion;
44     
45     private final String JavaDoc publicId;
46     private final String JavaDoc systemId;
47     
48     /** Creates a new instance of J2EEBaseVersion
49      */

50     protected J2EEBaseVersion(String JavaDoc moduleVersion, int nv,
51             String JavaDoc specVersion, int nsv, String JavaDoc pubId, String JavaDoc sysId) {
52         j2eeModuleVersion = moduleVersion;
53         numericModuleVersion = nv;
54         j2eeSpecVersion = specVersion;
55         numericSpecVersion = nsv;
56         publicId = pubId;
57         systemId = sysId;
58     }
59     
60     /** The string representation of this version.
61      *
62      * @return String representing the numeric version, e.g. "1.4"
63      */

64     public String JavaDoc toString() {
65         return j2eeModuleVersion;
66     }
67     
68     /** The Sun public id for this J2EE module type
69      *
70      * @return String representing the Sun public id for this J2EE module type.
71      */

72     public String JavaDoc getSunPublicId() {
73         return publicId;
74     }
75
76     /** The Sun system id for this J2EE module type
77      *
78      * @return String representing the Sun system id for this J2EE module type.
79      */

80     public String JavaDoc getSunSystemId() {
81         return systemId;
82     }
83     
84     /** Compare the j2ee/javaee spec version of this instance with another (as
85      * opposed to comparing the module type version.
86      *
87      * @param target Version object to compare with
88      * @return -1, 0, 1 if this spec version is less than, equal to, or greater than
89      * the target version.
90      */

91     public int compareSpecification(J2EEBaseVersion target) {
92         if(numericSpecVersion < target.numericSpecVersion) {
93             return -1;
94         } else if(numericSpecVersion > target.numericSpecVersion) {
95             return 1;
96         } else {
97             return 0;
98         }
99     }
100
101     /** For use by derived class to compare numeric versions. Derived class
102      * should ensure target is the appropriate type before invoking this method
103      * to compare the version numbers themselves.
104      *
105      * @param target Version object to compare with
106      * @return -1, 0, 1 if this module version is less than, equal to, or greater than
107      * the target version.
108      */

109     protected int numericCompare(J2EEBaseVersion target) {
110         if(numericModuleVersion < target.numericModuleVersion) {
111             return -1;
112         } else if(numericModuleVersion > target.numericModuleVersion) {
113             return 1;
114         } else {
115             return 0;
116         }
117     }
118     
119 /*
120     public static J2EEBaseVersion getJ2EEVersion(String version) {
121         J2EEBaseVersion result = null;
122         
123         
124         if(J2EE_1_3.toString().equals(version)) {
125             result = J2EE_1_3;
126         } else if(J2EE_1_4.toString().equals(version)) {
127             result = J2EE_1_4;
128         }
129         
130         return result;
131     }
132  */

133 }
134
Popular Tags