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

org.joda.beans.impl.flexi.FlexiMetaProperty Maven / Gradle / Ivy

/*
 *  Copyright 2001-present Stephen Colebourne
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.joda.beans.impl.flexi;

import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.List;

import org.joda.beans.Bean;
import org.joda.beans.MetaBean;
import org.joda.beans.PropertyStyle;
import org.joda.beans.impl.BasicMetaProperty;

/**
 * A meta-property using a {@code FlexiBean} for storage.
 */
final class FlexiMetaProperty extends BasicMetaProperty {

    /** The meta-bean. */
    private final MetaBean metaBean;

    /**
     * Factory to create a meta-property.
     * 
     * @param metaBean  the meta-bean, not null
     * @param propertyName  the property name, not empty
     */
    static FlexiMetaProperty of(MetaBean metaBean, String propertyName) {
        return new FlexiMetaProperty(metaBean, propertyName);
    }

    /**
     * Constructor.
     * 
     * @param metaBean  the meta-bean, not null
     * @param propertyName  the property name, not empty
     */
    private FlexiMetaProperty(MetaBean metaBean, String propertyName) {
        super(propertyName);
        this.metaBean = metaBean;
    }

    //-----------------------------------------------------------------------
    @Override
    public MetaBean metaBean() {
        return metaBean;
    }

    @Override
    public Class declaringType() {
        return FlexiBean.class;
    }

    @Override
    public Class propertyType() {
        return Object.class;
    }

    @Override
    public Class propertyGenericType() {
        return Object.class;
    }

    @Override
    public PropertyStyle style() {
        return PropertyStyle.READ_WRITE;
    }

    @Override
    public List annotations() {
        return Collections.emptyList();
    }

    //-----------------------------------------------------------------------
    @Override
    public Object get(Bean bean) {
        return ((FlexiBean) bean).propertyGet(name());
    }

    @Override
    public void set(Bean bean, Object value) {
        ((FlexiBean) bean).propertySet(name(), value);
    }

}