📄 functionbase.java
字号:
*/
public String getFunctionName() {
return functionName;
}
/**
* Returns the Identifier of the function to be handled by this
* particular object.
*
* @return the function Id
*/
public int getFunctionId() {
return functionId;
}
/**
* Returns the same value as <code>getReturnType</code>. This is here
* to support the <code>Expression</code> interface.
*
* @return the return type
*/
public URI getType() {
return getReturnType();
}
/**
* Get the attribute type returned by this function.
*
* @return a <code>URI</code> indicating the attribute type
* returned by this function
*/
public URI getReturnType() {
try {
return new URI(returnType);
} catch (Exception e) {
return null;
}
}
/**
* Returns true if this function returns a bag of values.
*
* @return true if the function returns a bag, false otherwise
*/
public boolean returnsBag() {
return returnsBag;
}
/**
* Returns the return type for this particular object.
*
* @return the return type
*/
public String getReturnTypeAsString() {
return returnType;
}
/**
* Create an <code>EvaluationResult</code> that indicates a
* processing error with the specified message. This method
* may be useful to subclasses.
*
* @param message a description of the error
* (<code>null</code> if none)
* @return the desired <code>EvaluationResult</code>
*/
protected static EvaluationResult makeProcessingError(String message) {
// Build up the processing error Status.
if (processingErrList == null) {
String [] errStrings = { Status.STATUS_PROCESSING_ERROR };
processingErrList = Arrays.asList(errStrings);
}
Status errStatus = new Status(processingErrList, message);
EvaluationResult processingError = new EvaluationResult(errStatus);
return processingError;
}
/**
* Evaluates each of the parameters, in order, filling in the argument
* array with the resulting values. If any error occurs, this method
* returns the error, otherwise null is returned, signalling that
* evaluation was successful for all inputs, and the resulting argument
* list can be used.
*
* @param params a <code>List</code> of <code>Evaluatable</code>
* objects representing the parameters to evaluate
* @param context the representation of the request
* @param args an array as long as the params <code>List</code> that
* will, on return, contain the <code>AttributeValue</code>s
* generated from evaluating all parameters
*
* @return <code>null</code> if no errors were encountered, otherwise
* an <code>EvaluationResult</code> representing the error
*/
protected EvaluationResult evalArgs(List params, EvaluationCtx context,
AttributeValue [] args) {
Iterator it = params.iterator();
int index = 0;
while (it.hasNext()) {
// get and evaluate the next parameter
Evaluatable eval = (Evaluatable)(it.next());
EvaluationResult result = eval.evaluate(context);
// If there was an error, pass it back...
if (result.indeterminate())
return result;
// ...otherwise save it and keep going
args[index++] = result.getAttributeValue();
}
// if no error occurred then we got here, so we return no errors
return null;
}
/**
* Default handling of input checking. This does some simple checking
* based on the type of constructor used. If you need anything more
* complex, or if you used the simple constructor, then you must
* override this method.
*
* @param inputs a <code>List></code> of <code>Evaluatable</code>s
*
* @throws IllegalArgumentException if the inputs won't work
*/
public void checkInputs(List inputs) throws IllegalArgumentException {
// first off, see what kind of function we are
if (singleType) {
// first, check the length of the inputs, if appropriate
if (numParams != -1) {
if (inputs.size() != numParams)
throw new IllegalArgumentException("wrong number of args" +
" to " + functionName);
} else {
if (inputs.size() < minParams)
throw new IllegalArgumentException("not enough args" +
" to " + functionName);
}
// now, make sure everything is of the same, correct type
Iterator it = inputs.iterator();
while (it.hasNext()) {
Evaluatable eval = (Evaluatable)(it.next());
if ((! eval.getType().toString().equals(paramType)) ||
(eval.returnsBag() != paramIsBag))
throw new IllegalArgumentException("illegal parameter");
}
} else {
// first, check the length of the inputs
if (paramTypes.length != inputs.size())
throw new IllegalArgumentException("wrong number of args" +
" to " + functionName);
// now, make sure everything is of the same, correct type
Iterator it = inputs.iterator();
int i = 0;
while (it.hasNext()) {
Evaluatable eval = (Evaluatable)(it.next());
if ((! eval.getType().toString().equals(paramTypes[i])) ||
(eval.returnsBag() != paramsAreBags[i]))
throw new IllegalArgumentException("illegal parameter");
i++;
}
}
}
/**
* Default handling of input checking. This does some simple checking
* based on the type of constructor used. If you need anything more
* complex, or if you used the simple constructor, then you must
* override this method.
*
* @param inputs a <code>List></code> of <code>Evaluatable</code>s
*
* @throws IllegalArgumentException if the inputs won't work
*/
public void checkInputsNoBag(List inputs) throws IllegalArgumentException {
// first off, see what kind of function we are
if (singleType) {
// first check to see if we need bags
if (paramIsBag)
throw new IllegalArgumentException(functionName + "needs" +
"bags on input");
// now check on the length
if (numParams != -1) {
if (inputs.size() != numParams)
throw new IllegalArgumentException("wrong number of args" +
" to " + functionName);
} else {
if (inputs.size() < minParams)
throw new IllegalArgumentException("not enough args" +
" to " + functionName);
}
// finally check param list
Iterator it = inputs.iterator();
while (it.hasNext()) {
Evaluatable eval = (Evaluatable)(it.next());
if (! eval.getType().toString().equals(paramType))
throw new IllegalArgumentException("illegal parameter");
}
} else {
// first, check the length of the inputs
if (paramTypes.length != inputs.size())
throw new IllegalArgumentException("wrong number of args" +
" to " + functionName);
// now, make sure everything is of the same, correct type
Iterator it = inputs.iterator();
int i = 0;
while (it.hasNext()) {
Evaluatable eval = (Evaluatable)(it.next());
if ((! eval.getType().toString().equals(paramTypes[i])) ||
(paramsAreBags[i]))
throw new IllegalArgumentException("illegal parameter");
i++;
}
}
}
/**
* Encodes this <code>FunctionBase</code> into its XML representation and
* writes this encoding to the given <code>OutputStream</code> with no
* indentation.
*
* @param output a stream into which the XML-encoded data is written
*/
public void encode(OutputStream output) {
encode(output, new Indenter(0));
}
/**
* Encodes this <code>FunctionBase</code> into its XML representation and
* writes this encoding to the given <code>OutputStream</code> with
* indentation.
*
* @param output a stream into which the XML-encoded data is written
* @param indenter an object that creates indentation strings
*/
public void encode(OutputStream output, Indenter indenter) {
PrintStream out = new PrintStream(output);
out.println(indenter.makeString() + "<Function FunctionId=\"" +
getFunctionName() + "\"/>");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -