Giter VIP home page Giter VIP logo

wraop's Introduction

WrAOP wrapper building library

Introduction

How many times have you created a wrapper class that delegates all the methods to it's delegate, while adding some functionality in few places? I've done this many times. This library would allow you to do this easily.

Another option to use it is when you need to provide plugin functionality for your library or application. Now you don't need to create chain of responsibility or "pre" and "post" interfaces simply for extension points. Simply allow your users to register aspects and wrap your objects with the help of this library.

Comparison to other options

  • Spring AOP.

    Actually this library is a wrapper over Spring AOP. If you can use Spring AOP directly, just do it. But not every object is in context. And this library allows to apply your wrapper at much more granular fashion. You directly say which objects you'd like to wrap

  • AspectJ

    AspectJ is much more global thing. It enhances your classes and prefers to do this in compile time. This library creates you proxies, and you can use AspectJ annotations to do the work.

Requirements

  • Java 6
  • Spring AOP

Optional dependencies

  • cglib - to make faster proxies
  • AspectJ weaver - to use AspectJ annotations

Quick start

 new WrapperFactoryBuilder().<TargetClass>build()
    .withAspects(aspect1, aspect2, aspect3).wrapAllInterfaces(target)

That's all. You can reuse the factory with aspects registered to wrap multiple objects. It's thread-safe. It will autodetect aspect types (Spring/AOP alliance/AspectJ). Here is an example aspect from tests:

 @Aspect
 public class ConstantReturningAspect {
     private final Object constant;

     public ConstantReturningAspect(Object constant) {
         this.constant = constant;
     }

     @Around("execution(* im.tym.wraop.data.Transformer.transform(..))")
     Object returnConstant() {
         return constant;
     }
 }

Easy, is not it?

Details

For WrapperFactory, please see it's javadoc. As of aspect types, please refer to Spring AOP documentation: http://docs.spring.io/spring/docs/3.2.3.RELEASE/spring-framework-reference/html/aop.html#aop-introduction

Contacts

Project home page: https://github.com/tivv/wraop You can submit bugs, feature requests or pull requests there.

Author contact: http://blog.vit.tym.im

wraop's People

Contributors

tivv avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.