List of usage examples for com.google.gwt.json.client JSONValue isObject
public JSONObject isObject()
From source file:com.ait.lienzo.client.core.shape.json.validators.ObjectValidator.java
License:Open Source License
@Override public void validate(JSONValue jval, ValidationContext ctx) throws ValidationException { if (null == jval) { ctx.addBadTypeError("Object"); return;/*from ww w . j a va 2 s. c om*/ } JSONObject jobj = jval.isObject(); if (null == jobj) { ctx.addBadTypeError("Object"); } else { Set<String> keys = jobj.keySet(); // Check required attributes for (String attrName : m_requiredAttributes) { ctx.push(attrName); if (false == keys.contains(attrName)) { ctx.addRequiredError(); // value is missing } else { JSONValue aval = jobj.get(attrName); if ((null == aval) || (null != aval.isNull())) { ctx.addRequiredError(); // value is null } } ctx.pop(); // attrName } // Now check the attribute values for (String attrName : keys) { ctx.push(attrName); IAttributeTypeValidator validator = m_attributes.get(attrName); if (null == validator) { ctx.addInvalidAttributeError(m_typeName); } else if (false == (validator instanceof IgnoreTypeValidator)) { JSONValue aval = jobj.get(attrName); validator.validate(aval, ctx); } ctx.pop(); // attrName } } }
From source file:com.ait.lienzo.client.core.shape.json.validators.ObjectValidator.java
License:Open Source License
protected void checkHardcodedAttribute(String attrName, String requiredAttrValue, JSONValue jval, ValidationContext ctx) throws ValidationException { // ASSUMPTION: requiredness was already checked and reported on JSONObject jobj = jval.isObject(); if (null != jobj) { JSONValue aval = jobj.get(attrName); if (null != aval) { JSONString s = aval.isString(); if ((null == s) || (false == requiredAttrValue.equals(s.stringValue()))) { ctx.push(attrName);//from w w w. j a v a 2 s .com ctx.addRequiredAttributeValueError(requiredAttrValue); ctx.pop(); // attrName } } } }
From source file:com.ait.lienzo.client.core.shape.json.validators.SpriteBehaviorMapValidator.java
License:Open Source License
@Override public void validate(final JSONValue jval, final ValidationContext ctx) throws ValidationException { if (null == jval) { ctx.addBadTypeError(getTypeName()); return;/*from w ww . j av a 2 s.c om*/ } final JSONObject jobj = jval.isObject(); if (null == jobj) { ctx.addBadTypeError(getTypeName()); } else { final Set<String> keys = jobj.keySet(); if (keys.isEmpty()) { ctx.addBadTypeError(getTypeName() + ": empty behavior keys"); return; } for (String ikey : keys) { final String akey = StringOps.toTrimOrNull(ikey); if (null == akey) { ctx.addBadTypeError(getTypeName() + ": empty behavior name"); return; } final JSONValue ival = jobj.get(akey); if (null == ival) { ctx.addBadTypeError(getTypeName() + ": missing behavior array for " + akey); return; } final JSONArray jarr = ival.isArray(); if (null == jarr) { ctx.addBadTypeError(getTypeName() + ": invalid behavior array for " + akey); return; } if (jarr.size() < 2) { ctx.addBadArraySizeError(2, jarr.size()); return; } BoundingBoxArrayValidator.INSTANCE.validate(jarr, ctx); } } }
From source file:com.ait.lienzo.client.core.shape.Node.java
License:Open Source License
/** * Constructor used by deserialization code. * /*from w w w. j a va 2s . co m*/ * @param type * @param node */ protected Node(final NodeType type, final JSONObject node, final ValidationContext ctx) throws ValidationException { m_type = type; if (null == node) { m_attr = new Attributes(this); m_meta = new MetaData(); return; } JSONValue aval = node.get("attributes"); if (null == aval) { m_attr = new Attributes(this); } else { JSONObject aobj = aval.isObject(); if (null == aobj) { m_attr = new Attributes(this); } else { JavaScriptObject ajso = aobj.getJavaScriptObject(); if (null == ajso) { m_attr = new Attributes(this); } else { m_attr = new Attributes(ajso, this); } } } JSONValue mval = node.get("meta"); if (null == mval) { m_meta = new MetaData(); } else { JSONObject mobj = mval.isObject(); if (null == mobj) { m_meta = new MetaData(); } else { JavaScriptObject mjso = mobj.getJavaScriptObject(); if (null == mjso) { m_meta = new MetaData(); } else { NFastStringMapMixedJSO jso = mjso.cast(); m_meta = new MetaData(jso); } } } }
From source file:com.ait.lienzo.client.core.shape.storage.AbstractStorageEngine.java
License:Open Source License
protected AbstractStorageEngine(final StorageEngineType type, final JSONObject node, final ValidationContext ctx) throws ValidationException { m_type = type;/*from www . j ava 2 s . c o m*/ final JSONValue mval = node.get("meta"); if (null == mval) { m_meta = new MetaData(); } else { final JSONObject mobj = mval.isObject(); if (null == mobj) { m_meta = new MetaData(); } else { final JavaScriptObject mjso = mobj.getJavaScriptObject(); if (null == mjso) { m_meta = new MetaData(); } else { final NObjectJSO jso = mjso.cast(); m_meta = new MetaData(jso); } } } }
From source file:com.ait.lienzo3d.client.shape.BaseObject3D.java
License:Open Source License
protected BaseObject3D(final Type3D type, final JSONObject node, final ValidationContext ctx) throws ValidationException { m_type = type;/*from w w w.ja va2 s . co m*/ if (null == node) { m_attr = new Attributes3D(this); m_meta = new MetaData(); return; } JSONValue aval = node.get("attributes"); if (null == aval) { m_attr = new Attributes3D(this); } else { JSONObject aobj = aval.isObject(); if (null == aobj) { m_attr = new Attributes3D(this); } else { JavaScriptObject ajso = aobj.getJavaScriptObject(); if (null == ajso) { m_attr = new Attributes3D(this); } else { m_attr = new Attributes3D(ajso, this); } } } JSONValue mval = node.get("meta"); if (null == mval) { m_meta = new MetaData(); } else { JSONObject mobj = mval.isObject(); if (null == mobj) { m_meta = new MetaData(); } else { JavaScriptObject mjso = mobj.getJavaScriptObject(); if (null == mjso) { m_meta = new MetaData(); } else { NFastStringMapMixedJSO jso = mjso.cast(); m_meta = new MetaData(jso); } } } refresh(); }
From source file:com.ait.toolkit.clientio.uploader.client.Configurable.java
License:Apache License
private void setOption(JSONObject rootObject, String path, Object value) { if (path == null) { return;/* w w w . jav a2s . c om*/ } if (path.startsWith("/")) { path = path.substring(1); } if (path.length() <= 0) { return; } String nodeName = path; if (nodeName.contains("/")) { nodeName = nodeName.substring(0, nodeName.indexOf("/")); JSONValue objectAsValue = rootObject.get(nodeName); if (objectAsValue == null || objectAsValue.isObject() == null) { rootObject.put(nodeName, new JSONObject()); } JSONObject object = (JSONObject) rootObject.get(nodeName); setOption(object, path.substring(path.indexOf("/") + 1), value); } else { rootObject.put(nodeName, convertToJSONValue(value)); } }
From source file:com.akanoo.client.dto.MessageCreator.java
License:Apache License
@Override public Message newInstance(JSONValue context) { Message message = null;// w ww .j a va 2 s .c om JSONObject jsonObject = context.isObject(); if (jsonObject != null) { JSONValue codeValue = jsonObject.get("code"); JSONValue bodyValue = jsonObject.get("body"); if (codeValue != null && bodyValue != null) { JSONString codeJSONString = codeValue.isString(); JSONObject bodyJSONValue = bodyValue.isObject(); if (codeJSONString != null && bodyJSONValue != null) { String codeString = codeJSONString.stringValue(); MessageConstants messageConstants = MessageConstants.fromString(codeString); if (messageConstants != null) { // initialize message message = new Message(); message.code = codeString; JsonReader<? extends Sendable> reader = readerMap.get(messageConstants); message.body = reader.read(bodyJSONValue); } } } } return message; }
From source file:com.apress.progwt.client.json.JSONWrapper.java
License:Apache License
public JSONWrapper(JSONValue value) { this.object = value.isObject(); if (object == null) { throw new UnsupportedOperationException("value not object"); }// ww w . j a v a 2s . c o m }
From source file:com.blockwithme.util.client.webworkers.impl.AbstractWebWorkerImpl.java
License:Apache License
@Override public final void handleEvent(final elemental.events.Event evt) { if (evt instanceof MessageEvent) { final Object data = ((MessageEvent) evt).getData(); if (data == null) { logger.severe("got MessageEvent with null data"); } else {//from w w w.ja va2 s. c o m try { JSONObject message = new JSONObject((JavaScriptObject) data); if (message.isObject() == null) { logger.log(Level.SEVERE, "Problem parsing data: " + stringify(data) + " : data not a JSONObject"); } else { if (message.containsKey("jsObject")) { final JSONValue jsObject = message.get("jsObject"); if (jsObject.isObject() != null) { message = jsObject.isObject(); } else { logger.log(Level.SEVERE, "Problem parsing data: " + stringify(data) + " : data.jsObject not a JSONObject"); message = null; } } if (message != null) { // Get and remove channel at the same time final JSONValue channel = message.put("_channel_", null); String ch = ""; if ((channel != null) && (channel != JSONNull.getInstance())) { final JSONString str = channel.isString(); if (str != null) { // Cannot be null ch = str.stringValue(); } else { ch = stringify(channel); } } if ("java.util.logging".equals(ch)) { final LogRecord record = WebWorkerLogHandler.fromJSONObject(message); if (record != null) { setThreadName(record, name); Logger.getLogger(record.getLoggerName()).log(record); } } else if ("set.thread.name".equals(ch)) { final String name = message.get("value").isString().stringValue(); setThreadName(Thread.currentThread(), name); } else { listener.onMessage(ch, message); } } } } catch (final Throwable t) { logger.log(Level.SEVERE, "Problem parsing data: " + stringify(data), t); } } } else if (evt instanceof ErrorEvent) { final ErrorEvent errEvt = (ErrorEvent) evt; final String filename = errEvt.getFilename(); final int lineno = errEvt.getLineno(); final String message = errEvt.getMessage(); logger.severe(filename + ":" + lineno + ": " + message); } else if (evt != null) { logger.severe("Cannot handle message of type " + evt.getClass() + " : " + stringify(evt)); } }