All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.apicurio.datamodels.cloning.ModelClonerVisitor Maven / Gradle / Ivy

There is a newer version: 3.5.0.Final
Show newest version
/*
 * Copyright 2019 JBoss Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.apicurio.datamodels.cloning;

import io.apicurio.datamodels.Library;
import io.apicurio.datamodels.core.models.Document;
import io.apicurio.datamodels.core.models.Extension;
import io.apicurio.datamodels.core.models.Node;
import io.apicurio.datamodels.core.models.ValidationProblem;
import io.apicurio.datamodels.core.models.common.Contact;
import io.apicurio.datamodels.core.models.common.ExternalDocumentation;
import io.apicurio.datamodels.core.models.common.Info;
import io.apicurio.datamodels.core.models.common.License;
import io.apicurio.datamodels.core.models.common.Tag;
import io.apicurio.datamodels.core.visitors.IVisitor;

/**
 * @author [email protected]
 */
public abstract class ModelClonerVisitor implements IVisitor {
    
    protected Node clone;
    
    public final Node getClone() {
        if (clone.ownerDocument() == null && clone.parent() != null) {
            clone._ownerDocument = clone.parent().ownerDocument();
        }
        return this.clone;
    }

    /**
     * @see io.apicurio.datamodels.core.visitors.IVisitor#visitContact(io.apicurio.datamodels.core.models.common.Contact)
     */
    @Override
    public final void visitContact(Contact node) {
        this.clone = node.ownerDocument().createInfo().createContact();
    }

    /**
     * @see io.apicurio.datamodels.core.visitors.IVisitor#visitDocument(io.apicurio.datamodels.core.models.Document)
     */
    @Override
    public final void visitDocument(Document node) {
        this.clone = Library.createDocument(node.getDocumentType());
    }

    /**
     * @see io.apicurio.datamodels.core.visitors.IVisitor#visitExtension(io.apicurio.datamodels.core.models.Extension)
     */
    @Override
    public final void visitExtension(Extension node) {
        this.clone = node.ownerDocument().createExtension();
    }

    /**
     * @see io.apicurio.datamodels.core.visitors.IVisitor#visitExternalDocumentation(io.apicurio.datamodels.core.models.common.ExternalDocumentation)
     */
    @Override
    public final void visitExternalDocumentation(ExternalDocumentation node) {
        this.clone = node.ownerDocument().createExternalDocumentation();
    }

    /**
     * @see io.apicurio.datamodels.core.visitors.IVisitor#visitInfo(io.apicurio.datamodels.core.models.common.Info)
     */
    @Override
    public final void visitInfo(Info node) {
        this.clone = node.ownerDocument().createInfo();
    }

    /**
     * @see io.apicurio.datamodels.core.visitors.IVisitor#visitLicense(io.apicurio.datamodels.core.models.common.License)
     */
    @Override
    public final void visitLicense(License node) {
        this.clone = node.ownerDocument().createInfo().createLicense();
    }

    /**
     * @see io.apicurio.datamodels.core.visitors.IVisitor#visitTag(io.apicurio.datamodels.core.models.common.Tag)
     */
    @Override
    public final void visitTag(Tag node) {
        this.clone = node.ownerDocument().createTag();
    }

    /**
     * @see io.apicurio.datamodels.core.visitors.IVisitor#visitValidationProblem(io.apicurio.datamodels.core.models.ValidationProblem)
     */
    @Override
    public final void visitValidationProblem(ValidationProblem problem) {
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy