View Javadoc

1   /*
2    * Copyright (c) 2010 Carman Consulting, Inc.
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  
17  package org.metastopheles;
18  
19  import java.beans.PropertyDescriptor;
20  import java.io.Serializable;
21  import java.lang.reflect.AnnotatedElement;
22  
23  /**
24   * @author James Carman
25   * @since 1.0
26   */
27  public class PropertyMetaData extends MetaDataObject
28  {
29  //**********************************************************************************************************************
30  // Fields
31  //**********************************************************************************************************************
32  
33      private static final long serialVersionUID = 1L;
34      private PropertyDescriptor propertyDescriptor;
35      private final BeanMetaData beanMetaData;
36  
37  //**********************************************************************************************************************
38  // Constructors
39  //**********************************************************************************************************************
40  
41      PropertyMetaData(BeanMetaData beanMetaData, PropertyDescriptor propertyDescriptor)
42      {
43          this.beanMetaData = beanMetaData;
44          this.propertyDescriptor = propertyDescriptor;
45      }
46  
47  //**********************************************************************************************************************
48  // Getter/Setter Methods
49  //**********************************************************************************************************************
50  
51      public BeanMetaData getBeanMetaData()
52      {
53          return beanMetaData;
54      }
55  
56      /**
57       * Returns the property descriptor
58       * @return the property descriptor
59       */
60      public PropertyDescriptor getPropertyDescriptor()
61      {
62          return propertyDescriptor;
63      }
64  
65  //**********************************************************************************************************************
66  // Other Methods
67  //**********************************************************************************************************************
68  
69      /**
70       * The default annotation source for a property is its getter method.
71       * @return the property's getter method
72       */
73      @Override
74      protected AnnotatedElement getDefaultAnnotationSource()
75      {
76          return propertyDescriptor.getReadMethod();
77      }
78  
79      protected Object writeReplace()
80      {
81          return new SerializedForm(beanMetaData, propertyDescriptor.getName());
82      }
83  
84  //**********************************************************************************************************************
85  // Inner Classes
86  //**********************************************************************************************************************
87  
88      private static class SerializedForm implements Serializable
89      {
90          private static final long serialVersionUID = 1L;
91          private final BeanMetaData beanMetaData;
92          private final String propertyName;
93  
94  
95          private SerializedForm(BeanMetaData beanMetaData, String propertyName)
96          {
97              this.beanMetaData = beanMetaData;
98              this.propertyName = propertyName;
99          }
100 
101         protected Object readResolve()
102         {
103             return beanMetaData.getPropertyMetaData(propertyName);
104         }
105     }
106 }