001: /*
002: * ========================================================================
003: *
004: * Copyright 2003 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * ========================================================================
019: */
020: package org.apache.cactus.integration.ant.deployment.webapp;
021:
022: import org.w3c.dom.DocumentType;
023:
024: /**
025: * Enumerated type that represents the version of the web deployment descriptor.
026: *
027: * @since Cactus 1.5
028: * @version $Id: WebXmlVersion.java 239003 2004-05-31 20:05:27Z vmassol $
029: */
030: public final class WebXmlVersion implements Comparable {
031:
032: // Public Constants --------------------------------------------------------
033:
034: /**
035: * Instance for version 2.2.
036: */
037: public static final WebXmlVersion V2_2 = new WebXmlVersion("2.2",
038: "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN",
039: "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd");
040:
041: /**
042: * Instance for version 2.3.
043: */
044: public static final WebXmlVersion V2_3 = new WebXmlVersion("2.3",
045: "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
046: "http://java.sun.com/dtd/web-app_2_3.dtd");
047:
048: // Instance Variables ------------------------------------------------------
049:
050: /**
051: * The version as strnig,
052: */
053: private String version;
054:
055: /**
056: * The public ID of the corresponding document type.
057: */
058: private String publicId;
059:
060: /**
061: * The system ID of the corresponding document type.
062: */
063: public String systemId;
064:
065: // Constructors ------------------------------------------------------------
066:
067: /**
068: * Constructor.
069: *
070: * @param theVersion The version as string
071: * @param thePublicId The public ID of the correspondig document type
072: * @param theSystemId The system ID of the correspondig document type
073: */
074: private WebXmlVersion(String theVersion, String thePublicId,
075: String theSystemId) {
076: this .version = theVersion;
077: this .publicId = thePublicId;
078: this .systemId = theSystemId;
079: }
080:
081: // Public Methods ----------------------------------------------------------
082:
083: /**
084: * @see java.lang.Comparable#compareTo
085: */
086: public int compareTo(Object theOther) {
087: if (theOther == this ) {
088: return 0;
089: }
090: WebXmlVersion otherVersion = (WebXmlVersion) theOther;
091: if (otherVersion == V2_3) {
092: return -1;
093: }
094: return 1;
095: }
096:
097: /**
098: * @see java.lang.Object#toString
099: */
100: public boolean equals(Object theOther) {
101: return super .equals(theOther);
102: }
103:
104: /**
105: * @see java.lang.Object#hashCode
106: */
107: public int hashCode() {
108: return super .hashCode();
109: }
110:
111: /**
112: * Returns the tag name.
113: *
114: * @return The tag name
115: */
116: public String getVersion() {
117: return this .version;
118: }
119:
120: /**
121: * Returns the public ID of the document type corresponding to the
122: * descriptor version.
123: *
124: * @return The public ID
125: */
126: public String getPublicId() {
127: return publicId;
128: }
129:
130: /**
131: * Returns the system ID of the document type corresponding to the
132: * descriptor version.
133: *
134: * @return The system ID
135: */
136: public String getSystemId() {
137: return systemId;
138: }
139:
140: /**
141: * @see java.lang.Object#toString
142: */
143: public String toString() {
144: return getVersion();
145: }
146:
147: /**
148: * Returns the version corresponding to the given document type.
149: *
150: * @param theDocType The document type
151: * @return The version that matches the document type, or <code>null</code>
152: * if the doctype is not recognized
153: * @throws NullPointerException If the document type is <code>null</code>
154: */
155: public static WebXmlVersion valueOf(DocumentType theDocType)
156: throws NullPointerException {
157: return valueOf(theDocType.getPublicId());
158: }
159:
160: /**
161: * Returns the version corresponding to the given public ID.
162: *
163: * @param thePublicId The public ID
164: * @return The version that matches the public ID, or <code>null</code>
165: * if the ID is not recognized
166: */
167: public static WebXmlVersion valueOf(String thePublicId) {
168: if (V2_2.getPublicId().equals(thePublicId)) {
169: return WebXmlVersion.V2_2;
170: } else if (V2_3.getPublicId().equals(thePublicId)) {
171: return WebXmlVersion.V2_3;
172: }
173: return null;
174: }
175:
176: }
|