com.eldar.models.templates.Template.java Source code

Java tutorial

Introduction

Here is the source code for com.eldar.models.templates.Template.java

Source

/*******************************************************************************
 * This file is part of Eldar Works.
 *
 * Eldar Works is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Eldar Works is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Eldar Works.  If not, see <http://www.gnu.org/licenses/>.
 * Copyright (c) 2012. Phillip Sanderson
 ******************************************************************************/

package com.eldar.models.templates;

import com.eldar.models.Base;
import com.eldar.models.Versionable;
import org.apache.commons.lang3.SerializationUtils;

/**
 * A template that defines the layout for one or more pages.
 *
 * @author Phillip Sanderson
 *         Date: 10/05/12
 *         Time: 10:52 PM
 */
public class Template extends Base implements Versionable<TemplateVersion> {

    private TemplateVersion templateVersion;

    private String unversionedFilename;

    public Template(TemplateVersion version) {
        setVersion(version);
    }

    /**
     * Sets the version that this template refers to.
     *
     * @param templateVersion - The version.
     */
    @Override
    public void setVersion(TemplateVersion templateVersion) {
        this.templateVersion = templateVersion;
    }

    /**
     * The version number of this templates version.
     *
     * @return - the version number.
     */
    public int getVersionNumber() {
        return getVersion().getVersion();
    }

    public void setVersionNumber(int version) {
        this.getVersion().setVersion(version);
    }

    /**
     * The name of this template
     *
     * @return - The template name.
     */
    public String getName() {
        return getVersion().getName();
    }

    /**
     * The name of this template.
     *
     * @param name - The template name.
     */
    public void setName(String name) {
        getVersion().setName(name);
    }

    /**
     * A description of the template.
     *
     * @return - String description
     */
    public String getDescription() {
        return getVersion().getDescription();
    }

    public void setDescription(String description) {
        this.getVersion().setDescription(description);
    }

    /**
     * Clones the current version using apache commons SerializationUtils.
     *
     * @return - the clone.
     */
    @Override
    public TemplateVersion cloneCurrentVersion() {
        TemplateVersion clone = SerializationUtils.clone(getVersion());
        //reset all the ids of the clones so they save.
        clone.setId(0);
        return clone;
    }

    public String getUnversionedFilename() {
        return unversionedFilename;
    }

    public void setUnversionedFilename(String unversionedFilename) {
        this.unversionedFilename = unversionedFilename;
    }

    public TemplateVersion getVersion() {
        return templateVersion;
    }

}