001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.routetemplate.xmlrouting;
018:
019: import java.util.Iterator;
020:
021: import javax.xml.namespace.QName;
022: import javax.xml.xpath.XPath;
023: import javax.xml.xpath.XPathFunction;
024: import javax.xml.xpath.XPathFunctionResolver;
025:
026: import org.w3c.dom.Node;
027:
028: import edu.iu.uis.eden.routetemplate.RuleExtension;
029: import edu.iu.uis.eden.routetemplate.RuleExtensionValue;
030: import edu.iu.uis.eden.support.xstream.XStreamSafeSearchFunction;
031:
032: /**
033: * A function resolver for XPath functions provided by KEW.
034: *
035: * @author jhopf
036: * @author ewestfal
037: */
038: public class WorkflowFunctionResolver implements XPathFunctionResolver {
039:
040: private RuleExtension ruleExtension;
041: private Node rootNode;
042: private XPath xpath;
043:
044: public XPathFunction resolveFunction(QName fname, int arity) {
045: if (fname == null) {
046: throw new NullPointerException(
047: "The function name cannot be null.");
048: }
049: if (fname.equals(new QName("http://nothingfornowwf.com",
050: "ruledata", "wf"))) {
051: if (ruleExtension == null) {
052: throw new NullPointerException(
053: "There are no rule extensions.");
054: }
055: return new XPathFunction() {
056: public Object evaluate(java.util.List args) {
057: if (args.size() == 1) {
058: String name = (String) args.get(0);
059: for (Iterator iter = ruleExtension
060: .getExtensionValues().iterator(); iter
061: .hasNext();) {
062: RuleExtensionValue value = (RuleExtensionValue) iter
063: .next();
064: if (value.getKey().equals(name)) {
065: return value.getValue();
066: }
067: }
068: }
069: return "";
070: }
071: };
072: } else if (fname.equals(new QName("http://nothingfornowwf.com",
073: "xstreamsafe", "wf"))) {
074: return new XStreamSafeSearchFunction(rootNode, this
075: .getXpath());
076: } else {
077: return null;
078: }
079: }
080:
081: public RuleExtension getRuleExtension() {
082: return ruleExtension;
083: }
084:
085: public void setRuleExtension(RuleExtension ruleExtension) {
086: this .ruleExtension = ruleExtension;
087: }
088:
089: public Node getRootNode() {
090: return rootNode;
091: }
092:
093: public void setRootNode(Node rootNode) {
094: this .rootNode = rootNode;
095: }
096:
097: public XPath getXpath() {
098: return xpath;
099: }
100:
101: public void setXpath(XPath xpath) {
102: this.xpath = xpath;
103: }
104: }
|