[isidorus-cvs] r774 - in branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets: base view

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Mon Aug 22 20:52:09 UTC 2011


Author: lgiessmann
Date: Mon Aug 22 13:52:07 2011
New Revision: 774

Log:
gdl-frontend: Widgets: finalised the filtering of consuming user data in GdlAssociationView

Modified:
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/PSIs.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.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/view/GdlAssociationView.java

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/PSIs.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/PSIs.java	Mon Aug 22 10:53:48 2011	(r773)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/PSIs.java	Mon Aug 22 13:52:07 2011	(r774)
@@ -46,6 +46,8 @@
 		public final static String tmclConstrainedTopicType = tmcl + "constrained-topic-type";
 		public final static String tmclConstrainedRole = tmcl + "constrained-role";
 		public final static String tmclRoleCombinationConstraint = tmcl + "role-combination-constraint";
+		public final static String tmclOtherConstrainedTopicType = tmcl + "other-constrained-topic-type";
+		public final static String tmclOtherConstrainedRole = tmcl + "other-constrained-role"; 
 	}
 	
 	

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java	Mon Aug 22 10:53:48 2011	(r773)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java	Mon Aug 22 13:52:07 2011	(r774)
@@ -1,7 +1,6 @@
 package us.isidor.gdl.anaToMia.Widgets.base;
 
 
-import java.util.ArrayList;
 
 import us.isidor.gdl.anaToMia.TmEngine.jtmsBasedEngine.JtmsTmEngine;
 import us.isidor.gdl.anaToMia.Widgets.environment.Pair;

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	Mon Aug 22 10:53:48 2011	(r773)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java	Mon Aug 22 13:52:07 2011	(r774)
@@ -656,14 +656,42 @@
 		Topic constraintRoleType = getTopicByPsi(PSIs.TMCL.tmclConstraint, tm);
 		Topic constrainedTopicTypeAssocType = getTopicByPsi(PSIs.TMCL.tmclConstrainedTopicType, tm);
 		Topic constrainedRoleType = getTopicByPsi(PSIs.TMCL.tmclConstrained, tm);
-		Topic topicType = getTopicByPsi(PSIs.TMCL.tmclTopictype, tm);
-		ArrayList<Topic> result = getOtherPlayerOfBinaryAssociation(topicRoleConstraint, constraintRoleType, constrainedTopicTypeAssocType, null, topicType, constrainedRoleType);
+		ArrayList<Topic> result = getOtherPlayerOfBinaryAssociation(topicRoleConstraint, constraintRoleType, constrainedTopicTypeAssocType, null, constrainedRoleType);
 		
 		if(result.size() != 1) throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(topicRoleConstraint) + " must be bound exactly once to a topic-type via a " + PSIs.TMCL.tmclConstrainedTopicType + " association, but is bound: " + result.size());
 		else return new Pair<Topic, Topic>(getConstraintRoleOfConstraint(topicRoleConstraint), result.get(0));
 	}
 	
 	
