
Author: lgiessmann Date: Thu Aug 25 06:56:56 2011 New Revision: 786 Log: gdl-frontend: Widgets: finalised the implementeation of gdl:preferred-scope in the display-by schema 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 06:32:05 2011 (r785) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java Thu Aug 25 06:56:56 2011 (r786) @@ -1938,6 +1938,8 @@ } + // returns the topic instance of gdlt:Value-Group that is bound to this + // visible element, or null if it is unbound public Topic getValueGroup() throws InvalidGdlSchemaException { if(this.valueGroupTopicSet){ return this.valueGroupTopic; @@ -1949,6 +1951,8 @@ } + // returns the direct (first) constraint that is bound to the value-group + // of this element - or null if it is unbound public Topic getConstraint() throws InvalidGdlSchemaException { if(this.constraintTopicSet){ return this.constraintTopic; @@ -1960,6 +1964,8 @@ } + // returns the root (last) constraint that is bound to the value-group + // of this element - or null if it is unbound public Topic getRootConstraint() throws InvalidGdlSchemaException { if(this.rootConstraintTopicSet){ return this.rootConstraintTopic; @@ -1971,6 +1977,8 @@ } + // returns the topic that represents the default topic maps value of + // the value-group that is bound to this element - null if it is unbound public Topic getDefaultTmValue() throws InvalidGdlSchemaException { if(this.defaultTmValueTopicSet){ return this.defaultTmValueTopic; @@ -1982,6 +1990,8 @@ } + // returns the topic that represents the default literal value of the + // value-group that is bound to this element - or null if it is unbound public Topic getDefaultLiteralValue() throws InvalidGdlSchemaException { if(this.defaultLiteralValueTopicSet){ return this.defaultLiteralValueTopic; @@ -1993,6 +2003,8 @@ } + // returns the topic that represents the default value of + // the value-group that is bound to this element - null if it is unbound public Topic getDefaultValue() throws InvalidGdlSchemaException { if(this.getDefaultLiteralValue() != null && this.getDefaultTmValue() != null) throw new InvalidGdlSchemaException("the topic " + TmHelper.getAnyIdOfTopic(this.getValueGroup()) + " must be bound to maximal one " + PSIs.GDL.TopicType.gdlDefaultValue + ", but is: 2"); else if(this.getDefaultLiteralValue() != null) return this.getDefaultLiteralValue(); @@ -2000,6 +2012,8 @@ } + // returns true if the default value is fixed + // otherwise the return value is false public boolean fixedDefaultValue() throws InvalidGdlSchemaException{ Topic defVal = this.getDefaultValue(); @@ -2020,6 +2034,8 @@ } + // returns all topic maps values 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; @@ -2031,6 +2047,8 @@ } + // returns all topics that represents literal values for this value-group - or + // an empty ArrayList public ArrayList<Topic> getLiteralValues() throws InvalidGdlSchemaException { if(this.literalValueTopicsSet){ return this.literalValueTopics; @@ -2042,28 +2060,36 @@ } + // returns the set literal value or null public String getSetLiteralValue() throws InvalidGdlSchemaException { // TODO Auto-generated method stub return null; } + // returns the set tm value or null public Construct getSetTmValue() throws InvalidGdlSchemaException { // TODO Auto-generated method stub return null; } + // returns the valid topic maps value for the constraint that is 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()); } + // returns the regular expression that is set for the constraint bound to the + // value-group of this element public String getLiteralValueForConstraint() throws InvalidGdlSchemaException { return TmHelper.getLiteralValueForConstraint(this.getConstraint()); } + // returns the display-by schema that is defined for the value-group that + // is bound to this element public Topic getDisplayByOfValueGroup() throws InvalidGdlSchemaException { if(this.displayByConstraintSet){ return this.displayByConstraint; @@ -2075,6 +2101,8 @@ } + // returns the preferred scope that is bound to the value-group of + // this element - or an empty ArrayList public ArrayList<Topic> getPreferredScopeOfValueGroup() throws InvalidGdlSchemaException { if(this.prefferedScopesSet){ return this.preferredScopes; @@ -2086,6 +2114,8 @@ } + // returns the string that represents the topic topicToRepresent corresponding + // to the passed displayBy and prefferedScopes arguments public String getTopicRepresentation(Topic topicToRepresent, Topic displayBy, ArrayList<Topic> preferredScopes) throws InvalidGdlSchemaException { return TmHelper.getTopicRepresentation(topicToRepresent, displayBy, preferredScopes); } 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 06:32:05 2011 (r785) +++ branches/gdl-frontend/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TmHelper.java Thu Aug 25 06:56:56 2011 (r786) @@ -1116,50 +1116,44 @@ Topic itemIdentifierConstraint = getTopicByPsi(PSIs.TMCL.tmclItemIdentifierConstraint, tm); Topic topicNameConstraint = getTopicByPsi(PSIs.TMCL.tmclTopicNameConstraint, tm); - String result = null; if(isInstanceOf(displayBy, topicNameConstraint)){ Topic nameType = TmHelper.getConstrainedStatement(displayBy); - ArrayList<Name> names = new ArrayList<Name>(); - for(int i = 0; i != topicToRepresent.getNames(nameType).length(); ++i) - names.add(topicToRepresent.getNames(nameType).get(i)); - - if(preferredScopes != null && preferredScopes.size() != 0){ - // TODO: implement + for(int i = 0; i != topicToRepresent.getNames(nameType).length(); ++i){ + Name name = topicToRepresent.getNames(nameType).get(i); + if(preferredScopes == null || preferredScopes.size() == 0){ + return name.getValue(); + } else { + for(int j = 0; j != name.getScope().length(); ++j){ + if(preferredScopes.contains(name.getScope().get(j))) return name.getValue(); + } + } } - if(names.size() != 0) result = names.get(0).getValue(); + throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(topicToRepresent) + " does not contain any name that can be used for its " + PSIs.GDL.AssociationType.gdlDisplayBy + " schema"); + } else if(isInstanceOf(displayBy, subjectIdentifierConstraint)){ Pattern rex = new Pattern(TmHelper.getLiteralValueForConstraint(displayBy)); for(int i = 0; i != topicToRepresent.getSubjectIdentifiers().length(); ++i){ String psi = topicToRepresent.getSubjectIdentifiers().get(i).getReference(); - if(rex.matches(psi)){ - result = psi; - break; - } + if(rex.matches(psi)) return psi; } + throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(topicToRepresent) + " does not contain any subject-identifier that can be used for its " + PSIs.GDL.AssociationType.gdlDisplayBy + " schema"); } else if(isInstanceOf(displayBy, subjectLocatorConstraint)){ Pattern rex = new Pattern(TmHelper.getLiteralValueForConstraint(displayBy)); for(int i = 0; i != topicToRepresent.getSubjectLocators().length(); ++i){ - String psi = topicToRepresent.getSubjectLocators().get(i).getReference(); - if(rex.matches(psi)){ - result = psi; - break; - } + String sl = topicToRepresent.getSubjectLocators().get(i).getReference(); + if(rex.matches(sl)) return sl; } + throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(topicToRepresent) + " does not contain any subject-locator that can be used for its " + PSIs.GDL.AssociationType.gdlDisplayBy + " schema"); } else if(isInstanceOf(displayBy, itemIdentifierConstraint)){ Pattern rex = new Pattern(TmHelper.getLiteralValueForConstraint(displayBy)); for(int i = 0; i != topicToRepresent.getItemIdentifiers().length(); ++i){ - String psi = topicToRepresent.getItemIdentifiers().get(i).getReference(); - if(rex.matches(psi)){ - result = psi; - break; - } + String ii = topicToRepresent.getItemIdentifiers().get(i).getReference(); + if(rex.matches(ii)) return ii; } + throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(topicToRepresent) + " does not contain any item-identifier that can be used for its " + PSIs.GDL.AssociationType.gdlDisplayBy + " schema"); } else { throw new InvalidGdlSchemaException("the topic " + getAnyIdOfTopic(displayBy) + " is not a valid representation schema type"); } - - if(result == null) throw new InvalidGdlSchemaException(""); - else return result; } } }