View Javadoc

1   /*
2    *  Copyright 2001-2013 Stephen Colebourne
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   */
16  package org.joda.beans.impl.flexi;
17  
18  import java.lang.annotation.Annotation;
19  import java.util.Collections;
20  import java.util.List;
21  
22  import org.joda.beans.Bean;
23  import org.joda.beans.MetaBean;
24  import org.joda.beans.Property;
25  import org.joda.beans.PropertyReadWrite;
26  import org.joda.beans.impl.BasicMetaProperty;
27  import org.joda.beans.impl.BasicProperty;
28  
29  /**
30   * A meta-property using a {@code FlexiBean} for storage.
31   * 
32   * @author Stephen Colebourne
33   */
34  final class FlexiMetaProperty extends BasicMetaProperty<Object> {
35  
36      /** The meta-bean. */
37      private final MetaBean metaBean;
38  
39      /**
40       * Factory to create a meta-property.
41       * 
42       * @param metaBean  the meta-bean, not null
43       * @param propertyName  the property name, not empty
44       */
45      static FlexiMetaProperty of(MetaBean metaBean, String propertyName) {
46          return new FlexiMetaProperty(metaBean, propertyName);
47      }
48  
49      /**
50       * Constructor.
51       * 
52       * @param metaBean  the meta-bean, not null
53       * @param propertyName  the property name, not empty
54       */
55      private FlexiMetaProperty(MetaBean metaBean, String propertyName) {
56          super(propertyName);
57          this.metaBean = metaBean;
58      }
59  
60      //-----------------------------------------------------------------------
61      @Override
62      public Property<Object> createProperty(Bean bean) {
63          return BasicProperty.of(bean, this);
64      }
65  
66      @Override
67      public MetaBean metaBean() {
68          return metaBean;
69      }
70  
71      @Override
72      public Class<?> declaringType() {
73          return FlexiBean.class;
74      }
75  
76      @Override
77      public Class<Object> propertyType() {
78          return Object.class;
79      }
80  
81      @Override
82      public Class<Object> propertyGenericType() {
83          return Object.class;
84      }
85  
86      @Override
87      public PropertyReadWrite readWrite() {
88          return PropertyReadWrite.READ_WRITE;
89      }
90  
91      @Override
92      public List<Annotation> annotations() {
93          return Collections.emptyList();
94      }
95  
96      //-----------------------------------------------------------------------
97      @Override
98      public Object get(Bean bean) {
99          return ((FlexiBean) bean).propertyGet(name());
100     }
101 
102     @Override
103     public void set(Bean bean, Object value) {
104         ((FlexiBean) bean).propertySet(name(), value);
105     }
106 
107 }