Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

com.github.andrasbeni:giftwrap-parent

Package Overview
Maintainers
1
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.github.andrasbeni:giftwrap-parent

An annotation processor that creates decorators.

  • 1.0.0
  • Source
  • Maven

Version published
Maintainers
1
Source

giftwrap

Build Status

A Dagger 2 inspired wrapper generator library

giftwrap generates decorator classes at compile-time

Usage

Create the annotation
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.METHOD)
@InterceptedBy(LoggerInterceptor.class)
public @interface Logged {

	LogLevel value() default LogLevel.DEBUG;
	
}
Create the corresponding interceptor
public class LoggerInterceptor implements Interceptor<Logged> {

	private static final Logger logger = Logger.getLogger("entrylogger");
	
	@Override
	public Object intercept(Interception<Logged> interception) throws Exception {
		Level level = interception.getAnnotation().value().julLevel();
		logger.log(level, "Entering method " + interception.getMethodName());
		return interception.proceed();
	}

}
Annotate your class
@GiftWrap
public class Whatever {

	@Logged(LogLevel.DEBUG)
	@Transactional
	public String doWhatever(String result) throws IOException {
		return result;
	}

}
Instantiate the wrapper
Whatever object = new WhateverIntercepted(
        contructor, arguments, ofWhatever,
		new LoggerInterceptor(), 
		new TransactionInterceptor());
Have a look at the stack
c.g.a.g.example.Whatever.doWhatever(Whatever.java:20)
c.g.a.g.example.WhateverIntercepted.access$0(WhateverIntercepted.java:1)
c.g.a.g.example.WhateverIntercepted$1.call(WhateverIntercepted.java:21)
c.g.a.g.Interception.proceed(Interception.java:32)
c.g.a.g.example.LoggerInterceptor.intercept(LoggerInterceptor.java:18)
c.g.a.g.InterceptorCallable.call(InterceptorCallable.java:27)
c.g.a.g.Interception.proceed(Interception.java:32)
c.g.a.g.example.TransactionInterceptor.intercept(TransactionInterceptor.java:10)
c.g.a.g.InterceptorCallable.call(InterceptorCallable.java:27)
c.g.a.g.example.WhateverIntercepted.doWhatever(WhateverIntercepted.java:35)

FAQs

Package last updated on 22 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc