KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > integration > ant > deployment > application > ApplicationXmlVersion


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.application;
21
22 import org.w3c.dom.DocumentType JavaDoc;
23
24 /**
25  * Enumerated type that represents the version of the deployment descriptor of
26  * a enterprise application (application.xml).
27  *
28  * @since Cactus 1.5
29  * @version $Id: ApplicationXmlVersion.java,v 1.1 2004/05/31 20:05:24 vmassol Exp $
30  */

31 public final class ApplicationXmlVersion implements Comparable JavaDoc
32 {
33
34     // Public Constants --------------------------------------------------------
35

36     /**
37      * Instance for version 1.2.
38      */

39     public static final ApplicationXmlVersion V1_2 = new ApplicationXmlVersion(
40         "1.2",
41         "-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN",
42         "http://java.sun.com/j2ee/dtds/application_1_2.dtd");
43
44     /**
45      * Instance for version 1.3.
46      */

47     public static final ApplicationXmlVersion V1_3 = new ApplicationXmlVersion(
48         "1.3",
49         "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN",
50         "http://java.sun.com/dtd/application_1_3.dtd");
51
52     // Instance Variables ------------------------------------------------------
53

54     /**
55      * The version as strnig,
56      */

57     private String JavaDoc version;
58
59     /**
60      * The public ID of the corresponding document type.
61      */

62     private String JavaDoc publicId;
63
64     /**
65      * The system ID of the corresponding document type.
66      */

67     public String JavaDoc systemId;
68
69     // Constructors ------------------------------------------------------------
70

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

78     private ApplicationXmlVersion(String JavaDoc theVersion, String JavaDoc thePublicId,
79         String JavaDoc theSystemId)
80     {
81         this.version = theVersion;
82         this.publicId = thePublicId;
83         this.systemId = theSystemId;
84     }
85
86     // Public Methods ----------------------------------------------------------
87

88     /**
89      * @see java.lang.Comparable#compareTo
90      */

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

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

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

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

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

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

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

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

182     public static ApplicationXmlVersion valueOf(String JavaDoc thePublicId)
183     {
184         if (V1_2.getPublicId().equals(thePublicId))
185         {
186             return ApplicationXmlVersion.V1_2;
187         }
188         else if (V1_3.getPublicId().equals(thePublicId))
189         {
190             return ApplicationXmlVersion.V1_3;
191         }
192         return null;
193     }
194
195 }
196
Popular Tags