Package org.waveprotocol.wave.model.operation

Examples of org.waveprotocol.wave.model.operation.OperationException


  public static DocOp composeUnchecked(DocOp op1, DocOp op2)
      throws OperationException {
    try {
      return new Composer(new UncheckedDocOpBuffer()).composeOperations(op1, op2);
    } catch (ComposeException e) {
      throw new OperationException(e.getMessage());
    }
  }
View Full Code Here


      for (WaveletOperation s : serverOps) {
        OperationPair<WaveletOperation> pair;
        try {
          pair = Transform.transform(c, s);
        } catch (TransformException e) {
          throw new OperationException(e);
        }
        c = pair.clientOp();
      }
      transformedClientOps.add(c);
    }
View Full Code Here

    checkConsistent();

    ViolationCollector v = new ViolationCollector();
    DocOpValidator.validate(v, schemaConstraints, this, m);
    if (!v.isValid()) {
      throw new OperationException("Validation failed: " + v);
    }

    inconsistent = true;

    annotationUpdates = AnnotationsUpdateImpl.EMPTY_MAP;
    final ListIterator<Item> iterator = items.listIterator();
    try {
      // In theory, the above call to the validator makes the error checking in
      // this DocOpCursor redundant.  We check for errors anyway in case the
      // validator is incorrect.
      m.apply(new DocOpCursor() {

        Item current = null;

        AnnotationMap inherited = AnnotationMapImpl.EMPTY_MAP;

        private AnnotationMap insertionAnnotations() {
          return inherited.updateWith(annotationUpdates);
        }

        @Override
        public void annotationBoundary(AnnotationBoundaryMap map) {
          annotationUpdates = annotationUpdates.composeWith(map);
          for (int i = 0; i < map.changeSize(); i++) {
            knownAnnotationKeys.add(map.getChangeKey(i));
          }
        }

        @Override
        public void characters(String s) {
          for (int i = 0; i < s.length(); i++) {
            iterator.add(new CharacterItem(s.charAt(i), insertionAnnotations()));
          }
        }

        @Override
        public void elementStart(String type, Attributes attrs) {
          iterator.add(new ElementStartItem(type, attrs, insertionAnnotations()));
        }

        @Override
        public void elementEnd() {
          iterator.add(new ElementEndItem(insertionAnnotations()));
        }

        @Override
        public void deleteCharacters(String s) {
          for (int i = 0; i < s.length(); i++) {
            CharacterItem item = nextCharacter();
            if (s.charAt(i) != item.character) {
              throw new OpCursorException("Mismatched deleted characters: " +
                  s.charAt(i) + " vs " + item.character);
            }
            inherited = item.getAnnotations();
            iterator.remove();
          }
        }

        @Override
        public void deleteElementEnd() {
          ElementEndItem item = nextElementEnd();
          inherited = item.getAnnotations();
          iterator.remove();
        }

        @Override
        public void deleteElementStart(String tag, Attributes attrs) {
          ElementStartItem item = nextElementStart();
          inherited = item.getAnnotations();
          iterator.remove();
        }

        @Override
        public void retain(int distance) {
          for (int i = 0; i < distance; i++) {
            inheritAndAnnotate(next());
          }
        }

        @Override
        public void replaceAttributes(Attributes oldAttrs, Attributes newAttrs) {
          ElementStartItem item = nextElementStart();
          item.replaceAttributes(newAttrs);
          inheritAndAnnotate(item);
        }

        @Override
        public void updateAttributes(AttributesUpdate attrUpdate) {
          ElementStartItem item = nextElementStart();
          item.updateAttributes(attrUpdate);
          inheritAndAnnotate(item);
        }

        private void inheritAndAnnotate(Item item) {
          inherited = item.getAnnotations();
          item.updateAnnotations(annotationUpdates);
        }

        Item next() {
          if (!iterator.hasNext()) {
            throw new OpCursorException("Action past end of document, of size: " + length());
          }
          current = iterator.next();
          return current;
        }

        ElementStartItem nextElementStart() {
          try {
            return (ElementStartItem) next();
          } catch (ClassCastException e) {
            throw new OpCursorException("Not at an element start, at: " + current);
          }
        }

        ElementEndItem nextElementEnd() {
          try {
            return (ElementEndItem) next();
          } catch (ClassCastException e) {
            throw new OpCursorException("Not at an element end, at: " + current);
          }
        }

        CharacterItem nextCharacter() {
          try {
            return (CharacterItem) next();
          } catch (ClassCastException e) {
            throw new OpCursorException("Not at a character, at: " + current);
          }
        }
      });
      if (iterator.hasNext()) {
        int remainingItems = 0;
        while (iterator.hasNext()) {
          remainingItems++;
          iterator.next();
        }
        throw new OperationException("Missing retain to end of document (" +
            remainingItems + " items)");
      }
    } catch (OpCursorException e) {
      throw new OperationException(e);
    }

    if (annotationUpdates.changeSize() != 0) {
      throw new OperationException("Unended annotations at end of operation: " + annotationUpdates);
    }

    resetReadState();

    inconsistent = false;