+	// return a pair that contains again two pair instances, whereas each pair
+	// represents a role type and a role player. The outer pair represents a valid
+	// combination of roles of a role-combination-constraint.
+	public static Pair<Pair<Topic, Topic>, Pair<Topic, Topic>> getRoleCombinationsOfConstraint(Topic roleCombinationconstraint) throws InvalidGdlSchemaException {
+		if(roleCombinationconstraint == null) return null;
+		
+		TopicMap tm = roleCombinationconstraint.getTopicMap();
+		Topic constraintRoleType = getTopicByPsi(PSIs.TMCL.tmclConstraint, tm);
+		Topic constrainedRoleAssocType = getTopicByPsi(PSIs.TMCL.tmclConstrainedRole, tm);
+		Topic constrainedRoleType = getTopicByPsi(PSIs.TMCL.tmclConstrained, tm);
+		ArrayList<Topic> roleTypes = getOtherPlayerOfBinaryAssociation(roleCombinationconstraint, constraintRoleType, constrainedRoleAssocType, null, constrainedRoleType);
+		if(roleTypes.size() != 1) throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(roleCombinationconstraint) + " must be bound exactly once to a role-type via a " + PSIs.TMCL.tmclConstrainedRole + ", but is: " + roleTypes.size());
+		Topic constrainedTopicTypeAssocType = getTopicByPsi(PSIs.TMCL.tmclConstrainedTopicType, tm);
+		ArrayList<Topic> playerTypes = getOtherPlayerOfBinaryAssociation(roleCombinationconstraint, constraintRoleType, constrainedTopicTypeAssocType, null, constrainedRoleType);
+		if(playerTypes.size() != 1) throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(roleCombinationconstraint) + " must be bound exactly once to a topic-type via a " + PSIs.TMCL.tmclConstrainedTopicType + ", but is: " + playerTypes.size());
+		
+		Topic otherConstrainedRoleAssocType = getTopicByPsi(PSIs.TMCL.tmclOtherConstrainedRole, tm);
+		ArrayList<Topic> otherRoleTypes = getOtherPlayerOfBinaryAssociation(roleCombinationconstraint, constraintRoleType, otherConstrainedRoleAssocType, null, constrainedRoleType);
+		if(otherRoleTypes.size() != 1) throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(roleCombinationconstraint) + " must be bound exactly once to an other-role-type via a " + PSIs.TMCL.tmclOtherConstrainedRole + ", but is: " + otherRoleTypes.size());
+		Topic otherConstrainedTopicTypeRoleType = getTopicByPsi(PSIs.TMCL.tmclOtherConstrainedTopicType, tm);
+		ArrayList<Topic> otherPlayerType = getOtherPlayerOfBinaryAssociation(roleCombinationconstraint, constraintRoleType, otherConstrainedTopicTypeRoleType, null, constrainedRoleType);
+		if(otherPlayerType.size() != 1) throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(roleCombinationconstraint) + " must be bound exactly once to an other-topic-type via a " + PSIs.TMCL.tmclOtherConstrainedTopicType + ", but is: " + otherPlayerType.size());
+		
+		Pair<Topic, Topic> firstRole = new Pair<Topic, Topic>(roleTypes.get(0), playerTypes.get(0));
+		Pair<Topic, Topic> secondRole = new Pair<Topic, Topic>(otherRoleTypes.get(0), otherPlayerType.get(0));
+		return new Pair<Pair<Topic,Topic>, Pair<Topic,Topic>>(firstRole, secondRole);
+	}
+	
+	
 	// returns the topic that plays the role of tmcl:constrained in an association
 	// of the type tmcl:constrained-statement that is bound to the passed topic
 	// constrinatTopic that plays the role of tmcl:constraint

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlAssociationView.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlAssociationView.java	Mon Aug 22 10:53:48 2011	(r773)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/view/GdlAssociationView.java	Mon Aug 22 13:52:07 2011	(r774)
@@ -3,7 +3,6 @@
 import java.util.ArrayList;
 
 import com.google.gwt.core.client.JsArray;
-import com.google.gwt.user.client.Window;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Association;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Role;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
@@ -26,6 +25,8 @@
 	private boolean roleAndPlayerTypesSet = false;
 	private ArrayList<Topic> roleCombinationConstraints = new ArrayList<Topic>();
 	private boolean roleCombinationConstraintsSet = false;
+	private ArrayList<Pair<Pair<Topic, Topic>, Pair<Topic, Topic>>> validRoleCombinations = new ArrayList<Pair<Pair<Topic,Topic>,Pair<Topic,Topic>>>();
+	private boolean validRoleCombinationsSet = false;
 	
 
 	public GdlAssociationView(Topic tmRepresentative, Topic receivedData) throws InvalidGdlSchemaException, ExecutionException {
@@ -181,11 +182,45 @@
 	}
 
 	
