Ignore:
Timestamp:
10/25/11 13:23:37 (14 years ago)
Author:
lgiessmann
Message:

gdl-frontend: Widgets: refactored the implementation for the tmcl:topic-occurrence-constraint and tmcl:topic-name-constraint semantics for generating content entered in GdlVisibleObject?

Location:
trunk/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/GdlVisibleObject.java

    r1018 r1019  
    24182418       
    24192419        // handles the getContent call for subject identifiers and subject locators
    2420         private void getTopicIdentifierContent(ArrayList<Pair<Object, TopicMapsTypes>> contents, boolean validate, Topic carier, int selectedValueIndex) throws InvalidGdlSchemaException, InvalidContentException, ExecutionException{
     2420        private void getTopicIdentifierContent(ArrayList<Pair<Object, TopicMapsTypes>> contents, boolean validate, Topic carrier, int selectedValueIndex) throws InvalidGdlSchemaException, InvalidContentException, ExecutionException{
    24212421                JsArray<Locator> identifiers = null;
    24222422                       
     
    24252425                if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclSubjectIdentifierConstraint)){
    24262426                        isPsiConstraint = true;
    2427                         identifiers = carier.getSubjectIdentifiers();
     2427                        identifiers = carrier.getSubjectIdentifiers();
    24282428                        filteredIdentifiers = this.filterLocators(TmHelper.getRegExp(this.getConstraint()), identifiers);
    24292429                } else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclSubjectLocatorConstraint)){
    2430                         identifiers = carier.getSubjectLocators();
     2430                        identifiers = carrier.getSubjectLocators();
    24312431                        filteredIdentifiers = this.filterLocators(TmHelper.getRegExp(this.getConstraint()), identifiers);
    24322432                } else {
     
    24392439                if(filteredIdentifiers.size() > selectedValueIndex){
    24402440                        changedIdentifier = filteredIdentifiers.get(selectedValueIndex);
    2441                         if(isPsiConstraint) carier.removeSubjectIdentifier(changedIdentifier);
    2442                         else carier.removeSubjectLocator(changedIdentifier);
     2441                        if(isPsiConstraint) carrier.removeSubjectIdentifier(changedIdentifier);
     2442                        else carrier.removeSubjectLocator(changedIdentifier);
    24432443                }
    24442444               
    2445                 changedIdentifier = carier.getTopicMap().createLocator(this.getSelectedValues().get(selectedValueIndex));
    2446                 if(isPsiConstraint) carier.addSubjectIdentifier(changedIdentifier);
    2447                 else carier.addSubjectLocator(changedIdentifier);
     2445                changedIdentifier = carrier.getTopicMap().createLocator(this.getSelectedValues().get(selectedValueIndex));
     2446                if(isPsiConstraint) carrier.addSubjectIdentifier(changedIdentifier);
     2447                else carrier.addSubjectLocator(changedIdentifier);
    24482448                contents.add(new Pair<Object, TopicMapsTypes>(changedIdentifier, TopicMapsTypes.Locator));
    24492449        }
     
    24512451       
    24522452        // handles the getContent call for item identifiers
    2453         private void getItemIdentifierContent(ArrayList<Pair<Object, TopicMapsTypes>> contents, boolean validate, Construct carier, int selectedValueIndex) throws InvalidGdlSchemaException, InvalidContentException, ExecutionException{
     2453        private void getItemIdentifierContent(ArrayList<Pair<Object, TopicMapsTypes>> contents, boolean validate, Construct carrier, int selectedValueIndex) throws InvalidGdlSchemaException, InvalidContentException, ExecutionException{
    24542454                if(!(this.receivedData instanceof Reifiable) || !(this.receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Reifiable, but is: " + receivedData.getClass());
    24552455
     
    24592459                int typeIdx = -1;
    24602460                JsArray<Topic> types = null;
    2461                 if((carier instanceof Topic)){
    2462                         types = ((Topic)carier).getTypes();
     2461                if((carrier instanceof Topic)){
     2462                        types = ((Topic)carrier).getTypes();
    24632463                        if(types.length() != 0){
    24642464                                for(typeIdx = 0; typeIdx != types.length(); ++typeIdx) if(types.get(typeIdx).equals(constrainedTopicType)) break;
     
    24682468                JsArray<Locator> identifiers = null;
    24692469                ArrayList<Locator> filteredIdentifiers = null;
    2470                 if((carier instanceof Topic) && types != null && typeIdx != types.length()){
    2471                         identifiers = ((Topic)carier).getItemIdentifiers();
     2470                if((carrier instanceof Topic) && types != null && typeIdx != types.length()){
     2471                        identifiers = ((Topic)carrier).getItemIdentifiers();
    24722472                        filteredIdentifiers = this.filterLocators(TmHelper.getRegExp(this.getConstraint()), identifiers);
    24732473                       
     
    24772477                        if(filteredIdentifiers.size() > selectedValueIndex){
    24782478                                changedIdentifier = filteredIdentifiers.get(selectedValueIndex);
    2479                                 ((Topic)carier).removeItemIdentifier(changedIdentifier);
     2479                                ((Topic)carrier).removeItemIdentifier(changedIdentifier);
    24802480                        }
    24812481                       
    2482                         changedIdentifier = ((Topic)carier).getTopicMap().createLocator(this.getSelectedValues().get(selectedValueIndex));
    2483                         ((Topic)carier).addItemIdentifier(changedIdentifier);
     2482                        changedIdentifier = ((Topic)carrier).getTopicMap().createLocator(this.getSelectedValues().get(selectedValueIndex));
     2483                        ((Topic)carrier).addItemIdentifier(changedIdentifier);
    24842484                        contents.add(new Pair<Object, TopicMapsTypes>(changedIdentifier, TopicMapsTypes.Locator));
    24852485                } else {                       
     
    24882488
    24892489                        // search for the characteristics type
    2490                         if(carier instanceof Topic){
    2491                                 JsArray<Name> names = ((Topic)carier).getNames(constrainedTopicType);
     2490                        if(carrier instanceof Topic){
     2491                                JsArray<Name> names = ((Topic)carrier).getNames(constrainedTopicType);
    24922492                                if(names.length() != 0){
    24932493                                        ref = names.get(0);
    24942494                                } else {
    2495                                         JsArray<Occurrence> occs = ((Topic)carier).getOccurrences(constrainedTopicType);
     2495                                        JsArray<Occurrence> occs = ((Topic)carrier).getOccurrences(constrainedTopicType);
    24962496                                        if(occs.length() != 0) ref = occs.get(0);
    24972497                                }
    2498                         } else if(carier instanceof Association){
    2499                                 JsArray<Role> roles = ((Association)carier).getRoles(constrainedTopicType);
     2498                        } else if(carrier instanceof Association){
     2499                                JsArray<Role> roles = ((Association)carrier).getRoles(constrainedTopicType);
    25002500                                if(roles.length() != 0) ref = roles.get(0);
    25012501                        }
     
    25112511                        if(filteredIdentifiers.size() > selectedValueIndex){
    25122512                                changedIdentifier = filteredIdentifiers.get(selectedValueIndex);
    2513                                 ((ReifiableStub)carier).removeItemIdentifier(changedIdentifier);
     2513                                ((ReifiableStub)carrier).removeItemIdentifier(changedIdentifier);
    25142514                        }
    25152515                       
    2516                         changedIdentifier = ((ReifiableStub)carier).getTopicMap().createLocator(this.getSelectedValues().get(selectedValueIndex));
    2517                         ((ReifiableStub)carier).addItemIdentifier(changedIdentifier);
     2516                        changedIdentifier = ((ReifiableStub)carrier).getTopicMap().createLocator(this.getSelectedValues().get(selectedValueIndex));
     2517                        ((ReifiableStub)carrier).addItemIdentifier(changedIdentifier);
    25182518                        contents.add(new Pair<Object, TopicMapsTypes>(changedIdentifier, TopicMapsTypes.Locator));
    25192519                }
     
    25212521       
    25222522
    2523         // handles the getContent call for item identifiers of varian-names
    2524         private void getVariantIdentifierContent(ArrayList<Pair<Object, TopicMapsTypes>> contents, boolean validate, Topic carier, int selectedValueIndex) throws InvalidGdlSchemaException, InvalidContentException, ExecutionException{
    2525                 ArrayList<Variant> possibleVariants = TmHelper.getVariantsForConstraint(carier, this.getRootConstraint());             
     2523        // handles the getContent call for item identifiers of variant-names
     2524        private void getVariantIdentifierContent(ArrayList<Pair<Object, TopicMapsTypes>> contents, boolean validate, Topic carrier, int selectedValueIndex) throws InvalidGdlSchemaException, InvalidContentException, ExecutionException{
     2525                ArrayList<Variant> possibleVariants = TmHelper.getVariantsForConstraint(carrier, this.getRootConstraint());             
    25262526                if(possibleVariants.size() != 0){
    25272527                        Variant variant = possibleVariants.get(0);
     
    25462546                }
    25472547        }
     2548       
     2549       
     2550        // handles the getContent call for occurrence and name values
     2551        private void getTopicCharacteristicContent(ArrayList<Pair<Object, TopicMapsTypes>> contents, boolean validate, Topic carrier, int selectedValueIndex) throws InvalidGdlSchemaException, InvalidContentException, ExecutionException{
     2552                Topic characteristicType = TmHelper.getConstrainedStatement(this.getConstraint());
    25482553               
     2554                boolean isOccConstraint = true;
     2555                if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclTopicOccurrenceConstraint)){
     2556                        isOccConstraint = true;
     2557                } else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclTopicNameConstraint)){
     2558                        isOccConstraint = false;
     2559                } else {
     2560                        throw new ExecutionException("the function getTopicCharacteristicContent can operate only on constraints of the type " + PSIs.TMCL.tmclTopicOccurrenceConstraint + " or " + PSIs.TMCL.tmclTopicNameConstraint + ", but is called with " + TmHelper.getAnyIdOfTopic(this.getConstraint()));
     2561                }
     2562               
     2563                JsArray<Name> names = null;
     2564                JsArray<Occurrence> occurrences = null;
     2565                if(isOccConstraint) occurrences = carrier.getOccurrences(characteristicType);
     2566                else names = carrier.getNames(characteristicType);
     2567               
     2568
     2569                Construct changedConstruct = null;
     2570                if(validate) this.validateLiteralValue(this.getSelectedValues().get(selectedValueIndex));
     2571
     2572                if(isOccConstraint){
     2573                        if(occurrences.length() > selectedValueIndex){
     2574                                changedConstruct = occurrences.get(selectedValueIndex);
     2575                                ((Occurrence)changedConstruct).setValue(this.getSelectedValues().get(selectedValueIndex));
     2576                        }else {
     2577                                changedConstruct = carrier.createOccurrence(characteristicType, this.getSelectedValues().get(selectedValueIndex), null);
     2578                        }
     2579                } else {
     2580                        if(names.length() > selectedValueIndex){
     2581                                changedConstruct = names.get(selectedValueIndex);
     2582                                ((Name)changedConstruct).setValue(this.getSelectedValues().get(selectedValueIndex));
     2583                        }else {
     2584                                changedConstruct = carrier.createName(this.getSelectedValues().get(selectedValueIndex), characteristicType, null);
     2585                        }
     2586                }
     2587                contents.add(new Pair<Object, TopicMapsTypes>(changedConstruct, isOccConstraint ? TopicMapsTypes.Occurrence : TopicMapsTypes.Name));
     2588        }
     2589       
    25492590               
    25502591        // returns the actual data that is hold by this instance
     
    25672608                        } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclTopicNameConstraint)){
    25682609                                if(!(localCarrier instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + localCarrier.getClass());
    2569                                 Topic nameType = TmHelper.getConstrainedStatement(this.getConstraint());
    2570                                 JsArray<Name> names = ((Topic)localCarrier).getNames(nameType);                         
    2571 
    2572                                 Name changedName = null;
    2573                                 if(validate) this.validateLiteralValue(this.getSelectedValues().get(idx));
    2574 
    2575                                 if(names.length() > idx){
    2576                                         changedName = names.get(idx);
    2577                                         changedName.setValue(this.getSelectedValues().get(idx));
    2578                                 }else {
    2579                                         changedName = ((Topic)localCarrier).createName(this.getSelectedValues().get(idx), nameType, null);
    2580                                 }
    2581                                 result.add(new Pair<Object, TopicMapsTypes>(changedName, TopicMapsTypes.Name));
     2610                                this.getTopicCharacteristicContent(result, validate, (Topic)localCarrier, idx);
    25822611                        } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclVariantNameConstraint)){
    25832612                                // TODO: implement
     
    25992628                        } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclTopicOccurrenceConstraint)){
    26002629                                if(!(localCarrier instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + localCarrier.getClass());
    2601                                 Topic occurrenceType = TmHelper.getConstrainedStatement(this.getConstraint());
    2602                                 JsArray<Occurrence> occurrences = ((Topic)localCarrier).getOccurrences(occurrenceType);
    2603 
    2604                                 Occurrence changedOccurrence = null;
    2605                                 if(validate) this.validateLiteralValue(this.getSelectedValues().get(idx));
    2606 
    2607                                 if(occurrences.length() > idx){
    2608                                         changedOccurrence = occurrences.get(idx);
    2609                                         changedOccurrence.setValue(this.getSelectedValues().get(idx));
    2610                                 }else {
    2611                                         changedOccurrence = ((Topic)localCarrier).createOccurrence(occurrenceType, this.getSelectedValues().get(idx), null, null);
    2612                                 }
    2613 
    2614                                 result.add(new Pair<Object, TopicMapsTypes>(changedOccurrence, TopicMapsTypes.Occurrence));
     2630                                this.getTopicCharacteristicContent(result, validate, (Topic)localCarrier, idx);
    26152631                        } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.GDL.TopicType.gdlRolePlayer)){
    26162632                                if(!(localCarrier instanceof Association)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to an Association, but is: " + localCarrier.getClass());
  • TabularUnified trunk/src/anaToMia/GDL_Widgets/src/us/isidor/gdl/anaToMia/Widgets/base/TestClass.java

    r1015 r1019  
    33import us.isidor.gdl.anaToMia.TmEngine.jtmsBasedEngine.JtmsTmEngine;
    44import us.isidor.gdl.anaToMia.TopicMaps.TmEngineModel.TmEngine;
     5import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Occurrence;
     6import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Name;
    57import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.TopicMapsTypes;
    68import us.isidor.gdl.anaToMia.TopicMaps.TopicMapsModel.Locator;
     
    6365                                                } else if(construct.getSecond().equals(TopicMapsTypes.Locator)){
    6466                                                        Window.alert(((Locator)construct.getFirst()).getReference() + " >> " + construct.getSecond());
     67                                                } else if(construct.getSecond().equals(TopicMapsTypes.Occurrence)){
     68                                                        Window.alert(((Occurrence)construct.getFirst()).getValue() + " >> " + construct.getSecond());
     69                                                } else if(construct.getSecond().equals(TopicMapsTypes.Name)){
     70                                                        Window.alert(((Name)construct.getFirst()).getValue() + " >> " + construct.getSecond());
    6571                                                } else {
    6672                                                        Window.alert(construct.getFirst() + " >> " + construct.getSecond());
Note: See TracChangeset for help on using the changeset viewer.