KickJava   Java API By Example, From Geeks To Geeks.

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


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: CommonsSchemas.java,v 1.8 2004/11/19 09:23:01 sauthieg Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas_lib.deployment.api;
28
29
30 import java.net.URL JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import java.util.List JavaDoc;
33
34
35 /**
36  * This class defines the declarations of the default J2EE 1.4 Schemas
37  * @author Florent Benoit
38  */

39 public abstract class CommonsSchemas implements Schemas {
40
41
42     /**
43      * List of schemas used by components
44      */

45     private static final String JavaDoc[] DEFAULT_SCHEMAS = new String JavaDoc[] {
46         "j2ee_1_4.xsd",
47         "j2ee_web_services_client_1_1.xsd",
48         "xml.xsd",
49         "jonas_j2ee_4_0.xsd",
50         "jonas_j2ee_4_1.xsd",
51         "jonas_j2ee_4_1_2.xsd",
52         "jonas_j2ee_4_1_4.xsd",
53         "jonas_j2ee_4_2.xsd"
54     };
55
56
57     /**
58      * List where the local schemas URLs are stored
59      */

60     private static ArrayList JavaDoc localSchemas = null;
61
62
63     /**
64      * Build a new object for Schemas handling
65      */

66     public CommonsSchemas() {
67         localSchemas = new ArrayList JavaDoc();
68         addSchemas(DEFAULT_SCHEMAS);
69     }
70
71     /**
72      * Gets the URLs of the local schemas
73      * @return the URLs of the local schemas
74      */

75     public List JavaDoc getlocalSchemas() {
76         return localSchemas;
77     }
78
79
80     /**
81      * Add to our repository the given local schemas
82      * @param schemas schemas to add to the repository
83      * @throws IllegalStateException if the dtds is not found as resource
84      */

85     protected static void addSchemas(String JavaDoc[] schemas) throws IllegalStateException JavaDoc {
86         URL JavaDoc url = null;
87         for (int i = 0; i < schemas.length; i++) {
88             url = CommonsSchemas.class.getResource("/" + schemas[i]);
89             if (url == null) {
90                 throw new IllegalStateException JavaDoc("'" + schemas[i] + "' was not found in the current classloader !");
91             }
92             localSchemas.add(url.toString());
93         }
94     }
95
96     /**
97      * @param element name of the root element (jonas-ejb-jar, ...)
98      * @param schemas array of Schemas (to be always up to date)
99      * @return a header for the right element with last element
100      */

101     public static String JavaDoc getHeaderForElement(String JavaDoc element, String JavaDoc[] schemas) {
102         StringBuffer JavaDoc header = new StringBuffer JavaDoc();
103         header.append("<");
104         header.append(element);
105         header.append(" xmlns=\"http://www.objectweb.org/jonas/ns\"\n");
106         header.append(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
107         header.append(" xsi:schemaLocation=\"http://www.objectweb.org/jonas/ns\n");
108         header.append(" http://www.objectweb.org/jonas/ns/");
109
110         // Get the last XSD
111
header.append(schemas[schemas.length - 1]);
112         header.append("\" >\n");
113
114         return header.toString();
115     }
116
117 }
118
Popular Tags