List of usage examples for org.apache.commons.digester Digester getDocumentLocator
public Locator getDocumentLocator()
From source file:ca.sqlpower.architect.ProjectLoader.java
/** * Loads the project data from the given input stream. * <p>/*from ww w .jav a 2 s . c om*/ * Note: the input stream is always closed afterwards. * * @param in * Used to load in the project data, must support mark. * @param dataSources * Collection of the data sources used in the project */ public void load(InputStream in, DataSourceCollection<? extends SPDataSource> dataSources, ArchitectSession messageDelegate) throws IOException, SQLObjectException { UnclosableInputStream uin = new UnclosableInputStream(in); siblingSession = messageDelegate; try { dbcsLoadIdMap = new HashMap<String, JDBCDataSource>(); sqlObjectLoadIdMap = new HashMap<String, SQLObject>(); Digester digester = null; // use digester to read from file try { digester = setupDigester(); digester.parse(uin); } catch (SAXException ex) { //The digester likes to wrap the cancelled exception in a SAXException. if (ex.getException() instanceof DigesterCancelledException) { //Digeseter was cancelled by the user. Do not load anything. throw new RuntimeException(new InterruptedIOException("progress")); } logger.error("SAX Exception in project file parse!", ex); String message; if (digester == null) { message = "Couldn't create an XML parser"; } else { message = "There is an XML parsing error in project file at Line:" + digester.getDocumentLocator().getLineNumber() + " Column:" + digester.getDocumentLocator().getColumnNumber(); } throw new SQLObjectException(message, ex); } catch (IOException ex) { logger.error("IO Exception in project file parse!", ex); throw new SQLObjectException("There was an I/O error while reading the file", ex); } catch (Exception ex) { logger.error("General Exception in project file parse!", ex); throw new SQLObjectException("Unexpected Exception", ex); } SQLObject dbConnectionContainer = ((SQLObject) getSession().getRootObject()); // hook up data source parent types for (SQLDatabase db : dbConnectionContainer.getChildren(SQLDatabase.class)) { JDBCDataSource ds = db.getDataSource(); String parentTypeId = ds.getPropertiesMap().get(JDBCDataSource.DBCS_CONNECTION_TYPE); if (parentTypeId != null) { for (JDBCDataSourceType dstype : dataSources.getDataSourceTypes()) { if (dstype.getName().equals(parentTypeId)) { ds.setParentType(dstype); // TODO unit test that this works } } if (ds.getParentType() == null) { logger.error("Data Source \"" + ds.getName() + "\" has type \"" + parentTypeId + "\", which is not configured in the user prefs."); // TODO either reconstruct the parent type, or bring this problem to the attention of the user. // TODO test this } else { // TODO test that the referenced parent type is properly configured (has a driver, etc) // TODO test for this behaviour } } } /* * for backward compatibilty, in the old project file, we have * primaryKeyName in the table attrbute, but nothing * in the sqlIndex that indicates primary key index, * so, we have to set the index as primary key index * if the index name == table.primaryKeyName after load the project, * table.primaryKeyName is save in the map now, not in the table object */ for (SQLTable table : (List<SQLTable>) getSession().getTargetDatabase().getTables()) { if (logger.isDebugEnabled()) { if (!table.isPopulated()) { logger.debug("Table [" + table.getName() + "] not populated"); } else { logger.debug( "Table [" + table.getName() + "] index folder contents: " + table.getIndices()); } } if (table.getPrimaryKeyIndex() == null) { logger.debug("primary key index is null in table: " + table); logger.debug("number of children found in indices folder: " + table.getIndices().size()); for (SQLIndex index : table.getIndices()) { if (sqlObjectLoadIdMap.get(table.getName() + "." + index.getName()) != null) { table.getPrimaryKeyIndex().updateToMatch(index); break; } } } logger.debug("Table [" + table.getName() + "]2 index folder contents: " + table.getIndices()); logger.debug("Table [" + table.getName() + "]3 index folder contents: " + table.getIndices()); if (logger.isDebugEnabled()) { if (!table.isPopulated()) { logger.debug("Table [" + table.getName() + "] not populated"); } else { logger.debug("Table [" + table.getName() + "] index folder contents: " + table.getIndices().size()); } } } /* * In old versions of the architect, user defined types weren't * available, so all columns stored their type as a JDBC type code. * For all columns in the playpen, we need to hook up upstream user * defined types. */ ListMultimap<String, SQLColumn> columns = ArrayListMultimap.create(); for (SQLTable table : getSession().getTargetDatabase().getTables()) { for (SQLColumn column : table.getChildren(SQLColumn.class)) { SQLColumn sourceColumn = column.getSourceColumn(); if (sourceColumn != null && sourceColumn.getPlatform() != null) { columns.put(column.getSourceColumn().getPlatform(), column); } else { columns.put(SQLTypePhysicalPropertiesProvider.GENERIC_PLATFORM, column); } } } for (String platform : columns.keySet()) { SQLColumn.assignTypes(columns.get(platform), dataSources, platform, new DefaultUserPrompterFactory()); } setModified(false); } finally { uin.forceClose(); } }