Changeset 1022 for trunk


Ignore:
Timestamp:
10/26/11 10:06:05 (14 years ago)
Author:
lgiessmann
Message:

gdl-frontend: Widgets: refactored GdlVisibleObject?.setReceivedData(...) and parted it to smaller sub-methods

File:
1 edited

Legend:

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

    r1021 r1022  
    18921892        public abstract void fixValue();
    18931893
    1894 
     1894       
     1895        // sets the item-identifier-fields for the received data
     1896        private void setReceivedItemIdentifiers() throws InvalidGdlSchemaException, ExecutionException {
     1897                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());
     1898               
     1899                // get type
     1900                Topic constrainedTopicType = TmHelper.getConstrainedTopicType(this.getConstraint());
     1901
     1902                int typeIdx = -1;
     1903                JsArray<Topic> types = null;
     1904                if((this.receivedData instanceof Topic)){
     1905                        types = ((Topic)this.receivedData).getTypes();
     1906                        if(types.length() != 0){
     1907                                for(typeIdx = 0; typeIdx != types.length(); ++typeIdx) if(types.get(typeIdx).equals(constrainedTopicType)) break;
     1908                        }
     1909                }
     1910
     1911                if((this.receivedData instanceof Topic) && types != null && typeIdx != types.length()){
     1912                        Pattern rex = new Pattern(this.getLiteralValueForConstraint());
     1913                        Topic top = (Topic)this.receivedData;
     1914                        for(int i = 0; i != top.getItemIdentifiers().length(); ++i){
     1915                                String ii = top.getItemIdentifiers().get(i).getReference();
     1916                                if(rex.matches(ii)){
     1917                                        this.addSubItem(ii);
     1918                                }
     1919                        }
     1920                } else {                       
     1921                        // search for the topic type
     1922                        Reifiable ref = null;
     1923
     1924                        // search for the characteristics type
     1925                        if(this.receivedData instanceof Topic){
     1926                                JsArray<Name> names = ((Topic)this.receivedData).getNames(constrainedTopicType);
     1927                                if(names.length() != 0){
     1928                                        ref = names.get(0);
     1929                                } else {
     1930                                        JsArray<Occurrence> occs = ((Topic)this.receivedData).getOccurrences(constrainedTopicType);
     1931                                        if(occs.length() != 0) ref = occs.get(0);
     1932                                }
     1933                        } else if(this.receivedData instanceof Association){
     1934                                JsArray<Role> roles = ((Association)this.receivedData).getRoles(constrainedTopicType);
     1935                                if(roles.length() != 0) ref = roles.get(0);
     1936                        }
     1937
     1938                        // search for item-identifiers of the found topic type or characteristics
     1939                        Pattern rex = new Pattern(this.getLiteralValueForConstraint());
     1940                        for(int i = 0; i != ((ReifiableStub)ref).getItemIdentifiers().length(); ++i){
     1941                                String ii = ((ReifiableStub)ref).getItemIdentifiers().get(i).getReference();
     1942                                if(rex.matches(ii)){
     1943                                        this.addSubItem(ii);
     1944                                }
     1945                        }
     1946                }
     1947        }
     1948       
     1949       
     1950        // sets the reifier-fields for the received data
     1951        private void setReceivedReifier() throws InvalidGdlSchemaException, ExecutionException {
     1952                Topic type = TmHelper.getConstrainedStatement(this.getConstraint());
     1953
     1954                Topic reifier = null;
     1955                if(this.receivedData instanceof Topic){
     1956                        JsArray<Name> names = ((Topic)this.receivedData).getNames(type);
     1957                        if(names.length() != 0) reifier = names.get(0).getReifier();
     1958                        if(reifier == null){
     1959                                JsArray<Occurrence> occs = ((Topic)this.receivedData).getOccurrences(type);
     1960                                if(occs.length() != 0) reifier = occs.get(0).getReifier();
     1961                        }
     1962                } else if(this.receivedData instanceof Association){
     1963                        if(((Association)this.receivedData).getType().equals(type)) type = ((Association)this.receivedData).getType();
     1964                } else {
     1965                        throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a topic or association, but is: " + this.receivedData.getClass());
     1966                }
     1967
     1968                String str = this.getTopicRepresentation(reifier, this.getDisplayByOfValueGroup(), this.getPreferredScopeOfValueGroup());
     1969                if(str == null) str = "";
     1970                this.addSubItem(str);
     1971        }
     1972       
     1973
     1974        // sets the scope-fields for the received data
     1975        private void setReceivedScope() throws InvalidGdlSchemaException, ExecutionException {
     1976                Topic type = TmHelper.getConstrainedStatement(this.getConstraint());
     1977
     1978                JsArray<Topic> scope = null;
     1979                if(this.receivedData instanceof Topic){
     1980                        JsArray<Name> names = ((Topic)this.receivedData).getNames(type);
     1981                        if(names.length() != 0) scope = names.get(0).getScope();
     1982                        if(scope == null){
     1983                                JsArray<Occurrence> occs = ((Topic)this.receivedData).getOccurrences(type);
     1984                                if(occs.length() != 0) scope = occs.get(0).getScope();
     1985                        }
     1986                } else if(this.receivedData instanceof Association){
     1987                        if(((Association)this.receivedData).getType().equals(type)) type = ((Association)this.receivedData).getType();
     1988                } else {
     1989                        throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a topic or association, but is: " + this.receivedData.getClass());
     1990                }
     1991
     1992                if(scope != null){
     1993                        for(int i = 0; i != scope.length(); ++i) this.addSubItem(this.getTopicRepresentation(scope.get(i), this.getDisplayByOfValueGroup(), this.getPreferredScopeOfValueGroup()));
     1994                }
     1995        }
     1996       
     1997       
     1998        // sets the type-fields for the received data
     1999        private void setReceivedType() throws InvalidGdlSchemaException, ExecutionException {
     2000                Topic type = null;
     2001                if(TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclTopicNameConstraint)){
     2002                        if(!(this.receivedData instanceof Topic)) throw new ExecutionException("The constraints " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " and " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()) + " are only valid when a topic is processed, but is: " + this.receivedData.getClass());
     2003                        type = TmHelper.getConstrainedStatement(this.getRootConstraint());
     2004                } else if(TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclTopicOccurrenceConstraint)){
     2005                        if(!(this.receivedData instanceof Topic)) throw new ExecutionException("The constraints " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " and " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()) + " are only valid when a topic is processed, but is: " + this.receivedData.getClass());
     2006                        type = TmHelper.getConstrainedStatement(this.getRootConstraint());
     2007                } else if(TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclTopicRoleConstraint)){
     2008                        if(!(this.receivedData instanceof Association)) throw new ExecutionException("The constraints " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " and " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()) + " are only valid when an association is processed, but is: " + this.receivedData.getClass());
     2009                        type = TmHelper.getConstrainedStatement(this.getRootConstraint());
     2010                } else if(TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclAssociationRoleConstraint)){
     2011                        if(!(this.receivedData instanceof Association)) throw new ExecutionException("The constraints " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " and " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()) + " are only valid when an association is processed, but is: " + this.receivedData.getClass());
     2012                        type = TmHelper.getConstraintRoleOfConstraint(this.getRootConstraint());
     2013                } else {
     2014                        String constraints = PSIs.TMCL.tmclTopicNameConstraint + ", " + PSIs.TMCL.tmclTopicOccurrenceConstraint + ", " + PSIs.TMCL.tmclTopicRoleConstraint + ", " + PSIs.TMCL.tmclAssociationRoleConstraint;
     2015                        throw new ExecutionException("The topic " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to the following root constraints: " + constraints);
     2016                }
     2017
     2018                String str = this.getTopicRepresentation(type, this.getDisplayByOfValueGroup(), this.getPreferredScopeOfValueGroup());
     2019                if(str == null) str = "";
     2020                this.addSubItem(str);
     2021        }
     2022       
     2023       
     2024        // sets the variant-name-scope-fields for the received data
     2025        private void setReceivedVariantNameScope() throws InvalidGdlSchemaException, ExecutionException {
     2026                if(!(this.receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
     2027                if(!TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclVariantNameConstraint)) throw new InvalidGdlSchemaException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a constraint of the type " + PSIs.TMCL.tmclVariantNameConstraint + ",  but is bound to: " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()));
     2028               
     2029                ArrayList<Variant> variants = TmHelper.getVariantsForConstraint((Topic)this.receivedData, this.getRootConstraint());
     2030                if(variants.size() != 0){
     2031                        for(int i = 0; i != variants.get(0).getScope().length(); ++i) this.addSubItem(this.getTopicRepresentation(variants.get(0).getScope().get(i), this.getDisplayByOfValueGroup(), this.getPreferredScopeOfValueGroup()));
     2032                }
     2033        }
     2034       
     2035       
     2036        // sets the variant-name-reifier-fields for the received data
     2037        private void setReceivedVariantNameReifier() throws InvalidGdlSchemaException, ExecutionException {
     2038                if(!(this.receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
     2039                if(!TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclVariantNameConstraint)) throw new InvalidGdlSchemaException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a constraint of the type " + PSIs.TMCL.tmclVariantNameConstraint + ",  but is bound to: " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()));
     2040               
     2041                ArrayList<Variant> variants = TmHelper.getVariantsForConstraint((Topic)this.receivedData, this.getRootConstraint());
     2042                if(variants.size() != 0 && variants.get(0).getReifier() != null){
     2043                        this.addSubItem(this.getTopicRepresentation(variants.get(0).getReifier(), this.getDisplayByOfValueGroup(), this.getPreferredScopeOfValueGroup()));     
     2044                }
     2045        }
     2046       
     2047       
     2048        // sets the subject-identifier and subjetc-locator-fields for the received data
     2049        private void setReceivedTopicIdentifiers() throws InvalidGdlSchemaException, ExecutionException {
     2050                if(!(receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
     2051
     2052                Pattern rex = new Pattern(this.getLiteralValueForConstraint());
     2053               
     2054                JsArray<Locator> identifiers = null;
     2055                if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclSubjectIdentifierConstraint)){
     2056                        identifiers = ((Topic)receivedData).getSubjectIdentifiers();
     2057                }else {
     2058                        identifiers = ((Topic)receivedData).getSubjectLocators();
     2059                }
     2060               
     2061                for(int i = 0; i != identifiers.length(); ++i){
     2062                        String id = identifiers.get(i).getReference();
     2063                        if(rex.matches(id)){
     2064                                this.addSubItem(id);
     2065                        }
     2066                }
     2067        }
     2068       
     2069       
     2070        // sets the variant-name-fields for the received data
     2071        private void setReceivedVariantName() throws InvalidGdlSchemaException, ExecutionException {
     2072                if(!(this.receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
     2073
     2074                ArrayList<Variant> variants = TmHelper.getVariantsForConstraint((Topic)this.receivedData, this.getConstraint());
     2075                if(variants.size() != 0){
     2076                        for (Variant variant : variants) {
     2077                                 this.addSubItem(variant.getValue());
     2078                        }
     2079                }
     2080                else{
     2081                        this.addSubItem("");
     2082                }       
     2083        }
     2084       
     2085       
     2086        // sets the role-player-fields for the received data
     2087        private void setReceivedRolePlayer() throws InvalidGdlSchemaException, ExecutionException {
     2088                if(!(receivedData instanceof Association)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to an Association, but is: " + receivedData.getClass());
     2089                if(this.getRootConstraint() == null || !TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclTopicRoleConstraint)) throw new InvalidGdlSchemaException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a root constraint of the type " + PSIs.TMCL.tmclTopicRoleConstraint + ", but ist bound to the root topic: " + (this.getRootConstraint() == null ? "null" : TmHelper.getAnyIdOfTopic(this.getRootConstraint())));
     2090
     2091                Pair<Topic, Topic> roleAndPlayerType = TmHelper.getConstrainedRoleAndPlayerTypeOfConstraint(this.getRootConstraint()); 
     2092                JsArray<Role> assocRoles = ((Association)this.receivedData).getRoles(roleAndPlayerType.getFirst());
     2093                for(int i = 0; i != assocRoles.length(); ++i){
     2094                        if(TmHelper.isInstanceOf(assocRoles.get(i).getPlayer(), roleAndPlayerType.getSecond())){
     2095                                this.addSubItem(this.getTopicRepresentation(assocRoles.get(i).getPlayer(), this.getDisplayByOfValueGroup(), this.getPreferredScopeOfValueGroup()));
     2096                        }
     2097                }
     2098        }
     2099       
     2100       
     2101        // sets the variant-name-identifiers-fields for the received data
     2102        private void setReceivedVariantNameIdentifiers() throws InvalidGdlSchemaException, ExecutionException {
     2103                if(!(this.receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
     2104                if(!TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclVariantNameConstraint)) throw new InvalidGdlSchemaException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a constraint of the type " + PSIs.TMCL.tmclVariantNameConstraint + ",  but is bound to: " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()));
     2105               
     2106                ArrayList<Variant> variants = TmHelper.getVariantsForConstraint((Topic)this.receivedData, this.getRootConstraint());
     2107                if(variants.size() != 0){
     2108                        for(int i = 0; i != variants.get(0).getItemIdentifiers().length(); ++i) this.addSubItem(variants.get(0).getItemIdentifiers().get(i).getReference());
     2109                }
     2110        }
     2111       
     2112       
     2113        // sets the datatype-fields for the received data
     2114        private void setReceivedDatatype() throws InvalidGdlSchemaException, ExecutionException {
     2115                if(!(this.receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
     2116
     2117                if(TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclVariantNameConstraint)){
     2118                        ArrayList<Variant> variants = TmHelper.getVariantsForConstraint((Topic)this.receivedData, this.getRootConstraint());
     2119                        if(variants.size() != 0){
     2120                                this.addSubItem(variants.get(0).getDatatype().getReference());
     2121                        }
     2122                } else if(TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclOccurrenceConstraint)){
     2123                        Topic occType = TmHelper.getConstrainedStatement(this.getRootConstraint());
     2124                        JsArray<Occurrence> occs = ((Topic)this.receivedData).getOccurrences(occType);
     2125                        if(occs.length() != 0) this.addSubItem(occs.get(0).getDatatype().getReference());
     2126                } else {
     2127                        throw new InvalidGdlSchemaException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a constraint of the type " + PSIs.TMCL.tmclVariantNameConstraint + " or " + PSIs.TMCL.tmclOccurrenceConstraint + ",  but is bound to: " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()));
     2128                }
     2129        }
     2130       
     2131       
     2132        // sets the name- and occurrence-fields for the received data
     2133        private void setReceivedTopicCharacteristics() throws InvalidGdlSchemaException, ExecutionException {
     2134                if(!(receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
     2135
     2136                Topic characteristicType = TmHelper.getConstrainedStatement(this.getConstraint());
     2137               
     2138                if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclTopicNameConstraint)){
     2139                        for(int i = 0; i != ((Topic)this.receivedData).getNames(characteristicType).length(); ++i)
     2140                                this.addSubItem(((Topic)this.receivedData).getNames(characteristicType).get(i).getValue());
     2141                } else {
     2142                        for(int i = 0; i != ((Topic)this.receivedData).getOccurrences(characteristicType).length(); ++i)
     2143                                this.addSubItem(((Topic)this.receivedData).getOccurrences(characteristicType).get(i).getValue());
     2144                }
     2145        }
     2146       
     2147       
    18952148        // sets the fields for the received data
    18962149        protected void setReceivedData() throws InvalidGdlSchemaException, ExecutionException {
     
    18982151
    18992152                if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclSubjectIdentifierConstraint)){
    1900                         if(!(receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
    1901 
    1902                         Pattern rex = new Pattern(this.getLiteralValueForConstraint());
    1903                         for(int i = 0; i != ((Topic)receivedData).getSubjectIdentifiers().length(); ++i){
    1904                                 String psi = ((Topic)receivedData).getSubjectIdentifiers().get(i).getReference();
    1905                                 if(rex.matches(psi)){
    1906                                         this.addSubItem(psi);
    1907                                 }
    1908                         }
     2153                        this.setReceivedTopicIdentifiers();
    19092154                } else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclSubjectLocatorConstraint)){
    1910                         if(!(receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
    1911 
    1912                         Pattern rex = new Pattern(this.getLiteralValueForConstraint());
    1913                         for(int i = 0; i != ((Topic)receivedData).getSubjectLocators().length(); ++i){
    1914                                 String sl = ((Topic)receivedData).getSubjectLocators().get(i).getReference();
    1915                                 if(rex.matches(sl)){
    1916                                         this.addSubItem(sl);
    1917                                 }
    1918                         }
     2155                        this.setReceivedTopicIdentifiers();
    19192156                } else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclItemIdentifierConstraint)){
    1920                         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());
    1921 
    1922                         // get type
    1923                         Topic constrainedTopicType = TmHelper.getConstrainedTopicType(this.getConstraint());
    1924 
    1925                         int typeIdx = -1;
    1926                         JsArray<Topic> types = null;
    1927                         if((this.receivedData instanceof Topic)){
    1928                                 types = ((Topic)this.receivedData).getTypes();
    1929                                 if(types.length() != 0){
    1930                                         for(typeIdx = 0; typeIdx != types.length(); ++typeIdx) if(types.get(typeIdx).equals(constrainedTopicType)) break;
    1931                                 }
    1932                         }
    1933 
    1934                         if((this.receivedData instanceof Topic) && types != null && typeIdx != types.length()){
    1935                                 Pattern rex = new Pattern(this.getLiteralValueForConstraint());
    1936                                 Topic top = (Topic)this.receivedData;
    1937                                 for(int i = 0; i != top.getItemIdentifiers().length(); ++i){
    1938                                         String ii = top.getItemIdentifiers().get(i).getReference();
    1939                                         if(rex.matches(ii)){
    1940                                                 this.addSubItem(ii);
    1941                                         }
    1942                                 }
    1943                         } else {                       
    1944                                 // search for the topic type
    1945                                 Reifiable ref = null;
    1946        
    1947                                 // search for the characteristics type
    1948                                 if(this.receivedData instanceof Topic){
    1949                                         JsArray<Name> names = ((Topic)this.receivedData).getNames(constrainedTopicType);
    1950                                         if(names.length() != 0){
    1951                                                 ref = names.get(0);
    1952                                         } else {
    1953                                                 JsArray<Occurrence> occs = ((Topic)this.receivedData).getOccurrences(constrainedTopicType);
    1954                                                 if(occs.length() != 0) ref = occs.get(0);
    1955                                         }
    1956                                 } else if(this.receivedData instanceof Association){
    1957                                         JsArray<Role> roles = ((Association)this.receivedData).getRoles(constrainedTopicType);
    1958                                         if(roles.length() != 0) ref = roles.get(0);
    1959                                 }
    1960        
    1961                                 // search for item-identifiers of the found topic type or characteristics
    1962                                 Pattern rex = new Pattern(this.getLiteralValueForConstraint());
    1963                                 for(int i = 0; i != ((ReifiableStub)ref).getItemIdentifiers().length(); ++i){
    1964                                         String ii = ((ReifiableStub)ref).getItemIdentifiers().get(i).getReference();
    1965                                         if(rex.matches(ii)){
    1966                                                 this.addSubItem(ii);
    1967                                         }
    1968                                 }
    1969                         }
     2157                        this.setReceivedItemIdentifiers();
    19702158                } else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclTopicNameConstraint)){
    1971                         if(!(receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
    1972 
    1973                         Topic nameType = TmHelper.getConstrainedStatement(this.getConstraint());
    1974                         for(int i = 0; i != ((Topic)this.receivedData).getNames(nameType).length(); ++i)
    1975                                 this.addSubItem(((Topic)this.receivedData).getNames(nameType).get(i).getValue());
     2159                        this.setReceivedTopicCharacteristics();
    19762160                } else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclTopicOccurrenceConstraint)){
    1977                         if(!(receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
    1978 
    1979                         Topic occurrenceType = TmHelper.getConstrainedStatement(this.getConstraint());
    1980                         for(int i = 0; i != ((Topic)this.receivedData).getOccurrences(occurrenceType).length(); ++i)
    1981                                 this.addSubItem(((Topic)this.receivedData).getOccurrences(occurrenceType).get(i).getValue());
     2161                        this.setReceivedTopicCharacteristics();
    19822162                } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclReifierConstraint)){
    1983                         Topic type = TmHelper.getConstrainedStatement(this.getConstraint());
    1984 
    1985                         Topic reifier = null;
    1986                         if(this.receivedData instanceof Topic){
    1987                                 JsArray<Name> names = ((Topic)this.receivedData).getNames(type);
    1988                                 if(names.length() != 0) reifier = names.get(0).getReifier();
    1989                                 if(reifier == null){
    1990                                         JsArray<Occurrence> occs = ((Topic)this.receivedData).getOccurrences(type);
    1991                                         if(occs.length() != 0) reifier = occs.get(0).getReifier();
    1992                                 }
    1993                         } else if(this.receivedData instanceof Association){
    1994                                 if(((Association)this.receivedData).getType().equals(type)) type = ((Association)this.receivedData).getType();
    1995                         } else {
    1996                                 throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a topic or association, but is: " + this.receivedData.getClass());
    1997                         }
    1998 
    1999                         String str = this.getTopicRepresentation(reifier, this.getDisplayByOfValueGroup(), this.getPreferredScopeOfValueGroup());
    2000                         if(str == null) str = "";
    2001                         this.addSubItem(str);
     2163                        this.setReceivedReifier();
    20022164                } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclVariantNameConstraint)){
    2003                         if(!(this.receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
    2004 
    2005                         ArrayList<Variant> variants = TmHelper.getVariantsForConstraint((Topic)this.receivedData, this.getConstraint());
    2006                         if(variants.size() != 0){
    2007                                 for (Variant variant : variants) {
    2008                                          this.addSubItem(variant.getValue());
    2009                                 }
    2010                         }
    2011                         else{
    2012                                 this.addSubItem("");
    2013                         }
     2165                        this.setReceivedVariantName();
    20142166                } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclScopeConstraint)){
    2015                         Topic type = TmHelper.getConstrainedStatement(this.getConstraint());
    2016 
    2017                         JsArray<Topic> scope = null;
    2018                         if(this.receivedData instanceof Topic){
    2019                                 JsArray<Name> names = ((Topic)this.receivedData).getNames(type);
    2020                                 if(names.length() != 0) scope = names.get(0).getScope();
    2021                                 if(scope == null){
    2022                                         JsArray<Occurrence> occs = ((Topic)this.receivedData).getOccurrences(type);
    2023                                         if(occs.length() != 0) scope = occs.get(0).getScope();
    2024                                 }
    2025                         } else if(this.receivedData instanceof Association){
    2026                                 if(((Association)this.receivedData).getType().equals(type)) type = ((Association)this.receivedData).getType();
    2027                         } else {
    2028                                 throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a topic or association, but is: " + this.receivedData.getClass());
    2029                         }
    2030 
    2031                         if(scope != null){
    2032                                 for(int i = 0; i != scope.length(); ++i) this.addSubItem(this.getTopicRepresentation(scope.get(i), this.getDisplayByOfValueGroup(), this.getPreferredScopeOfValueGroup()));
    2033                         }
     2167                        this.setReceivedScope();
    20342168                } else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.GDL.TopicType.gdlRolePlayer)){
    2035                         if(!(receivedData instanceof Association)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to an Association, but is: " + receivedData.getClass());
    2036                         if(this.getRootConstraint() == null || !TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclTopicRoleConstraint)) throw new InvalidGdlSchemaException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a root constraint of the type " + PSIs.TMCL.tmclTopicRoleConstraint + ", but ist bound to the root topic: " + (this.getRootConstraint() == null ? "null" : TmHelper.getAnyIdOfTopic(this.getRootConstraint())));
    2037 
    2038                         Pair<Topic, Topic> roleAndPlayerType = TmHelper.getConstrainedRoleAndPlayerTypeOfConstraint(this.getRootConstraint()); 
    2039                         JsArray<Role> assocRoles = ((Association)this.receivedData).getRoles(roleAndPlayerType.getFirst());
    2040                         for(int i = 0; i != assocRoles.length(); ++i){
    2041                                 if(TmHelper.isInstanceOf(assocRoles.get(i).getPlayer(), roleAndPlayerType.getSecond())){
    2042                                         this.addSubItem(this.getTopicRepresentation(assocRoles.get(i).getPlayer(), this.getDisplayByOfValueGroup(), this.getPreferredScopeOfValueGroup()));
    2043                                 }
    2044                         }
     2169                        this.setReceivedRolePlayer();
    20452170                } else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.GDL.TopicType.gdlType)){
    2046                         Topic type = null;
    2047                         if(TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclTopicNameConstraint)){
    2048                                 if(!(this.receivedData instanceof Topic)) throw new ExecutionException("The constraints " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " and " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()) + " are only valid when a topic is processed, but is: " + this.receivedData.getClass());
    2049                                 type = TmHelper.getConstrainedStatement(this.getRootConstraint());
    2050                         } else if(TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclTopicOccurrenceConstraint)){
    2051                                 if(!(this.receivedData instanceof Topic)) throw new ExecutionException("The constraints " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " and " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()) + " are only valid when a topic is processed, but is: " + this.receivedData.getClass());
    2052                                 type = TmHelper.getConstrainedStatement(this.getRootConstraint());
    2053                         } else if(TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclTopicRoleConstraint)){
    2054                                 if(!(this.receivedData instanceof Association)) throw new ExecutionException("The constraints " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " and " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()) + " are only valid when an association is processed, but is: " + this.receivedData.getClass());
    2055                                 type = TmHelper.getConstrainedStatement(this.getRootConstraint());
    2056                         } else if(TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclAssociationRoleConstraint)){
    2057                                 if(!(this.receivedData instanceof Association)) throw new ExecutionException("The constraints " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " and " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()) + " are only valid when an association is processed, but is: " + this.receivedData.getClass());
    2058                                 type = TmHelper.getConstraintRoleOfConstraint(this.getRootConstraint());
    2059                         } else {
    2060                                 String constraints = PSIs.TMCL.tmclTopicNameConstraint + ", " + PSIs.TMCL.tmclTopicOccurrenceConstraint + ", " + PSIs.TMCL.tmclTopicRoleConstraint + ", " + PSIs.TMCL.tmclAssociationRoleConstraint;
    2061                                 throw new ExecutionException("The topic " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to the following root constraints: " + constraints);
    2062                         }
    2063 
    2064                         String str = this.getTopicRepresentation(type, this.getDisplayByOfValueGroup(), this.getPreferredScopeOfValueGroup());
    2065                         if(str == null) str = "";
    2066                         this.addSubItem(str);
     2171                        this.setReceivedType();
    20672172                } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.GDL.TopicType.gdlDatatype)){
    2068                         if(!(this.receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
    2069 
    2070                         if(TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclVariantNameConstraint)){
    2071                                 ArrayList<Variant> variants = TmHelper.getVariantsForConstraint((Topic)this.receivedData, this.getRootConstraint());
    2072                                 if(variants.size() != 0){
    2073                                         this.addSubItem(variants.get(0).getDatatype().getReference());
    2074                                 }
    2075                         } else if(TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclOccurrenceConstraint)){
    2076                                 Topic occType = TmHelper.getConstrainedStatement(this.getRootConstraint());
    2077                                 JsArray<Occurrence> occs = ((Topic)this.receivedData).getOccurrences(occType);
    2078                                 if(occs.length() != 0) this.addSubItem(occs.get(0).getDatatype().getReference());
    2079                         } else {
    2080                                 throw new InvalidGdlSchemaException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a constraint of the type " + PSIs.TMCL.tmclVariantNameConstraint + " or " + PSIs.TMCL.tmclOccurrenceConstraint + ",  but is bound to: " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()));
    2081                         }
     2173                        this.setReceivedDatatype();
    20822174                } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.GDL.TopicType.gdlVariantNameIdentifiers)){
    2083                         if(!(this.receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
    2084                         if(!TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclVariantNameConstraint)) throw new InvalidGdlSchemaException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a constraint of the type " + PSIs.TMCL.tmclVariantNameConstraint + ",  but is bound to: " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()));
    2085                        
    2086                         ArrayList<Variant> variants = TmHelper.getVariantsForConstraint((Topic)this.receivedData, this.getRootConstraint());
    2087                         if(variants.size() != 0){
    2088                                 for(int i = 0; i != variants.get(0).getItemIdentifiers().length(); ++i) this.addSubItem(variants.get(0).getItemIdentifiers().get(i).getReference());
    2089                         }
     2175                        this.setReceivedVariantNameIdentifiers();
    20902176                } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.GDL.TopicType.gdlVariantNameReifier)){
    2091                         if(!(this.receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
    2092                         if(!TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclVariantNameConstraint)) throw new InvalidGdlSchemaException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a constraint of the type " + PSIs.TMCL.tmclVariantNameConstraint + ",  but is bound to: " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()));
    2093                        
    2094                         ArrayList<Variant> variants = TmHelper.getVariantsForConstraint((Topic)this.receivedData, this.getRootConstraint());
    2095                         if(variants.size() != 0 && variants.get(0).getReifier() != null){
    2096                                 this.addSubItem(this.getTopicRepresentation(variants.get(0).getReifier(), this.getDisplayByOfValueGroup(), this.getPreferredScopeOfValueGroup()));     
    2097                         }
     2177                        this.setReceivedVariantNameReifier();
    20982178                } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.GDL.TopicType.gdlVariantNameScope)){
    2099                         if(!(this.receivedData instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + receivedData.getClass());
    2100                         if(!TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclVariantNameConstraint)) throw new InvalidGdlSchemaException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a constraint of the type " + PSIs.TMCL.tmclVariantNameConstraint + ",  but is bound to: " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()));
    2101                        
    2102                         ArrayList<Variant> variants = TmHelper.getVariantsForConstraint((Topic)this.receivedData, this.getRootConstraint());
    2103                         if(variants.size() != 0){
    2104                                 for(int i = 0; i != variants.get(0).getScope().length(); ++i) this.addSubItem(this.getTopicRepresentation(variants.get(0).getScope().get(i), this.getDisplayByOfValueGroup(), this.getPreferredScopeOfValueGroup()));
    2105                         }
     2179                        this.setReceivedVariantNameScope();
    21062180                } else {
    21072181                        throw new InvalidGdlSchemaException("The constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " is not suported to be bound to the value group instance " + TmHelper.getAnyIdOfTopic(this.getValueGroup()));
     
    23922466                }
    23932467        }
    2394 
    23952468
    23962469
     
    26052678                }
    26062679                contents.add(new Pair<Object, TopicMapsTypes>(changedConstruct, isOccConstraint ? TopicMapsTypes.Occurrence : TopicMapsTypes.Name));
     2680        }
     2681       
     2682       
     2683        // handles the getContent call for subject identifiers and subject locators
     2684        private void getVariantNameContent(ArrayList<Pair<Object, TopicMapsTypes>> contents, boolean validate, Topic carrier, int selectedValueIndex) throws InvalidGdlSchemaException, InvalidContentException, ExecutionException{
     2685                // TODO: implement
     2686               
     2687                /*JsArray<Locator> identifiers = null;
     2688                       
     2689                ArrayList<Locator> filteredIdentifiers = null;
     2690                boolean isPsiConstraint = false;
     2691                if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclSubjectIdentifierConstraint)){
     2692                        isPsiConstraint = true;
     2693                        identifiers = carrier.getSubjectIdentifiers();
     2694                        filteredIdentifiers = this.filterLocators(TmHelper.getRegExp(this.getConstraint()), identifiers);
     2695                } else if(TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclSubjectLocatorConstraint)){
     2696                        identifiers = carrier.getSubjectLocators();
     2697                        filteredIdentifiers = this.filterLocators(TmHelper.getRegExp(this.getConstraint()), identifiers);
     2698                } else {
     2699                        throw new ExecutionException("Only the constraints " + PSIs.TMCL.tmclSubjectIdentifierConstraint + " and " + PSIs.TMCL.tmclSubjectLocatorConstraint + " are supported by the function getTopicIdentifierContent");
     2700                }
     2701               
     2702                Locator changedIdentifier = null;
     2703                if(validate) this.validateLiteralValue(this.getSelectedValues().get(selectedValueIndex));
     2704               
     2705                if(filteredIdentifiers.size() > selectedValueIndex){
     2706                        changedIdentifier = filteredIdentifiers.get(selectedValueIndex);
     2707                        if(isPsiConstraint) carrier.removeSubjectIdentifier(changedIdentifier);
     2708                        else carrier.removeSubjectLocator(changedIdentifier);
     2709                }
     2710               
     2711                changedIdentifier = carrier.getTopicMap().createLocator(this.getSelectedValues().get(selectedValueIndex));
     2712                if(isPsiConstraint) carrier.addSubjectIdentifier(changedIdentifier);
     2713                else carrier.addSubjectLocator(changedIdentifier);
     2714                contents.add(new Pair<Object, TopicMapsTypes>(changedIdentifier, TopicMapsTypes.Locator));
     2715                */
     2716        }
     2717       
     2718       
     2719        // handles the getContent call for role players
     2720        private void getRolePlayerContent(ArrayList<Pair<Object, TopicMapsTypes>> contents, boolean validate, Association carrier, int selectedValueIndex) throws InvalidGdlSchemaException, InvalidContentException, ExecutionException{
     2721                if(!TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclTopicRoleConstraint))throw new InvalidGdlSchemaException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a root constraint of the type " + PSIs.TMCL.tmclTopicRoleConstraint + ", but is: " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()));
     2722                Pair<Topic, Topic> roleAndPlayerType = TmHelper.getConstrainedRoleAndPlayerTypeOfConstraint(this.getRootConstraint());
     2723                Topic roleType = roleAndPlayerType.getFirst();
     2724                Topic playerType = roleAndPlayerType.getSecond();
     2725
     2726                JsArray<Role> typedRoles = carrier.getRoles(roleType);
     2727                ArrayList<Role> roles = new ArrayList<Role>();
     2728                for(int i = 0; i != typedRoles.length(); ++i)
     2729                        if(TmHelper.isInstanceOf(typedRoles.get(i).getPlayer(), playerType)) roles.add(typedRoles.get(i));
     2730
     2731                Role changedRole = null;
     2732
     2733                Topic player = TmHelper.getTopicFromStringRepresentation(this.getSelectedValues().get(selectedValueIndex), this.getValueGroup());
     2734                if(validate) this.validateTmValue(player);
     2735                if(roles.size() > selectedValueIndex){
     2736                        changedRole = roles.get(selectedValueIndex);
     2737                        changedRole.setPlayer(player);
     2738                } else {
     2739                        changedRole = carrier.createRole(roleType, player);
     2740                }
     2741                contents.add(new Pair<Object, TopicMapsTypes>(changedRole, TopicMapsTypes.Role));
    26072742        }
    26082743       
     
    26292764                                this.getTopicCharacteristicContent(result, validate, (Topic)localCarrier, idx);
    26302765                        } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclVariantNameConstraint)){
    2631                                 // TODO: implement
     2766                                if(!(localCarrier instanceof Topic)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a Topic, but is: " + localCarrier.getClass());
     2767                                this.getVariantNameContent(result, validate, (Topic)localCarrier, idx);
    26322768                        } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.TMCL.tmclScopeConstraint)){
    26332769                                // TODO: implement
     
    26512787                        } else if (TmHelper.isInstanceOf(this.getConstraint(), PSIs.GDL.TopicType.gdlRolePlayer)){
    26522788                                if(!(localCarrier instanceof Association)) throw new ExecutionException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to an Association, but is: " + localCarrier.getClass());
    2653                                 if(!TmHelper.isInstanceOf(this.getRootConstraint(), PSIs.TMCL.tmclTopicRoleConstraint))throw new InvalidGdlSchemaException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " must be bound to a root constraint of the type " + PSIs.TMCL.tmclTopicRoleConstraint + ", but is: " + TmHelper.getAnyIdOfTopic(this.getRootConstraint()));
    2654                                 Pair<Topic, Topic> roleAndPlayerType = TmHelper.getConstrainedRoleAndPlayerTypeOfConstraint(this.getRootConstraint());
    2655                                 Topic roleType = roleAndPlayerType.getFirst();
    2656                                 Topic playerType = roleAndPlayerType.getSecond();
    2657 
    2658                                 JsArray<Role> typedRoles = ((Association)localCarrier).getRoles(roleType);
    2659                                 ArrayList<Role> roles = new ArrayList<Role>();
    2660                                 for(int i = 0; i != typedRoles.length(); ++i)
    2661                                         if(TmHelper.isInstanceOf(typedRoles.get(i).getPlayer(), playerType)) roles.add(typedRoles.get(i));
    2662 
    2663                                 Role changedRole = null;
    2664 
    2665                                 Topic player = TmHelper.getTopicFromStringRepresentation(this.getSelectedValues().get(idx), this.getValueGroup());
    2666                                 if(validate) this.validateTmValue(player);
    2667                                 if(roles.size() > idx){
    2668                                         changedRole = roles.get(idx);
    2669                                         changedRole.setPlayer(player);
    2670                                 } else {
    2671                                         changedRole = ((Association)localCarrier).createRole(roleType, player);
    2672                                 }
    2673                                 result.add(new Pair<Object, TopicMapsTypes>(changedRole, TopicMapsTypes.Role));
     2789                                this.getRolePlayerContent(result, validate, (Association)localCarrier, idx);
    26742790                        } else {
    26752791                                throw new InvalidGdlSchemaException("the constraint " + TmHelper.getAnyIdOfTopic(this.getConstraint()) + " is not supported");
Note: See TracChangeset for help on using the changeset viewer.