Search in sources :

Example 1 with IExampleParent

use of io.apicurio.datamodels.core.models.common.IExampleParent in project apicurio-data-models by Apicurio.

the class SetExampleCommand_30 method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[SetExampleCommand_30] Executing.");
    this._oldValue = null;
    this._nullExample = false;
    if (!this.isNullOrUndefined(this._newExampleName)) {
        IExamplesParent parent = (IExamplesParent) this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parent)) {
            return;
        }
        if (this.isNullOrUndefined(parent.getExample(this._newExampleName))) {
            parent.addExample(parent.createExample(this._newExampleName));
            this._nullExample = true;
        } else {
            this._oldValue = parent.getExample(this._newExampleName).getValue();
        }
        parent.getExample(this._newExampleName).setValue(this._newExample);
    } else {
        IExampleParent parent = (IExampleParent) this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parent)) {
            return;
        }
        this._oldValue = parent.getExample();
        parent.setExample(this._newExample);
    }
}
Also used : IExamplesParent(io.apicurio.datamodels.core.models.common.IExamplesParent) IExampleParent(io.apicurio.datamodels.core.models.common.IExampleParent)

Example 2 with IExampleParent

use of io.apicurio.datamodels.core.models.common.IExampleParent in project apicurio-data-models by Apicurio.

the class SetExampleCommand_30 method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[SetExampleCommand_30] Reverting.");
    if (!this.isNullOrUndefined(this._newExampleName)) {
        IExamplesParent parent = (IExamplesParent) this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parent)) {
            return;
        }
        if (this._nullExample) {
            parent.removeExample(this._newExampleName);
        } else {
            parent.getExample(this._newExampleName).setValue(this._oldValue);
        }
    } else {
        IExampleParent parent = (IExampleParent) this._parentPath.resolve(document);
        if (this.isNullOrUndefined(parent)) {
            return;
        }
        parent.setExample(this._oldValue);
        this._oldValue = null;
    }
}
Also used : IExamplesParent(io.apicurio.datamodels.core.models.common.IExamplesParent) IExampleParent(io.apicurio.datamodels.core.models.common.IExampleParent)

Aggregations

IExampleParent (io.apicurio.datamodels.core.models.common.IExampleParent)2 IExamplesParent (io.apicurio.datamodels.core.models.common.IExamplesParent)2