* @param projectFileURL project file URL/path
* @return database for project or null
*/
private DatabaseType getProjectDatabase(final VoltCompilerReader projectReader)
{
DatabaseType database = null;
m_currentFilename = (projectReader != null ? projectReader.getName() : "null");
if (projectReader != null) {
try {
JAXBContext jc = JAXBContext.newInstance("org.voltdb.compiler.projectfile");
// This schema shot the sheriff.
SchemaFactory sf = SchemaFactory.newInstance(
javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = sf.newSchema(this.getClass().getResource("ProjectFileSchema.xsd"));
Unmarshaller unmarshaller = jc.createUnmarshaller();
// But did not shoot unmarshaller!
unmarshaller.setSchema(schema);
@SuppressWarnings("unchecked")
JAXBElement<ProjectType> result = (JAXBElement<ProjectType>) unmarshaller.unmarshal(projectReader);
ProjectType project = result.getValue();
database = project.getDatabase();
}
catch (JAXBException e) {
// Convert some linked exceptions to more friendly errors.
if (e.getLinkedException() instanceof java.io.FileNotFoundException) {
addErr(e.getLinkedException().getMessage());
compilerLog.error(e.getLinkedException().getMessage());
}
else {
DeprecatedProjectElement deprecated = DeprecatedProjectElement.valueOf(e);
if( deprecated != null) {
addErr("Found deprecated XML element \"" + deprecated.name() + "\" in project.xml file, "
+ deprecated.getSuggestion());
addErr("Error schema validating project.xml file. " + e.getLinkedException().getMessage());
compilerLog.error("Found deprecated XML element \"" + deprecated.name() + "\" in project.xml file");
compilerLog.error(e.getMessage());
compilerLog.error(projectReader.getPath());
}
else if (e.getLinkedException() instanceof org.xml.sax.SAXParseException) {
addErr("Error schema validating project.xml file. " + e.getLinkedException().getMessage());
compilerLog.error("Error schema validating project.xml file: " + e.getLinkedException().getMessage());
compilerLog.error(e.getMessage());
compilerLog.error(projectReader.getPath());
}
else {
throw new RuntimeException(e);
}
}
}
catch (SAXException e) {
addErr("Error schema validating project.xml file. " + e.getMessage());
compilerLog.error("Error schema validating project.xml file. " + e.getMessage());
}
}
else {
// No project.xml - create a stub object.
database = new DatabaseType();
}
return database;
}