Python: fixed statement parsing with custom classes
authorjani <jani@asema.com>
Tue, 19 Mar 2019 04:30:57 +0000 (06:30 +0200)
committerjani <jani@asema.com>
Tue, 19 Mar 2019 04:30:57 +0000 (06:30 +0200)
57 files changed:
Common/Python/SmartAPI/common/ClassMapper.py
Common/Python/SmartAPI/common/Tools.py
Common/Python/SmartAPI/factory/Factory.py
Common/Python/SmartAPI/model/Ability.py
Common/Python/SmartAPI/model/Account.py
Common/Python/SmartAPI/model/AccountAction.py
Common/Python/SmartAPI/model/AccountTransaction.py
Common/Python/SmartAPI/model/Activity.py
Common/Python/SmartAPI/model/Address.py
Common/Python/SmartAPI/model/AliveRequest.py
Common/Python/SmartAPI/model/Capacity.py
Common/Python/SmartAPI/model/Condition.py
Common/Python/SmartAPI/model/Contract.py
Common/Python/SmartAPI/model/Coordinates.py
Common/Python/SmartAPI/model/Direction.py
Common/Python/SmartAPI/model/Entity.py
Common/Python/SmartAPI/model/Enumeration.py
Common/Python/SmartAPI/model/Error.py
Common/Python/SmartAPI/model/Evaluation.py
Common/Python/SmartAPI/model/GrObj.py
Common/Python/SmartAPI/model/Grading.py
Common/Python/SmartAPI/model/Input.py
Common/Python/SmartAPI/model/InterfaceAddress.py
Common/Python/SmartAPI/model/License.py
Common/Python/SmartAPI/model/Map.py
Common/Python/SmartAPI/model/Message.py
Common/Python/SmartAPI/model/Obj.py
Common/Python/SmartAPI/model/Offering.py
Common/Python/SmartAPI/model/Orientation.py
Common/Python/SmartAPI/model/Output.py
Common/Python/SmartAPI/model/Parameter.py
Common/Python/SmartAPI/model/Person.py
Common/Python/SmartAPI/model/PhysicalEntity.py
Common/Python/SmartAPI/model/PriceSpecification.py
Common/Python/SmartAPI/model/Provenance.py
Common/Python/SmartAPI/model/Reference.py
Common/Python/SmartAPI/model/Request.py
Common/Python/SmartAPI/model/Response.py
Common/Python/SmartAPI/model/Restriction.py
Common/Python/SmartAPI/model/Ring.py
Common/Python/SmartAPI/model/Route.py
Common/Python/SmartAPI/model/Service.py
Common/Python/SmartAPI/model/ServiceProvider.py
Common/Python/SmartAPI/model/Size.py
Common/Python/SmartAPI/model/SomeItems.py
Common/Python/SmartAPI/model/Status.py
Common/Python/SmartAPI/model/SystemOfInterest.py
Common/Python/SmartAPI/model/TemporalContext.py
Common/Python/SmartAPI/model/TimeSeries.py
Common/Python/SmartAPI/model/Transaction.py
Common/Python/SmartAPI/model/TypeAndQuantityNode.py
Common/Python/SmartAPI/model/ValueObject.py
Common/Python/SmartAPI/model/Velocity.py
Common/Python/SmartAPI/model/Waypoint.py
Common/Python/SmartAPI/model/Waypoints.py
Common/Python/SmartAPI/model/Zone.py
Common/Python/SmartAPI/rdf/Variant.py

index e7f06a166b6c5e8ca24c2242863cd434534a4614..fd8e5e8e911ab657059103e40d30190b7d755ac0 100644 (file)
@@ -117,10 +117,11 @@ class ClassMapper(object):
                        RESOURCE.ZONE: Zone
                }       
                        
-       def getClass(self, typelist, default = None):
+       def getClass(self, typelist, default = None, custom_classes = {}):
                for t in typelist:
                        if self.class_map.has_key(t):
                                return self.class_map[t]
-               
+                       if custom_classes is not None and custom_classes.has_key(t):
+                               return custom_classes[t]
                # No match, return default
                return default
index 6f9b993fb22af2ab77d760ccc24877ef952860a2..eb251328e0ea860df93ab11789068d8957ebe0c8 100644 (file)
@@ -96,7 +96,7 @@ class Tools(object):
                return messageBody.replace('\n', '\r\n')
 
        @classmethod
-       def fromString(cls, strng, serialization = None):
+       def fromString(cls, strng, serialization = None, custom_classes = None):
                model = Factory().createModel()
                try:
                        model.parse(data = strng, format=serialization)
@@ -140,7 +140,7 @@ class Tools(object):
                return obj
 
        @classmethod
-       def fromResourceAsObj(cls, resource, objType = None):
+       def fromResourceAsObj(cls, resource, objType = None, custom_classes = None):
                '''
                @note: isType if exists, it should be a list of URIRefs
                '''     
@@ -170,9 +170,9 @@ class Tools(object):
                                        else: 
                                                model = cls.fromString(stringRepresentation, SERIALIZATION.TURTLE)
                                                rootRes = cls.getTopNode(model)[0]
-                                               _klass = cls.getResourceClass(rootRes)
+                                               _klass = cls.getResourceClass(rootRes, custom_classes = custom_classes)
                                                
-                                               recoveredObj =  _klass.parse(rootRes)
+                                               recoveredObj =  _klass.parse(rootRes, custom_classes = custom_classes)
                                                recoveredObj.setSignature(obj.getSignature())
                                                recoveredObj.setHashCode(obj.getHashCode())
                                                recoveredObj.setIdentifierUri(obj.getIdentifierUri())
@@ -184,7 +184,7 @@ class Tools(object):
                return obj
        
        @classmethod
-       def fromStringAsObj(cls, strng, serialization = None, isType = None):
+       def fromStringAsObj(cls, strng, serialization = None, isType = None, custom_classes = None):
                '''
                @note: isType if exists, it should be a list of URIRefs
                '''
@@ -193,9 +193,9 @@ class Tools(object):
                        node, isType = cls.getTopNode(model)
                # isType is a list of URIRefs
                res = cls.getResourceByType(isType, model)
-               return cls.fromResourceAsObj(node, isType)
+               return cls.fromResourceAsObj(node, isType, custom_classes = custom_classes)
        
-       def fromStringAsList(self, strng, serialization = None, isType = None):
+       def fromStringAsList(self, strng, serialization = None, isType = None, custom_classes = None):
                '''
                '''
                model = self.fromString(strng, serialization = serialization)
@@ -344,9 +344,9 @@ class Tools(object):
                return types
        
        @classmethod
-       def getResourceClass(cls, resource, default = None):
+       def getResourceClass(cls, resource, default = None, custom_classes = None):
                types = cls.getResourceTypes(resource)
-               return ClassMapper().getClass(types, default = default)
+               return ClassMapper().getClass(types, default = default, custom_classes = custom_classes)
 
        @classmethod
        def createIdentifierUri(cls, myDomain, systemIdentifier, *objectIdentifiers):
@@ -511,15 +511,27 @@ class Tools(object):
                return mimeMsg.split("\r\n"+"\r\n", 1)[1]  #(os.linesep+os.linesep, 1)[1]
        
        @classmethod
-       def parseNotification(cls, content, content_type = None, serialization=SERIALIZATION.TURTLE):
+       def parseNotification(cls, content, content_type = None, serialization=SERIALIZATION.TURTLE, custom_classes = None):
                '''
                '''
                from SmartAPI.model.Notification import Notification
-               notification = Notification.fromString(content, serialization)
-               return notification
+               httpMessage = parseMIMEmessage(content, content_type = content_type)
+               msgString = httpMessage.getMainPart()
+               if isinstance(httpMessage, HttpMessage): # multipart
+                       Tools.messagePartsForParse = httpMessage.getNonMainPartsAsDict() 
+               
+               else: # single part
+                       Tools.messagePartsForParse = {}
+               
+               # convert msgString to Response or Request object               
+               model = cls.fromString(msgString, serialization)
+               msgResource = cls.getResourceByType(RESOURCE.NOTIFICATION, model)
+               # This step might consume items from Tools.messagePartsForParse
+               return Notification.parse(msgResource, custom_classes = custom_classes)
+       
        
        @classmethod
-       def parseRequest(cls, content, content_type = None, serialization=SERIALIZATION.TURTLE):
+       def parseRequest(cls, content, content_type = None, serialization=SERIALIZATION.TURTLE, custom_classes = None):
                '''
                Extended version of Request/Response.fromString() method. It can handle both multipart and singlepart.
                
@@ -541,10 +553,10 @@ class Tools(object):
                model = cls.fromString(msgString, serialization)
                msgResource = cls.getResourceByType(RESOURCE.REQUEST, model)
                # This step might consume items from Tools.messagePartsForParse
-               return Request.parse(msgResource)
+               return Request.parse(msgResource, custom_classes = custom_classes)
        
        @classmethod
-       def parseResponse(cls, content, content_type = None, serialization = SERIALIZATION.TURTLE):
+       def parseResponse(cls, content, content_type = None, serialization = SERIALIZATION.TURTLE, custom_classes = None):
                '''
                Extended version of Request/Response.fromString() method. It can handle both multipart and singlepart.
                
@@ -567,7 +579,7 @@ class Tools(object):
                model = cls.fromString(msgString, serialization)
                msgResource = cls.getResourceByType(RESOURCE.RESPONSE, model)
                # This step might consume items from Tools.messagePartsForParse
-               return Response.parse(msgResource)
+               return Response.parse(msgResource, custom_classes = custom_classes)
                
        messageParts = {} 
        ''' A dictionary for keeping non-Main parts. Key is URI of a model class Object, value is
index ba2ad8c657e8911a2e52acf24f8bc1ea9536f85f..6c7906db279639f5cd6a9634aec7b6552459e130 100644 (file)
@@ -86,7 +86,7 @@ class Factory(object):
                All 6 parameters are integers.
                @return: a newly created isodate Duration Object
                '''
-               from isodate.duration import Duration   
+               from isodate.duration import Duration
                return Duration(years=years, months=months, days=days, hours=hours, minutes=minutes, seconds=seconds)
        
        @classmethod
@@ -233,9 +233,9 @@ class Factory(object):
 #              if entity.hasIdentifierUri():
 #                      e = Entity(entity.getIdentifierUri())
 #              else:
-#                      e = Entity()    
+#                      e = Entity()
                e = entity
-               e.setValueObjects([])   
+               e.setValueObjects([])
                
                if temporalContext is not None:
                        a.setTemporalContext(temporalContext)
index 93e5da82ee460e3a2831194dff7e28e87c846576..dddc988ad2245e741e2b52c67981e78c8282de43 100644 (file)
@@ -21,12 +21,12 @@ class Ability(Evaluation):
                self.init_property(PROPERTY.SMARTAPI_PROPERTY, 'property', self.hasProperty, self.getProperty)
                self.setType(RESOURCE.ABILITY)
        
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.ISCONTROLLEDBY, self.setIsControlledBy, Obj)
-               self.parse_property(statement, PROPERTY.HASCONDITION, self.setCondition, Condition)
-               self.parse_property(statement, PROPERTY.SMARTAPI_PROPERTY, self.setProperty, Obj)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.ISCONTROLLEDBY, self.setIsControlledBy, Obj, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HASCONDITION, self.setCondition, Condition, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.SMARTAPI_PROPERTY, self.setProperty, Obj, custom_classes = custom_classes)
                
-               super(Ability, self)._parseStatement(statement);
+               super(Ability, self)._parseStatement(statement, custom_classes = custom_classes)
 
        def hasIsControlledBy(self):
                return self.isControlledBy is not None
index bd76c4cb31253c3d7f8049736e975f7cd8ce5aa8..d4f80f9474a0b2c3eac56063872e7a1911ef1a0c 100644 (file)
@@ -44,45 +44,47 @@ class Account(Obj):
         self.init_property(PROPERTY.SOURCESYSTEMURI, "sourceSystemUri", self.hasSourceSystemUri, self.getSourceSystemUri)
         self.init_property(PROPERTY.COUNTERPARTYURI, "counterPartyUri", self.hasCounterPartyUri, self.getCounterPartyUri)
         self.init_property(PROPERTY.VALUEADDEDTAXINCLUDED, "vatPercentage", self.hasVatPercentage, self.getVatPercentage)
