
org.objectweb.jonas_lib.deployment.api.CommonsSchemas Maven / Gradle / Ivy
The newest version!
/**
* JOnAS: Java(TM) Open Application Server
* Copyright (C) 1999-2007 Bull S.A.S.
* Contact: [email protected]
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*
* --------------------------------------------------------------------------
* $Id: CommonsSchemas.java 10603 2007-06-12 11:22:04Z benoitf $
* --------------------------------------------------------------------------
*/
package org.objectweb.jonas_lib.deployment.api;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
/**
* This class defines the declarations of the default Java EE 5 Schemas.
* @author Florent Benoit
*/
public abstract class CommonsSchemas implements Schemas {
/**
* List of schemas used by components.
*/
private static final String[] DEFAULT_SCHEMAS = new String[] {
"javaee_5.xsd",
"javaee_web_services_client_1_2.xsd",
"j2ee_1_4.xsd",
"j2ee_web_services_client_1_1.xsd",
"xml.xsd",
"jonas_j2ee_4_0.xsd",
"jonas_j2ee_4_1.xsd",
"jonas_j2ee_4_1_2.xsd",
"jonas_j2ee_4_1_4.xsd",
"jonas_j2ee_4_2.xsd"
};
/**
* List where the local schemas URLs are stored.
*/
private static List localSchemas = null;
/**
* Build a new object for Schemas handling.
*/
public CommonsSchemas() {
localSchemas = new ArrayList();
addSchemas(DEFAULT_SCHEMAS);
}
/**
* Gets the URLs of the local schemas.
* @return the URLs of the local schemas
*/
public List getlocalSchemas() {
return localSchemas;
}
/**
* Add to our repository the given local schemas.
* @param schemas schemas to add to the repository
* @throws IllegalStateException if the dtds is not found as resource
*/
protected static void addSchemas(final String[] schemas) throws IllegalStateException {
URL url = null;
for (int i = 0; i < schemas.length; i++) {
url = CommonsSchemas.class.getResource("/" + schemas[i]);
if (url == null) {
throw new IllegalStateException("'" + schemas[i] + "' was not found in the current classloader !");
}
localSchemas.add(url.toString());
}
}
/**
* @param element name of the root element (jonas-ejb-jar, ...)
* @param schemas array of Schemas (to be always up to date)
* @return a header for the right element with last element
*/
public static String getHeaderForElement(final String element, final String[] schemas) {
StringBuffer header = new StringBuffer();
header.append("<");
header.append(element);
header.append(" xmlns=\"http://www.objectweb.org/jonas/ns\"\n");
header.append(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
header.append(" xsi:schemaLocation=\"http://www.objectweb.org/jonas/ns\n");
header.append(" http://www.objectweb.org/jonas/ns/");
// Get the last XSD
header.append(schemas[schemas.length - 1]);
header.append("\" >\n");
return header.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy