FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

AsteriskMapping.java: Allow `@AsteriskMapping` use on types. by seanbright · Pull Request #598 · asterisk-java/asterisk-java · GitHub

Repository navigation

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

Filter by extension

Filter by extension .java  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL