All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ogema.serialization.SchemaUtil Maven / Gradle / Ivy

There is a newer version: 2.2.1_1
Show newest version
/**
 * This file is part of OGEMA.
 *
 * OGEMA is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3
 * as published by the Free Software Foundation.
 *
 * OGEMA 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with OGEMA. If not, see .
 */
package org.ogema.serialization;

import javax.xml.XMLConstants;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import org.xml.sax.SAXException;

/**
 * 
 * @author jlapp
 */
public class SchemaUtil {

	private static class SchemaInstance {

		static final Schema INSTANCE = loadSchema();
		static SAXException ex;

		static Schema loadSchema() {
			try {
				SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
				Schema schema = sf.newSchema(SchemaUtil.class.getResource("/Ogema.xsd"));
				return schema;
			} catch (SAXException e) {
				ex = e;
				return null;
			}
		}
	}

	public static Schema getSchema() throws SAXException {
		if (SchemaInstance.INSTANCE == null) {
			throw SchemaInstance.ex;
		}
		return SchemaInstance.INSTANCE;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy