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.MethodDescriptor;
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 MethodMetaData extends MetaDataObject
28 {
29 //**********************************************************************************************************************
30 // Fields
31 //**********************************************************************************************************************
32
33 private static final long serialVersionUID = 1L;
34 private final MethodDescriptor methodDescriptor;
35 private final BeanMetaData beanMetaData;
36
37 //**********************************************************************************************************************
38 // Constructors
39 //**********************************************************************************************************************
40
41 MethodMetaData(BeanMetaData beanMetaData, MethodDescriptor methodDescriptor)
42 {
43 this.beanMetaData = beanMetaData;
44 this.methodDescriptor = methodDescriptor;
45 }
46
47 //**********************************************************************************************************************
48 // Getter/Setter Methods
49 //**********************************************************************************************************************
50
51 public BeanMetaData getBeanMetaData()
52 {
53 return beanMetaData;
54 }
55
56 public MethodDescriptor getMethodDescriptor()
57 {
58 return methodDescriptor;
59 }
60
61 //**********************************************************************************************************************
62 // Other Methods
63 //**********************************************************************************************************************
64
65 @Override
66 protected AnnotatedElement getDefaultAnnotationSource()
67 {
68 return methodDescriptor.getMethod();
69 }
70
71 protected Object writeReplace()
72 {
73 return new SerializedForm(beanMetaData, methodDescriptor.getMethod().getName(), getMethodDescriptor().getMethod().getParameterTypes());
74 }
75
76 //**********************************************************************************************************************
77 // Inner Classes
78 //**********************************************************************************************************************
79
80 private static class SerializedForm implements Serializable
81 {
82 private static final long serialVersionUID = 1L;
83 private final BeanMetaData beanMetaData;
84 private final String methodName;
85 private final Class<?>[] parameterTypes;
86
87
88 private SerializedForm(BeanMetaData beanMetaData, String methodName, Class<?>[] parameterTypes)
89 {
90 this.beanMetaData = beanMetaData;
91 this.methodName = methodName;
92 this.parameterTypes = parameterTypes;
93 }
94
95 protected Object readResolve()
96 {
97 return beanMetaData.getMethodMetaData(methodName, parameterTypes);
98 }
99 }
100 }