Package net.sf.json

Examples of net.sf.json.JSONFunction


  private JSONUtils() {
  }

  public static JSONFunction stringSerializedFunction(final String func) {
    return new JSONFunction(func) {
      @Override
      public String getText() {
        return "\"" + func + "\"";
      }
View Full Code Here


            target.appendChild(value.toString());
        } else if (JSONUtils.isFunction(value)) {
            if (value instanceof String) {
                value = JSONFunction.parse((String) value);
            }
            JSONFunction func = (JSONFunction) value;
            if (isTypeHintsEnabled()) {
                target.addAttribute(new Attribute(addJsonPrefix("type"), JSONTypes.FUNCTION));
            }
            String params = ArrayUtils.toString(func.getParams());
            params = params.substring(1);
            params = params.substring(0, params.length() - 1);
            target.addAttribute(new Attribute(addJsonPrefix("params"), params));
            target.appendChild(new Text("<![CDATA[" + func.getText() + "]]>"));
        } else if (JSONUtils.isString(value)) {
            if (isTypeHintsEnabled()) {
                target.addAttribute(new Attribute(addJsonPrefix("type"), JSONTypes.STRING));
            }
            target.appendChild(value.toString());
View Full Code Here

            if (isFunction(element)) {
                Attribute paramsAttribute = element.getAttribute(addJsonPrefix("params"));
                String[] params = null;
                String text = element.getValue();
                params = StringUtils.split(paramsAttribute.getValue(), ",");
                jsonArray.element(new JSONFunction(params, text));
                return;
            } else {
                jsonArray.element(simplifyValue(null, processElement(element, type)));
                return;
            }
        }

        boolean classProcessed = false;
        if (clazz != null) {
            if (clazz.compareToIgnoreCase(JSONTypes.ARRAY) == 0) {
                jsonArray.element(processArrayElement(element, type));
                classProcessed = true;
            } else if (clazz.compareToIgnoreCase(JSONTypes.OBJECT) == 0) {
                jsonArray.element(simplifyValue(null, processObjectElement(element, type)));
                classProcessed = true;
            }
        }
        if (!classProcessed) {
            if (type.compareToIgnoreCase(JSONTypes.BOOLEAN) == 0) {
                jsonArray.element(Boolean.valueOf(element.getValue()));
            } else if (type.compareToIgnoreCase(JSONTypes.NUMBER) == 0) {
                // try integer first
                try {
                    jsonArray.element(Integer.valueOf(element.getValue()));
                } catch (NumberFormatException e) {
                    jsonArray.element(Double.valueOf(element.getValue()));
                }
            } else if (type.compareToIgnoreCase(JSONTypes.INTEGER) == 0) {
                jsonArray.element(Integer.valueOf(element.getValue()));
            } else if (type.compareToIgnoreCase(JSONTypes.FLOAT) == 0) {
                jsonArray.element(Double.valueOf(element.getValue()));
            } else if (type.compareToIgnoreCase(JSONTypes.FUNCTION) == 0) {
                String[] params = null;
                String text = element.getValue();
                Attribute paramsAttribute = element.getAttribute(addJsonPrefix("params"));
                if (paramsAttribute != null) {
                    params = StringUtils.split(paramsAttribute.getValue(), ",");
                }
                jsonArray.element(new JSONFunction(params, text));
            } else if (type.compareToIgnoreCase(JSONTypes.STRING) == 0) {
                // see if by any chance has a 'params' attribute
                Attribute paramsAttribute = element.getAttribute(addJsonPrefix("params"));
                if (paramsAttribute != null) {
                    String[] params = null;
                    String text = element.getValue();
                    params = StringUtils.split(paramsAttribute.getValue(), ",");
                    jsonArray.element(new JSONFunction(params, text));
                } else {
                    if (isArray(element, false)) {
                        jsonArray.element(processArrayElement(element, defaultType));
                    } else if (isObject(element, false)) {
                        jsonArray.element(simplifyValue(null, processObjectElement(element, defaultType)));
View Full Code Here

        } else if (element.getAttributeCount() > 0) {
            if (isFunction(element)) {
                Attribute paramsAttribute = element.getAttribute(addJsonPrefix("params"));
                String text = element.getValue();
                String[] params = StringUtils.split(paramsAttribute.getValue(), ",");
                setOrAccumulate(jsonObject, key, new JSONFunction(params, text));
                return;
            }/*
             * else{ setOrAccumulate( jsonObject, key, simplifyValue( jsonObject,
       * processElement( element, type ) ) ); return; }
       */
        }

        boolean classProcessed = false;
        if (clazz != null) {
            if (clazz.compareToIgnoreCase(JSONTypes.ARRAY) == 0) {
                setOrAccumulate(jsonObject, key, processArrayElement(element, type));
                classProcessed = true;
            } else if (clazz.compareToIgnoreCase(JSONTypes.OBJECT) == 0) {
                setOrAccumulate(jsonObject, key, simplifyValue(jsonObject, processObjectElement(element, type)));
                classProcessed = true;
            }
        }
        if (!classProcessed) {
            if (type.compareToIgnoreCase(JSONTypes.BOOLEAN) == 0) {
                setOrAccumulate(jsonObject, key, Boolean.valueOf(element.getValue()));
            } else if (type.compareToIgnoreCase(JSONTypes.NUMBER) == 0) {
                // try integer first
                try {
                    setOrAccumulate(jsonObject, key, Integer.valueOf(element.getValue()));
                } catch (NumberFormatException e) {
                    try {
                        setOrAccumulate(jsonObject, key, Double.valueOf(element.getValue()));
                    } catch (NumberFormatException e1) {
                        SoapUI.log.debug("Unable to parse element " + elementName + " as number: " + element.getValue());
                    }
                }
            } else if (type.compareToIgnoreCase(JSONTypes.INTEGER) == 0) {
                setOrAccumulate(jsonObject, key, Integer.valueOf(element.getValue()));
            } else if (type.compareToIgnoreCase(JSONTypes.FLOAT) == 0) {
                setOrAccumulate(jsonObject, key, Double.valueOf(element.getValue()));
            } else if (type.compareToIgnoreCase(JSONTypes.FUNCTION) == 0) {
                String[] params = null;
                String text = element.getValue();
                Attribute paramsAttribute = element.getAttribute(addJsonPrefix("params"));
                if (paramsAttribute != null) {
                    params = StringUtils.split(paramsAttribute.getValue(), ",");
                }
                setOrAccumulate(jsonObject, key, new JSONFunction(params, text));
            } else if (type.compareToIgnoreCase(JSONTypes.STRING) == 0) {
                // see if by any chance has a 'params' attribute
                Attribute paramsAttribute = element.getAttribute(addJsonPrefix("params"));
                if (paramsAttribute != null) {
                    String[] params = null;
                    String text = element.getValue();
                    params = StringUtils.split(paramsAttribute.getValue(), ",");
                    setOrAccumulate(jsonObject, key, new JSONFunction(params, text));
                } else {
                    if (isArray(element, false)) {
                        setOrAccumulate(jsonObject, key, processArrayElement(element, defaultType));
                    } else if (isObject(element, false)) {
                        setOrAccumulate(jsonObject, key,
View Full Code Here

  }

  private void putFunction(final String keyName, final String body,
      final String[] parametersNames) {

    final JSONFunction function;

    if (parametersNames != null && parametersNames.length > 0) {
      function = new JSONFunction(parametersNames, body);
    } else {
      function = new JSONFunction(body);
    }

    json.put(keyName, function);
  }
View Full Code Here

  }

  private void putFunction(final String keyName, final String body, final String[] parametersNames)
  {

    final JSONFunction function;

    if (parametersNames != null && parametersNames.length > 0)
    {
      function = new JSONFunction(parametersNames, body);
    }
    else
    {
      function = new JSONFunction(body);
    }

    json.put(keyName, function);
  }
View Full Code Here

TOP

Related Classes of net.sf.json.JSONFunction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.