001/* 002 * HA-JDBC: High-Availability JDBC 003 * Copyright (C) 2012 Paul Ferraro 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Lesser General Public License as published by 007 * the Free Software Foundation, either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018package net.sf.hajdbc.xml; 019 020import java.io.File; 021import javax.xml.bind.JAXBContext; 022import javax.xml.bind.SchemaOutputResolver; 023import javax.xml.transform.Result; 024import javax.xml.transform.stream.StreamResult; 025 026public class SchemaGenerator 027{ 028 public static final String NAMESPACE = "urn:ha-jdbc:cluster:3.0"; 029 030 public static void main(String... args) throws Throwable 031 { 032 try 033 { 034 assert (args.length == 3) : String.format("Usage: java %s <base-class-name> <base-directory> <filename>", SchemaGenerator.class.getName()); 035 036 String baseClassName = args[0]; 037 String baseDirectoryName = args[1]; 038 String fileName = args[2]; 039 040 Class<?> baseClass = SchemaGenerator.class.getClassLoader().loadClass(baseClassName); 041 File baseDirectory = new File(baseDirectoryName); 042 043 final File file = new File(baseDirectory, fileName); 044 045 SchemaOutputResolver resolver = new SchemaOutputResolver() 046 { 047 @Override 048 public Result createOutput(String namespaceUri, String suggestedFileName) 049 { 050 return new StreamResult(file); 051 } 052 }; 053 054 System.out.println(String.format("Generating schema to %s", file.getPath())); 055 056 JAXBContext.newInstance(baseClass).generateSchema(resolver); 057 } 058 catch (Throwable e) 059 { 060 e.printStackTrace(System.err); 061 throw e; 062 } 063 } 064}