001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.j2ee.sun.share.configbean;
042:
043: import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule;
044:
045: /**
046: * Base class to relate enumerated types of various J2EE/JavaEE versions.
047: *
048: * @author Peter Williams
049: */
050: public abstract class J2EEBaseVersion implements Comparable {
051:
052: /** -----------------------------------------------------------------------
053: * Implementation
054: */
055: // This is the module version id, string and numeric form.
056: private final String j2eeModuleVersion; // e.g. "2.5" (servlet 2.5), "3.0" (ejb 3.0), etc.
057: private final int numericModuleVersion;
058:
059: // This is the j2ee/javaee spec version, string and numeric form.
060: private final String j2eeSpecVersion; // e.g. "1.4" (j2ee 1.4), "5.0" (javaee 5)
061: private final int numericSpecVersion;
062:
063: /** Creates a new instance of J2EEBaseVersion
064: */
065: protected J2EEBaseVersion(String moduleVersion, int nv,
066: String specVersion, int nsv) {
067: j2eeModuleVersion = moduleVersion;
068: numericModuleVersion = nv;
069: j2eeSpecVersion = specVersion;
070: numericSpecVersion = nsv;
071: }
072:
073: /** The string representation of this version.
074: *
075: * @return String representing the module specification version, e.g. servlet 2.x
076: * ejb-jar 2.x, etc.
077: */
078: @Override
079: public String toString() {
080: return j2eeModuleVersion;
081: }
082:
083: /** Compare the j2ee/javaee spec version of this instance with another (as
084: * opposed to comparing the module type version.
085: *
086: * @param target Version object to compare with
087: * @return -1, 0, 1 if this spec version is less than, equal to, or greater than
088: * the target version.
089: */
090: public int compareSpecification(J2EEBaseVersion target) {
091: if (numericSpecVersion < target.numericSpecVersion) {
092: return -1;
093: } else if (numericSpecVersion > target.numericSpecVersion) {
094: return 1;
095: } else {
096: return 0;
097: }
098: }
099:
100: /** For use by derived class to compare numeric versions. Derived class
101: * should ensure target is the appropriate type before invoking this method
102: * to compare the version numbers themselves.
103: *
104: * @param target Version object to compare with
105: * @return -1, 0, 1 if this module version is less than, equal to, or greater than
106: * the target version.
107: */
108: protected int numericCompare(J2EEBaseVersion target) {
109: if (numericModuleVersion < target.numericModuleVersion) {
110: return -1;
111: } else if (numericModuleVersion > target.numericModuleVersion) {
112: return 1;
113: } else {
114: return 0;
115: }
116: }
117:
118: public static J2EEBaseVersion getVersion(
119: Object/*ModuleType*/moduleType, String moduleVersion) {
120: J2EEBaseVersion version = null;
121: if (J2eeModule.WAR.equals(moduleType)) {
122: version = ServletVersion.getServletVersion(moduleVersion);
123: } else if (J2eeModule.EJB.equals(moduleType)) {
124: version = EjbJarVersion.getEjbJarVersion(moduleVersion);
125: } else if (J2eeModule.EAR.equals(moduleType)) {
126: version = ApplicationVersion
127: .getApplicationVersion(moduleVersion);
128: } else if (J2eeModule.CLIENT.equals(moduleType)) {
129: version = AppClientVersion
130: .getAppClientVersion(moduleVersion);
131: }
132: return version;
133: }
134:
135: /*
136: public static J2EEBaseVersion getJ2EEVersion(String version) {
137: J2EEBaseVersion result = null;
138:
139:
140: if(J2EE_1_3.toString().equals(version)) {
141: result = J2EE_1_3;
142: } else if(J2EE_1_4.toString().equals(version)) {
143: result = J2EE_1_4;
144: }
145:
146: return result;
147: }
148: */
149: }
|