List of usage examples for com.google.gwt.json.client JSONValue isObject
public JSONObject isObject()
From source file:org.eclipse.che.ide.jsonrpc.impl.ResponseDispatcher.java
License:Open Source License
private void processResult(String endpointId, String id, Class resultClass, JSONValue result) { final String combinedId = endpointId + '@' + id; final JSONObject resultObject = result.isObject(); if (resultObject != null) { applyObject(combinedId, resultObject, resultClass); } else {//from w ww . j ava 2 s .c om final JSONArray resultArray = result.isArray(); applyArray(combinedId, resultArray, resultClass); } }
From source file:org.eclipselabs.emfjson.gwt.internal.JSONLoad.java
License:Open Source License
public void fillResource(final Resource resource, InputStream inStream, Map<?, ?> options) { init(resource, options);/*from www. j a v a2s. c o m*/ JSONValue root = JSUtil.parse(inStream); if (root == null) { throw new IllegalArgumentException("root node should not be null."); } final JSONObject rootObject = root.isObject(); if (rootObject != null) { fillEObject(resource, rootObject); } else { final JSONArray jsonArray = root.isArray(); if (jsonArray != null) { for (int i = 0; i < jsonArray.size(); i++) { final JSONValue jsonValue = jsonArray.get(i); final JSONObject jsonObject = jsonValue.isObject(); fillEObject(resource, jsonObject); } } } }
From source file:org.eclipselabs.emfjson.gwt.internal.JSONLoad.java
License:Open Source License
private void fillEAttribute(EObject container, JSONObject node) { final EClass eClass = container.eClass(); if (node == null) return;/* ww w . j a va2s . c o m*/ // Iterates over all key values of the JSON Object, // if the value is not an object then // if the key corresponds to an EAttribute, fill it // if not and the EClass contains a MapEntry, fill it with the key, value. for (String key : node.keySet()) { JSONValue value = node.get(key); if (value.isObject() != null) // not an attribute continue; EAttribute attribute = ModelUtil.getEAttribute(eClass, key); if (attribute != null && !attribute.isTransient() && !attribute.isDerived()) { if (value.isArray() != null) { JSONArray array = value.isArray(); for (int i = 0; i < array.size(); i++) { setEAttributeValue(container, attribute, array.get(i)); } } else { setEAttributeValue(container, attribute, value); } } else { EStructuralFeature eFeature = ModelUtil.getDynamicMapEntryFeature(eClass); if (eFeature != null) { @SuppressWarnings("unchecked") EList<EObject> values = (EList<EObject>) container.eGet(eFeature); values.add(createEntry(key, value)); } } } }
From source file:org.eclipselabs.emfjson.gwt.internal.JSONLoad.java
License:Open Source License
private void fillEContainment(EObject eObject, JSONObject node, Resource resource) { final EClass eClass = eObject.eClass(); if (node == null) return;/*from w w w . j a v a2 s .c o m*/ for (String key : node.keySet()) { JSONValue value = node.get(key); EReference reference = ModelUtil.getEReference(eClass, key); if (reference != null && reference.isContainment() && !reference.isTransient()) { if (ModelUtil.isMapEntry(reference.getEType()) && value.isObject() != null) { createMapEntry(eObject, reference, value.isObject()); } else { createContainment(eObject, reference, node, value, resource); } } } }
From source file:org.eclipselabs.emfjson.gwt.internal.JSONLoad.java
License:Open Source License
private void fillEReference(EObject eObject, JSONObject node, Resource resource) { if (node == null) return;/*from w w w. ja v a 2 s .c o m*/ final EClass eClass = eObject.eClass(); for (String key : node.keySet()) { JSONValue value = node.get(key); EReference reference = ModelUtil.getEReference(eClass, key); if (reference != null && !reference.isContainment() && !reference.isDerived() && !reference.isTransient()) { JSONArray array = value.isArray(); if (array != null) { for (int i = 0; i < array.size(); i++) { createProxyReference(eObject, node, array.get(i).isObject(), reference, resource); } } else { createProxyReference(eObject, node, value.isObject(), reference, resource); } } } for (EObject content : eObject.eContents()) { if (processed.containsKey(content)) fillEReference(content, processed.get(content).isObject(), resource); } }
From source file:org.eclipselabs.emfjson.gwt.internal.JSONLoad.java
License:Open Source License
private void createContainment(EObject eObject, EReference reference, JSONObject root, JSONValue node, Resource resource) {/*from www. j a v a2s . c om*/ if (node.isArray() != null) { JSONArray array = node.isArray(); if (reference.isMany()) { @SuppressWarnings("unchecked") EList<EObject> values = (EList<EObject>) eObject.eGet(reference); for (int i = 0; i < array.size(); i++) { JSONValue current = array.get(i); EObject contained = createContainedObject(reference, root, current.isObject(), resource); if (contained != null) values.add(contained); } } else if (array.size() > 0) { JSONValue current = array.get(0); EObject contained = createContainedObject(reference, root, current.isObject(), resource); if (contained != null) eObject.eSet(reference, contained); } } else { EObject contained = createContainedObject(reference, root, node.isObject(), resource); if (reference.isMany()) { @SuppressWarnings("unchecked") EList<EObject> values = (EList<EObject>) eObject.eGet(reference); if (contained != null) values.add(contained); } else { if (contained != null) eObject.eSet(reference, contained); } } }
From source file:org.eclipselabs.emfjson.gwt.internal.JSONLoad.java
License:Open Source License
private EObject findEObject(Resource resource, JSONValue node) { EObject eObject = null;//from www . j a v a2 s . c om if (node.isObject() != null) { final URI objectURI = ModelUtil.getEObjectURI(node.isObject().get(EJS_REF_KEYWORD), resource.getURI(), nsMap); eObject = resourceSet.getEObject(objectURI, false); } return eObject; }
From source file:org.eclipselabs.emfjson.gwt.internal.JSONLoad.java
License:Open Source License
private boolean isRefNode(JSONValue node) { return node.isObject() != null && node.isObject().containsKey(EJS_REF_KEYWORD); }
From source file:org.eclipselabs.emfjson.gwt.map.EAttributeSerializer.java
License:Open Source License
void serializeString(JSONValue node, String key, String value) { if (node.isObject() != null) { node.isObject().put(key, new JSONString(value)); } else {/* ww w. j a va2 s . c o m*/ node.isArray().set(node.isArray().size(), new JSONString(value)); } }
From source file:org.eclipselabs.emfjson.gwt.map.EAttributeSerializer.java
License:Open Source License
void serializeBoolean(JSONValue node, String key, Boolean value) { if (node.isObject() != null) { node.isObject().put(key, JSONBoolean.getInstance(value)); } else {//from ww w . ja va2 s. co m node.isArray().set(node.isArray().size(), JSONBoolean.getInstance(value)); } }