-	// returns all associations contained in the ArrayList allAssociations
-	// that are valid to the role-combination-constraints that belongs to this view
-	private ArrayList<Association> filterAssociationsByRoleCombinations(ArrayList<Association> allAssociations) throws InvalidGdlSchemaException {
-		// TODO: implement
-		return null;
+	// throws an InvalidGdlSchemaException if passed one association does not satisfy
+	// any defined role-combination-constraint
+	private void checkAssociationsByRoleCombinations(ArrayList<Association> allAssociations) throws InvalidGdlSchemaException {
+		if(this.getRoleCombinationConstraints().size() == 0) return;
+		
+		for (Association assoc : allAssociations) {
+			JsArray<Role> roles = assoc.getRoles();
+			if(roles.length() != 2) throw new InvalidGdlSchemaException("the association " + assoc + " violates the defined role-combination-constrains");
+			Role fstRole = roles.get(0);
+			Role sndRole = roles.get(1);
+			
+			int i = 0;
+			for ( ; i != this.getValidRoleCombinations().size(); ++i) {
+				Pair<Topic, Topic> fstCombi = this.getValidRoleCombinations().get(i).getFirst();
+				Pair<Topic, Topic> sndCombi = this.getValidRoleCombinations().get(i).getSecond();
+				
+				if(fstRole.getType().equals(fstCombi.getFirst()) && TmHelper.isInstanceOf(fstRole.getPlayer(), fstCombi.getSecond()) &&	sndRole.getType().equals(sndCombi.getFirst()) && TmHelper.isInstanceOf(sndRole.getPlayer(), sndCombi.getSecond())) break;
+				if(sndRole.getType().equals(fstCombi.getFirst()) && TmHelper.isInstanceOf(sndRole.getPlayer(), fstCombi.getSecond()) &&	fstRole.getType().equals(sndCombi.getFirst()) && TmHelper.isInstanceOf(fstRole.getPlayer(), sndCombi.getSecond())) break;
+			}
+			
+			if(i == this.getValidRoleCombinations().size()) throw new InvalidGdlSchemaException("the association " + assoc + " violates the defined role-combination-constrains");
+		}
+	}
+	
+	
+	// Returns all valid role-player combinations for this association-view
+	public ArrayList<Pair<Pair<Topic, Topic>, Pair<Topic, Topic>>> getValidRoleCombinations() throws InvalidGdlSchemaException {
+		if(this.validRoleCombinationsSet){
+			return this.validRoleCombinations;
+		} else {
+			this.validRoleCombinationsSet = true;
+			ArrayList<Pair<Pair<Topic, Topic>, Pair<Topic, Topic>>> roleCombinations = new ArrayList<Pair<Pair<Topic,Topic>,Pair<Topic,Topic>>>();
+			for (Topic constraint : this.getRoleCombinationConstraints()) {
+				Pair<Pair<Topic, Topic>, Pair<Topic, Topic>> combination = TmHelper.getRoleCombinationsOfConstraint(constraint);
+				if(!roleCombinations.contains(combination)) roleCombinations.add(combination);
+			}
+			this.validRoleCombinations = roleCombinations;			
+			return this.validRoleCombinations;
+		}
 	}
 	
 		
@@ -193,9 +228,8 @@
 	// must be represented by this association view
 	private ArrayList<Association> filterAssociations() throws InvalidGdlSchemaException {
 		ArrayList<Association> filteredAssociations = this.filterAssociationsByType();
-		filteredAssociations = filterAssociationsByRoleAndPlayerTypes(filteredAssociations);
-		filteredAssociations = filterAssociationsByRoleCombinations(filteredAssociations);
-		
+		filteredAssociations = this.filterAssociationsByRoleAndPlayerTypes(filteredAssociations);
+		this.checkAssociationsByRoleCombinations(filteredAssociations);
 		this.associationsToRepresent = filteredAssociations;
 		this.associationsToRepresentSet = true;
 		return this.associationsToRepresent;
@@ -204,7 +238,7 @@
 	
 	// Returns the associations that are represented by this associaton-view
 	public ArrayList<Association> getAssociationsToRepresent() throws InvalidGdlSchemaException {
-		if(this.associationsToRepresentSet) return this.associationsToRepresent;
+	  	if(this.associationsToRepresentSet) return this.associationsToRepresent;
 		else return this.filterAssociations();
 	}
 }




More information about the Isidorus-cvs mailing list