01: /**
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999 Bull S.A.
04: * Contact: jonas-team@objectweb.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * 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 4729 2004-05-11 08:07:50Z sauthieg $
24: * --------------------------------------------------------------------------
25: */package org.objectweb.jonas_lib.deployment.api;
26:
27: import java.util.HashMap;
28: import java.util.Map;
29: import java.net.URL;
30:
31: /**
32: * This class defines the declarations of defaults DTDs used for J2EE 1.4 and less
33: * @author Florent Benoit
34: */
35: public abstract class CommonsDTDs implements DTDs {
36:
37: /**
38: * List of default dtds
39: */
40: private static final String[] DEFAULT_DTDS = new String[] {
41: "XMLSchema.dtd", "datatypes.dtd" };
42:
43: /**
44: * List of default publicId
45: */
46: private static final String[] DEFAULT_DTDS_PUBLIC_ID = new String[] {
47: "-//W3C//DTD XMLSCHEMA 200102//EN", "datatypes" };
48:
49: /**
50: * Map where mapping publicId/dtds are stored
51: */
52: private static HashMap dtdsMapping = null;
53:
54: /**
55: * Build a new object for DTDs handling
56: */
57: public CommonsDTDs() {
58: dtdsMapping = new HashMap();
59: addMapping(DEFAULT_DTDS, DEFAULT_DTDS_PUBLIC_ID);
60: }
61:
62: /**
63: * Gets the mapping between publicIds and DTDs
64: * @return the mapping between publicIds and DTDs
65: */
66: public Map getMapping() {
67: return dtdsMapping;
68: }
69:
70: /**
71: * Add to the list of DTDS the given dtds/publicId
72: * @param dtds array of dtds
73: * @param publicIds array of publicIds
74: */
75: protected void addMapping(String[] dtds, String[] publicIds) {
76: if (dtds.length != publicIds.length) {
77: throw new IllegalStateException(
78: "SEVERE ERROR !!! Number of dtds is different of the number of PublicId !!! check the source code");
79: }
80:
81: URL url = null;
82: for (int i = 0; i < dtds.length; i++) {
83: url = CommonsDTDs.class.getResource("/" + dtds[i]);
84: if (url == null) {
85: throw new IllegalStateException(
86: "'"
87: + dtds[i]
88: + "' was not found in the current classloader !");
89: }
90: dtdsMapping.put(publicIds[i], url.toString());
91: }
92: }
93:
94: }
|