package org.apache.slide.webdav.util.properties;

import org.apache.slide.common.NamespaceAccessToken;
import org.apache.slide.common.PropertyName;
import org.apache.slide.common.SlideException;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionDescriptors;
import org.apache.slide.util.conf.Configuration;
import org.apache.slide.util.conf.ConfigurationException;
import org.apache.slide.webdav.util.WebdavContext;
import org.apache.slide.webdav.util.resourcekind.ResourceKind;

/**
 * "Computed" property containing a constant value.
 */
public class ConstantProperty extends AbstractComputedProperty implements ConfigurablePropertyComputer{

    private PropertyName propertyName;
    private String constantValue = "constant not specified";
    
    public void setPropertyName(PropertyName propertyName) {
        this.propertyName = propertyName;
    }
    public void configure(Configuration configuration)
            throws ConfigurationException {
        try {
            Configuration c = configuration.getConfiguration("constant-value");
            this.constantValue = c.getValue("");
        } catch (ConfigurationException e) {
            // ignore; no default-value given; is ok too
        }
    }
    public PropertyName getPropertyName() {
        return this.propertyName;
    }

    /* (non-Javadoc)
     * @see org.apache.slide.webdav.util.properties.PropertyComputer#computeValue(org.apache.slide.common.NamespaceAccessToken, org.apache.slide.content.NodeRevisionDescriptors, org.apache.slide.content.NodeRevisionDescriptor, org.apache.slide.webdav.util.resourcekind.ResourceKind, org.apache.slide.webdav.util.WebdavContext)
     */
    public Object computeValue(NamespaceAccessToken nsaToken,
            NodeRevisionDescriptors revisionDescriptors,
            NodeRevisionDescriptor revisionDescriptor,
            ResourceKind resourceKind, WebdavContext context)
            throws SlideException {
        return this.constantValue;
    }
}
