Java 类javax.xml.xpath.XPathFunctionException 实例源码

项目:Camel    文件:XPathBuilder.java   
private XPathFunction createPropertiesFunction() {
    return new XPathFunction() {
        @SuppressWarnings("rawtypes")
        public Object evaluate(List list) throws XPathFunctionException {
            if (!list.isEmpty()) {
                Object value = list.get(0);
                if (value != null) {
                    String text = exchange.get().getContext().getTypeConverter().convertTo(String.class, value);
                    try {
                        // use the property placeholder resolver to lookup the property for us
                        Object answer = exchange.get().getContext().resolvePropertyPlaceholders("{{" + text + "}}");
                        return answer;
                    } catch (Exception e) {
                        throw new XPathFunctionException(e);
                    }
                }
            }
            return null;
        }
    };
}
项目:Camel    文件:XPathBuilder.java   
private XPathFunction createSimpleFunction() {
    return new XPathFunction() {
        @SuppressWarnings("rawtypes")
        public Object evaluate(List list) throws XPathFunctionException {
            if (!list.isEmpty()) {
                Object value = list.get(0);
                if (value != null) {
                    String text = exchange.get().getContext().getTypeConverter().convertTo(String.class, value);
                    Language simple = exchange.get().getContext().resolveLanguage("simple");
                    Expression exp = simple.createExpression(text);
                    Object answer = exp.evaluate(exchange.get(), Object.class);
                    return answer;
                }
            }
            return null;
        }
    };
}
项目:LoboEvolution    文件:AbstractFunction.java   
/**
 * Gets the string param.
 *
 * @param o
 *            the o
 * @return the string param
 * @throws XPathFunctionException
 *             the x path function exception
 */
protected String getStringParam(Object o) throws XPathFunctionException {
    // perform conversions
    String output = null;
    if (o instanceof String) {
        output = (String) o;
    } else if (o instanceof Boolean) {
        output = o.toString();
    } else if (o instanceof Double) {
        output = o.toString();
    } else if (o instanceof NodeList) {
        NodeList list = (NodeList) o;
        Node node = list.item(0);
        output = node.getTextContent();
    } else {
        throw new XPathFunctionException("Could not convert argument type");
    }
    return output;
}
项目:LoboEvolution    文件:AbstractFunction.java   
/**
 * Gets the number param.
 *
 * @param o
 *            the o
 * @return the number param
 * @throws XPathFunctionException
 *             the x path function exception
 */
