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

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Sun Jul 31 14:05:44 UTC 2011


Author: lgiessmann
Date: Sun Jul 31 07:05:43 2011
New Revision: 694

Log:
gdl-frontend: Widgets: implemented the method TmHelper.getTmValuesForTypeConstraint()

Modified:
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.java
   branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/IGdlHasValueGroup.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/text/GdlText.java

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.java	Sun Jul 31 02:09:48 2011	(r693)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlPsis.java	Sun Jul 31 07:05:43 2011	(r694)
@@ -32,6 +32,8 @@
 		public final static String tmclScopeConstraint = tmcl + "scope-constraint";
 		public final static String tmclTopicNameConstraint = tmcl + "topic-name-constraint";
 		public final static String tmclTopicOccurrenceConstraint = tmcl + "topic-occurrence-constraint";
+		public final static String tmclTopicRoleConstraint = tmcl + "topic-role-constraint";
+		public final static String tmclAssociationRoleConstraint = tmcl + "association-role-constraint";
 	}
 	
 	

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/IGdlHasValueGroup.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/IGdlHasValueGroup.java	Sun Jul 31 02:09:48 2011	(r693)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/IGdlHasValueGroup.java	Sun Jul 31 07:05:43 2011	(r694)
@@ -3,6 +3,7 @@
 import java.util.ArrayList;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Construct;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
+import us.isidor.gdl.anaToMia.Widgets.environment.ExecutionException;
 import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException;
 
 
@@ -49,7 +50,7 @@
 	// returns the topic that can be used to satisfy the constraint, that is
 	// bound to the element's value group instance. Note, this method
 	// returns all topics of a topic map that can be used for a defined constraint
-	public ArrayList<Topic> getTmValuesForConstraint() throws InvalidGdlSchemaException;
+	public ArrayList<Topic> getTmValuesForConstraint() throws InvalidGdlSchemaException, ExecutionException;
 	
 	// returns a regular expression that must be satisfied to satisfy the
 	// constraint, that is bound to the element's value group instance

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	Sun Jul 31 02:09:48 2011	(r693)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java	Sun Jul 31 07:05:43 2011	(r694)
@@ -11,6 +11,7 @@
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Topic;
 import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.TopicMap;
 import us.isidor.gdl.anaToMia.Widgets.base.GdlPsis.TMDM;
+import us.isidor.gdl.anaToMia.Widgets.environment.ExecutionException;
 import us.isidor.gdl.anaToMia.Widgets.environment.InvalidGdlSchemaException;
 import us.isidor.gdl.anaToMia.Widgets.environment.Pair;
 import us.isidor.gdl.anaToMia.Widgets.environment.TopicIdentifierTypes;
@@ -146,6 +147,21 @@
 	}
 	
 	
+	// returns true if the passed topic subtype is a subtype of the passed
+	// topic supertype
+	public static boolean isSupertypeOf(Topic subtype, Topic supertype){
+		return getAllSuperTypes(subtype, null).contains(supertype);
+	}
+	
+	
+	// returns true if the passed topic subtype is a subtype of the passed
+	// topic supertype, that is represented by the supertype psi
+	public static boolean isSupertypeOf(Topic subtype, String supertype){
+		if(subtype == null) return false;
+		return isSupertypeOf(subtype, getTopicByPsi(supertype, subtype.getTopicMap()));
+	}
+	
+	
 	// returns the direct supertypes of the passed topic
 	public static ArrayList<Topic> getDirectSuperTypes(Topic top){
 		ArrayList<Topic> result = new ArrayList<Topic>();
@@ -709,7 +725,7 @@
 
 	
 	// returns the topic that can be used to satisfy the passed constraint.
-	public static ArrayList<Topic> getTmValuesForConstraint(Topic constraint, Topic valueGroup) throws InvalidGdlSchemaException {
+	public static ArrayList<Topic> getTmValuesForConstraint(Topic constraint, Topic valueGroup) throws InvalidGdlSchemaException, ExecutionException {
 		ArrayList<Topic> result = new ArrayList<Topic>();
 		if(constraint == null || valueGroup == null) return result;
 		
@@ -762,19 +778,35 @@
 	
 	
 	// returns the topic that can be used to satisfy the passed type-constraint.
-	public static ArrayList<Topic> getTmValuesForTypeConstraint(Topic typeConstraint, Topic valueGroup) throws InvalidGdlSchemaException {
+	public static ArrayList<Topic> getTmValuesForTypeConstraint(Topic typeConstraint, Topic valueGroup) throws InvalidGdlSchemaException, ExecutionException {
 		ArrayList<Topic> result = new ArrayList<Topic>();
 		if(typeConstraint == null || valueGroup == null) return result;
 		
 		Topic rootConstraint = getRootConstraintOfValueGroup(valueGroup, typeConstraint);
 		if(rootConstraint == null) return result;
-		
+				
 		if(isInstanceOf(rootConstraint, GdlPsis.TMCL.tmclTopicNameConstraint) || isInstanceOf(rootConstraint, GdlPsis.TMCL.tmclTopicOccurrenceConstraint)){
-			
-		} else if(true /* TODO: association */){
-			
-		} else if(true /* TODO: role */){
-			
+			TopicMap tm = rootConstraint.getTopicMap();
+			Topic constraintRoleType = getTopicByPsi(GdlPsis.TMCL.tmclConstraint, tm);
+			Topic constrainedRoleType = getTopicByPsi(GdlPsis.TMCL.tmclConstrained, tm);
+			Topic nameType = getTopicByPsi(GdlPsis.TMCL.tmclNameType, tm);
+			Topic occurrenceType = getTopicByPsi(GdlPsis.TMCL.tmclOccurrenceType, tm);
+			Topic constrainedStatementAssocType = getTopicByPsi(GdlPsis.TMCL.tmclConstrainedStatement, tm);
+			ArrayList<Topic> nameTypeTopics = getOtherPlayerOfBinaryAssociation(rootConstraint, constraintRoleType, constrainedStatementAssocType, null, nameType, constrainedRoleType);
+			ArrayList<Topic> occurrenceTypeTopics = getOtherPlayerOfBinaryAssociation(rootConstraint, constraintRoleType, constrainedStatementAssocType, null, occurrenceType, constrainedRoleType);
+			ArrayList<Topic> typeTopics = Utils.union(nameTypeTopics, occurrenceTypeTopics);
+						
+			if(typeTopics.size() != 1){
+				throw new InvalidGdlSchemaException("the constraint " + getAnyIdOfTopic(rootConstraint) + " must be bound extactly once to an occurrence or name type, but is: " + typeTopics.size());
+			} else {
+				// get subtypes of typeTopic
+				JsArray<Topic> allTopics = tm.getTopics();
+				for(int i = 0; i != allTopics.length(); ++i) if(isSupertypeOf(allTopics.get(i), typeTopics.get(0))) result.add(allTopics.get(i));
+			}
+		} else if(isInstanceOf(rootConstraint, GdlPsis.TMCL.tmclAssociationRoleConstraint)){
+			throw new ExecutionException(GdlPsis.TMCL.tmclAssociationRoleConstraint + " is not implemented yet");
+		} else if(isInstanceOf(rootConstraint, GdlPsis.TMCL.tmclTopicRoleConstraint)){
+			throw new ExecutionException(GdlPsis.TMCL.tmclTopicRoleConstraint + " is not implemented yet");
 		}
 		
 		return result;

Modified: branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlText.java
==============================================================================
--- branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlText.java	Sun Jul 31 02:09:48 2011	(r693)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/text/GdlText.java	Sun Jul 31 07:05:43 2011	(r694)
@@ -929,7 +929,7 @@
 
 
 	@Override
-	public ArrayList<Topic> getTmValuesForConstraint() throws InvalidGdlSchemaException {
+	public ArrayList<Topic> getTmValuesForConstraint() throws InvalidGdlSchemaException, ExecutionException {
 		return TmHelper.getTmValuesForConstraint(this.getConstraint(), this.getValueGroup());
 	}
 




More information about the Isidorus-cvs mailing list