示例#1
0
 private ValidationResult AddViolation(ViolationCollector a, OperationInvalid v)
 {
     if (a != null)
     {
         a.Add(v);
     }
     return v.ValidationResult;
 }
示例#2
0
 private ValidationResult AddViolation(ViolationCollector a, SchemaViolation v)
 {
     if (a != null)
     {
         a.Add(v);
     }
     return v.ValidationResult;
 }
示例#3
0
 /// <summary>
 /// Returns whether op is well-formed.
 /// 
 /// Any violations recorded in the output <paramref name="collector"/> that are not well-formedness 
 /// violations are meaningless.
 /// </summary>
 public static bool IsWellformed(ViolationCollector collector, IDocOp docOp)
 {
     if (docOp is IBufferedDocOp)
     {
         return IsWellformed(collector, (BufferedDocOp) docOp);
     }
     return IsWellformedRaw(collector, docOp);
 }
示例#4
0
        /// <summary>
        /// Same as <see cref="IsWellformed"/>, but without the fast path for <see cref="BufferedDocOp"/>
        /// </summary>
        private static bool IsWellformedRaw(ViolationCollector collector, IDocOp docOp)
        {
            // We validate the operation against the empty document.  It will likely
            // be invalid; however, we ignore the validity aspect anyway since we
            // only care about well-formedness.
            var validationResult =
                Validate(collector, DocumentSchema.NoSchemaConstraints, DocOpAutomaton.EmptyDocument, docOp);

            return validationResult != ValidationResult.IllFormed;
        }
示例#5
0
        public ValidationResult CheckCharacters(string characters, ViolationCollector collector)
        {
            if (characters == null) return NullCharacters(collector);
            if (string.IsNullOrEmpty(characters)) return EmptyCharacters(collector);
            // Todo: implement other checks
            
            if (!DeletionStackIsEmpty()) { return InsertInsideDelete(collector); }

            // Todo: implement other checks
            throw new NotImplementedException();

            return Valid();
        }
示例#6
0
        /// <summary>
        /// Same as <see cref="IsWellformed" />, but with a fast path for already-validated instances of <see cref="BufferedDocOp"/>
        /// </summary>
        private static bool IsWellformed(ViolationCollector collector, BufferedDocOp docOp)
        {
            if (docOp.IsKnownToBeWellformed)
            {
                return true;
            }
            
            if (IsWellformedRaw(collector, docOp))
            {
                docOp.IsKnownToBeWellformed = true;
                return true;
            }

            return false;
        }
示例#7
0
        private static ValidationResult Validate(ViolationCollector collector, IDocumentSchema schema, IAutomatonDocument document, IDocOp docOp)
        {
            if (schema == null)
            {
                schema = DocumentSchema.NoSchemaConstraints;
            }

            var automation = new DocOpAutomaton(document, schema);
            var accu = new ValidationResult[] { ValidationResult.Valid };
            try
            {
                docOp.Apply(new ValidationDocOpCursor(collector, automation, accu));
            }
            catch (IllFormedException illFormed)
            {
                return ValidationResult.IllFormed;
            }

            accu[0] = accu[0].MergeWith(automation.CheckFinish(collector));
            return accu[0];
        }
示例#8
0
 private ValidationResult MismatchedStartAnnotation(ViolationCollector v, String key)
 {
     return AddViolation(v, IllFormedOperation("annotation of key " + key + " starts but never ends"));
 }
示例#9
0
 private ValidationResult NullTag(ViolationCollector collector)
 {
     return AddViolation(collector, IllFormedOperation("element type is null"));
 }
示例#10
0
 private ValidationResult EmptyCharacters(ViolationCollector collector)
 {
     return AddViolation(collector, IllFormedOperation("characters is empty"));
 }
示例#11
0
 /// <summary>
 /// Checks that a buffered doc op is well-formed.
 /// </summary>
 /// <param name="value">value op to check</param>
 /// <exception cref="InvalidOperationException">if the op is ill-formed</exception>
 private static void CheckWellformedness(IBufferedDocOp value)
 {
     if (!DocOpValidator.IsWellformed(null, value))
     {
         // Check again, collecting violations this time.
         var violationCollector = new ViolationCollector();
         DocOpValidator.IsWellformed(violationCollector, value);
         Preconditions.IllegalState(
             string.Format("Attempt to build ill-formed operation ({0}): {1}", violationCollector, value));
     }
 }