-        self.init_property(PROPERTY.PERSON, "user", self.hasUser, self.getUser)    
+        self.init_property(PROPERTY.PERSON, "user", self.hasUser, self.getUser)
     
-    def _parseStatement(self, statement):
+    def _parseStatement(self, statement, custom_classes = None):
         from SmartAPI.model.Parameter import Parameter
         
-        self.parse_property(statement, PROPERTY.VALIDFROM, self.setValidFrom, Variant)
-        self.parse_property(statement, PROPERTY.VALIDTHROUGH, self.setValidThrough, Variant)
-        self.parse_property(statement, PROPERTY.CREATED, self.setCreated, Variant)
-        self.parse_property(statement, PROPERTY.OPENED, self.setOpened, Variant)
-        self.parse_property(statement, PROPERTY.CLOSED, self.setClosed, Variant)
-        self.parse_property(statement, PROPERTY.ISCURRENTLYFROZEN, self.setCurrentlyFrozen, Variant)
-        self.parse_property(statement, PROPERTY.ISCURRENTLYINCOLLECTION, self.setCurrentlyInCollection, Variant)
-        self.parse_property(statement, PROPERTY.CURRENTBALANCE, self.setCurrentBalance, Variant)
-        self.parse_property(statement, PROPERTY.INITIALBALANCE, self.setInitialBalance, Variant)
-        self.parse_property(statement, PROPERTY.MINIMUMBALANCE, self.setMinBalance, Variant)
-        self.parse_property(statement, PROPERTY.MAXIMUMBALANCE, self.setMaxBalance, Variant)
-        self.parse_property(statement, PROPERTY.CREDITLIMIT, self.setCreditLimit, Variant)
-        self.parse_property(statement, PROPERTY.PREPAYMENTLIMIT, self.setPrepaymentLimit, Variant)
-        self.parse_property(statement, PROPERTY.FIXEDDISCOUNT, self.setFixedDiscount, Variant)
-        self.parse_property(statement, PROPERTY.PERCENTAGEDISCOUNT, self.setPercentageDiscount, Variant)
-        self.parse_property(statement, PROPERTY.FIXEDMARKUP, self.setFixedMarkup, Variant)
-        self.parse_property(statement, PROPERTY.PERCENTAGEMARKUP, self.setPercentageMarkup, Variant)
-        self.parse_property(statement, PROPERTY.CURRENCY, self.setDefaultCurrency, Variant)
-        self.parse_property(statement, PROPERTY.PAYMENTTERM, self.setPaymentTerm, Variant)
-        self.parse_property(statement, PROPERTY.POREFERENCE, self.setPoReference, Variant)
-        self.parse_property(statement, PROPERTY.EXCEEDINGBALANCEALLOWED, self.setAllowExceedingBalance, Variant)
-        self.parse_property(statement, PROPERTY.EXCEEDINGCREDITALLOWED, self.setAllowExceedingCredit, Variant)
-        self.parse_property(statement, PROPERTY.NOTE, self.setNotes, Variant)
-        self.parse_property(statement, PROPERTY.SOURCESYSTEMURI, self.setSourceSystemUri, Variant)
-        self.parse_property(statement, PROPERTY.COUNTERPARTYURI, self.setCounterPartyUri, Variant)
-        self.parse_property(statement, PROPERTY.VALUEADDEDTAXINCLUDED, self.setVatPercentage, Variant)
-        self.parse_property(statement, PROPERTY.PERSON, self.setUser, Person)
+        self.parse_property(statement, PROPERTY.VALIDFROM, self.setValidFrom, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.VALIDTHROUGH, self.setValidThrough, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.CREATED, self.setCreated, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.OPENED, self.setOpened, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.CLOSED, self.setClosed, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.ISCURRENTLYFROZEN, self.setCurrentlyFrozen, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.ISCURRENTLYINCOLLECTION, self.setCurrentlyInCollection, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.CURRENTBALANCE, self.setCurrentBalance, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.INITIALBALANCE, self.setInitialBalance, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.MINIMUMBALANCE, self.setMinBalance, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.MAXIMUMBALANCE, self.setMaxBalance, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.CREDITLIMIT, self.setCreditLimit, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.PREPAYMENTLIMIT, self.setPrepaymentLimit, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.FIXEDDISCOUNT, self.setFixedDiscount, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.PERCENTAGEDISCOUNT, self.setPercentageDiscount, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.FIXEDMARKUP, self.setFixedMarkup, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.PERCENTAGEMARKUP, self.setPercentageMarkup, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.CURRENCY, self.setDefaultCurrency, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.PAYMENTTERM, self.setPaymentTerm, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.POREFERENCE, self.setPoReference, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.EXCEEDINGBALANCEALLOWED, self.setAllowExceedingBalance, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.EXCEEDINGCREDITALLOWED, self.setAllowExceedingCredit, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.NOTE, self.setNotes, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.SOURCESYSTEMURI, self.setSourceSystemUri, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.COUNTERPARTYURI, self.setCounterPartyUri, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.VALUEADDEDTAXINCLUDED, self.setVatPercentage, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.PERSON, self.setUser, Person, custom_classes = custom_classes)
         
         predicate = str(statement.getPredicate())
         if predicate == PROPERTY.PARAMETER:
-            p = Parameter().parse(statement.getResource())                       
-            self.add(p.getKey().asString(), p.getValues())                     
+            p = Parameter().parse(statement.getResource())
+            self.add(p.getKey().asString(), p.getValues())
     
-    def hasValidFrom(self):     
+        super(Account, self)._parseStatement(statement, custom_classes = custom_classes)
+    
+    def hasValidFrom(self):
         return self.validFrom is not None
     
     def getValidFrom(self):
index aba6879313e155d9f7c95c342f5bf7287bc2f814..63227dce123408719d090dcacfe03c5cf9ab699e 100644 (file)
@@ -11,17 +11,19 @@ class AccountAction(Obj):
         self.init_property(PROPERTY.TIME, "time", self.hasTime, self.getTime)
         self.init_property(PROPERTY.NOTE, "notes", self.hasNotes, self.getNotes)
     
-    def _parseStatement(self, statement):
+    def _parseStatement(self, statement, custom_classes = None):
         from SmartAPI.model.Parameter import Parameter
         
-        self.parse_property(statement, PROPERTY.TIME, self.setTime, Variant)
-        self.parse_property(statement, PROPERTY.NOTE, self.setNotes, Variant)
+        self.parse_property(statement, PROPERTY.TIME, self.setTime, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.NOTE, self.setNotes, Variant, custom_classes = custom_classes)
         
         predicate = str(statement.getPredicate())
         if predicate == PROPERTY.PARAMETER:
-            p = Parameter().parse(statement.getResource())                       
-            self.add(p.getKey().asString(), p.getValues())   
-    
+            p = Parameter().parse(statement.getResource())
+            self.add(p.getKey().asString(), p.getValues())
+            
+        super(AccountAction, self)._parseStatement(statement, custom_classes = custom_classes)
+        
     def setAccountActionType(self, actiontype):
         if not isinstance(actiontype, Variant):
             actiontype = Variant(actiontype)
index e1e88c6edd33deca9445c76b4e44a86a78f3120a..f876a17e54c87a0e44a8b7a5129044dea8818658 100644 (file)
@@ -18,22 +18,24 @@ class AccountTransaction(Obj):
         self.init_property(PROPERTY.REFERENCE, "reference", self.hasReference, self.getReference)
         self.init_property(PROPERTY.CURRENCY, "currency", self.hasCurrency, self.getCurrency)
     
-    def _parseStatement(self, statement):
+    def _parseStatement(self, statement, custom_classes = None):
         from SmartAPI.model.Parameter import Parameter
         
-        self.parse_property(statement, PROPERTY.ACCOUNT, self.setAccountId, Variant)
-        self.parse_property(statement, PROPERTY.CONTRACT, self.setContractId, Variant)
-        self.parse_property(statement, PROPERTY.ACCOUNTTRANSACTION, self.setLinkedTransactionId, Variant)
-        self.parse_property(statement, PROPERTY.TIME, self.setTime, Variant)
-        self.parse_property(statement, PROPERTY.COUNT, self.setCount, Variant)
-        self.parse_property(statement, PROPERTY.RDF_VALUE, self.setUnitValue, Variant)
-        self.parse_property(statement, PROPERTY.REFERENCE, self.setReference, Variant)
-        self.parse_property(statement, PROPERTY.CURRENCY, self.setCurrency, Variant)
+        self.parse_property(statement, PROPERTY.ACCOUNT, self.setAccountId, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.CONTRACT, self.setContractId, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.ACCOUNTTRANSACTION, self.setLinkedTransactionId, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.TIME, self.setTime, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.COUNT, self.setCount, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.RDF_VALUE, self.setUnitValue, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.REFERENCE, self.setReference, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.CURRENCY, self.setCurrency, Variant, custom_classes = custom_classes)
         
         predicate = str(statement.getPredicate())
         if predicate == PROPERTY.PARAMETER:
-            p = Parameter().parse(statement.getResource())                       
-            self.add(p.getKey().asString(), p.getValues())     
+            p = Parameter().parse(statement.getResource())
+            self.add(p.getKey().asString(), p.getValues())
+        
+        super(AccountTransaction, self)._parseStatement(statement, custom_classes = custom_classes)
         
     def hasAccountId(self):
         return self.accountId is not None
index 79eeea85d71f95eaf852f200167ba3a864d3ac8d..97416cf042447b6693ed758f2f8cc096f4fd6aee 100644 (file)
@@ -29,23 +29,23 @@ class Activity(Evaluation):
                self.init_property(PROPERTY.INTERFACE, 'interfaces', self.hasInterface, self.getInterfaces, True)
                self.init_property(PROPERTY.ENTITY, 'entities', self.hasEntity, self.getEntities, True)
                
-       def _parseStatement(self, statement):
+       def _parseStatement(self, statement, custom_classes = None):
                from SmartAPI.model.Availability import Availability
                from SmartAPI.model.Input import Input
                from SmartAPI.model.Output import Output
                from SmartAPI.model.InterfaceAddress import InterfaceAddress
                from SmartAPI.model.Entity import Entity
                
-               self.parse_property(statement, PROPERTY.HASINPUT, self.addInput, Input)
-               self.parse_property(statement, PROPERTY.HASREFINPUT, self.addRefInput, Input)
-               self.parse_property(statement, PROPERTY.HASOUTPUT, self.addOutput, Output)
-               self.parse_property(statement, PROPERTY.HASREFOUTPUT, self.addRefOutput, Output)        
-               self.parse_property(statement, PROPERTY.HASAVAILABILITY, self.addAvailability, Availability)
-               self.parse_property(statement, PROPERTY.HASDATAAVAILABILITY, self.addDataAvailability, Availability)
-               self.parse_property(statement, PROPERTY.INTERFACE, self.addInterface, InterfaceAddress
-               self.parse_property(statement, PROPERTY.ENTITY, self.addEntity, Entity)
+               self.parse_property(statement, PROPERTY.HASINPUT, self.addInput, Input, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HASREFINPUT, self.addRefInput, Input, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HASOUTPUT, self.addOutput, Output, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HASREFOUTPUT, self.addRefOutput, Output, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HASAVAILABILITY, self.addAvailability, Availability, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HASDATAAVAILABILITY, self.addDataAvailability, Availability, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.INTERFACE, self.addInterface, InterfaceAddress, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.ENTITY, self.addEntity, Entity, custom_classes = custom_classes)
                
-               super(Activity, self)._parseStatement(statement)
+               super(Activity, self)._parseStatement(statement, custom_classes = custom_classes)
 
        def hasInput(self):
                return len(self.inputs) > 0
index b1f359c699b7f07f4470ff589fae574eea074a12..e20a7b3b45f6cd8cf18ce90d44731bc0d744e05c 100644 (file)
@@ -62,12 +62,12 @@ class Address(Obj):
        def setStreetAddress(self, streetAddress):
                if isinstance(streetAddress, str):
                        streetAddress = Variant(streetAddress)
-               self.streetAddress = streetAddress      
+               self.streetAddress = streetAddress
 
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.COUNTRY_NAME, self.setCountry, Variant)
-               self.parse_property(statement, PROPERTY.LOCALITY, self.setCity, Variant)
-               self.parse_property(statement, PROPERTY.STREET_ADDRESS, self.setStreetAddress, Variant)
-               self.parse_property(statement, PROPERTY.POSTAL_CODE, self.setZipCode, Variant)  
-               super(Address, self)._parseStatement(statement)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.COUNTRY_NAME, self.setCountry, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.LOCALITY, self.setCity, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.STREET_ADDRESS, self.setStreetAddress, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.POSTAL_CODE, self.setZipCode, Variant, custom_classes = custom_classes)
+               super(Address, self)._parseStatement(statement, custom_classes = custom_classes)
        
