List of usage examples for com.google.gwt.coreext.client DataBag hasOwnProperty
public static final native boolean hasOwnProperty(JavaScriptObject obj, String prop) ;
From source file:com.google.speedtracer.breaky.client.DumpValidator.java
License:Apache License
/** * Determine the schema of an object by looking at its "type" field. * //from w w w . j a v a 2 s . co m * @param obj the object with a "type" field * @return the corresponding {@link JsonSchema} */ public final JsonSchema getSchema(JavaScriptObject obj) { if (DataBag.hasOwnProperty(obj, "type")) { return getSchema(DataBag.getIntProperty(obj, "type")); } else { return null; } }
From source file:com.google.speedtracer.breaky.client.DumpValidator.java
License:Apache License
/** * Validate a Speedtracer dump object./*w ww .j a va2 s .c o m*/ * * @param obj a speedtracer dump object to be validated * @return {@link JsonSchemaResults} object indicating that the entire object * is valid or containing the error that caused it to be invalid. */ public JsonSchemaResults validate(JavaScriptObject obj) { JsonSchema concreteSchema = getSchema(obj); if (concreteSchema == null) { return JsonSchemaResults.create("", "No schema found for " + obj.toString()); } JsonSchemaResults results = JsonSchemaValidator.validate(obj, concreteSchema); if (!results.isValid()) { return results; } if (DataBag.hasOwnProperty(obj, "children")) { JsArray<JavaScriptObject> children = DataBag.getJSObjectProperty(obj, "children"); for (int i = 0; i < children.length() && results.isValid(); i++) { // TODO(conroy): make child validation incremental? results = this.validate(children.get(i)); } } return results; }
From source file:com.google.speedtracer.breaky.client.DumpValidator.java
License:Apache License
/** * In our schema set, if a schema has a fully constrained type property, then * it is a concrete rather than an abstract type. The ID Map let's us quickly * validate based on the concrete type as objects come in. *//*from w ww . j ava2 s . co m*/ private void fillIdMap() { JsArrayString schemaNames = listSchemas(); for (int i = 0; i < schemaNames.length(); i++) { JsonSchema schema = (JsonSchema) DataBag.getJSObjectProperty(schemas, schemaNames.get(i)); JavaScriptObject properties = schema.getProperties(); if (DataBag.hasOwnProperty(properties, "type")) { JsonSchema dumpType = DataBag.getJSObjectProperty(properties, "type"); if ((DataBag.hasOwnProperty(dumpType, "minimum") && DataBag.hasOwnProperty(dumpType, "maximum")) && dumpType.getMinimum() == dumpType.getMaximum()) { idMap.put(dumpType.getMinimum(), schema); } } } }
From source file:com.google.speedtracer.hintletengine.client.HintletEventRecordProcessor.java
License:Apache License
/** * Receive a new record of browser data and forward it to registered hintlets * //from w w w . j av a 2s . c om * @param dataRecord record to send to all hintlets */ public void onEventRecord(JavaScriptObject dataRecord) { if (!DataBag.hasOwnProperty(dataRecord, "type")) { throw new IllegalArgumentException("Expecting an EventRecord. Getting " + JSON.stringify(dataRecord)); } // TODO(haibinlu): make sure the type is valid EventRecord eventRecord = dataRecord.cast(); // Calculate the time spent in each event/sub-event exclusive of children computeSelfTime(eventRecord); // Keep state for a network resource. NetworkEventDispatcher // will determine which events to save data from. HintletNetworkResources.getInstance().onEventRecord(eventRecord); for (HintletRule rule : rules) { rule.onEventRecord(eventRecord); } }