示例#12
0
 private ValidationResult MismatchedEndAnnotation(ViolationCollector v, String key)
 {
     return AddViolation(v, IllFormedOperation("annotation of key " + key + " ends without having started"));
 }
示例#13
0
 private ValidationResult NullCharacters(ViolationCollector collector)
 {
     return AddViolation(collector, IllFormedOperation("characters is null"));
 }
示例#14
0
 private ValidationResult RetainInsideInsertOrDelete(ViolationCollector v)
 {
     return AddViolation(v, IllFormedOperation("retain inside insert or delete"));
 }
示例#15
0
 private ValidationResult MissingRetainToEnd(ViolationCollector v, int expectedLength, int actualLength)
 {
     return AddViolation(v, InvalidOperation("operation shorter than document, document length "
                                             + expectedLength + ", length of input of operation " + actualLength));
 }
示例#16
0
 private ValidationResult MismatchedDeleteStart(ViolationCollector v)
 {
     return AddViolation(v, IllFormedOperation("deleteElementStart with no matching deleteElementEnd"));
 }
示例#17
0
 internal ValidationResult NotClosed(DocOpAutomaton automaton, ViolationCollector collector)
 {
     return automaton.MismatchedInsertStart(collector);
 }
示例#18
0
 public ValidationResult CheckRetain(int itemCount, ViolationCollector v)
 {
     // well-formedness
     if (itemCount <= 0)
     {
         return RetainItemCountNotPositive(v);
     }
     if (!InsertionStackIsEmpty())
     {
         return RetainInsideInsertOrDelete(v);
     }
     if (!DeletionStackIsEmpty())
     {
         return RetainInsideInsertOrDelete(v);
     }
     //// validity
     if (!CanRetain(itemCount))
     {
         return RetainPastEnd(v, _document.Length(), itemCount);
     }
     return CheckAnnotationsForRetain(v, itemCount);
 }
示例#19
0
        public ValidationResult CheckElementStart(string type, IAttributes attributes, ViolationCollector collector)
        {
            // Well-formedness
            if (type == null)
            {
                return NullTag(collector);
            }

            if (!DeletionStackIsEmpty()) { return InsertInsideDelete(collector); }

            throw new NotImplementedException();
        }
示例#20
0
        /// <summary>
        ///     Checks whether the automaton is in an accepting state, i.e., whether the
        ///     operation would be valid if no further operation components follow.
        /// </summary>
        public ValidationResult CheckFinish(ViolationCollector v)
        {
            // well-formedness
            if (!InsertionStackIsEmpty())
            {
                foreach (InsertStart e in _insertionStack)
                {
                    return e.NotClosed(this, v);
                }
            }
            if (!DeletionStackIsEmpty())
            {
                return MismatchedDeleteStart(v);
            }
            if (_annotationsUpdate.ChangeSize() > 0)
            {
                return MismatchedStartAnnotation(v, _annotationsUpdate.GetChangeKey(0));
            }

            // validity
            if (_effectivePos != _document.Length())
            {
                return MissingRetainToEnd(v, _document.Length(), _effectivePos);
            }
            return Valid();
        }
示例#21
0
 private ValidationResult RetainPastEnd(ViolationCollector collector, int expectedLength, int retainItemCount)
 {
     return AddViolation(collector,
         InvalidOperation("retain past end of document, document length " + expectedLength +
                          ", retain item count " + retainItemCount));
 }
示例#22
0
 private ValidationResult CheckAnnotationsForRetain(ViolationCollector collector, int itemCount)
 {
     for (int i = 0; i < _annotationsUpdate.ChangeSize(); i++)
     {
         throw new NotImplementedException();
         //var key = _annotationsUpdate.getChangeKey(i);
         //var oldValue = _annotationsUpdate.getOldValue(i);
         //var firstChange = _document.FirstAnnotationChange(_effectivePos, _effectivePos + itemCount, key, oldValue);
         //if (firstChange != -1)
         //{
         //    return OldAnnotationsDifferFromDocument(collector, key, oldValue,
         //        _document.GetAnnotation(firstChange, key));
         //}
     }
     return Valid();
 }
示例#23
0
 private ValidationResult InsertInsideDelete(ViolationCollector v)
 {
     return AddViolation(v, IllFormedOperation("insertion inside deletion"));
 }
示例#24
0
 private ValidationResult RetainItemCountNotPositive(ViolationCollector v)
 {
     return AddViolation(v, IllFormedOperation("retain item count not positive"));
 }