binder.bind(VelocityContext.class).toProvider(VelocityContextProvider.class);
binder.bind(Engine.class).toProvider(CTLEngineProvider.class);
binder.bind(Context.class).toProvider(CTLContextProvider.class);
// 注册所有的Restful服务对象
ServiceHelper jRestContext = ServiceHelper.getInstance();
Path annotation;
String[] uris;
String mimiType, name;
String[] mimiTypes;
Field[] fields;
RemoteReference remoteServiceAnnotation;
RESTful resourceAnnotation;
Class<RemoteReference> remoteServiceClass = RemoteReference.class;
Class type;
for (Class clazz : classes) {
if (clazz.isAnnotationPresent(RESTful.class)) {
resourceAnnotation = (RESTful)clazz.getAnnotation(RESTful.class);
if(resourceAnnotation.remoteable()){
name = resourceAnnotation.name();
if (name == null || name.trim().equals(""))
name = clazz.getName();
jRestContext.addRemoteService(name, clazz);
}
}
// 绑定远程服务引用的Provider
fields = clazz.getDeclaredFields();
for (Field f : fields) {
if (f.isAnnotationPresent(remoteServiceClass)) {
remoteServiceAnnotation = f
.getAnnotation(remoteServiceClass);
type = f.getType();
binder.bind(type).annotatedWith(
remoteServiceClass).toProvider(
RemoteServiceProvider.create(type));
}
}
if (clazz.isAnnotationPresent(Path.class)) {
// 注册Rest服务
annotation = (Path) clazz.getAnnotation(Path.class);
uris = annotation.value();
int index = 0;
for (String uri : uris)
jRestContext.addResource(uri, clazz, index++ == 0);
}else if (clazz.isAnnotationPresent(RESTful.class)) {
jRestContext.addResourceByClassMethodInfo(clazz);
}else if (RequestContentReader.class.isAssignableFrom(clazz)) {
// 注册RequestContentReader
try {
RequestContentReader reader = (RequestContentReader) clazz
.newInstance();