/activeobjects-dbex/src/main/java/com/atlassian/dbexporter/node/NodeCreator.java

https://bitbucket.org/activeobjects/ao-plugin · Java · 109 lines · 18 code · 12 blank · 79 comment · 0 complexity · e4865c18f760b56903ee4d90e7128bce MD5 · raw file

  1. package com.atlassian.dbexporter.node;
  2. import java.io.IOException;
  3. import java.io.Reader;
  4. import java.math.BigDecimal;
  5. import java.math.BigInteger;
  6. import java.util.Date;
  7. /**
  8. * Represents a node in streaming XML documents. This is a small abstraction
  9. * layer over StAX that allows other streaming data formats to be created (JSON,
  10. * ASN.1, ?) and make it easier to deal with StAX, of which the API can be a bit
  11. * tedious. This interface also provides type conversion instead of just strings.
  12. * This interface only provides write access to a streaming node graph.
  13. *
  14. * @author Erik van Zijst
  15. * @see NodeParser counterpart of this interface that provides read access to
  16. * streaming node graphs.
  17. * @see NodeStreamWriter
  18. */
  19. public interface NodeCreator {
  20. /**
  21. * Creates a new child node under the current node.
  22. *
  23. * @param name the name of the new child node.
  24. * @return a reference to the new node. Continue with this reference.
  25. */
  26. NodeCreator addNode(String name);
  27. /**
  28. * Closes the current node and returns a reference to the parent node.
  29. *
  30. * @return a reference to the parent node. Continue with this reference.
  31. */
  32. NodeCreator closeEntity();
  33. /**
  34. * Similar to {@link NodeCreator#setContentAsString(String)}, but sets the
  35. * content to the specified {@link java.util.Date} instance.
  36. *
  37. * @param date
  38. * @return a reference to the current node.
  39. */
  40. NodeCreator setContentAsDate(Date date);
  41. /**
  42. * Similar to {@link NodeCreator#setContentAsString(String)}, but sets the
  43. * content to the specified {@link java.math.BigInteger} instance.
  44. *
  45. * @param bigInteger
  46. * @return a reference to the current node.
  47. */
  48. NodeCreator setContentAsBigInteger(BigInteger bigInteger);
  49. NodeCreator setContentAsBigDecimal(BigDecimal bigDecimal);
  50. /**
  51. * Sets the content of the current node to be the specified string. This
  52. * method does not automatically close the node, but returns a reference to
  53. * the current node. The caller is responsible for closing the node using
  54. * {@link NodeCreator#closeEntity()}.
  55. * <P>
  56. * Use <code>null</code> to explicitly encode the null value (results in
  57. * <code>&lt;node xsi:nil="true"/&gt;</code> in XML, while an empty
  58. * string produces <code>&lt;node&gt;&lt;/node&gt;</code>).
  59. *
  60. * @param string the content for the current node.
  61. * @return a reference to the current node.
  62. */
  63. NodeCreator setContentAsString(String string);
  64. /**
  65. * Similar to {@link NodeCreator#setContentAsString(String)}, but sets the
  66. * content to the specified {@link Boolean} instance.
  67. *
  68. * @param bool
  69. * @return a reference to the current node.
  70. */
  71. NodeCreator setContentAsBoolean(Boolean bool);
  72. /**
  73. * Similar to {@link NodeCreator#setContentAsString(String)}, but sets the
  74. * content to the specified {@link byte[]} instance.
  75. *
  76. * @param bytes
  77. * @return a reference to the current node.
  78. */
  79. NodeCreator setContentAsBinary(byte[] bytes);
  80. /**
  81. * Similar to {@link NodeCreator#setContentAsString(String)}, but passes the
  82. * content to the {@link NodeCreator} as a {@link java.io.Reader} instance. Use this
  83. * to encode large chunks of content in a memory-efficient way.
  84. *
  85. * @param data
  86. * @return a reference to the current node.
  87. * @throws java.io.IOException
  88. */
  89. NodeCreator setContent(Reader data) throws IOException;
  90. /**
  91. * Adds an attribute to the current node.
  92. *
  93. * @param key
  94. * @param value
  95. */
  96. NodeCreator addAttribute(String key, String value);
  97. }