/*
 *    GeoTools - OpenSource mapping toolkit
 *    http://geotools.org
 *    (C) 2004-2006, GeoTools Project Managment Committee (PMC)
 *    (C) 2004, Institut de Recherche pour le Développement
 *   
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library 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
 *    Lesser General Public License for more details.
 *
 *    This package contains documentation from OpenGIS specifications.
 *    OpenGIS consortium's work is fully acknowledged here.
 */
package org.geotools.metadata.iso.identification;

// J2SE direct dependencies
import java.util.Collection;

// OpenGIS dependencies
import org.opengis.metadata.citation.Citation;
import org.opengis.metadata.identification.Keywords;
import org.opengis.metadata.identification.KeywordType;
import org.opengis.util.InternationalString;

// Geotools dependencies
import org.geotools.metadata.iso.MetadataEntity;


/**
 * Keywords, their type and reference source.
 *
 * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/main/java/org/geotools/metadata/iso/identification/KeywordsImpl.java $
 * @version $Id: KeywordsImpl.java 25189 2007-04-17 13:23:47Z desruisseaux $
 * @author Martin Desruisseaux
 * @author Touraïvane
 *
 * @since 2.1
 */
public class KeywordsImpl extends MetadataEntity implements Keywords {
    /**
     * Serial number for compatibility with different versions.
     */
    private static final long serialVersionUID = 48691634443678266L;

    /**
     * Commonly used word(s) or formalised word(s) or phrase(s) used to describe the subject.
     */
    private Collection keywords;

    /**
     * Subject matter used to group similar keywords.
     */
    private KeywordType type;

    /**
     * Name of the formally registered thesaurus or a similar authoritative source of keywords.
     */
    private Citation thesaurusName;

    /**
     * Constructs an initially empty keywords.
     */
    public KeywordsImpl() {
        super();
    }

    /**
     * Constructs a metadata entity initialized with the values from the specified metadata.
     *
     * @since 2.4
     */
    public KeywordsImpl(final Keywords source) {
        super(source);
    }

    /**
     * Creates keywords initialized to the given list.
     */    
    public KeywordsImpl(final Collection keywords) {
        setKeywords(keywords);
    }

    /**
     * Commonly used word(s) or formalised word(s) or phrase(s) used to describe the subject.
     */
    public synchronized Collection getKeywords() {
        return keywords = nonNullCollection(keywords, InternationalString.class);
    }

    /**
     * Set commonly used word(s) or formalised word(s) or phrase(s) used to describe the subject.
     */
    public synchronized void setKeywords(final Collection newValues) {
        keywords = copyCollection(newValues, keywords, InternationalString.class);
    }

    /**
     * Subject matter used to group similar keywords.
     */
    public KeywordType getType() {
        return type;
    }

    /**
     * Set the subject matter used to group similar keywords.
     */
    public synchronized void setType(final KeywordType newValue) {
        checkWritePermission();
        type = newValue;
    }

    /**
     * Name of the formally registered thesaurus or a similar authoritative source of keywords.
     */
    public Citation getThesaurusName() {
        return thesaurusName;
    }
    
    /**
     * Set the name of the formally registered thesaurus or a similar authoritative source
     * of keywords.
     */
    public synchronized void setThesaurusName(final Citation newValue) {
        checkWritePermission();
        thesaurusName = newValue;
    }
}
