Example usage for com.mongodb.util JSON parse

List of usage examples for com.mongodb.util JSON parse

Introduction

In this page you can find the example usage for com.mongodb.util JSON parse.

Prototype

public static Object parse(final String jsonString) 

Source Link

Document

Parses a JSON string and returns a corresponding Java object.

Usage

From source file:eu.cassandra.sim.SimulationParams.java

License:Apache License

/**
 * @param args//from w  ww  .j  a  v a 2 s .c o  m
 * @throws IOException
 * @throws ParseException
 */
public static void main(String[] args) throws IOException, ParseException {
    String s = Utils.readFile("simparam.json");

    DBObject obj = (DBObject) JSON.parse(s);

    SimulationParams sp = new SimulationParams(obj);

    System.out.println("Name:" + sp.getName());
    System.out.println("Location Info:" + sp.getLocationInfo());
    System.out.println("SimCalendar:" + sp.getSimCalendar().toString());
}

From source file:eu.cassandra.sim.utilities.Utils.java

License:Apache License

public static String inject(String message, String field, String value) {
    DBObject data = (DBObject) JSON.parse(message);
    data.put(field, value);/*from   ww w  . jav  a  2  s .co  m*/
    return data.toString();
}

From source file:eu.cassandra.sim.utilities.Utils.java

License:Apache License

public static Response returnResponse(String json) {
    DBObject jsonResponse = (DBObject) JSON.parse(json);
    if (Boolean.parseBoolean(jsonResponse.get("success").toString())) {
        return Response.ok(json, MediaType.APPLICATION_JSON).build();
    } else {//  w  w  w .j av a2s .  com
        return Response.status(Response.Status.BAD_REQUEST).entity(json).build();
    }
}

From source file:eu.cassandra.sim.utilities.Utils.java

License:Apache License

public static Response returnResponseWithAppend(String json, String key, Integer value) {
    DBObject jsonResponse = (DBObject) JSON.parse(json);
    if (Boolean.parseBoolean(jsonResponse.get("success").toString())) {
        jsonResponse.put(key, value);//  w ww  .  j ava  2s  . c o m
        return Response.ok(PrettyJSONPrinter.prettyPrint(jsonResponse.toString()), MediaType.APPLICATION_JSON)
                .build();
    } else {
        return Response.status(Response.Status.BAD_REQUEST).entity(json).build();
    }
}

From source file:eu.cassandra.sim.utilities.Utils.java

License:Apache License

public static boolean failed(String json) {
    DBObject jsonResponse = (DBObject) JSON.parse(json);
    if (Boolean.parseBoolean(jsonResponse.get("success").toString())) {
        return false;
    } else {/* w  w w. j  a v a2s  . c o m*/
        return true;
    }
}

From source file:eu.cassandra.training.consumption.ActiveConsumptionModel.java

License:Apache License

/**
 * This is the constructor of the active activeOnly consumption model.
 * /*from   w w w.  j  a  v  a2s .  c  o m*/
 * @param amodel
 *          The string of the JSON schema that fully defines the active
 *          activeOnly
 *          consumption model to implement.
 */
public ActiveConsumptionModel(String amodel) {
    model = amodel;
    DBObject modelObj = (DBObject) JSON.parse(model);
    init(modelObj);
}

From source file:eu.cassandra.training.consumption.PowerConsumptionModel.java

License:Apache License

/**
 * This is the constructor of the active activeOnly consumption model.
 * /*w ww.  j a va2s  .c  om*/
 * @param amodel
 *          The string of the JSON schema that fully defines the active
 *          activeOnly
 *          consumption model to implement.
 */
public PowerConsumptionModel(String amodel) {
    model = amodel;
    DBObject modelObj = (DBObject) JSON.parse(model);
    init(modelObj);
}

From source file:eu.cassandra.training.consumption.ReactiveConsumptionModel.java

License:Apache License

/**
 * This is the constructor of the reactive activeOnly consumption model.
 * //  www .j a va 2  s .c  o  m
 * @param amodel
 *          The string of the JSON schema that fully defines the active activeOnly
 *          consumption model to implement.
 */
public ReactiveConsumptionModel(String amodel) {
    model = amodel;
    DBObject modelObj = (DBObject) JSON.parse(model);
    init(modelObj);
}

From source file:eu.cassandra.training.entities.Appliance.java

License:Apache License

/**
 * The constructor of an Appliance Model.
 * /*  w ww. j a  va2 s . c  om*/
 * @param name
 *          The name of the Appliance Model
 * @param installation
 *          The name of the installation that the Appliance Model is installed
 * @param activeModel
 *          The active active consumption of the Appliance Model
 * @param reactiveModel
 *          The reactive active consumption of the Appliance Model
 * @param eventFile
 *          The event file of the Appliance Model
 */
public Appliance(String name, String installation, String activeModel, String reactiveModel, String eventFile,
        Boolean... base) {

    this.name = name;
    this.installation = installation;
    this.eventsFile = eventFile;
    activeConsumptionModelString = activeModel;
    reactiveConsumptionModelString = reactiveModel;
    DBObject dbo = (DBObject) JSON.parse(activeConsumptionModelString);
    activeConsumptionModel.init(dbo);
    dbo = (DBObject) JSON.parse(reactiveConsumptionModelString);
    reactiveConsumptionModel.init(dbo);
    if (base.length == 1)
        this.base = base[0];

    staticConsumption = checkStatic();
}

From source file:eu.cassandra.training.entities.Appliance.java

License:Apache License

/**
 * This function is the parser of the consumption model provided by the user.
 * /*from  ww w.j  a  v  a2  s  .c  om*/
 * @param filename
 *          The file name of the consumption model
 * @throws IOException
 */
public void parseConsumptionModel(String filename) throws IOException {

    File file = new File(filename);

    String model = "";

    String extension = filename.substring(filename.length() - 3, filename.length());

    Scanner scanner = new Scanner(file);
    switch (extension) {

    case "son":

        while (scanner.hasNext())
            model = model + scanner.nextLine();
        break;
    default:

        while (scanner.hasNext())
            model = model + scanner.nextLine();

        model.replace(" ", "");
    }
    scanner.close();

    activeConsumptionModelString = model;
    DBObject dbo = (DBObject) JSON.parse(activeConsumptionModelString);
    activeConsumptionModel.init(dbo);

    reactiveConsumptionModelString = activeConsumptionModelString.replace("p", "q");
    reactiveConsumptionModelString = reactiveConsumptionModelString.replace("qara", "para");
    System.out.println(reactiveConsumptionModelString);
    dbo = (DBObject) JSON.parse(reactiveConsumptionModelString);
    reactiveConsumptionModel.init(dbo);

}