KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas_lib > deployment > api > CommonsDTDs


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or 1any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * Initial developer: Florent BENOIT
22  * --------------------------------------------------------------------------
23  * $Id: CommonsDTDs.java,v 1.2 2004/05/11 08:07:50 sauthieg Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas_lib.deployment.api;
28
29 import java.util.HashMap JavaDoc;
30 import java.util.Map JavaDoc;
31 import java.net.URL JavaDoc;
32
33
34 /**
35  * This class defines the declarations of defaults DTDs used for J2EE 1.4 and less
36  * @author Florent Benoit
37  */

38 public abstract class CommonsDTDs implements DTDs {
39
40     /**
41      * List of default dtds
42      */

43     private static final String JavaDoc[] DEFAULT_DTDS = new String JavaDoc[] {
44         "XMLSchema.dtd",
45         "datatypes.dtd"
46     };
47
48     /**
49      * List of default publicId
50      */

51     private static final String JavaDoc[] DEFAULT_DTDS_PUBLIC_ID = new String JavaDoc[] {
52         "-//W3C//DTD XMLSCHEMA 200102//EN",
53         "datatypes"
54     };
55
56
57     /**
58      * Map where mapping publicId/dtds are stored
59      */

60     private static HashMap JavaDoc dtdsMapping = null;
61
62     /**
63      * Build a new object for DTDs handling
64      */

65     public CommonsDTDs() {
66         dtdsMapping = new HashMap JavaDoc();
67         addMapping(DEFAULT_DTDS, DEFAULT_DTDS_PUBLIC_ID);
68     }
69
70     /**
71      * Gets the mapping between publicIds and DTDs
72      * @return the mapping between publicIds and DTDs
73      */

74     public Map JavaDoc getMapping() {
75         return dtdsMapping;
76     }
77
78
79
80     /**
81      * Add to the list of DTDS the given dtds/publicId
82      * @param dtds array of dtds
83      * @param publicIds array of publicIds
84      */

85     protected void addMapping(String JavaDoc[] dtds, String JavaDoc[] publicIds) {
86         if (dtds.length != publicIds.length) {
87             throw new IllegalStateException JavaDoc("SEVERE ERROR !!! Number of dtds is different of the number of PublicId !!! check the source code");
88         }
89
90         URL JavaDoc url = null;
91         for (int i = 0; i < dtds.length; i++) {
92             url = CommonsDTDs.class.getResource("/" + dtds[i]);
93             if (url == null) {
94                 throw new IllegalStateException JavaDoc("'" + dtds[i] + "' was not found in the current classloader !");
95             }
96             dtdsMapping.put(publicIds[i], url.toString());
97         }
98     }
99
100 }
101
Popular Tags