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
18 changes: 11 additions & 7 deletions src/main/java/org/asteriskjava/manager/AsteriskMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Customized the mapping to Asterisk. In general the mapping is done implicitly based
* on reflection but there are certain action that are using headers with specical
* characters that can not be represented in Java. In those cases you can annotate
* the property (getter, setter or field) and provide the header name that Asterisk expects.
* Customize the mapping to Asterisk. In general the mapping is done implicitly
* based on reflection but there are certain actions that use headers with
* characters that are not valid in Java identifiers. In those cases you can
* annotate the property (getter, setter or field) and provide the header name
* that Asterisk sends or expects.
* <p>
* Similarly, if an AMI event name contains characters that are not valid Java
* identifiers, the class itself can be decorated with this annotation to
* affect the mapping.
*
* @since 1.0.0
*/
@Target({METHOD, FIELD})
@Target({TYPE, METHOD, FIELD})
@Retention(RUNTIME)
public @interface AsteriskMapping {
String value();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.asteriskjava.manager.internal;

import org.asteriskjava.manager.AsteriskMapping;
import org.asteriskjava.manager.event.*;
import org.asteriskjava.manager.util.EventAttributesHelper;
import org.asteriskjava.util.Log;
Expand Down Expand Up @@ -60,14 +61,18 @@ private void registerBuiltinEventClasses() {
}

public final void registerEventClass(Class<? extends ManagerEvent> clazz) throws IllegalArgumentException {
String className;
String eventType;

className = clazz.getName();
eventType = className.substring(className.lastIndexOf('.') + 1).toLowerCase(Locale.ENGLISH);
AsteriskMapping annotation = clazz.getAnnotation(AsteriskMapping.class);
if (annotation == null) {
String className = clazz.getName();
eventType = className.substring(className.lastIndexOf('.') + 1).toLowerCase(Locale.ENGLISH);

if (eventType.endsWith("event")) {
eventType = eventType.substring(0, eventType.length() - "event".length());
if (eventType.endsWith("event")) {
eventType = eventType.substring(0, eventType.length() - "event".length());
}
} else {
eventType = annotation.value().toLowerCase(Locale.ENGLISH);
}

if (UserEvent.class.isAssignableFrom(clazz) && !eventType.startsWith("userevent")) {
Expand Down