 Timestamp:
 28/03/07 14:54:39 (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

TI02CSML/trunk/csml/parser.py
r2341 r2343 57 57 if hasattr(obj, 'ELEMORDER'): 58 58 for elem in elems: 59 obj.ELEMORDER.append(elem s)59 obj.ELEMORDER.append(elem) 60 60 else: 61 61 obj.ELEMORDER=elems … … 75 75 if not hasattr(self, 'ATTRIBUTES'): 76 76 self.__dict__['ATTRIBUTES']=[] 77 78 77 if not hasattr(self, 'ELEMORDER'): 78 self.__dict__['ELEMORDER']=[] 79 if not hasattr(self, 'CHILDREN'): 80 self.__dict__['CHILDREN']={} 79 81 #The __setattr__ and __getattribute__ special methods have been overridden. 80 82 #This is so that attributes can be called by their fully qualified name internally … … 166 168 csmlfrag.set(GML(item), self.__dict__[item]) 167 169 # self.CHILDREN (recursive  calls the toXML method of children 168 for att in self.__dict__: 169 if att not in ['ATTRIBUTES', 'CHILDREN', 'CONTENT','ELEMORDER']: 170 for child in self.ELEMORDER: 171 appendLater=False 172 if child == att: 173 parserobjects=[] 174 if type(self.__dict__[att]) is list: 175 for a in self.__dict__[att]: 176 parserobjects.append(a) 177 else: 178 parserobjects.append(self.__dict__[att]) 179 parentfrag=None 180 if len(self.CHILDREN[child])>=3: 181 ename2=self.CHILDREN[child][2] 182 parentfrag=ET.Element(ename2) 183 for po in parserobjects: 184 if type(self.CHILDREN[child][0]) is not list: 185 ename=self.CHILDREN[child][0] 186 else: 187 ename = self._getReverseSubsType(type(po).__name__) 188 if len(self.CHILDREN[child])==3: 189 frag=ET.Element(ename) 190 po.toXML(frag) 191 parentfrag.append(frag) 192 appendLater=True 193 elif len(self.CHILDREN[child])>=4: 194 if self.CHILDREN[child][3]==1: 195 frag=ET.Element(ename) 196 po.toXML(frag) 197 parentfrag.append(frag) 198 csmlfrag.append(parentfrag) 199 parentfrag=ET.Element(parentfrag.tag) 200 appendLater=False 201 else: 202 frag=ET.Element(ename) 203 try: 204 po.toXML(frag) 205 except: 206 print 'PARSING ERROR  could not convert %s to XML'%frag 207 print dir(ename) 208 raise 209 csmlfrag.append(frag) 210 appendLater=True 211 if appendLater==True and parentfrag != None: 212 csmlfrag.append(parentfrag) 170 for child in self.ELEMORDER: 171 if not self.__dict__.has_key(child): 172 continue 173 appendLater=False 174 parserobjects=[] 175 if type(self.__dict__[child]) is list: 176 for a in self.__dict__[child]: 177 parserobjects.append(a) 178 else: 179 parserobjects.append(self.__dict__[child]) 180 parentfrag=None 181 if len(self.CHILDREN[child])>=3: 182 ename2=self.CHILDREN[child][2] 183 parentfrag=ET.Element(ename2) 184 for po in parserobjects: 185 if type(self.CHILDREN[child][0]) is not list: 186 ename=self.CHILDREN[child][0] 187 else: 188 ename = self._getReverseSubsType(type(po).__name__) 189 if len(self.CHILDREN[child])==3: 190 frag=ET.Element(ename) 191 po.toXML(frag) 192 parentfrag.append(frag) 193 appendLater=True 194 elif len(self.CHILDREN[child])>=4: 195 if self.CHILDREN[child][3]==1: 196 frag=ET.Element(ename) 197 po.toXML(frag) 198 parentfrag.append(frag) 199 csmlfrag.append(parentfrag) 200 parentfrag=ET.Element(parentfrag.tag) 201 appendLater=False 202 else: 203 frag=ET.Element(ename) 204 try: 205 po.toXML(frag) 206 except: 207 print 'PARSING ERROR  could not convert %s to XML'%frag 208 print dir(ename) 209 raise 210 csmlfrag.append(frag) 211 appendLater=True 212 if appendLater==True and parentfrag != None: 213 csmlfrag.append(parentfrag) 213 214 return csmlfrag 214 215 … … 288 289 elems=['metaDataProperty', 'description'] 289 290 addelems(self,elems) 290 csElement.__init__(self,**kwargs)291 291 children={elems[0]:[GML('metaDataProperty'),'csString'],elems[1]:[GML('description'),'csString']} 292 292 addchildren(self,children) 293 csElement.__init__(self,**kwargs) 293 294 294 295 class AssociationAttributeGroup(csElement): … … 301 302 def __init__(self, text=None,**kwargs): 302 303 #Needed so it can use xlink 304 addelems(self,[]) 303 305 AssociationAttributeGroup.__init__(self,**kwargs) 304 306 if text != None: … … 318 320 class SRSInformationGroup(csElement): 319 321 def __init__(self, **kwargs): 320 a =['uomLabels','axisLabels'] 322 a =['uomLabels','axisLabels'] 321 323 addatts(self,a) 322 324 csElement.__init__(self,**kwargs) … … 324 326 class ArrayDescriptor(AbstractGML, csElement): 325 327 def __init__(self,**kwargs): 328 AbstractGML.__init__(self,**kwargs) 326 329 elems=['arraySize', 'uom', 'numericType','regExpTransform','numericTransform'] 327 330 addelems(self,elems) 328 AbstractGML.__init__(self,**kwargs)329 331 children={elems[0]:[CSML('arraySize'), 'csString'], elems[1]:[CSML('uom'),'csString'], elems[2]:[CSML('numericType'),'csString'], elems[3]:[CSML('regExpTransform'),'csString'], elems[4]:[CSML('numericTransform'),'csString']} 330 332 addchildren(self,children) … … 333 335 class GridEnvelope(AbstractGML,SRSReferenceGroup, csElement): 334 336 def __init__(self, **kwargs): 337 SRSReferenceGroup.__init__(self,**kwargs) 338 AbstractGML.__init__(self,**kwargs) 335 339 elems=['low', 'high'] 336 340 addelems(self,elems) 341 children={elems[0]:[GML('low'), 'csString'],elems[1]:[GML('high'), 'csString']} 342 addchildren(self,children) 343 csElement.__init__(self,**kwargs) 344 345 class Envelope(AbstractGML,SRSReferenceGroup, csElement): 346 def __init__(self, **kwargs): 337 347 SRSReferenceGroup.__init__(self,**kwargs) 338 348 AbstractGML.__init__(self,**kwargs) 339 children={elems[0]:[GML('low'), 'csString'],elems[1]:[GML('high'), 'csString']}340 addchildren(self,children)341 csElement.__init__(self,**kwargs)342 343 class Envelope(AbstractGML,SRSReferenceGroup, csElement):344 def __init__(self, **kwargs):345 349 elems=['lowerCorner','upperCorner'] 346 350 addelems(self,elems) 347 SRSReferenceGroup.__init__(self,**kwargs)348 AbstractGML.__init__(self,**kwargs)349 351 children={elems[0]:[GML('lowerCorner'), 'csString'],elems[1]:[GML('upperCorner'), 'csString']} 350 352 addchildren(self,children) … … 362 364 class AbstractFeature(AbstractGML,csElement): 363 365 def __init__(self, **kwargs): 366 AbstractGML.__init__(self,**kwargs) 364 367 elems=['boundedBy'] 365 368 addelems(self,elems) 366 AbstractGML.__init__(self,**kwargs)367 369 #this pattern works but can only accept EnvelopeWithTimePeriod for the boundedBy, 368 370 #which is probably ok … … 384 386 class AggregatedArray(ArrayDescriptor,csElement): 385 387 def __init__(self, **kwargs): 388 ArrayDescriptor.__init__(self,**kwargs) 386 389 elems=['aggType', 'aggIndex', 'components'] 387 390 addelems(self,elems) 388 ArrayDescriptor.__init__(self,**kwargs)389 391 children={elems[0]:[CSML('aggType'),'csString'], elems[1]:[CSML('aggIndex'),'csString'],elems[2]:[FILEFORMATS, 'ArrayDescriptor',CSML('component')]} 390 392 addchildren(self,children) … … 393 395 class MeasureOrNullList(AbstractGML,csElement): 394 396 def __init__(self, **kwargs): 397 AbstractGML.__init__(self,**kwargs) 395 398 elems=['__insertedExtract'] # should this be here ? check 396 399 addelems(self,elems) 397 AbstractGML.__init__(self,**kwargs)398 400 #note __insertedExtract is used in resolving xlinks and shouldn't be written to directly (except by the code which handles the xlink resolutions) 399 401 children={elems[0]:[FILEFORMATS,'FileExtract',CSML('__insertedExtract')]} … … 406 408 class CompositeValue(AbstractGML,csElement): 407 409 def __init__(self, **kwargs): 410 AbstractGML.__init__(self,**kwargs) 408 411 elems=['measures'] 409 412 addelems(self,elems) 410 AbstractGML.__init__(self,**kwargs)411 413 children={elems[0]:[GML('measure'),'csString',GML('valueComponents')]} 412 414 addchildren(self,children) … … 416 418 #THIS IS INCOMPLETE 417 419 def __init__(self, **kwargs): 420 AbstractGML.__init__(self,**kwargs) 418 421 elems=['doubleOrNullTupleList','rangeParameters'] 419 422 addelems(self,elems) 420 AbstractGML.__init__(self,**kwargs)421 423 children={elems[0]:[GML('doubleOrNullTupleList'),'csString'],elems[1]:[GML('CompositeValue'), 'CompositeValue', GML('rangeParameters')]} 422 424 addchildren(self,children) … … 425 427 class ValueComponent(AbstractGML, AssociationAttributeGroup, csElement): 426 428 def __init__(self, **kwargs): 429 AbstractGML.__init__(self,**kwargs) 430 AssociationAttributeGroup.__init__(self,**kwargs) 427 431 elems=['quantityList'] 428 432 addelems(self,elems) 429 AbstractGML.__init__(self,**kwargs)430 AssociationAttributeGroup.__init__(self,**kwargs)431 433 children=children={elems[0]:[GML('QuantityList'), 'MeasureOrNullList']} 432 434 addchildren(self,children) … … 435 437 class ValueArray(AbstractGML, csElement): 436 438 def __init__(self, **kwargs): 439 AbstractGML.__init__(self,**kwargs) 437 440 elems=['valueComponent'] 438 441 addelems(self,elems) 439 AbstractGML.__init__(self,**kwargs)440 442 #this is a bit of a diversion from the object/property pattern but is necessary to 441 443 #make valueComponent a class so valueComponent can have xlink attributes … … 733 735 class GridSeriesCoverage(AbstractDiscreteCoverage,csElement): 734 736 def __init__(self, **kwargs): 737 elems=['gridSeriesDomain', 'rangeSet', 'coverageFunction'] 738 addelems(self,elems) 739 children={elems[0]:[CSML('GridSeriesDomain'),'GridSeriesDomain' ,CSML('gridSeriesDomain') ], elems[1]:[GML('rangeSet'), 'RangeSet'],elems[2]:[GML('coverageFunction'),'csString']} 740 addchildren(self,children) 735 741 AbstractDiscreteCoverage.__init__(self,**kwargs) 736 elems=['gridSeriesDomain', 'rangeSet', 'coverageFunction']737 addelems(self,elems)738 children={elems[0]:[CSML('GridSeriesDomain'),'GridSeriesDomain' ,CSML('gridSeriesDomain') ], elems[1]:[GML('rangeSet'), 'RangeSet'],elems[2]:[GML('coverageFunction'),'csString']}739 addchildren(self,children)740 742 csElement.__init__(self,**kwargs) 741 743 … … 796 798 class GridSeriesFeature(AbstractFeature, csElement): 797 799 def __init__(self, **kwargs): 798 AbstractFeature.__init__(self,**kwargs)799 800 elems=['value','parameter'] 800 801 addelems(self,elems) 801 children={elems[0]:[CSML('GridSeriesCoverage'), 'GridSeriesCoverage', CSML('value')],elems[0]:[CSML('parameter'), 'Phenomenon']} 802 addchildren(self,children) 802 children={elems[0]:[CSML('GridSeriesCoverage'), 'GridSeriesCoverage', CSML('value')],elems[1]:[CSML('parameter'), 'Phenomenon']} 803 addchildren(self,children) 804 AbstractFeature.__init__(self,**kwargs) 803 805 csElement.__init__(self,**kwargs) 804 806 … … 878 880 class FileList(AssociationAttributeGroup,AbstractGML,csElement): 879 881 def __init__(self,**kwargs): 882 elems=['fileNames'] 883 addelems(self,elems) 880 884 AssociationAttributeGroup.__init__(self,**kwargs) 881 885 AbstractGML.__init__(self,**kwargs) 882 elems=['fileNames']883 addelems(self,elems)884 886 addatts(self,[]) 885 887 children= {elems[0]:[CSML('fileNames'), 'csString']} … … 990 992 a=[CSML('id')] 991 993 addatts(self,a) 992 elems=[' featureCollection','storageDescriptor']993 addelems(self,elems) 994 children = {elems[ 0]:[CSML('CSMLFeatureCollection') ,'CSMLFeatureCollection'],elems[1]:[CSML('CSMLStorageDescriptor'), 'CSMLStorageDescriptor']}994 elems=['storageDescriptor','featureCollection',] 995 addelems(self,elems) 996 children = {elems[1]:[CSML('CSMLFeatureCollection') ,'CSMLFeatureCollection'],elems[0]:[CSML('CSMLStorageDescriptor'), 'CSMLStorageDescriptor']} 995 997 addchildren(self,children) 996 998 csElement.__init__(self,**kwargs) … … 1025 1027 ds.fromXML(tree.getroot()) 1026 1028 csmltree=ds.toXML() 1027 #print csmltree1028 1029 1029 1030 csmlout=parser_extra.PrettyPrint(csmltree)
Note: See TracChangeset
for help on using the changeset viewer.