use of org.mybatis.generator.exception.XMLParserException in project generator by mybatis.
the class MyBatisGeneratorConfigurationParser method parseProperties.
protected void parseProperties(Configuration configuration, Node node) throws XMLParserException {
Properties attributes = parseAttributes(node);
//$NON-NLS-1$
String resource = attributes.getProperty("resource");
//$NON-NLS-1$
String url = attributes.getProperty("url");
if (!stringHasValue(resource) && !stringHasValue(url)) {
//$NON-NLS-1$
throw new XMLParserException(getString("RuntimeError.14"));
}
if (stringHasValue(resource) && stringHasValue(url)) {
//$NON-NLS-1$
throw new XMLParserException(getString("RuntimeError.14"));
}
URL resourceUrl;
try {
if (stringHasValue(resource)) {
resourceUrl = ObjectFactory.getResource(resource);
if (resourceUrl == null) {
throw new XMLParserException(getString("RuntimeError.15", //$NON-NLS-1$
resource));
}
} else {
resourceUrl = new URL(url);
}
InputStream inputStream = resourceUrl.openConnection().getInputStream();
configurationProperties.load(inputStream);
inputStream.close();
} catch (IOException e) {
if (stringHasValue(resource)) {
throw new XMLParserException(getString("RuntimeError.16", //$NON-NLS-1$
resource));
} else {
throw new XMLParserException(getString("RuntimeError.17", //$NON-NLS-1$
url));
}
}
}
use of org.mybatis.generator.exception.XMLParserException in project jeesuite-libs by vakinge.
the class MyBatisGeneratorTool method main.
public static void main(String[] args) {
List<String> warnings = new ArrayList<String>();
String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
boolean overwrite = true;
File configFile = new File(path + "/../../src/test/resources/generator/generatorConfig.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = null;
try {
config = cp.parseConfiguration(configFile);
} catch (IOException e) {
e.printStackTrace();
} catch (XMLParserException e) {
e.printStackTrace();
}
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = null;
try {
myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
try {
myBatisGenerator.generate(null);
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of org.mybatis.generator.exception.XMLParserException in project generator by mybatis.
the class MyBatisGeneratorConfigurationParser method parseProperties.
protected void parseProperties(Node node) throws XMLParserException {
Properties attributes = parseAttributes(node);
// $NON-NLS-1$
String resource = attributes.getProperty("resource");
// $NON-NLS-1$
String url = attributes.getProperty("url");
if (!stringHasValue(resource) && !stringHasValue(url)) {
// $NON-NLS-1$
throw new XMLParserException(getString("RuntimeError.14"));
}
if (stringHasValue(resource) && stringHasValue(url)) {
// $NON-NLS-1$
throw new XMLParserException(getString("RuntimeError.14"));
}
URL resourceUrl;
try {
if (stringHasValue(resource)) {
resourceUrl = ObjectFactory.getResource(resource);
if (resourceUrl == null) {
throw new XMLParserException(getString("RuntimeError.15", // $NON-NLS-1$
resource));
}
} else {
resourceUrl = new URL(url);
}
InputStream inputStream = resourceUrl.openConnection().getInputStream();
configurationProperties.load(inputStream);
inputStream.close();
} catch (IOException e) {
if (stringHasValue(resource)) {
throw new XMLParserException(getString("RuntimeError.16", // $NON-NLS-1$
resource));
} else {
throw new XMLParserException(getString("RuntimeError.17", // $NON-NLS-1$
url));
}
}
}
use of org.mybatis.generator.exception.XMLParserException in project generator by mybatis.
the class ShellRunner method main.
public static void main(String[] args) {
if (args.length == 0) {
usage();
System.exit(0);
// only to satisfy compiler, never returns
return;
}
Map<String, String> arguments = parseCommandLine(args);
if (arguments.containsKey(HELP_1)) {
usage();
System.exit(0);
// only to satisfy compiler, never returns
return;
}
if (!arguments.containsKey(CONFIG_FILE)) {
// $NON-NLS-1$
writeLine(getString("RuntimeError.0"));
return;
}
List<String> warnings = new ArrayList<>();
String configfile = arguments.get(CONFIG_FILE);
File configurationFile = new File(configfile);
if (!configurationFile.exists()) {
// $NON-NLS-1$
writeLine(getString("RuntimeError.1", configfile));
return;
}
Set<String> fullyqualifiedTables = new HashSet<>();
if (arguments.containsKey(TABLES)) {
// $NON-NLS-1$
StringTokenizer st = new StringTokenizer(arguments.get(TABLES), ",");
while (st.hasMoreTokens()) {
String s = st.nextToken().trim();
if (s.length() > 0) {
fullyqualifiedTables.add(s);
}
}
}
Set<String> contexts = new HashSet<>();
if (arguments.containsKey(CONTEXT_IDS)) {
StringTokenizer st = new StringTokenizer(arguments.get(CONTEXT_IDS), // $NON-NLS-1$
",");
while (st.hasMoreTokens()) {
String s = st.nextToken().trim();
if (s.length() > 0) {
contexts.add(s);
}
}
}
try {
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configurationFile);
DefaultShellCallback shellCallback = new DefaultShellCallback(arguments.containsKey(OVERWRITE));
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
ProgressCallback progressCallback = arguments.containsKey(VERBOSE) ? new VerboseProgressCallback() : null;
myBatisGenerator.generate(progressCallback, contexts, fullyqualifiedTables);
} catch (XMLParserException e) {
// $NON-NLS-1$
writeLine(getString("Progress.3"));
writeLine();
for (String error : e.getErrors()) {
writeLine(error);
}
return;
} catch (SQLException | IOException e) {
e.printStackTrace(System.out);
return;
} catch (InvalidConfigurationException e) {
// $NON-NLS-1$
writeLine(getString("Progress.16"));
for (String error : e.getErrors()) {
writeLine(error);
}
return;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
for (String warning : warnings) {
writeLine(warning);
}
if (warnings.isEmpty()) {
// $NON-NLS-1$
writeLine(getString("Progress.4"));
} else {
writeLine();
// $NON-NLS-1$
writeLine(getString("Progress.5"));
}
}
use of org.mybatis.generator.exception.XMLParserException in project generator by mybatis.
the class RunGeneratorThread method run.
/*
* (non-Javadoc)
*
* @see org.eclipse.core.resources.IWorkspaceRunnable#run(org.eclipse.core.runtime.IProgressMonitor)
*/
public void run(IProgressMonitor monitor) throws CoreException {
SubMonitor subMonitor = SubMonitor.convert(monitor, 1000);
subMonitor.beginTask("Generating MyBatis/iBATIS Artifacts:", 1000);
setClassLoader();
try {
subMonitor.subTask("Parsing Configuration");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(inputFile.getLocation().toFile());
subMonitor.worked(50);
MyBatisGenerator mybatisGenerator = new MyBatisGenerator(config, new EclipseShellCallback(), warnings);
monitor.subTask("Generating Files from Database Tables");
SubMonitor spm = subMonitor.newChild(950);
mybatisGenerator.generate(new EclipseProgressCallback(spm));
} catch (InterruptedException e) {
throw new OperationCanceledException();
} catch (SQLException e) {
Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
Activator.getDefault().getLog().log(status);
throw new CoreException(status);
} catch (IOException e) {
Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
Activator.getDefault().getLog().log(status);
throw new CoreException(status);
} catch (XMLParserException e) {
List<String> errors = e.getErrors();
MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR, "XML Parser Errors\n See Details for more Information", null);
Iterator<String> iter = errors.iterator();
while (iter.hasNext()) {
Status message = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, iter.next(), null);
multiStatus.add(message);
}
throw new CoreException(multiStatus);
} catch (InvalidConfigurationException e) {
List<String> errors = e.getErrors();
MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR, "Invalid Configuration\n See Details for more Information", null);
Iterator<String> iter = errors.iterator();
while (iter.hasNext()) {
Status message = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, iter.next(), null);
multiStatus.add(message);
}
throw new CoreException(multiStatus);
} finally {
monitor.done();
restoreClassLoader();
}
}
Aggregations