/FSKit/Source/Common/enunciate/dev/temple.m

http://fskit.googlecode.com/ · Objective C · 1195 lines · 820 code · 163 blank · 212 comment · 124 complexity · 6fb29ac6c49836f997dcfe6c40c2db30 MD5 · raw file

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