org.glassfish.pfl.basic.logex
Class WrapperGenerator

java.lang.Object
  extended by org.glassfish.pfl.basic.logex.WrapperGenerator

public class WrapperGenerator
extends Object

Given an annotated interface, return a Proxy that implements that interface. Interface must be annotated with @ExceptionWrapper( String idPrefix, String loggerName ). id prefix defaults to empty, loggerName defaults to the package name of the annotated class.

Also, note that this returned wrapper will always implement the MessageInfo interface, which provides a way to capture all of the messages and IDs used in the interface. This is used to generate resource bundles. In order for this to work, it is required that the interface declare a field

public static final [class name] self = ExceptionWrapper.makeWrapper( ... ) ;

This is necessary because the extension mechanism allows the construction of message IDs that cannot be predicted based on the annotations alone.

The behavior of the implementation of each method on the interface is determined in part by its return type as follows:

Each method may be annotated as follows: In addition, the @Chain annotation may be used on a method parameter (whose type must be a subclass of Throwable) of a method that returns an exception to indicate that the parameter should be the cause of the returned exception. All other method parameters are used as arguments in formatting the message.

Author:
ken

Nested Class Summary
static interface WrapperGenerator.Extension
          Extension API available to override the default behavior of the WrapperGenerator.
static class WrapperGenerator.ExtensionBase
          Convenience base class for implementations of Extension that don't need to override every method.
static interface WrapperGenerator.MessageInfo
          Hidden interface implemented by the result of the makeWrapper call.
 
Method Summary
static String getStandardLogId(Method method)
          Expose the standard log ID for the method.
static
<T> T
makeWrapper(Class<T> cls)
          Given an interface annotated with @ExceptionWrapper, return a proxy implementing the interface.
static
<T> T
makeWrapper(Class<T> cls, WrapperGenerator.Extension extension)
          Given an interface annotated with @ExceptionWrapper, return a proxy implementing the interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getStandardLogId

public static String getStandardLogId(Method method)
Expose the standard log ID for the method. This is simply the annotated value in the @Log annotation: it is not processed in any way.

Parameters:
method - The method for which the ID is requested.
Returns:
The ID (as a string), or null if no @Log annotation is present.

makeWrapper

public static <T> T makeWrapper(Class<T> cls)
Given an interface annotated with @ExceptionWrapper, return a proxy implementing the interface.

Type Parameters:
T - The annotated interface type.
Parameters:
cls - The class of the annotated interface.
Returns:
An instance of the interface.

makeWrapper

public static <T> T makeWrapper(Class<T> cls,
                                WrapperGenerator.Extension extension)
Given an interface annotated with @ExceptionWrapper, return a proxy implementing the interface.

Type Parameters:
T - The annotated interface type.
Parameters:
cls - The class of the annotated interface.
extension - The extension instance used to override the default behavior.
Returns:
An instance of the interface.


Copyright © 2013 Oracle. All Rights Reserved.