view flys-artifacts/src/main/java/de/intevation/flys/exports/TypeSection.java @ 4255:670e98f5a441

Fixed leak while merging facets. The ThemeList that is used by OutputHelper to sort the Facets for an Output now uses a list to store the ManagedFacets. The correct order is made up by sorting the List using Collections.sort() function of the Java JDK. Therfore, the ManagedFacet class implements the Comparable interface. The return value of its compareTo(other) method depends on the value of the 'position' field.
author Ingo Weinzierl <weinzierl.ingo@googlemail.com>
date Thu, 25 Oct 2012 14:01:46 +0200
parents cbe2febe30cc
children
line wrap: on
line source
package de.intevation.flys.exports;

import org.apache.log4j.Logger;

import de.intevation.artifactdatabase.state.Attribute;
import de.intevation.artifactdatabase.state.DefaultSection;


/**
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class TypeSection extends DefaultSection {

    private static final Logger logger = Logger.getLogger(TypeSection.class);

    public TypeSection(String key) {
        super(key);
    }


    /** Set a string value for a attribute with additional (choice) type. */
    public void setChoiceStringValue(String key, String value, String choiceType) {
        if (value == null || value.length() == 0) {
            return;
        }

        Attribute attr = getAttribute(key);
        if (attr == null) {
            attr = new ChoiceStringAttribute(key, value, true, choiceType);
            addAttribute(key, attr);
        }
        else {
            attr.setValue(value);
        }
    }


    public void setStringValue(String key, String value) {
        if (value == null || value.length() == 0) {
            return;
        }

        Attribute attr = getAttribute(key);
        if (attr == null) {
            attr = new StringAttribute(key, value, true);
            addAttribute(key, attr);
        }
        else {
            attr.setValue(value);
        }
    }


    public String getStringValue(String key) {
        Attribute attr = getAttribute(key);

        if (attr instanceof StringAttribute) {
            return (String) attr.getValue();
        }

        logger.debug("attribute " + key + " not found in typesection.getString");

        return null;
    }


    public void setIntegerValue(String key, int value) {
        Attribute attr = getAttribute(key);
        if (attr == null) {
            attr = new IntegerAttribute(key, value, true);
            addAttribute(key, attr);
        }
        else {
            attr.setValue(value);
        }
    }


    public Integer getIntegerValue(String key) {
        Attribute attr = getAttribute(key);

        if (attr instanceof IntegerAttribute) {
            return (Integer) attr.getValue();
        }

        return null;
    }



    public void setDoubleValue(String key, double value) {
        Attribute attr = getAttribute(key);
        if (attr == null) {
            attr = new DoubleAttribute(key, value, true);
            addAttribute(key, attr);
        }
        else {
            attr.setValue(value);
        }
    }


    public Double getDoubleValue(String key) {
        Attribute attr = getAttribute(key);

        if (attr instanceof DoubleAttribute) {
            return (Double) attr.getValue();
        }

        return null;
    }


    public void setBooleanValue(String key, boolean value) {
        Attribute attr = getAttribute(key);
        if (attr == null) {
            attr = new BooleanAttribute(key, value, true);
            addAttribute(key, attr);
        }
        else {
            attr.setValue(value);
        }
    }


    public Boolean getBooleanValue(String key) {
        Attribute attr = getAttribute(key);

        if (attr instanceof BooleanAttribute) {
            return (Boolean) attr.getValue();
        }

        return null;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org