コード例 #1
0
ファイル: ProjectParser.java プロジェクト: periclesjr/Sapelli
    public Constraint resolve(Form form)
        throws SAXException, IllegalArgumentException, NullPointerException, ParseException {
      // Form checks:
      if (form == null)
        throw new NullPointerException("Non-null form is needed to resolve Constraint");
      if (!form.isProducesRecords()) {
        addWarning(
            "Cannot impose constraint on records of form \""
                + form.id
                + "\" because it does not produce data records.");
        return null;
      }

      // Get column:
      @SuppressWarnings("unchecked")
      ColumnPointer<ComparableColumn<?>> columnPointer =
          (ColumnPointer<ComparableColumn<?>>)
              ColumnPointer.ByName(
                  form.getSchema(),
                  columnName,
                  true,
                  true); // will throw IllegalArgumentException if no such column is found (but name
      // sanitation will be used first)

      // Column check:
      if (!(columnPointer.getColumn() instanceof ComparableColumn<?>))
        throw new SAXException(
            "Constraint refers to a column (\"" + columnName + "\") which is not comparable.");

      // Return RuleConstraint:
      return RuleConstraint.FromString(columnPointer, comparison, valueString);
    }
コード例 #2
0
 /* (non-Javadoc)
  * @see uk.ac.ucl.excites.sapelli.collector.db.ProjectStore#doAdd(uk.ac.ucl.excites.sapelli.collector.model.Project)
  */
 @Override
 protected void doAdd(Project project)
     throws ProjectIdentificationClashException, ProjectSignatureClashException,
         IllegalStateException {
   try { // Note: we use insert() instead of store() to not allow updates
     // Store project record:
     rsWrapper.recordStore.insert(getProjectRecord(project));
     // Store an FSI record for each record-producing form:
     for (Form form : project.getForms())
       if (form.isProducesRecords()) rsWrapper.recordStore.insert(getFSIRecord(form));
     // Cache the project:
     cacheProject(project);
   } catch (DBPrimaryKeyException dbPKE) {
     throw new ProjectIdentificationClashException(project, false);
   } catch (DBConstraintException dbCE) {
     throw new ProjectSignatureClashException(project);
   } catch (DBException e) {
     e.printStackTrace(System.err);
     throw new IllegalStateException(e);
   }
 }