index b03e2b6959f2e89450c7671f7c5773db417031e8..e54488deb40fc2201344dc1c47a7f036e0ad3c40 100644 (file)
@@ -10,8 +10,8 @@ class AliveRequest(Request):
        
        def __init__(self, uri = None):
                Request.__init__(self, uri)
-               self.setType(RESOURCE.ALIVEREQUEST)             
-                       
+               self.setType(RESOURCE.ALIVEREQUEST)
+       
        @classmethod
        def fromString(cls, data, serialization):
                m = Tools().fromString(data, serialization)
index c9d19b17a215b1f5db721098361ad74e22cb7f3a..e98a3c4cfca46ebab37797fcf1144e064a3f16d6 100644 (file)
@@ -15,16 +15,15 @@ class Capacity(ValueObject):
                self.setType(RESOURCE.CAPACITY)
                self.init_property(PROPERTY.PERCENTAGE, 'percentage', self.hasPercentage, self.getPercentage)
                self.init_property(PROPERTY.SYSTEMOFINTEREST, 'system_of_interest', self.hasSystemOfInterest, self.getSystemOfInterest)
-                                               
+               
                self.automatic_percentage_calculation = True
-               self.setSystemOfInterest(system_of_interest)            
+               self.setSystemOfInterest(system_of_interest)
                self.setMaximum(maximum)
                
-       def _parseStatement(self, statement):           
-       
-               self.parse_property(statement, PROPERTY.PERCENTAGE, self.setPercentage, Variant)
-               self.parse_property(statement, PROPERTY.SYSTEMOFINTEREST, self.setSystemOfInterest, SystemOfInterest)                           
-               super(Capacity, self)._parseStatement(statement)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.PERCENTAGE, self.setPercentage, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.SYSTEMOFINTEREST, self.setSystemOfInterest, SystemOfInterest, custom_classes = custom_classes)
+               super(Capacity, self)._parseStatement(statement, custom_classes = custom_classes)
 
        def hasPercentage(self):
                return self.percentage is not None
@@ -60,17 +59,17 @@ class Capacity(ValueObject):
        def setSystemOfInterest(self, s):
                self.system_of_interest = s
                
-       def setSystemOfInterestWithType(self, *types):  
+       def setSystemOfInterestWithType(self, *types):
                soi = SystemOfInterest()
                soi.clearTypes()
                for type in types:
-                       soi.addType(type)               
+                       soi.addType(type)
                self.setSystemOfInterest(soi)
        
-       def setSystemOfInterestWithSameAs(self, sameAs):        
+       def setSystemOfInterestWithSameAs(self, sameAs):
                soi = SystemOfInterest()
                soi.setSameAs(sameAs)
-               self.setSystemOfInterest(soi)   
+               self.setSystemOfInterest(soi)
 
        def enableAutomaticPercentageCalculation(self):
                self.automatic_percentage_calculation = True
@@ -83,7 +82,7 @@ class Capacity(ValueObject):
                        v = self.value.getValue()
                        m = self.maximum.getValue()
                        if v is not None and m is not None:
-                               if m != 0:                                                      
+                               if m != 0:
                                        self.setPercentage(Variant(v/m*100))
                                        return True
                return False
index bed898d503caca28dfd06f5a0b77213b31eaa4d2..6c88d06d21c8b2e3fc069c63c2e2db267f9b760d 100644 (file)
@@ -22,12 +22,12 @@ class Condition(Obj):
                self.init_property(PROPERTY.AND, 'ands', self.hasAnd, self.getAnds, True)
                self.init_property(PROPERTY.XOR, 'xors', self.hasXor, self.getXors, True)
        
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.REGEX, self.addRegex, Variant)
-               self.parse_property(statement, PROPERTY.OR, self.addOr, Variant)
-               self.parse_property(statement, PROPERTY.AND, self.addAnd, Variant)
-               self.parse_property(statement, PROPERTY.XOR, self.addXor, Variant)      
-               super(Condition, self)._parseStatement(statement)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.REGEX, self.addRegex, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.OR, self.addOr, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.AND, self.addAnd, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.XOR, self.addXor, Variant, custom_classes = custom_classes)
+               super(Condition, self)._parseStatement(statement, custom_classes = custom_classes)
 
        def hasOr(self):
                return len(self.ors) > 0
index 6183fe73953064c89b1c57f76463ed18ac4956af..72f7a9ca872398b3655d63e12015928247bb25d2 100644 (file)
@@ -23,26 +23,28 @@ class Contract(Obj):
         self.init_property(PROPERTY.POREFERENCE, "poReference", self.hasPoReference, self.getPoReference)
         self.init_property(PROPERTY.PAIDUNTIL, "paidUntil", self.hasPaidUntil, self.getPaidUntil)
     
-    def _parseStatement(self, statement):
+    def _parseStatement(self, statement, custom_classes = None):
         from SmartAPI.model.Parameter import Parameter
         
-        self.parse_property(statement, PROPERTY.ACCOUNT, self.setAccountId, Variant)  
-        self.parse_property(statement, PROPERTY.RELATEDRESOURCE, self.setRelatedResourceId, Variant)
-        self.parse_property(statement, PROPERTY.OFFERS, self.setOfferingId, Variant)
-        self.parse_property(statement, PROPERTY.SOURCESYSTEMURI, self.setSourceSystemUri, Variant)
-        self.parse_property(statement, PROPERTY.COUNTERPARTYURI, self.setCounterPartyUri, Variant)
-        self.parse_property(statement, PROPERTY.VALIDFROM, self.setValidFrom, Variant)
-        self.parse_property(statement, PROPERTY.VALIDTHROUGH, self.setValidThrough, Variant)
-        self.parse_property(statement, PROPERTY.PRICE, self.setPrice, ValueObject)
-        self.parse_property(statement, PROPERTY.CREATED, self.setCreated, Variant)
-        self.parse_property(statement, PROPERTY.CANCELLED, self.setCancelled, Variant)
-        self.parse_property(statement, PROPERTY.POREFERENCE, self.setPoReference, Variant)
-        self.parse_property(statement, PROPERTY.PAIDUNTIL, self.setPaidUntil, Variant)
+        self.parse_property(statement, PROPERTY.ACCOUNT, self.setAccountId, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.RELATEDRESOURCE, self.setRelatedResourceId, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.OFFERS, self.setOfferingId, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.SOURCESYSTEMURI, self.setSourceSystemUri, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.COUNTERPARTYURI, self.setCounterPartyUri, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.VALIDFROM, self.setValidFrom, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.VALIDTHROUGH, self.setValidThrough, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.PRICE, self.setPrice, ValueObject, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.CREATED, self.setCreated, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.CANCELLED, self.setCancelled, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.POREFERENCE, self.setPoReference, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.PAIDUNTIL, self.setPaidUntil, Variant, custom_classes = custom_classes)
         
         predicate = str(statement.getPredicate())
         if predicate == PROPERTY.PARAMETER:
-            p = Parameter().parse(statement.getResource())                       
-            self.add(p.getKey().asString(), p.getValues())           
+            p = Parameter().parse(statement.getResource())
+            self.add(p.getKey().asString(), p.getValues())
+            
+        super(Contract, self)._parseStatement(statement, custom_classes = custom_classes)
         
     def hasAccountId(self): 
         return self.accountId is not None
@@ -93,7 +95,7 @@ class Contract(Obj):
         elif isinstance(offeringId, URIRef):
             self.offeringId = Variant(offeringId)
         else:
-            self.offeringId = offeringId        
+            self.offeringId = offeringId
             
     def hasSourceSystemUri(self): 
         return self.sourceSystemUri is not None
@@ -112,7 +114,7 @@ class Contract(Obj):
         elif isinstance(sourceSystemUri, URIRef):
             self.sourceSystemUri = Variant(sourceSystemUri)
         else:
-            self.sourceSystemUri = sourceSystemUri        
+            self.sourceSystemUri = sourceSystemUri
             
     def hasCounterPartyUri(self): 
         return self.counterPartyUri is not None
@@ -131,7 +133,7 @@ class Contract(Obj):
         elif isinstance(counterPartyUri, URIRef):
             self.counterPartyUri = Variant(counterPartyUri)
         else:
-            self.counterPartyUri = counterPartyUri        
+            self.counterPartyUri = counterPartyUri
             
     def hasValidFrom(self): 
         return self.validFrom is not None
@@ -144,9 +146,9 @@ class Contract(Obj):
         @param validFrom: either datetime or Variant
         '''
         if not isinstance(validFrom, Variant):
-            self.validFrom = Variant(validFrom)        
+            self.validFrom = Variant(validFrom)
         else:
-            self.validFrom = validFrom        
+            self.validFrom = validFrom
             
     def hasValidThrough(self): 
         return self.validThrough is not None
@@ -159,11 +161,11 @@ class Contract(Obj):
         @param validThrough: either datetime or Variant
         '''
         if not isinstance(validThrough, Variant):
-            self.validThrough = Variant(validThrough)        
+            self.validThrough = Variant(validThrough)
         else:
-            self.validThrough = validThrough        
+            self.validThrough = validThrough
     
-    def setContractTerms(self, terms):    
+    def setContractTerms(self, terms):
         if not isinstance(terms, Variant):
             terms = Variant(terms)
         self.add("contract_terms", terms)
index 8c46593ef233ac14d9975fdc81bdda19f4cc17de..eafa463f4e83bb6cc6d2692dadca2ecc458a8260 100644 (file)
@@ -91,12 +91,12 @@ class Coordinates(Obj):
                self.latitude = value[0]
                self.longitude = value[1]
        
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.LAT, self.setLatitude, Variant)
-               self.parse_property(statement, PROPERTY.LONG, self.setLongitude, Variant)
-               self.parse_property(statement, PROPERTY.ALT, self.setAltitude, Variant
-               self.parse_property(statement, PROPERTY.MINRADIUS, self.setMinRadius, ValueObject)
-               self.parse_property(statement, PROPERTY.MAXRADIUS, self.setMaxRadius, ValueObject)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.LAT, self.setLatitude, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.LONG, self.setLongitude, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.ALT, self.setAltitude, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.MINRADIUS, self.setMinRadius, ValueObject, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.MAXRADIUS, self.setMaxRadius, ValueObject, custom_classes = custom_classes)
                # pass on to Object
-               super(Coordinates, self)._parseStatement(statement)
+               super(Coordinates, self)._parseStatement(statement, custom_classes = custom_classes)
        
index 0a5d5b8d6a0ec082498719631c791f4e9218bbe1..8b501c2cc1a22a949fec3f977ed91871890709f5 100644 (file)
@@ -51,9 +51,9 @@ class Direction(Obj):
        def getCourse(self):
                return self.course
 
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.BEARING, self.setBearing, ValueObject)
-               self.parse_property(statement, PROPERTY.HEADING, self.setHeading, ValueObject)
-               self.parse_property(statement, PROPERTY.TRACKING, self.setTracking, ValueObject)
-               self.parse_property(statement, PROPERTY.COURSE, self.setCourse, ValueObject)
-               super(Direction, self)._parseStatement(statement)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.BEARING, self.setBearing, ValueObject, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HEADING, self.setHeading, ValueObject, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.TRACKING, self.setTracking, ValueObject, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.COURSE, self.setCourse, ValueObject, custom_classes = custom_classes)
+               super(Direction, self)._parseStatement(statement, custom_classes = custom_classes)
index 7bf0657b716ed6fa8deed46df393cf0de284d619..3d1c703d8c91ac41bf96596585d2fa3037f21b59 100644 (file)
@@ -37,7 +37,7 @@ class Entity(Obj):
                
                self.setType(RESOURCE.ENTITY)
 
-       def _parseStatement(self, statement):
+       def _parseStatement(self, statement, custom_classes = None):
                from SmartAPI.model.Address import Address
                from SmartAPI.model.Coordinates import Coordinates
                from SmartAPI.model.Zone import Zone
@@ -50,26 +50,26 @@ class Entity(Obj):
                from SmartAPI.model.ValueObject import ValueObject
                from SmartAPI.rdf.Variant import Variant
                
