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

net.contextfw.web.application.configuration.BindableProperty Maven / Gradle / Ivy

package net.contextfw.web.application.configuration;

public class BindableProperty implements SelfSettableProperty {

    private final String key;
    
    private final T instance;
   
    private final Class type;
    
    @Override
    public String getKey() {
        return key;
    }
    
    public BindableProperty(String key) {
        this.key = key;
        this.instance = null;
        this.type = null;
    }

    private BindableProperty(String key, T instance) {
        this.key = key;
        this.instance = instance;
        this.type = null;
    }
    
    private BindableProperty(String key, Class type) {
        this.key = key;
        this.instance = null;
        this.type = type;
    }

    @Override
    public Object unserialize(String value) {
        throw new UnsupportedOperationException();
    }

    @Override
    public String serialize(Object value) {
        throw new UnsupportedOperationException();
    }

    @Override
    public Object validate(Object value) {
        return value;
    }

    @Override
    public Object getValue() {
        return instance == null ? type : instance; 
    }

    public T getInstance() {
        return instance;
    }

    public Class getType() {
        return type;
    }
    
    public  BindableProperty as(Class type) {
        return new BindableProperty(key, type);
    }
    
    public BindableProperty asInstance(T instance) {
        return new BindableProperty(key, instance);
    }
}