Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 61 additions & 16 deletions core/src/main/java/io/cloudevents/core/v03/CloudEventV03.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,51 @@
*/
public final class CloudEventV03 extends BaseCloudEvent {

/**
* The name of the <a href="https://github.com/cloudevents/spec/blob/v0.3/spec.md#id">id</a> attribute
*/
public final static String ID = "id";

/**
* The name of the <a href="https://github.com/cloudevents/spec/blob/v0.3/spec.md#source">source</a> attribute
*/
public final static String SOURCE = "source";

/**
* The name of the <a href="https://github.com/cloudevents/spec/blob/v0.3/spec.md#specversion">specversion</a> attribute
*/
public final static String SPECVERSION = "specversion";

/**
* The name of the <a href="https://github.com/cloudevents/spec/blob/v0.3/spec.md#type">type</a> attribute
*/
public final static String TYPE = "type";

/**
* The name of the <a href="https://github.com/cloudevents/spec/blob/v0.3/spec.md#time">time</a> attribute
*/
public final static String TIME = "time";

/**
* The name of the <a href="https://github.com/cloudevents/spec/blob/v0.3/spec.md#schemaurl">schemaurl</a> attribute
*/
public final static String SCHEMAURL = "schemaurl";

/**
* The name of the <a href="https://github.com/cloudevents/spec/blob/v0.3/spec.md#datacontenttype">datacontenttype</a> attribute
*/
public final static String DATACONTENTTYPE = "datacontenttype";

/**
* The name of the <a href="https://github.com/cloudevents/spec/blob/v0.3/spec.md#datacontentencoding">datacontentencoding</a> attribute
*/
public final static String DATACONTENTENCODING = "datacontentencoding";

/**
* The name of the <a href="https://github.com/cloudevents/spec/blob/v0.3/spec.md#subject">subject</a> attribute
*/
public final static String SUBJECT = "subject";

private final String id;
private final URI source;
private final String type;
Expand Down Expand Up @@ -100,23 +145,23 @@ public OffsetDateTime getTime() {
@Override
public Object getAttribute(String attributeName) {
switch (attributeName) {
case "specversion":
case SPECVERSION:
return getSpecVersion();
case "id":
case ID:
return this.id;
case "source":
case SOURCE:
return this.source;
case "type":
case TYPE:
return this.type;
case "datacontenttype":
case DATACONTENTTYPE:
return this.datacontenttype;
case "schemaurl":
case SCHEMAURL:
return this.schemaurl;
case "subject":
case SUBJECT:
return this.subject;
case "time":
case TIME:
return this.time;
case "datacontentencoding":
case DATACONTENTENCODING:
// We don't save datacontentencoding, but the attribute name is valid, hence we just return always null
return null;
}
Expand All @@ -126,38 +171,38 @@ public Object getAttribute(String attributeName) {
@Override
public void readAttributes(CloudEventAttributesWriter writer) throws CloudEventRWException {
writer.withAttribute(
ContextAttributes.ID.name().toLowerCase(),
ID,
this.id
);
writer.withAttribute(
ContextAttributes.SOURCE.name().toLowerCase(),
SOURCE,
this.source
);
writer.withAttribute(
ContextAttributes.TYPE.name().toLowerCase(),
TYPE,
this.type
);
if (this.datacontenttype != null) {
writer.withAttribute(
ContextAttributes.DATACONTENTTYPE.name().toLowerCase(),
DATACONTENTTYPE,
this.datacontenttype
);
}
if (this.schemaurl != null) {
writer.withAttribute(
ContextAttributes.SCHEMAURL.name().toLowerCase(),
SCHEMAURL,
this.schemaurl
);
}
if (this.subject != null) {
writer.withAttribute(
ContextAttributes.SUBJECT.name().toLowerCase(),
SUBJECT,
this.subject
);
}
if (this.time != null) {
writer.withAttribute(
ContextAttributes.TIME.name().toLowerCase(),
TIME,
this.time
);
}
Expand Down
52 changes: 0 additions & 52 deletions core/src/main/java/io/cloudevents/core/v03/ContextAttributes.java

This file was deleted.

70 changes: 55 additions & 15 deletions core/src/main/java/io/cloudevents/core/v1/CloudEventV1.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,46 @@
*/
public final class CloudEventV1 extends BaseCloudEvent {

/**
* The name of the <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#id">id</a> attribute
*/
public final static String ID = "id";

/**
* The name of the <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#source">source</a> attribute
*/
public final static String SOURCE = "source";

/**
* The name of the <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#specversion">specversion</a> attribute
*/
public final static String SPECVERSION = "specversion";

/**
* The name of the <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#type">type</a> attribute
*/
public final static String TYPE = "type";

/**
* The name of the <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#time">time</a> attribute
*/
public final static String TIME = "time";

/**
* The name of the <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#dataschema">dataschema</a> attribute
*/
public final static String DATASCHEMA = "dataschema";

/**
* The name of the <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#datacontenttype">datacontenttype</a> attribute
*/
public final static String DATACONTENTTYPE = "datacontenttype";

/**
* The name of the <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#subject">subject</a> attribute
*/
public final static String SUBJECT = "subject";

private final String id;
private final URI source;
private final String type;
Expand Down Expand Up @@ -95,21 +135,21 @@ public OffsetDateTime getTime() {
@Override
public Object getAttribute(String attributeName) {
switch (attributeName) {
case "specversion":
case SPECVERSION:
return getSpecVersion();
case "id":
case ID:
return this.id;
case "source":
case SOURCE:
return this.source;
case "type":
case TYPE:
return this.type;
case "datacontenttype":
case DATACONTENTTYPE:
return this.datacontenttype;
case "dataschema":
case DATASCHEMA:
return this.dataschema;
case "subject":
case SUBJECT:
return this.subject;
case "time":
case TIME:
return this.time;
}
throw new IllegalArgumentException("Spec version v1 doesn't have attribute named " + attributeName);
Expand All @@ -118,38 +158,38 @@ public Object getAttribute(String attributeName) {
@Override
public void readAttributes(CloudEventAttributesWriter writer) throws CloudEventRWException {
writer.withAttribute(
ContextAttributes.ID.name().toLowerCase(),
ID,
this.id
);
writer.withAttribute(
ContextAttributes.SOURCE.name().toLowerCase(),
SOURCE,
this.source
);
writer.withAttribute(
ContextAttributes.TYPE.name().toLowerCase(),
TYPE,
this.type
);
if (this.datacontenttype != null) {
writer.withAttribute(
ContextAttributes.DATACONTENTTYPE.name().toLowerCase(),
DATACONTENTTYPE,
this.datacontenttype
);
}
if (this.dataschema != null) {
writer.withAttribute(
ContextAttributes.DATASCHEMA.name().toLowerCase(),
DATASCHEMA,
this.dataschema
);
}
if (this.subject != null) {
writer.withAttribute(
ContextAttributes.SUBJECT.name().toLowerCase(),
SUBJECT,
this.subject
);
}
if (this.time != null) {
writer.withAttribute(
ContextAttributes.TIME.name().toLowerCase(),
TIME,
this.time
);
}
Expand Down
49 changes: 0 additions & 49 deletions core/src/main/java/io/cloudevents/core/v1/ContextAttributes.java

This file was deleted.