I Wanted Orange (The machine would not make a mistake.)


Codec decorators in Preon: The right way

Here's the wrong way to use decorators in Preon. They'll only work on the first level, and won't apply to nested Preon objects.

final DefaultCodecFactory fact = new DefaultCodecFactory();
Codec<MyFileType> codec = fact.create(MyFileType.class);
final LoggingDecorator ld = new LoggingDecorator(new CustomLogger());
codec = ld.decorate(codec,null,MyFileType.class,null);
// Resulting codec only does outermost-level logging.

The right way appears to be:

final DefaultCodecFactory fact = new DefaultCodecFactory();
final CodecDecorator[] decorators = new CodecDecorator[]{
    new LoggingDecorator(new CustomLogger())
final Codec<MyFileType> codec = fact.create(null, MyFileType.class, new CodecFactory[]{},decorators);
I haven't found any other way to alter the decorator-chain yet.
Tagged as: Comments Off
Comments (0) Trackbacks (0)

Sorry, the comment form is closed at this time.

Trackbacks are disabled.