/FSKit/Source/Common/enunciate/dev/temple.m
Objective C | 1195 lines | 820 code | 163 blank | 212 comment | 124 complexity | 6fb29ac6c49836f997dcfe6c40c2db30 MD5 | raw file
Possible License(s): BSD-3-Clause
1#import "temple.h" 2 3 4/** 5 * A list of temples. 6 7 @author Rob Lyon 8 9 */ 10@implementation FSTEMPLEV1Temples 11 12/** 13 * the number of temples. 14 */ 15- (int) count 16{ 17 return _count; 18} 19 20/** 21 * the number of temples. 22 */ 23- (void) setCount: (int) newCount 24{ 25 _count = newCount; 26} 27 28/** 29 * a list of temples. 30 */ 31- (NSArray *) templeItems 32{ 33 return _templeItems; 34} 35 36/** 37 * a list of temples. 38 */ 39- (void) setTempleItems: (NSArray *) newTempleItems 40{ 41 [newTempleItems retain]; 42 [_templeItems release]; 43 _templeItems = newTempleItems; 44} 45 46- (void) dealloc 47{ 48 [self setTempleItems: nil]; 49 [super dealloc]; 50} 51@end /* implementation FSTEMPLEV1Temples */ 52 53/** 54 * Internal, private interface for JAXB reading and writing. 55 */ 56@interface FSTEMPLEV1Temples (JAXB) <JAXBReading, JAXBWriting, JAXBType> 57 58@end /*interface FSTEMPLEV1Temples (JAXB)*/ 59 60/** 61 * Internal, private implementation for JAXB reading and writing. 62 */ 63@implementation FSTEMPLEV1Temples (JAXB) 64 65/** 66 * Read an instance of FSTEMPLEV1Temples from an XML reader. 67 * 68 * @param reader The reader. 69 * @return An instance of FSTEMPLEV1Temples defined by the XML reader. 70 */ 71+ (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader 72{ 73 FSTEMPLEV1Temples *_fSTEMPLEV1Temples = [[FSTEMPLEV1Temples alloc] init]; 74 NS_DURING 75 { 76 [_fSTEMPLEV1Temples initWithReader: reader]; 77 } 78 NS_HANDLER 79 { 80 [_fSTEMPLEV1Temples dealloc]; 81 _fSTEMPLEV1Temples = nil; 82 [localException raise]; 83 } 84 NS_ENDHANDLER 85 86 [_fSTEMPLEV1Temples autorelease]; 87 return _fSTEMPLEV1Temples; 88} 89 90/** 91 * Initialize this instance of FSTEMPLEV1Temples according to 92 * the XML being read from the reader. 93 * 94 * @param reader The reader. 95 */ 96- (id) initWithReader: (xmlTextReaderPtr) reader 97{ 98 return [super initWithReader: reader]; 99} 100 101/** 102 * Write the XML for this instance of FSTEMPLEV1Temples to the writer. 103 * Note that since we're only writing the XML type, 104 * No start/end element will be written. 105 * 106 * @param reader The reader. 107 */ 108- (void) writeXMLType: (xmlTextWriterPtr) writer 109{ 110 [super writeXMLType:writer]; 111} 112 113//documentation inherited. 114- (BOOL) readJAXBAttribute: (xmlTextReaderPtr) reader 115{ 116 void *_child_accessor; 117 118 if ([super readJAXBAttribute: reader]) { 119 return YES; 120 } 121 122 if ((xmlStrcmp(BAD_CAST "count", xmlTextReaderConstLocalName(reader)) == 0) && (xmlTextReaderConstNamespaceUri(reader) == NULL)) { 123#if DEBUG_ENUNCIATE > 1 124 NSLog(@"Attempting to read attribute {}count..."); 125#endif 126 _child_accessor = xmlTextReaderReadIntType(reader); 127 if (_child_accessor == NULL) { 128 //panic: unable to read the attribute value for some reason. 129 [self dealloc]; 130 [NSException raise: @"XMLReadError" 131 format: @"Error reading attribute {}count."]; 132 } 133 [self setCount: *((int*) _child_accessor)]; 134 free(_child_accessor); 135#if DEBUG_ENUNCIATE > 1 136 NSLog(@"successfully read attribute {}count..."); 137#endif 138 return YES; 139 } 140 141 return NO; 142} 143 144//documentation inherited. 145- (BOOL) readJAXBValue: (xmlTextReaderPtr) reader 146{ 147 return [super readJAXBValue: reader]; 148} 149 150//documentation inherited. 151- (BOOL) readJAXBChildElement: (xmlTextReaderPtr) reader 152{ 153 id __child; 154 void *_child_accessor; 155 int status, depth; 156 157 if ([super readJAXBChildElement: reader]) { 158 return YES; 159 } 160 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT 161 && xmlStrcmp(BAD_CAST "temple", xmlTextReaderConstLocalName(reader)) == 0 162 && xmlStrcmp(BAD_CAST "http://api.familysearch.org/temple/v1", xmlTextReaderConstNamespaceUri(reader)) == 0) { 163 164#if DEBUG_ENUNCIATE > 1 165 NSLog(@"Attempting to read choice {http://api.familysearch.org/temple/v1}temple of type {http://api.familysearch.org/temple/v1}temple."); 166#endif 167 168 __child = [FSTEMPLEV1Temple readXMLType: reader]; 169#if DEBUG_ENUNCIATE > 1 170 NSLog(@"successfully read choice {http://api.familysearch.org/temple/v1}temple of type {http://api.familysearch.org/temple/v1}temple."); 171#endif 172 173 if ([self templeItems]) { 174 [self setTempleItems: [[self templeItems] arrayByAddingObject: __child]]; 175 } 176 else { 177 [self setTempleItems: [NSArray arrayWithObject: __child]]; 178 } 179 return YES; 180 } //end "if choice" 181 182 183 return NO; 184} 185 186//documentation inherited. 187- (int) readUnknownJAXBChildElement: (xmlTextReaderPtr) reader 188{ 189 return [super readUnknownJAXBChildElement: reader]; 190} 191 192//documentation inherited. 193- (void) readUnknownJAXBAttribute: (xmlTextReaderPtr) reader 194{ 195 [super readUnknownJAXBAttribute: reader]; 196} 197 198//documentation inherited. 199- (void) writeJAXBAttributes: (xmlTextWriterPtr) writer 200{ 201 int status; 202 203 [super writeJAXBAttributes: writer]; 204 205 if (YES) { //always write the primitive attributes... 206 207 status = xmlTextWriterStartAttributeNS(writer, NULL, BAD_CAST "count", NULL); 208 if (status < 0) { 209 [NSException raise: @"XMLWriteError" 210 format: @"Error writing start attribute {}count."]; 211 } 212 213#if DEBUG_ENUNCIATE > 1 214 NSLog(@"writing attribute {}count..."); 215#endif 216 status = xmlTextWriterWriteIntType(writer, &_count); 217 if (status < 0) { 218 [NSException raise: @"XMLWriteError" 219 format: @"Error writing attribute {}count."]; 220 } 221#if DEBUG_ENUNCIATE > 1 222 NSLog(@"successfully wrote attribute {}count..."); 223#endif 224 225 status = xmlTextWriterEndAttribute(writer); 226 if (status < 0) { 227 [NSException raise: @"XMLWriteError" 228 format: @"Error writing end attribute {}count."]; 229 } 230 } 231} 232 233//documentation inherited. 234- (void) writeJAXBValue: (xmlTextWriterPtr) writer 235{ 236 [super writeJAXBValue: writer]; 237} 238 239/** 240 * Method for writing the child elements. 241 * 242 * @param writer The writer. 243 */ 244- (void) writeJAXBChildElements: (xmlTextWriterPtr) writer 245{ 246 int status; 247 id __item; 248 NSEnumerator *__enumerator; 249 250 [super writeJAXBChildElements: writer]; 251 252 if ([self templeItems]) { 253 __enumerator = [[self templeItems] objectEnumerator]; 254 255 while ( (__item = [__enumerator nextObject]) ) { 256 status = xmlTextWriterStartElementNS(writer, BAD_CAST "temple_v1", BAD_CAST "temple", NULL); 257 if (status < 0) { 258 [NSException raise: @"XMLWriteError" 259 format: @"Error writing start child element {http://api.familysearch.org/temple/v1}temple."]; 260 } 261 262#if DEBUG_ENUNCIATE > 1 263 NSLog(@"writing element {http://api.familysearch.org/temple/v1}temple..."); 264#endif 265 [__item writeXMLType: writer]; 266#if DEBUG_ENUNCIATE > 1 267 NSLog(@"successfully wrote element {http://api.familysearch.org/temple/v1}temple..."); 268#endif 269 270 status = xmlTextWriterEndElement(writer); 271 if (status < 0) { 272 [NSException raise: @"XMLWriteError" 273 format: @"Error writing end child element {http://api.familysearch.org/temple/v1}temple."]; 274 } 275 } //end item iterator. 276 } 277} 278@end /* implementation FSTEMPLEV1Temples (JAXB) */ 279 280/** 281 * A temple. 282 283 @author Rob Lyon 284 285 */ 286@implementation FSTEMPLEV1Temple 287 288/** 289 * the code of the temple. 290 */ 291- (NSString *) code 292{ 293 return _code; 294} 295 296/** 297 * the code of the temple. 298 */ 299- (void) setCode: (NSString *) newCode 300{ 301 [newCode retain]; 302 [_code release]; 303 _code = newCode; 304} 305 306/** 307 * the old code of the temple. 308 */ 309- (NSString *) oldCode 310{ 311 return _oldCode; 312} 313 314/** 315 * the old code of the temple. 316 */ 317- (void) setOldCode: (NSString *) newOldCode 318{ 319 [newOldCode retain]; 320 [_oldCode release]; 321 _oldCode = newOldCode; 322} 323 324/** 325 * the requested code of the temple. 326 */ 327- (NSString *) requestedCode 328{ 329 return _requestedCode; 330} 331 332/** 333 * the requested code of the temple. 334 */ 335- (void) setRequestedCode: (NSString *) newRequestedCode 336{ 337 [newRequestedCode retain]; 338 [_requestedCode release]; 339 _requestedCode = newRequestedCode; 340} 341 342/** 343 * the name of the temple. 344 */ 345- (NSString *) name 346{ 347 return _name; 348} 349 350/** 351 * the name of the temple. 352 */ 353- (void) setName: (NSString *) newName 354{ 355 [newName retain]; 356 [_name release]; 357 _name = newName; 358} 359 360/** 361 * the district of the temple. 362 */ 363- (long *) district 364{ 365 return _district; 366} 367 368/** 369 * the district of the temple. 370 */ 371- (void) setDistrict: (long *) newDistrict 372{ 373 if (_district != NULL) { 374 free(_district); 375 } 376 _district = newDistrict; 377} 378 379/** 380 * the location of the temple. 381 */ 382- (NSString *) location 383{ 384 return _location; 385} 386 387/** 388 * the location of the temple. 389 */ 390- (void) setLocation: (NSString *) newLocation 391{ 392 [newLocation retain]; 393 [_location release]; 394 _location = newLocation; 395} 396 397/** 398 * the dedication date of the temple. 399 */ 400- (NSString *) dedicationDate 401{ 402 return _dedicationDate; 403} 404 405/** 406 * the dedication date of the temple. 407 */ 408- (void) setDedicationDate: (NSString *) newDedicationDate 409{ 410 [newDedicationDate retain]; 411 [_dedicationDate release]; 412 _dedicationDate = newDedicationDate; 413} 414 415- (void) dealloc 416{ 417 [self setCode: nil]; 418 [self setOldCode: nil]; 419 [self setRequestedCode: nil]; 420 [self setName: nil]; 421 [self setDistrict: NULL]; 422 [self setLocation: nil]; 423 [self setDedicationDate: nil]; 424 [super dealloc]; 425} 426@end /* implementation FSTEMPLEV1Temple */ 427 428/** 429 * Internal, private interface for JAXB reading and writing. 430 */ 431@interface FSTEMPLEV1Temple (JAXB) <JAXBReading, JAXBWriting, JAXBType> 432 433@end /*interface FSTEMPLEV1Temple (JAXB)*/ 434 435/** 436 * Internal, private implementation for JAXB reading and writing. 437 */ 438@implementation FSTEMPLEV1Temple (JAXB) 439 440/** 441 * Read an instance of FSTEMPLEV1Temple from an XML reader. 442 * 443 * @param reader The reader. 444 * @return An instance of FSTEMPLEV1Temple defined by the XML reader. 445 */ 446+ (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader 447{ 448 FSTEMPLEV1Temple *_fSTEMPLEV1Temple = [[FSTEMPLEV1Temple alloc] init]; 449 NS_DURING 450 { 451 [_fSTEMPLEV1Temple initWithReader: reader]; 452 } 453 NS_HANDLER 454 { 455 [_fSTEMPLEV1Temple dealloc]; 456 _fSTEMPLEV1Temple = nil; 457 [localException raise]; 458 } 459 NS_ENDHANDLER 460 461 [_fSTEMPLEV1Temple autorelease]; 462 return _fSTEMPLEV1Temple; 463} 464 465/** 466 * Initialize this instance of FSTEMPLEV1Temple according to 467 * the XML being read from the reader. 468 * 469 * @param reader The reader. 470 */ 471- (id) initWithReader: (xmlTextReaderPtr) reader 472{ 473 return [super initWithReader: reader]; 474} 475 476/** 477 * Write the XML for this instance of FSTEMPLEV1Temple to the writer. 478 * Note that since we're only writing the XML type, 479 * No start/end element will be written. 480 * 481 * @param reader The reader. 482 */ 483- (void) writeXMLType: (xmlTextWriterPtr) writer 484{ 485 [super writeXMLType:writer]; 486} 487 488//documentation inherited. 489- (BOOL) readJAXBAttribute: (xmlTextReaderPtr) reader 490{ 491 void *_child_accessor; 492 493 if ([super readJAXBAttribute: reader]) { 494 return YES; 495 } 496 497 if ((xmlStrcmp(BAD_CAST "code", xmlTextReaderConstLocalName(reader)) == 0) && (xmlTextReaderConstNamespaceUri(reader) == NULL)) { 498#if DEBUG_ENUNCIATE > 1 499 NSLog(@"Attempting to read attribute {}code..."); 500#endif 501 [self setCode: (NSString*) [NSString readXMLType: reader]]; 502#if DEBUG_ENUNCIATE > 1 503 NSLog(@"successfully read attribute {}code..."); 504#endif 505 return YES; 506 } 507 508 if ((xmlStrcmp(BAD_CAST "oldCode", xmlTextReaderConstLocalName(reader)) == 0) && (xmlTextReaderConstNamespaceUri(reader) == NULL)) { 509#if DEBUG_ENUNCIATE > 1 510 NSLog(@"Attempting to read attribute {}oldCode..."); 511#endif 512 [self setOldCode: (NSString*) [NSString readXMLType: reader]]; 513#if DEBUG_ENUNCIATE > 1 514 NSLog(@"successfully read attribute {}oldCode..."); 515#endif 516 return YES; 517 } 518 519 if ((xmlStrcmp(BAD_CAST "requestedCode", xmlTextReaderConstLocalName(reader)) == 0) && (xmlTextReaderConstNamespaceUri(reader) == NULL)) { 520#if DEBUG_ENUNCIATE > 1 521 NSLog(@"Attempting to read attribute {}requestedCode..."); 522#endif 523 [self setRequestedCode: (NSString*) [NSString readXMLType: reader]]; 524#if DEBUG_ENUNCIATE > 1 525 NSLog(@"successfully read attribute {}requestedCode..."); 526#endif 527 return YES; 528 } 529 530 return NO; 531} 532 533//documentation inherited. 534- (BOOL) readJAXBValue: (xmlTextReaderPtr) reader 535{ 536 return [super readJAXBValue: reader]; 537} 538 539//documentation inherited. 540- (BOOL) readJAXBChildElement: (xmlTextReaderPtr) reader 541{ 542 id __child; 543 void *_child_accessor; 544 int status, depth; 545 546 if ([super readJAXBChildElement: reader]) { 547 return YES; 548 } 549 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT 550 && xmlStrcmp(BAD_CAST "name", xmlTextReaderConstLocalName(reader)) == 0 551 && xmlStrcmp(BAD_CAST "http://api.familysearch.org/temple/v1", xmlTextReaderConstNamespaceUri(reader)) == 0) { 552 553#if DEBUG_ENUNCIATE > 1 554 NSLog(@"Attempting to read choice {http://api.familysearch.org/temple/v1}name of type {http://www.w3.org/2001/XMLSchema}string."); 555#endif 556 __child = [NSString readXMLType: reader]; 557#if DEBUG_ENUNCIATE > 1 558 NSLog(@"successfully read choice {http://api.familysearch.org/temple/v1}name of type {http://www.w3.org/2001/XMLSchema}string."); 559#endif 560 561 [self setName: __child]; 562 return YES; 563 } //end "if choice" 564 565 566 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT 567 && xmlStrcmp(BAD_CAST "district", xmlTextReaderConstLocalName(reader)) == 0 568 && xmlStrcmp(BAD_CAST "http://api.familysearch.org/temple/v1", xmlTextReaderConstNamespaceUri(reader)) == 0) { 569 570 _child_accessor = xmlTextReaderReadLongType(reader); 571 if (_child_accessor == NULL) { 572 //panic: unable to return the value for some reason. 573 [self dealloc]; 574 [NSException raise: @"XMLReadError" 575 format: @"Error reading element value."]; 576 } 577 [self setDistrict: ((long*) _child_accessor)]; 578 return YES; 579 } 580 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT 581 && xmlStrcmp(BAD_CAST "location", xmlTextReaderConstLocalName(reader)) == 0 582 && xmlStrcmp(BAD_CAST "http://api.familysearch.org/temple/v1", xmlTextReaderConstNamespaceUri(reader)) == 0) { 583 584#if DEBUG_ENUNCIATE > 1 585 NSLog(@"Attempting to read choice {http://api.familysearch.org/temple/v1}location of type {http://www.w3.org/2001/XMLSchema}string."); 586#endif 587 __child = [NSString readXMLType: reader]; 588#if DEBUG_ENUNCIATE > 1 589 NSLog(@"successfully read choice {http://api.familysearch.org/temple/v1}location of type {http://www.w3.org/2001/XMLSchema}string."); 590#endif 591 592 [self setLocation: __child]; 593 return YES; 594 } //end "if choice" 595 596 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT 597 && xmlStrcmp(BAD_CAST "dedicationDate", xmlTextReaderConstLocalName(reader)) == 0 598 && xmlStrcmp(BAD_CAST "http://api.familysearch.org/temple/v1", xmlTextReaderConstNamespaceUri(reader)) == 0) { 599 600#if DEBUG_ENUNCIATE > 1 601 NSLog(@"Attempting to read choice {http://api.familysearch.org/temple/v1}dedicationDate of type {http://www.w3.org/2001/XMLSchema}string."); 602#endif 603 __child = [NSString readXMLType: reader]; 604#if DEBUG_ENUNCIATE > 1 605 NSLog(@"successfully read choice {http://api.familysearch.org/temple/v1}dedicationDate of type {http://www.w3.org/2001/XMLSchema}string."); 606#endif 607 608 [self setDedicationDate: __child]; 609 return YES; 610 } //end "if choice" 611 612 613 return NO; 614} 615 616//documentation inherited. 617- (int) readUnknownJAXBChildElement: (xmlTextReaderPtr) reader 618{ 619 return [super readUnknownJAXBChildElement: reader]; 620} 621 622//documentation inherited. 623- (void) readUnknownJAXBAttribute: (xmlTextReaderPtr) reader 624{ 625 [super readUnknownJAXBAttribute: reader]; 626} 627 628//documentation inherited. 629- (void) writeJAXBAttributes: (xmlTextWriterPtr) writer 630{ 631 int status; 632 633 [super writeJAXBAttributes: writer]; 634 635 if ([self code]) { 636 637 status = xmlTextWriterStartAttributeNS(writer, NULL, BAD_CAST "code", NULL); 638 if (status < 0) { 639 [NSException raise: @"XMLWriteError" 640 format: @"Error writing start attribute {}code."]; 641 } 642 643#if DEBUG_ENUNCIATE > 1 644 NSLog(@"writing attribute {}code..."); 645#endif 646 [[self code] writeXMLType: writer]; 647#if DEBUG_ENUNCIATE > 1 648 NSLog(@"successfully wrote attribute {}code..."); 649#endif 650 651 status = xmlTextWriterEndAttribute(writer); 652 if (status < 0) { 653 [NSException raise: @"XMLWriteError" 654 format: @"Error writing end attribute {}code."]; 655 } 656 } 657 if ([self oldCode]) { 658 659 status = xmlTextWriterStartAttributeNS(writer, NULL, BAD_CAST "oldCode", NULL); 660 if (status < 0) { 661 [NSException raise: @"XMLWriteError" 662 format: @"Error writing start attribute {}oldCode."]; 663 } 664 665#if DEBUG_ENUNCIATE > 1 666 NSLog(@"writing attribute {}oldCode..."); 667#endif 668 [[self oldCode] writeXMLType: writer]; 669#if DEBUG_ENUNCIATE > 1 670 NSLog(@"successfully wrote attribute {}oldCode..."); 671#endif 672 673 status = xmlTextWriterEndAttribute(writer); 674 if (status < 0) { 675 [NSException raise: @"XMLWriteError" 676 format: @"Error writing end attribute {}oldCode."]; 677 } 678 } 679 if ([self requestedCode]) { 680 681 status = xmlTextWriterStartAttributeNS(writer, NULL, BAD_CAST "requestedCode", NULL); 682 if (status < 0) { 683 [NSException raise: @"XMLWriteError" 684 format: @"Error writing start attribute {}requestedCode."]; 685 } 686 687#if DEBUG_ENUNCIATE > 1 688 NSLog(@"writing attribute {}requestedCode..."); 689#endif 690 [[self requestedCode] writeXMLType: writer]; 691#if DEBUG_ENUNCIATE > 1 692 NSLog(@"successfully wrote attribute {}requestedCode..."); 693#endif 694 695 status = xmlTextWriterEndAttribute(writer); 696 if (status < 0) { 697 [NSException raise: @"XMLWriteError" 698 format: @"Error writing end attribute {}requestedCode."]; 699 } 700 } 701} 702 703//documentation inherited. 704- (void) writeJAXBValue: (xmlTextWriterPtr) writer 705{ 706 [super writeJAXBValue: writer]; 707} 708 709/** 710 * Method for writing the child elements. 711 * 712 * @param writer The writer. 713 */ 714- (void) writeJAXBChildElements: (xmlTextWriterPtr) writer 715{ 716 int status; 717 id __item; 718 NSEnumerator *__enumerator; 719 720 [super writeJAXBChildElements: writer]; 721 722 if ([self name]) { 723 status = xmlTextWriterStartElementNS(writer, BAD_CAST "temple_v1", BAD_CAST "name", NULL); 724 if (status < 0) { 725 [NSException raise: @"XMLWriteError" 726 format: @"Error writing start child element {http://api.familysearch.org/temple/v1}name."]; 727 } 728 729#if DEBUG_ENUNCIATE > 1 730 NSLog(@"writing element {http://api.familysearch.org/temple/v1}name..."); 731#endif 732 [[self name] writeXMLType: writer]; 733#if DEBUG_ENUNCIATE > 1 734 NSLog(@"successfully wrote element {http://api.familysearch.org/temple/v1}name..."); 735#endif 736 737 status = xmlTextWriterEndElement(writer); 738 if (status < 0) { 739 [NSException raise: @"XMLWriteError" 740 format: @"Error writing end child element {http://api.familysearch.org/temple/v1}name."]; 741 } 742 } 743 if ([self district] != NULL) { 744 status = xmlTextWriterStartElementNS(writer, BAD_CAST "temple_v1", BAD_CAST "district", NULL); 745 if (status < 0) { 746 [NSException raise: @"XMLWriteError" 747 format: @"Error writing start child element {http://api.familysearch.org/temple/v1}district."]; 748 } 749 750#if DEBUG_ENUNCIATE > 1 751 NSLog(@"writing element {http://api.familysearch.org/temple/v1}district..."); 752#endif 753 status = xmlTextWriterWriteLongType(writer, [self district]); 754#if DEBUG_ENUNCIATE > 1 755 NSLog(@"successfully wrote element {http://api.familysearch.org/temple/v1}district..."); 756#endif 757 if (status < 0) { 758 [NSException raise: @"XMLWriteError" 759 format: @"Error writing child element {http://api.familysearch.org/temple/v1}district."]; 760 } 761 762 status = xmlTextWriterEndElement(writer); 763 if (status < 0) { 764 [NSException raise: @"XMLWriteError" 765 format: @"Error writing end child element {http://api.familysearch.org/temple/v1}district."]; 766 } 767 } 768 if ([self location]) { 769 status = xmlTextWriterStartElementNS(writer, BAD_CAST "temple_v1", BAD_CAST "location", NULL); 770 if (status < 0) { 771 [NSException raise: @"XMLWriteError" 772 format: @"Error writing start child element {http://api.familysearch.org/temple/v1}location."]; 773 } 774 775#if DEBUG_ENUNCIATE > 1 776 NSLog(@"writing element {http://api.familysearch.org/temple/v1}location..."); 777#endif 778 [[self location] writeXMLType: writer]; 779#if DEBUG_ENUNCIATE > 1 780 NSLog(@"successfully wrote element {http://api.familysearch.org/temple/v1}location..."); 781#endif 782 783 status = xmlTextWriterEndElement(writer); 784 if (status < 0) { 785 [NSException raise: @"XMLWriteError" 786 format: @"Error writing end child element {http://api.familysearch.org/temple/v1}location."]; 787 } 788 } 789 if ([self dedicationDate]) { 790 status = xmlTextWriterStartElementNS(writer, BAD_CAST "temple_v1", BAD_CAST "dedicationDate", NULL); 791 if (status < 0) { 792 [NSException raise: @"XMLWriteError" 793 format: @"Error writing start child element {http://api.familysearch.org/temple/v1}dedicationDate."]; 794 } 795 796#if DEBUG_ENUNCIATE > 1 797 NSLog(@"writing element {http://api.familysearch.org/temple/v1}dedicationDate..."); 798#endif 799 [[self dedicationDate] writeXMLType: writer]; 800#if DEBUG_ENUNCIATE > 1 801 NSLog(@"successfully wrote element {http://api.familysearch.org/temple/v1}dedicationDate..."); 802#endif 803 804 status = xmlTextWriterEndElement(writer); 805 if (status < 0) { 806 [NSException raise: @"XMLWriteError" 807 format: @"Error writing end child element {http://api.familysearch.org/temple/v1}dedicationDate."]; 808 } 809 } 810} 811@end /* implementation FSTEMPLEV1Temple (JAXB) */ 812 813 814/** 815 * @author Rob Lyon 816 817 */ 818@implementation FSTEMPLEV1TempleRootElement 819 820/** 821 * The temples. 822 */ 823- (FSTEMPLEV1Temples *) temples 824{ 825 return _temples; 826} 827 828/** 829 * The temples. 830 */ 831- (void) setTemples: (FSTEMPLEV1Temples *) newTemples 832{ 833 [newTemples retain]; 834 [_temples release]; 835 _temples = newTemples; 836} 837 838- (void) dealloc 839{ 840 [self setTemples: nil]; 841 [super dealloc]; 842} 843 844//documentation inherited. 845+ (id<EnunciateXML>) readFromXML: (NSData *) xml 846{ 847 FSTEMPLEV1TempleRootElement *_fSTEMPLEV1TempleRootElement; 848 xmlTextReaderPtr reader = xmlReaderForMemory([xml bytes], [xml length], NULL, NULL, 0); 849 if (reader == NULL) { 850 [NSException raise: @"XMLReadError" 851 format: @"Error instantiating an XML reader."]; 852 return nil; 853 } 854 855 _fSTEMPLEV1TempleRootElement = (FSTEMPLEV1TempleRootElement *) [FSTEMPLEV1TempleRootElement readXMLElement: reader]; 856 xmlFreeTextReader(reader); //free the reader 857 return _fSTEMPLEV1TempleRootElement; 858} 859 860//documentation inherited. 861- (NSData *) writeToXML 862{ 863 xmlBufferPtr buf; 864 xmlTextWriterPtr writer; 865 int rc; 866 NSData *data; 867 868 buf = xmlBufferCreate(); 869 if (buf == NULL) { 870 [NSException raise: @"XMLWriteError" 871 format: @"Error creating an XML buffer."]; 872 return nil; 873 } 874 875 writer = xmlNewTextWriterMemory(buf, 0); 876 if (writer == NULL) { 877 xmlBufferFree(buf); 878 [NSException raise: @"XMLWriteError" 879 format: @"Error creating an XML writer."]; 880 return nil; 881 } 882 883 rc = xmlTextWriterStartDocument(writer, NULL, "utf-8", NULL); 884 if (rc < 0) { 885 xmlFreeTextWriter(writer); 886 xmlBufferFree(buf); 887 [NSException raise: @"XMLWriteError" 888 format: @"Error writing XML start document."]; 889 return nil; 890 } 891 892 NS_DURING 893 { 894 [self writeXMLElement: writer]; 895 } 896 NS_HANDLER 897 { 898 xmlFreeTextWriter(writer); 899 xmlBufferFree(buf); 900 [localException raise]; 901 } 902 NS_ENDHANDLER 903 904 rc = xmlTextWriterEndDocument(writer); 905 if (rc < 0) { 906 xmlFreeTextWriter(writer); 907 xmlBufferFree(buf); 908 [NSException raise: @"XMLWriteError" 909 format: @"Error writing XML end document."]; 910 return nil; 911 } 912 913 xmlFreeTextWriter(writer); 914 data = [NSData dataWithBytes: buf->content length: buf->use]; 915 xmlBufferFree(buf); 916 return data; 917} 918@end /* implementation FSTEMPLEV1TempleRootElement */ 919 920/** 921 * Internal, private interface for JAXB reading and writing. 922 */ 923@interface FSTEMPLEV1TempleRootElement (JAXB) <JAXBReading, JAXBWriting, JAXBType, JAXBElement> 924 925@end /*interface FSTEMPLEV1TempleRootElement (JAXB)*/ 926 927/** 928 * Internal, private implementation for JAXB reading and writing. 929 */ 930@implementation FSTEMPLEV1TempleRootElement (JAXB) 931 932/** 933 * Read an instance of FSTEMPLEV1TempleRootElement from an XML reader. 934 * 935 * @param reader The reader. 936 * @return An instance of FSTEMPLEV1TempleRootElement defined by the XML reader. 937 */ 938+ (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader 939{ 940 FSTEMPLEV1TempleRootElement *_fSTEMPLEV1TempleRootElement = [[FSTEMPLEV1TempleRootElement alloc] init]; 941 NS_DURING 942 { 943 [_fSTEMPLEV1TempleRootElement initWithReader: reader]; 944 } 945 NS_HANDLER 946 { 947 [_fSTEMPLEV1TempleRootElement dealloc]; 948 _fSTEMPLEV1TempleRootElement = nil; 949 [localException raise]; 950 } 951 NS_ENDHANDLER 952 953 [_fSTEMPLEV1TempleRootElement autorelease]; 954 return _fSTEMPLEV1TempleRootElement; 955} 956 957/** 958 * Initialize this instance of FSTEMPLEV1TempleRootElement according to 959 * the XML being read from the reader. 960 * 961 * @param reader The reader. 962 */ 963- (id) initWithReader: (xmlTextReaderPtr) reader 964{ 965 return [super initWithReader: reader]; 966} 967 968/** 969 * Write the XML for this instance of FSTEMPLEV1TempleRootElement to the writer. 970 * Note that since we're only writing the XML type, 971 * No start/end element will be written. 972 * 973 * @param reader The reader. 974 */ 975- (void) writeXMLType: (xmlTextWriterPtr) writer 976{ 977 [super writeXMLType:writer]; 978} 979 980/** 981 * Reads a FSTEMPLEV1TempleRootElement from an XML reader. The element to be read is 982 * "{http://api.familysearch.org/temple/v1}temple". 983 * 984 * @param reader The XML reader. 985 * @return The FSTEMPLEV1TempleRootElement. 986 */ 987+ (id<JAXBElement>) readXMLElement: (xmlTextReaderPtr) reader { 988 int status; 989 FSTEMPLEV1TempleRootElement *_templeRootElement = nil; 990 991 if (xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT) { 992 status = xmlTextReaderAdvanceToNextStartOrEndElement(reader); 993 if (status < 1) { 994 [NSException raise: @"XMLReadError" 995 format: @"Error advancing the reader to start element {http://api.familysearch.org/temple/v1}temple."]; 996 } 997 } 998 999 if (xmlStrcmp(BAD_CAST "temple", xmlTextReaderConstLocalName(reader)) == 0 1000 && xmlStrcmp(BAD_CAST "http://api.familysearch.org/temple/v1", xmlTextReaderConstNamespaceUri(reader)) == 0) { 1001#if DEBUG_ENUNCIATE > 1 1002 NSLog(@"Attempting to read root element {http://api.familysearch.org/temple/v1}temple."); 1003#endif 1004 _templeRootElement = (FSTEMPLEV1TempleRootElement *)[FSTEMPLEV1TempleRootElement readXMLType: reader]; 1005#if DEBUG_ENUNCIATE > 1 1006 NSLog(@"Successfully read root element {http://api.familysearch.org/temple/v1}temple."); 1007#endif 1008 } 1009 else { 1010 if (xmlTextReaderConstNamespaceUri(reader) == NULL) { 1011 [NSException raise: @"XMLReadError" 1012 format: @"Unable to read FSTEMPLEV1TempleRootElement. Expected element {http://api.familysearch.org/temple/v1}temple. Current element: {}%s", xmlTextReaderConstLocalName(reader)]; 1013 } 1014 else { 1015 [NSException raise: @"XMLReadError" 1016 format: @"Unable to read FSTEMPLEV1TempleRootElement. Expected element {http://api.familysearch.org/temple/v1}temple. Current element: {%s}%s\n", xmlTextReaderConstNamespaceUri(reader), xmlTextReaderConstLocalName(reader)]; 1017 } 1018 } 1019 1020 return _templeRootElement; 1021} 1022 1023/** 1024 * Writes this FSTEMPLEV1TempleRootElement to XML under element name "{http://api.familysearch.org/temple/v1}temple". 1025 * The namespace declarations for the element will be written. 1026 * 1027 * @param writer The XML writer. 1028 * @param _templeRootElement The TempleRootElement to write. 1029 * @return 1 if successful, 0 otherwise. 1030 */ 1031- (void) writeXMLElement: (xmlTextWriterPtr) writer 1032{ 1033 [self writeXMLElement: writer writeNamespaces: YES]; 1034} 1035 1036/** 1037 * Writes this FSTEMPLEV1TempleRootElement to an XML writer. 1038 * 1039 * @param writer The writer. 1040 * @param writeNs Whether to write the namespaces for this element to the xml writer. 1041 */ 1042- (void) writeXMLElement: (xmlTextWriterPtr) writer writeNamespaces: (BOOL) writeNs 1043{ 1044 int rc = xmlTextWriterStartElementNS(writer, BAD_CAST "temple_v1", BAD_CAST "temple", NULL); 1045 if (rc < 0) { 1046 [NSException raise: @"XMLWriteError" 1047 format: @"Error writing start element {http://api.familysearch.org/temple/v1}temple. XML writer status: %i\n", rc]; 1048 } 1049 1050 if (writeNs) { 1051#if DEBUG_ENUNCIATE > 1 1052 NSLog(@"writing namespaces for start element {http://api.familysearch.org/temple/v1}temple..."); 1053#endif 1054 1055 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:fsapi_v1", BAD_CAST "http://api.familysearch.org/v1"); 1056 if (rc < 0) { 1057 [NSException raise: @"XMLWriteError" 1058 format: @"Error writing attribute 'xmlns:fsapi_v1' on '{http://api.familysearch.org/temple/v1}temple'. XML writer status: %i\n", rc]; 1059 } 1060 1061 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST "xmlns:temple_v1", BAD_CAST "http://api.familysearch.org/temple/v1"); 1062 if (rc < 0) { 1063 [NSException raise: @"XMLWriteError" 1064 format: @"Error writing attribute 'xmlns:temple_v1' on '{http://api.familysearch.org/temple/v1}temple'. XML writer status: %i\n", rc]; 1065 } 1066#if DEBUG_ENUNCIATE > 1 1067 NSLog(@"successfully wrote namespaces for start element {http://api.familysearch.org/temple/v1}temple..."); 1068#endif 1069 } 1070 1071#if DEBUG_ENUNCIATE > 1 1072 NSLog(@"writing type {http://api.familysearch.org/temple/v1}templeRootElement for root element {http://api.familysearch.org/temple/v1}temple..."); 1073#endif 1074 [self writeXMLType: writer]; 1075#if DEBUG_ENUNCIATE > 1 1076 NSLog(@"successfully wrote type {http://api.familysearch.org/temple/v1}templeRootElement for root element {http://api.familysearch.org/temple/v1}temple..."); 1077#endif 1078 rc = xmlTextWriterEndElement(writer); 1079 if (rc < 0) { 1080 [NSException raise: @"XMLWriteError" 1081 format: @"Error writing end element {http://api.familysearch.org/temple/v1}temple. XML writer status: %i\n", rc]; 1082 } 1083} 1084 1085//documentation inherited. 1086- (BOOL) readJAXBAttribute: (xmlTextReaderPtr) reader 1087{ 1088 void *_child_accessor; 1089 1090 if ([super readJAXBAttribute: reader]) { 1091 return YES; 1092 } 1093 1094 return NO; 1095} 1096 1097//documentation inherited. 1098- (BOOL) readJAXBValue: (xmlTextReaderPtr) reader 1099{ 1100 return [super readJAXBValue: reader]; 1101} 1102 1103//documentation inherited. 1104- (BOOL) readJAXBChildElement: (xmlTextReaderPtr) reader 1105{ 1106 id __child; 1107 void *_child_accessor; 1108 int status, depth; 1109 1110 if ([super readJAXBChildElement: reader]) { 1111 return YES; 1112 } 1113 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT 1114 && xmlStrcmp(BAD_CAST "temples", xmlTextReaderConstLocalName(reader)) == 0 1115 && xmlStrcmp(BAD_CAST "http://api.familysearch.org/temple/v1", xmlTextReaderConstNamespaceUri(reader)) == 0) { 1116 1117#if DEBUG_ENUNCIATE > 1 1118 NSLog(@"Attempting to read choice {http://api.familysearch.org/temple/v1}temples of type {http://api.familysearch.org/temple/v1}temples."); 1119#endif 1120 __child = [FSTEMPLEV1Temples readXMLType: reader]; 1121#if DEBUG_ENUNCIATE > 1 1122 NSLog(@"successfully read choice {http://api.familysearch.org/temple/v1}temples of type {http://api.familysearch.org/temple/v1}temples."); 1123#endif 1124 1125 [self setTemples: __child]; 1126 return YES; 1127 } //end "if choice" 1128 1129 1130 return NO; 1131} 1132 1133//documentation inherited. 1134- (int) readUnknownJAXBChildElement: (xmlTextReaderPtr) reader 1135{ 1136 return [super readUnknownJAXBChildElement: reader]; 1137} 1138 1139//documentation inherited. 1140- (void) readUnknownJAXBAttribute: (xmlTextReaderPtr) reader 1141{ 1142 [super readUnknownJAXBAttribute: reader]; 1143} 1144 1145//documentation inherited. 1146- (void) writeJAXBAttributes: (xmlTextWriterPtr) writer 1147{ 1148 int status; 1149 1150 [super writeJAXBAttributes: writer]; 1151 1152} 1153 1154//documentation inherited. 1155- (void) writeJAXBValue: (xmlTextWriterPtr) writer 1156{ 1157 [super writeJAXBValue: writer]; 1158} 1159 1160/** 1161 * Method for writing the child elements. 1162 * 1163 * @param writer The writer. 1164 */ 1165- (void) writeJAXBChildElements: (xmlTextWriterPtr) writer 1166{ 1167 int status; 1168 id __item; 1169 NSEnumerator *__enumerator; 1170 1171 [super writeJAXBChildElements: writer]; 1172 1173 if ([self temples]) { 1174 status = xmlTextWriterStartElementNS(writer, BAD_CAST "temple_v1", BAD_CAST "temples", NULL); 1175 if (status < 0) { 1176 [NSException raise: @"XMLWriteError" 1177 format: @"Error writing start child element {http://api.familysearch.org/temple/v1}temples."]; 1178 } 1179 1180#if DEBUG_ENUNCIATE > 1 1181 NSLog(@"writing element {http://api.familysearch.org/temple/v1}temples..."); 1182#endif 1183 [[self temples] writeXMLType: writer]; 1184#if DEBUG_ENUNCIATE > 1 1185 NSLog(@"successfully wrote element {http://api.familysearch.org/temple/v1}temples..."); 1186#endif 1187 1188 status = xmlTextWriterEndElement(writer); 1189 if (status < 0) { 1190 [NSException raise: @"XMLWriteError" 1191 format: @"Error writing end child element {http://api.familysearch.org/temple/v1}temples."]; 1192 } 1193 } 1194} 1195@end /* implementation FSTEMPLEV1TempleRootElement (JAXB) */