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:com.mcherm.zithiacharsheet.client.model.JSONDeserializer.java

License:Apache License

protected void updateFromField(JSONObject inputObject, String fieldName, SkillList skillList) {
    JSONValue fieldValue = notNull(inputObject.get(fieldName));
    JSONArray fieldArray = notNull(fieldValue.isArray());
    skillList.clear();/*w w w. j  a  v a2  s  .c om*/
    for (int i = 0; i < fieldArray.size(); i++) {
        JSONValue skillDataValue = fieldArray.get(i);
        JSONObject skillDataObj = notNull(skillDataValue.isObject());
        JSONValue zithiaSkillValue = notNull(skillDataObj.get("skill"));
        ZithiaSkill zithiaSkill = lookupSkill(zithiaSkillValue);
        SkillValue result = skillList.addNewSkill(zithiaSkill);
        updateFromField(skillDataObj, "levels", result.getLevels());
        if (zithiaSkill.hasRoll()) {
            updateFromField(skillDataObj, "roll", result.getRoll());
        }
        updateFromField(skillDataObj, "cost", result.getCost());
    }
}

From source file:com.mcherm.zithiacharsheet.client.model.JSONDeserializer.java

License:Apache License

protected WeaponSkill lookupWeaponSkill(JSONValue input) {
    JSONObject inputObj = notNull(input.isObject());
    JSONValue idValue = notNull(inputObj.get("id"));
    JSONString idString = notNull(idValue.isString());
    String id = idString.stringValue();
    return notNull(WeaponsCatalog.getSingleton().getWeaponSkillById(id));
}

From source file:com.mcherm.zithiacharsheet.client.model.JSONDeserializer.java

License:Apache License

protected WeaponTraining newWeaponTraining(JSONValue input, WeaponTraining parent) {
    JSONObject inputObject = notNull(input.isObject());
    WeaponSkill weaponSkill = lookupWeaponSkill(notNull(inputObject.get("weaponSkill")));
    WeaponTraining result = parent.createChild(weaponSkill);
    updateFromField(inputObject, "basicTrainingDesired", result.getBasicTrainingDesired());
    updateFromField(inputObject, "levelsPurchased", result.getLevelsPurchased());
    updateFromField(inputObject, "levels", result.getLevels());
    updateFromField(inputObject, "thisCost", result.getThisCost());
    updateFromField(inputObject, "totalCost", result.getTotalCost());
    return result;
}

From source file:com.mcherm.zithiacharsheet.client.model.JSONDeserializer.java

License:Apache License

/**
 * This is used for reading the top-level WeaponTraining. The input must
 * specify a weaponSkill that matches the skill in wt. The WeaponTraining
 * passed must be newly created or have had .clean() called on it before
 * calling this./*from   w  w  w .j  ava  2s.co  m*/
 */
protected void update(JSONValue input, WeaponTraining wt) {
    JSONObject inputObject = notNull(input.isObject());
    WeaponSkill weaponSkillFound = lookupWeaponSkill(notNull(inputObject.get("weaponSkill")));
    if (wt.getWeaponSkill() != weaponSkillFound) {
        throw new JSONBuildException();
    }
    updateFromField(inputObject, "basicTrainingDesired", wt.getBasicTrainingDesired());
    updateFromField(inputObject, "levelsPurchased", wt.getLevelsPurchased());
    updateFromField(inputObject, "levels", wt.getLevels());
    updateFromField(inputObject, "thisCost", wt.getThisCost());
    updateFromField(inputObject, "totalCost", wt.getTotalCost());
    JSONValue childrenValue = inputObject.get("children");
    if (childrenValue != null) {
        JSONArray childrenArray = notNull(childrenValue.isArray());
        for (int i = 0; i < childrenArray.size(); i++) {
            JSONValue childValue = childrenArray.get(i);
            JSONObject childObject = notNull(childValue.isObject());
            JSONValue childWeaponSkillValue = notNull(childObject.get("weaponSkill"));
            WeaponSkill childWeaponSkill = lookupWeaponSkill(childWeaponSkillValue);
            WeaponTraining newChild = wt.createChild(childWeaponSkill);
            update(childValue, newChild);
        }
    }
}

From source file:com.mcherm.zithiacharsheet.client.model.JSONDeserializer.java

License:Apache License

