Example usage for com.google.gwt.json.client JSONValue isObject

List of usage examples for com.google.gwt.json.client JSONValue isObject

Introduction

In this page you can find the example usage for com.google.gwt.json.client JSONValue isObject.

Prototype

public JSONObject isObject() 

Source Link

Document

Returns non-null if this JSONValue is really a JSONObject.

Usage

From source file:lh.api.showcase.client.operations.JsonParserFlightUtils.java

License:Apache License

private static JSONNumber getNumberIfExist(JSONObject jsObj, String object, String property) {
    JSONValue jsObjectVal = jsObj.get(object);
    JSONNumber jsNum = null;/* ww w .  j a  v a 2  s  .c om*/
    if (jsObjectVal != null) {
        JSONValue jsObjectPropVal = jsObjectVal.isObject().get(property);
        if (jsObjectPropVal != null) {
            jsNum = jsObjectPropVal.isNumber();
        }
    }
    return jsNum;
}

From source file:lh.api.showcase.client.operations.JsonParserFlightUtils.java

License:Apache License

private static JSONString getStringIfExist(JSONObject jsObj, String object, String alternativeObject,
        String property) {/*from  ww  w .  j  av  a  2 s  .com*/
    JSONValue jsVal = jsObj.get(object);
    if (jsVal == null) {
        jsVal = jsObj.get(alternativeObject);
    }
    JSONString jsStr = null;
    if (jsVal != null) {
        JSONValue jsObjectPropVal = jsVal.isObject().get(property);
        if (jsObjectPropVal != null) {
            jsStr = jsObjectPropVal.isString();
        }
    }
    return jsStr;
}

From source file:lh.api.showcase.client.operations.schedules.SchedulesResponseJsonParser.java

License:Apache License

@Override
public List<Schedule> parse(String json) {

    List<Schedule> ret = new ArrayList<Schedule>();

    JSONValue jsv = JSONParser.parseStrict(json);
    JSONObject jobj = jsv.isObject();

    JSONValue jsScheduleResourceVal = jobj.get("ScheduleResource");
    JSONObject jsScheduleResourceObj = jsScheduleResourceVal.isObject();

    JSONValue jsScheduleVal = jsScheduleResourceObj.get("Schedule");
    JSONObject jsScheduleObj = jsScheduleVal.isObject();

    if (jsScheduleObj == null) {
        JSONArray jarraySchedule = jsScheduleVal.isArray();
        if (jarraySchedule != null) {
            for (int i = 0; i < jarraySchedule.size(); ++i) {
                JSONObject jsScheduleObject = jarraySchedule.get(i).isObject();
                Schedule schedule = getScheduleInfo(jsScheduleObject);
                if (schedule != null) {
                    ret.add(schedule);// w  w w  . j  a  v a 2s .c o m
                }
            }
        }
    } else {
        Schedule schedule = getScheduleInfo(jsScheduleObj);
        if (schedule != null) {
            ret.add(schedule);
        }
    }
    return ret;
}

From source file:lh.api.showcase.client.operations.schedules.SchedulesResponseJsonParser.java

License:Apache License

private Schedule getScheduleInfo(JSONObject jsScheduleObj) {

    if (jsScheduleObj == null) {
        return null;
    }/*  w w w  .  java2 s .  com*/
    JSONValue jsTotalJourneyVal = jsScheduleObj.get("TotalJourney");
    JSONObject jsTotalJourneyObj = jsTotalJourneyVal.isObject();

    JSONString jsDurationStr = jsTotalJourneyObj.get("Duration").isString();

    List<Flight> flightList = new ArrayList<Flight>();
    JSONValue jsFlightVal = jsScheduleObj.get("Flight");
    JSONObject jsFlightObj = jsFlightVal.isObject();
    if (jsFlightObj == null) {
        JSONArray jarrayFlight = jsFlightVal.isArray();
        if (jarrayFlight != null) {
            for (int i = 0; i < jarrayFlight.size(); ++i) {
                JSONObject jsFlightObject = jarrayFlight.get(i).isObject();
                Flight flight = JsonParserFlightUtils.getFlightInfo(jsFlightObject);
                if (flight != null) {
                    flightList.add(flight);
                }
            }
        }
    } else {
        Flight flight = JsonParserFlightUtils.getFlightInfo(jsFlightObj);
        if (flight != null) {
            flightList.add(flight);
        }
    }

    return new Schedule((jsDurationStr == null) ? ("") : (jsDurationStr.toString().replace("\"", "")),
            flightList);
}

