@Override
RandomizerOperationComponent generate(final DocOpAutomaton a, boolean valid, Stage stage) {
if (stage != Stage.S1_UNRESTRICTED) {
return null;
}
final Attributes oldAttrs = a.currentElementStartAttributes();
if (oldAttrs == null) {
if (valid) {
return null;
}
}
if (!valid) {
// TODO: bring this back.
// several cases: invalid because of wrong old attributes, or invalid
// because of schema violation of new attributes, or because no
// element start here
throw new RuntimeException("Not implemented");
}
AttributesUpdate u = generateRandomAttributesUpdate(valid,
oldAttrs, new AttributesUpdateChecker() {
@Override
public ValidationResult check(AttributesUpdate u) {
return a.checkReplaceAttributes(oldAttrs, oldAttrs.updateWith(u), null);
}
});
if (u == null) {
return null;
}
final Attributes newAttrs = oldAttrs.updateWith(u);
return new RandomizerOperationComponent() {
@Override
public void apply(DocOpAutomaton a) {
a.doReplaceAttributes(oldAttrs, newAttrs);
}