1 package org.jfrog.reflect.impl;
2
3 import org.jfrog.reflect.MethodDefinition;
4 import org.jfrog.reflect.ObjectMappingException;
5
6 import java.lang.reflect.Method;
7
8
9
10
11
12
13
14 public class MethodDefinitionImpl extends AccessibleObjectDefinitionImpl implements MethodDefinition {
15 private String methodName;
16 private Method reflectMethod;
17 private final Class[] parameterTypes;
18
19 public MethodDefinitionImpl(Enum enumEntry, Class... parameterTypes) {
20 super(enumEntry);
21 this.parameterTypes = parameterTypes;
22 }
23
24 public MethodDefinitionImpl(Enum enumEntry, String methodName, Class... parameterTypes) {
25 super(enumEntry);
26 this.methodName = methodName;
27 this.parameterTypes = parameterTypes;
28 }
29
30 public String getMethodName() {
31 if (methodName == null) {
32 methodName = enumEntry.name();
33 }
34 return methodName;
35 }
36
37 public Method getMethod() {
38 if (reflectMethod == null) {
39 try {
40 reflectMethod = getModelClass().getDeclaredMethod(getMethodName(), parameterTypes);
41 } catch (NoSuchMethodException e) {
42 throw new ObjectMappingException("Method " + enumEntry + " with name " + methodName +
43 " with parameters " + parameterTypes + " does not exists in " + modelClass, e);
44 }
45 }
46 return reflectMethod;
47 }
48 }