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

lgiessmann at common-lisp.net lgiessmann at common-lisp.net
Thu Aug 25 21:25:07 UTC 2011


Author: lgiessmann
Date: Thu Aug 25 14:25:06 2011
New Revision: 788

Log:
gdl-frontend: Widgets: added some methods to get the raw string of gdlt:Literal-Value instances

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

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	Thu Aug 25 07:41:29 2011	(r787)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java	Thu Aug 25 14:25:06 2011	(r788)
@@ -100,6 +100,8 @@
 	protected boolean prefferedScopesSet = false;
 	protected Topic displayByConstraint = null;
 	protected boolean displayByConstraintSet = false;
+	protected ArrayList<String> literals = new ArrayList<String>();
+	protected boolean literalsSet = false;
 	
 
 	// some constructors
@@ -2059,6 +2061,18 @@
 		}
 	}
 
+	
+	// returns an ArrayList of strings that are set to a value group as literal values
+	public ArrayList<String> getLiterals() throws InvalidGdlSchemaException {
+		if(this.literalsSet){
+			return this.literals;
+		} else {
+			this.literalsSet = true;
+			this.literals = TmHelper.getLiterals(this.getValueGroup());
+			return this.literals;
+		}
+	}
+	
 
 	// returns the set literal value or null
 	public String getSetLiteralValue() throws InvalidGdlSchemaException {
@@ -2074,7 +2088,7 @@
 	}
 
 
-	// returns the valid topic maps value for the constraint that is bound
+	// returns the valid topic maps value for the constraint bound
 	// to the value-group that is bound to this element - or an empty ArrayList
 	public ArrayList<Topic> getTmValuesForConstraint() throws InvalidGdlSchemaException, ExecutionException {
 		return TmHelper.getTmValuesForConstraint(this.getConstraint(), 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	Thu Aug 25 07:41:29 2011	(r787)
+++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java	Thu Aug 25 14:25:06 2011	(r788)
@@ -846,7 +846,7 @@
 	}
 	
 	
-	// returns the topics that represent the literal value for the passed value group
+	// returns the topics that represent the literal values for the passed value group
 	public static ArrayList<Topic> getLiteralValues(Topic valueGroup){
 		ArrayList<Topic> result = new ArrayList<Topic>();
 		if(valueGroup == null) return result;
@@ -861,6 +861,26 @@
 	}
 
 	
+	// returns a string that is the literal value of the literal-value-topic
+	public static String getLiteral (Topic literalValue) throws InvalidGdlSchemaException {
+		if(literalValue == null) return null;
+		
+		Occurrence occ = getSingleOccurrence(literalValue, getTopicByPsi(PSIs.GDL.OccurrenceType.gdlLiteralValue, literalValue.getTopicMap()));
+		if(occ == null) throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(literalValue) + " must be bound exactly once to an occurrence of the type " + PSIs.GDL.OccurrenceType.gdlLiteralValue + ", but is: 0");
+		else return occ.getValue();
+	}
+	
+	
+	// returns an ArrayList of strings that are set to a value group as literal values
+	public static ArrayList<String> getLiterals(Topic valueGroup) throws InvalidGdlSchemaException {
+		ArrayList<Topic> literalTopics = getLiteralValues(valueGroup);
+		
+		ArrayList<String> result = new ArrayList<String>();
+		for (Topic topic : literalTopics) result.add(getLiteral(topic));
+		
+		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>();
@@ -873,7 +893,7 @@
 		} else if(isInstanceOf(constraint, PSIs.GDL.TopicType.gdlVariantNameScope)){
 			return getTmValuesForVariantNameScopeConstraint(constraint);
 		} else if(isInstanceOf(constraint, PSIs.GDL.TopicType.gdlRolePlayer)){
-			return getTmValuesForRolePlayerConstraint(constraint);
+			return getTmValuesForRolePlayerConstraint(constraint, valueGroup);
 		} else if(isInstanceOf(constraint, PSIs.TMCL.tmclReifierConstraint)){
 			return getTmValuesForReifierConstraint(constraint);
 		} else if(isInstanceOf(constraint, PSIs.TMCL.tmclScopeConstraint)){
@@ -928,8 +948,20 @@
 	
 	
 	// returns the topic that can be used to satisfy the passed role-player-constraint.
-	public static ArrayList<Topic> getTmValuesForRolePlayerConstraint(Topic rolePlayerConstraint) throws ExecutionException{
-		throw new ExecutionException("this method is currently not implemented");
+	public static ArrayList<Topic> getTmValuesForRolePlayerConstraint(Topic rolePlayerConstraint, Topic valueGroup) throws ExecutionException, InvalidGdlSchemaException {
+		ArrayList<Topic> result = new ArrayList<Topic>();
+		if(rolePlayerConstraint == null || valueGroup == null) return result;
+		
+		Topic topicRoleConstraint = getRootConstraintOfValueGroup(valueGroup, rolePlayerConstraint);
+		if(!isInstanceOf(topicRoleConstraint, PSIs.TMCL.tmclTopicRoleConstraint)) throw new InvalidGdlSchemaException("the root constraint of the topic " + getAnyIdOfTopic(rolePlayerConstraint) + " must be an instance of " + PSIs.TMCL.tmclTopicRoleConstraint + ", but is: " + getAnyIdOfTopic(topicRoleConstraint));
+		
+		Pair<Topic, Topic> roleAndPlayerType = getConstrainedRoleAndPlayerTypeOfConstraint(topicRoleConstraint);
+		Topic playerType = roleAndPlayerType.getSecond();
+		JsArray<Topic> allTopics = rolePlayerConstraint.getTopicMap().getTopics();
+		for(int i = 0; i != allTopics.length(); ++i)
+			if(isInstanceOf(allTopics.get(i), playerType)) result.add(allTopics.get(i));
+		
+		return result;
 	}
 	
 	
@@ -963,8 +995,10 @@
 				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, PSIs.TMCL.tmclAssociationRoleConstraint)){
+			// TODO: implement
 			throw new ExecutionException(PSIs.TMCL.tmclAssociationRoleConstraint + " is not implemented yet");
 		} else if(isInstanceOf(rootConstraint, PSIs.TMCL.tmclTopicRoleConstraint)){
+			// TODO: implement
 			throw new ExecutionException(PSIs.TMCL.tmclTopicRoleConstraint + " is not implemented yet");
 		}
 		
@@ -974,12 +1008,14 @@
 	
 	// returns the topic that can be used to satisfy the passed variant-name-reifier-constraint.
 	public static ArrayList<Topic> getTmValuesForVariantNameReifierConstraint(Topic variantNameReifierConstraint) throws ExecutionException {
+		// TODO: implement
 		throw new ExecutionException("this mehtod is currently not implemented");
 	}
 	
 	
 	// returns the topic that can be used to satisfy the passed variant-name-scope-constraint.
 	public static ArrayList<Topic> getTmValuesForVariantNameScopeConstraint(Topic variantNameScopeConstraint) throws ExecutionException{
+		// TODO: implement
 		throw new ExecutionException("this method is currently not implemented");
 	}
 	




More information about the Isidorus-cvs mailing list