[isidorus-cvs] r536 - in branches/gdl-frontend/src/anaToMia/GDL_TmEngine: lib src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine

Author: lgiessmann Date: Thu Jun 30 03:30:38 2011 New Revision: 536 Log: gdl-frontend: Topic Maps Engine: fixed a bug when a topic reference or an array is set to null instead of being set to a value Modified: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/lib/GDL_TopicMaps_Model.jar branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngine.java branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/TestClass.java Modified: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/lib/GDL_TopicMaps_Model.jar ============================================================================== Binary file (source and/or target). No diff available. Modified: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngine.java ============================================================================== --- branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngine.java Thu Jun 30 03:28:32 2011 (r535) +++ branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/JtmsTmEngine.java Thu Jun 30 03:30:38 2011 (r536) @@ -8,6 +8,8 @@ import com.google.gwt.json.client.JSONParser; import com.google.gwt.json.client.JSONString; import com.google.gwt.json.client.JSONValue; +import com.google.gwt.user.client.Window; + import us.isidor.gdl.anaToMia.TopicMaps.TmEngineModel.ExporterException; import us.isidor.gdl.anaToMia.TopicMaps.TmEngineModel.FormatException; import us.isidor.gdl.anaToMia.TopicMaps.TmEngineModel.MissingReference; @@ -416,6 +418,8 @@ private Topic getReferenced(JSONValue reference, TopicMap tm, Prefixes prefixes) throws FormatException, MissingReference{ + if(reference.isNull() != null) return null; + JSONString stringValue = reference.isString(); if(stringValue == null){ throw new FormatException("expected a string value as topic reference, but found \"" + reference.toString() + "\""); @@ -452,6 +456,10 @@ ArrayList<String> stringReferences = new ArrayList<String>(); JSONArray stringValues = references.isArray(); + if(references.isNull() != null){ + return getReferenceds(stringReferences, tm, prefixes); + } + if(stringValues == null){ throw new FormatException("expected an array of strings as topic references, but found \"" + references.toString() + "\""); } @@ -553,17 +561,22 @@ if(object.containsKey(key)){ JSONValue jsonValue = object.get(key); - JSONArray jsonArray = jsonValue.isArray(); - if(jsonArray == null){ - throw new FormatException("the field \"" + key + "\" must be a string array"); + if(jsonValue.isNull() != null){ + // the value must be null, so return an emtpy ArrayList + return values; } else { - for(int i = 0; i != jsonArray.size(); ++i){ - JSONValue itemValue = jsonArray.get(i); - JSONString itemString = itemValue.isString(); - if(itemString == null){ - throw new FormatException("the field \"" + key + "\" must be a string array"); - } else { - values.add(itemString.stringValue()); + JSONArray jsonArray = jsonValue.isArray(); + if(jsonArray == null){ + throw new FormatException("the field \"" + key + "\" must be a string array, but is " + jsonValue); + } else { + for(int i = 0; i != jsonArray.size(); ++i){ + JSONValue itemValue = jsonArray.get(i); + JSONString itemString = itemValue.isString(); + if(itemString == null){ + throw new FormatException("the field \"" + key + "\" must be a string array, but is " + jsonValue); + } else { + values.add(itemString.stringValue()); + } } } } @@ -579,16 +592,21 @@ if(object.containsKey(key)){ JSONValue jsonValues = object.get(key); JSONArray jsonArray = jsonValues.isArray(); - if(jsonArray == null){ - throw new FormatException("the field \"" + key + "\" must be an array of JSON objects"); + if(jsonValues.isNull() != null){ + // the value must be null, so return an emtpy ArrayList + return values; } else { - for(int i = 0; i != jsonArray.size(); ++i){ - JSONValue jsonValue = jsonArray.get(i); - JSONObject jsonObject = jsonValue.isObject(); - if(jsonObject == null){ - throw new FormatException("the field \"" + key + "\" must be an array of JSON objects"); - } else { - values.add(jsonObject); + if(jsonArray == null){ + throw new FormatException("the field \"" + key + "\" must be an array of JSON objects"); + } else { + for(int i = 0; i != jsonArray.size(); ++i){ + JSONValue jsonValue = jsonArray.get(i); + JSONObject jsonObject = jsonValue.isObject(); + if(jsonObject == null){ + throw new FormatException("the field \"" + key + "\" must be an array of JSON objects"); + } else { + values.add(jsonObject); + } } } } Modified: branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/TestClass.java ============================================================================== --- branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/TestClass.java Thu Jun 30 03:28:32 2011 (r535) +++ branches/gdl-frontend/src/anaToMia/GDL_TmEngine/src/us/isidor/gdl/anaToMia/TmEngine/jtmsBasedEngine/TestClass.java Thu Jun 30 03:30:38 2011 (r536) @@ -29,19 +29,7 @@ private Label exportedJTMLabel = new Label(); private Label title = new Label(); private HorizontalPanel statusPanel = new HorizontalPanel(); - private String tmData = "{\"version\":\"1.1\","+ - "\"item_type\":\"topicmap\"," + - "\"item_identifiers\":[\"http://some.where/my-tm\"]," + - "\"topics\":[{\"subject_identifiers\":[\"http://some.where/my-top-1\"," + - "\"http://some.where/my-top-1-1\"]," + - "\"names\":[{\"item_identifiers\":[\"http://some.where/my-name-ii-1\"]," + - "\"value\":\"_Test_Topic_\"," + - "\"scope\":[\"si:http://some.where/my-scope-1\"," + - "\"si:http://some.where/my-scope-2\"]," + - "\"type\":\"si:http://some.where/my-name-type-1\"}]}," + - "{\"subject_identifiers\":[\"http://some.where/my-name-type-1\"]}," + - "{\"subject_identifiers\":[\"http://some.where/my-scope-1\"]}," + - "{\"subject_identifiers\":[\"http://some.where/my-scope-2\"]}]}"; + private String tmData = "{\"version\":\"1.1\",\"prefixes\":{\"pref_1\":\"http://www.topicmaps.org/xtm/1.0/core.xtm#\",\"pref_2\":\"http://psi.topicmaps.org/iso13250/model/\",\"pref_5\":\"http://some.where/tmsparql/author/\",\"xsd\":\"http://www.w3.org/2001/XMLSchema#\",\"pref_3\":\"http://psi.topicmaps.org/tmcl/\",\"pref_6\":\"http://some.where/psis/poem/\",\"pref_4\":\"http://some.where/tmsparql/\",\"pref_7\":\"http://some.where/ii/zb/\",\"pref_8\":\"http://some.where/ii/\"},\"item_identifiers\":[\"[pref_4:jtm-tm]\"],\"topics\":[{\"subject_identifiers\":[\"[pref_1:topic]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":null,\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_1:association]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":null,\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_1:occurrence]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":null,\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_1:class-instance]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":null,\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_1:class]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":null,\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_1:supertype-subtype]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":null,\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_1:supertype]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":null,\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_1:subtype]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":null,\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_1:sort]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":null,\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_1:display]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":null,\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_2:type-instance]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":null,\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_2:type]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":null,\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_2:instance]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":null,\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_3:topic-type]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:topic-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_3:occurrence-type]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:topic-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_3:association-type]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:topic-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_4:written-by]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:association-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_3:role-type]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:topic-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_4:written]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:role-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_4:writer]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:role-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_3:name-type]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:topic-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_3:scope-type]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:topic-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_4:author]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:topic-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_4:poem]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:topic-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_4:first-name]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:name-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_4:last-name]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:name-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_4:title]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:name-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_4:display-name]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:scope-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_4:de]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:scope-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_4:date-of-birth]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:occurrence-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_4:date-of-death]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:occurrence-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_4:poem-content]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:occurrence-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_4:years]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:occurrence-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_4:isDead]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:occurrence-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_4:isAlive]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:occurrence-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_4:reifier-type]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_3:topic-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_5:goethe]\"],\"subject_locators\":null,\"item_identifiers\":[\"[pref_8:goethe]\"],\"instance_of\":[\"si:[pref_4:author]\"],\"names\":[{\"item_identifiers\":null,\"value\":\"Johann Wolfgang\",\"type\":\"si:[pref_4:first-name]\",\"scope\":null,\"variants\":null,\"reifier\":null},{\"item_identifiers\":null,\"value\":\"von Goethe\",\"type\":\"si:[pref_4:last-name]\",\"scope\":null,\"variants\":[{\"item_identifiers\":[\"[pref_8:goethe-variant]\"],\"datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"value\":\"Goethe\",\"scope\":[\"si:[pref_4:display-name]\"],\"reifier\":null}],\"reifier\":\"ii:[pref_8:goethe-name-reifier]\"},{\"item_identifiers\":[\"[pref_8:goethe-untyped-name]\"],\"value\":\"Johann Wolfgang von Goethe\",\"type\":null,\"scope\":null,\"variants\":null,\"reifier\":null}],\"occurrences\":[{\"item_identifiers\":[\"[pref_8:goethe-occ]\"],\"datatype\":\"http://www.w3.org/2001/XMLSchema#date\",\"type\":\"si:[pref_4:date-of-birth]\",\"value\":\"28.08.1749\",\"scope\":null,\"reifier\":\"ii:[pref_8:goethe-occ-reifier]\"},{\"item_identifiers\":null,\"datatype\":\"http://www.w3.org/2001/XMLSchema#date\",\"type\":\"si:[pref_4:date-of-death]\",\"value\":\"22.03.1832\",\"scope\":null,\"reifier\":null},{\"item_identifiers\":[\"[pref_8:goethe-years-occ]\"],\"datatype\":\"http://www.w3.org/2001/XMLSchema#integer\",\"type\":\"si:[pref_4:years]\",\"value\":\"82\",\"scope\":null,\"reifier\":null},{\"item_identifiers\":null,\"datatype\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"type\":\"si:[pref_4:isDead]\",\"value\":\"true\",\"scope\":null,\"reifier\":null},{\"item_identifiers\":null,\"datatype\":\"http://www.w3.org/2001/XMLSchema#boolean\",\"type\":\"si:[pref_4:isAlive]\",\"value\":\"false\",\"scope\":null,\"reifier\":null}]},{\"subject_identifiers\":null,\"subject_locators\":null,\"item_identifiers\":[\"[pref_8:goethe-occ-reifier]\"],\"instance_of\":[\"si:[pref_4:reifier-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":null,\"subject_locators\":null,\"item_identifiers\":[\"[pref_8:goethe-name-reifier]\"],\"instance_of\":[\"si:[pref_4:reifier-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":[\"[pref_6:zauberlehrling]\"],\"subject_locators\":null,\"item_identifiers\":null,\"instance_of\":[\"si:[pref_4:poem]\"],\"names\":[{\"item_identifiers\":null,\"value\":\"Der Zauberlehrling\",\"type\":\"si:[pref_4:title]\",\"scope\":null,\"variants\":null,\"reifier\":null}],\"occurrences\":[{\"item_identifiers\":[\"[pref_7:occurrence]\"],\"datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"type\":\"si:[pref_4:poem-content]\",\"value\":\"Hat der alte Hexenmeister ... sich doch einmal wegbegeben! ...\",\"scope\":[\"si:[pref_4:de]\"],\"reifier\":null}]},{\"subject_identifiers\":null,\"subject_locators\":null,\"item_identifiers\":[\"[pref_8:association-reifier]\"],\"instance_of\":[\"si:[pref_4:reifier-type]\"],\"names\":null,\"occurrences\":null},{\"subject_identifiers\":null,\"subject_locators\":null,\"item_identifiers\":[\"[pref_8:role-reifier]\"],\"instance_of\":[\"si:[pref_4:reifier-type]\"],\"names\":null,\"occurrences\":null}],\"associations\":[{\"item_identifiers\":[\"[pref_8:association]\"],\"type\":\"si:[pref_4:written-by]\",\"reifier\":\"ii:[pref_8:association-reifier]\",\"scope\":null,\"roles\":[{\"item_identifiers\":null,\"type\":\"si:[pref_4:writer]\",\"reifier\":\"ii:[pref_8:role-reifier]\",\"player\":\"si:[pref_5:goethe]\"},{\"item_identifiers\":[\"[pref_8:role-2]\"],\"type\":\"si:[pref_4:written]\",\"reifier\":null,\"player\":\"si:[pref_6:zauberlehrling]\"}]}],\"item_type\":\"topicmap\",\"reifier\":null}"; @Override public void onModuleLoad() { @@ -111,10 +99,13 @@ try{ tme.importTopicMap(userInputField.getValue(), tm); }catch(FormatException fe){ + fe.printStackTrace(); Window.alert("caught error: " + fe.getMessage()); }catch(MissingReference me){ + me.printStackTrace(); Window.alert("caught error: " + me.getMessage()); }catch (Exception e){ + e.printStackTrace(); Window.alert("cought error: " + e.getMessage()); }finally { topicsLabel.setText("topics: " + tm.getTopics().length());
participants (1)
-
lgiessmann@common-lisp.net