-               self.parse_property(statement, PROPERTY.ZONE, self.setZone, Zone)
-               self.parse_property(statement, PROPERTY.LOCATION, self.setCoordinates, Coordinates)
-               self.parse_property(statement, PROPERTY.HASADDRESS, self.setAddress, Address)
-               self.parse_property(statement, PROPERTY.ISMANAGEDBY, self.setManagedBy, Variant)
-               self.parse_property(statement, PROPERTY.HASEVALUATION, self.addControllability, Controllability)
-               self.parse_property(statement, PROPERTY.HASAVAILABILITY, self.addAvailability, Availability)
-               self.parse_property(statement, PROPERTY.HASDATAAVAILABILITY, self.addDataAvailability, Availability)
-               self.parse_property(statement, PROPERTY.HASCAPABILITY, self.addCapability, Activity)
-               self.parse_property(statement, PROPERTY.MANAGES, self.addManagedEntity, Variant)
-               self.parse_property(statement, PROPERTY.CAPACITY, self.addCapacity, Evaluation)         
-               self.parse_property(statement, PROPERTY.OWNER, self.addOwner, Entity)
-               self.parse_property(statement, PROPERTY.HASURL, self.addWebsite, Variant)
-               self.parse_property(statement, PROPERTY.CREATOR, self.addCreator, Entity)
-               self.parse_property(statement, PROPERTY.HASLOGO, self.addLogo, Variant)
-               self.parse_property(statement, PROPERTY.HASPHOTO, self.addPhoto, Variant)
-               self.parse_property(statement, PROPERTY.HASSOUND, self.addSound, Variant)
-               self.parse_property(statement, PROPERTY.VALUEOBJECT, self.addValueObject, ValueObject)
-               self.parse_property(statement, PROPERTY.INTERFACE, self.addInterface, InterfaceAddress)
-               self.parse_property(statement, PROPERTY.ROUTE, self.setRoute, Route)
-               super(Entity, self)._parseStatement(statement)
+               self.parse_property(statement, PROPERTY.ZONE, self.setZone, Zone, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.LOCATION, self.setCoordinates, Coordinates, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HASADDRESS, self.setAddress, Address, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.ISMANAGEDBY, self.setManagedBy, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HASEVALUATION, self.addControllability, Controllability, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HASAVAILABILITY, self.addAvailability, Availability, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HASDATAAVAILABILITY, self.addDataAvailability, Availability, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HASCAPABILITY, self.addCapability, Activity, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.MANAGES, self.addManagedEntity, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.CAPACITY, self.addCapacity, Evaluation, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.OWNER, self.addOwner, Entity, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HASURL, self.addWebsite, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.CREATOR, self.addCreator, Entity, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HASLOGO, self.addLogo, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HASPHOTO, self.addPhoto, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HASSOUND, self.addSound, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.VALUEOBJECT, self.addValueObject, ValueObject, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.INTERFACE, self.addInterface, InterfaceAddress, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.ROUTE, self.setRoute, Route, custom_classes = custom_classes)
+               super(Entity, self)._parseStatement(statement, custom_classes = custom_classes)
        
        def hasZone(self):
                return self.zone is not None
index fc8b8622829764b6460787e59e186eb996fc0bb0..8c13b4a396877245c61e0c3b248d29a2977aea6b 100644 (file)
@@ -26,5 +26,8 @@ class Enumeration(Obj):
             op = Variant(op)
         self.options.append(op) 
         
-    def _parseStatement(self, statement):
-        self.parse_property(statement, PROPERTY.OPTIONS, self.addOption, Variant)
\ No newline at end of file
+    def _parseStatement(self, statement, custom_classes = None):
+        self.parse_property(statement, PROPERTY.OPTIONS, self.addOption, Variant, custom_classes = custom_classes)
+        super(Enumeration, self)._parseStatement(statement, custom_classes = custom_classes)
+        
+        
\ No newline at end of file
index fc4e6de46a94f4e2a8ac1ba21bf48dad6e96b3cb..64205c4b1698dde9b8df435b26a643a1da15b1b9 100644 (file)
@@ -13,7 +13,7 @@ class Error(Obj):
        
        def setErrorMessage(self, em):
                if not isinstance(em, Variant):
-                       em = Variant(em)                        
+                       em = Variant(em)
                self.message = em
        
        def getErrorMessage(self):
@@ -33,9 +33,8 @@ class Error(Obj):
        def hasErrorMessage(self):
                return self.message != None
        
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.ERRORMESSAGE, self.setErrorMessage, Variant)
-               self.parse_property(statement, PROPERTY.ERRORCODE, self.setErrorCode, Variant)          
-               super(Error, self)._parseStatement(statement)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.ERRORMESSAGE, self.setErrorMessage, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.ERRORCODE, self.setErrorCode, Variant, custom_classes = custom_classes)
+               super(Error, self)._parseStatement(statement, custom_classes = custom_classes)
 
-               
index 6770a01a89c28b001d5d67ea6134f6095a5514c2..1733aaff45588acdc1e869f6458f37d5fbe54e2a 100644 (file)
@@ -37,18 +37,18 @@ class Evaluation(ValueObject):
                        traceback.print_exc()
                        return None
        
-       def _parseStatement(self, statement):
+       def _parseStatement(self, statement, custom_classes = None):
                from SmartAPI.rdf.Variant import Variant
                from SmartAPI.model.Obj import Obj
                from SmartAPI.model.SystemOfInterest import SystemOfInterest
                from SmartAPI.model.TimeSeries import TimeSeries
                from SmartAPI.common.Tools import Tools
                
-               self.parse_property(statement, PROPERTY.SYSTEMOFINTEREST, self.setSystemOfInterest, SystemOfInterest)
-               self.parse_property(statement, PROPERTY.CATEGORY, self.addCategory, Variant)
-               self.parse_property(statement, PROPERTY.TIMESERIES, self.addTimeSerie, TimeSeries)
-               self.parse_property(statement, PROPERTY.METHOD, self.setMethod, Variant)
-               super(Evaluation, self)._parseStatement(statement)
+               self.parse_property(statement, PROPERTY.SYSTEMOFINTEREST, self.setSystemOfInterest, SystemOfInterest, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.CATEGORY, self.addCategory, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.TIMESERIES, self.addTimeSerie, TimeSeries, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.METHOD, self.setMethod, Variant, custom_classes = custom_classes)
+               super(Evaluation, self)._parseStatement(statement, custom_classes = custom_classes)
 
        def hasCategory(self):
                return len(self.categories) > 0
@@ -110,6 +110,8 @@ class Evaluation(ValueObject):
                return self.method
        
        def setMethod(self, methodUri):
+               from SmartAPI.rdf.Variant import Variant
+               
                '''
                @param methodUri: method Uri string
                '''     
index 26be3dbb0248220553584ba5c36bf7426494bd6d..451ca58576372b01bd0bc27a83b0538f439d9a70 100644 (file)
@@ -10,12 +10,12 @@ class GrObj(Obj):
     classdocs
     '''
 
-    def __init__(self, uri = None):        
+    def __init__(self, uri = None):
         super(GrObj, self).__init__(uri)
         self.init_property(PROPERTY.NAME, 'grName', self.hasGrName, self.getGrName)
-        self.init_property(PROPERTY.GR_DESCRIPTION, 'grDescription', self.hasGrDescription, self.getGrDescription)        
+        self.init_property(PROPERTY.GR_DESCRIPTION, 'grDescription', self.hasGrDescription, self.getGrDescription)
     
-    def hasGrName(self):  
+    def hasGrName(self):
         return self.grName is not None
     
     def setGrName(self, gname):
@@ -24,7 +24,7 @@ class GrObj(Obj):
         self.grName = gname
         
     def getGrName(self):
-        return self.grName  
+        return self.grName
     
     def hasGrDescription(self):
         return self.grDescription is not None
@@ -35,10 +35,10 @@ class GrObj(Obj):
     def setGrDescription(self, gdescription):
         if not isinstance(gdescription, Variant):
             gdescription = Variant(gdescription)
-        self.grDescription = gdescription        
+        self.grDescription = gdescription
     
-    def _parseStatement(self, statement):
-        self.parse_property(statement, PROPERTY.NAME, self.setGrName, Variant)
-        self.parse_property(statement, PROPERTY.GR_DESCRIPTION, self.setGrDescription, Variant)                
-        super(GrObj, self)._parseStatement(statement)
+    def _parseStatement(self, statement, custom_classes = None):
+        self.parse_property(statement, PROPERTY.NAME, self.setGrName, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.GR_DESCRIPTION, self.setGrDescription, Variant, custom_classes = custom_classes)
+        super(GrObj, self)._parseStatement(statement, custom_classes = custom_classes)
     
\ No newline at end of file
index 61ead16dacb978774ee54049b6fbb9e419d29e84..902113275e5f80da68eb2d4aa80318a94fb5cbe3 100644 (file)
@@ -19,15 +19,15 @@ class Grading(Obj):
         self.init_property(PROPERTY.VALUEGRADE, 'valueGrade', self.hasValueGrade, self.getValueGrade)
         self.init_property(PROPERTY.SYNTAXGRADE, 'syntaxGrade', self.hasSyntaxGrade, self.getSyntaxGrade)
         self.init_property(PROPERTY.CONCEPTGRADE, 'conceptGrade', self.hasConceptGrade, self.getConceptGrade)
-        self.init_property(PROPERTY.GRADE, 'grade', self.hasGrade, self.getGrade)     
+        self.init_property(PROPERTY.GRADE, 'grade', self.hasGrade, self.getGrade)
+    
+    def _parseStatement(self, statement, custom_classes = None):
+        self.parse_property(statement, PROPERTY.VALUEGRADE, self.setValueGrade, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.SYNTAXGRADE, self.setSyntaxGrade, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.CONCEPTGRADE, self.setConceptGrade, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.GRADE, self.setGrade, Variant, custom_classes = custom_classes)
+        super(Grading, self)._parseStatement(statement, custom_classes = custom_classes)
     
-    def _parseStatement(self, statement):
-        self.parse_property(statement, PROPERTY.VALUEGRADE, self.setValueGrade, Variant)
-        self.parse_property(statement, PROPERTY.SYNTAXGRADE, self.setSyntaxGrade, Variant)
-        self.parse_property(statement, PROPERTY.CONCEPTGRADE, self.setConceptGrade, Variant)
-        self.parse_property(statement, PROPERTY.GRADE, self.setGrade, Variant)                  
-        super(Grading, self)._parseStatement(statement)
-                
     def setValueGrade(self, grade):
         '''
         @type grade: simple Python data type 
index 2409ceaec476aeb689952b6b858586e3be907611..86261c56b14fef1b1bf527fc76541754186d86b7 100644 (file)
@@ -12,16 +12,16 @@ class Input(Evaluation):
        TYPE_REFERENCE = 1
                
        def __init__(self, uri = None, inputType = TYPE_DATA):
-               Evaluation.__init__(self, uri)          
+               Evaluation.__init__(self, uri)
                self.inputType = inputType
-               self.init_property(PROPERTY.OUTPUTVALUES, 'outputValues', self.hasOutputValue, self.getOutputValues, True)              
+               self.init_property(PROPERTY.OUTPUTVALUES, 'outputValues', self.hasOutputValue, self.getOutputValues, True)
                self.setType(RESOURCE.INPUT)
 
-       def _parseStatement(self, statement):
+       def _parseStatement(self, statement, custom_classes = None):
                from SmartAPI.model.ValueObject import ValueObject
-                                               
-               self.parse_property(statement, PROPERTY.OUTPUTVALUES, self.addOutputValue, ValueObject)
-               super(Input, self)._parseStatement(statement)
+               
+               self.parse_property(statement, PROPERTY.OUTPUTVALUES, self.addOutputValue, ValueObject, custom_classes = custom_classes)
+               super(Input, self)._parseStatement(statement, custom_classes = custom_classes)
 
        def getInputType(self):
                return self.inputType
