All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.wsclient.services.WSUtils Maven / Gradle / Ivy

There is a newer version: 5.1
Show newest version
/*
 * Sonar, open source software quality management tool.
 * Copyright (C) 2008-2012 SonarSource
 * mailto:contact AT sonarsource DOT com
 *
 * Sonar is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * Sonar is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Sonar; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
 */
package org.sonar.wsclient.services;

import java.util.Date;
import java.util.Set;

/**
 * Compatibility layer between GWT and plain Java.
 * Well, this is bad, because code is not type-safe, so all unmarshallers also,
 * but this allows to remove duplications between sonar-gwt-api and sonar-ws-client.
 */
public abstract class WSUtils {

  private static WSUtils instance = null;

  public static void setInstance(WSUtils utils) {
    instance = utils;
  }

  public static WSUtils getINSTANCE() {
    return instance;
  }

  public abstract String format(Date date, String format);

  public abstract String encodeUrl(String url);

  /**
   * @return value of specified field from specified JSON object,
   *         or null if field does not exist
   */
  public abstract Object getField(Object json, String field);

  /**
   * @return value of a string field from specified JSON object,
   *         or string representation of a numeric field,
   *         or null if field does not exist
   */
  public abstract String getString(Object json, String field);

  /**
   * @return Boolean value of specified field from specified JSON object,
   *         or null if field does not exist
   */
  public abstract Boolean getBoolean(Object json, String field);

  /**
   * @return Integer value of specified field from specified JSON object,
   *         or null if field does not exist
   */
  public abstract Integer getInteger(Object json, String field);

  /**
   * @return Double value of specified field from specified JSON object,
   *         or null if field does not exist
   */
  public abstract Double getDouble(Object json, String field);

  /**
   * @return Long value of specified field from specified JSON object,
   *         or null if field does not exist
   */
  public abstract Long getLong(Object json, String field);

  /**
   * @return Date value of specified field from specified JSON object,
   *         or null if field does not exist
   */
  public abstract Date getDateTime(Object json, String field);

  /**
   * @return size of specified JSON array
   */
  public abstract int getArraySize(Object array);

  /**
   * @return element from specified JSON array
   */
  public abstract Object getArrayElement(Object array, int i);

  /**
   * @return JSON object
   */
  public abstract Object parse(String jsonStr);

  /**
   * @return field names in specified JSON object
   */
  public abstract Set getFields(Object json);

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy