| Constructor: |
public CallParamRule(int paramIndex) {
this(paramIndex, null);
}
Construct a "call parameter" rule that will save the body text of this
element as the parameter value.
Note that if the element is empty the an empty string is
passed to the target method, not null. And if automatic type conversion
is being applied (ie if the target function takes something other than
a string as a parameter) then the conversion will fail if the converter
class does not accept an empty string as valid input. Parameters:
paramIndex - The zero-relative parameter number
|
public CallParamRule(Digester digester,
int paramIndex) {
this(paramIndex);
}
Construct a "call parameter" rule that will save the body text of this
element as the parameter value.
Note that if the element is empty the an empty string is
passed to the target method, not null. And if automatic type conversion
is being applied (ie if the target function takes something other than
a string as a parameter) then the conversion will fail if the converter
class does not accept an empty string as valid input. Parameters:
digester - The associated Digester
paramIndex - The zero-relative parameter number
|
public CallParamRule(int paramIndex,
String attributeName) {
this.paramIndex = paramIndex;
this.attributeName = attributeName;
}
Construct a "call parameter" rule that will save the value of the
specified attribute as the parameter value. Parameters:
paramIndex - The zero-relative parameter number
attributeName - The name of the attribute to save
|
public CallParamRule(int paramIndex,
boolean fromStack) {
this.paramIndex = paramIndex;
this.fromStack = fromStack;
}
Construct a "call parameter" rule. Parameters:
paramIndex - The zero-relative parameter number
fromStack - should this parameter be taken from the top of the stack?
|
public CallParamRule(int paramIndex,
int stackIndex) {
this.paramIndex = paramIndex;
this.fromStack = true;
this.stackIndex = stackIndex;
}
Constructs a "call parameter" rule which sets a parameter from the stack.
If the stack contains too few objects, then the parameter will be set to null. Parameters:
paramIndex - The zero-relative parameter number
stackIndex - the index of the object which will be passed as a parameter.
The zeroth object is the top of the stack, 1 is the next object down and so on.
|
public CallParamRule(Digester digester,
int paramIndex,
String attributeName) {
this(paramIndex, attributeName);
}
Construct a "call parameter" rule that will save the value of the
specified attribute as the parameter value. Parameters:
digester - The associated Digester
paramIndex - The zero-relative parameter number
attributeName - The name of the attribute to save
|
| Method from org.apache.commons.digester.CallParamRule Detail: |
public void begin(Attributes attributes) throws Exception {
// --------------------------------------------------------- Public Methods
Object param = null;
if (attributeName != null) {
param = attributes.getValue(attributeName);
} else if(fromStack) {
param = digester.peek(stackIndex);
if (digester.log.isDebugEnabled()) {
StringBuffer sb = new StringBuffer("[CallParamRule]{");
sb.append(digester.match);
sb.append("} Save from stack; from stack?").append(fromStack);
sb.append("; object=").append(param);
digester.log.debug(sb.toString());
}
}
// Have to save the param object to the param stack frame here.
// Can't wait until end(). Otherwise, the object will be lost.
// We can't save the object as instance variables, as
// the instance variables will be overwritten
// if this CallParamRule is reused in subsequent nesting.
if(param != null) {
Object parameters[] = (Object[]) digester.peekParams();
parameters[paramIndex] = param;
}
}
Process the start of this element. |
public void body(String bodyText) throws Exception {
if (attributeName == null && !fromStack) {
// We must wait to set the parameter until end
// so that we can make sure that the right set of parameters
// is at the top of the stack
if (bodyTextStack == null) {
bodyTextStack = new ArrayStack();
}
bodyTextStack.push(bodyText.trim());
}
}
Process the body text of this element. |
public void end(String namespace,
String name) {
if (bodyTextStack != null && !bodyTextStack.empty()) {
// what we do now is push one parameter onto the top set of parameters
Object parameters[] = (Object[]) digester.peekParams();
parameters[paramIndex] = bodyTextStack.pop();
}
}
Process any body texts now. |
public String toString() {
StringBuffer sb = new StringBuffer("CallParamRule[");
sb.append("paramIndex=");
sb.append(paramIndex);
sb.append(", attributeName=");
sb.append(attributeName);
sb.append(", from stack=");
sb.append(fromStack);
sb.append("]");
return (sb.toString());
}
Render a printable version of this Rule. |