PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/FSKit/Source/Common/enunciate/prod/familytree.m

http://fskit.googlecode.com/
Objective C | 2598 lines | 1418 code | 343 blank | 837 comment | 233 complexity | f86155998a246f9f696849a4c5e71603 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. #import <familytree.h>
  2. /**
  3. * Enunciate-specific C functions.
  4. */
  5. #ifndef ENUNCIATE_C_UTILITIES
  6. #define ENUNCIATE_C_UTILITIES
  7. /*******************xml utilities************************************/
  8. static int xmlTextReaderAdvanceToNextStartOrEndElement(xmlTextReaderPtr reader) {
  9. int status = xmlTextReaderRead(reader);
  10. while (status && xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT && xmlTextReaderNodeType(reader) != XML_READER_TYPE_END_ELEMENT) {
  11. status = xmlTextReaderRead(reader);
  12. }
  13. return status;
  14. }
  15. static int xmlTextReaderSkipElement(xmlTextReaderPtr reader) {
  16. int status = xmlTextReaderNext(reader);
  17. while (status && xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT && xmlTextReaderNodeType(reader) != XML_READER_TYPE_END_ELEMENT) {
  18. status = xmlTextReaderRead(reader);
  19. }
  20. return status;
  21. }
  22. static xmlChar *xmlTextReaderReadEntireNodeValue(xmlTextReaderPtr reader) {
  23. xmlChar *buffer = calloc(1, sizeof(xmlChar));
  24. const xmlChar *snippet;
  25. int status;
  26. if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ATTRIBUTE) {
  27. return xmlTextReaderValue(reader);
  28. }
  29. else if (xmlTextReaderIsEmptyElement(reader) == 0) {
  30. status = xmlTextReaderRead(reader);
  31. while (status && (xmlTextReaderNodeType(reader) == XML_READER_TYPE_TEXT || xmlTextReaderNodeType(reader) == XML_READER_TYPE_CDATA || xmlTextReaderNodeType(reader) == XML_READER_TYPE_ENTITY_REFERENCE)) {
  32. snippet = xmlTextReaderConstValue(reader);
  33. buffer = realloc(buffer, (xmlStrlen(buffer) + xmlStrlen(snippet) + 1) * sizeof(xmlChar));
  34. xmlStrcat(buffer, snippet);
  35. status = xmlTextReaderRead(reader);
  36. }
  37. }
  38. return buffer;
  39. }
  40. /*******************base 64 utilities************************************/
  41. /*
  42. * Base64 Translation Table as described in RFC1113.
  43. *
  44. * This code was graciously ripped from http://base64.sourceforge.net
  45. */
  46. static const char cb64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  47. /*
  48. * Base64 Translation Table to decode (created by author)
  49. *
  50. * This code was graciously ripped from http://base64.sourceforge.net
  51. */
  52. static const char cd64[]="|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq";
  53. /*
  54. * encode 3 8-bit binary bytes as 4 '6-bit' characters
  55. *
  56. * This code was graciously ripped from http://base64.sourceforge.net
  57. *
  58. * @param in the block to encode
  59. * @param out the block to encode to
  60. * @param len the length of the 'in' block.
  61. */
  62. static void _encode_base64_block(unsigned char in[3], unsigned char out[4], int len) {
  63. out[0] = cb64[ in[0] >> 2 ];
  64. out[1] = cb64[ ((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4) ];
  65. out[2] = (unsigned char) (len > 1 ? cb64[ ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ] : '=');
  66. out[3] = (unsigned char) (len > 2 ? cb64[ in[2] & 0x3f ] : '=');
  67. }
  68. /*
  69. * decode 4 '6-bit' characters into 3 8-bit binary bytes
  70. *
  71. * This code was graciously ripped from http://base64.sourceforge.net
  72. */
  73. static void _decode_base64_block( unsigned char in[4], unsigned char out[3] )
  74. {
  75. out[ 0 ] = (unsigned char ) (in[0] << 2 | in[1] >> 4);
  76. out[ 1 ] = (unsigned char ) (in[1] << 4 | in[2] >> 2);
  77. out[ 2 ] = (unsigned char ) (((in[2] << 6) & 0xc0) | in[3]);
  78. }
  79. /*
  80. * base64 encode a stream adding padding and line breaks as per spec.
  81. *
  82. * This code was graciously ripped from http://base64.sourceforge.net
  83. *
  84. * @param instream The stream to encode.
  85. * @param insize The size of the stream to encode.
  86. * @return The encoded string.
  87. */
  88. xmlChar *_encode_base64(unsigned char *instream, int insize) {
  89. unsigned char in[3];
  90. unsigned char out[4];
  91. xmlChar *encoded;
  92. int i, in_index = 0, out_index = 0, blocklen;
  93. if (insize == 0) {
  94. return BAD_CAST "\0";
  95. }
  96. encoded = calloc(((insize / 3) * 4) + 10, sizeof(xmlChar));
  97. while (in_index <= insize) {
  98. blocklen = 0;
  99. for (i = 0; i < 3; i++) {
  100. in[i] = instream[in_index++];
  101. if (in_index <= insize) {
  102. blocklen++;
  103. }
  104. else {
  105. in[i] = 0;
  106. }
  107. }
  108. if (blocklen) {
  109. _encode_base64_block(in, out, blocklen);
  110. for( i = 0; i < 4; i++ ) {
  111. encoded[out_index++] = out[i];
  112. }
  113. }
  114. }
  115. return encoded;
  116. }
  117. /*
  118. * Decode a base64 encoded stream discarding padding, line breaks and noise
  119. *
  120. * This code was graciously ripped from http://base64.sourceforge.net
  121. *
  122. * @param invalue The string to decode.
  123. * @param outsize Holder for the length of the returned data.
  124. * @return The decoded data.
  125. */
  126. unsigned char *_decode_base64( const xmlChar *invalue, int *outsize ) {
  127. xmlChar in[4];
  128. unsigned char out[3], v;
  129. int i, in_index = 0, out_index = 0, blocklen;
  130. unsigned char *outstream;
  131. if (invalue == NULL) {
  132. return NULL;
  133. }
  134. outstream = calloc(((xmlStrlen(invalue) / 4) * 3) + 1, sizeof(unsigned char));
  135. while (invalue[in_index] != '\0') {
  136. for (blocklen = 0, i = 0; i < 4 && invalue[in_index]; i++) {
  137. v = 0;
  138. while (invalue[in_index] != '\0' && v == 0) {
  139. v = (unsigned char) invalue[in_index++];
  140. v = (unsigned char) ((v < 43 || v > 122) ? 0 : cd64[ v - 43 ]);
  141. if (v) {
  142. v = (unsigned char) ((v == '$') ? 0 : v - 61);
  143. }
  144. }
  145. if (invalue[in_index] != '\0') {
  146. blocklen++;
  147. if (v) {
  148. in[i] = (unsigned char) (v - 1);
  149. }
  150. }
  151. else {
  152. in[i] = 0;
  153. }
  154. }
  155. if (blocklen) {
  156. _decode_base64_block( in, out );
  157. for( i = 0; i < blocklen - 1; i++ ) {
  158. outstream[out_index++] = out[i];
  159. }
  160. }
  161. }
  162. if (outsize != NULL) {
  163. *outsize = out_index;
  164. }
  165. return outstream;
  166. }
  167. #endif /* ENUNCIATE_C_UTILITIES */
  168. #ifndef ENUNCIATE_OBJC_CLASSES
  169. #define ENUNCIATE_OBJC_CLASSES
  170. /**
  171. * Protocol defining a JAXB (see https://jaxb.dev.java.net/) type.
  172. */
  173. @protocol JAXBType
  174. /**
  175. * Read an XML type from an XML reader.
  176. *
  177. * @param reader The reader.
  178. * @return An instance of the object defining the JAXB type.
  179. */
  180. + (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader;
  181. /**
  182. * Initialize the object with an XML reader.
  183. *
  184. * @param reader The XML reader from which to initialize the values of this type.
  185. */
  186. - (id) initWithReader: (xmlTextReaderPtr) reader;
  187. /**
  188. * Write this instance of a JAXB type to a writer.
  189. *
  190. * @param writer The writer.
  191. */
  192. - (void) writeXMLType: (xmlTextWriterPtr) writer;
  193. @end /*protocol JAXBType*/
  194. /**
  195. * Protocol defining a JAXB (see https://jaxb.dev.java.net/) element.
  196. */
  197. @protocol JAXBElement
  198. /**
  199. * Read the XML element from an XML reader. It is assumed
  200. * that the reader is pointing at the start element (be careful
  201. * that it's not still pointing to the XML document).
  202. *
  203. * @param reader The reader.
  204. * @return An instance of the object defining the JAXB element.
  205. */
  206. + (id<JAXBElement>) readXMLElement: (xmlTextReaderPtr) reader;
  207. /**
  208. * Write this instance of a JAXB element to a writer.
  209. *
  210. * @param writer The writer.
  211. */
  212. - (void) writeXMLElement: (xmlTextWriterPtr) writer;
  213. /**
  214. * Write this instance of a JAXB element to a writer.
  215. *
  216. * @param writer The writer.
  217. * @param writeNs Whether to write the namespaces for this element to the xml writer.
  218. */
  219. - (void) writeXMLElement: (xmlTextWriterPtr) writer writeNamespaces: (BOOL) writeNs;
  220. @end /*protocol JAXBElement*/
  221. /**
  222. * Protocol defining methods for events that occur
  223. * when reading/parsing XML. Intended for internal
  224. * use only.
  225. */
  226. @protocol JAXBReading
  227. /**
  228. * Method for reading an attribute.
  229. *
  230. * @param reader The reader pointing to the attribute.
  231. * @return Whether the attribute was read.
  232. */
  233. - (BOOL) readJAXBAttribute: (xmlTextReaderPtr) reader;
  234. /**
  235. * Method for reading the value of an element.
  236. *
  237. * @param reader The reader pointing to the element containing a value.
  238. * @return Whether the value was read.
  239. */
  240. - (BOOL) readJAXBValue: (xmlTextReaderPtr) reader;
  241. /**
  242. * Method for reading a child element. If (and only if) the child
  243. * element was handled, the element in the reader should be
  244. * "consumed" and the reader will be pointing to the end element.
  245. *
  246. * @param reader The reader pointing to the child element.
  247. * @return Whether the child element was read.
  248. */
  249. - (BOOL) readJAXBChildElement: (xmlTextReaderPtr) reader;
  250. /**
  251. * Method for reading an unknown attribute.
  252. *
  253. * @param reader The reader pointing to the unknown attribute.
  254. * @return Whether the attribute was read.
  255. */
  256. - (void) readUnknownJAXBAttribute: (xmlTextReaderPtr) reader;
  257. /**
  258. * Method for reading an unknown child element. Implementations
  259. * must be responsible for "consuming" the child element.
  260. *
  261. * @param reader The reader pointing to the unknown child element.
  262. * @return The status of the reader after having consumed the unknown child element.
  263. */
  264. - (int) readUnknownJAXBChildElement: (xmlTextReaderPtr) reader;
  265. @end /*protocol JAXBReading*/
  266. /**
  267. * Protocol defining methods for events that occur
  268. * when writing XML. Intended for internal
  269. * use only.
  270. */
  271. @protocol JAXBWriting
  272. /**
  273. * Method for writing the attributes.
  274. *
  275. * @param writer The writer.
  276. */
  277. - (void) writeJAXBAttributes: (xmlTextWriterPtr) writer;
  278. /**
  279. * Method for writing the element value.
  280. *
  281. * @param writer The writer.
  282. */
  283. - (void) writeJAXBValue: (xmlTextWriterPtr) writer;
  284. /**
  285. * Method for writing the child elements.
  286. *
  287. * @param writer The writer.
  288. */
  289. - (void) writeJAXBChildElements: (xmlTextWriterPtr) writer;
  290. @end /*protocol JAXBWriting*/
  291. /**
  292. * Declaration of the JAXB type, element, events for a base object.
  293. */
  294. @interface NSObject (JAXB) <JAXBType, JAXBElement, JAXBReading, JAXBWriting>
  295. @end
  296. /**
  297. * Implementation of the JAXB type, element, events for a base object.
  298. */
  299. @implementation NSObject (JAXB)
  300. /**
  301. * Read the XML type from the reader; an instance of NSXMLElement.
  302. *
  303. * @param reader The reader.
  304. * @return An instance of NSXMLElement
  305. */
  306. + (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader
  307. {
  308. return [JAXBBasicXMLNode readXMLType: reader];
  309. }
  310. /**
  311. * Read an XML type from an XML reader into an existing instance.
  312. *
  313. * @param reader The reader.
  314. * @param existing The existing instance into which to read values.
  315. */
  316. - (id) initWithReader: (xmlTextReaderPtr) reader
  317. {
  318. int status, depth;
  319. if ((self = [self init])) {
  320. if (xmlTextReaderHasAttributes(reader)) {
  321. while (xmlTextReaderMoveToNextAttribute(reader)) {
  322. if ([self readJAXBAttribute: reader] == NO) {
  323. [self readUnknownJAXBAttribute: reader];
  324. }
  325. }
  326. status = xmlTextReaderMoveToElement(reader);
  327. if (!status) {
  328. //panic: unable to return to the element node.
  329. [NSException raise: @"XMLReadError"
  330. format: @"Error moving back to element position from attributes."];
  331. }
  332. }
  333. if ([self readJAXBValue: reader] == NO) {
  334. //no value handled; attempt to process child elements
  335. if (xmlTextReaderIsEmptyElement(reader) == 0) {
  336. depth = xmlTextReaderDepth(reader);//track the depth.
  337. status = xmlTextReaderAdvanceToNextStartOrEndElement(reader);
  338. while (xmlTextReaderDepth(reader) > depth) {
  339. if (status < 1) {
  340. //panic: XML read error.
  341. [NSException raise: @"XMLReadError"
  342. format: @"Error handling a child element."];
  343. }
  344. else if ([self readJAXBChildElement: reader]) {
  345. status = xmlTextReaderAdvanceToNextStartOrEndElement(reader);
  346. }
  347. else {
  348. status = [self readUnknownJAXBChildElement: reader];
  349. }
  350. }
  351. }
  352. }
  353. }
  354. return self;
  355. }
  356. /**
  357. * Write the XML type value of this object to the writer.
  358. *
  359. * @param writer The writer.
  360. */
  361. - (void) writeXMLType: (xmlTextWriterPtr) writer
  362. {
  363. [self writeJAXBAttributes: writer];
  364. [self writeJAXBValue: writer];
  365. [self writeJAXBChildElements: writer];
  366. }
  367. /**
  368. * Read the XML element from the reader; an instance of NSXMLElement.
  369. *
  370. * @param reader The reader.
  371. * @return An instance of NSXMLElement
  372. */
  373. + (id<JAXBElement>) readXMLElement: (xmlTextReaderPtr) reader
  374. {
  375. return (id<JAXBElement>) [JAXBBasicXMLNode readXMLType: reader];
  376. }
  377. /**
  378. * No op; root objects don't have an element name/namespace. Subclasses must override.
  379. *
  380. * @param writer The writer.
  381. */
  382. - (void) writeXMLElement: (xmlTextWriterPtr) writer
  383. {
  384. //no-op
  385. }
  386. /**
  387. * No op; root objects don't have an element name/namespace. Subclasses must override.
  388. *
  389. * @param writer The writer.
  390. * @param writeNs Ignored.
  391. */
  392. - (void) writeXMLElement: (xmlTextWriterPtr) writer writeNamespaces: (BOOL) writeNs
  393. {
  394. //no-op
  395. }
  396. /**
  397. * No-op; base objects do not handle any attributes.
  398. *
  399. * @param reader The reader pointing to the attribute.
  400. * @return NO
  401. */
  402. - (BOOL) readJAXBAttribute: (xmlTextReaderPtr) reader
  403. {
  404. return NO;
  405. }
  406. /**
  407. * No-op; base objects do not handle any values.
  408. *
  409. * @param reader The reader pointing to the element containing a value.
  410. * @return NO
  411. */
  412. - (BOOL) readJAXBValue: (xmlTextReaderPtr) reader
  413. {
  414. return NO;
  415. }
  416. /**
  417. * No-op; base objects do not handle any child elements.
  418. *
  419. * @param reader The reader pointing to the child element.
  420. * @return NO
  421. */
  422. - (BOOL) readJAXBChildElement: (xmlTextReaderPtr) reader
  423. {
  424. return NO;
  425. }
  426. /**
  427. * No-op; base objects do not handle any attributes.
  428. *
  429. * @param reader The reader pointing to the unknown attribute.
  430. */
  431. - (void) readUnknownJAXBAttribute: (xmlTextReaderPtr) reader
  432. {
  433. }
  434. /**
  435. * Just skips the unknown element; base objects do not handle any child elements.
  436. *
  437. * @param reader The reader pointing to the unknown child element.
  438. * @return The status of the reader after skipping the unknown child element.
  439. */
  440. - (int) readUnknownJAXBChildElement: (xmlTextReaderPtr) reader
  441. {
  442. return xmlTextReaderSkipElement(reader);
  443. }
  444. /**
  445. * No-op; base objects have no attributes.
  446. *
  447. * @param writer The writer.
  448. */
  449. - (void) writeJAXBAttributes: (xmlTextWriterPtr) writer
  450. {
  451. //no-op.
  452. }
  453. /**
  454. * No-op; base objects have no element value.
  455. *
  456. * @param writer The writer.
  457. */
  458. - (void) writeJAXBValue: (xmlTextWriterPtr) writer
  459. {
  460. //no-op.
  461. }
  462. /**
  463. * No-op; base objects have no child elements.
  464. *
  465. * @param writer The writer.
  466. */
  467. - (void) writeJAXBChildElements: (xmlTextWriterPtr) writer
  468. {
  469. //no-op.
  470. }
  471. @end /*NSObject (JAXB)*/
  472. /**
  473. * Implementation of the JAXB type, element for an xml element.
  474. */
  475. @implementation JAXBBasicXMLNode
  476. /**
  477. * Accessor for the (local) name of the XML node.
  478. *
  479. * @return The (local) name of the XML node.
  480. */
  481. - (NSString *) name
  482. {
  483. return _name;
  484. }
  485. /**
  486. * Accessor for the (local) name of the XML node.
  487. *
  488. * @param newName The (local) name of the XML node.
  489. */
  490. - (void) setName: (NSString *) newName
  491. {
  492. [newName retain];
  493. [_name release];
  494. _name = newName;
  495. }
  496. /**
  497. * Accessor for the namespace of the XML node.
  498. *
  499. * @return The namespace of the XML node.
  500. */
  501. - (NSString *) ns
  502. {
  503. return _ns;
  504. }
  505. /**
  506. * Accessor for the namespace of the XML node.
  507. *
  508. * @param newNs The namespace of the XML node.
  509. */
  510. - (void) setNs: (NSString *) newNs
  511. {
  512. [newNs retain];
  513. [_ns release];
  514. _ns = newNs;
  515. }
  516. /**
  517. * Accessor for the namespace prefix of the XML node.
  518. *
  519. * @return The namespace prefix of the XML node.
  520. */
  521. - (NSString *) prefix
  522. {
  523. return _prefix;
  524. }
  525. /**
  526. * Accessor for the namespace prefix of the XML node.
  527. *
  528. * @param newPrefix The namespace prefix of the XML node.
  529. */
  530. - (void) setPrefix: (NSString *) newPrefix
  531. {
  532. [newPrefix retain];
  533. [_prefix release];
  534. _prefix = newPrefix;
  535. }
  536. /**
  537. * Accessor for the value of the XML node.
  538. *
  539. * @return The value of the XML node.
  540. */
  541. - (NSString *) value
  542. {
  543. return _value;
  544. }
  545. /**
  546. * Accessor for the value of the XML node.
  547. *
  548. * @param newValue The value of the XML node.
  549. */
  550. - (void) setValue: (NSString *) newValue
  551. {
  552. [newValue retain];
  553. [_value release];
  554. _value = newValue;
  555. }
  556. /**
  557. * Accessor for the child elements of the XML node.
  558. *
  559. * @return The child elements of the XML node.
  560. */
  561. - (NSArray *) childElements
  562. {
  563. return _childElements;
  564. }
  565. /**
  566. * Accessor for the child elements of the XML node.
  567. *
  568. * @param newValue The child elements of the XML node.
  569. */
  570. - (void) setChildElements: (NSArray *) newChildElements
  571. {
  572. [newChildElements retain];
  573. [_childElements release];
  574. _childElements = newChildElements;
  575. }
  576. /**
  577. * Accessor for the attributes of the XML node.
  578. *
  579. * @return The attributes of the XML node.
  580. */
  581. - (NSArray *) attributes
  582. {
  583. return _attributes;
  584. }
  585. /**
  586. * Accessor for the attributes of the XML node.
  587. *
  588. * @param newAttributes The attributes of the XML node.
  589. */
  590. - (void) setAttributes: (NSArray *) newAttributes
  591. {
  592. [newAttributes retain];
  593. [_attributes release];
  594. _attributes = newAttributes;
  595. }
  596. - (void) dealloc {
  597. [self setName: nil];
  598. [self setNs: nil];
  599. [self setPrefix: nil];
  600. [self setValue: nil];
  601. [self setChildElements: nil];
  602. [self setAttributes: nil];
  603. [super dealloc];
  604. }
  605. @end /*implementation JAXBBasicXMLNode*/
  606. /**
  607. * Internal, private interface for JAXB reading and writing.
  608. */
  609. @interface JAXBBasicXMLNode (JAXB) <JAXBType, JAXBElement>
  610. @end /*interface JAXBBasicXMLNode (JAXB)*/
  611. @implementation JAXBBasicXMLNode (JAXB)
  612. /**
  613. * Read the XML type from the reader; an instance of JAXBBasicXMLNode.
  614. *
  615. * @param reader The reader.
  616. * @return An instance of JAXBBasicXMLNode
  617. */
  618. + (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader
  619. {
  620. JAXBBasicXMLNode *node = [[JAXBBasicXMLNode alloc] init];
  621. NS_DURING
  622. {
  623. [node initWithReader: reader];
  624. }
  625. NS_HANDLER
  626. {
  627. [node dealloc];
  628. node = nil;
  629. [localException raise];
  630. }
  631. NS_ENDHANDLER
  632. [node autorelease];
  633. return node;
  634. }
  635. /**
  636. * Read an XML type from an XML reader into an existing instance of JAXBBasicXMLNode.
  637. *
  638. * @param reader The reader.
  639. * @param existing The existing instance into which to read values.
  640. */
  641. - (id) initWithReader: (xmlTextReaderPtr) reader
  642. {
  643. int status, depth;
  644. JAXBBasicXMLNode *child;
  645. xmlChar *value = NULL;
  646. const xmlChar *text;
  647. NSMutableArray *children;
  648. if ((self = [self init])) {
  649. depth = xmlTextReaderDepth(reader);
  650. [self setName: [NSString stringWithUTF8String: (const char *) xmlTextReaderLocalName(reader)]];
  651. [self setNs: [NSString stringWithUTF8String: (const char *) xmlTextReaderNamespaceUri(reader)]];
  652. [self setPrefix: [NSString stringWithUTF8String: (const char *)xmlTextReaderPrefix(reader)]];
  653. if (xmlTextReaderHasAttributes(reader)) {
  654. child = nil;
  655. children = [[NSMutableArray alloc] init];
  656. while (xmlTextReaderMoveToNextAttribute(reader)) {
  657. child = [[JAXBBasicXMLNode alloc] init];
  658. [child setName: [NSString stringWithUTF8String: (const char *) xmlTextReaderLocalName(reader)]];
  659. [child setNs: [NSString stringWithUTF8String: (const char *)xmlTextReaderNamespaceUri(reader)]];
  660. [child setPrefix: [NSString stringWithUTF8String: (const char *) xmlTextReaderPrefix(reader)]];
  661. [child setValue: [NSString stringWithUTF8String: (const char *) xmlTextReaderValue(reader)]];
  662. [children addObject: child];
  663. }
  664. [self setAttributes: children];
  665. status = xmlTextReaderMoveToElement(reader);
  666. if (status < 1) {
  667. //panic: unable to return to the element node.
  668. [NSException raise: @"XMLReadError"
  669. format: @"Error moving to element from attributes."];
  670. }
  671. }
  672. if (xmlTextReaderIsEmptyElement(reader) == 0) {
  673. children = [[NSMutableArray alloc] init];
  674. status = xmlTextReaderRead(reader);
  675. while (status == 1 && xmlTextReaderDepth(reader) > depth) {
  676. switch (xmlTextReaderNodeType(reader)) {
  677. case XML_READER_TYPE_ELEMENT:
  678. child = (JAXBBasicXMLNode *) [JAXBBasicXMLNode readXMLType: reader];
  679. [children addObject: child];
  680. break;
  681. case XML_READER_TYPE_TEXT:
  682. case XML_READER_TYPE_CDATA:
  683. text = xmlTextReaderConstValue(reader);
  684. value = xmlStrncat(value, text, xmlStrlen(text));
  685. break;
  686. default:
  687. //skip anything else.
  688. break;
  689. }
  690. status = xmlTextReaderRead(reader);
  691. }
  692. if (status < 1) {
  693. //panic: xml read error
  694. [NSException raise: @"XMLReadError"
  695. format: @"Error reading child elements."];
  696. }
  697. if ([children count] > 0) {
  698. [self setChildElements: children];
  699. }
  700. if (value != NULL) {
  701. [self setValue: [NSString stringWithUTF8String: (const char *) value]];
  702. }
  703. }
  704. }
  705. return self;
  706. }
  707. /**
  708. * Read the XML element from the reader; an instance of NSXMLElement.
  709. *
  710. * @param reader The reader.
  711. * @return An instance of NSXMLElement
  712. */
  713. + (id<JAXBElement>) readXMLElement: (xmlTextReaderPtr) reader
  714. {
  715. return (id<JAXBElement>) [JAXBBasicXMLNode readXMLType: reader];
  716. }
  717. /**
  718. * Write the basic node to an xml writer.
  719. *
  720. * @param writer The writer.
  721. */
  722. - (void) writeXMLType: (xmlTextWriterPtr) writer
  723. {
  724. int status;
  725. NSEnumerator *enumerator;
  726. JAXBBasicXMLNode *child;
  727. xmlChar *childns, *childname, *childprefix, *childvalue;
  728. status = xmlTextWriterStartElementNS(writer, _prefix ? BAD_CAST [_prefix UTF8String] : NULL, _name ? BAD_CAST [_name UTF8String] : NULL, _ns ? BAD_CAST [_ns UTF8String] : NULL);
  729. if (status < 0) {
  730. childns = BAD_CAST "";
  731. if (_ns) {
  732. childns = BAD_CAST [_ns UTF8String];
  733. }
  734. childname = BAD_CAST "";
  735. if (_name) {
  736. childname = BAD_CAST [_name UTF8String];
  737. }
  738. [NSException raise: @"XMLWriteError"
  739. format: @"Error writing start element {%s}%s for JAXBBasicXMLNode.", childns, childname];
  740. }
  741. if (_attributes) {
  742. enumerator = [_attributes objectEnumerator];
  743. while ( (child = (JAXBBasicXMLNode *)[enumerator nextObject]) ) {
  744. childns = NULL;
  745. if ([child ns]) {
  746. childns = BAD_CAST [[child ns] UTF8String];
  747. }
  748. childprefix = NULL;
  749. if ([child prefix]) {
  750. childprefix = BAD_CAST [[child prefix] UTF8String];
  751. }
  752. childname = NULL;
  753. if ([child name]) {
  754. childname = BAD_CAST [[child name] UTF8String];
  755. }
  756. childvalue = NULL;
  757. if ([child value]) {
  758. childvalue = BAD_CAST [[child value] UTF8String];
  759. }
  760. status = xmlTextWriterWriteAttributeNS(writer, childprefix, childname, childns, childvalue);
  761. if (status < 0) {
  762. [NSException raise: @"XMLWriteError"
  763. format: @"Error writing attribute {%s}%s for JAXBBasicXMLNode.", childns, childname];
  764. }
  765. }
  766. }
  767. if (_value) {
  768. status = xmlTextWriterWriteString(writer, BAD_CAST [_value UTF8String]);
  769. if (status < 0) {
  770. [NSException raise: @"XMLWriteError"
  771. format: @"Error writing value of JAXBBasicXMLNode."];
  772. }
  773. }
  774. if (_childElements) {
  775. enumerator = [_childElements objectEnumerator];
  776. while ( (child = [enumerator nextObject]) ) {
  777. [child writeXMLType: writer];
  778. }
  779. }
  780. status = xmlTextWriterEndElement(writer);
  781. if (status < 0) {
  782. childns = BAD_CAST "";
  783. if (_ns) {
  784. childns = BAD_CAST [_ns UTF8String];
  785. }
  786. childname = BAD_CAST "";
  787. if (_name) {
  788. childname = BAD_CAST [_name UTF8String];
  789. }
  790. [NSException raise: @"XMLWriteError"
  791. format: @"Error writing end element {%s}%s for JAXBBasicXMLNode.", childns, childname];
  792. }
  793. }
  794. /**
  795. * Writes this node to a writer.
  796. *
  797. * @param writer The writer.
  798. */
  799. - (void) writeXMLElement: (xmlTextWriterPtr) writer
  800. {
  801. [self writeXMLType: writer];
  802. }
  803. /**
  804. * Writes this node to a writer.
  805. *
  806. * @param writer The writer.
  807. * @param writeNs Whether to write the namespaces for this element to the xml writer.
  808. */
  809. - (void) writeXMLElement: (xmlTextWriterPtr) writer writeNamespaces: (BOOL) writeNs
  810. {
  811. [self writeXMLType: writer];
  812. }
  813. @end /* implementation JAXBBasicXMLNode (JAXB) */
  814. /**
  815. * Declaration of the JAXB type for a string.
  816. */
  817. @interface NSString (JAXBType) <JAXBType>
  818. @end
  819. /**
  820. * Implementation of the JAXB type for a string.
  821. */
  822. @implementation NSString (JAXBType)
  823. /**
  824. * Read the XML type from the reader.
  825. *
  826. * @param reader The reader.
  827. * @return The NSString that was read from the reader.
  828. */
  829. + (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader
  830. {
  831. return [NSString stringWithUTF8String: (const char *) xmlTextReaderReadEntireNodeValue(reader)];
  832. }
  833. /**
  834. * Read an XML type from an XML reader into an existing instance.
  835. *
  836. * @param reader The reader.
  837. * @param existing The existing instance into which to read values.
  838. */
  839. - (id) initWithReader: (xmlTextReaderPtr) reader
  840. {
  841. [NSException raise: @"XMLReadError"
  842. format: @"An existing string cannot be modified."];
  843. return nil;
  844. }
  845. /**
  846. * Write the NSString to the writer.
  847. *
  848. * @param writer The writer.
  849. */
  850. - (void) writeXMLType: (xmlTextWriterPtr) writer
  851. {
  852. xmlTextWriterWriteString(writer, BAD_CAST [self UTF8String]);
  853. }
  854. @end /*NSString (JAXBType)*/
  855. /**
  856. * Declaration of the JAXB type for a big number.
  857. */
  858. @interface NSNumber (JAXBType) <JAXBType>
  859. @end
  860. /**
  861. * Implementation of the JAXB type for a big number.
  862. */
  863. @implementation NSNumber (JAXBType)
  864. /**
  865. * Read the XML type from the reader.
  866. *
  867. * @param reader The reader.
  868. * @return The NSNumber that was read from the reader.
  869. */
  870. + (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader
  871. {
  872. return [NSNumber numberWithLongLong: [[NSString stringWithUTF8String: (const char *) xmlTextReaderReadEntireNodeValue(reader)] longLongValue]];
  873. }
  874. /**
  875. * Read an XML type from an XML reader into an existing instance.
  876. *
  877. * @param reader The reader.
  878. * @param existing The existing instance into which to read values.
  879. */
  880. - (id) initWithReader: (xmlTextReaderPtr) reader
  881. {
  882. [NSException raise: @"XMLReadError"
  883. format: @"An existing number cannot be modified."];
  884. return nil;
  885. }
  886. /**
  887. * Write the NSNumber to the writer.
  888. *
  889. * @param writer The writer.
  890. */
  891. - (void) writeXMLType: (xmlTextWriterPtr) writer
  892. {
  893. xmlTextWriterWriteString(writer, BAD_CAST [[self description] UTF8String]);
  894. }
  895. @end /*NSNumber (JAXBType)*/
  896. /**
  897. * Declaration of the JAXB type for a big number.
  898. */
  899. @interface NSDecimalNumber (JAXBType) <JAXBType>
  900. @end
  901. /**
  902. * Implementation of the JAXB type for a big number.
  903. */
  904. @implementation NSDecimalNumber (JAXBType)
  905. /**
  906. * Read the XML type from the reader.
  907. *
  908. * @param reader The reader.
  909. * @return The NSDecimalNumber that was read from the reader.
  910. */
  911. + (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader
  912. {
  913. return [NSDecimalNumber decimalNumberWithString: [NSString stringWithUTF8String: (const char *) xmlTextReaderReadEntireNodeValue(reader)]];
  914. }
  915. /**
  916. * Read an XML type from an XML reader into an existing instance.
  917. *
  918. * @param reader The reader.
  919. * @param existing The existing instance into which to read values.
  920. */
  921. - (id) initWithReader: (xmlTextReaderPtr) reader
  922. {
  923. [NSException raise: @"XMLReadError"
  924. format: @"An existing decimal number cannot be modified."];
  925. return nil;
  926. }
  927. /**
  928. * Write the NSDecimalNumber to the writer.
  929. *
  930. * @param writer The writer.
  931. */
  932. - (void) writeXMLType: (xmlTextWriterPtr) writer
  933. {
  934. xmlTextWriterWriteString(writer, BAD_CAST [[self description] UTF8String]);
  935. }
  936. @end /*NSDecimalNumber (JAXBType)*/
  937. /**
  938. * Declaration of the JAXB type for a url.
  939. */
  940. @interface NSURL (JAXBType) <JAXBType>
  941. @end
  942. /**
  943. * Implementation of the JAXB type for a url.
  944. */
  945. @implementation NSURL (JAXBType)
  946. /**
  947. * Read the XML type from the reader.
  948. *
  949. * @param reader The reader.
  950. * @return The NSURL that was read from the reader.
  951. */
  952. + (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader
  953. {
  954. return [NSURL URLWithString: [NSString stringWithUTF8String: (const char *) xmlTextReaderReadEntireNodeValue(reader)]];
  955. }
  956. /**
  957. * Read an XML type from an XML reader into an existing instance.
  958. *
  959. * @param reader The reader.
  960. * @param existing The existing instance into which to read values.
  961. */
  962. - (id) initWithReader: (xmlTextReaderPtr) reader
  963. {
  964. [NSException raise: @"XMLReadError"
  965. format: @"An existing url cannot be modified."];
  966. return nil;
  967. }
  968. /**
  969. * Write the NSURL to the writer.
  970. *
  971. * @param writer The writer.
  972. */
  973. - (void) writeXMLType: (xmlTextWriterPtr) writer
  974. {
  975. xmlTextWriterWriteString(writer, BAD_CAST [[self absoluteString] UTF8String]);
  976. }
  977. @end /*NSURL (JAXBType)*/
  978. /**
  979. * Declaration of the JAXB type for binary data.
  980. */
  981. @interface NSData (JAXBType) <JAXBType>
  982. @end
  983. /**
  984. * Implementation of the JAXB type for a binary data.
  985. */
  986. @implementation NSData (JAXBType)
  987. /**
  988. * Read the XML type from the reader.
  989. *
  990. * @param reader The reader.
  991. * @return The NSData that was read from the reader.
  992. */
  993. + (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader
  994. {
  995. xmlChar *base64data = xmlTextReaderReadEntireNodeValue(reader);
  996. int len;
  997. unsigned char *data = _decode_base64(base64data, &len);
  998. NSData *wrappedData = [NSData dataWithBytesNoCopy: data length: len];
  999. free(base64data);
  1000. return wrappedData;
  1001. }
  1002. /**
  1003. * Read an XML type from an XML reader into an existing instance.
  1004. *
  1005. * @param reader The reader.
  1006. * @param existing The existing instance into which to read values.
  1007. */
  1008. - (id) initWithReader: (xmlTextReaderPtr) reader
  1009. {
  1010. [NSException raise: @"XMLReadError"
  1011. format: @"An existing NSData cannot be modified."];
  1012. return nil;
  1013. }
  1014. /**
  1015. * Write the NSData to the writer.
  1016. *
  1017. * @param writer The writer.
  1018. */
  1019. - (void) writeXMLType: (xmlTextWriterPtr) writer
  1020. {
  1021. xmlChar *out = _encode_base64((unsigned char *)[self bytes], [self length]);
  1022. xmlTextWriterWriteString(writer, out);
  1023. free(out);
  1024. }
  1025. @end /*NSData (JAXBType)*/
  1026. /**
  1027. * Declaration of the JAXB type for a big number.
  1028. */
  1029. @interface NSDate (JAXBType) <JAXBType>
  1030. @end
  1031. /**
  1032. * Implementation of the JAXB type for a big number.
  1033. */
  1034. @implementation NSDate (JAXBType)
  1035. /**
  1036. * Read the XML type from the reader.
  1037. *
  1038. * @param reader The reader.
  1039. * @return The NSDate that was read from the reader.
  1040. */
  1041. + (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader
  1042. {
  1043. return [NSCalendarDate readXMLType: reader];
  1044. }
  1045. /**
  1046. * Read an XML type from an XML reader into an existing instance.
  1047. *
  1048. * @param reader The reader.
  1049. * @param existing The existing instance into which to read values.
  1050. */
  1051. - (id) initWithReader: (xmlTextReaderPtr) reader
  1052. {
  1053. [NSException raise: @"XMLReadError"
  1054. format: @"An existing date cannot be modified."];
  1055. return nil;
  1056. }
  1057. /**
  1058. * Write the NSDate to the writer.
  1059. *
  1060. * @param writer The writer.
  1061. */
  1062. - (void) writeXMLType: (xmlTextWriterPtr) writer
  1063. {
  1064. NSDateFormatter *formatter = [[NSDateFormatter alloc] initWithDateFormat: @"%Y-%m-%dT%H:%M:%S %z" allowNaturalLanguage: NO];
  1065. xmlChar *timevalue = BAD_CAST [[formatter stringForObjectValue: self] UTF8String];
  1066. timevalue[19] = timevalue[20];
  1067. timevalue[20] = timevalue[21];
  1068. timevalue[21] = timevalue[22];
  1069. timevalue[22] = ':';
  1070. xmlTextWriterWriteString(writer, timevalue);
  1071. [formatter release];
  1072. }
  1073. @end /*NSDate (JAXBType)*/
  1074. /**
  1075. * Declaration of the JAXB type for a big number.
  1076. */
  1077. @interface NSCalendarDate (JAXBType) <JAXBType>
  1078. @end
  1079. /**
  1080. * Implementation of the JAXB type for a big number.
  1081. */
  1082. @implementation NSCalendarDate (JAXBType)
  1083. /**
  1084. * Read the XML type from the reader.
  1085. *
  1086. * @param reader The reader.
  1087. * @return The NSCalendarDate that was read from the reader.
  1088. */
  1089. + (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader
  1090. {
  1091. xmlChar *timevalue = xmlTextReaderReadEntireNodeValue(reader);
  1092. NSInteger year = 0;
  1093. NSUInteger month = 1, day = 1, hour = 0, minute = 0, second = 0;
  1094. NSTimeZone *tz = nil;
  1095. BOOL skip_time = NO;
  1096. int index = 0, token_index = 0, len = xmlStrlen(timevalue), offset_seconds = 0;
  1097. char token[len];
  1098. if (len > (index + 5) && timevalue[index + 4] == '-') {
  1099. //assume we're at yyyy-MM-dd
  1100. token_index = 0;
  1101. while (index < len && timevalue[index] != '-') {
  1102. token[token_index++] = timevalue[index++];
  1103. }
  1104. token[token_index] = '\0';
  1105. if (token_index != 4) {
  1106. [NSException raise: @"XMLReadError"
  1107. format: @"Unable to read dateTime %s; invalid year: %s", timevalue, token];
  1108. }
  1109. year = atoi(token);
  1110. index++;
  1111. //go to next '-' character.
  1112. token_index = 0;
  1113. while (index < len && timevalue[index] != '-') {
  1114. token[token_index++] = timevalue[index++];
  1115. }
  1116. token[token_index] = '\0';
  1117. if (token_index != 2) {
  1118. [NSException raise: @"XMLReadError"
  1119. format: @"Unable to read dateTime %s; invalid month: %s", timevalue, token];
  1120. }
  1121. month = atoi(token);
  1122. index++;
  1123. //go to 'T', 'Z', '+', or '-' character.
  1124. token_index = 0;
  1125. while (index < len && timevalue[index] != 'T' && timevalue[index] != 'Z' && timevalue[index] != '-' && timevalue[index] != '+') {
  1126. token[token_index++] = timevalue[index++];
  1127. }
  1128. token[token_index] = '\0';
  1129. if (token_index != 2) {
  1130. [NSException raise: @"XMLReadError"
  1131. format: @"Unable to read dateTime %s; invalid day of month: %s", timevalue, token];
  1132. }
  1133. day = atoi(token);
  1134. if (timevalue[index] != 'T') {
  1135. skip_time = YES;
  1136. }
  1137. if (timevalue[index] != '-') {
  1138. index++;
  1139. }
  1140. }
  1141. if (skip_time == NO || (len > (index + 3) && timevalue[index + 2] == ':')) {
  1142. //assume we're at HH:mm:ss
  1143. //go to ':' character.
  1144. token_index = 0;
  1145. while (index < len && timevalue[index] != ':') {
  1146. token[token_index++] = timevalue[index++];
  1147. }
  1148. token[token_index] = '\0';
  1149. if (token_index != 2) {
  1150. [NSException raise: @"XMLReadError"
  1151. format: @"Unable to read dateTime %s; invalid hour: %s", timevalue, token];
  1152. }
  1153. hour = atoi(token);
  1154. index++;
  1155. //go to ':' character.
  1156. token_index = 0;
  1157. while (index < len && timevalue[index] != ':') {
  1158. token[token_index++] = timevalue[index++];
  1159. }
  1160. token[token_index] = '\0';
  1161. if (token_index != 2) {
  1162. [NSException raise: @"XMLReadError"
  1163. format: @"Unable to read dateTime %s; invalid minute: %s", timevalue, token];
  1164. }
  1165. minute = atoi(token);
  1166. index++;
  1167. //go to '+' or '-' or 'Z' character.
  1168. token_index = 0;
  1169. while (index < len && timevalue[index] != '+' && timevalue[index] != '-' && timevalue[index] != 'Z') {
  1170. token[token_index++] = timevalue[index++];
  1171. }
  1172. token[token_index] = '\0';
  1173. if (token_index == 0) {
  1174. [NSException raise: @"XMLReadError"
  1175. format: @"Unable to read dateTime %s; invalid seconds: %s", timevalue, token];
  1176. }
  1177. second = (NSUInteger) atof(token);
  1178. if (timevalue[index] != '-') {
  1179. index++;
  1180. }
  1181. }
  1182. //go to ':' character.
  1183. token_index = 0;
  1184. while (index < len && timevalue[index] != ':') {
  1185. token[token_index++] = timevalue[index++];
  1186. }
  1187. token[token_index] = '\0';
  1188. offset_seconds += atoi(token) * 60 * 60;
  1189. index++;
  1190. //go to end.
  1191. token_index = 0;
  1192. while (index < len) {
  1193. token[token_index++] = timevalue[index++];
  1194. }
  1195. token[token_index] = '\0';
  1196. offset_seconds += atoi(token) * 60;
  1197. tz = [NSTimeZone timeZoneForSecondsFromGMT: offset_seconds];
  1198. free(timevalue);
  1199. return [NSCalendarDate dateWithYear: year month: month day: day hour: hour minute: minute second: second timeZone: tz];
  1200. }
  1201. /**
  1202. * Read an XML type from an XML reader into an existing instance.
  1203. *
  1204. * @param reader The reader.
  1205. * @param existing The existing instance into which to read values.
  1206. */
  1207. - (id) initWithReader: (xmlTextReaderPtr) reader
  1208. {
  1209. [NSException raise: @"XMLReadError"
  1210. format: @"An existing date cannot be modified."];
  1211. return nil;
  1212. }
  1213. /**
  1214. * Write the NSDate to the writer.
  1215. *
  1216. * @param writer The writer.
  1217. */
  1218. - (void) writeXMLType: (xmlTextWriterPtr) writer
  1219. {
  1220. [super writeXMLType: writer];
  1221. }
  1222. @end /*NSCalendarDate (JAXBType)*/
  1223. #endif /* ENUNCIATE_OBJC_CLASSES */
  1224. #ifndef ENUNCIATE_XML_OBJC_PRIMITIVE_FUNCTIONS
  1225. #define ENUNCIATE_XML_OBJC_PRIMITIVE_FUNCTIONS
  1226. /*******************boolean************************************/
  1227. /**
  1228. * Read a boolean value from the reader.
  1229. *
  1230. * @param reader The reader (pointing at a node with a value).
  1231. * @return YES if "true" was read. NO otherwise.
  1232. */
  1233. static BOOL *xmlTextReaderReadBooleanType(xmlTextReaderPtr reader) {
  1234. xmlChar *nodeValue = xmlTextReaderReadEntireNodeValue(reader);
  1235. BOOL *value = malloc(sizeof(BOOL));
  1236. *value = (xmlStrcmp(BAD_CAST "true", nodeValue) == 0) ? YES : NO;
  1237. free(nodeValue);
  1238. return value;
  1239. }
  1240. /**
  1241. * Write a boolean value to the writer.
  1242. *
  1243. * @param writer The writer.
  1244. * @param value The value to be written.
  1245. * @return the bytes written (may be 0 because of buffering) or -1 in case of error.
  1246. */
  1247. static int xmlTextWriterWriteBooleanType(xmlTextWriterPtr writer, BOOL *value) {
  1248. if (*value) {
  1249. return xmlTextWriterWriteString(writer, BAD_CAST "false");
  1250. }
  1251. else {
  1252. return xmlTextWriterWriteString(writer, BAD_CAST "true");
  1253. }
  1254. }
  1255. /*******************byte************************************/
  1256. /**
  1257. * Read a byte value from the reader.
  1258. *
  1259. * @param reader The reader (pointing at a node with a value).
  1260. * @return the byte.
  1261. */
  1262. static unsigned char *xmlTextReaderReadByteType(xmlTextReaderPtr reader) {
  1263. xmlChar *nodeValue = xmlTextReaderReadEntireNodeValue(reader);
  1264. unsigned char *value = malloc(sizeof(unsigned char));
  1265. *value = (unsigned char) atoi((char *) nodeValue);
  1266. free(nodeValue);
  1267. return value;
  1268. }
  1269. /**
  1270. * Write a byte value to the writer.
  1271. *
  1272. * @param writer The writer.
  1273. * @param value The value to be written.
  1274. * @return the bytes written (may be 0 because of buffering) or -1 in case of error.
  1275. */
  1276. static int xmlTextWriterWriteByteType(xmlTextWriterPtr writer, unsigned char *value) {
  1277. return xmlTextWriterWriteFormatString(writer, "%i", *value);
  1278. }
  1279. /*******************double************************************/
  1280. /**
  1281. * Read a double value from the reader.
  1282. *
  1283. * @param reader The reader (pointing at a node with a value).
  1284. * @return the double.
  1285. */
  1286. static double *xmlTextReaderReadDoubleType(xmlTextReaderPtr reader) {
  1287. xmlChar *nodeValue = xmlTextReaderReadEntireNodeValue(reader);
  1288. double *value = malloc(sizeof(double));
  1289. *value = atof((char *) nodeValue);
  1290. free(nodeValue);
  1291. return value;
  1292. }
  1293. /**
  1294. * Write a double value to the writer.
  1295. *
  1296. * @param writer The writer.
  1297. * @param value The value to be written.
  1298. * @return the bytes written (may be 0 because of buffering) or -1 in case of error.
  1299. */
  1300. static int xmlTextWriterWriteDoubleType(xmlTextWriterPtr writer, double *value) {
  1301. return xmlTextWriterWriteFormatString(writer, "%f", *value);
  1302. }
  1303. /*******************float************************************/
  1304. /**
  1305. * Read a float value from the reader.
  1306. *
  1307. * @param reader The reader (pointing at a node with a value).
  1308. * @return the float.
  1309. */
  1310. static float *xmlTextReaderReadFloatType(xmlTextReaderPtr reader) {
  1311. xmlChar *nodeValue = xmlTextReaderReadEntireNodeValue(reader);
  1312. float *value = malloc(sizeof(float));
  1313. *value = atof((char *)nodeValue);
  1314. free(nodeValue);
  1315. return value;
  1316. }
  1317. /**
  1318. * Write a float value to the writer.
  1319. *
  1320. * @param writer The writer.
  1321. * @param value The value to be written.
  1322. * @return the bytes written (may be 0 because of buffering) or -1 in case of error.
  1323. */
  1324. static int xmlTextWriterWriteFloatType(xmlTextWriterPtr writer, float *value) {
  1325. return xmlTextWriterWriteFormatString(writer, "%f", *value);
  1326. }
  1327. /*******************int************************************/
  1328. /**
  1329. * Read a int value from the reader.
  1330. *
  1331. * @param reader The reader (pointing at a node with a value).
  1332. * @param value The value to be written.
  1333. * @return the int.
  1334. */
  1335. static int *xmlTextReaderReadIntType(xmlTextReaderPtr reader) {
  1336. xmlChar *nodeValue = xmlTextReaderReadEntireNodeValue(reader);
  1337. int *value = malloc(sizeof(int));
  1338. *value = atoi((char *)nodeValue);
  1339. free(nodeValue);
  1340. return value;
  1341. }
  1342. /**
  1343. * Write a int value to the writer.
  1344. *
  1345. * @param writer The writer.
  1346. * @param value The value to be written.
  1347. * @return the bytes written (may be 0 because of buffering) or -1 in case of error.
  1348. */
  1349. static int xmlTextWriterWriteIntType(xmlTextWriterPtr writer, int *value) {
  1350. return xmlTextWriterWriteFormatString(writer, "%i", *value);
  1351. }
  1352. /*******************long************************************/
  1353. /**
  1354. * Read a long value from the reader.
  1355. *
  1356. * @param reader The reader (pointing at a node with a value).
  1357. * @return the long.
  1358. */
  1359. static long *xmlTextReaderReadLongType(xmlTextReaderPtr reader) {
  1360. xmlChar *nodeValue = xmlTextReaderReadEntireNodeValue(reader);
  1361. long *value = malloc(sizeof(long));
  1362. *value = atol((char *)nodeValue);
  1363. free(nodeValue);
  1364. return value;
  1365. }
  1366. /**
  1367. * Write a long value to the writer.
  1368. *
  1369. * @param writer The writer.
  1370. * @param value The value to be written.
  1371. * @return the bytes written (may be 0 because of buffering) or -1 in case of error.
  1372. */
  1373. static int xmlTextWriterWriteLongType(xmlTextWriterPtr writer, long *value) {
  1374. return xmlTextWriterWriteFormatString(writer, "%ld", *value);
  1375. }
  1376. /*******************short************************************/
  1377. /**
  1378. * Read a short value from the reader.
  1379. *
  1380. * @param reader The reader (pointing at a node with a value).
  1381. * @return the short.
  1382. */
  1383. static short *xmlTextReaderReadShortType(xmlTextReaderPtr reader) {
  1384. xmlChar *nodeValue = xmlTextReaderReadEntireNodeValue(reader);
  1385. short *value = malloc(sizeof(short));
  1386. *value = atoi((char *)nodeValue);
  1387. free(nodeValue);
  1388. return value;
  1389. }
  1390. /**
  1391. * Write a short value to the writer.
  1392. *
  1393. * @param writer The writer.
  1394. * @param value The value to be written.
  1395. * @return the bytes written (may be 0 because of buffering) or -1 in case of error.
  1396. */
  1397. static int xmlTextWriterWriteShortType(xmlTextWriterPtr writer, short *value) {
  1398. return xmlTextWriterWriteFormatString(writer, "%h", *value);
  1399. }
  1400. /*******************char************************************/
  1401. /**
  1402. * Read a character value from the reader.
  1403. *
  1404. * @param reader The reader (pointing at a node with a value).
  1405. * @return the character.
  1406. */
  1407. static xmlChar *xmlTextReaderReadCharacterType(xmlTextReaderPtr reader) {
  1408. return xmlTextReaderReadEntireNodeValue(reader);
  1409. }
  1410. /**
  1411. * Write a character value to the writer.
  1412. *
  1413. * @param writer The writer.
  1414. * @param value The value to be written.
  1415. * @return the bytes written (may be 0 because of buffering) or -1 in case of error.
  1416. */
  1417. static int xmlTextWriterWriteCharacterType(xmlTextWriterPtr writer, xmlChar *value) {
  1418. return xmlTextWriterWriteString(writer, value);
  1419. }
  1420. #endif /* ENUNCIATE_XML_OBJC_PRIMITIVE_FUNCTIONS */
  1421. /**
  1422. * An assertion value.
  1423. @author Rob Lyon
  1424. */
  1425. @implementation FSFAMILYTREEV2AssertionValue
  1426. /**
  1427. * the id of the value.
  1428. */
  1429. - (NSString *) id
  1430. {
  1431. return _id;
  1432. }
  1433. /**
  1434. * the id of the value.
  1435. */
  1436. - (void) setId: (NSString *) newId
  1437. {
  1438. [newId retain];
  1439. [_id release];
  1440. _id = newId;
  1441. }
  1442. /**
  1443. * The title of the type in the case of user-defined characteristics.
  1444. */
  1445. - (NSString *) title
  1446. {
  1447. return _title;
  1448. }
  1449. /**
  1450. * The title of the type in the case of user-defined characteristics.
  1451. */
  1452. - (void) setTitle: (NSString *) newTitle
  1453. {
  1454. [newTitle retain];
  1455. [_title release];
  1456. _title = newTitle;
  1457. }
  1458. - (void) dealloc
  1459. {
  1460. [self setId: nil];
  1461. [self setTitle: nil];
  1462. [super dealloc];
  1463. }
  1464. @end /* implementation FSFAMILYTREEV2AssertionValue */
  1465. /**
  1466. * Internal, private interface for JAXB reading and writing.
  1467. */
  1468. @interface FSFAMILYTREEV2AssertionValue (JAXB) <JAXBReading, JAXBWriting, JAXBType>
  1469. @end /*interface FSFAMILYTREEV2AssertionValue (JAXB)*/
  1470. /**
  1471. * Internal, private implementation for JAXB reading and writing.
  1472. */
  1473. @implementation FSFAMILYTREEV2AssertionValue (JAXB)
  1474. /**
  1475. * Read an instance of FSFAMILYTREEV2AssertionValue from an XML reader.
  1476. *
  1477. * @param reader The reader.
  1478. * @return An instance of FSFAMILYTREEV2AssertionValue defined by the XML reader.
  1479. */
  1480. + (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader
  1481. {
  1482. FSFAMILYTREEV2AssertionValue *_fSFAMILYTREEV2AssertionValue = [[FSFAMILYTREEV2AssertionValue alloc] init];
  1483. NS_DURING
  1484. {
  1485. [_fSFAMILYTREEV2AssertionValue initWithReader: reader];
  1486. }
  1487. NS_HANDLER
  1488. {
  1489. [_fSFAMILYTREEV2AssertionValue dealloc];
  1490. _fSFAMILYTREEV2AssertionValue = nil;
  1491. [localException raise];
  1492. }
  1493. NS_ENDHANDLER
  1494. [_fSFAMILYTREEV2AssertionValue autorelease];
  1495. return _fSFAMILYTREEV2AssertionValue;
  1496. }
  1497. /**
  1498. * Initialize this instance of FSFAMILYTREEV2AssertionValue according to
  1499. * the XML being read from the reader.
  1500. *
  1501. * @param reader The reader.
  1502. */
  1503. - (id) initWithReader: (xmlTextReaderPtr) reader
  1504. {
  1505. return [super initWithReader: reader];
  1506. }
  1507. /**
  1508. * Write the XML for this instance of FSFAMILYTREEV2AssertionValue to the writer.
  1509. * Note that since we're only writing the XML type,
  1510. * No start/end element will be written.
  1511. *
  1512. * @param reader The reader.
  1513. */
  1514. - (void) writeXMLType: (xmlTextWriterPtr) writer
  1515. {
  1516. [super writeXMLType:writer];
  1517. }
  1518. //documentation inherited.
  1519. - (BOOL) readJAXBAttribute: (xmlTextReaderPtr) reader
  1520. {
  1521. void *_child_accessor;
  1522. if ([super readJAXBAttribute: reader]) {
  1523. return YES;
  1524. }
  1525. if ((xmlStrcmp(BAD_CAST "id", xmlTextReaderConstLocalName(reader)) == 0) && (xmlTextReaderConstNamespaceUri(reader) == NULL)) {
  1526. #if DEBUG_ENUNCIATE > 1
  1527. NSLog(@"Attempting to read attribute {}id...");
  1528. #endif
  1529. [self setId: (NSString*) [NSString readXMLType: reader]];
  1530. #if DEBUG_ENUNCIATE > 1
  1531. NSLog(@"successfully read attribute {}id...");
  1532. #endif
  1533. return YES;
  1534. }
  1535. return NO;
  1536. }
  1537. //documentation inherited.
  1538. - (BOOL) readJAXBValue: (xmlTextReaderPtr) reader
  1539. {
  1540. return [super readJAXBValue: reader];
  1541. }
  1542. //documentation inherited.
  1543. - (BOOL) readJAXBChildElement: (xmlTextReaderPtr) reader
  1544. {
  1545. id __child;
  1546. void *_child_accessor;
  1547. int status, depth;
  1548. if ([super readJAXBChildElement: reader]) {
  1549. return YES;
  1550. }
  1551. if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT
  1552. && xmlStrcmp(BAD_CAST "title", xmlTextReaderConstLocalName(reader)) == 0
  1553. && xmlStrcmp(BAD_CAST "http://api.familysearch.org/familytree/v2", xmlTextReaderConstNamespaceUri(reader)) == 0) {
  1554. #if DEBUG_ENUNCIATE > 1
  1555. NSLog(@"Attempting to read choice {http://api.familysearch.org/familytree/v2}title of type {http://www.w3.org/2001/XMLSchema}string.");
  1556. #endif
  1557. __child = [NSString readXMLType: reader];
  1558. #if DEBUG_ENUNCIATE > 1
  1559. NSLog(@"successfully read choice {http://api.familysearch.org/familytree/v2}title of type {http://www.w3.org/2001/XMLSchema}string.");
  1560. #endif
  1561. [self setTitle: __child];
  1562. return YES;
  1563. } //end "if choice"
  1564. return NO;
  1565. }
  1566. //documentation inherited.
  1567. - (int) readUnknownJAXBChildElement: (xmlTextReaderPtr) reader
  1568. {
  1569. return [super readUnknownJAXBChildElement: reader];
  1570. }
  1571. //documentation inherited.
  1572. - (void) readUnknownJAXBAttribute: (xmlTextReaderPtr) reader
  1573. {
  1574. [super readUnknownJAXBAttribute: reader];
  1575. }
  1576. //documentation inherited.
  1577. - (void) writeJAXBAttributes: (xmlTextWriterPtr) writer
  1578. {
  1579. int status;
  1580. [super writeJAXBAttributes: writer];
  1581. if ([self id]) {
  1582. status = xmlTextWriterStartAttributeNS(writer, NULL, BAD_CAST "id", NULL);
  1583. if (status < 0) {
  1584. [NSException raise: @"XMLWriteError"
  1585. format: @"Error writing start attribute {}id."];
  1586. }
  1587. #if DEBUG_ENUNCIATE > 1
  1588. NSLog(@"writing attribute {}id...");
  1589. #endif
  1590. [[self id] writeXMLType: writer];
  1591. #if DEBUG_ENUNCIATE > 1
  1592. NSLog(@"successfully wrote attribute {}id...");
  1593. #endif
  1594. status = xmlTextWriterEndAttribute(writer);
  1595. if (status < 0) {
  1596. [NSException raise: @"XMLWriteError"
  1597. format: @"Error writing end attribute {}id."];
  1598. }
  1599. }
  1600. }
  1601. //documentation inherited.
  1602. - (void) writeJAXBValue: (xmlTextWriterPtr) writer
  1603. {
  1604. [super writeJAXBValue: writer];
  1605. }
  1606. /**
  1607. * Method for writing the child elements.
  1608. *
  1609. * @param writer The writer.
  1610. */
  1611. - (void) writeJAXBChildElements: (xmlTextWriterPtr) writer
  1612. {
  1613. int status;
  1614. id __item;
  1615. NSEnumerator *__enumerator;
  1616. [super writeJAXBChildElements: writer];
  1617. if ([self title]) {
  1618. status = xmlTextWriterStartElementNS(writer, BAD_CAST "familytree_v2", BAD_CAST "title", NULL);
  1619. if (status < 0) {
  1620. [NSException raise: @"XMLWriteError"
  1621. format: @"Error writing start child element {http://api.familysearch.org/familytree/v2}title."];
  1622. }
  1623. #if DEBUG_ENUNCIATE > 1
  1624. NSLog(@"writing element {http://api.familysearch.org/familytree/v2}title...");
  1625. #endif
  1626. [[self title] writeXMLType: writer];
  1627. #if DEBUG_ENUNCIATE > 1
  1628. NSLog(@"successfully wrote element {http://api.familysearch.org/familytree/v2}title...");
  1629. #endif
  1630. status = xmlTextWriterEndElement(writer);
  1631. if (status < 0) {
  1632. [NSException raise: @"XMLWriteError"
  1633. format: @"Error writing end child element {http://api.familysearch.org/familytree/v2}title."];
  1634. }
  1635. }
  1636. }
  1637. @end /* implementation FSFAMILYTREEV2AssertionValue (JAXB) */
  1638. /**
  1639. * @author Rob Lyon
  1640. */
  1641. @implementation FSFAMILYTREEV2ChangeAction
  1642. /**
  1643. * the change action type.
  1644. */
  1645. - (enum FSFAMILYTREEV2ChangeActionType *) type
  1646. {
  1647. return _type;
  1648. }
  1649. /**
  1650. * the change action type.
  1651. */
  1652. - (void) setType: (enum FSFAMILYTREEV2ChangeActionType *) newType
  1653. {
  1654. if (_type != NULL) {
  1655. free(_type);
  1656. }
  1657. _type = newType;
  1658. }
  1659. /**
  1660. * the action value.
  1661. */
  1662. - (NSString *) value
  1663. {
  1664. return _value;
  1665. }
  1666. /**
  1667. * the action value.
  1668. */
  1669. - (void) setValue: (NSString *) newValue
  1670. {
  1671. [newValue retain];
  1672. [_value release];
  1673. _value = newValue;
  1674. }
  1675. - (void) dealloc
  1676. {
  1677. [self setType: NULL];
  1678. [self setValue: nil];
  1679. [super dealloc];
  1680. }
  1681. @end /* implementation FSFAMILYTREEV2ChangeAction */
  1682. /**
  1683. * Internal, private interface for JAXB reading and writing.
  1684. */
  1685. @interface FSFAMILYTREEV2ChangeAction (JAXB) <JAXBReading, JAXBWriting, JAXBType>
  1686. @end /*interface FSFAMILYTREEV2ChangeAction (JAXB)*/
  1687. /**
  1688. * Internal, private implementation for JAXB reading and writing.
  1689. */
  1690. @implementation FSFAMILYTREEV2ChangeAction (JAXB)
  1691. /**
  1692. * Read an instance of FSFAMILYTREEV2ChangeAction from an XML reader.
  1693. *
  1694. * @param reader The reader.
  1695. * @return An instance of FSFAMILYTREEV2ChangeAction defined by the XML reader.
  1696. */
  1697. + (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader
  1698. {
  1699. FSFAMILYTREEV2ChangeAction *_fSFAMILYTREEV2ChangeAction = [[FSFAMILYTREEV2ChangeAction alloc] init];
  1700. NS_DURING
  1701. {
  1702. [_fSFAMILYTREEV2ChangeAction initWithReader: reader];
  1703. }
  1704. NS_HANDLER
  1705. {
  1706. [_fSFAMILYTREEV2ChangeAction dealloc];
  1707. _fSFAMILYTREEV2ChangeAction = nil;
  1708. [localException raise];
  1709. }
  1710. NS_ENDHANDLER
  1711. [_fSFAMILYTREEV2ChangeAction autorelease];
  1712. return _fSFAMILYTREEV2ChangeAction;
  1713. }
  1714. /**
  1715. * Initialize this instance of FSFAMILYTREEV2ChangeAction according to
  1716. * the XML being read from the reader.
  1717. *
  1718. * @param reader The reader.
  1719. */
  1720. - (id) initWithReader: (xmlTextReaderPtr) reader
  1721. {
  1722. return [super initWithReader: reader];
  1723. }
  1724. /**
  1725. * Write the XML for this instance of FSFAMILYTREEV2ChangeAction to the writer.
  1726. * Note that since we're only writing the XML type,
  1727. * No start/end element will be written.
  1728. *
  1729. * @param reader The reader.
  1730. */
  1731. - (void) writeXMLType: (xmlTextWriterPtr) writer
  1732. {
  1733. [super writeXMLType:writer];
  1734. }
  1735. //documentation inherited.
  1736. - (BOOL) readJAXBAttribute: (xmlTextReaderPtr) reader
  1737. {
  1738. void *_child_accessor;
  1739. if ([super readJAXBAttribute: reader]) {
  1740. return YES;
  1741. }
  1742. if ((xmlStrcmp(BAD_CAST "type", xmlTextReaderConstLocalName(reader)) == 0) && (xmlTextReaderConstNamespaceUri(reader) == NULL)) {
  1743. #if DEBUG_ENUNCIATE > 1
  1744. NSLog(@"Attempting to read attribute {}type...");
  1745. #endif
  1746. _child_accessor = xmlTextReaderReadFSFAMILYTREEV2ChangeActionTypeType(reader);
  1747. if (_child_accessor == NULL) {
  1748. //panic: unable to read the attribute value for some reason.
  1749. [self dealloc];
  1750. [NSException raise: @"XMLReadError"
  1751. format: @"Error reading attribute {}type."];
  1752. }
  1753. [self setType: ((enum FSFAMILYTREEV2ChangeActionType*) _child_accessor)];
  1754. #if DEBUG_ENUNCIATE > 1
  1755. NSLog(@"successfully read attribute {}type...");
  1756. #endif
  1757. return YES;
  1758. }
  1759. return NO;
  1760. }
  1761. //documentation inherited.
  1762. - (BOOL) readJAXBValue: (xmlTextReaderPtr) reader
  1763. {
  1764. #if DEBUG_ENUNCIATE > 1
  1765. NSLog(@"Attempting to read element value...");
  1766. #endif
  1767. if (xmlTextReaderIsEmptyElement(reader) == 0) {
  1768. [self setValue: (NSString *) [NSString readXMLType: reader]];
  1769. }
  1770. else {
  1771. [self setValue: @""];
  1772. }
  1773. #if DEBUG_ENUNCIATE > 1
  1774. NSLog(@"successfully read element value...");
  1775. #endif
  1776. return YES;
  1777. }
  1778. //documentation inherited.
  1779. - (BOOL) readJAXBChildElement: (xmlTextReaderPtr) reader
  1780. {
  1781. return [super readJAXBChildElement: reader];
  1782. }
  1783. //documentation inherited.
  1784. - (int) readUnknownJAXBChildElement: (xmlTextReaderPtr) reader
  1785. {
  1786. return [super readUnknownJAXBChildElement: reader];
  1787. }
  1788. //documentation inherited.
  1789. - (void) readUnknownJAXBAttribute: (xmlTextReaderPtr) reader
  1790. {
  1791. [super readUnknownJAXBAttribute: reader];
  1792. }
  1793. //documentation inherited.
  1794. - (void) writeJAXBAttributes: (xmlTextWriterPtr) writer
  1795. {
  1796. int status;
  1797. [super writeJAXBAttributes: writer];
  1798. if ([self type] != NULL) {
  1799. status = xmlTextWriterStartAttributeNS(writer, NULL, BAD_CAST "type", NULL);
  1800. if (status < 0) {
  1801. [NSException raise: @"XMLWriteError"
  1802. format: @"Error writing start attribute {}type."];
  1803. }
  1804. #if DEBUG_ENUNCIATE > 1
  1805. NSLog(@"writing attribute {}type...");
  1806. #endif
  1807. status = xmlTextWriterWriteFSFAMILYTREEV2ChangeActionTypeType(writer, [self type]);
  1808. if (status < 0) {
  1809. [NSException raise: @"XMLWriteError"
  1810. format: @"Error writing attribute {}type."];
  1811. }
  1812. #if DEBUG_ENUNCIATE > 1
  1813. NSLog(@"successfully wrote attribute {}type...");
  1814. #endif
  1815. status = xmlTextWriterEndAttribute(writer);
  1816. if (status < 0) {
  1817. [NSException raise: @"XMLWriteError"
  1818. format: @"Error writing end attribute {}type."];
  1819. }
  1820. }
  1821. }
  1822. //documentation inherited.
  1823. - (void) writeJAXBValue: (xmlTextWriterPtr) writer
  1824. {
  1825. #if DEBUG_ENUNCIATE > 1
  1826. NSLog(@"writing element value...");
  1827. #endif
  1828. [[self value] writeXMLType: writer];
  1829. #if DEBUG_ENUNCIATE > 1
  1830. NSLog(@"successfully wrote element value...");
  1831. #endif
  1832. }
  1833. /**
  1834. * Method for writing the child elements.
  1835. *
  1836. * @param writer The writer.
  1837. */
  1838. - (void) writeJAXBChildElements: (xmlTextWriterPtr) writer
  1839. {
  1840. [super writeJAXBChildElements: writer];
  1841. }
  1842. @end /* implementation FSFAMILYTREEV2ChangeAction (JAXB) */
  1843. /**
  1844. * @author Rob Lyon
  1845. */
  1846. @implementation FSFAMILYTREEV2Changes
  1847. /**
  1848. * The count of changes.
  1849. */
  1850. - (int) count
  1851. {
  1852. return _count;
  1853. }
  1854. /**
  1855. * The count of changes.
  1856. */
  1857. - (void) setCount: (int) newCount
  1858. {
  1859. _count = newCount;
  1860. }
  1861. /**
  1862. * The changes.
  1863. */
  1864. - (NSArray *) changeList
  1865. {
  1866. return _changeList;
  1867. }
  1868. /**
  1869. * The changes.
  1870. */
  1871. - (void) setChangeList: (NSArray *) newChangeList
  1872. {
  1873. [newChangeList retain];
  1874. [_changeList release];
  1875. _changeList = newChangeList;
  1876. }
  1877. - (void) dealloc
  1878. {
  1879. [self setChangeList: nil];
  1880. [super dealloc];
  1881. }
  1882. @end /* implementation FSFAMILYTREEV2Changes */
  1883. /**
  1884. * Internal, private interface for JAXB reading and writing.
  1885. */
  1886. @interface FSFAMILYTREEV2Changes (JAXB) <JAXBReading, JAXBWriting, JAXBType>
  1887. @end /*interface FSFAMILYTREEV2Changes (JAXB)*/
  1888. /**
  1889. * Internal, private implementation for JAXB reading and writing.
  1890. */
  1891. @implementation FSFAMILYTREEV2Changes (JAXB)
  1892. /**
  1893. * Read an instance of FSFAMILYTREEV2Changes from an XML reader.
  1894. *
  1895. * @param reader The reader.
  1896. * @return An instance of FSFAMILYTREEV2Changes defined by the XML reader.
  1897. */
  1898. + (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader
  1899. {
  1900. FSFAMILYTREEV2Changes *_fSFAMILYTREEV2Changes = [[FSFAMILYTREEV2Changes alloc] init];
  1901. NS_DURING
  1902. {
  1903. [_fSFAMILYTREEV2Changes initWithReader: reader];
  1904. }
  1905. NS_HANDLER
  1906. {
  1907. [_fSFAMILYTREEV2Changes dealloc];
  1908. _fSFAMILYTREEV2Changes = nil;
  1909. [localException raise];
  1910. }
  1911. NS_ENDHANDLER
  1912. [_fSFAMILYTREEV2Changes autorelease];
  1913. return _fSFAMILYTREEV2Changes;
  1914. }
  1915. /**
  1916. * Initialize this instance of FSFAMILYTREEV2Changes according to
  1917. * the XML being read from the reader.
  1918. *
  1919. * @param reader The reader.
  1920. */
  1921. - (id) initWithReader: (xmlTextReaderPtr) reader
  1922. {
  1923. return [super initWithReader: reader];
  1924. }
  1925. /**
  1926. * Write the XML for this instance of FSFAMILYTREEV2Changes to the writer.
  1927. * Note that since we're only writing the XML type,
  1928. * No start/end element will be written.
  1929. *
  1930. * @param reader The reader.
  1931. */
  1932. - (void) writeXMLType: (xmlTextWriterPtr) writer
  1933. {
  1934. [super writeXMLType:writer];
  1935. }
  1936. //documentation inherited.
  1937. - (BOOL) readJAXBAttribute: (xmlTextReaderPtr) reader
  1938. {
  1939. void *_child_accessor;
  1940. if ([super readJAXBAttribute: reader]) {
  1941. return YES;
  1942. }
  1943. if ((xmlStrcmp(BAD_CAST "count", xmlTextReaderConstLocalName(reader)) == 0) && (xmlTextReaderConstNamespaceUri(reader) == NULL)) {
  1944. #if DEBUG_ENUNCIATE > 1
  1945. NSLog(@"Attempting to read attribute {}count...");
  1946. #endif
  1947. _child_accessor = xmlTextReaderReadIntType(reader);
  1948. if (_child_accessor == NULL) {
  1949. //panic: unable to read the attribute value for some reason.
  1950. [self dealloc];
  1951. [NSException raise: @"XMLReadError"
  1952. format: @"Error reading attribute {}count."];
  1953. }
  1954. [self setCount: *((int*) _child_accessor)];
  1955. free(_child_accessor);
  1956. #if DEBUG_ENUNCIATE > 1
  1957. NSLog(@"successfully read attribute {}count...");
  1958. #endif
  1959. return YES;
  1960. }
  1961. return NO;
  1962. }
  1963. //documentation inherited.
  1964. - (BOOL) readJAXBValue: (xmlTextReaderPtr) reader
  1965. {
  1966. return [super readJAXBValue: reader];
  1967. }
  1968. //documentation inherited.
  1969. - (BOOL) readJAXBChildElement: (xmlTextReaderPtr) reader
  1970. {
  1971. id __child;
  1972. void *_child_accessor;
  1973. int status, depth;
  1974. if ([super readJAXBChildElement: reader]) {
  1975. return YES;
  1976. }
  1977. if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT
  1978. && xmlStrcmp(BAD_CAST "change", xmlTextReaderConstLocalName(reader)) == 0
  1979. && xmlStrcmp(BAD_CAST "http://api.familysearch.org/familytree/v2", xmlTextReaderConstNamespaceUri(reader)) == 0) {
  1980. #if DEBUG_ENUNCIATE > 1
  1981. NSLog(@"Attempting to read choice {http://api.familysearch.org/familytree/v2}change of type {http://api.familysearch.org/familytree/v2}change.");
  1982. #endif
  1983. __child = [FSFAMILYTREEV2Change readXMLType: reader];
  1984. #if DEBUG_ENUNCIATE > 1
  1985. NSLog(@"successfully read choice {http://api.familysearch.org/familytree/v2}change of type {http://api.familysearch.org/familytree/v2}change.");
  1986. #endif
  1987. if ([self changeList]) {
  1988. [self setChangeList: [[self changeList] arrayByAddingObject: __child]];
  1989. }
  1990. else {
  1991. [self setChangeList: [NSArray arrayWithObject: __child]];
  1992. }
  1993. return YES;
  1994. } //end "if choice"
  1995. return NO;
  1996. }
  1997. //documentation inherited.
  1998. - (int) readUnknownJAXBChildElement: (xmlTextReaderPtr) reader
  1999. {
  2000. return [super readUnknownJAXBChildElement: reader];
  2001. }
  2002. //documentation inherited.
  2003. - (void) readUnknownJAXBAttribute: (xmlTextReaderPtr) reader
  2004. {
  2005. [super readUnknownJAXBAttribute: reader];
  2006. }
  2007. //documentation inherited.
  2008. - (void) writeJAXBAttributes: (xmlTextWriterPtr) writer
  2009. {
  2010. int status;
  2011. [super writeJAXBAttributes: writer];
  2012. if (YES) { //always write the primitive attributes...
  2013. status = xmlTextWriterStartAttributeNS(writer, NULL, BAD_CAST "count", NULL);
  2014. if (status < 0) {
  2015. [NSException raise: @"XMLWriteError"
  2016. format: @"Error writing start attribute {}count."];
  2017. }
  2018. #if DEBUG_ENUNCIATE > 1
  2019. NSLog(@"writing attribute {}count...");
  2020. #endif
  2021. status = xmlTextWriterWriteIntType(writer, &_count);
  2022. if (status < 0) {
  2023. [NSException raise: @"XMLWriteError"
  2024. format: @"Error writing attribute {}count."];
  2025. }
  2026. #if DEBUG_ENUNCIATE > 1
  2027. NSLog(@"successfully wrote attribute {}count...");
  2028. #endif
  2029. status = xmlTextWriterEndAttribute(writer);
  2030. if (status < 0) {
  2031. [NSException raise: @"XMLWriteError"
  2032. format: @"Error writing end attribute {}count."];
  2033. }
  2034. }
  2035. }
  2036. //documentation inherited.
  2037. - (void) writeJAXBValue: (xmlTextWriterPtr) writer
  2038. {
  2039. [super writeJAXBValue: writer];
  2040. }
  2041. /**
  2042. * Method for writing the child elements.
  2043. *
  2044. * @param writer The writer.
  2045. */
  2046. - (void) writeJAXBChildElements: (xmlTextWriterPtr) writer
  2047. {
  2048. int status;
  2049. id __item;
  2050. NSEnumerator *__enumerator;
  2051. [super writeJAXBChildElements: writer];
  2052. if ([self changeList]) {
  2053. __enumerator = [[self changeList] objectEnumerator];
  2054. while ( (__item = [__enumerator nextObject]) ) {
  2055. status = xmlTextWriterStartElementNS(writer, BAD_CAST "familytree_v2", BAD_CAST "change", NULL);
  2056. if (status < 0) {
  2057. [NSException raise: @"XMLWriteError"
  2058. format: @"Error writing start child element {http://api.familysearch.org/familytree/v2}change."];
  2059. }
  2060. #if DEBUG_ENUNCIATE > 1
  2061. NSLog(@"writing element {http://api.familysearch.org/familytree/v2}change...");
  2062. #endif
  2063. [__item writeXMLType: writer];
  2064. #if DEBUG_ENUNCIATE > 1
  2065. NSLog(@"successfully wrote element {http://api.familysearch.org/familytree/v2}change...");
  2066. #endif
  2067. status = xmlTextWriterEndElement(writer);
  2068. if (status < 0) {
  2069. [NSException raise: @"XMLWriteError"
  2070. format: @"Error writing end child element {http://api.familysearch.org/familytree/v2}change."];
  2071. }
  2072. } //end item iterator.
  2073. }
  2074. }
  2075. @end /* implementation FSFAMILYTREEV2Changes (JAXB) */
  2076. /**
  2077. * Citation Field
  2078. @author Rob Lyon
  2079. */
  2080. @implementation FSFAMILYTREEV2CitationField
  2081. /**
  2082. * (no documentation provided)
  2083. */
  2084. - (enum FSFAMILYTREEV2CitationFieldType *) type
  2085. {
  2086. return _type;
  2087. }
  2088. /**
  2089. * (no documentation provided)
  2090. */
  2091. - (void) setType: (enum FSFAMILYTREEV2CitationFieldType *) newType
  2092. {
  2093. if (_type != NULL) {
  2094. free(_type);
  2095. }
  2096. _type = newType;
  2097. }
  2098. /**
  2099. * (no documentation provided)
  2100. */
  2101. - (NSString *) value
  2102. {
  2103. return _value;
  2104. }
  2105. /**
  2106. * (no documentation provided)
  2107. */
  2108. - (void) setValue: (NSString *) newValue
  2109. {
  2110. [newValue retain];
  2111. [_value release];
  2112. _value = newValue;
  2113. }
  2114. - (void) dealloc
  2115. {
  2116. [self setType: NULL];
  2117. [self setValue: nil];
  2118. [super dealloc];
  2119. }
  2120. @end /* implementation FSFAMILYTREEV2CitationField */
  2121. /**
  2122. * Internal, private interface for JAXB reading and writing.
  2123. */
  2124. @interface FSFAMILYTREEV2CitationField (JAXB) <JAXBReading, JAXBWriting, JAXBType>
  2125. @end /*interface FSFAMILYTREEV2CitationField (JAXB)*/
  2126. /**
  2127. * Internal, private implementation for JAXB reading and writing.
  2128. */
  2129. @implementation FSFAMILYTREEV2CitationField (JAXB)
  2130. /**
  2131. * Read an instance of FSFAMILYTREEV2CitationField from an XML reader.
  2132. *
  2133. * @param reader The reader.
  2134. * @return An instance of FSFAMILYTREEV2CitationField defined by the XML reader.
  2135. */
  2136. + (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader
  2137. {
  2138. FSFAMILYTREEV2CitationField *_fSFAMILYTREEV2CitationField = [[FSFAMILYTREEV2CitationField alloc] init];
  2139. NS_DURING
  2140. {
  2141. [_fSFAMILYTREEV2CitationField initWithReader: reader];
  2142. }
  2143. NS_HANDLER
  2144. {
  2145. [_fSFAMILYTREEV2CitationField dealloc];
  2146. _fSFAMILYTREEV2CitationField = nil;
  2147. [localException raise];
  2148. }
  2149. NS_ENDHANDLER
  2150. [_fSFAMILYTREEV2CitationField autorelease];
  2151. return _fSFAMILYTREEV2CitationField;
  2152. }
  2153. /**
  2154. * Initialize this instance of FSFAMILYTREEV2CitationField according to
  2155. * the XML being read from the reader.
  2156. *
  2157. * @param reader The reader.
  2158. */
  2159. - (id) initWithReader: (xmlTextReaderPtr) reader
  2160. {
  2161. return [super initWithReader: reader];
  2162. }
  2163. /**
  2164. * Write the XML for this instance of FSFAMILYTREEV2CitationField to the writer.
  2165. * Note that since we're only writing the XML type,
  2166. * No start/end element will be written.
  2167. *
  2168. * @param reader The reader.
  2169. */
  2170. - (void) writeXMLType: (xmlTextWriterPtr) writer
  2171. {
  2172. [super writeXMLType:writer];
  2173. }
  2174. //documentation inherited.
  2175. - (BOOL) readJAXBAttribute: (xmlTextReaderPtr) reader
  2176. {
  2177. void *_child_accessor;
  2178. if ([super readJAXBAttribute: reader]) {
  2179. return YES;
  2180. }
  2181. if ((xmlStrcmp(BAD_CAST "type", xmlTextReaderConstLocalName(reader)) == 0) && (xmlTextReaderConstNamespaceUri(reader) == NULL)) {
  2182. #if DEBUG_ENUNCIATE > 1
  2183. NSLog(@"Attempting to read attribute {}type...");
  2184. #endif
  2185. _child_accessor = xmlTextReaderReadFSFAMILYTREEV2CitationFieldTypeType(reader);
  2186. if (_child_accessor == NULL) {
  2187. //panic: unable to read the attribute value for some reason.
  2188. [self dealloc];
  2189. [NSException raise: @"XMLReadError"
  2190. format: @"Error reading attribute {}type."];
  2191. }
  2192. [self setType: ((enum FSFAMILYTREEV2CitationFieldType*) _child_accessor)];
  2193. #if DEBUG_ENUNCIATE > 1
  2194. NSLog(@"successfully read attribute {}type...");
  2195. #endif
  2196. return YES;
  2197. }
  2198. return NO;
  2199. }
  2200. //documentation inherited.
  2201. - (BOOL) readJAXBValue: (xmlTextReaderPtr) reader
  2202. {
  2203. #if DEBUG_ENUNCIATE > 1
  2204. NSLog(@"Attempting to read element value...");
  2205. #endif
  2206. if (xmlTextReaderIsEmptyElement(reader) == 0) {
  2207. [self setValue: (NSString *) [NSString readXMLType: reader]];
  2208. }
  2209. else {
  2210. [self setValue: @""];
  2211. }
  2212. #if DEBUG_ENUNCIATE > 1
  2213. NSLog(@"successfully read element value...");
  2214. #endif
  2215. return YES;
  2216. }
  2217. //documentation inherited.
  2218. - (BOOL) readJAXBChildElement: (xmlTextReaderPtr) reader
  2219. {
  2220. return [super readJAXBChildElement: reader];
  2221. }
  2222. //documentation inherited.
  2223. - (int) readUnknownJAXBChildElement: (xmlTextReaderPtr) reader
  2224. {
  2225. return [super readUnknownJAXBChildElement: reader];
  2226. }
  2227. //documentation inherited.
  2228. - (void) readUnknownJAXBAttribute: (xmlTextReaderPtr) reader
  2229. {
  2230. [super readUnknownJAXBAttribute: reader];
  2231. }
  2232. //documentation inherited.
  2233. - (void) writeJAXBAttributes: (xmlTextWriterPtr) writer
  2234. {
  2235. int status;
  2236. [super writeJAXBAttributes: writer];
  2237. if ([self type] != NULL) {
  2238. status = xmlTextWriterStartAttributeNS(writer, NULL, BAD_CAST "type", NULL);
  2239. if (status < 0) {
  2240. [NSException raise: @"XMLWriteError"
  2241. format: @"Error writing start attribute {}type."];
  2242. }
  2243. #if DEBUG_ENUNCIATE > 1
  2244. NSLog(@"writing attribute {}type...");
  2245. #endif
  2246. status = xmlTextWriterWriteFSFAMILYTREEV2CitationFieldTypeType(writer, [self type]);
  2247. if (status < 0) {
  2248. [NSException raise: @"XMLWriteError"
  2249. format: @"Error writing attribute {}type."];