index 13bc9a51088f700f708634928fa0c9048956a5e3..d6329fa74743464ade90f264be196fa30d0758ac 100644 (file)
@@ -17,14 +17,14 @@ class InterfaceAddress(Obj):
                self.init_property(PROPERTY.TOPIC, 'topic', self.hasCompleteEncodedTopic, self.getCompleteEncodedTopic)
                self.init_property(PROPERTY.CONTENTTYPE, 'contentTypes', self.hasContentType, self.getContentType, True)
                
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.SCHEME, self.setScheme, Variant)
-               self.parse_property(statement, PROPERTY.HOST, self.setHost, Variant)
-               self.parse_property(statement, PROPERTY.PORT, self.setPort, Variant)
-               self.parse_property(statement, PROPERTY.PATH, self.setPath, Variant)
-               self.parse_property(statement, PROPERTY.TOPIC, self.setCompleteEncodedTopic, Variant)
-               self.parse_property(statement, PROPERTY.CONTENTTYPE, self.addContentType, Variant)
-               super(InterfaceAddress, self)._parseStatement(statement)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.SCHEME, self.setScheme, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HOST, self.setHost, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.PORT, self.setPort, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.PATH, self.setPath, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.TOPIC, self.setCompleteEncodedTopic, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.CONTENTTYPE, self.addContentType, Variant, custom_classes = custom_classes)
+               super(InterfaceAddress, self)._parseStatement(statement, custom_classes = custom_classes)
        
        def hasHost(self):
                return self.host is not None
index 4774abe4ea69a8d53128b8b2aad735134b2223ac..3352d47ff983176f506ba1c39cf00797a8bcbae6 100644 (file)
@@ -14,12 +14,13 @@ class License(Contract):
         self.init_property(PROPERTY.ACCOUNT, "account", self.hasAccount, self.getAccount)
         self.init_property(PROPERTY.HASPRICESPECIFICATION, "priceSpecifications", self.hasPriceSpecification, self.getPriceSpecifications, True)
     
-    def _parseStatement(self, statement):
+    def _parseStatement(self, statement, custom_classes = None):
         from SmartAPI.model.Account import Account
         
-        self.parse_property(statement, PROPERTY.LICENSEKEY, self.setLicenseKey, Variant)  
-        self.parse_property(statement, PROPERTY.ACCOUNT, self.setAccount, Acount)
-        self.parse_property(statement, PROPERTY.HASPRICESPECIFICATION, self.addPriceSpecification, PriceSpecification)
+        self.parse_property(statement, PROPERTY.LICENSEKEY, self.setLicenseKey, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.ACCOUNT, self.setAccount, Account, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.HASPRICESPECIFICATION, self.addPriceSpecification, PriceSpecification, custom_classes = custom_classes)
+        super(License, self)._parseStatement(statement, custom_classes = custom_classes)
         
     def hasLicenseKey(self):
         return self.licenseKey is not None
index a65052e1da5feb26ca20081c41027d14a6ba3a4b..fcdc4b25a100518614c593e4e406401c4f964664 100644 (file)
@@ -91,10 +91,9 @@ class Map(Obj):
                return resource
 
 
-       def _parseStatement(self, statement):
+       def _parseStatement(self, statement, custom_classes = None):
                from SmartAPI.rdf.Variant import Variant
                
-               
                # get predicate
                predicate = str(statement.getPredicate())
                
@@ -111,10 +110,10 @@ class Map(Obj):
                                key = Variant().parse(keyStmt[0])
                                s = valueStmt[0]
                                
-                               target_class = Tools().getResourceClass(s.getResource())
+                               target_class = Tools().getResourceClass(s.getResource(), custom_classes = custom_classes)
                                if target_class is not None:
                                        try:
-                                               value = target_class().parse(s.getResource())
+                                               value = target_class().parse(s.getResource(), custom_classes = custom_classes)
                                        except:
                                                print "Unable to interpret seas:value as value for Parameter."
                                                traceback.print_exc()
@@ -136,5 +135,5 @@ class Map(Obj):
                        return
 
                # pass on to Object
-               super(Map, self)._parseStatement(statement)
+               super(Map, self)._parseStatement(statement, custom_classes = custom_classes)
 
index 13855454229fe2d5fdce830d693537994a3b46ca..61264856fac6aa0e7393357537d954160b55e396 100644 (file)
@@ -16,21 +16,21 @@ class Message(Obj):
        
        def __init__(self, uri = None):
                Obj.__init__(self, uri)
-               self.init_property(PROPERTY.ID, 'id', self.hasId, self.getId)                   
-               self.init_property(PROPERTY.METHOD, 'method', self.hasMethod, self.getMethod)   
+               self.init_property(PROPERTY.ID, 'id', self.hasId, self.getId)
+               self.init_property(PROPERTY.METHOD, 'method', self.hasMethod, self.getMethod)
                self.init_property(PROPERTY.TRANSACTIONID, 'transactionId', self.hasTransactionId, self.getTransactionId)
-               self.init_property(PROPERTY.PROCESSID, 'processId', self.hasProcessId, self.getProcessId)       
-               self.init_property(PROPERTY.ACTIVITY, 'activities', self.hasActivity, self.getActivities, islist = True)                
-               self.setType(RESOURCE.MESSAGE)          
+               self.init_property(PROPERTY.PROCESSID, 'processId', self.hasProcessId, self.getProcessId)
+               self.init_property(PROPERTY.ACTIVITY, 'activities', self.hasActivity, self.getActivities, islist = True)
+               self.setType(RESOURCE.MESSAGE)
        
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.ID, self.setId, Variant)
-               self.parse_property(statement, PROPERTY.METHOD, self.setMethod, Variant)
-               self.parse_property(statement, PROPERTY.TRANSACTIONID, self.setTransactionId, Obj)      
-               self.parse_property(statement, PROPERTY.PROCESSID, self.setProcessId, Variant)
-               self.parse_property(statement, PROPERTY.ACTIVITY, self.addActivity, Activity)                                                   
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.ID, self.setId, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.METHOD, self.setMethod, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.TRANSACTIONID, self.setTransactionId, Obj, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.PROCESSID, self.setProcessId, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.ACTIVITY, self.addActivity, Activity, custom_classes = custom_classes)
                # pass on to Evaluation
-               super(Message, self)._parseStatement(statement)
+               super(Message, self)._parseStatement(statement, custom_classes = custom_classes)
 
        def hasMethod(self):
                return self.method is not None
@@ -38,7 +38,7 @@ class Message(Obj):
        def getMethod(self):
                return self.method
        
-       def setMethod(self, m):         
+       def setMethod(self, m):
                if m is not None:
                        if isinstance(m, str): 
                                m = Variant(URIRef(m))
index 91629053663fe5bfcb827579edcbc841f6cede81..98833282e95ad8088111d4ce6876420841944e96 100644 (file)
@@ -368,12 +368,13 @@ class Obj(object):
                if getter is None: getter = getattr(self, 'get' + classProperty[0].upper() + classProperty[1:])
                self.properties[property] = (hasFunc, getter, listClass)
                
-       def parse_property(self, stmt, property, setter, klass):
+       def parse_property(self, stmt, property, setter, klass, custom_classes = None):
                if (str(stmt.getPredicate()) == property):
-                       setter(klass.parse(stmt.getResource()))
+                       klazz = Tools.getResourceClass(stmt.getResource(), default = klass, custom_classes = custom_classes)
+                       setter(klazz.parse(stmt.getResource(), custom_classes = custom_classes))
                        raise ParseSucceededException() # yes, this is raised _on success_, not fail
 
-       def parse_propertylist(self, stmt, property, setter, klass):
+       def parse_propertylist(self, stmt, property, setter, klass, custom_classes = None):
                if (str(stmt.getPredicate()) == property):
                        listObject = stmt.getResource().toList(klass)
                        setter(listObject)
@@ -390,7 +391,7 @@ class Obj(object):
                resource.addProperty( model.createProperty( property ), self._convert(obj, model))
                
        @classmethod
-       def parse(cls, element):
+       def parse(cls, element, custom_classes = None):
                '''
                factory method and class method. It takes in Resource as parameter, create a Smart API Obj or 
                its subClass object. 
@@ -411,7 +412,7 @@ class Obj(object):
                        
                        for i in element.findProperties():
                                try:
-                                       obj._parseStatement(i)
+                                       obj._parseStatement(i, custom_classes = custom_classes)
                                except ParseSucceededException:
                                        pass
                                
@@ -433,7 +434,7 @@ class Obj(object):
                                                        rootRes = Tools.getTopNode(model)[0]
                                                        
                                                        # figure out its SMARTAPI Class
-                                                       seasCls = Tools.getResourceClass(rootRes)
+                                                       seasCls = Tools.getResourceClass(rootRes, custom_classes = custom_classes)
                                                        
                                                        # recover it to Obj or its subclass Object
                                                        recoveredObj =  seasCls.parse(rootRes)
@@ -456,7 +457,7 @@ class Obj(object):
                
                return None
                
-       def _parseStatement(self, statement):
+       def _parseStatement(self, statement, custom_classes = None):
                '''
                It takes in statement as input, add property to existing model Class object.
                Return None
@@ -629,7 +630,8 @@ class Obj(object):
                # parameters
                if predicate == PROPERTY.PARAMETER:
                        p = Parameter().parse(statement.getResource())
-                       self.add(p.getKey(), p.getValues())
+                       if p.getKey():
+                               self.add(p.getKey().getValue(), p.getValues())
                        return 
                
                # if literal object
@@ -653,7 +655,7 @@ class Obj(object):
                        
                        # first check if resource has a type implemented built-in
                        # and parse using that
-                       klass = Tools().getResourceClass(resource, default = Obj)
+                       klass = Tools().getResourceClass(resource, default = Obj, custom_classes = custom_classes)
                        
                        if klass is not None:
                                self.add(URIRef(predicate), klass.parse(resource))
@@ -666,7 +668,7 @@ class Obj(object):
                # Nothing else matches, use BNode as blank default entry
                if isinstance(objectNode, BNode):
                        try:
-                               klass = Tools().getResourceClass(statement.getResource(), default = None)
+                               klass = Tools().getResourceClass(statement.getResource(), default = None, custom_classes = custom_classes)
                        except:
                                klass = None
                        if klass is not None:
index e458fbd03b0ea0be7ecbb9f27a5f41f05b1577d1..c1497d083249b5b9b4ff43993ecddfcaaee080e5 100644 (file)
@@ -54,7 +54,7 @@ class Offering(GrObj):
         '''
         @type sometimes: SomeItems 
         '''
-        self.includes.append(someitems)   
+        self.includes.append(someitems)
         
     def hasTypeAndQuantityNode(self):
         return len(self.typeAndQuantityNodes) > 0
@@ -87,12 +87,12 @@ class Offering(GrObj):
         price = UnitPriceSpecification(None, price, unit, secondaryUnit, secondaryQuantity, validFrom, validThrough)
         self.addPriceSpecification(price)
     
-    def _parseStatement(self, statement):
+    def _parseStatement(self, statement, custom_classes = None):
         from TypeAndQuantityNode import TypeAndQuantityNode
         
-        self.parse_property(statement, PROPERTY.HASBUSINESSFUNCTION, self.setBusinessFunction, Obj)
-        self.parse_property(statement, PROPERTY.HASPRICESPECIFICATION, self.addPriceSpecification, PriceSpecification)
-        self.parse_property(statement, PROPERTY.INCLUDES, self.addIncludes, SomeItems)
-        self.parse_property(statement, PROPERTY.INCLUDESOBJECT, self.addTypeAndQuantityNode, TypeAndQuantityNode)
-        super(Offering, self)._parseStatement(statement)
+        self.parse_property(statement, PROPERTY.HASBUSINESSFUNCTION, self.setBusinessFunction, Obj, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.HASPRICESPECIFICATION, self.addPriceSpecification, PriceSpecification, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.INCLUDES, self.addIncludes, SomeItems, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.INCLUDESOBJECT, self.addTypeAndQuantityNode, TypeAndQuantityNode, custom_classes = custom_classes)
+        super(Offering, self)._parseStatement(statement, custom_classes = custom_classes)
     
\ No newline at end of file
index 18cd4aae78bbfa7958ea1c2de986cc672c139b60..7b8aa2c4e8bd74aad5f159d2799cb6021d97f809 100644 (file)
@@ -39,9 +39,9 @@ class Orientation(Obj):
        def getRoll(self):
                return self.roll
        
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.PITCH, self.setPitch, ValueObject)
-               self.parse_property(statement, PROPERTY.YAW, self.setYaw, ValueObject)
-               self.parse_property(statement, PROPERTY.ROLL, self.setRoll, ValueObject)
-               super(Orientation, self)._parseStatement(statement)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.PITCH, self.setPitch, ValueObject, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.YAW, self.setYaw, ValueObject, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.ROLL, self.setRoll, ValueObject, custom_classes = custom_classes)
+               super(Orientation, self)._parseStatement(statement, custom_classes = custom_classes)
        
