IIRC, there are several "TODO" comments in the code about validation
and about proper exception handling - this may be a new one of those
issues.  (Yesterday, for example, I was trying to understand
Composer.java, which has one of those.)


On Nov 22, 9:58 am, Tad Glines <[email protected]> wrote:
> Actually, on furthor inspection of the code I see that
> BootstrapDocument is already using the DocOpValidator.
>
> So the code is simplified to:
> BootstrapDocument bdoc = new BootstrapDocument();
> DocOpBuilder docOp = new DocOpBuilder();
> docOp.characters("ABCDEF");
> bdoc.consume(docOp.build());
>
> docOp = new DocOpBuilder();
> docOp.retain(1);
> docOp.deleteCharacters("B");
> docOp.retain(4);
> BufferedDocOp op1 = docOp.build();
>
> docOp = new DocOpBuilder();
> docOp.retain(2);
> docOp.deleteCharacters("C");
> docOp.retain(3);
> BufferedDocOp op2 = docOp.build();
>
> // This call will succeed.
> bdoc.consume(op1);
>
> // This call will throw an exception
> bdoc.consume(op2);
>
> The text of the thrown exception should be this:
> "ViolationCollector[3: invalid operation: attempt to delete character
> C when the actual character is D at original document position 2 /
> resulting document position 2]"
>
>
>
> On Sun, Nov 22, 2009 at 9:51 AM, Tad Glines <[email protected]> wrote:
> > OK, I see now. If I use the DocOpValidator, I get a very detailed
> > error description.
>
> > For those that may be interested, here is an example that shows how to
> > use the DocOpValidator:
>
> > BootstrapDocument bdoc = new BootstrapDocument();
> > DocOpBuilder docOp = new DocOpBuilder();
> > docOp.characters("ABCDEF");
> > bdoc.consume(docOp.build());
>
> > docOp = new DocOpBuilder();
> > docOp.retain(1);
> > docOp.deleteCharacters("B");
> > docOp.retain(4);
> > BufferedDocOp op1 = docOp.build();
>
> > docOp = new DocOpBuilder();
> > docOp.retain(2);
> > docOp.deleteCharacters("C");
> > docOp.retain(3);
> > BufferedDocOp op2 = docOp.build();
>
> > DocOpAutomaton.ViolationCollector vcol = new
> > DocOpAutomaton.ViolationCollector();
> > DocOpAutomaton.ValidationResult vres = DocOpValidator.validate(vcol,
> > DocumentSchema.NO_SCHEMA_CONSTRAINTS, bdoc, op1);
> > if (!vres.isValid()) {
> >  System.out.println(vcol.toString());
> >  System.exit(1);
> > }
>
> > bdoc.consume(op1);
>
> > vcol = new DocOpAutomaton.ViolationCollector();
> > vres = DocOpValidator.validate(vcol,
> > DocumentSchema.NO_SCHEMA_CONSTRAINTS, bdoc, op2);
> > if (!vres.isValid()) {
> >  System.out.println(vcol.toString());
> >  System.exit(1);
> > }
>
> > bdoc.consume(op2);
>
> > On Sun, Nov 22, 2009 at 6:38 AM, Alexandre Mah <[email protected]> wrote:
>
> >> Yes.  The composition and transform algorithms currently don't guard
> >> against their inputs being nonsensical operations.  When the
> >> composition algorithm was written, we were for the most part only
> >> using composition in places where the operations were already expected
> >> to be valid, so we didn't ascribe a high priority to implementing
> >> proper checking within the composition algorithm itself since it would
> >> only have increased the cost of composition by doing redundant checks
> >> (but we did regardless leave a TODO to put in proper validity checking
> >> since it seemed like a good idea to have it eventually anyway).
>
> >> Best regards,
> >> Alex
>
> >> On 11/22/09, Tad Glines <[email protected]> wrote:
>
> >>> I was doing some testing to validate my understanding of composition
> >>> when I ran into a case that (I assumed) shouldn't succeed and should
> >>> instead throw an exception.
>
> >>> Here's the code:
> >>> DocOpBuilder docOp = new DocOpBuilder();
> >>> docOp.characters("ABCDEF");
> >>> BufferedDocOp doc = docOp.build();
>
> >>> System.out.println(doc.toString()); // Prints: ++"ABCDEF";
>
> >>> DocOpCollector col = new DocOpCollector();
>
> >>> docOp = new DocOpBuilder();
> >>> docOp.retain(1);
> >>> docOp.deleteCharacters("B");
> >>> docOp.retain(4);
> >>> col.add(docOp.build());
>
> >>> docOp = new DocOpBuilder();
> >>> docOp.retain(2);
> >>> docOp.deleteCharacters("C");
> >>> docOp.retain(3);
> >>> col.add(docOp.build());
>
> >>> doc = Composer.compose(doc, col.composeAll());
> >>> System.out.println(doc.toString()); // Prints: ++"ACEF";
>
> >>> When I wrote this I assumed that it would fail on the second to last
> >>> line, but instead it succeeds.
>
> >>> Does this just represent one of the cases where stricter operation
> >>> validation hasn't been implemented yet?
> >>> Similar naive (un-transformed) compositions involving
> >>> deleteElementStart() and updateAttributes() do fail with an exception.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Wave 
Protocol" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/wave-protocol?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to