01: /*******************************************************************************
02: * Portions created by Sebastian Thomschke are copyright (c) 2005-2007 Sebastian
03: * Thomschke.
04: *
05: * All Rights Reserved. This program and the accompanying materials
06: * are made available under the terms of the Eclipse Public License v1.0
07: * which accompanies this distribution, and is available at
08: * http://www.eclipse.org/legal/epl-v10.html
09: *
10: * Contributors:
11: * Sebastian Thomschke - initial implementation.
12: *******************************************************************************/package net.sf.oval.context;
13:
14: import java.lang.reflect.Constructor;
15:
16: import net.sf.oval.internal.MessageResolverHolder;
17: import net.sf.oval.internal.util.SerializableConstructor;
18: import net.sf.oval.internal.util.StringUtils;
19:
20: /**
21: * @author Sebastian Thomschke
22: */
23: public class ConstructorParameterContext extends OValContext {
24: private static final long serialVersionUID = 1L;
25:
26: private final SerializableConstructor constructor;
27: private final int parameterIndex;
28: private final String parameterName;
29:
30: /**
31: *
32: * @param constructor
33: * @param parameterIndex
34: */
35: public ConstructorParameterContext(
36: final Constructor<?> constructor, final int parameterIndex,
37: final String parameterName) {
38: this .constructor = SerializableConstructor
39: .getInstance(constructor);
40: this .parameterIndex = parameterIndex;
41: this .parameterName = parameterName;
42: }
43:
44: /**
45: * @return Returns the constructor.
46: */
47: public Constructor<?> getConstructor() {
48: return constructor.getConstructor();
49: }
50:
51: /**
52: * @return Returns the parameterIndex.
53: */
54: public int getParameterIndex() {
55: return parameterIndex;
56: }
57:
58: /**
59: * @return the parameterName
60: */
61: public String getParameterName() {
62: return parameterName;
63: }
64:
65: @Override
66: public String toString() {
67: return constructor.getDeclaringClass().getName()
68: + "("
69: + StringUtils.implode(constructor.getParameterTypes(),
70: ",")
71: + ") "
72: + MessageResolverHolder
73: .getMessageResolver()
74: .getMessage(
75: "net.sf.oval.context.ConstructorParameterContext.parameter")
76: + " "
77: + parameterIndex
78: + (parameterName == null || parameterName.length() == 0 ? ""
79: : " (" + parameterName + ")");
80: }
81: }
|