Java tutorial
/* This file is part of Moose. Moose 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 3 of the License, or (at your option) any later version. Moose 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 Moose. If not, see <http://www.gnu.org/licenses/>. */ package com.quigley.moose.spring; import java.io.IOException; import javax.xml.parsers.ParserConfigurationException; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.io.ByteArrayResource; import org.springframework.xml.xsd.SimpleXsdSchema; import org.xml.sax.SAXException; import com.quigley.moose.mapping.Mapping; import com.quigley.moose.mapping.provider.MappingProvider; import com.quigley.moose.schema.SchemaGenerator; public class MooseXsdSchema extends SimpleXsdSchema implements InitializingBean { @Override public void afterPropertiesSet() throws ParserConfigurationException, IOException, SAXException { if (mappingProvider != null) { mapping = mappingProvider.getMapping(); } xsdResource = new ByteArrayResource(SchemaGenerator.generate(mapping).getBytes()); setXsd(xsdResource); super.afterPropertiesSet(); } public Mapping getMapping() { return mapping; } public void setMapping(Mapping mapping) { this.mapping = mapping; } public MappingProvider getMappingProvider() { return mappingProvider; } public void setMappingProvider(MappingProvider mappingProvider) { this.mappingProvider = mappingProvider; } protected Mapping mapping; protected MappingProvider mappingProvider; protected ByteArrayResource xsdResource; }