protected Number getNumberParam(Object o) throws XPathFunctionException {
    // perform conversions
    Number output = null;
    try {
        if (o instanceof String) {
            output = Double.parseDouble((String) o);
        } else if (o instanceof Double) {
            output = (Double) o;
        } else if (o instanceof NodeList) {
            NodeList list = (NodeList) o;
            Node node = list.item(0);
            output = Double.parseDouble(node.getTextContent());
        } else {
            throw new XPathFunctionException("Could not convert argument type");
        }
    } catch (NumberFormatException ex) {
        throw new XPathFunctionException(ex);
    }
    return output;
}
项目:carbon-business-process    文件:JaxpFunctionResolver.java   
public Object evaluate(List args) throws XPathFunctionException {
    MessageDAO inputMsg = evalCtx.getInput();
    String partName = (String) args.get(0);
    Node matchingElement = null;
    if (StringUtils.isNullOrEmpty(partName)) {
        throw new HumanTaskRuntimeException("The getInput function should be provided with the part name");
    }

    if (inputMsg.getBodyData().hasChildNodes()) {
        NodeList nodeList = inputMsg.getBodyData().getChildNodes();

        for (int i = 0; i < nodeList.getLength(); i++) {
            if (partName.trim().equals(nodeList.item(i).getNodeName())) {
                matchingElement = nodeList.item(i);
            }
        }
    }

    if (matchingElement == null || matchingElement.getFirstChild() == null) {
        throw new HumanTaskRuntimeException(
                "Cannot find a matching Element for expression evaluation: getInput");
    }

    return matchingElement.getFirstChild();
}
项目:carbon-business-process    文件:JaxpFunctionResolver.java   
public Object evaluate(List args) throws XPathFunctionException {
    MessageDAO outputMsg = evalCtx.getOutput();
    String partName = (String) args.get(0);
    Node matchingElement = null;
    if (StringUtils.isNullOrEmpty(partName)) {
        throw new HumanTaskRuntimeException(
                "The getOutput function should be provided with the part name");
    }

    if (outputMsg.getBodyData().hasChildNodes()) {
        NodeList nodeList = outputMsg.getBodyData().getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            if (partName.trim().equals(nodeList.item(i).getNodeName())) {
                matchingElement = nodeList.item(i);
            }
        }
    }

    if (matchingElement == null || matchingElement.getFirstChild() == null) {
        throw new HumanTaskRuntimeException(
                "Cannot find a matching Element for expression evaluation: getOutput");
    }

    return matchingElement.getFirstChild();
}
项目:carbon-business-process    文件:JaxpFunctionResolver.java   
public Object evaluate(List args) throws XPathFunctionException {
    String username = "";
    if (args.size() == 0) {
        // Case 1: consider current Task.
        username = getUserNameFromCtx();

    } else if ((args.size() == 1) && (args.get(0) instanceof String)) {
        String taskName = (String) args.get(0);
        if (evalCtx.getTask().getName().equals(taskName)) {
            //Case 2: TaskName equals to current task, consider current task
            username = getUserNameFromCtx();
        } else if (!StringUtils.isNullOrEmpty(taskName)) {
            // Case 3: Getting specific task. Unsupported.
            log.warn("HumanTask Xpath: getActualOwner(\"" + taskName + "\")"
                    + " operation is not currently supported in this version of WSO2 BPS."
                    + " Use getActualOwner() instead.");
        }

    }
    return createHttUser(username);
}
项目:carbon-business-process    文件:JaxpFunctionResolver.java   
public Object evaluate(List args) throws XPathFunctionException {
    GenericHumanRoleDAO businessAdmins = null;
    if (args.size() == 0) {
        // Case 1: consider current Task.
        businessAdmins = getBussinessAdminsFromCtx();
    } else if ((args.size() == 1) && (args.get(0) instanceof String)) {
        String taskName = (String) args.get(0);
        if (evalCtx.getTask().getName().equals(taskName)) {
            //Case 2 : TaskName equals to current task, consider current task
            businessAdmins = getBussinessAdminsFromCtx();
        } else if (!StringUtils.isNullOrEmpty(taskName)) {
            // Case 3: Getting specific task. Unsupported.
            log.warn("HumanTask Xpath: getBusinessAdministrators(\"" + taskName + "\")"
                    + " operation is not currently supported in this version of WSO2 BPS."
                    + " Use getBusinessAdministrators() instead.");
        }

    }
    return createOrgEntity(businessAdmins);
}
项目:carbon-business-process    文件:JaxpFunctionResolver.java   
public Object evaluate(List args) throws XPathFunctionException {
    GenericHumanRoleDAO excludedOwners = null;
    if (args.size() == 0) {
        // Case 1: consider current Task.
        excludedOwners = getExcludedOwnersFromCtx();
    } else if ((args.size() == 1) && (args.get(0) instanceof String)) {
        String taskName = (String) args.get(0);
        if (evalCtx.getTask().getName().equals(taskName)) {
            //Case 2 : TaskName equals to current task, consider current task
            excludedOwners = getExcludedOwnersFromCtx();
        } else if (!StringUtils.isNullOrEmpty(taskName)) {
            // Case 3: Getting specific task. Unsupported.
            log.warn("HumanTask Xpath: getExcludedOwners(\"" + taskName + "\")"
                    + " operation is not currently supported in this version of WSO2 BPS."
                    + " Use getExcludedOwners() instead.");
        }

    }
    return createOrgEntity(excludedOwners);
}
项目:carbon-business-process    文件:JaxpFunctionResolver.java   
public Object evaluate(List args) throws XPathFunctionException {
    String username = "";
    if (args.size() == 0) {
        username = getUserNameFromCtx();
    } else if ((args.size() == 1) && (args.get(0) instanceof String)) {
        String taskName = (String) args.get(0);
        if (evalCtx.getTask().getName().equals(taskName)) {
            //Case 2 : TaskName equals to current task, consider current task
            username = getUserNameFromCtx();
        } else if (!StringUtils.isNullOrEmpty(taskName)) {
            // Case 3: Getting specific task. Unsupported.
            log.warn("HumanTask Xpath: getTaskInitiator(\"" + taskName + "\")"
                    + " operation is not currently supported in this version of WSO2 BPS."
                    + " Use getTaskInitiator() instead.");
        }

    }
    return createHttUser(username);
}
项目:carbon-business-process    文件:JaxpFunctionResolver.java   
public Object evaluate(List args) throws XPathFunctionException {
    GenericHumanRoleDAO stakeholders = null;
    if (args.size() == 0) {
        // Case 1: consider current Task.
        stakeholders = getStakeholdersFromCtx();
    } else if ((args.size() == 1) && (args.get(0) instanceof String)) {
        String taskName = (String) args.get(0);
        if (evalCtx.getTask().getName().equals(taskName)) {
            //Case 2 : TaskName equals to current task, consider current task
            stakeholders = getStakeholdersFromCtx();
        } else if (!StringUtils.isNullOrEmpty(taskName)) {
            // Case 3: Getting specific task. Unsupported.
            log.warn("HumanTask Xpath: getTaskStakeholders(\"" + taskName + "\")"
                    + " operation is not currently supported in this version of WSO2 BPS."
                    + " Use getTaskStakeholders() instead.");
        }

    }
    return createOrgEntity(stakeholders);
}
项目:carbon-business-process    文件:JaxpFunctionResolver.java   
@Override
public Object evaluate(List args) throws XPathFunctionException {
    if (args.size() != 2) {
        throw new HumanTaskRuntimeException("Invalid number of arguments for expression: except");
    }
    if (!(args.get(0) instanceof Node && args.get(1) instanceof Node)) {
        throw new HumanTaskRuntimeException("Invalid arguments for expression: except");
    }
    Node node1 = (Node) args.get(0);
    Node node2 = (Node) args.get(1);
    Set<String> set1 = new HashSet<String>();
    Set<String> set2 = new HashSet<String>();
    parseOrgEntityTypeOrUser(node1, set1);
    parseOrgEntityTypeOrUser(node2, set2);
    set1.retainAll(set2);
    return createOrgEntity(set1);
}
项目:carbon-business-process    文件:JaxpFunctionResolver.java   
@Override
public Object evaluate(List args) throws XPathFunctionException {
    if (args.size() != 2) {
        throw new HumanTaskRuntimeException(
                "Invalid number of arguments: " + args.size() + ", for expression: except");
    }
    if (!(args.get(0) instanceof Node && args.get(1) instanceof Node)) {
        throw new HumanTaskRuntimeException(
                "Invalid arguments :" + args.get(0) + " , " + args.get(1) + " ,  for expression: except");
    }
    Node node1 = (Node) args.get(0);
    Node node2 = (Node) args.get(1);
    Set<String> resoledUsers = new HashSet<String>();
    Set<String> excludedUsers = new HashSet<String>();

    parseOrgEntityTypeOrUser(node1, resoledUsers);
    parseOrgEntityTypeOrUser(node2, excludedUsers);
    resoledUsers.removeAll(excludedUsers);
    return createOrgEntity(resoledUsers);
}
项目:carbon-business-process    文件:JaxpFunctionResolver.java   
@Override
public Object evaluate(List args) throws XPathFunctionException {
    if (args.size() == 0) {
        //Case 1 : Consider current task
        return evalCtx.getTask().getSubTasks().size();
    } else if ((args.size() == 1) && (args.get(0) instanceof String)) {
        String taskName = (String) args.get(0);
        if (evalCtx.getTask().getName().equals(taskName)) {
            //Case 2 : TaskName equals to current task, consider current task
            return evalCtx.getTask().getSubTasks().size();
        } else {
            // Case 3: Getting specific task. Unsupported.
            log.warn("HumanTask Xpath: getCountOfSubTasks(\"" + taskName + "\")"
                    + " operation is not currently supported in this version of WSO2 BPS."
                    + " Use getCountOfSubTasks() instead.");
        }
    }
    return 0;
}
项目:carbon-business-process    文件:JaxpFunctionResolver.java   
@Override
public Object evaluate(List args) throws XPathFunctionException {
    {
        if (args.size() == 1) {
            //Case 1 : Consider current task
            return countSubTasks(args.get(0));
        } else if ((args.size() == 2) && (args.get(1) instanceof String)) {
            String taskName = (String) args.get(1);
            if (evalCtx.getTask().getName().equals(taskName)) {
                //Case 2 : TaskName equals to current task, consider current task
                return countSubTasks(args.get(0));
            } else {
                // Case 3: Getting specific task. Unsupported.
                log.warn("HumanTask Xpath: getCountOfSubTasks(\"" + taskName + "\")"
                        + " operation is not currently supported in this version of WSO2 BPS."
                        + " Use getCountOfSubTasks() instead.");
            }
        } else {
            throw new HumanTaskRuntimeException("Invalid number of arguments : " + args.size()
                    + ", for function getCountOfSubTasksInState()");
        }
        return 0;
    }
}
项目:mulgara    文件:AfnFunctionGroup.java   
public Object eval(List<?> args) throws XPathFunctionException {
  String source = args.get(0).toString();
  int start = ((Number)args.get(1)).intValue();
  int end = ((Number)args.get(2)).intValue();
  // perform boundary checking
  if (start < 0) start = 0;
  int len = source.length();
  if (start > len) {
    start = len;
    end = len;
  }
  if (end > len) end = len;
  if (end < start) end = start;

  return source.substring(start, end);
}
项目:mulgara    文件:FnFunctionGroup.java   
public Object eval(List<?> args) throws XPathFunctionException {
  String source = args.get(0).toString();
  int start = ((Number)args.get(1)).intValue() - 1;
  int end = ((Number)args.get(2)).intValue() + start;
  // perform boundary checking
  int len = source.length();
  if (start < 0) start = 0;
  if (start > len) {
    start = len;
    end = len;
  }
  if (end > len) end = len;
  if (end < start) end = start;

  return source.substring(start, end);
}
项目:mulgara    文件:MulgaraXFunctionGroup.java   
public Object eval(List<?> args) throws XPathFunctionException {
  String str = (String)args.get(0);
  StringBuilder outputString = new StringBuilder();
  try {
    Process proc = Runtime.getRuntime().exec(str);
    proc.getOutputStream().close();
    BufferedReader procStdOut = new BufferedReader(new InputStreamReader(proc.getInputStream()));
    char[] buffer = new char[BUFFER_SIZE];
    int len;
    while ((len = procStdOut.read(buffer)) >= 0) outputString.append(buffer, 0, len);
    procStdOut.close();
    proc.getErrorStream().close();
  } catch (IOException e) {
    throw new XPathFunctionException("I/O error communicating with external process.");
  }
  return outputString.toString();
}
项目:lolxml-common    文件:XPathFunctionRandom.java   
/**
 * Random XPath wrapper. Return depends on the params, as follows:
 * <ul>
 * <li>random(): returns a floating-point number between 0.0 and 1.0.</li>
 * <li>random(num): integer between 0 (inclusive) and num (exclusive).</li>
 * <li>random(nodeset): picks a random node from the set.</li>
 * </ul>
 */