From source file:lh.api.showcase.client.referencedata.aircraft.AircraftResponseJsonParser.java

License:Apache License

@Override
public List<Aircraft> parse(String json) {

    List<Aircraft> ret = new ArrayList<Aircraft>();

    JSONValue jsv = JSONParser.parseStrict(json);
    JSONObject jobj = jsv.isObject();

    JSONValue jsAircraftResourceVal = jobj.get("AircraftResource");
    JSONObject jsAircraftResourceObj = jsAircraftResourceVal.isObject();

    JSONValue jsAircraftSummariesVal = jsAircraftResourceObj.get("AircraftSummaries");
    JSONObject jsAircraftSummariesObj = jsAircraftSummariesVal.isObject();

    JSONValue jsAircraftSummaryVal = jsAircraftSummariesObj.get("AircraftSummary");
    JSONObject jsAircraftSummaryObj = jsAircraftSummaryVal.isObject();

    if (jsAircraftSummaryObj == null) {
        JSONArray jarrayAircraftSummary = jsAircraftSummaryVal.isArray();
        if (jarrayAircraftSummary != null) {
            for (int i = 0; i < jarrayAircraftSummary.size(); ++i) {
                JSONObject jsTmpAircraftSummaryObject = jarrayAircraftSummary.get(i).isObject();
                if (jsTmpAircraftSummaryObject == null) {
                    continue;
                }/*from  w w  w . ja v  a2  s . com*/
                Aircraft Aircraft = getAircraftInfo(jsTmpAircraftSummaryObject);
                if (Aircraft != null) {
                    ret.add(Aircraft);
                }
            }
        }
    } else {
        Aircraft Aircraft = getAircraftInfo(jsAircraftSummaryObj);
        if (Aircraft != null) {
            ret.add(Aircraft);
        }
    }
    return ret;
}

From source file:lh.api.showcase.client.referencedata.airlines.AirlinesResponseJsonParser.java

License:Apache License

@Override
public List<Airline> parse(String json) {

    List<Airline> ret = new ArrayList<Airline>();

    JSONValue jsv = JSONParser.parseStrict(json);
    JSONObject jobj = jsv.isObject();

    JSONValue jsAirlineResourceVal = jobj.get("AirlineResource");
    JSONObject jsAirlineResourceObj = jsAirlineResourceVal.isObject();

    JSONValue jsAirlinesVal = jsAirlineResourceObj.get("Airlines");
    JSONObject jsAirlinesObj = jsAirlinesVal.isObject();

    JSONValue jsAirlineVal = jsAirlinesObj.get("Airline");
    JSONObject jsAirlineObj = jsAirlineVal.isObject();

    if (jsAirlineObj == null) {
        JSONArray jarrayAirlines = jsAirlineVal.isArray();
        if (jarrayAirlines != null) {
            for (int i = 0; i < jarrayAirlines.size(); ++i) {
                JSONObject jsAirlineObject = jarrayAirlines.get(i).isObject();
                if (jsAirlineObject == null) {
                    continue;
                }//from   w w  w.  ja  v  a 2  s.  c o  m
                Airline airline = getAirlineInfo(jsAirlineObject);
                if (airline != null) {
                    ret.add(airline);
                }
            }
        }
    } else {
        Airline airline = getAirlineInfo(jsAirlineObj);
        if (airline != null) {
            ret.add(airline);
        }
    }
    return ret;
}

From source file:lh.api.showcase.client.referencedata.airlines.AirlinesResponseJsonParser.java

License:Apache License

private Airline getAirlineInfo(JSONObject jsAirlineObj) {

    JSONValue jsAirlineIdVal = jsAirlineObj.get("AirlineID");
    JSONValue jsAirlineIdIcaoVal = jsAirlineObj.get("AirlineID_ICAO");

    if (jsAirlineIdVal == null || jsAirlineIdIcaoVal == null) {
        return null;
    }//from   w w  w .j  a v a2  s .c  o  m
    JSONString jsAirlineIdStr = jsAirlineIdVal.isString();
    JSONString jsAirlineIdIcaoStr = jsAirlineIdIcaoVal.isString();

    JSONObject jsNamesObj = jsAirlineObj.get("Names").isObject();

    JSONValue jsOtherIdsVal = jsAirlineObj.get("OtherIDs");
    JSONObject jsOtherIdsObj = null;
    if (jsOtherIdsVal != null) {
        jsOtherIdsObj = jsOtherIdsVal.isObject();
    }

    return new Airline((jsAirlineIdStr == null) ? ("") : (jsAirlineIdStr.toString().replace("\"", "")),
            (jsAirlineIdIcaoStr == null) ? ("") : (jsAirlineIdIcaoStr.toString().replace("\"", "")),
            getOtherIDsInfo(jsOtherIdsObj), JsonParserUtils.getNamesMap(jsNamesObj));

}

