/** * Copyright 2015 ArcBees Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.arcbees.gaestudio.client.application.visualizer; import java.util.Set; import com.arcbees.gaestudio.client.application.entity.editor.PropertyUtil; import com.arcbees.gaestudio.shared.PropertyType; import com.arcbees.gaestudio.shared.dto.entity.EntityDto; import com.arcbees.gaestudio.shared.dto.entity.KeyDto; import com.google.gwt.json.client.JSONObject; import com.google.gwt.json.client.JSONParser; import com.google.gwt.json.client.JSONValue; import static com.arcbees.gaestudio.shared.PropertyName.PROPERTY_MAP; public class ParsedEntity { private EntityDto entityDto; private JSONObject jsonObject; public ParsedEntity(EntityDto entityDto) { this.entityDto = new EntityDto(entityDto.getKey(), entityDto.getJson()); parseJson(); } public JSONObject getJsonObject() { return jsonObject; } public Set<String> propertyKeys() { return getPropertyMap().keySet(); } public PropertyType getPropertyType(String key) { JSONValue jsonValue = getProperty(key); return PropertyUtil.getPropertyType(jsonValue); } public JSONValue getProperty(String key) { return getPropertyMap().get(key); } public JSONValue getCleanedUpProperty(String key) { JSONValue property = getProperty(key); return PropertyUtil.cleanUpMetadata(property); } public JSONObject getPropertyMap() { return jsonObject.get(PROPERTY_MAP).isObject(); } public EntityDto getEntityDto() { return entityDto; } public void setEntityDto(EntityDto entityDto) { this.entityDto = entityDto; parseJson(); } public KeyDto getKey() { return entityDto.getKey(); } public String getJson() { return jsonObject.toString(); } public void parseJson() { jsonObject = JSONParser.parseStrict(entityDto.getJson()).isObject(); } }