001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2011 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * Sonar is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * Sonar is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public
017 * License along with Sonar; if not, write to the Free Software
018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
019 */
020 package org.sonar.wsclient.services;
021
022 import java.util.Date;
023 import java.util.Set;
024
025 /**
026 * Compatibility layer between GWT and plain Java.
027 * Well, this is bad, because code is not type-safe, so all unmarshallers also,
028 * but this allows to remove duplications between sonar-gwt-api and sonar-ws-client.
029 */
030 public abstract class WSUtils {
031
032 private static WSUtils INSTANCE = null;
033
034 public static void setInstance(WSUtils utils) {
035 INSTANCE = utils;
036 }
037
038 public static WSUtils getINSTANCE() {
039 return INSTANCE;
040 }
041
042 public abstract String format(Date date, String format);
043
044 public abstract String encodeUrl(String url);
045
046 /**
047 * @return value of specified field from specified JSON object,
048 * or <code>null</code> if field does not exist
049 */
050 public abstract Object getField(Object json, String field);
051
052 /**
053 * @return String value of specified field from specified JSON object,
054 * or <code>null</code> if field does not exist
055 */
056 public abstract String getString(Object json, String field);
057
058 /**
059 * @return Boolean value of specified field from specified JSON object,
060 * or <code>null</code> if field does not exist
061 */
062 public abstract Boolean getBoolean(Object json, String field);
063
064 /**
065 * @return Integer value of specified field from specified JSON object,
066 * or <code>null</code> if field does not exist
067 */
068 public abstract Integer getInteger(Object json, String field);
069
070 /**
071 * @return Double value of specified field from specified JSON object,
072 * or <code>null</code> if field does not exist
073 */
074 public abstract Double getDouble(Object json, String field);
075
076 /**
077 * @return Long value of specified field from specified JSON object,
078 * or <code>null</code> if field does not exist
079 */
080 public abstract Long getLong(Object json, String field);
081
082 /**
083 * @return Date value of specified field from specified JSON object,
084 * or <code>null</code> if field does not exist
085 */
086 public abstract Date getDateTime(Object json, String field);
087
088 /**
089 * @return size of specified JSON array
090 */
091 public abstract int getArraySize(Object array);
092
093 /**
094 * @return element from specified JSON array
095 */
096 public abstract Object getArrayElement(Object array, int i);
097
098 /**
099 * @return JSON object
100 */
101 public abstract Object parse(String jsonStr);
102
103 /**
104 * @return field names in specified JSON object
105 */
106 public abstract Set<String> getFields(Object json);
107
108 }