From source file:lh.api.showcase.client.referencedata.airlines.AirlinesResponseJsonParser.java

License:Apache License

public Set<String> getOtherIDsInfo(JSONObject jsOtherIdsObj) {

    if (jsOtherIdsObj == null) {
        return null;
    }//from  w  w w  .ja va 2s  . co  m
    Set<String> res = new HashSet<String>();

    JSONValue jsOtherIdVal = jsOtherIdsObj.get("OtherID");
    JSONObject jsOtherIdObj = jsOtherIdVal.isObject();

    if (jsOtherIdObj == null) {

        JSONArray jsOtherIdArray = jsOtherIdVal.isArray();
        if (jsOtherIdArray != null) {
            for (int i = 0; i < jsOtherIdArray.size(); ++i) {

                JSONObject jsTmpOtherIdObj = jsOtherIdArray.get(i).isObject();
                if (jsTmpOtherIdObj == null) {
                    continue;
                }
                String oid = getOtherIDInfo(jsTmpOtherIdObj);
                if (oid != null) {
                    res.add(oid);
                }
            }
        }
    } else {
        String oid = getOtherIDInfo(jsOtherIdObj);
        if (oid != null) {
            res.add(oid);
        }
    }
    return res;
}

From source file:lh.api.showcase.client.referencedata.airports.AirportsResponseJsonParser.java

License:Apache License

@Override
public List<Airport> parse(String json) {

    List<Airport> ret = new ArrayList<Airport>();

    JSONValue jsv = JSONParser.parseStrict(json);
    JSONObject jobj = jsv.isObject();

    JSONValue jsAirportResourceVal = jobj.get("AirportResource");
    JSONObject jsAirportResourceObj = jsAirportResourceVal.isObject();

    JSONValue jsAirportsVal = jsAirportResourceObj.get("Airports");
    JSONObject jsAirportsObj = jsAirportsVal.isObject();

    JSONValue jsAirportVal = jsAirportsObj.get("Airport");
    JSONObject jsAirportObj = jsAirportVal.isObject();

    if (jsAirportObj == null) {
        JSONArray jarrayAirports = jsAirportVal.isArray();
        if (jarrayAirports != null) {
            for (int i = 0; i < jarrayAirports.size(); ++i) {
                JSONObject jsAirportObject = jarrayAirports.get(i).isObject();
                if (jsAirportObject == null) {
                    continue;
                }/*from  ww  w  .ja  v a  2s.  c  om*/
                Airport airport = JsonParserUtils.getAirportInfo(jsAirportObject);
                if (airport != null) {
                    ret.add(airport);
                }
            }
        }
    } else {
        Airport airport = JsonParserUtils.getAirportInfo(jsAirportObj);
        if (airport != null) {
            ret.add(airport);
        }
    }
    return ret;
}

From source file:lh.api.showcase.client.referencedata.cities.CitiesResponseJsonParser.java

License:Apache License

@Override
public ArrayList<City> parse(String json) {

    ArrayList<City> ret = new ArrayList<City>();

    JSONValue jsv = JSONParser.parseStrict(json);
    JSONObject jobj = jsv.isObject();

    JSONValue jsCityResourceVal = jobj.get("CityResource");
    JSONObject jsCityResourceObj = jsCityResourceVal.isObject();

    JSONValue jsCitiesVal = jsCityResourceObj.get("Cities");
    JSONObject jsCitiesObj = jsCitiesVal.isObject();

    JSONValue jsCityVal = jsCitiesObj.get("City");
    JSONObject jsCityObj = jsCityVal.isObject();

    if (jsCityObj == null) {
        JSONArray jarrayCities = jsCityVal.isArray();
        if (jarrayCities != null) {
            for (int i = 0; i < jarrayCities.size(); ++i) {
                JSONObject jsCityObject = jarrayCities.get(i).isObject();
                if (jsCityObject == null) {
                    continue;
                }/*  w  ww . j a  va  2s . c o m*/
                City city = getCityInfo(jsCityObject);
                if (city != null) {
                    ret.add(city);
                }
            }
        }
    } else {
        City city = getCityInfo(jsCityObj);
        if (city != null) {
            ret.add(city);
        }
    }
    return ret;
}