Top Description Inners Fields Constructors Methods
org.glassfish.pfl.basic.logex

public Class WrapperGenerator

extends Object
Class Inheritance
Imports
java.lang.annotation.Annotation, java.lang.reflect.Constructor, .InvocationHandler, .InvocationTargetException, .Method, .Proxy, java.util.ArrayList, .List, .Map, .MissingResourceException, .ResourceBundle, .TreeMap, java.util.logging.Formatter, .Level, .LogRecord, .Logger, org.glassfish.pfl.basic.algorithm.AnnotationAnalyzer, org.glassfish.pfl.basic.proxy.CompositeInvocationHandler, .CompositeInvocationHandlerImpl

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 and Inner Type Summary

Modifier and TypeClass and Description
public static interface
WrapperGenerator.Extension

Extension API available to override the default behavior of the WrapperGenerator.

public abstract static class
WrapperGenerator.ExtensionBase

Convenience base class for implementations of Extension that don't need to override every method.

public static interface
WrapperGenerator.MessageInfo

Hidden interface implemented by the result of the makeWrapper call.

pack-priv static enum
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv static final AnnotationAnalyzer
pack-priv static final String
pack-priv static final WrapperGenerator.Extension

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv static WrapperGenerator.ReturnType
pack-priv static int
findAnnotatedParameter(Annotation[][] pannos, Class<? extends Annotation> cls)

pack-priv static String
getMessage(Method method, String prefix, WrapperGenerator.Extension extension)

pack-priv static Map<String, String>
pack-priv static String
pack-priv static String
getMsgKey(String logger, Method method)

pack-priv static String
public static String

Returns:

The ID (as a string), or null if no @Log annotation is present.
getStandardLogId
(Method
The method for which the ID is requested.
method
)

Expose the standard log ID for the method.

pack-priv static Object[]
getWithSkip(Object[] args, int skip)

pack-priv static Object
handleFullLogging(Log log, Method method, WrapperGenerator.ReturnType rtype, Logger logger, String idPrefix, Object[] messageParams, Throwable cause, WrapperGenerator.Extension extension)

pack-priv static String
handleMessageOnly(Method method, WrapperGenerator.Extension extension, Logger logger, Object[] messageParams)

pack-priv static boolean
pack-priv static LogRecord
makeLogRecord(Level level, String key, Object[] args, Logger logger)

pack-priv static Throwable
makeStandardException(final String msg, final Method method)

public static <
The annotated interface type.
T
>
T

Returns:

An instance of the interface.
makeWrapper
(final Class<T>
The class of the annotated interface.
cls
)

Given an interface annotated with @ExceptionWrapper, return a proxy implementing the interface.

public static <
The annotated interface type.
T
>
T

Returns:

An instance of the interface.
makeWrapper
(final Class<T>
The class of the annotated interface.
cls
,
final WrapperGenerator.Extension
The extension instance used to override the default behavior.
extension
)

Given an interface annotated with @ExceptionWrapper, return a proxy implementing the interface.

pack-priv static boolean
needStackTrace(Level level, Method method)

pack-priv static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aaback to summary
pack-priv static final AnnotationAnalyzer aa
cihiNameback to summary
pack-priv static final String cihiName
stdExtensionback to summary
pack-priv static final WrapperGenerator.Extension stdExtension

Constructor Detail

WrapperGeneratorback to summary
private WrapperGenerator()

Method Detail

classifyReturnTypeback to summary
pack-priv static WrapperGenerator.ReturnType classifyReturnType(Method method)
findAnnotatedParameterback to summary
pack-priv static int findAnnotatedParameter(Annotation[][] pannos, Class<? extends Annotation> cls)
getMessageback to summary
pack-priv static String getMessage(Method method, String prefix, WrapperGenerator.Extension extension)
getMessageMapback to summary
pack-priv static Map<String, String> getMessageMap(Class<?> cls, WrapperGenerator.Extension extension)
getMessageOrKeyback to summary
pack-priv static String getMessageOrKey(Logger logger, Method method, WrapperGenerator.Extension extension)
getMsgKeyback to summary
pack-priv static String getMsgKey(String logger, Method method)
getStandardLoggerNameback to summary
pack-priv static String getStandardLoggerName(Class<?> cls)
getStandardLogIdback to summary
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:Method

The method for which the ID is requested.

Returns:String

The ID (as a string), or null if no @Log annotation is present.

getWithSkipback to summary
pack-priv static Object[] getWithSkip(Object[] args, int skip)
handleFullLoggingback to summary
pack-priv static Object handleFullLogging(Log log, Method method, WrapperGenerator.ReturnType rtype, Logger logger, String idPrefix, Object[] messageParams, Throwable cause, WrapperGenerator.Extension extension)
handleMessageOnlyback to summary
pack-priv static String handleMessageOnly(Method method, WrapperGenerator.Extension extension, Logger logger, Object[] messageParams)
isMajorLevelback to summary
pack-priv static boolean isMajorLevel(Level level)
makeLogRecordback to summary
pack-priv static LogRecord makeLogRecord(Level level, String key, Object[] args, Logger logger)
makeStandardExceptionback to summary
pack-priv static Throwable makeStandardException(final String msg, final Method method)
makeWrapperback to summary
public static <T> T makeWrapper(final Class<T> cls)

Given an interface annotated with @ExceptionWrapper, return a proxy implementing the interface.

Parameters
<T>
The annotated interface type.
cls:Class<T>

The class of the annotated interface.

Returns:T

An instance of the interface.

makeWrapperback to summary
public static <T> T makeWrapper(final Class<T> cls, final WrapperGenerator.Extension extension)

Given an interface annotated with @ExceptionWrapper, return a proxy implementing the interface.

Parameters
<T>
The annotated interface type.
cls:Class<T>

The class of the annotated interface.

extension:WrapperGenerator.Extension

The extension instance used to override the default behavior.

Returns:T

An instance of the interface.

Annotations
@SuppressWarnings:unchecked, unchecked
needStackTraceback to summary
pack-priv static boolean needStackTrace(Level level, Method method)
trimStackTraceback to summary
pack-priv static void trimStackTrace(Throwable exc, LogRecord lrec)
org.glassfish.pfl.basic.logex back to summary

public Interface WrapperGenerator.Extension

Known Direct Implementers
org.glassfish.pfl.basic.logex.WrapperGenerator.ExtensionBase

Extension API available to override the default behavior of the WrapperGenerator.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

A possibly updated logger name
getLoggerName
(Class<?>
The standard logger name
cls
)

Modify the default logger name if needed.

public String

Returns:

The message id.
getLogId
(Method
The method defining this log.
method
)

Get a message id for this log.

public Throwable
makeException(String
The message to use in the exception.
msg
,
Method
The method creating the exception.
method
)

Construct an exception from the message and the exception type.

Method Detail

getLoggerNameback to summary
public String getLoggerName(Class<?> cls)

Modify the default logger name if needed.

Parameters
cls:Class<?>

The standard logger name

Returns:String

A possibly updated logger name

getLogIdback to summary
public String getLogId(Method method)

Get a message id for this log.

Parameters
method:Method

The method defining this log.

Returns:String

The message id.

makeExceptionback to summary
public Throwable makeException(String msg, Method method)

Construct an exception from the message and the exception type. The method provides access to any additional annotations that may be needed.

Parameters
msg:String

The message to use in the exception.

method:Method

The method creating the exception.

org.glassfish.pfl.basic.logex back to summary

public abstract Class WrapperGenerator.ExtensionBase

extends Object
implements Extension
Class Inheritance
All Implemented Interfaces
org.glassfish.pfl.basic.logex.WrapperGenerator.Extension

Convenience base class for implementations of Extension that don't need to override every method.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String
getLoggerName(Class<?> cls)

