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.application;
021:
022: import org.w3c.dom.DocumentType;
023:
024: /**
025: * Enumerated type that represents the version of the deployment descriptor of
026: * a enterprise application (application.xml).
027: *
028: * @since Cactus 1.5
029: * @version $Id: ApplicationXmlVersion.java 239003 2004-05-31 20:05:27Z vmassol $
030: */
031: public final class ApplicationXmlVersion implements Comparable {
032:
033: // Public Constants --------------------------------------------------------
034:
035: /**
036: * Instance for version 1.2.
037: */
038: public static final ApplicationXmlVersion V1_2 = new ApplicationXmlVersion(
039: "1.2",
040: "-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN",
041: "http://java.sun.com/j2ee/dtds/application_1_2.dtd");
042:
043: /**
044: * Instance for version 1.3.
045: */
046: public static final ApplicationXmlVersion V1_3 = new ApplicationXmlVersion(
047: "1.3",
048: "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN",
049: "http://java.sun.com/dtd/application_1_3.dtd");
050:
051: // Instance Variables ------------------------------------------------------
052:
053: /**
054: * The version as strnig,
055: */
056: private String version;
057:
058: /**
059: * The public ID of the corresponding document type.
060: */
061: private String publicId;
062:
063: /**
064: * The system ID of the corresponding document type.
065: */
066: public String systemId;
067:
068: // Constructors ------------------------------------------------------------
069:
070: /**
071: * Constructor.
072: *
073: * @param theVersion The version as string
074: * @param thePublicId The public ID of the correspondig document type
075: * @param theSystemId The system ID of the correspondig document type
076: */
077: private ApplicationXmlVersion(String theVersion,
078: String thePublicId, String theSystemId) {
079: this .version = theVersion;
080: this .publicId = thePublicId;
081: this .systemId = theSystemId;
082: }
083:
084: // Public Methods ----------------------------------------------------------
085:
086: /**
087: * @see java.lang.Comparable#compareTo
088: */
089: public int compareTo(Object theOther) {
090: if (theOther == this ) {
091: return 0;
092: }
093: ApplicationXmlVersion otherVersion = (ApplicationXmlVersion) theOther;
094: if (otherVersion == V1_3) {
095: return -1;
096: }
097: return 1;
098: }
099:
100: /**
101: * @see java.lang.Object#toString
102: */
103: public boolean equals(Object theOther) {
104: return super .equals(theOther);
105: }
106:
107: /**
108: * @see java.lang.Object#hashCode
109: */
110: public int hashCode() {
111: return super .hashCode();
112: }
113:
114: /**
115: * Returns the tag name.
116: *
117: * @return The tag name
118: */
119: public String getVersion() {
120: return this .version;
121: }
122:
123: /**
124: * Returns the public ID of the document type corresponding to the
125: * descriptor version.
126: *
127: * @return The public ID
128: */
129: public String getPublicId() {
130: return publicId;
131: }
132:
133: /**
134: * Returns the system ID of the document type corresponding to the
135: * descriptor version.
136: *
137: * @return The system ID
138: */
139: public String getSystemId() {
140: return systemId;
141: }
142:
143: /**
144: * @see java.lang.Object#toString
145: */
146: public String toString() {
147: return getVersion();
148: }
149:
150: /**
151: * Returns the version corresponding to the given document type.
152: *
153: * @param theDocType The document type
154: * @return The version that matches the document type, or <code>null</code>
155: * if the doctype is not recognized
156: * @throws NullPointerException If the document type is <code>null</code>
157: */
158: public static ApplicationXmlVersion valueOf(DocumentType theDocType)
159: throws NullPointerException {
160: return valueOf(theDocType.getPublicId());
161: }
162:
163: /**
164: * Returns the version corresponding to the given public ID.
165: *
166: * @param thePublicId The public ID
167: * @return The version that matches the public ID, or <code>null</code>
168: * if the ID is not recognized
169: */
170: public static ApplicationXmlVersion valueOf(String thePublicId) {
171: if (V1_2.getPublicId().equals(thePublicId)) {
172: return ApplicationXmlVersion.V1_2;
173: } else if (V1_3.getPublicId().equals(thePublicId)) {
174: return ApplicationXmlVersion.V1_3;
175: }
176: return null;
177: }
178:
179: }
|