Ignore:
Timestamp:
08/05/06 11:44:45 (14 years ago)
Author:
domlowe
Message:

Added some checking for mandatory csml elements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI02-CSML/trunk/newparser/Parser.py

    r888 r896  
    7676def checkMandatory(obj,*args): 
    7777    #check mandatory attributes/elements are present. 
    78     #should be called at the *end* of each fromXML method 
     78    #should be called at the *end* of each fromXML method if that object has mandatory attributes 
    7979    for arg in args: 
    8080        if not hasattr(obj, arg): 
     
    286286    def fromXML(self,csmlFrag): 
    287287        AbstractGML.fromXML(self,csmlFrag) 
    288         #TO DO: how  best to handle errors? 
     288        #checkMandatory(self, 'id') 
    289289        if not hasattr(self,'id'): 
    290290            #print 'gml:id mandatory value missing in ' + csmlFrag.tag 
     291            #how best to handle the case where there is an xlink to the definition, 
     292            #so the reference to the definition object doesn't actually have an id 
    291293            pass 
    292294    def toXML(self,csmlFrag): 
     
    338340        if csmlFrag.attrib.has_key('factor'): 
    339341            self.factor=csmlFrag.attrib['factor'] 
     342        checkMandatory(self,'unit') 
    340343    def toXML(self,csmlFrag): 
    341344        csmlFrag.text=self.data 
     
    905908            if frag.tag==GML('axisDirection'): 
    906909                self.axisDirection=frag.text 
     910            checkMandatory(self,'uom') 
    907911    def toXML(self,csmlFrag): 
    908912        CoordinateSystemAxisBase.toXML(self,csmlFrag) 
     
    982986                self.usesAxes.append(CoordinateSystemAxis()) 
    983987                self.usesAxes[-1].fromXML(frag.getchildren()[0]) 
    984  
     988        checkMandatory(self,'usesAxes') 
    985989    def toXML(self,csmlFrag): 
    986990        AbstractCoordinateSystemBase.toXML(self, csmlFrag) 
     
    13191323                    definitionMember.fromXML(subFrag) 
    13201324                    self.definitionMembers.append(definitionMember) 
     1325        checkMandatory(self,'definitionMembers') 
    13211326    def toXML(self,csmlFrag): 
    13221327        Definition.toXML(self,csmlFrag) 
     
    14211426            elif frag.tag == CSML('numericTransform'): 
    14221427                self.numericTransform = frag.text 
     1428        checkMandatory(self,'arraySize') 
    14231429    def toXML(self,csmlFrag): 
    14241430        csmlFrag = AbstractGML.toXML(self,csmlFrag) 
     
    19691975        if csmlFrag.attrib.has_key('uom'): 
    19701976            self.uom = csmlFrag.attrib['uom'] 
     1977        checkMandatory(self,'uom') 
    19711978    def toXML(self, csmlFrag): 
    19721979        if hasattr(self,'vals'): 
Note: See TracChangeset for help on using the changeset viewer.