\ No newline at end of file
index 68d76bb14e64e5b5be7a35d669c73df02e159288..829d5ba04696854f5a9116e6ca818059ab24b901 100644 (file)
@@ -15,15 +15,15 @@ class Output(Evaluation):
                
                self.init_property(PROPERTY.HASAVAILABILITY, 'availabilities', self.hasAvailability, self.getActivities, islist = True)
                self.init_property(PROPERTY.HASDATAAVAILABILITY, 'dataAvailabilities', self.hasDataAvailability, self.getDataAvailabilities, islist = True)
-                                               
-               self.setType(RESOURCE.OUTPUT)   
+               
+               self.setType(RESOURCE.OUTPUT)
 
-       def _parseStatement(self, statement):
+       def _parseStatement(self, statement, custom_classes = None):
                from SmartAPI.model.Availability import Availability
                
-               self.parse_property(statement, PROPERTY.HASAVAILABILITY, self.addAvailability, Availability)
-               self.parse_property(statement, PROPERTY.HASDATAAVAILABILITY, self.addDataAvailability, Availability)
-               super(Output, self)._parseStatement(statement)
+               self.parse_property(statement, PROPERTY.HASAVAILABILITY, self.addAvailability, Availability, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HASDATAAVAILABILITY, self.addDataAvailability, Availability, custom_classes = custom_classes)
+               super(Output, self)._parseStatement(statement, custom_classes = custom_classes)
 
        def hasAvailability(self):
                return len(self.availabilities) > 0
index e0e0956746cc0287778d60fe780b84cd07ba672f..ecfddd09748ac1b9be8dbb360412cdaa3bdbfc12 100644 (file)
@@ -48,9 +48,9 @@ class Parameter(Obj):
        def getValues(self):
                return self.values
                
-       def _parseStatement(self, statement):
+       def _parseStatement(self, statement, custom_classes = None):
                self.parse_property(statement, PROPERTY.KEY, self.setKey, Variant)
-               self.parse_property(statement, PROPERTY.RDF_VALUE, self.addValue, Variant)                              
+               self.parse_property(statement, PROPERTY.RDF_VALUE, self.addValue, Variant)
                # pass on to Object
-               super(Parameter, self)._parseStatement(statement)
+               super(Parameter, self)._parseStatement(statement, custom_classes = custom_classes)
 
index fa2b80219c60b09e3f02c047edb091b91e228327..532170b1909b2ac2b9f5b23e29b7562833578a4d 100644 (file)
@@ -24,6 +24,7 @@ class Person(PhysicalEntity):
                        u = Variant(u)
                self.username = u
                
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.USERNAME, self.setUsername, Variant)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.USERNAME, self.setUsername, Variant, custom_classes = custom_classes)
+               super(Person, self)._parseStatement(statement, custom_classes = custom_classes)
                
\ No newline at end of file
index 1b150740ba98d94475d9e67362ba6614f3c8c996..a87fa3b9293160c0fa9e42d6e75be1012c156c1f 100644 (file)
@@ -60,16 +60,16 @@ class PhysicalEntity(Entity):
        def setWeight(self, w):
                self.weight = w
        
-       def _parseStatement(self, statement):
+       def _parseStatement(self, statement, custom_classes = None):
                from SmartAPI.model.Size import Size
                from SmartAPI.model.Orientation import Orientation
                from SmartAPI.model.Direction import Direction
                from SmartAPI.model.Velocity import Velocity
                from SmartAPI.model.ValueObject import ValueObject
                
-               self.parse_property(statement, PROPERTY.VELOCITY, self.setVelocity, Velocity)
-               self.parse_property(statement, PROPERTY.ORIENTATION, self.setOrientation, Orientation)
-               self.parse_property(statement, PROPERTY.SIZE, self.setSize, Size)
-               self.parse_property(statement, PROPERTY.DIRECTION, self.setDirection, Direction)
-               self.parse_property(statement, PROPERTY.WEIGHT, self.setWeight, ValueObject)
-               super(PhysicalEntity, self)._parseStatement(statement);
+               self.parse_property(statement, PROPERTY.VELOCITY, self.setVelocity, Velocity, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.ORIENTATION, self.setOrientation, Orientation, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.SIZE, self.setSize, Size, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.DIRECTION, self.setDirection, Direction, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.WEIGHT, self.setWeight, ValueObject, custom_classes = custom_classes)
+               super(PhysicalEntity, self)._parseStatement(statement, custom_classes = custom_classes)
index 4a370b80d0d24e826fee346a93a068891baf1686..2989618fe0a2d2b5e77a5ea074016e61af1e4bd9 100644 (file)
@@ -64,7 +64,7 @@ class PriceSpecification(GrObj):
         if isinstance(q, str): 
             q = Variant(URIRef(q))
         elif isinstance(q, URIRef):
-            q = Variant(q)            
+            q = Variant(q)
         self.quantity = q
     
     def hasUnit(self):
@@ -93,8 +93,8 @@ class PriceSpecification(GrObj):
         if isinstance(secQuantity, str): 
             secQuantity = Variant(URIRef(secQuantity))
         elif isinstance(secQuantity, URIRef):
-            secQuantity = Variant(secQuantity)  
-        self.secondQuantity = secQuantity 
+            secQuantity = Variant(secQuantity)
+        self.secondQuantity = secQuantity
         
     def hasSecondUnit(self):
         return self.secondUnit is not None
@@ -165,17 +165,18 @@ class PriceSpecification(GrObj):
         else: # if int, double,...
             self.vatPercentage = Variant(vp)
     
+    def _parseStatement(self, statement, custom_classes = None):
+        self.parse_property(statement, PROPERTY.HASCURRENCY, self.setCurrency, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.HASCURRENCYVALUE, self.setCurrencyValue, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.VALIDFROM, self.setValidFrom, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.VALIDTHROUGH, self.setValidThrough, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.VALUEADDEDTAXINCLUDED, self.setValueAddedTaxIncluded, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.VATPERCENTAGE, self.setVatPercentage, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.QUANTITYKIND, self.setQuantity, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.UNIT, self.setUnit, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.SECONDARYQUANTITYKIND, self.setSecondQuantity, Variantv, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.SECONDARYUNIT, self.setSecondUnit, Variant, custom_classes = custom_classes)
+        
+        super(PriceSpecification, self)._parseStatement(statement, custom_classes = custom_classes)
     
-    def _parseStatement(self, statement):
-        self.parse_property(statement, PROPERTY.HASCURRENCY, self.setCurrency, Variant)
-        self.parse_property(statement, PROPERTY.HASCURRENCYVALUE, self.setCurrencyValue, Variant)
-        self.parse_property(statement, PROPERTY.VALIDFROM, self.setValidFrom, Variant)
-        self.parse_property(statement, PROPERTY.VALIDTHROUGH, self.setValidThrough, Variant)
-        self.parse_property(statement, PROPERTY.VALUEADDEDTAXINCLUDED, self.setValueAddedTaxIncluded, Variant)
-        self.parse_property(statement, PROPERTY.VATPERCENTAGE, self.setVatPercentage, Variant)
-        self.parse_property(statement, PROPERTY.QUANTITYKIND, self.setQuantity, Variant)
-        self.parse_property(statement, PROPERTY.UNIT, self.setUnit, Variant)
-        self.parse_property(statement, PROPERTY.SECONDARYQUANTITYKIND, self.setSecondQuantity, Variant)
-        self.parse_property(statement, PROPERTY.SECONDARYUNIT, self.setSecondUnit, Variant)        
-                
-        super(PriceSpecification, self)._parseStatement(statement)  
\ No newline at end of file
+    
\ No newline at end of file
index 2dc3d65ac6f8c5b0489d5ae915dda29c55ff6d07..12b12a11d42bfedc064e0dead65e7d7f9df05994 100644 (file)
@@ -79,9 +79,9 @@ class Provenance(Evaluation):
        def setProperties(self, _properties):
                self.props = _properties
                
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.GENERATIONMETHOD, self.addGenerationMethod, Variant)
-               self.parse_property(statement, PROPERTY.DATASOURCE, self.addDataSource, Variant)
-               self.parse_property(statement, PROPERTY.SMARTAPI_PROPERTY, self.addSmartAPIProperty, Variant)
-               super(Provenance, self)._parseStatement(statement)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.GENERATIONMETHOD, self.addGenerationMethod, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.DATASOURCE, self.addDataSource, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.SMARTAPI_PROPERTY, self.addSmartAPIProperty, Variant, custom_classes = custom_classes)
+               super(Provenance, self)._parseStatement(statement, custom_classes = custom_classes)
 
index 79b7d71ad03812c69e96c1eaa5b202aa2f06460e..4d3186e5666261f0d54a60e3cd2448fd482cbc6b 100644 (file)
@@ -5,7 +5,7 @@ class Reference(Obj):
 
     def __init__(self, uri=None, hashCode=None, signature=None, sessionKey=None, encryptionKeyType=None, notary=None):
         super(Reference, self).__init__(uri)
-        self.setType(RESOURCE.REFERENCE)        
+        self.setType(RESOURCE.REFERENCE)
         
         self.setHashCode(hashCode)
         self.setSignature(signature)
index 769f659ce229fefdffb0a1cc5b10c01ce0404bb4..8b0d9ff779571284564724e29de117d0abfc9845 100644 (file)
@@ -14,11 +14,10 @@ class Request(Message):
        def __init__(self, uri = None):
                Message.__init__(self, uri)
                self.setType(RESOURCE.REQUEST)
-               
        
        @classmethod
        def fromString(cls, data, serialization):
-               from SmartAPI.common.Tools import Tools         
+               from SmartAPI.common.Tools import Tools
                try:
                        return cls.parse(Tools().getResourceByType(RESOURCE.REQUEST, Tools().fromString(data, serialization)));
                except:
@@ -26,4 +25,3 @@ class Request(Message):
                        traceback.print_exc() 
                        return None
        
-       
index cbc0d72939f363a0039f7d6bb44ce714cc7a572a..f750a474e95de03eba44a346d73da84961dc8fc2 100644 (file)
@@ -23,5 +23,4 @@ class Response(Message):
                        print "Unable to parse Response from the given string."
                        traceback.print_exc() 
                        return None
-       
-       
+       
\ No newline at end of file
index b038bddee69ea08c7ef3c409b561346bd0949d51..d0db139b117f14f716fb0d0309fd8fd2d23d1ae4 100644 (file)
@@ -31,7 +31,7 @@ class Restriction(Evaluation):
                        traceback.print_exc() 
                        return None
        
-       def _parseStatement(self, statement):
+       def _parseStatement(self, statement, custom_classes = None):
                from SmartAPI.rdf.Variant import Variant
                from SmartAPI.model.Obj import Obj
                from SmartAPI.model.Activity import Activity
@@ -40,14 +40,13 @@ class Restriction(Evaluation):
                from SmartAPI.model.TimeSeries import TimeSeries
                from SmartAPI.common.Tools import Tools
                
-               self.parse_property(statement, PROPERTY.CARDINALITY, self.setCardinality, Variant)
-               self.parse_property(statement, PROPERTY.MINCARDINALITY, self.setMinCardinality, Variant)
-               self.parse_property(statement, PROPERTY.MAXCARDINALITY, self.setMaxCardinality, Variant)
-               self.parse_property(statement, PROPERTY.OPTIONAL, self.setOptional, Variant)
-               self.parse_property(statement, PROPERTY.ONDATARANGE, self.setDataRange, Obj)
-               self.parse_property(statement, PROPERTY.ONPROPERTIES, self.addOnProperty, Obj)
-               super(Evaluation, self)._parseStatement(statement)
-               
+               self.parse_property(statement, PROPERTY.CARDINALITY, self.setCardinality, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.MINCARDINALITY, self.setMinCardinality, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.MAXCARDINALITY, self.setMaxCardinality, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.OPTIONAL, self.setOptional, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.ONDATARANGE, self.setDataRange, Obj, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.ONPROPERTIES, self.addOnProperty, Obj, custom_classes = custom_classes)
+               super(Evaluation, self)._parseStatement(statement, custom_classes = custom_classes)
                
        def hasCardinality(self):
                return self.cardinality is not None