View Full Code Here

        opsApplied++;
      }
    } catch (OperationException e) {
      // Deltas are atomic, so roll back all operations that were successful
      rollbackWaveletOperations(wavelet, reverseOps);
      throw new OperationException("Only applied " + opsApplied + " of "
          + delta.size() + " operations at version " + wavelet.getVersion()
          + ", rolling back, failed op was " + lastOp, e);
    }
  }
View Full Code Here

          try {
            WaveletDeltaRecord applicationResult = transformAndApplyRemoteDelta(appliedDelta);
            long opsApplied = applicationResult.getResultingVersion().getVersion()
                    - expectedVersion.getVersion();
            if (opsApplied != appliedDelta.getMessage().getOperationsApplied()) {
              throw new OperationException("Operations applied here do not match the authoritative"
                  + " server claim (got " + opsApplied + ", expected "
                  + appliedDelta.getMessage().getOperationsApplied() + ".");
            }
            // Add transformed result to return list.
            resultingDeltas.add(applicationResult);
View Full Code Here

   */
  private void dealWithBadOp(
      boolean isLocal, Object operation, Exception e, boolean probableCorruption) {

    // Project the exception onto one of its two possible states.
    OperationException oe;
    RuntimeException re;
    if (e instanceof OperationException) {
      oe = (OperationException) e;
      re = null;
    } else {
      oe = null;
      re = (RuntimeException) e;
    }
    String msg =  (probableCorruption ? "DEATH: " : "")
        + "Invalid " + (isLocal ? "LOCAL" : "REMOTE") + " operation: " + operation
        + (oe != null && oe.hasViolationsInformation()
              ? " Violation: " + oe.getViolations().firstDescription()
              : " <No violation information!> ")
        + "Exception: " + e
        + " IndexedDoc: " + indexedDoc.toString();
    EditorStaticDeps.logger.error().logPlainText(msg);

    RuntimeException death;
    if (oe == null) {
      death = re;
    } else if (isLocal && !probableCorruption) {
      assert oe.hasViolationsInformation();
      if (oe.getViolations().getValidationResult().isInvalidSchema()) {
        death = new SchemaViolatingLocalOperationException(oe.getViolations());
      } else {
        death = new BadOpLocalOperationException(oe.getViolations());
      }
    } else {
      death = new OperationRuntimeException("Invalid for current document", oe);
    }

View Full Code Here

    beginChange();

    try {
      op.apply(invertibleCursor);
    } catch (OpCursorException e) {
      throw new OperationException(e.getMessage(), e);
    }

    endChange();
  }
View Full Code Here

    if (!DocOpValidator.validate(null, schemaConstraints, autoDoc, op).isValid()) {
      // Validate again to collect diagnostics (more expensive)
      ViolationCollector vc = new ViolationCollector();
      DocOpValidator.validate(vc, schemaConstraints, autoDoc, op);

      throw new OperationException(vc);
    }
  }
View Full Code Here

    nindoCursor.begin2();

    try {
      op.apply(nindoCursor);
    } catch (OpCursorException e) {
      throw new OperationException(e.getMessage(), e);
    }

    return nindoCursor.finish2();
  }
View Full Code Here

  @Override
  public void maybeThrowOperationExceptionFor(Nindo op) throws OperationException {
    ViolationCollector vc = NindoValidator.validate(this, op, schemaConstraints);
    if (!vc.isValid()) {
      // TODO(danilatos): reconcile the two validation methods
      throw new OperationException(vc);
    }
  }
View Full Code Here

TOP

Related Classes of org.waveprotocol.wave.model.operation.OperationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.