[isidorus-cvs] r821 - branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Fri Sep 2 10:54:41 UTC 2011


Author: lgiessmann
Date: Fri Sep  2 03:54:41 2011
New Revision: 821

Log:
gdl-frontend: Widgets: implemented the validation of gdlt:Role-Player values

Modified:
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/Utils.java

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java	Fri Sep  2 02:59:10 2011	(r820)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java	Fri Sep  2 03:54:41 2011	(r821)
@@ -109,6 +109,8 @@
 	protected boolean cardMinSet = false;
 	protected int cardMax = 0;
 	protected boolean cardMaxSet = false;
+	protected ArrayList<Topic> rawTmValues = new ArrayList<Topic>();
+	protected boolean rawTmValuesSet = false;
 	
 
 	// some constructors
@@ -2096,8 +2098,9 @@
 	}
 	
 
-	// returns all topic maps values that are valid and declared for the value-group
-	// of this element - or an empty ArrayList
+	// returns all topic maps values represented by topics of the type gdlt:Tm-Value
+	// that are valid and declared for the value-group of this element - or
+	// an empty ArrayList
 	public ArrayList<Topic> getTmValues() throws InvalidGdlSchemaException {
 		if(this.tmValueTopicsSet){
 			return this.tmValueTopics;
@@ -2235,6 +2238,33 @@
 		}
 	}
 	
+	
+	// validates the the tm values of a constraint
+	private void validateTmValue(Topic selectedPlayer) throws InvalidContentException, InvalidGdlSchemaException, ExecutionException {
+		if(this.getRawTmValues().size() != 0 && !this.getRawTmValues().contains(selectedPlayer)){
+			throw new InvalidContentException("the topic " + TmHelper.getAnyIdOfTopic(selectedPlayer) + " does not satisfy the contraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " and the topic values: " + Utils.topicArrayToString(this.getRawTmValues()));
+		} else {
+			if(!this.getTmValuesForConstraint().contains(selectedPlayer)){
+				throw new InvalidContentException("the topic " + TmHelper.getAnyIdOfTopic(selectedPlayer) + " does not satisfy the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " and topic values: " + Utils.topicArrayToString(this.getTmValuesForConstraint()));
+			}
+		}
+	}
+	
+	
+	
+	// returns the actual topics that are set as possible tm-values
+	private ArrayList<Topic> getRawTmValues() throws InvalidGdlSchemaException{
+		if(this.rawTmValuesSet){
+			return this.rawTmValues;
+		} else {
+			this.rawTmValuesSet = true;
+			ArrayList<Topic> tmValues = this.getTmValues();
+			for (Topic tmValue : tmValues) this.rawTmValues = Utils.union(this.rawTmValues, TmHelper.getValuesForTmValue(tmValue));
+			return this.rawTmValues;
+		}
+	}
+	
+	
 	// returns the actual data that is hold by this instance
 	public ArrayList<Pair<Construct, TopicMapsTypes>> getContent(Construct carrier, boolean validate) throws InvalidGdlSchemaException, ExecutionException, InvalidContentException {
 		ArrayList<Pair<Construct, TopicMapsTypes>> result = new ArrayList<Pair<Construct,TopicMapsTypes>>();
@@ -2306,8 +2336,10 @@
 					// TODO: implement
 				} else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.GDL.TopicType.gdlRolePlayer)){
 					if(roles.size() > idx){
+						Topic player = TmHelper.getTopicFromStringRepresentation(this.getSelectedValues().get(idx), this.getValueGroup());
+						if(validate) this.validateTmValue(player);
 						changedRole = roles.get(idx);
-						changedRole.setPlayer(TmHelper.getTopicFromStringRepresentation(this.getSelectedValues().get(idx), this.getValueGroup()));
+						changedRole.setPlayer(player);
 					} else {
 						changedRole = ((Association)localCarrier).createRole(roleType, TmHelper.getTopicFromStringRepresentation(this.getSelectedValues().get(idx), this.getValueGroup()));
 					}

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java	Fri Sep  2 02:59:10 2011	(r820)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java	Fri Sep  2 03:54:41 2011	(r821)
@@ -715,7 +715,7 @@
 	}
 	
 	
-	// returns a topic or associaitons that is represented by the nearest instance of GdlView
+	// returns a topic or associations that is represented by the nearest instance of GdlView
 	public static Construct getNearestTopicOrAssociation(GdlVisibleObject elem) throws InvalidGdlSchemaException{
 		if(elem == null) return null;
 		
@@ -1021,6 +1021,7 @@
 		return result;
 	}
 	
+	
 	// returns the topic that can be used to satisfy the passed constraint.
 	public static ArrayList<Topic> getTmValuesForConstraint(Topic constraint, Topic valueGroup) throws InvalidGdlSchemaException, ExecutionException {
 		ArrayList<Topic> result = new ArrayList<Topic>();

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/Utils.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/Utils.java	Fri Sep  2 02:59:10 2011	(r820)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/Utils.java	Fri Sep  2 03:54:41 2011	(r821)
@@ -2,6 +2,8 @@
 
 import java.util.ArrayList;
 import com.google.gwt.core.client.JavaScriptObject;
+
+import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
 import us.isidor.gdl.anaToMia.Widgets.environment.Pattern;
 import com.google.gwt.core.client.JsArray;
 import com.google.gwt.dom.client.Element;
@@ -18,6 +20,21 @@
 		}
 		
 		return result.substring(0, result.length() - 2) + "]";
+	}
+	
+	
+	// returns a string of the form [item1, item2, ... ] for all
+	// topics of an ArrayList, whereas each item is any identifier
+	// of the topic
+	public static String topicArrayToString(ArrayList<Topic> topicList){
+		if(topicList == null || topicList.size() == 0) return "[ ]";
+		
+		String result = "[";
+		for (Topic top : topicList) {
+			result += TmHelper.getAnyIdOfTopic(top) + ", ";
+		}
+		
+		return result.substring(0, result.length() - 2) + "]";
 	}
 	
 	




More information about the Isidorus-cvs mailing list