KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > integration > ant > deployment > webapp > WebXmlVersion


1 /*
2  * ========================================================================
3  *
4  * Copyright 2003 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.integration.ant.deployment.webapp;
21
22 import org.w3c.dom.DocumentType JavaDoc;
23
24 /**
25  * Enumerated type that represents the version of the web deployment descriptor.
26  *
27  * @since Cactus 1.5
28  * @version $Id: WebXmlVersion.java,v 1.1 2004/05/31 20:05:23 vmassol Exp $
29  */

30 public final class WebXmlVersion implements Comparable JavaDoc
31 {
32
33     // Public Constants --------------------------------------------------------
34

35     /**
36      * Instance for version 2.2.
37      */

38     public static final WebXmlVersion V2_2 = new WebXmlVersion("2.2",
39         "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN",
40         "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd");
41
42     /**
43      * Instance for version 2.3.
44      */

45     public static final WebXmlVersion V2_3 = new WebXmlVersion("2.3",
46         "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN",
47         "http://java.sun.com/dtd/web-app_2_3.dtd");
48
49     // Instance Variables ------------------------------------------------------
50

51     /**
52      * The version as strnig,
53      */

54     private String JavaDoc version;
55
56     /**
57      * The public ID of the corresponding document type.
58      */

59     private String JavaDoc publicId;
60
61     /**
62      * The system ID of the corresponding document type.
63      */

64     public String JavaDoc systemId;
65
66     // Constructors ------------------------------------------------------------
67

68     /**
69      * Constructor.
70      *
71      * @param theVersion The version as string
72      * @param thePublicId The public ID of the correspondig document type
73      * @param theSystemId The system ID of the correspondig document type
74      */

75     private WebXmlVersion(String JavaDoc theVersion, String JavaDoc thePublicId,
76         String JavaDoc theSystemId)
77     {
78         this.version = theVersion;
79         this.publicId = thePublicId;
80         this.systemId = theSystemId;
81     }
82
83     // Public Methods ----------------------------------------------------------
84

85     /**
86      * @see java.lang.Comparable#compareTo
87      */

88     public int compareTo(Object JavaDoc theOther)
89     {
90         if (theOther == this)
91         {
92             return 0;
93         }
94         WebXmlVersion otherVersion = (WebXmlVersion) theOther;
95         if (otherVersion == V2_3)
96         {
97             return -1;
98         }
99         return 1;
100     }
101     
102     /**
103      * @see java.lang.Object#toString
104      */

105     public boolean equals(Object JavaDoc theOther)
106     {
107         return super.equals(theOther);
108     }
109     
110     /**
111      * @see java.lang.Object#hashCode
112      */

113     public int hashCode()
114     {
115         return super.hashCode();
116     }
117     
118     /**
119      * Returns the tag name.
120      *
121      * @return The tag name
122      */

123     public String JavaDoc getVersion()
124     {
125         return this.version;
126     }
127     
128     /**
129      * Returns the public ID of the document type corresponding to the
130      * descriptor version.
131      *
132      * @return The public ID
133      */

134     public String JavaDoc getPublicId()
135     {
136         return publicId;
137     }
138
139     /**
140      * Returns the system ID of the document type corresponding to the
141      * descriptor version.
142      *
143      * @return The system ID
144      */

145     public String JavaDoc getSystemId()
146     {
147         return systemId;
148     }
149
150     /**
151      * @see java.lang.Object#toString
152      */

153     public String JavaDoc toString()
154     {
155         return getVersion();
156     }
157
158     /**
159      * Returns the version corresponding to the given document type.
160      *
161      * @param theDocType The document type
162      * @return The version that matches the document type, or <code>null</code>
163      * if the doctype is not recognized
164      * @throws NullPointerException If the document type is <code>null</code>
165      */

166     public static WebXmlVersion valueOf(DocumentType JavaDoc theDocType)
167         throws NullPointerException JavaDoc
168     {
169         return valueOf(theDocType.getPublicId());
170     }
171
172     /**
173      * Returns the version corresponding to the given public ID.
174      *
175      * @param thePublicId The public ID
176      * @return The version that matches the public ID, or <code>null</code>
177      * if the ID is not recognized
178      */

179     public static WebXmlVersion valueOf(String JavaDoc thePublicId)
180     {
181         if (V2_2.getPublicId().equals(thePublicId))
182         {
183             return WebXmlVersion.V2_2;
184         }
185         else if (V2_3.getPublicId().equals(thePublicId))
186         {
187             return WebXmlVersion.V2_3;
188         }
189         return null;
190     }
191
192 }
193
Popular Tags