All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nico.aoc.scan.AocAnnotationScanner Maven / Gradle / Ivy

There is a newer version: 1.1.3
Show newest version
package org.nico.aoc.scan;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;

import org.nico.aoc.ConfigKey;
import org.nico.aoc.book.Book;
import org.nico.aoc.book.shop.BookShop;
import org.nico.aoc.throwable.BookHandlingException;
import org.nico.log.Logging;
import org.nico.log.LoggingHelper;
import org.nico.util.collection.CollectionUtils;
import org.nico.util.reflect.ClassUtils;

/** 
 * 
 * @author nico
 * @version createTime:2018年1月21日 下午1:56:52
 */

public class AocAnnotationScanner extends AocAbstractScanner{

	private Logging logging = LoggingHelper.getLogging(AocAnnotationScanner.class);

	@Override
	public List scan(List packs) throws BookHandlingException {
		List newBooks = new ArrayList();
		if(packs == null || packs.isEmpty()){
			return newBooks;
		}
		BookShop bookShop = BookShop.getInstance();
		try {
			List> classes = new ArrayList>();
			for(String pack: packs){
				try{
					logging.info("Scanning the class package's name:" + pack);
					classes.addAll(ClassUtils.getClasses(pack));
				}catch(Exception e){
					logging.error("Scanner package's fail at:" + e.getMessage());
					logging.error(e);
				}
			}
			if(CollectionUtils.isNotBlank(classes)){
				for(int index = classes.size() - 1; index >= 0; index --){
					Class clazz = classes.get(index);
					Annotation[] annotations = clazz.getDeclaredAnnotations();
					boolean access = false;
					if(annotations != null && annotations.length > 0){
						for(Annotation an: annotations){
							if(ConfigKey.ACCESS_BOOK_ABOUT_ANNOTATIONS.contains(an.annotationType())){
								String id = assemble.generateId(clazz);
								if(! bookShop.containsBook(id)){
									Book book = assemble.assembleBook(id, clazz);
									bookShop.put(book);
									newBooks.add(book);
								}
								break;
							}
						}
					}
				}
			}
		} catch (Throwable e) {
			throw new BookHandlingException(e.getMessage(), e);
		}
		return newBooks;
	}


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy