Skip to content

Commit

Permalink
JavaDoc now builds, fixed typos
Browse files Browse the repository at this point in the history
Signed-off-by: Jem Day <[email protected]>
  • Loading branch information
JemDay committed Jan 3, 2023
1 parent 9c857c0 commit dec4019
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 26 deletions.
10 changes: 9 additions & 1 deletion formats/xml/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>io.cloudevents</groupId>
<artifactId>cloudevents-parent</artifactId>
<version>2.4.0-SNAPSHOT</version>
<version>2.5.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand All @@ -32,7 +32,9 @@
<packaging>jar</packaging>

<properties>
<module-name>io.cloudevents.formats.xml</module-name>
<xmlunit.version>2.9.0</xmlunit.version>
<javax.xml.version>2.3.1</javax.xml.version>
</properties>

<dependencies>
Expand All @@ -43,6 +45,12 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${javax.xml.version}</version>
</dependency>

<!-- Test deps -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@
import java.util.Set;

/**
* Tracks the occurances of a key to ensure only a single
* Tracks the occurrences of a key to ensure only a single
* instance is allowed.
*
* Used to ensure that each CloudEvent context attribute
* only occurs once in each CloudEvent element instance.
*
*/
class OccuranceTracker {
class OccurrenceTracker {

private Set<String> keySet;
private final Set<String> keySet;

OccuranceTracker() {
OccurrenceTracker() {
keySet = new HashSet<>();
}

void trackOccurance(String name) throws IllegalStateException {
void trackOccurrence(String name) throws IllegalStateException {

if (! keySet.add(name)){
throw new IllegalStateException(name + ": Occurs more than once");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

/**
* A variant of {@link CloudEventData} that supports direct access
* to data as an XML {@link Document}.
* to data as an XML {@link Document}
*/
public interface XMLCloudEventData extends CloudEventData {

/**
* Get the XML {@link Document} representation of the
* Get an XML Document representation of the
* CloudEvent data.
*
* @return The {@link Document} representation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
class XMLDeserializer implements CloudEventReader {

private final Document xmlDocument;
private final OccuranceTracker ceAtrributeTracker = new OccuranceTracker();
private final OccurrenceTracker ceAttributeTracker = new OccurrenceTracker();

XMLDeserializer(Document doc) {
this.xmlDocument = doc;
Expand Down Expand Up @@ -130,7 +130,7 @@ public <W extends CloudEventWriter<R>, R> R read(
// Private Methods --------------------------------------------------------

/**
* Get the first child {@link Element} of an {@link Element}
* Get the first child Element of an Element
*
* @param e
* @return The first child, or NULL if there isn't one.
Expand Down Expand Up @@ -216,10 +216,10 @@ private CloudEventData processData(Element data) throws CloudEventRWException {
}

/**
* Ensure that the root elemement of the received XML document is valid
* Ensure that the root element of the received XML document is valid
* in our context.
*
* @param e The root {@link Element}
* @param e The root Element
* @throws CloudEventRWException
*/
private void checkValidRootElement(Element e) throws CloudEventRWException {
Expand All @@ -236,7 +236,7 @@ private void checkValidRootElement(Element e) throws CloudEventRWException {
}

/**
* Ensure the XML `data` element is well formed.
* Ensure the XML `data` element is well-formed.
*
* @param dataEl
* @throws CloudEventRWException
Expand Down Expand Up @@ -278,7 +278,7 @@ private void ensureValidContextAttribute(Element el) throws CloudEventRWExceptio
throw CloudEventRWException.newInvalidDataType(localName, " context atttribute names MUST be lowercase");
}

// A bit kludgy, not relevent for 'data' - should refactor
// A bit of a kludge, not relevant for 'data' - should refactor
if (!XMLConstants.XML_DATA_ELEMENT.equals(localName)) {
// It must not have any children
if (XMLUtils.countOfChildElements(el) != 0) {
Expand All @@ -288,7 +288,7 @@ private void ensureValidContextAttribute(Element el) throws CloudEventRWExceptio

// Finally, ensure we only see each CE Attribute once...
try {
ceAtrributeTracker.trackOccurance(localName);
ceAttributeTracker.trackOccurrence(localName);
} catch (IllegalStateException e){
throw CloudEventRWException.newOther(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
class XMLSerializer {

/**
* Convert the CloudEvent to an XML DOM representation.
* Convert a CloudEvent to an XML {@link Document}.
*
* @param ce
* @return
*/
static Document toDocument(CloudEvent ce) {

// Setup the writer
// Set up the writer
XMLCloudEventWriter eventWriter = new XMLCloudEventWriter(ce.getSpecVersion());

// Process the Context Attributes
Expand Down
6 changes: 3 additions & 3 deletions formats/xml/src/main/java/io/cloudevents/xml/XMLUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private XMLUtils() {
* Parse a byte stream into an XML {@link Document}
*
* @param data
* @return {@link Document}
* @return Document
* @throws CloudEventRWException
*/
static Document parseIntoDocument(byte[] data) throws CloudEventRWException {
Expand All @@ -65,7 +65,7 @@ static Document parseIntoDocument(byte[] data) throws CloudEventRWException {
}

/**
* Obtain a byte array representation of a {@link Document}
* Obtain a byte array representation of an {@link Document}
*
* @param doc {@link Document}
* @return byte[]
Expand All @@ -92,7 +92,7 @@ static byte[] documentToBytes(Document doc) throws TransformerException {
/**
* Get the number of child elements of an {@link Element}
*
* @param e The Element to introspect.
* @param e The {@link Element} to introspect.
* @return The count of child elements
*/
static int countOfChildElements(Element e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class OccuranceTrackerTest {
public class OccurrenceTrackerTest {

private final OccuranceTracker tracker = new OccuranceTracker();
private final OccurrenceTracker tracker = new OccurrenceTracker();

@Test
public void verifyTracking() {

// These should all work...
Assertions.assertDoesNotThrow(() -> {
tracker.trackOccurance("CE1");
tracker.trackOccurance("CE2");
tracker.trackOccurance("ce1");
tracker.trackOccurrence("CE1");
tracker.trackOccurrence("CE2");
tracker.trackOccurrence("ce1");
});

// This should fail
Assertions.assertThrows(IllegalStateException.class, () -> {
tracker.trackOccurance("CE2");
tracker.trackOccurrence("CE2");
});

}
Expand Down

0 comments on commit dec4019

Please sign in to comment.