Ximplementation基于Java注解的调用时路由框架
Ximplementation是一个基于Java注解的调用时路由框架。
它包括两个核心注解:
@Implementor
此注解标注于类,表明类是某个或者某些类的实现类,就像implements和extends关键字。
@Implement
此注解标注于@Implementor类的方法,表明方法是实现方法,就像@Overriden注解。
示例
假设有一个接口类如下:
public interface Service{ T plus(T a, T b); T minus(T a, T b); }
那么,你可以自由地编写它的实现类:
public class ServiceImplDefaultimplements Service { public T plus(T a, T b){...} public T minus(T a, T b){...} } public class ServiceImplPlusInteger implements Service { @Override public Integer plus(Integer a, Integer b){...} @NotImplement @Override public Integer minus(Integer a, Integer b){ throw new UnsupportedOperationException(); } } @Implementor(Service.class) public class ServiceImplMinusInteger { @Implement public Integer minus(Integer a, Integer b){...} }
注:ServiceImplMinusInteger并不是必须的。而且,你可以在同一个或者多个其他@Implementor实现类内为plus和/或minus编写多个实现方法。
之后,你可以通过如下方式获得Service的实例:
Implementationimplementation = new ImplementationResolver().resolve(Service.class, ServiceImplDefault.class, ServiceImplPlusInteger.class, ServiceImplMinusInteger.class); ImplementorBeanFactory implementorBeanFactory = SimpleImplementorBeanFactory .valueOf(new ServiceImplDefault (), new ServiceImplPlusInteger(), new ServiceImplMinusInteger()); Service service = new ProxyImplementeeBeanBuilder().build(implementation, implementorBeanFactory);
对于serivce.plus方法的调用,如果参数类型是Integer,将被路由至ServiceImplPlusInteger.plus方法,否则,将被路由至ServiceImplDefault.plus方法;对于serivce.minus方法的调用,如果参数类型是Integer,将被路由至ServiceImplMinusInteger.minus方法,否则,将被路由至ServiceImplDefault.minus方法。
扩展库
Ximplementation-spring是一个将ximplementation整合至Spring的库,使Spring能够支持多实例依赖注入和更多ximplementation特性。
评论
EChartsAnnotationECharts的Java注解框架
ECharts的Java注解框架:用原生Java注解来映射ECharts的Option类,提供Annotation到JSON的转换功能。思路Howitworks1在后台使用Annotation来标注B
EChartsAnnotationECharts的Java注解框架
0
Mongodb-ORM基于Java的ORM框架
mongodb-orm简介MongodbORM是基于java的ORM框架,简化了SDK的使用,使代码变得更清晰、简单。 与Ibatis类似,将查询、执行语句封装在xml中,与代码隔离。简称MQL。 项
Mongodb-ORM基于Java的ORM框架
0
EasyJWeb基于JAVA的快速开发框架
EasyJWeb是基于java技术,用于企业级JavaWeb应用程序快速开发的MVC框架。框架设计构思来源于国内众多项目实践,框架的设计及实现借鉴当前主要流行的开源Web框架,如Rails、Strut
EasyJWeb基于JAVA的快速开发框架
0
ROMA Framework基于 POJO 的Java框架
Roma是一个基于POJO的Java框架,是唯一的“meta”(元)框架。使用Roma,你可以完全从你使用的技术中解脱出来。它是如何工作的?Roma提供称作“Aspects”的非常普通的行为接口。As
ROMA Framework基于 POJO 的Java框架
0