Package org.glassfish.pfl.basic.logex
Class WrapperGenerator
- java.lang.Object
-
- org.glassfish.pfl.basic.logex.WrapperGenerator
-
public class WrapperGenerator extends java.lang.ObjectGiven 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:
- void. Such a method can only log a message. Must have @Log, @Message is optional.
- String. Such a method may log a message, and also returns the message. Both @Log and @Message are optional.
- A subclass of Exception. Such a method may log a message, and also returns an exception containing the message. Both @Log and @Message are optional.
- @Message( String value ). This defines the message to be placed in a resource
bundle (generated at build time by a separate tool). The key to the resource
bundle is
<loggerName>.<methodName>. The message is prepended with the idPrefix and the id from the @Log annotation (if @Log is present, otherwise nothing is prepended to the message). If this annotation is not present, a default message is created from the method name and the arguments. - @Log( LogLevel level, int id ). The presence of this annotation indicates that a log record must be generated, and logger IF the appropriate logger is enabled at the given level (note that LogLevel is an enum used for the annotation, each member of which returns the java.util.logging.Level from a getLevel() method).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceWrapperGenerator.ExtensionExtension API available to override the default behavior of the WrapperGenerator.static classWrapperGenerator.ExtensionBaseConvenience base class for implementations of Extension that don't need to override every method.static interfaceWrapperGenerator.MessageInfoHidden interface implemented by the result of the makeWrapper call.(package private) static classWrapperGenerator.ReturnType(package private) static classWrapperGenerator.ShortFormatter
-
Field Summary
Fields Modifier and Type Field Description (package private) static AnnotationAnalyzeraa(package private) static java.lang.StringcihiName(package private) static WrapperGenerator.ExtensionstdExtension
-
Constructor Summary
Constructors Modifier Constructor Description privateWrapperGenerator()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static WrapperGenerator.ReturnTypeclassifyReturnType(java.lang.reflect.Method method)(package private) static intfindAnnotatedParameter(java.lang.annotation.Annotation[][] pannos, java.lang.Class<? extends java.lang.annotation.Annotation> cls)(package private) static java.lang.StringgetMessage(java.lang.reflect.Method method, java.lang.String prefix, WrapperGenerator.Extension extension)(package private) static java.util.Map<java.lang.String,java.lang.String>getMessageMap(java.lang.Class<?> cls, WrapperGenerator.Extension extension)(package private) static java.lang.StringgetMessageOrKey(java.util.logging.Logger logger, java.lang.reflect.Method method, WrapperGenerator.Extension extension)(package private) static java.lang.StringgetMsgKey(java.lang.String logger, java.lang.reflect.Method method)(package private) static java.lang.StringgetStandardLoggerName(java.lang.Class<?> cls)static java.lang.StringgetStandardLogId(java.lang.reflect.Method method)Expose the standard log ID for the method.(package private) static java.lang.Object[]getWithSkip(java.lang.Object[] args, int skip)(package private) static java.lang.ObjecthandleFullLogging(Log log, java.lang.reflect.Method method, WrapperGenerator.ReturnType rtype, java.util.logging.Logger logger, java.lang.String idPrefix, java.lang.Object[] messageParams, java.lang.Throwable cause, WrapperGenerator.Extension extension)(package private) static java.lang.StringhandleMessageOnly(java.lang.reflect.Method method, WrapperGenerator.Extension extension, java.util.logging.Logger logger, java.lang.Object[] messageParams)(package private) static booleanisMajorLevel(java.util.logging.Level level)(package private) static java.util.logging.LogRecordmakeLogRecord(java.util.logging.Level level, java.lang.String key, java.lang.Object[] args, java.util.logging.Logger logger)(package private) static java.lang.ThrowablemakeStandardException(java.lang.String msg, java.lang.reflect.Method method)static <T> TmakeWrapper(java.lang.Class<T> cls)Given an interface annotated with @ExceptionWrapper, return a proxy implementing the interface.static <T> TmakeWrapper(java.lang.Class<T> cls, WrapperGenerator.Extension extension)Given an interface annotated with @ExceptionWrapper, return a proxy implementing the interface.(package private) static booleanneedStackTrace(java.util.logging.Level level, java.lang.reflect.Method method)(package private) static voidtrimStackTrace(java.lang.Throwable exc, java.util.logging.LogRecord lrec)
-
-
-
Field Detail
-
stdExtension
static final WrapperGenerator.Extension stdExtension
-
aa
static final AnnotationAnalyzer aa
-
cihiName
static final java.lang.String cihiName
-
-
Method Detail
-
getStandardLogId
public static java.lang.String getStandardLogId(java.lang.reflect.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.
-
makeStandardException
static java.lang.Throwable makeStandardException(java.lang.String msg, java.lang.reflect.Method method)
-
getStandardLoggerName
static java.lang.String getStandardLoggerName(java.lang.Class<?> cls)
-
findAnnotatedParameter
static int findAnnotatedParameter(java.lang.annotation.Annotation[][] pannos, java.lang.Class<? extends java.lang.annotation.Annotation> cls)
-
getWithSkip
static java.lang.Object[] getWithSkip(java.lang.Object[] args, int skip)
-
getMsgKey
static java.lang.String getMsgKey(java.lang.String logger, java.lang.reflect.Method method)
-
getMessageMap
static java.util.Map<java.lang.String,java.lang.String> getMessageMap(java.lang.Class<?> cls, WrapperGenerator.Extension extension)
-
getMessage
static java.lang.String getMessage(java.lang.reflect.Method method, java.lang.String prefix, WrapperGenerator.Extension extension)
-
getMessageOrKey
static java.lang.String getMessageOrKey(java.util.logging.Logger logger, java.lang.reflect.Method method, WrapperGenerator.Extension extension)
-
handleMessageOnly
static java.lang.String handleMessageOnly(java.lang.reflect.Method method, WrapperGenerator.Extension extension, java.util.logging.Logger logger, java.lang.Object[] messageParams)
-
classifyReturnType
static WrapperGenerator.ReturnType classifyReturnType(java.lang.reflect.Method method)
-
makeLogRecord
static java.util.logging.LogRecord makeLogRecord(java.util.logging.Level level, java.lang.String key, java.lang.Object[] args, java.util.logging.Logger logger)
-
trimStackTrace
static void trimStackTrace(java.lang.Throwable exc, java.util.logging.LogRecord lrec)
-
isMajorLevel
static boolean isMajorLevel(java.util.logging.Level level)
-
needStackTrace
static boolean needStackTrace(java.util.logging.Level level, java.lang.reflect.Method method)
-
handleFullLogging
static java.lang.Object handleFullLogging(Log log, java.lang.reflect.Method method, WrapperGenerator.ReturnType rtype, java.util.logging.Logger logger, java.lang.String idPrefix, java.lang.Object[] messageParams, java.lang.Throwable cause, WrapperGenerator.Extension extension)
-
makeWrapper
public static <T> T makeWrapper(java.lang.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(java.lang.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.
-
-