@Override protected void parseEndElement(String uri, String localName, String qName) throws Exception { // </Sapelli-Collector-Project>, or </ExCiteS-Collector-Project> (for backwards compatibility) if (qName.equals(TAG_PROJECT) || qName.equals(TAG_PROJECT_V1X)) { clearSubtreeParsers(); if (project.getForms().size() == 0) throw new SAXException("A project such have at least 1 form!"); else { // Resolve startForm Form startForm = project.getForm( startFormID); // will return null if startFormID is null or there is no form with // that name, uses equalsIgnoreCase() if (startForm != null) project.setStartForm(startForm); // else: first form of project will remain the startForm // Resolve form relationships: if (relationshipToFormID != null) for (Entry<Relationship, String> entry : relationshipToFormID.entrySet()) { Relationship rel = entry.getKey(); Form relatedForm = project.getForm(entry.getValue()); // uses equalsIgnoreCase() if (relatedForm == null) throw new SAXException( "Relationship \"" + rel.id + "\" in form \"" + rel.form.id + "\" refers to unknown related form \"" + entry.getValue() + "\"."); rel.setRelatedForm( relatedForm); // will trigger initialisation of Schema of relatedForm (this should // not be a problem, it will not be done again below) } // Initialise forms... for (Form form : project.getForms()) { try { // generates Schema, Columns & ValueDictionaries: form.initialiseStorage( fsiProvider != null ? fsiProvider.getByPassableFieldIDs(form) : null); // Note: fsiProvider will be null if this project is loaded/parsed for // the first time } catch (ModelFullException mfe) { throw new SAXException( "This project contains more data-producing Forms than allowed (maximum: " + Project.MAX_RECORD_PRODUCING_FORMS + ")."); } catch (DuplicateColumnException dce) { throw new SAXException( "Duplicate column name (\"" + dce.getColumnName() + "\") in schema for form \"" + form.id + "\"."); } addWarnings(form.getWarnings()); // !!! form.clearWarnings(); } // Seal project model: project.getModel().seal(); // Resolve relationship constraints: if (relationshipToConstraints != null) for (Entry<Relationship, List<ConstraintDescription>> entry : relationshipToConstraints.entrySet()) for (ConstraintDescription constrDesc : entry.getValue()) try { Relationship rel = entry.getKey(); rel.addConstraint(constrDesc.resolve(rel.getRelatedForm())); } catch (Exception e) { throw new Exception( "Error upon resolving constraint on Relationship \"" + entry.getKey().id + "\"", e); } } } }