protected void updateFromField(JSONObject inputObject, String fieldName, ZithiaCosts zithiaCosts) {
    JSONValue fieldValue = inputObject.get(fieldName);
    if (fieldValue != null) {
        JSONObject fieldObject = notNull(fieldValue.isObject());
        updateFromField(fieldObject, "raceCost", zithiaCosts.getRaceCost());
        updateFromField(fieldObject, "statCost", zithiaCosts.getStatCost());
        updateFromField(fieldObject, "skillCost", zithiaCosts.getSkillCost());
        updateFromField(fieldObject, "weaponSkillCost", zithiaCosts.getWeaponSkillCost());
        updateFromField(fieldObject, "totalCost", zithiaCosts.getTotalCost());
        updateFromField(fieldObject, "basePts", zithiaCosts.getBasePts());
        updateFromField(fieldObject, "loanPts", zithiaCosts.getLoanPts());
        updateFromField(fieldObject, "expSpent", zithiaCosts.getExpSpent());
        updateFromField(fieldObject, "expEarned", zithiaCosts.getExpEarned());
        updateFromField(fieldObject, "paidForLoan", zithiaCosts.getPaidForLoan());
        updateFromField(fieldObject, "expUnspent", zithiaCosts.getExpUnspent());
    }/*from   www.j a  v a2 s  .  com*/
}

From source file:com.mcherm.zithiacharsheet.client.model.JSONDeserializer.java

License:Apache License

protected void updateFromField(JSONObject inputObject, String fieldName, RaceValue raceValue) {
    JSONValue fieldValue = inputObject.get(fieldName);
    if (fieldValue == null) {
        // If omitted, default to Human.
        raceValue.getRace().setValue(Race.Human);
    } else {//  w  ww  . j  a  va  2s .  c om
        JSONObject fieldObject = notNull(fieldValue.isObject());
        updateFromFieldRace(fieldObject, "race", raceValue.getRace());
    }
}

From source file:com.mcherm.zithiacharsheet.client.model.JSONDeserializer.java

License:Apache License

protected void updateFromField(JSONObject inputObject, String fieldName, CombatValues combatValues) {
    JSONValue fieldValue = inputObject.get(fieldName);
    if (fieldValue == null) {
        // If omitted, then all fields take default values
        combatValues.getOffense().setAdjustments(null, null);
        combatValues.getDefense().setAdjustments(null, null);
    } else {/*from w w w  .ja va 2s  . com*/
        JSONObject fieldObject = notNull(fieldValue.isObject());
        updateFromField(fieldObject, "offense", combatValues.getOffense());
        updateFromField(fieldObject, "defense", combatValues.getDefense());
    }
}

From source file:com.mcherm.zithiacharsheet.client.model.JSONDeserializer.java

License:Apache License

protected void updateFromField(JSONObject inputObject, String fieldName, ArmorValue armorValue) {
    JSONValue fieldValue = inputObject.get(fieldName);
    if (fieldValue == null) {
        // If omitted, then all fields take default values
        armorValue.setDefaultSettings();
    } else {//  w w w . ja  v  a  2  s.  c o m
        JSONObject fieldObject = notNull(fieldValue.isObject());
        updateFromFieldArmorType(fieldObject, "armorType", armorValue.getArmorType());
        updateFromField(fieldObject, "hpBlock", armorValue.getHpBlock());
        updateFromField(fieldObject, "stunBlock", armorValue.getStunBlock());
        updateFromField(fieldObject, "defPenalty", armorValue.getDefPenalty());
    }
}

From source file:com.mcherm.zithiacharsheet.client.model.JSONDeserializer.java

License:Apache License

protected void updateFromField(JSONObject inputObject, String fieldName, Names names) {
    JSONValue fieldValue = notNull(inputObject.get(fieldName));
    JSONObject fieldObject = notNull(fieldValue.isObject());
    updateFromField(fieldObject, "name", names.getCharacterName());
    updateFromField(fieldObject, "player", names.getPlayerName());
}

From source file:com.mcherm.zithiacharsheet.client.model.JSONDeserializer.java

License:Apache License

protected void updateFromField(JSONObject inputObject, String fieldName, CharacterNotes notes) {
    JSONValue fieldValue = inputObject.get(fieldName);
    if (fieldValue == null) {
        notes.getBackground().setValue("");
    } else {/*from   w w  w.  j  av  a  2  s  .co  m*/
        JSONObject fieldObject = notNull(fieldValue.isObject());
        updateFromField(fieldObject, "background", notes.getBackground());
    }
}