Extensibility Using SIP Meta-Annotations
Meta-annotations provide built-in extensibility. SIP meta-annotations allow application developers to define and use their own annotations. For example, an application can define an annotation called foo.example.18xResponses for handling only 18x responses. A single annotation can also contain more than one SIP meta-annotation.
Example 3-6 shows a user defined annotation.
Example 3-6 User Defined Annotation
@Retention(RUNTIME) @Target({METHOD}) @SipResponseRange(begin = 200, end = 299) @SipMethod("INVITE") public @interface MySucessfulInviteResponse { }
Example 3-7 shows an annotation that combines a @SipPredicate annotation with other meta annotations
Example 3-7 Combined Annotations
@Retention(RUNTIME) @Target({METHOD}) @SipPredicate(MyInitialInvite.Predicate.class) @SipMethod("INVITE") public @interface MyInitialInvite { class Predicate implements javax.servlet.sip.Predicate<SipServletRequest> { @Override public boolean apply(final SipServletRequest request) { return request.isInitial(); } } }
The application can then use the @MyInitialInvite annotation to select a method for handling an initial invite as shown in Example 3-8.
Example 3-8 Using a Custom Annotation
@MyInitialInvite public void handleInviteRequest(SipServletRequest request) { //... }