1 package org.apache.commons.digester3.binder;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import static java.lang.String.format;
23
24 import org.apache.commons.digester3.AbstractMethodRule;
25
26
27
28
29
30
31
32
33
34
35 public abstract class AbstractParamTypeBuilder<R extends AbstractMethodRule>
36 extends AbstractBackToLinkedRuleBuilder<R>
37 {
38
39 private final String methodName;
40
41 private final ClassLoader classLoader;
42
43 private boolean useExactMatch = false;
44
45 private Class<?> paramType;
46
47 private boolean fireOnBegin = false;
48
49 AbstractParamTypeBuilder( String keyPattern, String namespaceURI, RulesBinder mainBinder,
50 LinkedRuleBuilder mainBuilder, String methodName, ClassLoader classLoader )
51 {
52 super( keyPattern, namespaceURI, mainBinder, mainBuilder );
53 this.methodName = methodName;
54 this.classLoader = classLoader;
55 }
56
57
58
59
60
61
62
63
64
65
66
67 public final AbstractParamTypeBuilder<R> withParameterType( Class<?> paramType )
68 {
69 if ( paramType == null )
70 {
71 reportError( format( ".%s.withParameterType( Class<?> )", methodName ), "NULL Java type not allowed" );
72 return this;
73 }
74 this.paramType = paramType;
75 return withParameterType( paramType.getName() );
76 }
77
78
79
80
81
82
83
84
85
86
87
88 public final AbstractParamTypeBuilder<R> withParameterType( String paramType )
89 {
90 if ( paramType == null )
91 {
92 reportError( format( ".%s.withParameterType( Class<?> )", methodName ), "NULL Java type not allowed" );
93 return this;
94 }
95
96 if ( this.paramType == null )
97 {
98 try
99 {
100 this.paramType = classLoader.loadClass( paramType );
101 }
102 catch ( ClassNotFoundException e )
103 {
104 this.reportError( format( ".%s.withParameterType( Class<?> )", methodName ),
105 format( "class '%s' cannot be load", paramType ) );
106 }
107 }
108 return this;
109 }
110
111
112
113
114
115
116
117 public final AbstractParamTypeBuilder<R> useExactMatch( boolean useExactMatch )
118 {
119 this.useExactMatch = useExactMatch;
120 return this;
121 }
122
123
124
125
126
127
128
129 public final AbstractParamTypeBuilder<R> fireOnBegin( boolean fireOnBegin )
130 {
131 this.fireOnBegin = fireOnBegin;
132 return this;
133 }
134
135 final String getMethodName()
136 {
137 return methodName;
138 }
139
140 final Class<?> getParamType()
141 {
142 return paramType;
143 }
144
145 final boolean isUseExactMatch()
146 {
147 return useExactMatch;
148 }
149
150 final boolean isFireOnBegin()
151 {
152 return fireOnBegin;
153 }
154
155 }