index 47afd919dc2f7113d3b9cedf543afe339a459296..9a9d411de9f6c38514c7dff3a78bab30d42b1fb8 100644 (file)
@@ -48,9 +48,9 @@ class Ring(Obj):
                        maxRadius = Variant(maxRadius)
                self.setMaxRadius(ValueObject(quantity=RESOURCE.LENGTH, unit=RESOURCE.KILOMETER, value=maxRadius))
 
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.LOCATION, self.setCoordinates, Coordinates)
-               self.parse_property(statement, PROPERTY.MINRADIUS, self.setMinRadius, ValueObject)
-               self.parse_property(statement, PROPERTY.MAXRADIUS, self.setMaxRadius, ValueObject)
-               super(Ring, self)._parseStatement(statement)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.LOCATION, self.setCoordinates, Coordinates, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.MINRADIUS, self.setMinRadius, ValueObject, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.MAXRADIUS, self.setMaxRadius, ValueObject, custom_classes = custom_classes)
+               super(Ring, self)._parseStatement(statement, custom_classes = custom_classes)
        
index 2b6e8ade9e694c8d7f73d6ba14337a19724b7c43..cb61656ed85086e8f99822c2771c31e1c0a22f69 100644 (file)
@@ -56,19 +56,19 @@ class Route(Obj):
                '''
                self.route_zones.append(zone);
                
-       def _parseStatement(self, statement):
+       def _parseStatement(self, statement, custom_classes = None):
                from SmartAPI.model.Velocity import Velocity
                from SmartAPI.model.ValueObject import ValueObject
                from SmartAPI.model.TemporalContext import TemporalContext
                
-               self.parse_propertylist(statement, PROPERTY.LIST, self.setRoutePoints, Coordinates)
-               self.parse_propertylist(statement, PROPERTY.ZONEROUTE, self.setRouteZones, Zone)
-               self.parse_property(statement, PROPERTY.LENGTH, self.setLength, ValueObject)
-               self.parse_property(statement, PROPERTY.ENERGYCONSUMPTION, self.setEnergyConsumption, ValueObject)
-               self.parse_property(statement, PROPERTY.AVERAGEVELOCITY, self.setAverageVelocity, Velocity)
-               self.parse_property(statement, PROPERTY.DURATION, self.setDuration, TemporalContext)
-       
-               super(Route, self)._parseStatement(statement)
+               self.parse_propertylist(statement, PROPERTY.LIST, self.setRoutePoints, Coordinates, custom_classes = custom_classes)
+               self.parse_propertylist(statement, PROPERTY.ZONEROUTE, self.setRouteZones, Zone, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.LENGTH, self.setLength, ValueObject, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.ENERGYCONSUMPTION, self.setEnergyConsumption, ValueObject, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.AVERAGEVELOCITY, self.setAverageVelocity, Velocity, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.DURATION, self.setDuration, TemporalContext, custom_classes = custom_classes)
+       
+               super(Route, self)._parseStatement(statement, custom_classes = custom_classes)
 
        def hasLength(self):
                return self.length is not None
index ab05412bb939433823e24fcc27f0da800ebd8354..7c458d768213bf2d6244d9511a8043f4ddee9c03 100644 (file)
@@ -24,9 +24,9 @@ class Service(AbstractEntity):
        def addScreenShot(self, screenshot):
                self.screenshots.append(screenshot)
        
-       def _parseStatement(self, statement):
+       def _parseStatement(self, statement, custom_classes = None):
                from SmartAPI.rdf.Variant import Variant
                
-               self.parse_property(statement, PROPERTY.SCREENSHOT, self.addScreenShot, Variant)
-               super(Service, self)._parseStatement(statement)
+               self.parse_property(statement, PROPERTY.SCREENSHOT, self.addScreenShot, Variant, custom_classes = custom_classes)
+               super(Service, self)._parseStatement(statement, custom_classes = custom_classes)
 
index c34068daca12cb3dc41a62849031227301250dac..2e97d57b493ad9d1064001a83550754654e56937 100644 (file)
@@ -8,7 +8,7 @@ class ServiceProvider(AbstractEntity):
 
        def __init__(self, uri = None):
                AbstractEntity.__init__(self, uri)
-               self.init_property(PROPERTY.OFFERSSERVICE, 'services', self.hasServices, self.getServices, True)                
+               self.init_property(PROPERTY.OFFERSSERVICE, 'services', self.hasServices, self.getServices, True)
                self.setType(RESOURCE.SERVICEPROVIDER)
 
        def setService(self, service):
@@ -23,7 +23,7 @@ class ServiceProvider(AbstractEntity):
        def hasServices(self):
                return len(self.services) > 0
        
-       def _parseStatement(self, statement):
+       def _parseStatement(self, statement, custom_classes = None):
                from SmartAPI.model.Service import Service
-               self.parse_property(statement, PROPERTY.OFFERSSERVICE, self.addService, Service)                                
-               super(ServiceProvider, self)._parseStatement(statement)
+               self.parse_property(statement, PROPERTY.OFFERSSERVICE, self.addService, Service, custom_classes = custom_classes)
+               super(ServiceProvider, self)._parseStatement(statement, custom_classes = custom_classes)
index 80fc3b7c9e2b5b1aabcdcf617206ac583aff6a6c..f3fe77dfb5a53d71826dea39965a38da08c49ae2 100644 (file)
@@ -42,11 +42,11 @@ class Size(Obj):
        def getDepth(self):
                return self.depth
        
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.WIDTH, self.setWidth, ValueObject)
-               self.parse_property(statement, PROPERTY.HEIGHT, self.setHeight, ValueObject)
-               self.parse_property(statement, PROPERTY.DEPTH, self.setDepth, ValueObject)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.WIDTH, self.setWidth, ValueObject, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HEIGHT, self.setHeight, ValueObject, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.DEPTH, self.setDepth, ValueObject, custom_classes = custom_classes)
                
                # pass on to Object
-               super(Size, self)._parseStatement(statement)
+               super(Size, self)._parseStatement(statement, custom_classes = custom_classes)
        
\ No newline at end of file
index aa072e4f2c5c157052e1d367be0073f504005e08..a76fc2f689ed08575c6ea612203f677e7bf1db1a 100644 (file)
@@ -100,11 +100,13 @@ class SomeItems(GrObj):
         except:
             traceback.print_exc()
        
-    def _parseStatement(self, statement):
+    def _parseStatement(self, statement, custom_classes = None):
         from SmartAPI.rdf.Variant import Variant
         
-        self.parse_property(statement, PROPERTY.METHOD, self.setMethod, Variant)
-        self.parse_property(statement, PROPERTY.DURATION, self.setDuration, Variant)
-        self.parse_property(statement, PROPERTY.SYSTEMOFINTEREST, self.setSystemOfInterest, SystemOfInterest)
-        super(SomeItems, self)._parseStatement(statement)
+        self.parse_property(statement, PROPERTY.METHOD, self.setMethod, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.DURATION, self.setDuration, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.SYSTEMOFINTEREST, self.setSystemOfInterest, SystemOfInterest, custom_classes = custom_classes)
+        super(SomeItems, self)._parseStatement(statement, custom_classes = custom_classes)
+        
+        
        
\ No newline at end of file
index e4f59b77fa0b02d7991b355cffdd1a3516c09cea..590a0c390a2b9073febee909ad5aa57fc1a83328 100644 (file)
@@ -16,16 +16,16 @@ class Status(Obj):
                self.init_property(PROPERTY.PERCENTAGE, 'percentage', self.hasPercentage, self.getPercentage)
                self.init_property(PROPERTY.TOTAL, 'total', self.hasTotal, self.getTotal)
                self.init_property(PROPERTY.COMPLETED, 'completed', self.hasCompleted, self.getCompleted)
-               self.init_property(PROPERTY.TEMPORALCONTEXT, 'temporalContext', self.hasTemporalContext, self.getTemporalContext)               
+               self.init_property(PROPERTY.TEMPORALCONTEXT, 'temporalContext', self.hasTemporalContext, self.getTemporalContext)
                self.init_property(PROPERTY.STATUSCODE, 'statusCode', self.hasStatusCode, self.getStatusCode)
        
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.PERCENTAGE, self.setPercentage, Variant)
-               self.parse_property(statement, PROPERTY.TOTAL, self.setTotal, Variant)
-               self.parse_property(statement, PROPERTY.COMPLETED, self.setCompleted, Variant)
-               self.parse_property(statement, PROPERTY.TEMPORALCONTEXT, self.setTemporalContext, TemporalContext)      
-               self.parse_property(statement, PROPERTY.STATUSCODE, self.setStatusCode, Variant)
-               super(Status, self)._parseStatement(statement)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.PERCENTAGE, self.setPercentage, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.TOTAL, self.setTotal, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.COMPLETED, self.setCompleted, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.TEMPORALCONTEXT, self.setTemporalContext, TemporalContext, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.STATUSCODE, self.setStatusCode, Variant, custom_classes = custom_classes)
+               super(Status, self)._parseStatement(statement, custom_classes = custom_classes)
        
        def setPercentage(self, p):
                if not isinstance(p, Variant):
index f330c1a47c32eeca360a62719259adf1830d3428..fd8a40198cb59df1f3f3badf4a05bbff84de8baa 100644 (file)
@@ -10,11 +10,11 @@ class SystemOfInterest(Entity):
        def __init__(self, uri = None):
                Entity.__init__(self, uri)
                self.setType(RESOURCE.SYSTEMOFINTEREST)
-               self.init_property(PROPERTY.REALIZEDBY, 'realizedBy', self.hasRealizedBy, self.getRealizedBy)   
+               self.init_property(PROPERTY.REALIZEDBY, 'realizedBy', self.hasRealizedBy, self.getRealizedBy)
 
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.REALIZEDBY, self.setRealizedBy, Entity)         
-               super(SystemOfInterest, self)._parseStatement(statement)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.REALIZEDBY, self.setRealizedBy, Entity, custom_classes = custom_classes)
+               super(SystemOfInterest, self)._parseStatement(statement, custom_classes = custom_classes)
 
        def hasRealizedBy(self):
                return self.realizedBy is not None
index 4cadf135a67e93cec690f2d11c32e92e6016b276..594aac0c58858a38377d4d85f9099c9083f3a214 100644 (file)
@@ -22,18 +22,18 @@ class TemporalContext(Obj):
                self.init_property(PROPERTY.DURATION, 'duration', self.hasDuration, self.getDuration)
                self.init_property(PROPERTY.DURING, 'during', self.hasDuring, self.getDuring)
                if start is not None:
-                       self.setStart(start)            
+                       self.setStart(start)
                if end is not None:
-                       self.setEnd(end)                
+                       self.setEnd(end)
                if during is not None:
-                       self.setDuring(during)                  
+                       self.setDuring(during)
 
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.START, self.setStart, Variant)
-               self.parse_property(statement, PROPERTY.END, self.setEnd, Variant)                      
-               self.parse_property(statement, PROPERTY.DURATION, self.setDuration, Variant)                                            
-               self.parse_property(statement, PROPERTY.DURING, self.setDuring, Variant)                
-               super(TemporalContext, self)._parseStatement(statement)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.START, self.setStart, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.END, self.setEnd, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.DURATION, self.setDuration, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.DURING, self.setDuring, Variant, custom_classes = custom_classes)
+               super(TemporalContext, self)._parseStatement(statement, custom_classes = custom_classes)
                
        def hasStart(self):
                return self.start is not None
index 1bd2581ef1196baa5731c47eadd4f5c9a26d9a6e..7e55b1bbab3553d2b0d3043f9a89618d29832801 100644 (file)
@@ -24,16 +24,16 @@ class TimeSeries(Obj):
                self.init_propertylist(PROPERTY.LIST, 'list', OrderedList.OrderedList, self.hasList, self.getList)
                self.setType(RESOURCE.TIMESERIES)
 
-       def _parseStatement(self, statement):
+       def _parseStatement(self, statement, custom_classes = None):
                from SmartAPI.rdf.Variant import Variant
                
-               self.parse_propertylist(statement, PROPERTY.LIST, self.setList, Evaluation)
-               self.parse_property(statement, PROPERTY.QUANTITYKIND, self.setQuantity, Variant)
-               self.parse_property(statement, PROPERTY.UNIT, self.setUnit, Variant)
-               self.parse_property(statement, PROPERTY.TIMESTEP, self.setTimeStep, Variant)
-               self.parse_property(statement, PROPERTY.SYSTEMOFINTEREST, self.setSystemOfInterest, SystemOfInterest)
-               self.parse_property(statement, PROPERTY.TEMPORALCONTEXT, self.setTemporalContext, TemporalContext)
-               super(TimeSeries, self)._parseStatement(statement)
+               self.parse_propertylist(statement, PROPERTY.LIST, self.setList, Evaluation, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.QUANTITYKIND, self.setQuantity, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.UNIT, self.setUnit, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.TIMESTEP, self.setTimeStep, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.SYSTEMOFINTEREST, self.setSystemOfInterest, SystemOfInterest, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.TEMPORALCONTEXT, self.setTemporalContext, TemporalContext, custom_classes = custom_classes)
+               super(TimeSeries, self)._parseStatement(statement, custom_classes = custom_classes)
 
        def hasQuantity(self):
                return self.quantity is not None
index 76f678d4eff31f32a6730d4492892d185da6c683..e20689561c237dd7fa3dac48a9e2e1b7a838af70 100644 (file)
@@ -40,8 +40,9 @@ class Transaction(Obj):
     def setNotarizedObject(self, no):
         self.notarizedObject = no
     
-    def _parseStatement(self, statement):
-        self.parse_property(statement, PROPERTY.SIGNER, self.setSigner, Entity)
-        self.parse_property(statement, PROPERTY.NOTARIZEDOBJECT, self.setNotarizedObject, Obj)
+    def _parseStatement(self, statement, custom_classes = None):
+        self.parse_property(statement, PROPERTY.SIGNER, self.setSigner, Entity, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.NOTARIZEDOBJECT, self.setNotarizedObject, Obj, custom_classes = custom_classes)
+        
+        super(Transaction, self)._parseStatement(statement, custom_classes = custom_classes)
         
-        super(Transaction, self)._parseStatement(statement)
index a2abaa08a3723a5cceac8315ee2905d7f9731059..300cbe2e59b9b1b81d7819e22d4bee5613fc7bb8 100644 (file)
@@ -55,11 +55,15 @@ class TypeAndQuantityNode(GrObj):
     def setTypeOfGood(self, obj):
         self.typeOfGood = obj
     
-    def _parseStatement(self, statement):
+    def _parseStatement(self, statement, custom_classes = None):
         from SmartAPI.rdf.Variant import Variant
         from Obj import Obj
         
-        self.parse_property(statement, PROPERTY.AMOUNTOFTHISGOOD, self.setAmount, Variant)
-        self.parse_property(statement, PROPERTY.HASUNITOFMEASUREMENT, self.setUnitOfMeasurement, Variant)
-        self.parse_property(statement, PROPERTY.TYPEOFGOOD, self.setTypeOfGood, Obj)
+        self.parse_property(statement, PROPERTY.AMOUNTOFTHISGOOD, self.setAmount, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.HASUNITOFMEASUREMENT, self.setUnitOfMeasurement, Variant, custom_classes = custom_classes)
+        self.parse_property(statement, PROPERTY.TYPEOFGOOD, self.setTypeOfGood, Obj, custom_classes = custom_classes)
+        
+        super(TypeAndQuantityNode, self)._parseStatement(statement, custom_classes = custom_classes)
+        
+        
         
\ No newline at end of file
index 5397fe2a20847357cb8b8ea1ad15596d6aca5d2f..dfa3594b104bb2642c1d34d3e425a7c8adc94298 100644 (file)
@@ -193,18 +193,18 @@ class ValueObject(Obj):
                        instant = Variant(instant)
                self.instant = instant
        
-       def _parseStatement(self, statement):
+       def _parseStatement(self, statement, custom_classes = None):
                from SmartAPI.rdf.Resource import Resource
                from SmartAPI.model.TemporalContext import TemporalContext
-       
-               self.parse_property(statement, PROPERTY.QUANTITYKIND, self.setQuantity, Variant)
-               self.parse_property(statement, PROPERTY.UNIT, self.setUnit, Variant)
-               self.parse_property(statement, PROPERTY.SECONDARYQUANTITYKIND, self.setSecondaryQuantity, Variant)
-               self.parse_property(statement, PROPERTY.SECONDARYUNIT, self.setSecondaryUnit, Variant)
-               self.parse_property(statement, PROPERTY.DATATYPE, self.setDataType, Variant)
-               self.parse_property(statement, PROPERTY.RDF_VALUE, self.setValue, Variant)
-               self.parse_property(statement, PROPERTY.MAXIMUM, self.setMaximum, Variant)
-               self.parse_property(statement, PROPERTY.MINIMUM, self.setMinimum, Variant)
-               self.parse_property(statement, PROPERTY.INSTANT, self.setInstant, Variant)
-               self.parse_property(statement, PROPERTY.TEMPORALCONTEXT, self.setTemporalContext, TemporalContext)
-               super(ValueObject, self)._parseStatement(statement)
+               
+               self.parse_property(statement, PROPERTY.QUANTITYKIND, self.setQuantity, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.UNIT, self.setUnit, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.SECONDARYQUANTITYKIND, self.setSecondaryQuantity, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.SECONDARYUNIT, self.setSecondaryUnit, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.DATATYPE, self.setDataType, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.RDF_VALUE, self.setValue, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.MAXIMUM, self.setMaximum, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.MINIMUM, self.setMinimum, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.INSTANT, self.setInstant, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.TEMPORALCONTEXT, self.setTemporalContext, TemporalContext, custom_classes = custom_classes)
+               super(ValueObject, self)._parseStatement(statement, custom_classes = custom_classes)
index ae97a00933df392fb202a3e9637684170f118c7e..9a7757975107622e1afa986cfe8096fa1a02ebea 100644 (file)
@@ -80,16 +80,16 @@ class Velocity(Obj):
        def getGroundSpeed(self):
                return self.groundSpeed
        
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.ANGULARVELOCITYX, self.setAngularVelocityX, ValueObject)
-               self.parse_property(statement, PROPERTY.ANGULARVELOCITYY, self.setAngularVelocityX, ValueObject)
-               self.parse_property(statement, PROPERTY.ANGULARVELOCITYZ, self.setAngularVelocityZ, ValueObject)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.ANGULARVELOCITYX, self.setAngularVelocityX, ValueObject, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.ANGULARVELOCITYY, self.setAngularVelocityX, ValueObject, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.ANGULARVELOCITYZ, self.setAngularVelocityZ, ValueObject, custom_classes = custom_classes)
                
-               self.parse_property(statement, PROPERTY.LINEARVELOCITYX, self.setLinearVelocityX, ValueObject)
-               self.parse_property(statement, PROPERTY.LINEARVELOCITYY, self.setLinearVelocityY, ValueObject)
-               self.parse_property(statement, PROPERTY.LINEARVELOCITYZ, self.setLinearVelocityZ, ValueObject)
+               self.parse_property(statement, PROPERTY.LINEARVELOCITYX, self.setLinearVelocityX, ValueObject, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.LINEARVELOCITYY, self.setLinearVelocityY, ValueObject, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.LINEARVELOCITYZ, self.setLinearVelocityZ, ValueObject, custom_classes = custom_classes)
                
-               self.parse_property(statement, PROPERTY.GROUNDSPEED, self.setGroundSpeed, ValueObject)
+               self.parse_property(statement, PROPERTY.GROUNDSPEED, self.setGroundSpeed, ValueObject, custom_classes = custom_classes)
                
-               super(Velocity, self)._parseStatement(statement)
+               super(Velocity, self)._parseStatement(statement, custom_classes = custom_classes)
        
index 34be309fa7d37db66de058750816f49435862d5d..91709f13f1e4fb4cf7dd590e4552a02b135c564d 100644 (file)
@@ -57,10 +57,10 @@ class Waypoint(Obj):
        def setRoute(self, route):
                self.route = route
        
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.LOCATION, self.setLocation, Coordinates)
-               self.parse_property(statement, PROPERTY.HASADDRESS, self.setAddress, Address)
-               self.parse_property(statement, PROPERTY.INSTANT, self.setInstant, Variant)
-               self.parse_property(statement, PROPERTY.ROUTE, self.setRoute, Route)
-               super(Waypoint, self)._parseStatement(statement)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.LOCATION, self.setLocation, Coordinates, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.HASADDRESS, self.setAddress, Address, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.INSTANT, self.setInstant, Variant, custom_classes = custom_classes)
+               self.parse_property(statement, PROPERTY.ROUTE, self.setRoute, Route, custom_classes = custom_classes)
+               super(Waypoint, self)._parseStatement(statement, custom_classes = custom_classes)
                
index e32dac803a8de384da38bae1ad5b07a4dd64a79d..09fe23e7947b81d26f13a5f82effe8c9d811d382 100644 (file)
@@ -29,7 +29,7 @@ class Waypoints(Obj):
        def addWaypoint(self, wp):
                self.waypoints.append(wp)
        
-       def _parseStatement(self, statement):
-               self.parse_propertylist(statement, PROPERTY.LIST, self.setWaypoints, Waypoint)
-               super(Waypoints, self)._parseStatement(statement)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_propertylist(statement, PROPERTY.LIST, self.setWaypoints, Waypoint, custom_classes = custom_classes)
+               super(Waypoints, self)._parseStatement(statement, custom_classes = custom_classes)
 
index dea37ec0e8d0b5432753dd6fcd9d93c2ea9a9d1c..9dfc1e6abf30fd87e22b09df90edf04335a86beb 100644 (file)
@@ -12,7 +12,7 @@ class Zone(Obj):
 
        def __init__(self, uri = None):
                Obj.__init__(self, uri)
-               self.init_property(PROPERTY.ZONENUMBER, 'zoneNumber', self.hasZoneNumber, self.getZoneNumber)           
+               self.init_property(PROPERTY.ZONENUMBER, 'zoneNumber', self.hasZoneNumber, self.getZoneNumber)
                self.setType(RESOURCE.ZONE)
 
        def hasZoneNumber(self):
@@ -26,7 +26,7 @@ class Zone(Obj):
                        zoneNumber = Variant(zoneNumber)
                self.zoneNumber = zoneNumber
                
-       def _parseStatement(self, statement):
-               self.parse_property(statement, PROPERTY.ZONENUMBER, self.setZoneNumber, Variant)                
-               super(Zone, self)._parseStatement(statement)
+       def _parseStatement(self, statement, custom_classes = None):
+               self.parse_property(statement, PROPERTY.ZONENUMBER, self.setZoneNumber, Variant, custom_classes = custom_classes)
+               super(Zone, self)._parseStatement(statement, custom_classes = custom_classes)
 
index d5d5678791ed30661d5fe18c95bf10e25eaecc81..83da47341dd6eb862639989a356bb2f8f0265c82 100644 (file)
@@ -38,22 +38,22 @@ class Variant(object):
                        return Literal(self.variant)
 
        @classmethod
-       def parse(cls, element):
+       def parse(cls, element, custom_classes = None):
                # get predicate and object
                if isinstance(element, Resource):
                        if element.isLiteral():
                                return cls.parse(element.getNode())
                        else:
-                               klass = Tools().getResourceClass(element, default = Obj)
+                               klass = Tools().getResourceClass(element, default = Obj, custom_classes = custom_classes)
                                if klass is not None:
-                                       v = klass().parse(element)
+                                       v = klass().parse(element, custom_classes = custom_classes)
                                else:
                                        # None found, resort to Variant
                                        v = cls()
                                        propsNum = 0
                                        for stmt in element.findProperties():
                                                propsNum = propsNum + 1
-                                               v.parse(stmt)
+                                               v.parse(stmt, custom_classes = custom_classes)
                                        if (propsNum == 0):
                                                v = Variant(URIRef(element.getNode().toPython()))
                                return v
@@ -70,12 +70,12 @@ class Variant(object):
                        
                        elif (element.getResource() is not None):
                                resource = element.getResource()
-                               klass = Tools().getResourceClass(resource, default = Obj)
+                               klass = Tools().getResourceClass(resource, default = Obj, custom_classes = custom_classes)
                                if klass is not None:
-                                       v = klass().parse(resource)
+                                       v = klass().parse(resource, custom_classes = custom_classes)
                                else:
                                        # None found, resort to Obj (the base class)
-                                       v = Obj().parse(resource)
+                                       v = Obj().parse(resource, custom_classes = custom_classes)
                                
                                return v