use of io.apicurio.datamodels.core.models.ExtensibleNode in project apicurio-data-models by Apicurio.
the class DeleteAllExtensionsCommand method undo.
/**
* @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void undo(Document document) {
LoggerCompat.info("[DeleteAllExtensionsCommand] Reverting.");
if (this._oldExtensions.size() == 0) {
return;
}
ExtensibleNode parent = (ExtensibleNode) this._parentPath.resolve(document);
this._oldExtensions.forEach(oldExtension -> {
Extension extension = parent.createExtension();
ModelUtils.unmarshalExtension(oldExtension, extension);
parent.addExtension(extension.name, extension);
});
}
use of io.apicurio.datamodels.core.models.ExtensibleNode in project apicurio-data-models by Apicurio.
the class DeleteExtensionCommand method undo.
/**
* @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void undo(Document document) {
LoggerCompat.info("[DeleteExtensionCommand] Reverting.");
ExtensibleNode parent = (ExtensibleNode) this._parentPath.resolve(document);
if (this.isNullOrUndefined(parent)) {
return;
}
// Find any existing extension with this name
Extension extension = parent.getExtension(this._name);
if (this._hasOldValue && ModelUtils.isDefined(extension)) {
extension.value = this._oldValue;
}
if (this._hasOldValue && this.isNullOrUndefined(extension)) {
Extension ext = parent.createExtension();
ext.name = this._name;
ext.value = this._oldValue;
parent.addExtension(this._name, ext);
}
}
use of io.apicurio.datamodels.core.models.ExtensibleNode in project apicurio-data-models by Apicurio.
the class DeleteExtensionCommand method execute.
/**
* @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void execute(Document document) {
LoggerCompat.info("[DeleteExtensionCommand] Executing.");
this._oldValue = null;
this._hasOldValue = false;
ExtensibleNode parent = (ExtensibleNode) this._parentPath.resolve(document);
if (this.isNullOrUndefined(parent)) {
return;
}
// Find any existing extension with this name
Extension extension = parent.getExtension(this._name);
// If found, remove it.
if (ModelUtils.isDefined(extension)) {
this._hasOldValue = true;
this._oldValue = extension.value;
parent.removeExtension(this._name);
} else {
this._hasOldValue = false;
}
}
use of io.apicurio.datamodels.core.models.ExtensibleNode in project apicurio-data-models by Apicurio.
the class SetExtensionCommand method undo.
/**
* @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void undo(Document document) {
LoggerCompat.info("[SetExtensionCommand] Reverting.");
ExtensibleNode parent = (ExtensibleNode) this._parentPath.resolve(document);
if (this.isNullOrUndefined(parent)) {
return;
}
// Find any existing extension with this name
Extension extension = parent.getExtension(this._name);
if (this._hasOldValue && ModelUtils.isDefined(extension)) {
extension.value = this._oldValue;
}
if (!this._hasOldValue && ModelUtils.isDefined(extension)) {
parent.removeExtension(this._name);
}
}
use of io.apicurio.datamodels.core.models.ExtensibleNode in project apicurio-data-models by Apicurio.
the class Oas20to30TransformationVisitor method visitExtension.
/**
* @see io.apicurio.datamodels.core.visitors.IVisitor#visitExtension(io.apicurio.datamodels.core.models.Extension)
*/
@Override
public void visitExtension(Extension node) {
ExtensibleNode parent30 = (ExtensibleNode) this.lookup(node.parent());
Extension ext30 = parent30.createExtension();
ext30.name = node.name;
ext30.value = node.value;
parent30.addExtension(node.name, ext30);
}
Aggregations