classInfos = index.getAllKnownImplementors(DotName.createSimple(DomainEvent.class));
+ for (final ClassInfo classInfo : classInfos) {
+ if (!Modifier.isAbstract(classInfo.flags())
+ && !Modifier.isInterface(classInfo.flags())) {
+
+ final Class> clasz = JandexUtils.loadClass(classInfo.name());
+ if (!AggregateCommand.class.isAssignableFrom(clasz)) {
+ boolean include = true;
+ if (clasz.getAnnotation(HasSerializedDataTypeConstant.class) == null) {
+ LOG.warn("Missing annotation @{} on {} class: {}", HasSerializedDataTypeConstant.class.getSimpleName(), DomainEvent.class.getSimpleName(), clasz.getName());
+ include = false;
+ }
+ if (include) {
+ classes.add(clasz);
+ LOG.info("Added {} class to {}: {}", DomainEvent.class.getSimpleName(), JandexEntityIdFactory.class.getSimpleName(), clasz.getName());
+ } else {
+ LOG.debug("Ignored {} class: {}", DomainEvent.class.getSimpleName(), clasz.getName());
+ }
+ }
+ }
+ }
+ return classes;
+ }
+
+ public SerializedDataType serializedDataTypeConstant(Class> domainEventClass) {
+ final HasSerializedDataTypeConstant annotation = domainEventClass.getAnnotation(HasSerializedDataTypeConstant.class);
+ return HasSerializedDataTypeConstantValidator.extractValue(domainEventClass, annotation.value());
+ }
+
+}
diff --git a/src/test/java/org/fuin/cqrs4j/ACreatedEvent.java b/src/test/java/org/fuin/cqrs4j/ACreatedEvent.java
new file mode 100644
index 0000000..9e56c2e
--- /dev/null
+++ b/src/test/java/org/fuin/cqrs4j/ACreatedEvent.java
@@ -0,0 +1,56 @@
+/**
+ * Copyright (C) 2015 Michael Schnell. All rights reserved.
+ * http://www.fuin.org/
+ *
+ * This library is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option) any
+ * later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library. If not, see http://www.gnu.org/licenses/.
+ */
+package org.fuin.cqrs4j;
+
+import org.fuin.ddd4j.ddd.AbstractDomainEvent;
+import org.fuin.ddd4j.ddd.EntityIdPath;
+import org.fuin.ddd4j.ddd.EventType;
+import org.fuin.esc.api.HasSerializedDataTypeConstant;
+import org.fuin.esc.api.SerializedDataType;
+import org.fuin.esc.api.TypeName;
+
+@HasSerializedDataTypeConstant
+public class ACreatedEvent extends AbstractDomainEvent {
+
+ private static final long serialVersionUID = 1L;
+
+ /** Unique name of the event. */
+ public static final TypeName TYPE = new TypeName("ACreatedEvent");
+
+ /** Unique name of the serialized event. */
+ public static final SerializedDataType SER_TYPE = new SerializedDataType(TYPE.asBaseType());
+
+ private static final EventType EVENT_TYPE = new EventType(TYPE.asBaseType());
+
+ private AId id;
+
+ public ACreatedEvent(final AId id) {
+ super(new EntityIdPath(id));
+ this.id = id;
+ }
+
+ public AId getId() {
+ return id;
+ }
+
+ @Override
+ public EventType getEventType() {
+ return EVENT_TYPE;
+ }
+
+}
diff --git a/src/test/java/org/fuin/cqrs4j/JandexDomainEventRegistryTest.java b/src/test/java/org/fuin/cqrs4j/JandexDomainEventRegistryTest.java
new file mode 100644
index 0000000..b68baf5
--- /dev/null
+++ b/src/test/java/org/fuin/cqrs4j/JandexDomainEventRegistryTest.java
@@ -0,0 +1,27 @@
+package org.fuin.cqrs4j;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test for the {@link JandexDomainEventRegistry} class.
+ */
+public class JandexDomainEventRegistryTest {
+
+ @Test
+ public void testCreate() {
+ final JandexDomainEventRegistry testee = new JandexDomainEventRegistry(new File("target/test-classes"));
+ assertThat(testee.getDomainEventClasses()).containsOnly(ACreatedEvent.class);
+ }
+
+ @Test
+ public void testFind() {
+ final JandexDomainEventRegistry testee = new JandexDomainEventRegistry(new File("target/test-classes"));
+ assertThat(testee.findClass(ACreatedEvent.SER_TYPE)).isEqualTo(ACreatedEvent.class);
+
+ }
+
+}