001 /*
002 * Sonar, open source software quality management tool.
003 * Copyright (C) 2008-2012 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 value of a string field from specified JSON object,
054 * or string representation of a numeric field,
055 * or <code>null</code> if field does not exist
056 */
057 public abstract String getString(Object json, String field);
058
059 /**
060 * @return Boolean value of specified field from specified JSON object,
061 * or <code>null</code> if field does not exist
062 */
063 public abstract Boolean getBoolean(Object json, String field);
064
065 /**
066 * @return Integer value of specified field from specified JSON object,
067 * or <code>null</code> if field does not exist
068 */
069 public abstract Integer getInteger(Object json, String field);
070
071 /**
072 * @return Double value of specified field from specified JSON object,
073 * or <code>null</code> if field does not exist
074 */
075 public abstract Double getDouble(Object json, String field);
076
077 /**
078 * @return Long value of specified field from specified JSON object,
079 * or <code>null</code> if field does not exist
080 */
081 public abstract Long getLong(Object json, String field);
082
083 /**
084 * @return Date value of specified field from specified JSON object,
085 * or <code>null</code> if field does not exist
086 */
087 public abstract Date getDateTime(Object json, String field);
088
089 /**
090 * @return size of specified JSON array
091 */
092 public abstract int getArraySize(Object array);
093
094 /**
095 * @return element from specified JSON array
096 */
097 public abstract Object getArrayElement(Object array, int i);
098
099 /**
100 * @return JSON object
101 */
102 public abstract Object parse(String jsonStr);
103
104 /**
105 * @return field names in specified JSON object
106 */
107 public abstract Set<String> getFields(Object json);
108
109 }