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 org.apache.commons.digester3.CallParamRule;
23
24
25
26
27
28
29 public final class CallParamBuilder
30 extends AbstractBackToLinkedRuleBuilder<CallParamRule>
31 {
32
33 private int paramIndex = 0;
34
35 private int stackIndex = 0;
36
37 private boolean fromStack = false;
38
39 private String attributeName;
40
41 CallParamBuilder( String keyPattern, String namespaceURI, RulesBinder mainBinder, LinkedRuleBuilder mainBuilder )
42 {
43 super( keyPattern, namespaceURI, mainBinder, mainBuilder );
44 }
45
46
47
48
49
50
51
52 public CallParamBuilder ofIndex( int paramIndex )
53 {
54 if ( paramIndex < 0 )
55 {
56 reportError( "callParam().ofIndex( int )", "negative index argument not allowed" );
57 }
58
59 this.paramIndex = paramIndex;
60 return this;
61 }
62
63
64
65
66
67
68
69 public CallParamBuilder fromAttribute(
70 {
71 this.attributeName = attributeName;
72 return this;
73 }
74
75
76
77
78
79
80
81 public CallParamBuilder fromStack( boolean fromStack )
82 {
83 this.fromStack = fromStack;
84 return this;
85 }
86
87
88
89
90
91
92
93 public CallParamBuilder withStackIndex( int stackIndex )
94 {
95 this.stackIndex = stackIndex;
96 this.fromStack = true;
97 return this;
98 }
99
100
101
102
103 @Override
104 protected CallParamRule createRule()
105 {
106 CallParamRule rule;
107
108 if ( fromStack )
109 {
110 rule = new CallParamRule( paramIndex, stackIndex );
111 }
112 else
113 {
114 rule = new CallParamRule( paramIndex );
115 }
116
117 rule.setAttributeName( attributeName );
118
119 return rule;
120 }
121
122 }