Implements org.glassfish.pfl.basic.logex.WrapperGenerator.Extension.getLoggerName.

Modify the default logger name if needed.

public String
getLogId(Method method)

Implements org.glassfish.pfl.basic.logex.WrapperGenerator.Extension.getLogId.

Get a message id for this log.

public Throwable
makeException(String msg, Method method)

Implements org.glassfish.pfl.basic.logex.WrapperGenerator.Extension.makeException.

Construct an exception from the message and the exception type.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ExtensionBaseback to summary
public ExtensionBase()

Method Detail

getLoggerNameback to summary
public String getLoggerName(Class<?> cls)

Implements org.glassfish.pfl.basic.logex.WrapperGenerator.Extension.getLoggerName.

Doc from org.glassfish.pfl.basic.logex.WrapperGenerator.Extension.getLoggerName.

Modify the default logger name if needed.

Annotations
@Override
getLogIdback to summary
public String getLogId(Method method)

Implements org.glassfish.pfl.basic.logex.WrapperGenerator.Extension.getLogId.

Doc from org.glassfish.pfl.basic.logex.WrapperGenerator.Extension.getLogId.

Get a message id for this log.

Annotations
@Override
makeExceptionback to summary
public Throwable makeException(String msg, Method method)

Implements org.glassfish.pfl.basic.logex.WrapperGenerator.Extension.makeException.

Doc from org.glassfish.pfl.basic.logex.WrapperGenerator.Extension.makeException.

Construct an exception from the message and the exception type. The method provides access to any additional annotations that may be needed.

Annotations
@Override
org.glassfish.pfl.basic.logex back to summary

public Interface WrapperGenerator.MessageInfo


Hidden interface implemented by the result of the makeWrapper call. This is needed in the resource file generation tool.

Method Summary

Modifier and TypeMethod and Description
public Map<String, String>

Returns:

map from message ID to message.
getMessageInfo
()

Return a map from message ID to message for all exceptions defined in a @ExceptionWrapper interface.

Method Detail

getMessageInfoback to summary
public Map<String, String> getMessageInfo()

Return a map from message ID to message for all exceptions defined in a @ExceptionWrapper interface. The key in the result is the message ID, and the value is the message string (defined in @Message).

Returns:Map<String, String>

map from message ID to message.

org.glassfish.pfl.basic.logex back to summary

pack-priv final Enum WrapperGenerator.ReturnType

extends Enum<WrapperGenerator.ReturnType>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final WrapperGenerator.ReturnType
public static final WrapperGenerator.ReturnType
public static final WrapperGenerator.ReturnType

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static WrapperGenerator.ReturnType
public static WrapperGenerator.ReturnType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

EXCEPTIONback to summary
public static final WrapperGenerator.ReturnType EXCEPTION
NULLback to summary
public static final WrapperGenerator.ReturnType NULL
STRINGback to summary
public static final WrapperGenerator.ReturnType STRING

Constructor Detail

ReturnTypeback to summary
private ReturnType()

Method Detail

valueOfback to summary
public static WrapperGenerator.ReturnType valueOf(String name)
valuesback to summary
public static WrapperGenerator.ReturnType[] values()
org.glassfish.pfl.basic.logex back to summary

pack-priv Class WrapperGenerator.ShortFormatter

extends Formatter
Class Inheritance

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public String
format(LogRecord record)

Implements abstract java.util.logging.Formatter.format.

Format the given log record and return the formatted string.

Inherited from java.util.logging.Formatter:
formatMessagegetHeadgetTail

Constructor Detail

ShortFormatterback to summary
pack-priv ShortFormatter()

Method Detail

formatback to summary
public String format(LogRecord record)

Implements abstract java.util.logging.Formatter.format.

Doc from java.util.logging.Formatter.format.

Format the given log record and return the formatted string.

The resulting formatted String will normally include a localized and formatted version of the LogRecord's message field. It is recommended to use the Formatter#formatMessage convenience method to localize and format the message field.

Annotations
@Override