@SuppressWarnings("rawtypes")
@Override
public Object evaluate(List params) throws XPathFunctionException {
    if (params==null || params.size() ==0){
        return random.nextDouble();
    }
    Object oParam = params.get(0);
    if (oParam instanceof Double){
        double d= (double) random.nextInt((int)Math.round(((Double)oParam)));
        return d;
    }
    if (oParam instanceof NodeList){
        NodeList nl = (NodeList)oParam;
        return nl.item(random.nextInt(nl.getLength()));
    }
    return null;
}
项目:swingx-ws    文件:AbstractFunction.java   
protected Number getNumberParam(Object o) throws XPathFunctionException {
    // perform conversions
    Number output = null;
    try {
        if (o instanceof String) output = Double.parseDouble((String) o);
        else if (o instanceof Double) output = (Double)o;
        else if (o instanceof NodeList) {
            NodeList list = (NodeList) o;
            Node node = list.item(0);
            output = Double.parseDouble(node.getTextContent());
        } else {
            throw new XPathFunctionException("Could not convert argument type");
        }
    } catch (NumberFormatException ex) {
        throw new XPathFunctionException(ex);
    }
    return output;
}
项目:griffon-swingx-ws-plugin    文件:AbstractFunction.java   
protected Number getNumberParam(Object o) throws XPathFunctionException {
    // perform conversions
    Number output = null;
    try {
        if (o instanceof String) output = Double.parseDouble((String) o);
        else if (o instanceof Double) output = (Double)o;
        else if (o instanceof NodeList) {
            NodeList list = (NodeList) o;
            Node node = list.item(0);
            output = Double.parseDouble(node.getTextContent());
        } else {
            throw new XPathFunctionException("Could not convert argument type");
        }
    } catch (NumberFormatException ex) {
        throw new XPathFunctionException(ex);
    }
    return output;
}
项目:windup    文件:XmlFileFunctionResolver.java   
@Override
public XPathFunction resolveFunction(final QName functionName, final int arity)
{
    if (functionMap.containsKey(functionName))
    {
        return new XPathFunction()
        {
            @Override
            public Object evaluate(List args) throws XPathFunctionException
            {
                return functionMap.get(functionName).evaluate(args);
            }
        };
    }
    return originalResolver.resolveFunction(functionName, arity);
}
项目:javify    文件:CurrentFunction.java   
public Object evaluate(List args)
  throws XPathFunctionException
{
  // We can't do anything useful here.
  // So much for the JAXP API...
  return Collections.EMPTY_SET;
}
项目:Camel    文件:XPathBuilder.java   
private XPathFunction createBodyFunction() {
    return new XPathFunction() {
        @SuppressWarnings("rawtypes")
        public Object evaluate(List list) throws XPathFunctionException {
            return exchange.get().getIn().getBody();
        }
    };
}
项目:Camel    文件:XPathBuilder.java   
private XPathFunction createHeaderFunction() {
    return new XPathFunction() {
        @SuppressWarnings("rawtypes")
        public Object evaluate(List list) throws XPathFunctionException {
            if (!list.isEmpty()) {
                Object value = list.get(0);
                if (value != null) {
                    String text = exchange.get().getContext().getTypeConverter().convertTo(String.class, value);
                    return exchange.get().getIn().getHeader(text);
                }
            }
            return null;
        }
    };
}
项目:Camel    文件:XPathBuilder.java   
private XPathFunction createOutBodyFunction() {
    return new XPathFunction() {
        @SuppressWarnings("rawtypes")
        public Object evaluate(List list) throws XPathFunctionException {
            if (exchange.get() != null && exchange.get().hasOut()) {
                return exchange.get().getOut().getBody();
            }
            return null;
        }
    };
}
项目:Camel    文件:XPathBuilder.java   
private XPathFunction createOutHeaderFunction() {
    return new XPathFunction() {
        @SuppressWarnings("rawtypes")
        public Object evaluate(List list) throws XPathFunctionException {
            if (exchange.get() != null && !list.isEmpty()) {
                Object value = list.get(0);
                if (value != null) {
                    String text = exchange.get().getContext().getTypeConverter().convertTo(String.class, value);
                    return exchange.get().getOut().getHeader(text);
                }
            }
            return null;
        }
    };
}
项目:kc-rice    文件:XStreamSafeSearchFunction.java   
public Object evaluate(List parameters) throws XPathFunctionException {
    String xPathExpression = getXPathExpressionParameter(parameters);
    evaluator.setXpath(xpath);
    //Node rootSearchNode = getRootSearchNodeParameter(parameters);
    try {
        return evaluator.evaluate(xPathExpression, rootNode);
    } catch (XPathExpressionException e) {
        throw new XPathFunctionException(e);
    }
}
项目:kc-rice    文件:XStreamSafeSearchFunction.java   
private String getXPathExpressionParameter(List parameters) throws XPathFunctionException {
    if (parameters.size() < 1) {
        throw new XPathFunctionException("First parameter must be an XPath expression.");
    }
    if (!(parameters.get(0) instanceof String)) {
        throw new XPathFunctionException("First parameter must be an XPath expression String");
    }
    return (String)parameters.get(0);
}
项目:jvm-stm    文件:CurrentFunction.java   
public Object evaluate(List args)
  throws XPathFunctionException
{
  // We can't do anything useful here.
  // So much for the JAXP API...
  return Collections.EMPTY_SET;
}
项目:AJ    文件:InBlacklistFunction.java   
@Override
public Object evaluate(List args) throws XPathFunctionException {
  NodeList nodeList = (NodeList) args.get(0);

  for (int i = 0; i < nodeList.getLength(); i++) {
    Node item = nodeList.item(i);
    for (String blacklistedMember : Property.BLACKLIST.getArray()) {
      if (eq(item.getTextContent(), blacklistedMember)) {
        return true;
      }
    }
  }

  return false;
}
项目:jlibs    文件:TestFunctionResolver.java   
@Override
public Object evaluate(List args) throws XPathFunctionException{
    char[] ch = ((String)args.get(0)).toCharArray();
    for(int i=0, j=ch.length-1; i<j; i++, j--){
        char temp = ch[i];
        ch[i] = ch[j];
        ch[j] = temp;
    }
    return new String(ch);
}
项目:jlibs    文件:Functions.java   
@Override
public Object evaluate(Object... args){
    try{
        return xpathFunction.evaluate(Arrays.asList(args));
    }catch(XPathFunctionException ex){
        throw new RuntimeException(ex);
    }
}
项目:LoboEvolution    文件:EscapeUri.java   
@Override
public Object evaluate(List args) throws XPathFunctionException {
    try {
        return URLEncoder.encode(getStringParam(args.get(0)), "UTF-8");
    } catch (Exception e) {
        throw new XPathFunctionException(e);
    }
}
项目:LoboEvolution    文件:Replace.java   
@Override
public Object evaluate(List args) throws XPathFunctionException {
    String s = getStringParam(args.get(0));
    String pattern = getStringParam(args.get(1));
    String replace = getStringParam(args.get(2));
    return s.replaceAll(pattern, replace);
}
项目:LoboEvolution    文件:EqualsIgnoreCase.java   
@Override
public Object evaluate(List args) throws XPathFunctionException {
    NodeList nodes = (NodeList) args.get(0);
    String s1 = nodes.getLength() > 0 ? nodes.item(0).getLocalName() : "";
    String s2 = getStringParam(args.get(1));
    return s1.equalsIgnoreCase(s2);
}
项目:carbon-business-process    文件:JaxpFunctionResolver.java   
public Object evaluate(List args) throws XPathFunctionException {
    GenericHumanRoleDAO potentialOwners = null;
    TaskDAO taskDAO = evalCtx.getTask();
    if (args.size() == 0) {
        // Case 1: consider current Task.
        potentialOwners = getPotentialOwnersFromCtx();
    } else if (taskDAO != null && (args.size() == 1) && (args.get(0) instanceof String)) {
        String taskName = (String) args.get(0);
        if (taskDAO.getName().equals(taskName)) {
            //Case 2: TaskName equals to current task, consider current task
            potentialOwners = getPotentialOwnersFromCtx();
        } else if (!StringUtils.isNullOrEmpty(taskName)) {
            // Case 3: Getting specific task. Unsupported.
            log.warn("HumanTask Xpath: getPotentialOwners(\"" + taskName + "\")"
                    + " operation is not currently supported in this version of WSO2 BPS."
                    + " Use getPotentialOwners() instead.");
            // We can evaluate only role based and literal based people assignments only. expression based
            // people eval will not work here.
            // Also we can obtain only the HumanTaskBaseConfiguration, but without taskDAO we can't build
            // eval context for that task configuration.
        }

    }
    // else is an Error case, so potentialOwners is null. createOrgEntity will generate an empty
    // htt:organizationalEntity element in such a scenario..

    return createOrgEntity(potentialOwners);
}
项目:carbon-business-process    文件:JaxpFunctionResolver.java   
@Override
public Object evaluate(List args) throws XPathFunctionException {
    if (args.size() != 2) {
        throw new HumanTaskRuntimeException("Invalid number of arguments for expression: except");
    }
    if (!(args.get(0) instanceof Node && args.get(1) instanceof Node)) {
        throw new HumanTaskRuntimeException("Invalid arguments for expression: except");
    }
    Node node1 = (Node) args.get(0);
    Node node2 = (Node) args.get(1);
    Set<String> resoledUsers = new HashSet<String>();
    parseOrgEntityTypeOrUser(node1, resoledUsers);
    parseOrgEntityTypeOrUser(node2, resoledUsers);
    return createOrgEntity(resoledUsers);
}
项目:carbon-business-process    文件:JaxpFunctionResolver.java   
@Override
public Object evaluate(List args) throws XPathFunctionException {
    if (args.size() == 1 && args.get(0) instanceof ArrayList) {
        try {
            Map<String, Integer> frequencyMap = generateFrequencyMap((ArrayList) args.get(0));
            boolean tie = false;
            String result = "";
            int least = Integer.MAX_VALUE;
            for (Map.Entry<String, Integer> entry : frequencyMap.entrySet()) {
                //check if the minimum
                if (entry.getValue() < least) {
                    //new least occurrence
                    least = entry.getValue();
                    result = entry.getKey();
                    tie = false;
                } else if (entry.getValue() == least) {
                    //a tie
                    tie = true;
                }
            }
            if (tie) {
                return "";
            } else {
                return result;
            }
        } catch (HumanTaskRuntimeException e) {
            throw new HumanTaskRuntimeException(
                    "Error in processing arguments" + args.get(0) + " for function leastFrequentOccurence()",
                    e);
        }

    } else {
        throw new HumanTaskRuntimeException(
                "Invalid arguments:" + args + ", for function leastFrequentOccurence()");
    }
}
项目:carbon-business-process    文件:JaxpFunctionResolver.java   
@Override
public Object evaluate(List args) throws XPathFunctionException {
    if (args.size() == 1 && args.get(0) instanceof ArrayList) {
        try {
            Map<String, Integer> frequencyMap = generateFrequencyMap((ArrayList) args.get(0));
            boolean tie = false;
            int max = Integer.MIN_VALUE;
            String result = "";
            for (Map.Entry<String, Integer> entry : frequencyMap.entrySet()) {
                if (entry.getValue() > max) {
                    //new max
                    max = entry.getValue();
                    result = entry.getKey();
                    tie = false;
                } else if (entry.getValue() == max) {
                    //a tie
                    tie = true;
                }

            }
            if (tie) {
                return "";
            } else {
                return result;
            }

        } catch (HumanTaskRuntimeException e) {
            throw new HumanTaskRuntimeException(
                    "Error in processing arguments for function mostFrequentOccurence()", e);
        }
    } else {
        throw new HumanTaskRuntimeException("Invalid arguments for function mostFrequentOccurence()");
    }
}