├── WebContent ├── META-INF │ └── MANIFEST.MF ├── WEB-INF │ ├── lib │ │ └── dom4j-1.6.1.jar │ ├── minisMVC-servlet.xml │ └── web.xml └── jsp │ ├── error.jsp │ └── test.jsp ├── src └── com │ ├── minis │ ├── aop │ │ ├── Advice.java │ │ ├── AfterAdvice.java │ │ ├── Interceptor.java │ │ ├── AopProxy.java │ │ ├── BeforeAdvice.java │ │ ├── framework │ │ │ ├── AopProxy.java │ │ │ ├── AopProxyFactory.java │ │ │ ├── DefaultAopProxyFactory.java │ │ │ ├── adapter │ │ │ │ ├── MethodBeforeAdviceInterceptor.java │ │ │ │ └── AfterReturningAdviceInterceptor.java │ │ │ ├── ReflectiveMethodInvocation.java │ │ │ ├── JdkDynamicAopProxy.java │ │ │ ├── autoproxy │ │ │ │ └── BeanNameAutoProxyCreator.java │ │ │ └── ProxyFactoryBean.java │ │ ├── PointcutAdvisor.java │ │ ├── AopProxyFactory.java │ │ ├── Pointcut.java │ │ ├── MethodInterceptor.java │ │ ├── MethodMatcher.java │ │ ├── Advisor.java │ │ ├── MethodBeforeAdvice.java │ │ ├── MethodInvocation.java │ │ ├── AfterReturningAdvice.java │ │ ├── DefaultAopProxyFactory.java │ │ ├── MethodBeforeAdviceInterceptor.java │ │ ├── DefaultAdvisor.java │ │ ├── AfterReturningAdviceInterceptor.java │ │ ├── NameMatchMethodPointcut.java │ │ ├── support │ │ │ ├── NameMatchMethodPointcut.java │ │ │ └── NameMatchMethodPointcutAdvisor.java │ │ ├── JdkDynamicAopProxy.java │ │ ├── ReflectiveMethodInvocation.java │ │ ├── NameMatchMethodPointcutAdvisor.java │ │ ├── AsyncExecutionInterceptor.java │ │ └── ProxyFactoryBean.java │ ├── batis │ │ ├── SqlSessionFactoryBuilder.java │ │ ├── SqlSessionFactory.java │ │ ├── SqlSession.java │ │ ├── MapperNode.java │ │ ├── DefaultSqlSession.java │ │ └── DefaultSqlSessionFactory.java │ ├── core │ │ ├── Resource.java │ │ ├── env │ │ │ ├── EnvironmentCapable.java │ │ │ ├── Environment.java │ │ │ └── PropertyResolver.java │ │ └── ClassPathXmlResource.java │ ├── util │ │ ├── concurrent │ │ │ ├── FailureCallback.java │ │ │ ├── SuccessCallback.java │ │ │ ├── ListenableFuture.java │ │ │ ├── ListenableFutureTask.java │ │ │ └── ListenableFutureCallbackRegistry.java │ │ ├── ObjectMapper.java │ │ ├── WebUtils.java │ │ ├── DefaultObjectMapper.java │ │ └── PatternMatchUtils.java │ ├── beans │ │ ├── factory │ │ │ ├── NoSuchBeanDefinitionException.java │ │ │ ├── BeanFactoryAware.java │ │ │ ├── FactoryBean.java │ │ │ ├── config │ │ │ │ ├── ConfigurableListableBeanFactory.java │ │ │ │ ├── BeanFactoryPostProcessor.java │ │ │ │ ├── SingletonBeanRegistry.java │ │ │ │ ├── BeanPostProcessor.java │ │ │ │ ├── AutowireCapableBeanFactory.java │ │ │ │ ├── ConfigurableBeanFactory.java │ │ │ │ ├── ConstructorArgumentValues.java │ │ │ │ ├── ConstructorArgumentValue.java │ │ │ │ ├── AbstractAutowireCapableBeanFactory.java │ │ │ │ └── BeanDefinition.java │ │ │ ├── BeanFactory.java │ │ │ ├── annotation │ │ │ │ ├── Autowired.java │ │ │ │ └── AutowiredAnnotationBeanPostProcessor.java │ │ │ ├── support │ │ │ │ ├── BeanDefinitionRegistry.java │ │ │ │ ├── FactoryBeanRegistrySupport.java │ │ │ │ ├── DefaultListableBeanFactory.java │ │ │ │ └── DefaultSingletonBeanRegistry.java │ │ │ ├── ListableBeanFactory.java │ │ │ └── xml │ │ │ │ └── XmlBeanDefinitionReader.java │ │ ├── BeansException.java │ │ ├── PropertyEditor.java │ │ ├── AbstractPropertyAccessor.java │ │ ├── PropertyValue.java │ │ ├── StringEditor.java │ │ ├── CustomNumberEditor.java │ │ ├── PropertyValues.java │ │ ├── BeanWrapperImpl.java │ │ └── PropertyEditorRegistrySupport.java │ ├── web │ │ ├── servlet │ │ │ ├── ViewResolver.java │ │ │ ├── HandlerMapping.java │ │ │ ├── HandlerAdapter.java │ │ │ ├── View.java │ │ │ ├── view │ │ │ │ ├── JstlView.java │ │ │ │ └── InternalResourceViewResolver.java │ │ │ ├── ModelAndView.java │ │ │ └── DispatcherServlet.java │ │ ├── bind │ │ │ ├── support │ │ │ │ ├── WebBindingInitializer.java │ │ │ │ └── WebDataBinderFactory.java │ │ │ ├── annotation │ │ │ │ ├── PathVariable.java │ │ │ │ ├── ResponseBody.java │ │ │ │ └── RequestMapping.java │ │ │ └── WebDataBinder.java │ │ ├── context │ │ │ ├── WebApplicationContext.java │ │ │ ├── support │ │ │ │ ├── XmlWebApplicationContext.java │ │ │ │ ├── XmlScanComponentHelper.java │ │ │ │ └── AnnotationConfigWebApplicationContext.java │ │ │ └── ContextLoaderListener.java │ │ └── method │ │ │ ├── HandlerMethod.java │ │ │ └── annotation │ │ │ ├── MappingRegistry.java │ │ │ ├── RequestMappingHandlerMapping.java │ │ │ └── RequestMappingHandlerAdapter.java │ ├── jdbc │ │ ├── core │ │ │ ├── RowMapper.java │ │ │ ├── StatementCallback.java │ │ │ ├── ResultSetExtractor.java │ │ │ ├── PreparedStatementCallback.java │ │ │ ├── RowMapperResultSetExtractor.java │ │ │ ├── OldJdbcTemplate.java │ │ │ ├── ArgumentPreparedStatementSetter.java │ │ │ └── JdbcTemplate.java │ │ ├── datasource │ │ │ └── SingleConnectionDataSource.java │ │ └── pool │ │ │ └── PooledDataSource.java │ ├── context │ │ ├── ApplicationEventPublisher.java │ │ ├── ApplicationListener.java │ │ ├── ApplicationContextAware.java │ │ ├── ApplicationContextEvent.java │ │ ├── ContextRefreshedEvent.java │ │ ├── ApplicationEvent.java │ │ ├── SimpleApplicationEventPublisher.java │ │ ├── ApplicationContext.java │ │ ├── ClassPathXmlApplicationContext.java │ │ └── AbstractApplicationContext.java │ ├── http │ │ └── converter │ │ │ ├── HttpMessageConverter.java │ │ │ └── DefaultHttpMessageConverter.java │ └── scheduling │ │ ├── annotation │ │ ├── Async.java │ │ ├── AsyncAnnotationAdvisor.java │ │ ├── AsyncResult.java │ │ └── AsyncAnnotationBeanPostProcessor.java │ │ └── concurrent │ │ └── ThreadPoolTaskExecutor.java │ └── test │ ├── service │ ├── AService.java │ ├── IAction.java │ ├── Action1.java │ ├── Action2.java │ ├── MyBeforeAdvice.java │ ├── MyAfterAdvice.java │ ├── BaseBaseService.java │ ├── BaseService.java │ ├── MyInterceptor.java │ ├── UserJdbcImpl.java │ ├── AServiceImpl.java │ ├── OldUserService.java │ └── UserService.java │ ├── DateInitializer.java │ ├── MyListener.java │ ├── MyBeanFactoryPostProcessor.java │ ├── entity │ └── User.java │ ├── LogBeanPostProcessor.java │ ├── CustomDateEditor.java │ └── controller │ └── HelloWorldBean.java ├── .idea ├── vcs.xml ├── .gitignore ├── modules.xml ├── libraries │ └── lib.xml ├── misc.xml ├── artifacts │ └── Minis_Web_exploded.xml └── Minis.iml ├── resources ├── mapper │ └── User_Mapper.xml └── applicationContext.xml └── README.md /WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /src/com/minis/aop/Advice.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | public interface Advice { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/com/minis/aop/AfterAdvice.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | public interface AfterAdvice extends Advice { 4 | 5 | } -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/dom4j-1.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YaleGuo/Minis/HEAD/WebContent/WEB-INF/lib/dom4j-1.6.1.jar -------------------------------------------------------------------------------- /src/com/minis/aop/Interceptor.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | public interface Interceptor extends Advice { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/com/minis/aop/AopProxy.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | public interface AopProxy { 4 | Object getProxy(); 5 | } 6 | 7 | -------------------------------------------------------------------------------- /src/com/minis/aop/BeforeAdvice.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | public interface BeforeAdvice extends Advice { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/com/test/service/AService.java: -------------------------------------------------------------------------------- 1 | package com.test.service; 2 | 3 | public interface AService { 4 | void sayHello(); 5 | } 6 | -------------------------------------------------------------------------------- /src/com/minis/batis/SqlSessionFactoryBuilder.java: -------------------------------------------------------------------------------- 1 | package com.minis.batis; 2 | 3 | public class SqlSessionFactoryBuilder { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/com/minis/aop/framework/AopProxy.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop.framework; 2 | 3 | public interface AopProxy { 4 | Object getProxy(); 5 | } 6 | 7 | -------------------------------------------------------------------------------- /src/com/test/service/IAction.java: -------------------------------------------------------------------------------- 1 | package com.test.service; 2 | 3 | public interface IAction { 4 | void doAction(); 5 | void doSomething(); 6 | } 7 | -------------------------------------------------------------------------------- /src/com/minis/aop/PointcutAdvisor.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | public interface PointcutAdvisor extends Advisor { 4 | Pointcut getPointcut(); 5 | } -------------------------------------------------------------------------------- /src/com/minis/core/Resource.java: -------------------------------------------------------------------------------- 1 | package com.minis.core; 2 | 3 | import java.util.Iterator; 4 | 5 | public interface Resource extends Iterator{ 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/com/minis/core/env/EnvironmentCapable.java: -------------------------------------------------------------------------------- 1 | package com.minis.core.env; 2 | 3 | public interface EnvironmentCapable { 4 | Environment getEnvironment(); 5 | } 6 | -------------------------------------------------------------------------------- /src/com/minis/util/concurrent/FailureCallback.java: -------------------------------------------------------------------------------- 1 | package com.minis.util.concurrent; 2 | 3 | public interface FailureCallback { 4 | void onFailure(Throwable ex); 5 | } -------------------------------------------------------------------------------- /src/com/minis/util/concurrent/SuccessCallback.java: -------------------------------------------------------------------------------- 1 | package com.minis.util.concurrent; 2 | 3 | public interface SuccessCallback { 4 | void onSuccess(T result); 5 | } 6 | -------------------------------------------------------------------------------- /WebContent/WEB-INF/minisMVC-servlet.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/NoSuchBeanDefinitionException.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory; 2 | 3 | public class NoSuchBeanDefinitionException extends Exception { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/com/minis/aop/AopProxyFactory.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | public interface AopProxyFactory { 4 | AopProxy createAopProxy(Object target, PointcutAdvisor adviseor); 5 | } 6 | -------------------------------------------------------------------------------- /src/com/minis/aop/Pointcut.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | public interface Pointcut { 4 | //ClassFilter getClassFilter(); 5 | 6 | MethodMatcher getMethodMatcher(); 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/BeanFactoryAware.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory; 2 | 3 | public interface BeanFactoryAware { 4 | void setBeanFactory(BeanFactory beanFactory); 5 | } 6 | -------------------------------------------------------------------------------- /src/com/minis/web/servlet/ViewResolver.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.servlet; 2 | 3 | public interface ViewResolver { 4 | View resolveViewName(String viewName) throws Exception; 5 | 6 | } 7 | -------------------------------------------------------------------------------- /src/com/minis/batis/SqlSessionFactory.java: -------------------------------------------------------------------------------- 1 | package com.minis.batis; 2 | 3 | public interface SqlSessionFactory { 4 | SqlSession openSession(); 5 | MapperNode getMapperNode(String name); 6 | } 7 | -------------------------------------------------------------------------------- /src/com/minis/beans/BeansException.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans; 2 | 3 | public class BeansException extends Exception { 4 | public BeansException(String msg) { 5 | super(msg); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/com/minis/aop/MethodInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | public interface MethodInterceptor extends Interceptor{ 4 | Object invoke(MethodInvocation invocation) throws Throwable; 5 | } 6 | -------------------------------------------------------------------------------- /src/com/minis/aop/MethodMatcher.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | public interface MethodMatcher { 6 | boolean matches(Method method, Class targetClass); 7 | } 8 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /src/com/minis/beans/PropertyEditor.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans; 2 | 3 | public interface PropertyEditor { 4 | void setAsText(String text); 5 | void setValue(Object value); 6 | Object getValue(); 7 | String getAsText(); 8 | } 9 | -------------------------------------------------------------------------------- /src/com/minis/aop/Advisor.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | public interface Advisor { 4 | MethodInterceptor getMethodInterceptor(); 5 | void setMethodInterceptor(MethodInterceptor methodInterceptor); 6 | Advice getAdvice(); 7 | } 8 | -------------------------------------------------------------------------------- /src/com/minis/web/bind/support/WebBindingInitializer.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.bind.support; 2 | 3 | import com.minis.web.bind.WebDataBinder; 4 | 5 | public interface WebBindingInitializer { 6 | void initBinder(WebDataBinder binder); 7 | } 8 | -------------------------------------------------------------------------------- /src/com/minis/jdbc/core/RowMapper.java: -------------------------------------------------------------------------------- 1 | package com.minis.jdbc.core; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.SQLException; 5 | 6 | public interface RowMapper { 7 | T mapRow(ResultSet rs, int rowNum) throws SQLException; 8 | } 9 | -------------------------------------------------------------------------------- /src/com/minis/util/ObjectMapper.java: -------------------------------------------------------------------------------- 1 | package com.minis.util; 2 | 3 | public interface ObjectMapper { 4 | void setDateFormat(String dateFormat); 5 | void setDecimalFormat(String decimalFormat); 6 | String writeValuesAsString(Object obj); 7 | } 8 | -------------------------------------------------------------------------------- /src/com/minis/context/ApplicationEventPublisher.java: -------------------------------------------------------------------------------- 1 | package com.minis.context; 2 | 3 | public interface ApplicationEventPublisher { 4 | void publishEvent(ApplicationEvent event); 5 | void addApplicationListener(ApplicationListener listener); 6 | } 7 | -------------------------------------------------------------------------------- /src/com/minis/aop/MethodBeforeAdvice.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | public interface MethodBeforeAdvice extends BeforeAdvice{ 6 | void before(Method method, Object[] args, Object target) throws Throwable; 7 | } 8 | -------------------------------------------------------------------------------- /src/com/minis/context/ApplicationListener.java: -------------------------------------------------------------------------------- 1 | package com.minis.context; 2 | 3 | import java.util.EventListener; 4 | 5 | public interface ApplicationListener extends EventListener { 6 | void onApplicationEvent(E event); 7 | } 8 | -------------------------------------------------------------------------------- /src/com/minis/jdbc/core/StatementCallback.java: -------------------------------------------------------------------------------- 1 | package com.minis.jdbc.core; 2 | 3 | import java.sql.SQLException; 4 | import java.sql.Statement; 5 | 6 | public interface StatementCallback { 7 | Object doInStatement(Statement stmt) throws SQLException; 8 | } 9 | -------------------------------------------------------------------------------- /src/com/minis/aop/framework/AopProxyFactory.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop.framework; 2 | 3 | import com.minis.aop.Advisor; 4 | import com.minis.aop.PointcutAdvisor; 5 | 6 | public interface AopProxyFactory { 7 | AopProxy createAopProxy(Object target, Advisor adviseor); 8 | } 9 | -------------------------------------------------------------------------------- /src/com/minis/context/ApplicationContextAware.java: -------------------------------------------------------------------------------- 1 | package com.minis.context; 2 | 3 | import com.minis.beans.BeansException; 4 | 5 | public interface ApplicationContextAware { 6 | void setApplicationContext(ApplicationContext applicationContext) throws BeansException; 7 | } 8 | -------------------------------------------------------------------------------- /src/com/minis/aop/MethodInvocation.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | public interface MethodInvocation { 6 | Method getMethod(); 7 | Object[] getArguments(); 8 | Object getThis(); 9 | Object proceed() throws Throwable; 10 | } 11 | -------------------------------------------------------------------------------- /src/com/minis/jdbc/core/ResultSetExtractor.java: -------------------------------------------------------------------------------- 1 | package com.minis.jdbc.core; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.SQLException; 5 | 6 | public interface ResultSetExtractor { 7 | 8 | T extractData(ResultSet rs) throws SQLException; 9 | 10 | } 11 | 12 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/FactoryBean.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory; 2 | 3 | public interface FactoryBean { 4 | T getObject() throws Exception; 5 | 6 | Class getObjectType(); 7 | 8 | default boolean isSingleton() { 9 | return true; 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/com/minis/aop/AfterReturningAdvice.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | public interface AfterReturningAdvice extends AfterAdvice { 6 | void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable; 7 | } 8 | -------------------------------------------------------------------------------- /src/com/minis/core/env/Environment.java: -------------------------------------------------------------------------------- 1 | package com.minis.core.env; 2 | 3 | public interface Environment extends PropertyResolver { 4 | String[] getActiveProfiles(); 5 | 6 | String[] getDefaultProfiles(); 7 | 8 | boolean acceptsProfiles(String... profiles); 9 | 10 | } 11 | 12 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/com/minis/jdbc/core/PreparedStatementCallback.java: -------------------------------------------------------------------------------- 1 | package com.minis.jdbc.core; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.SQLException; 5 | 6 | public interface PreparedStatementCallback { 7 | Object doInPreparedStatement(PreparedStatement stmt) throws SQLException; 8 | } 9 | -------------------------------------------------------------------------------- /src/com/minis/util/concurrent/ListenableFuture.java: -------------------------------------------------------------------------------- 1 | package com.minis.util.concurrent; 2 | 3 | import java.util.concurrent.Future; 4 | 5 | public interface ListenableFuture extends Future { 6 | void addCallback(SuccessCallback successCallback, FailureCallback failureCallback); 7 | } 8 | -------------------------------------------------------------------------------- /src/com/minis/aop/DefaultAopProxyFactory.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | public class DefaultAopProxyFactory implements AopProxyFactory { 4 | 5 | @Override 6 | public AopProxy createAopProxy(Object target, PointcutAdvisor advisor) { 7 | return new JdkDynamicAopProxy(target, advisor); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/com/minis/web/servlet/HandlerMapping.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.servlet; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | import com.minis.web.method.HandlerMethod; 6 | 7 | public interface HandlerMapping { 8 | HandlerMethod getHandler(HttpServletRequest request) throws Exception; 9 | } 10 | -------------------------------------------------------------------------------- /src/com/minis/http/converter/HttpMessageConverter.java: -------------------------------------------------------------------------------- 1 | package com.minis.http.converter; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.http.HttpServletResponse; 6 | 7 | public interface HttpMessageConverter { 8 | void write(Object obj, HttpServletResponse response) throws IOException; 9 | } 10 | -------------------------------------------------------------------------------- /resources/mapper/User_Mapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/config/ConfigurableListableBeanFactory.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory.config; 2 | 3 | import com.minis.beans.factory.ListableBeanFactory; 4 | 5 | public interface ConfigurableListableBeanFactory 6 | extends ListableBeanFactory, AutowireCapableBeanFactory, ConfigurableBeanFactory { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/config/BeanFactoryPostProcessor.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory.config; 2 | 3 | import com.minis.beans.BeansException; 4 | import com.minis.beans.factory.BeanFactory; 5 | 6 | public interface BeanFactoryPostProcessor { 7 | void postProcessBeanFactory(BeanFactory beanFactory) throws BeansException; 8 | } 9 | -------------------------------------------------------------------------------- /src/com/minis/web/servlet/HandlerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.servlet; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | public interface HandlerAdapter { 7 | ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception; 8 | } 9 | -------------------------------------------------------------------------------- /.idea/libraries/lib.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/com/test/service/Action1.java: -------------------------------------------------------------------------------- 1 | package com.test.service; 2 | 3 | public class Action1 implements IAction { 4 | 5 | @Override 6 | public void doAction() { 7 | System.out.println("really do action1"); 8 | 9 | } 10 | 11 | @Override 12 | public void doSomething() { 13 | System.out.println("really do something action1"); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/com/test/service/Action2.java: -------------------------------------------------------------------------------- 1 | package com.test.service; 2 | 3 | public class Action2 implements IAction { 4 | 5 | @Override 6 | public void doAction() { 7 | System.out.println("really do action2"); 8 | 9 | } 10 | 11 | @Override 12 | public void doSomething() { 13 | System.out.println("really do something action2"); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/config/SingletonBeanRegistry.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory.config; 2 | 3 | public interface SingletonBeanRegistry { 4 | void registerSingleton(String beanName, Object singletonObject); 5 | 6 | Object getSingleton(String beanName); 7 | 8 | boolean containsSingleton(String beanName); 9 | 10 | String[] getSingletonNames(); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/BeanFactory.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory; 2 | 3 | import com.minis.beans.BeansException; 4 | 5 | public interface BeanFactory { 6 | Object getBean(String name) throws BeansException; 7 | boolean containsBean(String name); 8 | boolean isSingleton(String name); 9 | boolean isPrototype(String name); 10 | Class getType(String name); 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/com/minis/context/ApplicationContextEvent.java: -------------------------------------------------------------------------------- 1 | package com.minis.context; 2 | 3 | public abstract class ApplicationContextEvent extends ApplicationEvent { 4 | public ApplicationContextEvent(ApplicationContext source) { 5 | super(source); 6 | } 7 | 8 | public final ApplicationContext getApplicationContext() { 9 | return (ApplicationContext) getSource(); 10 | } 11 | 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/com/minis/context/ContextRefreshedEvent.java: -------------------------------------------------------------------------------- 1 | package com.minis.context; 2 | 3 | public class ContextRefreshedEvent extends ApplicationContextEvent{ 4 | 5 | private static final long serialVersionUID = 1L; 6 | 7 | public ContextRefreshedEvent(ApplicationContext source) { 8 | super(source); 9 | } 10 | 11 | public String toString() { 12 | return this.msg; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/com/minis/context/ApplicationEvent.java: -------------------------------------------------------------------------------- 1 | package com.minis.context; 2 | 3 | import java.util.EventObject; 4 | 5 | public abstract class ApplicationEvent extends EventObject { 6 | 7 | private static final long serialVersionUID = 1L; 8 | protected String msg = null; 9 | 10 | public ApplicationEvent(Object arg0) { 11 | super(arg0); 12 | this.msg = arg0.toString(); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/com/minis/web/bind/annotation/PathVariable.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.bind.annotation; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.RetentionPolicy; 7 | 8 | @Target(ElementType.PARAMETER) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface PathVariable { 11 | } 12 | -------------------------------------------------------------------------------- /src/com/minis/web/bind/annotation/ResponseBody.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.bind.annotation; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.RetentionPolicy; 7 | 8 | @Target({ElementType.METHOD}) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface ResponseBody { 11 | 12 | } -------------------------------------------------------------------------------- /src/com/minis/aop/framework/DefaultAopProxyFactory.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop.framework; 2 | 3 | import com.minis.aop.Advisor; 4 | import com.minis.aop.PointcutAdvisor; 5 | 6 | public class DefaultAopProxyFactory implements AopProxyFactory { 7 | 8 | @Override 9 | public AopProxy createAopProxy(Object target, Advisor advisor) { 10 | return new JdkDynamicAopProxy(target, advisor); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/annotation/Autowired.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory.annotation; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.RetentionPolicy; 7 | 8 | @Target(ElementType.FIELD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Autowired { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /WebContent/jsp/error.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 | Error! 11 | 12 | -------------------------------------------------------------------------------- /src/com/minis/batis/SqlSession.java: -------------------------------------------------------------------------------- 1 | package com.minis.batis; 2 | 3 | import com.minis.jdbc.core.JdbcTemplate; 4 | import com.minis.jdbc.core.PreparedStatementCallback; 5 | 6 | public interface SqlSession { 7 | void setJdbcTemplate(JdbcTemplate jdbcTemplate); 8 | void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory); 9 | Object selectOne(String sqlid, Object[] args, PreparedStatementCallback pstmtcallback); 10 | } 11 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/support/BeanDefinitionRegistry.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory.support; 2 | 3 | import com.minis.beans.factory.config.BeanDefinition; 4 | 5 | public interface BeanDefinitionRegistry { 6 | void registerBeanDefinition(String name, BeanDefinition bd); 7 | void removeBeanDefinition(String name); 8 | BeanDefinition getBeanDefinition(String name); 9 | boolean containsBeanDefinition(String name); 10 | } 11 | -------------------------------------------------------------------------------- /src/com/test/service/MyBeforeAdvice.java: -------------------------------------------------------------------------------- 1 | package com.test.service; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import com.minis.aop.MethodBeforeAdvice; 6 | 7 | public class MyBeforeAdvice implements MethodBeforeAdvice{ 8 | 9 | @Override 10 | public void before(Method method, Object[] args, Object target) throws Throwable { 11 | System.out.println("----------my interceptor befor method call----------"); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/com/minis/scheduling/annotation/Async.java: -------------------------------------------------------------------------------- 1 | package com.minis.scheduling.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ElementType.TYPE, ElementType.METHOD}) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Async { 11 | String value() default ""; 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/com/test/DateInitializer.java: -------------------------------------------------------------------------------- 1 | package com.test; 2 | 3 | import java.util.Date; 4 | 5 | import com.minis.web.bind.WebDataBinder; 6 | import com.minis.web.bind.support.WebBindingInitializer; 7 | 8 | public class DateInitializer implements WebBindingInitializer{ 9 | @Override 10 | public void initBinder(WebDataBinder binder) { 11 | binder.registerCustomEditor(Date.class, new CustomDateEditor(Date.class,"yyyy-MM-dd", false)); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/com/test/service/MyAfterAdvice.java: -------------------------------------------------------------------------------- 1 | package com.test.service; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import com.minis.aop.AfterReturningAdvice; 6 | 7 | public class MyAfterAdvice implements AfterReturningAdvice{ 8 | @Override 9 | public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable { 10 | System.out.println("----------my interceptor after method call----------"); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/com/minis/web/context/WebApplicationContext.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.context; 2 | 3 | import javax.servlet.ServletContext; 4 | 5 | import com.minis.context.ApplicationContext; 6 | 7 | public interface WebApplicationContext extends ApplicationContext { 8 | String ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE = WebApplicationContext.class.getName() + ".ROOT"; 9 | 10 | ServletContext getServletContext(); 11 | void setServletContext(ServletContext servletContext); 12 | } 13 | -------------------------------------------------------------------------------- /src/com/minis/web/bind/annotation/RequestMapping.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.bind.annotation; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | import java.lang.annotation.ElementType; 6 | import java.lang.annotation.RetentionPolicy; 7 | 8 | @Target(value={ElementType.METHOD}) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface RequestMapping { 11 | String value() default ""; 12 | String method() default "GET"; 13 | } 14 | -------------------------------------------------------------------------------- /WebContent/jsp/test.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=ISO-8859-1" 2 | pageEncoding="ISO-8859-1"%> 3 | 4 | 5 | 6 | 7 | 8 | minis request 9 | 10 | 11 | 12 | 13 | <%= request.getAttribute("msg").toString() %> 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/com/test/MyListener.java: -------------------------------------------------------------------------------- 1 | package com.test; 2 | 3 | import com.minis.context.ApplicationListener; 4 | import com.minis.context.ContextRefreshedEvent; 5 | 6 | public class MyListener implements ApplicationListener { 7 | @Override 8 | public void onApplicationEvent(ContextRefreshedEvent event) { 9 | System.out.println(".........refreshed.........beans count : " + event.getApplicationContext().getBeanDefinitionCount()); 10 | } 11 | 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/config/BeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory.config; 2 | 3 | import com.minis.beans.BeansException; 4 | import com.minis.beans.factory.BeanFactory; 5 | 6 | public interface BeanPostProcessor { 7 | Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException; 8 | 9 | Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException; 10 | 11 | void setBeanFactory(BeanFactory beanFactory); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/com/minis/aop/MethodBeforeAdviceInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | public class MethodBeforeAdviceInterceptor implements MethodInterceptor { 4 | private final MethodBeforeAdvice advice; 5 | 6 | public MethodBeforeAdviceInterceptor(MethodBeforeAdvice advice) { 7 | this.advice = advice; 8 | } 9 | 10 | @Override 11 | public Object invoke(MethodInvocation mi) throws Throwable { 12 | this.advice.before(mi.getMethod(), mi.getArguments(), mi.getThis()); 13 | return mi.proceed(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/com/test/MyBeanFactoryPostProcessor.java: -------------------------------------------------------------------------------- 1 | package com.test; 2 | 3 | import com.minis.beans.BeansException; 4 | import com.minis.beans.factory.BeanFactory; 5 | import com.minis.beans.factory.config.BeanFactoryPostProcessor; 6 | 7 | public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor{ 8 | 9 | @Override 10 | public void postProcessBeanFactory(BeanFactory beanFactory) throws BeansException { 11 | System.out.println(".........MyBeanFactoryPostProcessor..........."); 12 | 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/com/test/service/BaseBaseService.java: -------------------------------------------------------------------------------- 1 | package com.test.service; 2 | 3 | public class BaseBaseService { 4 | private AServiceImpl as; 5 | 6 | public AServiceImpl getAs() { 7 | return as; 8 | } 9 | public void setAs(AServiceImpl as) { 10 | this.as = as; 11 | } 12 | public BaseBaseService() { 13 | } 14 | public void sayHello() { 15 | System.out.println("Base Base Service says hello"); 16 | 17 | } 18 | 19 | public void init() { 20 | System.out.println("..........call init-mothod.........."); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/ListableBeanFactory.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory; 2 | 3 | import java.util.Map; 4 | 5 | import com.minis.beans.BeansException; 6 | 7 | public interface ListableBeanFactory extends BeanFactory { 8 | 9 | boolean containsBeanDefinition(String beanName); 10 | 11 | int getBeanDefinitionCount(); 12 | 13 | String[] getBeanDefinitionNames(); 14 | 15 | String[] getBeanNamesForType(Class type); 16 | 17 | Map getBeansOfType(Class type) throws BeansException; 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /src/com/minis/aop/DefaultAdvisor.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | public class DefaultAdvisor implements Advisor{ 4 | private MethodInterceptor methodInterceptor; 5 | 6 | public DefaultAdvisor() { 7 | } 8 | 9 | public void setMethodInterceptor(MethodInterceptor methodInterceptor) { 10 | this.methodInterceptor = methodInterceptor; 11 | } 12 | 13 | public MethodInterceptor getMethodInterceptor() { 14 | return this.methodInterceptor; 15 | } 16 | 17 | @Override 18 | public Advice getAdvice() { 19 | return this.methodInterceptor; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/com/minis/web/bind/support/WebDataBinderFactory.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.bind.support; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | import com.minis.web.bind.WebDataBinder; 6 | 7 | public class WebDataBinderFactory { 8 | public WebDataBinder createBinder(HttpServletRequest request, Object target, String objectName) { 9 | WebDataBinder wbd= new WebDataBinder(target,objectName); 10 | initBinder(wbd, request); 11 | return wbd; 12 | } 13 | protected void initBinder(WebDataBinder dataBinder, HttpServletRequest request){ 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/com/minis/aop/AfterReturningAdviceInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | public class AfterReturningAdviceInterceptor implements MethodInterceptor, AfterAdvice { 4 | 5 | private final AfterReturningAdvice advice; 6 | 7 | public AfterReturningAdviceInterceptor(AfterReturningAdvice advice) { 8 | this.advice = advice; 9 | } 10 | 11 | @Override 12 | public Object invoke(MethodInvocation mi) throws Throwable { 13 | Object retVal = mi.proceed(); 14 | this.advice.afterReturning(retVal, mi.getMethod(), mi.getArguments(), mi.getThis()); 15 | return retVal; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/com/test/service/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.test.service; 2 | 3 | import com.minis.beans.factory.annotation.Autowired; 4 | 5 | public class BaseService { 6 | @Autowired 7 | private BaseBaseService bbs; 8 | 9 | public BaseBaseService getBbs() { 10 | return bbs; 11 | } 12 | public void setBbs(BaseBaseService bbs) { 13 | this.bbs = bbs; 14 | } 15 | public BaseService() { 16 | } 17 | public void sayHello() { 18 | System.out.print("Base Service says hello"); 19 | bbs.sayHello(); 20 | } 21 | public String getHello() { 22 | return "Base Service get Hello."; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/com/test/service/MyInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.test.service; 2 | 3 | import com.minis.aop.MethodInterceptor; 4 | import com.minis.aop.MethodInvocation; 5 | 6 | public class MyInterceptor implements MethodInterceptor{ 7 | 8 | @Override 9 | public Object invoke(MethodInvocation invocation) throws Throwable { 10 | System.out.println("method "+invocation.getMethod()+" is called on "+ 11 | invocation.getThis()+" with args "+invocation.getArguments()); 12 | Object ret=invocation.proceed(); 13 | System.out.println("method "+invocation.getMethod()+" returns "+ret); 14 | 15 | return ret; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/com/test/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.test.entity; 2 | 3 | import java.util.Date; 4 | 5 | public class User { 6 | int id = 1; 7 | 8 | public int getId() { 9 | return id; 10 | } 11 | public void setId(int id) { 12 | this.id = id; 13 | } 14 | String name = ""; 15 | 16 | public String getName() { 17 | return this.name; 18 | } 19 | public void setName(String name) { 20 | this.name = name; 21 | } 22 | 23 | Date birthday = new Date(); 24 | 25 | public Date getBirthday() { 26 | return birthday; 27 | } 28 | public void setBirthday(Date birthday) { 29 | this.birthday = birthday; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/config/AutowireCapableBeanFactory.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory.config; 2 | 3 | import com.minis.beans.BeansException; 4 | import com.minis.beans.factory.BeanFactory; 5 | 6 | public interface AutowireCapableBeanFactory extends BeanFactory{ 7 | int AUTOWIRE_NO = 0; 8 | int AUTOWIRE_BY_NAME = 1; 9 | int AUTOWIRE_BY_TYPE = 2; 10 | 11 | Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName) 12 | throws BeansException; 13 | 14 | Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName) 15 | throws BeansException; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/com/minis/context/SimpleApplicationEventPublisher.java: -------------------------------------------------------------------------------- 1 | package com.minis.context; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class SimpleApplicationEventPublisher implements ApplicationEventPublisher{ 7 | List listeners = new ArrayList<>(); 8 | 9 | @Override 10 | public void publishEvent(ApplicationEvent event) { 11 | for (ApplicationListener listener : listeners) { 12 | listener.onApplicationEvent(event); 13 | } 14 | } 15 | 16 | @Override 17 | public void addApplicationListener(ApplicationListener listener) { 18 | this.listeners.add(listener); 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/com/minis/web/servlet/View.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.servlet; 2 | 3 | import java.util.Map; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpServletResponse; 7 | 8 | public interface View { 9 | void render(Map model, HttpServletRequest request, HttpServletResponse response) 10 | throws Exception; 11 | 12 | default String getContentType() { 13 | return null; 14 | } 15 | void setContentType(String contentType); 16 | 17 | void setUrl(String url); 18 | String getUrl(); 19 | 20 | void setRequestContextAttribute(String requestContextAttribute); 21 | String getRequestContextAttribute(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/config/ConfigurableBeanFactory.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory.config; 2 | 3 | import com.minis.beans.factory.BeanFactory; 4 | 5 | public interface ConfigurableBeanFactory extends BeanFactory,SingletonBeanRegistry { 6 | 7 | String SCOPE_SINGLETON = "singleton"; 8 | String SCOPE_PROTOTYPE = "prototype"; 9 | 10 | void addBeanPostProcessor(BeanPostProcessor beanPostProcessor); 11 | 12 | int getBeanPostProcessorCount(); 13 | 14 | void registerDependentBean(String beanName, String dependentBeanName); 15 | 16 | String[] getDependentBeans(String beanName); 17 | 18 | String[] getDependenciesForBean(String beanName); 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /src/com/minis/aop/framework/adapter/MethodBeforeAdviceInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop.framework.adapter; 2 | 3 | import com.minis.aop.MethodBeforeAdvice; 4 | import com.minis.aop.MethodInterceptor; 5 | import com.minis.aop.MethodInvocation; 6 | 7 | public class MethodBeforeAdviceInterceptor implements MethodInterceptor { 8 | private final MethodBeforeAdvice advice; 9 | 10 | public MethodBeforeAdviceInterceptor(MethodBeforeAdvice advice) { 11 | this.advice = advice; 12 | } 13 | 14 | @Override 15 | public Object invoke(MethodInvocation mi) throws Throwable { 16 | this.advice.before(mi.getMethod(), mi.getArguments(), mi.getThis()); 17 | return mi.proceed(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/com/minis/beans/AbstractPropertyAccessor.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans; 2 | 3 | import java.lang.reflect.Field; 4 | import java.lang.reflect.InvocationTargetException; 5 | import java.lang.reflect.Method; 6 | 7 | 8 | public abstract class AbstractPropertyAccessor extends PropertyEditorRegistrySupport{ 9 | 10 | PropertyValues pvs; 11 | 12 | public AbstractPropertyAccessor() { 13 | super(); 14 | 15 | } 16 | 17 | 18 | public void setPropertyValues(PropertyValues pvs) { 19 | this.pvs = pvs; 20 | for (PropertyValue pv : this.pvs.getPropertyValues()) { 21 | setPropertyValue(pv); 22 | } 23 | } 24 | 25 | public abstract void setPropertyValue(PropertyValue pv) ; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/com/minis/jdbc/core/RowMapperResultSetExtractor.java: -------------------------------------------------------------------------------- 1 | package com.minis.jdbc.core; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.SQLException; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class RowMapperResultSetExtractor implements ResultSetExtractor> { 9 | private final RowMapper rowMapper; 10 | 11 | public RowMapperResultSetExtractor(RowMapper rowMapper) { 12 | this.rowMapper = rowMapper; 13 | } 14 | 15 | @Override 16 | public List extractData(ResultSet rs) throws SQLException { 17 | List results = new ArrayList<>(); 18 | int rowNum = 0; 19 | while (rs.next()) { 20 | results.add(this.rowMapper.mapRow(rs, rowNum++)); 21 | } 22 | return results; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/com/minis/scheduling/annotation/AsyncAnnotationAdvisor.java: -------------------------------------------------------------------------------- 1 | package com.minis.scheduling.annotation; 2 | 3 | import com.minis.aop.Advice; 4 | import com.minis.aop.Advisor; 5 | import com.minis.aop.AsyncExecutionInterceptor; 6 | import com.minis.aop.MethodInterceptor; 7 | 8 | public class AsyncAnnotationAdvisor implements Advisor{ 9 | MethodInterceptor methodInterceptor; 10 | 11 | @Override 12 | public MethodInterceptor getMethodInterceptor() { 13 | return this.methodInterceptor; 14 | } 15 | 16 | @Override 17 | public void setMethodInterceptor(MethodInterceptor methodInterceptor) { 18 | this.methodInterceptor= methodInterceptor; 19 | } 20 | 21 | @Override 22 | public Advice getAdvice() { 23 | // TODO Auto-generated method stub 24 | return null; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/com/minis/web/context/support/XmlWebApplicationContext.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.context.support; 2 | 3 | import javax.servlet.ServletContext; 4 | import com.minis.context.ClassPathXmlApplicationContext; 5 | import com.minis.web.context.WebApplicationContext; 6 | 7 | public class XmlWebApplicationContext 8 | extends ClassPathXmlApplicationContext implements WebApplicationContext{ 9 | private ServletContext servletContext; 10 | 11 | public XmlWebApplicationContext(String fileName) { 12 | super(fileName); 13 | } 14 | 15 | @Override 16 | public ServletContext getServletContext() { 17 | return this.servletContext; 18 | } 19 | 20 | @Override 21 | public void setServletContext(ServletContext servletContext) { 22 | this.servletContext = servletContext; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.idea/artifacts/Minis_Web_exploded.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | $PROJECT_DIR$/out/artifacts/Minis_Web_exploded 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/com/minis/aop/framework/adapter/AfterReturningAdviceInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop.framework.adapter; 2 | 3 | import com.minis.aop.AfterAdvice; 4 | import com.minis.aop.AfterReturningAdvice; 5 | import com.minis.aop.MethodInterceptor; 6 | import com.minis.aop.MethodInvocation; 7 | 8 | public class AfterReturningAdviceInterceptor implements MethodInterceptor, AfterAdvice { 9 | 10 | private final AfterReturningAdvice advice; 11 | 12 | public AfterReturningAdviceInterceptor(AfterReturningAdvice advice) { 13 | this.advice = advice; 14 | } 15 | 16 | @Override 17 | public Object invoke(MethodInvocation mi) throws Throwable { 18 | Object retVal = mi.proceed(); 19 | this.advice.afterReturning(retVal, mi.getMethod(), mi.getArguments(), mi.getThis()); 20 | return retVal; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/com/minis/core/env/PropertyResolver.java: -------------------------------------------------------------------------------- 1 | package com.minis.core.env; 2 | 3 | public interface PropertyResolver { 4 | boolean containsProperty(String key); 5 | 6 | String getProperty(String key); 7 | 8 | String getProperty(String key, String defaultValue); 9 | 10 | T getProperty(String key, Class targetType); 11 | 12 | T getProperty(String key, Class targetType, T defaultValue); 13 | 14 | Class getPropertyAsClass(String key, Class targetType); 15 | 16 | String getRequiredProperty(String key) throws IllegalStateException; 17 | 18 | T getRequiredProperty(String key, Class targetType) throws IllegalStateException; 19 | 20 | String resolvePlaceholders(String text); 21 | 22 | String resolveRequiredPlaceholders(String text) throws IllegalArgumentException; 23 | 24 | } 25 | 26 | -------------------------------------------------------------------------------- /src/com/test/service/UserJdbcImpl.java: -------------------------------------------------------------------------------- 1 | package com.test.service; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.SQLException; 5 | 6 | import com.minis.jdbc.core.JdbcTemplate; 7 | import com.minis.jdbc.core.OldJdbcTemplate; 8 | import com.test.entity.User; 9 | 10 | public class UserJdbcImpl extends OldJdbcTemplate { 11 | 12 | @Override 13 | protected Object doInStatement(ResultSet rs) { 14 | User rtnUser = null; 15 | 16 | try { 17 | if (rs.next()) { 18 | rtnUser = new User(); 19 | rtnUser.setId(rs.getInt("id")); 20 | rtnUser.setName(rs.getString("name")); 21 | rtnUser.setBirthday(new java.util.Date(rs.getDate("birthday").getTime())); 22 | } else { 23 | } 24 | } catch (SQLException e) { 25 | e.printStackTrace(); 26 | } 27 | 28 | return rtnUser; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Minis 2 | 3 | A mini Spring platform for learning. We plan to implement IoC,MVC,JDBCTemplate,AOP and ThreadPool from scratch. 4 | 5 | IoC is the core of Minis. We will use a bean factory to manage all required beans. 6 | 7 | mvc,integrate with IoC. mapping request uri to controller method, 8 | use handleadapter to invocate method and process response, 9 | and use view resolver to render return message (JSP). 10 | 11 | Use jdbctemplate to access database, and connectionpool supported. 12 | PooledConnection supported. 13 | 14 | FactoryBean supported. Use JDKDynamicsProxy technology. 15 | 16 | methodinterceptor,methodbeforeadvice, afterreturningadvice supported. 17 | 18 | implements Pointcut and AutoProxyCreator. 19 | 20 | Using annotation + aop implements @Async 21 | 22 | REFTful supported 23 | 24 | Implemented mBatis based on JDBC Template. 25 | 26 | -------------------------------------------------------------------------------- /src/com/minis/aop/NameMatchMethodPointcut.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | import java.lang.reflect.Method; 4 | import com.minis.util.PatternMatchUtils; 5 | 6 | public class NameMatchMethodPointcut implements MethodMatcher,Pointcut{ 7 | private String mappedName = ""; 8 | 9 | public void setMappedName(String mappedName) { 10 | this.mappedName = mappedName; 11 | } 12 | 13 | @Override 14 | public boolean matches(Method method, Class targetClass) { 15 | if (mappedName.equals(method.getName()) || isMatch(method.getName(), mappedName)) { 16 | return true; 17 | } 18 | return false; 19 | } 20 | 21 | protected boolean isMatch(String methodName, String mappedName) { 22 | return PatternMatchUtils.simpleMatch(mappedName, methodName); 23 | } 24 | 25 | @Override 26 | public MethodMatcher getMethodMatcher() { 27 | return this; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/com/test/LogBeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | package com.test; 2 | 3 | import com.minis.beans.BeansException; 4 | import com.minis.beans.factory.BeanFactory; 5 | import com.minis.beans.factory.config.BeanPostProcessor; 6 | 7 | public class LogBeanPostProcessor implements BeanPostProcessor { 8 | 9 | @Override 10 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 11 | System.out.println("postProcessBeforeInitialization : " + beanName); 12 | return bean; 13 | } 14 | 15 | @Override 16 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 17 | System.out.println("postProcessAfterInitialization : " + beanName); 18 | return bean; 19 | } 20 | 21 | @Override 22 | public void setBeanFactory(BeanFactory beanFactory) { 23 | // TODO Auto-generated method stub 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/com/minis/util/WebUtils.java: -------------------------------------------------------------------------------- 1 | package com.minis.util; 2 | 3 | import java.util.Enumeration; 4 | import java.util.Map; 5 | import java.util.TreeMap; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | 9 | public class WebUtils { 10 | public static Map getParametersStartingWith(HttpServletRequest request, String prefix) { 11 | Enumeration paramNames = request.getParameterNames(); 12 | Map params = new TreeMap<>(); 13 | if (prefix == null) { 14 | prefix = ""; 15 | } 16 | while (paramNames != null && paramNames.hasMoreElements()) { 17 | String paramName = paramNames.nextElement(); 18 | if (prefix.isEmpty() || paramName.startsWith(prefix)) { 19 | String unprefixed = paramName.substring(prefix.length()); 20 | String value = request.getParameter(paramName); 21 | 22 | params.put(unprefixed, value); 23 | } 24 | } 25 | return params; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/config/ConstructorArgumentValues.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory.config; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | 7 | public class ConstructorArgumentValues { 8 | private final List argumentValueList = new ArrayList(); 9 | 10 | public ConstructorArgumentValues() { 11 | } 12 | 13 | public void addArgumentValue(ConstructorArgumentValue argumentValue) { 14 | this.argumentValueList.add(argumentValue); 15 | } 16 | 17 | public ConstructorArgumentValue getIndexedArgumentValue(int index) { 18 | ConstructorArgumentValue argumentValue = this.argumentValueList.get(index); 19 | return argumentValue; 20 | } 21 | 22 | public int getArgumentCount() { 23 | return (this.argumentValueList.size()); 24 | } 25 | 26 | public boolean isEmpty() { 27 | return (this.argumentValueList.isEmpty()); 28 | } 29 | } -------------------------------------------------------------------------------- /src/com/minis/beans/PropertyValue.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans; 2 | 3 | public class PropertyValue{ 4 | private final String type; 5 | private final String name; 6 | private final Object value; 7 | private final boolean isRef; 8 | 9 | public PropertyValue(String type, String name, Object value, boolean isRef) { 10 | this.type = type; 11 | this.name = name; 12 | this.value = value; 13 | this.isRef = isRef; 14 | } 15 | 16 | public PropertyValue(String type, String name, Object value) { 17 | this(type, name, value, false); 18 | } 19 | 20 | public PropertyValue(String name, Object value) { 21 | this("", name, value, false); 22 | } 23 | 24 | public String getType() { 25 | return this.type; 26 | } 27 | 28 | public String getName() { 29 | return this.name; 30 | } 31 | 32 | public Object getValue() { 33 | return this.value; 34 | } 35 | 36 | public boolean getIsRef() { 37 | return isRef; 38 | } 39 | 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src/com/minis/aop/support/NameMatchMethodPointcut.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop.support; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import com.minis.aop.MethodMatcher; 6 | import com.minis.aop.Pointcut; 7 | import com.minis.util.PatternMatchUtils; 8 | 9 | public class NameMatchMethodPointcut implements MethodMatcher,Pointcut{ 10 | private String mappedName = ""; 11 | 12 | public void setMappedName(String mappedName) { 13 | this.mappedName = mappedName; 14 | } 15 | 16 | @Override 17 | public boolean matches(Method method, Class targetClass) { 18 | if (mappedName.equals(method.getName()) || isMatch(method.getName(), mappedName)) { 19 | return true; 20 | } 21 | return false; 22 | } 23 | 24 | protected boolean isMatch(String methodName, String mappedName) { 25 | return PatternMatchUtils.simpleMatch(mappedName, methodName); 26 | } 27 | 28 | @Override 29 | public MethodMatcher getMethodMatcher() { 30 | return this; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/config/ConstructorArgumentValue.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory.config; 2 | 3 | public class ConstructorArgumentValue { 4 | private Object value; 5 | private String type; 6 | private String name; 7 | 8 | public ConstructorArgumentValue(String type, Object value) { 9 | this.value = value; 10 | this.type = type; 11 | } 12 | public ConstructorArgumentValue(String type, String name, Object value) { 13 | this.value = value; 14 | this.type = type; 15 | this.name = name; 16 | } 17 | 18 | public void setValue(Object value) { 19 | this.value = value; 20 | } 21 | 22 | public Object getValue() { 23 | return this.value; 24 | } 25 | 26 | public void setType(String type) { 27 | this.type = type; 28 | } 29 | 30 | public String getType() { 31 | return this.type; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public String getName() { 39 | return this.name; 40 | } 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /src/com/test/service/AServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.test.service; 2 | 3 | public class AServiceImpl implements AService { 4 | private String name; 5 | private int level; 6 | private String property1; 7 | private String property2; 8 | private BaseService ref1; 9 | 10 | public BaseService getRef1() { 11 | return ref1; 12 | } 13 | 14 | public void setRef1(BaseService bs) { 15 | this.ref1 = bs; 16 | } 17 | 18 | public String getProperty1() { 19 | return property1; 20 | } 21 | 22 | public void setProperty1(String property1) { 23 | this.property1 = property1; 24 | } 25 | 26 | public String getProperty2() { 27 | return property2; 28 | } 29 | 30 | public void setProperty2(String property2) { 31 | this.property2 = property2; 32 | } 33 | 34 | public AServiceImpl() { 35 | } 36 | 37 | public AServiceImpl(String name, int level) { 38 | this.name = name; 39 | this.level = level; 40 | } 41 | 42 | public void sayHello() { 43 | System.out.print(this.property1 + "," + this.property2); 44 | ref1.sayHello(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/com/minis/context/ApplicationContext.java: -------------------------------------------------------------------------------- 1 | package com.minis.context; 2 | 3 | import com.minis.beans.BeansException; 4 | import com.minis.beans.factory.ListableBeanFactory; 5 | import com.minis.beans.factory.config.BeanFactoryPostProcessor; 6 | import com.minis.beans.factory.config.ConfigurableBeanFactory; 7 | import com.minis.beans.factory.config.ConfigurableListableBeanFactory; 8 | import com.minis.core.env.Environment; 9 | import com.minis.core.env.EnvironmentCapable; 10 | 11 | public interface ApplicationContext 12 | extends EnvironmentCapable, ListableBeanFactory, ConfigurableBeanFactory, ApplicationEventPublisher{ 13 | String getApplicationName(); 14 | long getStartupDate(); 15 | ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException; 16 | void setEnvironment(Environment environment); 17 | Environment getEnvironment(); 18 | void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor); 19 | void refresh() throws BeansException, IllegalStateException; 20 | void close(); 21 | boolean isActive(); 22 | 23 | } 24 | -------------------------------------------------------------------------------- /WebContent/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | contextConfigLocation 5 | applicationContext.xml 6 | 7 | 8 | 9 | com.minis.web.context.ContextLoaderListener 10 | 11 | 12 | 13 | minisMVC 14 | com.minis.web.servlet.DispatcherServlet 15 | 16 | contextConfigLocation 17 | /WEB-INF/minisMVC-servlet.xml 18 | 19 | 1 20 | 21 | 22 | minisMVC 23 | / 24 | 25 | -------------------------------------------------------------------------------- /src/com/minis/jdbc/core/OldJdbcTemplate.java: -------------------------------------------------------------------------------- 1 | package com.minis.jdbc.core; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.PreparedStatement; 6 | import java.sql.ResultSet; 7 | 8 | 9 | public abstract class OldJdbcTemplate { 10 | public OldJdbcTemplate() { 11 | } 12 | 13 | public Object query(String sql) { 14 | Connection con = null; 15 | PreparedStatement stmt = null; 16 | ResultSet rs = null; 17 | Object rtnObj = null; 18 | 19 | try { 20 | Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 21 | con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databasename=DEMO;user=sa;password=Sql2016;"); 22 | 23 | stmt = con.prepareStatement(sql); 24 | rs = stmt.executeQuery(); 25 | 26 | rtnObj = doInStatement(rs); 27 | } 28 | catch (Exception e) { 29 | e.printStackTrace(); 30 | } 31 | finally { 32 | try { 33 | rs.close(); 34 | stmt.close(); 35 | con.close(); 36 | } catch (Exception e) { 37 | 38 | } 39 | } 40 | 41 | return rtnObj; 42 | 43 | } 44 | protected abstract Object doInStatement(ResultSet rs); 45 | } 46 | -------------------------------------------------------------------------------- /src/com/minis/web/context/support/XmlScanComponentHelper.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.context.support; 2 | 3 | import java.net.MalformedURLException; 4 | import java.net.URL; 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | import java.util.Iterator; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | import org.dom4j.Document; 12 | import org.dom4j.DocumentException; 13 | import org.dom4j.Element; 14 | import org.dom4j.Node; 15 | import org.dom4j.io.SAXReader; 16 | 17 | public class XmlScanComponentHelper { 18 | public static List getNodeValue(URL xmlPath) { 19 | List packages = new ArrayList<>(); 20 | SAXReader saxReader=new SAXReader(); 21 | Document document = null; 22 | try { 23 | document = saxReader.read(xmlPath); 24 | } catch (DocumentException e) { 25 | e.printStackTrace(); 26 | } 27 | Element root = document.getRootElement(); 28 | List elements = root.elements("component-scan"); 29 | for (Object element : elements) { 30 | packages.add(((Element)element).attributeValue("base-package")); 31 | } 32 | 33 | return packages; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/com/minis/jdbc/core/ArgumentPreparedStatementSetter.java: -------------------------------------------------------------------------------- 1 | package com.minis.jdbc.core; 2 | 3 | import java.sql.PreparedStatement; 4 | import java.sql.SQLException; 5 | 6 | public class ArgumentPreparedStatementSetter { 7 | private final Object[] args; 8 | 9 | public ArgumentPreparedStatementSetter(Object[] args) { 10 | this.args = args; 11 | } 12 | 13 | 14 | public void setValues(PreparedStatement pstmt) throws SQLException { 15 | if (this.args != null) { 16 | for (int i = 0; i < this.args.length; i++) { 17 | Object arg = this.args[i]; 18 | doSetValue(pstmt, i + 1, arg); 19 | } 20 | } 21 | } 22 | 23 | protected void doSetValue(PreparedStatement pstmt, int parameterPosition, Object argValue) throws SQLException { 24 | 25 | if (argValue instanceof String) { 26 | pstmt.setString(parameterPosition, (String)argValue); 27 | } 28 | else if (argValue instanceof Integer) { 29 | pstmt.setInt(parameterPosition, (int)argValue); 30 | } 31 | else if (argValue instanceof java.util.Date) { 32 | pstmt.setDate(parameterPosition, new java.sql.Date(((java.util.Date)argValue).getTime())); 33 | 34 | } 35 | 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/com/minis/beans/StringEditor.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans; 2 | 3 | import java.text.NumberFormat; 4 | 5 | import com.minis.util.NumberUtils; 6 | import com.minis.util.StringUtils; 7 | 8 | public class StringEditor implements PropertyEditor { 9 | private Class strClass; 10 | private String strFormat; 11 | private boolean allowEmpty; 12 | private Object value; 13 | 14 | public StringEditor(Class strClass, 15 | boolean allowEmpty) throws IllegalArgumentException { 16 | this(strClass, "", allowEmpty); 17 | } 18 | 19 | public StringEditor(Class strClass, 20 | String strFormat, boolean allowEmpty) throws IllegalArgumentException { 21 | this.strClass = strClass; 22 | this.strFormat = strFormat; 23 | this.allowEmpty = allowEmpty; 24 | } 25 | 26 | @Override 27 | public void setAsText(String text) { 28 | setValue(text); 29 | } 30 | 31 | @Override 32 | public void setValue(Object value) { 33 | this.value = value; 34 | } 35 | 36 | @Override 37 | public String getAsText() { 38 | return value.toString(); 39 | } 40 | 41 | @Override 42 | public Object getValue() { 43 | return this.value; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/com/minis/core/ClassPathXmlResource.java: -------------------------------------------------------------------------------- 1 | package com.minis.core; 2 | 3 | import java.net.URL; 4 | import java.util.Iterator; 5 | import java.util.List; 6 | 7 | import org.dom4j.Document; 8 | import org.dom4j.DocumentException; 9 | import org.dom4j.Element; 10 | import org.dom4j.io.SAXReader; 11 | 12 | import com.minis.beans.factory.config.BeanDefinition; 13 | 14 | public class ClassPathXmlResource implements Resource { 15 | Document document; 16 | Element rootElement; 17 | Iterator elementIterator; 18 | 19 | public ClassPathXmlResource(String fileName) { 20 | SAXReader saxReader=new SAXReader(); 21 | URL xmlPath=this.getClass().getClassLoader().getResource(fileName); 22 | try { 23 | this.document = saxReader.read(xmlPath); 24 | this.rootElement=document.getRootElement(); 25 | this.elementIterator=this.rootElement.elementIterator(); 26 | } catch (DocumentException e) { 27 | e.printStackTrace(); 28 | } 29 | } 30 | 31 | @Override 32 | public boolean hasNext() { 33 | return this.elementIterator.hasNext(); 34 | } 35 | 36 | @Override 37 | public Object next() { 38 | return this.elementIterator.next(); 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/com/minis/batis/MapperNode.java: -------------------------------------------------------------------------------- 1 | package com.minis.batis; 2 | 3 | public class MapperNode { 4 | String namespace; 5 | String id; 6 | String parameterType; 7 | String resultType; 8 | String sql; 9 | String parameter; 10 | 11 | public String getNamespace() { 12 | return namespace; 13 | } 14 | public void setNamespace(String namespace) { 15 | this.namespace = namespace; 16 | } 17 | public String getId() { 18 | return id; 19 | } 20 | public void setId(String id) { 21 | this.id = id; 22 | } 23 | public String getParameterType() { 24 | return parameterType; 25 | } 26 | public void setParameterType(String parameterType) { 27 | this.parameterType = parameterType; 28 | } 29 | public String getResultType() { 30 | return resultType; 31 | } 32 | public void setResultType(String resultType) { 33 | this.resultType = resultType; 34 | } 35 | public String getSql() { 36 | return sql; 37 | } 38 | public void setSql(String sql) { 39 | this.sql = sql; 40 | } 41 | public String getParameter() { 42 | return parameter; 43 | } 44 | public void setParameter(String parameter) { 45 | this.parameter = parameter; 46 | } 47 | 48 | public String toString(){ 49 | return this.namespace+"."+this.id+" : " +this.sql; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/com/minis/aop/JdkDynamicAopProxy.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | import java.lang.reflect.InvocationHandler; 4 | import java.lang.reflect.Method; 5 | import java.lang.reflect.Proxy; 6 | 7 | public class JdkDynamicAopProxy implements AopProxy, InvocationHandler { 8 | Object target; 9 | PointcutAdvisor advisor; 10 | 11 | public JdkDynamicAopProxy(Object target, PointcutAdvisor advisor) { 12 | this.target = target; 13 | this.advisor = advisor; 14 | } 15 | 16 | @Override 17 | public Object getProxy() { 18 | Object obj = Proxy.newProxyInstance(JdkDynamicAopProxy.class.getClassLoader(), target.getClass().getInterfaces(), this); 19 | return obj; 20 | } 21 | 22 | @Override 23 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 24 | Class targetClass = (target != null ? target.getClass() : null); 25 | 26 | if (this.advisor.getPointcut().getMethodMatcher().matches(method, targetClass)) { 27 | //if (method.getName().equals("doAction")) { 28 | MethodInterceptor interceptor = this.advisor.getMethodInterceptor(); 29 | MethodInvocation invocation = 30 | new ReflectiveMethodInvocation(proxy, target, method, args, targetClass); 31 | 32 | return interceptor.invoke(invocation); 33 | } 34 | return null; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/com/minis/http/converter/DefaultHttpMessageConverter.java: -------------------------------------------------------------------------------- 1 | package com.minis.http.converter; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.http.HttpServletResponse; 7 | 8 | import com.minis.util.ObjectMapper; 9 | 10 | public class DefaultHttpMessageConverter implements HttpMessageConverter { 11 | String defaultContentType = "text/json;charset=UTF-8"; 12 | String defaultCharacterEncoding = "UTF-8"; 13 | ObjectMapper objectMapper; 14 | 15 | public ObjectMapper getObjectMapper() { 16 | return objectMapper; 17 | } 18 | 19 | public void setObjectMapper(ObjectMapper objectMapper) { 20 | this.objectMapper = objectMapper; 21 | } 22 | 23 | public DefaultHttpMessageConverter() { 24 | } 25 | 26 | @Override 27 | public void write(Object obj, HttpServletResponse response) throws IOException { 28 | response.setContentType(defaultContentType); 29 | response.setCharacterEncoding(defaultCharacterEncoding); 30 | 31 | writeInternal(obj, response); 32 | 33 | response.flushBuffer(); 34 | } 35 | 36 | private void writeInternal(Object obj, HttpServletResponse response) throws IOException{ 37 | String sJsonStr = this.objectMapper.writeValuesAsString(obj); 38 | PrintWriter pw = response.getWriter(); 39 | pw.write(sJsonStr); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/com/test/service/OldUserService.java: -------------------------------------------------------------------------------- 1 | package com.test.service; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.PreparedStatement; 6 | import java.sql.ResultSet; 7 | 8 | import com.test.entity.User; 9 | 10 | public class OldUserService { 11 | public User getUserInfo(int userid) { 12 | Connection con = null; 13 | PreparedStatement stmt = null; 14 | ResultSet rs = null; 15 | User returnUser =null; 16 | 17 | try { 18 | Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 19 | con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databasename=DEMO;user=sa;password=Sql2016;"); 20 | 21 | stmt = con.prepareStatement("select name,birthday from users where id=?"); 22 | stmt.setInt(1, userid); 23 | rs = stmt.executeQuery(); 24 | 25 | if (rs.next()) { 26 | returnUser = new User(); 27 | returnUser.setId(userid); 28 | returnUser.setName(rs.getString("name")); 29 | returnUser.setBirthday(new java.util.Date(rs.getDate("birthday").getTime())); 30 | } else { 31 | } 32 | } 33 | catch (Exception e) { 34 | e.printStackTrace(); 35 | } 36 | finally { 37 | try { 38 | rs.close(); 39 | stmt.close(); 40 | con.close(); 41 | } catch (Exception e) { 42 | 43 | } 44 | } 45 | 46 | return returnUser; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/com/minis/web/context/ContextLoaderListener.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.context; 2 | 3 | import javax.servlet.ServletContext; 4 | import javax.servlet.ServletContextEvent; 5 | import javax.servlet.ServletContextListener; 6 | 7 | import com.minis.web.context.support.XmlWebApplicationContext; 8 | 9 | public class ContextLoaderListener implements ServletContextListener { 10 | public static final String CONFIG_LOCATION_PARAM = "contextConfigLocation"; 11 | private WebApplicationContext context; 12 | 13 | public ContextLoaderListener() { 14 | } 15 | 16 | public ContextLoaderListener(WebApplicationContext context) { 17 | this.context = context; 18 | } 19 | 20 | @Override 21 | public void contextDestroyed(ServletContextEvent event) { 22 | } 23 | 24 | @Override 25 | public void contextInitialized(ServletContextEvent event) { 26 | initWebApplicationContext(event.getServletContext()); 27 | } 28 | 29 | private void initWebApplicationContext(ServletContext servletContext) { 30 | String sContextLocation = servletContext.getInitParameter(CONFIG_LOCATION_PARAM); 31 | 32 | WebApplicationContext wac = new XmlWebApplicationContext(sContextLocation); 33 | wac.setServletContext(servletContext); 34 | this.context = wac; 35 | servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context); 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/com/minis/scheduling/annotation/AsyncResult.java: -------------------------------------------------------------------------------- 1 | package com.minis.scheduling.annotation; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | import com.minis.util.concurrent.FailureCallback; 6 | import com.minis.util.concurrent.ListenableFuture; 7 | import com.minis.util.concurrent.SuccessCallback; 8 | 9 | public class AsyncResult implements ListenableFuture { 10 | private final V value; 11 | private final Throwable executionException; 12 | 13 | public AsyncResult(V value) { 14 | this(value, null); 15 | } 16 | private AsyncResult(V value, Throwable ex) { 17 | this.value = value; 18 | this.executionException = ex; 19 | } 20 | 21 | public boolean cancel(boolean mayInterruptIfRunning) { 22 | return false; 23 | } 24 | 25 | public boolean isCancelled() { 26 | return false; 27 | } 28 | 29 | public boolean isDone() { 30 | return true; 31 | } 32 | 33 | public V get() { 34 | return this.value; 35 | } 36 | 37 | public V get(long timeout, TimeUnit unit) { 38 | return get(); 39 | } 40 | 41 | @Override 42 | public void addCallback(SuccessCallback successCallback, FailureCallback failureCallback) { 43 | try { 44 | if (this.executionException != null) { 45 | failureCallback.onFailure(this.executionException); 46 | } 47 | else { 48 | successCallback.onSuccess(this.value); 49 | } 50 | } 51 | catch (Throwable ex) { 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/com/minis/util/concurrent/ListenableFutureTask.java: -------------------------------------------------------------------------------- 1 | package com.minis.util.concurrent; 2 | 3 | import java.util.concurrent.Callable; 4 | import java.util.concurrent.ExecutionException; 5 | import java.util.concurrent.FutureTask; 6 | 7 | public class ListenableFutureTask extends FutureTask implements ListenableFuture{ 8 | 9 | private final ListenableFutureCallbackRegistry callbacks = new ListenableFutureCallbackRegistry<>(); 10 | 11 | public ListenableFutureTask(Callable callable) { 12 | super(callable); 13 | } 14 | 15 | public ListenableFutureTask(Runnable runnable, T result) { 16 | super(runnable, result); 17 | } 18 | 19 | public void addCallback(SuccessCallback successCallback, FailureCallback failureCallback) { 20 | this.callbacks.addSuccessCallback(successCallback); 21 | this.callbacks.addFailureCallback(failureCallback); 22 | } 23 | 24 | @Override 25 | protected void done() { 26 | Throwable cause; 27 | try { 28 | T result = get(); 29 | this.callbacks.success(result); 30 | return; 31 | } 32 | catch (InterruptedException ex) { 33 | Thread.currentThread().interrupt(); 34 | return; 35 | } 36 | catch (ExecutionException ex) { 37 | cause = ex.getCause(); 38 | if (cause == null) { 39 | cause = ex; 40 | } 41 | } 42 | catch (Throwable ex) { 43 | cause = ex; 44 | } 45 | this.callbacks.failure(cause); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /.idea/Minis.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/com/minis/batis/DefaultSqlSession.java: -------------------------------------------------------------------------------- 1 | package com.minis.batis; 2 | 3 | import javax.sql.DataSource; 4 | 5 | import com.minis.jdbc.core.JdbcTemplate; 6 | import com.minis.jdbc.core.PreparedStatementCallback; 7 | 8 | public class DefaultSqlSession implements SqlSession{ 9 | // private DataSource dataSource; 10 | // 11 | // public void setDataSource(DataSource dataSource) { 12 | // this.dataSource = dataSource; 13 | // } 14 | // 15 | // public DataSource getDataSource() { 16 | // return this.dataSource; 17 | // } 18 | 19 | JdbcTemplate jdbcTemplate; 20 | public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { 21 | this.jdbcTemplate = jdbcTemplate; 22 | } 23 | public JdbcTemplate getJdbcTemplate() { 24 | return this.jdbcTemplate; 25 | } 26 | 27 | SqlSessionFactory sqlSessionFactory; 28 | public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) { 29 | this.sqlSessionFactory = sqlSessionFactory; 30 | } 31 | public SqlSessionFactory getSqlSessionFactory() { 32 | return this.sqlSessionFactory; 33 | } 34 | 35 | @Override 36 | public Object selectOne(String sqlid, Object[] args, PreparedStatementCallback pstmtcallback) { 37 | System.out.println(sqlid); 38 | String sql = this.sqlSessionFactory.getMapperNode(sqlid).getSql(); 39 | System.out.println(sql); 40 | 41 | return jdbcTemplate.query(sql, args, pstmtcallback); 42 | } 43 | 44 | private void buildParameter(){ 45 | } 46 | 47 | private Object resultSet2Obj() { 48 | return null; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/com/minis/aop/ReflectiveMethodInvocation.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | public class ReflectiveMethodInvocation implements MethodInvocation{ 6 | protected final Object proxy; 7 | protected final Object target; 8 | protected final Method method; 9 | protected Object[] arguments; 10 | private Class targetClass; 11 | //protected MethodInterceptor methodInterceptor; 12 | 13 | protected ReflectiveMethodInvocation( 14 | Object proxy, Object target, Method method, Object[] arguments, 15 | Class targetClass) { 16 | 17 | this.proxy = proxy; 18 | this.target = target; 19 | this.targetClass = targetClass; 20 | this.method = method; 21 | this.arguments = arguments; 22 | //this.methodInterceptor = methodInterceptor; 23 | } 24 | 25 | public final Object getProxy() { 26 | return this.proxy; 27 | } 28 | 29 | public final Object getThis() { 30 | return this.target; 31 | } 32 | 33 | public final Method getMethod() { 34 | return this.method; 35 | } 36 | 37 | public final Object[] getArguments() { 38 | return this.arguments; 39 | } 40 | 41 | public void setArguments(Object... arguments) { 42 | this.arguments = arguments; 43 | } 44 | 45 | public Class getTargetClass() { 46 | return targetClass; 47 | } 48 | 49 | public void setTargetClass(Class targetClass) { 50 | this.targetClass = targetClass; 51 | } 52 | 53 | public Object proceed() throws Throwable { 54 | return this.method.invoke(this.target, this.arguments); 55 | } 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/support/FactoryBeanRegistrySupport.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory.support; 2 | 3 | import com.minis.beans.BeansException; 4 | import com.minis.beans.factory.FactoryBean; 5 | 6 | public abstract class FactoryBeanRegistrySupport extends DefaultSingletonBeanRegistry { 7 | 8 | protected Class getTypeForFactoryBean(final FactoryBean factoryBean) { 9 | return factoryBean.getObjectType(); 10 | } 11 | 12 | protected Object getObjectFromFactoryBean(FactoryBean factory, String beanName) { 13 | Object object = doGetObjectFromFactoryBean(factory, beanName); 14 | try { 15 | object = postProcessObjectFromFactoryBean(object, beanName); 16 | } catch (BeansException e) { 17 | e.printStackTrace(); 18 | } 19 | return object; 20 | } 21 | 22 | private Object doGetObjectFromFactoryBean(final FactoryBean factory, final String beanName) { 23 | 24 | Object object = null; 25 | try { 26 | object = factory.getObject(); 27 | } catch (Exception e) { 28 | e.printStackTrace(); 29 | } 30 | 31 | return object; 32 | } 33 | 34 | protected Object postProcessObjectFromFactoryBean(Object object, String beanName) throws BeansException { 35 | return object; 36 | } 37 | 38 | protected FactoryBean getFactoryBean(String beanName, Object beanInstance) throws BeansException { 39 | if (!(beanInstance instanceof FactoryBean)) { 40 | throw new BeansException( 41 | "Bean instance of type [" + beanInstance.getClass() + "] is not a FactoryBean"); 42 | } 43 | return (FactoryBean) beanInstance; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/com/minis/aop/framework/ReflectiveMethodInvocation.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop.framework; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import com.minis.aop.MethodInvocation; 6 | 7 | public class ReflectiveMethodInvocation implements MethodInvocation{ 8 | protected final Object proxy; 9 | protected final Object target; 10 | protected final Method method; 11 | protected Object[] arguments; 12 | private Class targetClass; 13 | //protected MethodInterceptor methodInterceptor; 14 | 15 | protected ReflectiveMethodInvocation( 16 | Object proxy, Object target, Method method, Object[] arguments, 17 | Class targetClass) { 18 | 19 | this.proxy = proxy; 20 | this.target = target; 21 | this.targetClass = targetClass; 22 | this.method = method; 23 | this.arguments = arguments; 24 | //this.methodInterceptor = methodInterceptor; 25 | } 26 | 27 | public final Object getProxy() { 28 | return this.proxy; 29 | } 30 | 31 | public final Object getThis() { 32 | return this.target; 33 | } 34 | 35 | public final Method getMethod() { 36 | return this.method; 37 | } 38 | 39 | public final Object[] getArguments() { 40 | return this.arguments; 41 | } 42 | 43 | public void setArguments(Object... arguments) { 44 | this.arguments = arguments; 45 | } 46 | 47 | public Class getTargetClass() { 48 | return targetClass; 49 | } 50 | 51 | public void setTargetClass(Class targetClass) { 52 | this.targetClass = targetClass; 53 | } 54 | 55 | public Object proceed() throws Throwable { 56 | return this.method.invoke(this.target, this.arguments); 57 | } 58 | 59 | } 60 | 61 | -------------------------------------------------------------------------------- /src/com/minis/aop/NameMatchMethodPointcutAdvisor.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | public class NameMatchMethodPointcutAdvisor implements PointcutAdvisor{ 4 | private Advice advice = null; 5 | private MethodInterceptor methodInterceptor; 6 | private String mappedName; 7 | private final NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut(); 8 | 9 | public NameMatchMethodPointcutAdvisor() { 10 | } 11 | 12 | public NameMatchMethodPointcutAdvisor(Advice advice) { 13 | this.advice = advice; 14 | } 15 | 16 | public void setMethodInterceptor(MethodInterceptor methodInterceptor) { 17 | this.methodInterceptor = methodInterceptor; 18 | } 19 | 20 | public MethodInterceptor getMethodInterceptor() { 21 | return this.methodInterceptor; 22 | } 23 | 24 | 25 | public void setAdvice(Advice advice) { 26 | this.advice = advice; 27 | 28 | MethodInterceptor mi = null; 29 | 30 | if (advice instanceof BeforeAdvice) { 31 | mi = new MethodBeforeAdviceInterceptor((MethodBeforeAdvice)advice); 32 | } 33 | else if (advice instanceof AfterAdvice){ 34 | mi = new AfterReturningAdviceInterceptor((AfterReturningAdvice)advice); 35 | } 36 | else if (advice instanceof MethodInterceptor) { 37 | mi = (MethodInterceptor)advice; 38 | } 39 | 40 | setMethodInterceptor(mi); 41 | } 42 | 43 | @Override 44 | public Advice getAdvice() { 45 | return this.advice; 46 | } 47 | 48 | @Override 49 | public Pointcut getPointcut() { 50 | return pointcut; 51 | } 52 | 53 | public void setMappedName(String mappedName) { 54 | this.mappedName = mappedName; 55 | this.pointcut.setMappedName(this.mappedName); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/com/minis/web/servlet/view/JstlView.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.servlet.view; 2 | 3 | import java.util.Map; 4 | import java.util.Map.Entry; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | 9 | import com.minis.web.servlet.View; 10 | 11 | public class JstlView implements View{ 12 | public static final String DEFAULT_CONTENT_TYPE = "text/html;charset=ISO-8859-1"; 13 | private String contentType = DEFAULT_CONTENT_TYPE; 14 | private String requestContextAttribute; 15 | private String beanName; 16 | private String url; 17 | 18 | public void setContentType(String contentType) { 19 | this.contentType = contentType; 20 | } 21 | public String getContentType() { 22 | return this.contentType; 23 | } 24 | public void setRequestContextAttribute(String requestContextAttribute) { 25 | this.requestContextAttribute = requestContextAttribute; 26 | } 27 | public String getRequestContextAttribute() { 28 | return this.requestContextAttribute; 29 | } 30 | public void setBeanName(String beanName) { 31 | this.beanName = beanName; 32 | } 33 | 34 | public String getBeanName() { 35 | return this.beanName; 36 | } 37 | @Override 38 | public void setUrl(String url) { 39 | this.url = url; 40 | } 41 | @Override 42 | public String getUrl() { 43 | return this.url; 44 | } 45 | @Override 46 | public void render(Map model, HttpServletRequest request, HttpServletResponse response) 47 | throws Exception { 48 | for (Entry e : model.entrySet()) { 49 | request.setAttribute(e.getKey(),e.getValue()); 50 | } 51 | 52 | request.getRequestDispatcher(getUrl()).forward(request, response); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/com/minis/web/method/HandlerMethod.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.method; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | public class HandlerMethod { 6 | private Object bean; 7 | private Class beanType; 8 | private Method method; 9 | private Class returnType; 10 | private String description; 11 | private String className; 12 | private String methodName; 13 | 14 | public HandlerMethod(Method method, Object obj, Class clz, String methodName) { 15 | this.method = method; 16 | this.bean = obj; 17 | this.beanType = clz; 18 | this.methodName = methodName; 19 | 20 | } 21 | 22 | public Method getMethod() { 23 | return method; 24 | } 25 | 26 | public void setMethod(Method method) { 27 | this.method = method; 28 | } 29 | 30 | public Object getBean() { 31 | return bean; 32 | } 33 | 34 | public void setBean(Object bean) { 35 | this.bean = bean; 36 | } 37 | 38 | public Class getReturnType() { 39 | return returnType; 40 | } 41 | 42 | public void setReturnType(Class returnType) { 43 | this.returnType = returnType; 44 | } 45 | 46 | public Class getBeanType() { 47 | return beanType; 48 | } 49 | 50 | public void setBeanType(Class beanType) { 51 | this.beanType = beanType; 52 | } 53 | 54 | public String getMethodName() { 55 | return methodName; 56 | } 57 | 58 | public void setMethodName(String methodName) { 59 | this.methodName = methodName; 60 | } 61 | 62 | public String getClassName() { 63 | return className; 64 | } 65 | 66 | public void setClassName(String className) { 67 | this.className = className; 68 | } 69 | 70 | public String getDescription() { 71 | return description; 72 | } 73 | 74 | public void setDescription(String description) { 75 | this.description = description; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/config/AbstractAutowireCapableBeanFactory.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory.config; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.minis.beans.BeansException; 7 | import com.minis.beans.factory.support.AbstractBeanFactory; 8 | 9 | public abstract class AbstractAutowireCapableBeanFactory 10 | extends AbstractBeanFactory implements AutowireCapableBeanFactory{ 11 | private final List beanPostProcessors = new ArrayList(); 12 | 13 | public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor) { 14 | this.beanPostProcessors.remove(beanPostProcessor); 15 | this.beanPostProcessors.add(beanPostProcessor); 16 | } 17 | public int getBeanPostProcessorCount() { 18 | return this.beanPostProcessors.size(); 19 | } 20 | public List getBeanPostProcessors() { 21 | return this.beanPostProcessors; 22 | } 23 | 24 | public Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName) 25 | throws BeansException { 26 | 27 | Object result = existingBean; 28 | for (BeanPostProcessor beanProcessor : getBeanPostProcessors()) { 29 | beanProcessor.setBeanFactory(this); 30 | result = beanProcessor.postProcessBeforeInitialization(result, beanName); 31 | if (result == null) { 32 | return result; 33 | } 34 | } 35 | existingBean = result; 36 | return result; 37 | } 38 | 39 | public Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName) 40 | throws BeansException { 41 | 42 | Object result = existingBean; 43 | for (BeanPostProcessor beanProcessor : getBeanPostProcessors()) { 44 | result = beanProcessor.postProcessAfterInitialization(result, beanName); 45 | if (result == null) { 46 | return result; 47 | } 48 | } 49 | return result; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/com/minis/web/bind/WebDataBinder.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.bind; 2 | 3 | import java.util.Map; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | 7 | import com.minis.beans.AbstractPropertyAccessor; 8 | import com.minis.beans.BeanWrapperImpl; 9 | import com.minis.beans.PropertyEditor; 10 | import com.minis.beans.PropertyValues; 11 | import com.minis.util.WebUtils; 12 | 13 | public class WebDataBinder { 14 | private Object target; 15 | private Class clz; 16 | 17 | private String objectName; 18 | AbstractPropertyAccessor propertyAccessor; 19 | 20 | public WebDataBinder(Object target) { 21 | this(target,""); 22 | } 23 | public WebDataBinder(Object target, String targetName) { 24 | this.target = target; 25 | this.objectName = targetName; 26 | this.clz = this.target.getClass(); 27 | this.propertyAccessor = new BeanWrapperImpl(this.target); 28 | } 29 | 30 | public void bind(HttpServletRequest request) { 31 | PropertyValues mpvs = assignParameters(request); 32 | addBindValues(mpvs, request); 33 | doBind(mpvs); 34 | } 35 | 36 | private void doBind(PropertyValues mpvs) { 37 | applyPropertyValues(mpvs); 38 | 39 | } 40 | 41 | protected void applyPropertyValues(PropertyValues mpvs) { 42 | getPropertyAccessor().setPropertyValues(mpvs); 43 | } 44 | 45 | protected AbstractPropertyAccessor getPropertyAccessor() { 46 | return this.propertyAccessor; 47 | } 48 | 49 | private PropertyValues assignParameters(HttpServletRequest request) { 50 | Map map = WebUtils.getParametersStartingWith(request, ""); 51 | 52 | return new PropertyValues(map); 53 | } 54 | 55 | public void registerCustomEditor(Class requiredType, PropertyEditor propertyEditor) { 56 | getPropertyAccessor().registerCustomEditor(requiredType, propertyEditor); 57 | } 58 | 59 | protected void addBindValues(PropertyValues mpvs, HttpServletRequest request) { 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/com/minis/aop/framework/JdkDynamicAopProxy.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop.framework; 2 | 3 | import java.lang.reflect.InvocationHandler; 4 | import java.lang.reflect.Method; 5 | import java.lang.reflect.Proxy; 6 | 7 | import com.minis.aop.Advisor; 8 | import com.minis.aop.MethodInterceptor; 9 | import com.minis.aop.MethodInvocation; 10 | import com.minis.aop.PointcutAdvisor; 11 | import com.minis.scheduling.annotation.AsyncAnnotationAdvisor; 12 | 13 | public class JdkDynamicAopProxy implements AopProxy, InvocationHandler { 14 | Object target; 15 | Advisor advisor; //should be a list to support multiple advisors 16 | 17 | public JdkDynamicAopProxy(Object target, Advisor advisor) { 18 | this.target = target; 19 | this.advisor = advisor; 20 | } 21 | 22 | @Override 23 | public Object getProxy() { 24 | Object obj = Proxy.newProxyInstance(JdkDynamicAopProxy.class.getClassLoader(), target.getClass().getInterfaces(), this); 25 | return obj; 26 | } 27 | 28 | @Override 29 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { 30 | Class targetClass = (target != null ? target.getClass() : null); 31 | 32 | if (this.advisor instanceof PointcutAdvisor) { 33 | if (((PointcutAdvisor)this.advisor).getPointcut().getMethodMatcher().matches(method, targetClass)) { 34 | //if (method.getName().equals("doAction")) { 35 | MethodInterceptor interceptor = this.advisor.getMethodInterceptor(); 36 | MethodInvocation invocation = 37 | new ReflectiveMethodInvocation(proxy, target, method, args, targetClass); 38 | return interceptor.invoke(invocation); 39 | } 40 | } 41 | if (this.advisor instanceof AsyncAnnotationAdvisor) { 42 | MethodInterceptor interceptor = this.advisor.getMethodInterceptor(); 43 | 44 | MethodInvocation invocation = 45 | new ReflectiveMethodInvocation(proxy, target, method, args, targetClass); 46 | return interceptor.invoke(invocation); 47 | } 48 | return null; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory.annotation; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | import com.minis.beans.BeansException; 6 | import com.minis.beans.factory.BeanFactory; 7 | import com.minis.beans.factory.BeanFactoryAware; 8 | import com.minis.beans.factory.config.BeanPostProcessor; 9 | 10 | public class AutowiredAnnotationBeanPostProcessor implements BeanPostProcessor,BeanFactoryAware { 11 | private BeanFactory beanFactory; 12 | 13 | @Override 14 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 15 | Object result = bean; 16 | 17 | Class clazz = bean.getClass(); 18 | Field[] fields = clazz.getDeclaredFields(); 19 | if(fields!=null){ 20 | for(Field field : fields){ 21 | boolean isAutowired = field.isAnnotationPresent(Autowired.class); 22 | if(isAutowired){ 23 | String fieldName = field.getName(); 24 | Object autowiredObj = this.getBeanFactory().getBean(fieldName); 25 | try { 26 | field.setAccessible(true); 27 | field.set(bean, autowiredObj); 28 | System.out.println("autowire " + fieldName + " for bean " + beanName); 29 | System.out.println("autowire " + fieldName + " for bean " + beanName + " : " + autowiredObj + " class : "+autowiredObj.getClass()); 30 | } catch (IllegalArgumentException e) { 31 | e.printStackTrace(); 32 | } catch (IllegalAccessException e) { 33 | e.printStackTrace(); 34 | } 35 | 36 | } 37 | } 38 | } 39 | 40 | return result; 41 | } 42 | 43 | @Override 44 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 45 | // TODO Auto-generated method stub 46 | return bean; 47 | } 48 | 49 | public BeanFactory getBeanFactory() { 50 | return beanFactory; 51 | } 52 | 53 | public void setBeanFactory(BeanFactory beanFactory) { 54 | this.beanFactory = beanFactory; 55 | } 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/com/minis/aop/support/NameMatchMethodPointcutAdvisor.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop.support; 2 | 3 | import com.minis.aop.Advice; 4 | import com.minis.aop.AfterAdvice; 5 | import com.minis.aop.AfterReturningAdvice; 6 | import com.minis.aop.BeforeAdvice; 7 | import com.minis.aop.MethodBeforeAdvice; 8 | import com.minis.aop.MethodInterceptor; 9 | import com.minis.aop.Pointcut; 10 | import com.minis.aop.PointcutAdvisor; 11 | import com.minis.aop.framework.adapter.AfterReturningAdviceInterceptor; 12 | import com.minis.aop.framework.adapter.MethodBeforeAdviceInterceptor; 13 | 14 | public class NameMatchMethodPointcutAdvisor implements PointcutAdvisor{ 15 | private Advice advice = null; 16 | private MethodInterceptor methodInterceptor; 17 | private String mappedName; 18 | private final NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut(); 19 | 20 | public NameMatchMethodPointcutAdvisor() { 21 | } 22 | 23 | public NameMatchMethodPointcutAdvisor(Advice advice) { 24 | this.advice = advice; 25 | } 26 | 27 | public void setMethodInterceptor(MethodInterceptor methodInterceptor) { 28 | this.methodInterceptor = methodInterceptor; 29 | } 30 | 31 | public MethodInterceptor getMethodInterceptor() { 32 | return this.methodInterceptor; 33 | } 34 | 35 | 36 | public void setAdvice(Advice advice) { 37 | this.advice = advice; 38 | 39 | MethodInterceptor mi = null; 40 | 41 | if (advice instanceof BeforeAdvice) { 42 | mi = new MethodBeforeAdviceInterceptor((MethodBeforeAdvice)advice); 43 | } 44 | else if (advice instanceof AfterAdvice){ 45 | mi = new AfterReturningAdviceInterceptor((AfterReturningAdvice)advice); 46 | } 47 | else if (advice instanceof MethodInterceptor) { 48 | mi = (MethodInterceptor)advice; 49 | } 50 | 51 | setMethodInterceptor(mi); 52 | } 53 | 54 | @Override 55 | public Advice getAdvice() { 56 | return this.advice; 57 | } 58 | 59 | @Override 60 | public Pointcut getPointcut() { 61 | return pointcut; 62 | } 63 | 64 | public void setMappedName(String mappedName) { 65 | this.mappedName = mappedName; 66 | this.pointcut.setMappedName(this.mappedName); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/com/minis/aop/AsyncExecutionInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | import java.lang.reflect.Method; 4 | import java.util.concurrent.Callable; 5 | import java.util.concurrent.ExecutionException; 6 | import java.util.concurrent.Future; 7 | 8 | import com.minis.scheduling.concurrent.ThreadPoolTaskExecutor; 9 | import com.minis.util.concurrent.ListenableFuture; 10 | 11 | public class AsyncExecutionInterceptor implements MethodInterceptor{ 12 | ThreadPoolTaskExecutor executor; 13 | 14 | public ThreadPoolTaskExecutor getExecutor() { 15 | return this.executor; 16 | } 17 | public void setExecutor(ThreadPoolTaskExecutor defaultExecutor) { 18 | this.executor = defaultExecutor; 19 | } 20 | 21 | public AsyncExecutionInterceptor() { 22 | } 23 | 24 | public Object invoke(final MethodInvocation invocation) throws Throwable { 25 | Callable task = () -> { 26 | try { 27 | Object result = invocation.proceed(); 28 | if (result instanceof Future) { 29 | return ((Future) result).get(); 30 | } 31 | } 32 | catch (ExecutionException ex) { 33 | throw ex; 34 | } 35 | catch (Throwable ex) { 36 | } 37 | return null; 38 | }; 39 | 40 | System.out.println("Async Interceptor.invoke().Execute method asynchronously. " 41 | + Thread.currentThread().getName()); 42 | return doSubmit(task, executor, invocation.getMethod().getReturnType()); 43 | } 44 | 45 | protected Object doSubmit(Callable task, ThreadPoolTaskExecutor executor, Class returnType) { 46 | if (ListenableFuture.class.isAssignableFrom(returnType)) { 47 | System.out.println("Async dosubmit() listenableFuture. " 48 | + Thread.currentThread().getName()); 49 | return executor.submitListenable(task); 50 | } 51 | else if (Future.class.isAssignableFrom(returnType)) { 52 | System.out.println("Async dosubmit() Future. " 53 | + Thread.currentThread().getName()); 54 | return executor.submit(task); 55 | } 56 | else { 57 | System.out.println("Async dosubmit(). " 58 | + Thread.currentThread().getName()); 59 | executor.submit(task); 60 | return null; 61 | } 62 | } 63 | 64 | } 65 | 66 | -------------------------------------------------------------------------------- /src/com/minis/web/servlet/view/InternalResourceViewResolver.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.servlet.view; 2 | 3 | import com.minis.web.servlet.View; 4 | import com.minis.web.servlet.ViewResolver; 5 | 6 | public class InternalResourceViewResolver implements ViewResolver{ 7 | private Class viewClass = null; 8 | private String viewClassName = ""; 9 | private String prefix = ""; 10 | private String suffix = ""; 11 | private String contentType; 12 | 13 | public InternalResourceViewResolver() { 14 | if (getViewClass() == null) { 15 | setViewClass(JstlView.class); 16 | } 17 | } 18 | 19 | public void setViewClassName(String viewClassName) { 20 | this.viewClassName = viewClassName; 21 | Class clz = null; 22 | try { 23 | clz = Class.forName(viewClassName); 24 | } catch (ClassNotFoundException e) { 25 | e.printStackTrace(); 26 | } 27 | setViewClass(clz); 28 | } 29 | 30 | protected String getViewClassName() { 31 | return this.viewClassName; 32 | } 33 | public void setViewClass(Class viewClass) { 34 | this.viewClass = viewClass; 35 | } 36 | protected Class getViewClass() { 37 | return this.viewClass; 38 | } 39 | public void setPrefix(String prefix) { 40 | this.prefix = (prefix != null ? prefix : ""); 41 | } 42 | protected String getPrefix() { 43 | return this.prefix; 44 | } 45 | public void setSuffix(String suffix) { 46 | this.suffix = (suffix != null ? suffix : ""); 47 | } 48 | protected String getSuffix() { 49 | return this.suffix; 50 | } 51 | public void setContentType(String contentType) { 52 | this.contentType = contentType; 53 | } 54 | protected String getContentType() { 55 | return this.contentType; 56 | } 57 | 58 | @Override 59 | public View resolveViewName(String viewName) throws Exception { 60 | return buildView(viewName); 61 | } 62 | 63 | protected View buildView(String viewName) throws Exception { 64 | Class viewClass = getViewClass(); 65 | 66 | View view = (View) viewClass.newInstance(); 67 | view.setUrl(getPrefix() + viewName + getSuffix()); 68 | 69 | String contentType = getContentType(); 70 | view.setContentType(contentType); 71 | 72 | return view; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/com/minis/beans/CustomNumberEditor.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans; 2 | 3 | import java.text.NumberFormat; 4 | 5 | import com.minis.util.NumberUtils; 6 | import com.minis.util.StringUtils; 7 | 8 | public class CustomNumberEditor implements PropertyEditor { 9 | private Class numberClass; 10 | private NumberFormat numberFormat; 11 | private boolean allowEmpty; 12 | private Object value; 13 | 14 | public CustomNumberEditor(Class numberClass, 15 | boolean allowEmpty) throws IllegalArgumentException { 16 | this(numberClass, null, allowEmpty); 17 | } 18 | 19 | public CustomNumberEditor(Class numberClass, 20 | NumberFormat numberFormat, boolean allowEmpty) throws IllegalArgumentException { 21 | this.numberClass = numberClass; 22 | this.numberFormat = numberFormat; 23 | this.allowEmpty = allowEmpty; 24 | } 25 | 26 | @Override 27 | public void setAsText(String text) { 28 | if (this.allowEmpty && !StringUtils.hasText(text)) { 29 | // Treat empty String as null value. 30 | setValue(null); 31 | } 32 | else if (this.numberFormat != null) { 33 | // Use given NumberFormat for parsing text. 34 | setValue(NumberUtils.parseNumber(text, this.numberClass, this.numberFormat)); 35 | } 36 | else { 37 | // Use default valueOf methods for parsing text. 38 | setValue(NumberUtils.parseNumber(text, this.numberClass)); 39 | } 40 | } 41 | 42 | @Override 43 | public void setValue(Object value) { 44 | if (value instanceof Number) { 45 | this.value = (NumberUtils.convertNumberToTargetClass((Number) value, this.numberClass)); 46 | } 47 | else { 48 | this.value = value; 49 | } 50 | } 51 | 52 | @Override 53 | public String getAsText() { 54 | Object value = this.value; 55 | if (value == null) { 56 | return ""; 57 | } 58 | if (this.numberFormat != null) { 59 | // Use NumberFormat for rendering value. 60 | return this.numberFormat.format(value); 61 | } 62 | else { 63 | // Use toString method for rendering value. 64 | return value.toString(); 65 | } 66 | } 67 | 68 | @Override 69 | public Object getValue() { 70 | return this.value; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/com/minis/beans/PropertyValues.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | 8 | public class PropertyValues{ 9 | private final List propertyValueList; 10 | 11 | public PropertyValues() { 12 | this.propertyValueList = new ArrayList(10); 13 | } 14 | public PropertyValues(Map map) { 15 | this.propertyValueList = new ArrayList(10); 16 | for (Map.Entry e: map.entrySet()) { 17 | PropertyValue pv = new PropertyValue(e.getKey(),e.getValue()); 18 | this.propertyValueList.add(pv); 19 | } 20 | } 21 | 22 | public List getPropertyValueList() { 23 | return this.propertyValueList; 24 | } 25 | 26 | public int size() { 27 | return this.propertyValueList.size(); 28 | } 29 | 30 | public void addPropertyValue(PropertyValue pv) { 31 | this.propertyValueList.add(pv); 32 | } 33 | 34 | // public void addPropertyValue(String propertyType, String propertyName, Object propertyValue) { 35 | // addPropertyValue(new PropertyValue(propertyType, propertyName, propertyValue)); 36 | // } 37 | 38 | public void removePropertyValue(PropertyValue pv) { 39 | this.propertyValueList.remove(pv); 40 | } 41 | 42 | public void removePropertyValue(String propertyName) { 43 | this.propertyValueList.remove(getPropertyValue(propertyName)); 44 | } 45 | 46 | 47 | public PropertyValue[] getPropertyValues() { 48 | return this.propertyValueList.toArray(new PropertyValue[this.propertyValueList.size()]); 49 | } 50 | 51 | public PropertyValue getPropertyValue(String propertyName) { 52 | for (PropertyValue pv : this.propertyValueList) { 53 | if (pv.getName().equals(propertyName)) { 54 | return pv; 55 | } 56 | } 57 | return null; 58 | } 59 | 60 | public Object get(String propertyName) { 61 | PropertyValue pv = getPropertyValue(propertyName); 62 | return (pv != null ? pv.getValue() : null); 63 | } 64 | 65 | public boolean contains(String propertyName) { 66 | return (getPropertyValue(propertyName) != null); 67 | } 68 | 69 | public boolean isEmpty() { 70 | return this.propertyValueList.isEmpty(); 71 | } 72 | 73 | 74 | } 75 | 76 | -------------------------------------------------------------------------------- /src/com/minis/util/concurrent/ListenableFutureCallbackRegistry.java: -------------------------------------------------------------------------------- 1 | package com.minis.util.concurrent; 2 | 3 | import java.util.LinkedList; 4 | import java.util.Queue; 5 | 6 | public class ListenableFutureCallbackRegistry { 7 | private enum State {NEW, SUCCESS, FAILURE} 8 | 9 | private final Queue> successCallbacks = new LinkedList<>(); 10 | private final Queue failureCallbacks = new LinkedList<>(); 11 | 12 | private State state = State.NEW; 13 | 14 | private Object result; 15 | private final Object mutex = new Object(); 16 | 17 | private void notifySuccess(SuccessCallback callback) { 18 | try { 19 | callback.onSuccess((T) this.result); 20 | } 21 | catch (Throwable ex) { 22 | } 23 | } 24 | 25 | private void notifyFailure(FailureCallback callback) { 26 | try { 27 | callback.onFailure((Throwable) this.result); 28 | } 29 | catch (Throwable ex) { 30 | } 31 | } 32 | 33 | public void addSuccessCallback(SuccessCallback callback) { 34 | synchronized (this.mutex) { 35 | switch (this.state) { 36 | case NEW: 37 | this.successCallbacks.add(callback); 38 | break; 39 | // case SUCCESS: 40 | // notifySuccess(callback); 41 | // break; 42 | } 43 | } 44 | } 45 | 46 | public void addFailureCallback(FailureCallback callback) { 47 | synchronized (this.mutex) { 48 | switch (this.state) { 49 | case NEW: 50 | this.failureCallbacks.add(callback); 51 | break; 52 | // case FAILURE: 53 | // notifyFailure(callback); 54 | // break; 55 | } 56 | } 57 | } 58 | 59 | public void success(T result) { 60 | synchronized (this.mutex) { 61 | this.state = State.SUCCESS; 62 | this.result = result; 63 | SuccessCallback callback; 64 | while ((callback = this.successCallbacks.poll()) != null) { 65 | notifySuccess(callback); 66 | } 67 | } 68 | } 69 | 70 | public void failure(Throwable ex) { 71 | synchronized (this.mutex) { 72 | this.state = State.FAILURE; 73 | this.result = ex; 74 | FailureCallback callback; 75 | while ((callback = this.failureCallbacks.poll()) != null) { 76 | notifyFailure(callback); 77 | } 78 | } 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /src/com/minis/web/method/annotation/MappingRegistry.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.method.annotation; 2 | 3 | import java.lang.reflect.Method; 4 | import java.util.ArrayList; 5 | import java.util.HashMap; 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | public class MappingRegistry { 10 | private List urlMappingNames = new ArrayList<>(); 11 | private List requestMethods = new ArrayList<>(); 12 | private List qualifiedNames = new ArrayList<>(); 13 | private Map mappingObjs = new HashMap<>(); 14 | private Map mappingMethods = new HashMap<>(); 15 | private Map mappingMethodNames = new HashMap<>(); 16 | private Map> mappingClasses = new HashMap<>(); 17 | 18 | public List getUrlMappingNames() { 19 | return urlMappingNames; 20 | } 21 | public void setUrlMappingNames(List urlMappingNames) { 22 | this.urlMappingNames = urlMappingNames; 23 | } 24 | public Map getMappingObjs() { 25 | return mappingObjs; 26 | } 27 | public void setMappingObjs(Map mappingObjs) { 28 | this.mappingObjs = mappingObjs; 29 | } 30 | public Map getMappingMethods() { 31 | return mappingMethods; 32 | } 33 | public void setMappingMethods(Map mappingMethods) { 34 | this.mappingMethods = mappingMethods; 35 | } 36 | public Map> getMappingClasses() { 37 | return mappingClasses; 38 | } 39 | public void setMappingClasses(Map> mappingClasses) { 40 | this.mappingClasses = mappingClasses; 41 | } 42 | public Map getMappingMethodNames() { 43 | return mappingMethodNames; 44 | } 45 | public void setMappingMethodNames(Map mappingMethodNames) { 46 | this.mappingMethodNames = mappingMethodNames; 47 | } 48 | public List getRequestMethods() { 49 | return requestMethods; 50 | } 51 | public void setRequestMethods(List requestMethods) { 52 | this.requestMethods = requestMethods; 53 | } 54 | public List getQualifiedNames() { 55 | return qualifiedNames; 56 | } 57 | public void setQualifiedNames(List qualifiedNames) { 58 | this.qualifiedNames = qualifiedNames; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/com/minis/web/servlet/ModelAndView.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.servlet; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class ModelAndView { 7 | private Object view; 8 | private Map model = new HashMap<>(); 9 | 10 | public ModelAndView() { 11 | } 12 | 13 | public ModelAndView(String viewName) { 14 | this.view = viewName; 15 | } 16 | 17 | public ModelAndView(View view) { 18 | this.view = view; 19 | } 20 | 21 | public ModelAndView(String viewName, Map modelData) { 22 | this.view = viewName; 23 | if (modelData != null) { 24 | addAllAttributes(modelData); 25 | } 26 | } 27 | 28 | public ModelAndView(View view, Map model) { 29 | this.view = view; 30 | if (model != null) { 31 | addAllAttributes(model); 32 | } 33 | } 34 | 35 | public ModelAndView(String viewName, String modelName, Object modelObject) { 36 | this.view = viewName; 37 | addObject(modelName, modelObject); 38 | } 39 | 40 | public ModelAndView(View view, String modelName, Object modelObject) { 41 | this.view = view; 42 | addObject(modelName, modelObject); 43 | } 44 | 45 | 46 | public void setViewName(String viewName) { 47 | this.view = viewName; 48 | } 49 | 50 | 51 | public String getViewName() { 52 | return (this.view instanceof String ? (String) this.view : null); 53 | } 54 | 55 | 56 | public void setView(View view) { 57 | this.view = view; 58 | } 59 | 60 | public View getView() { 61 | return (this.view instanceof View ? (View) this.view : null); 62 | } 63 | 64 | public boolean hasView() { 65 | return (this.view != null); 66 | } 67 | 68 | public boolean isReference() { 69 | return (this.view instanceof String); 70 | } 71 | 72 | public Map getModel() { 73 | return this.model; 74 | } 75 | 76 | private void addAllAttributes(Map modelData) { 77 | if (modelData != null) { 78 | model.putAll(modelData); 79 | } 80 | } 81 | 82 | public void addAttribute(String attributeName, Object attributeValue) { 83 | model.put(attributeName, attributeValue); 84 | } 85 | 86 | public ModelAndView addObject(String attributeName, Object attributeValue) { 87 | addAttribute(attributeName, attributeValue); 88 | return this; 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/com/test/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.test.service; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.SQLException; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import com.minis.beans.factory.annotation.Autowired; 9 | import com.minis.jdbc.core.JdbcTemplate; 10 | import com.minis.jdbc.core.RowMapper; 11 | import com.test.entity.User; 12 | 13 | public class UserService { 14 | @Autowired 15 | JdbcTemplate jdbcTemplate; 16 | 17 | // public User getUserInfo(int userid) { 18 | // final String sql = "select id, name,birthday from users where id="+userid; 19 | // return (User)jdbcTemplate.query( 20 | // (stmt)->{ 21 | // ResultSet rs = stmt.executeQuery(sql); 22 | // User rtnUser = null; 23 | // if (rs.next()) { 24 | // rtnUser = new User(); 25 | // rtnUser.setId(userid); 26 | // rtnUser.setName(rs.getString("name")); 27 | // rtnUser.setBirthday(new java.util.Date(rs.getDate("birthday").getTime())); 28 | // } else { 29 | // } 30 | // return rtnUser; 31 | // } 32 | // ); 33 | // } 34 | 35 | public User getUserInfo(int userid) { 36 | final String sql = "select id, name,birthday from users where id=?"; 37 | return (User)jdbcTemplate.query(sql, new Object[]{new Integer(userid)}, 38 | (pstmt)->{ 39 | ResultSet rs = pstmt.executeQuery(); 40 | User rtnUser = null; 41 | if (rs.next()) { 42 | rtnUser = new User(); 43 | rtnUser.setId(userid); 44 | rtnUser.setName(rs.getString("name")); 45 | rtnUser.setBirthday(new java.util.Date(rs.getDate("birthday").getTime())); 46 | } else { 47 | } 48 | return rtnUser; 49 | } 50 | ); 51 | } 52 | 53 | public List getUsers(int userid) { 54 | final String sql = "select id, name,birthday from users where id>?"; 55 | return (List)jdbcTemplate.query(sql, new Object[]{new Integer(userid)}, 56 | new RowMapper(){ 57 | public User mapRow(ResultSet rs, int i) throws SQLException { 58 | User rtnUser = new User(); 59 | rtnUser.setId(rs.getInt("id")); 60 | rtnUser.setName(rs.getString("name")); 61 | rtnUser.setBirthday(new java.util.Date(rs.getDate("birthday").getTime())); 62 | 63 | return rtnUser; 64 | } 65 | } 66 | ); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/com/test/CustomDateEditor.java: -------------------------------------------------------------------------------- 1 | package com.test; 2 | 3 | import java.text.NumberFormat; 4 | import java.time.LocalDate; 5 | import java.time.LocalDateTime; 6 | import java.time.ZoneId; 7 | import java.time.format.DateTimeFormatter; 8 | import java.util.Date; 9 | 10 | import com.minis.beans.PropertyEditor; 11 | import com.minis.util.NumberUtils; 12 | import com.minis.util.StringUtils; 13 | 14 | public class CustomDateEditor implements PropertyEditor { 15 | private Class dateClass; 16 | private DateTimeFormatter datetimeFormatter; 17 | private boolean allowEmpty; 18 | private Date value; 19 | 20 | public CustomDateEditor() throws IllegalArgumentException { 21 | this(Date.class, "yyyy-MM-dd", true); 22 | } 23 | public CustomDateEditor(Class dateClass) throws IllegalArgumentException { 24 | this(dateClass, "yyyy-MM-dd", true); 25 | } 26 | 27 | public CustomDateEditor(Class dateClass, 28 | boolean allowEmpty) throws IllegalArgumentException { 29 | this(dateClass, "yyyy-MM-dd", allowEmpty); 30 | } 31 | 32 | public CustomDateEditor(Class dateClass, 33 | String pattern, boolean allowEmpty) throws IllegalArgumentException { 34 | this.dateClass = dateClass; 35 | this.datetimeFormatter = DateTimeFormatter.ofPattern(pattern); 36 | this.allowEmpty = allowEmpty; 37 | } 38 | 39 | @Override 40 | public void setAsText(String text) { 41 | if (this.allowEmpty && !StringUtils.hasText(text)) { 42 | // Treat empty String as null value. 43 | setValue(null); 44 | } 45 | 46 | else { 47 | // Use default valueOf methods for parsing text. 48 | LocalDate localdate = LocalDate.parse(text, datetimeFormatter); 49 | 50 | setValue(Date.from(localdate.atStartOfDay(ZoneId.systemDefault()).toInstant())); 51 | } 52 | } 53 | 54 | @Override 55 | public void setValue(Object value) { 56 | this.value = (Date) value; 57 | } 58 | 59 | @Override 60 | public String getAsText() { 61 | Date value = this.value; 62 | if (value == null) { 63 | return ""; 64 | } 65 | else { 66 | LocalDate localDate = value.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); 67 | return localDate.format(datetimeFormatter); 68 | } 69 | } 70 | 71 | @Override 72 | public Object getValue() { 73 | return this.value; 74 | } 75 | 76 | } -------------------------------------------------------------------------------- /src/com/minis/beans/factory/support/DefaultListableBeanFactory.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory.support; 2 | 3 | import java.util.ArrayList; 4 | import java.util.LinkedHashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | import com.minis.beans.BeansException; 9 | import com.minis.beans.factory.config.AbstractAutowireCapableBeanFactory; 10 | import com.minis.beans.factory.config.BeanDefinition; 11 | import com.minis.beans.factory.config.ConfigurableListableBeanFactory; 12 | 13 | public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory 14 | implements ConfigurableListableBeanFactory{ 15 | ConfigurableListableBeanFactory parentBeanFctory; 16 | 17 | @Override 18 | public int getBeanDefinitionCount() { 19 | return this.beanDefinitionMap.size(); 20 | } 21 | 22 | @Override 23 | public String[] getBeanDefinitionNames() { 24 | return (String[])this.beanDefinitionNames.toArray(new String[this.beanDefinitionNames.size()]); 25 | } 26 | 27 | @Override 28 | public String[] getBeanNamesForType(Class type) { 29 | List result = new ArrayList<>(); 30 | 31 | for (String beanName : this.beanDefinitionNames) { 32 | boolean matchFound = false; 33 | BeanDefinition mbd = this.getBeanDefinition(beanName); 34 | Class classToMatch = mbd.getClass(); 35 | if (type.isAssignableFrom(classToMatch)) { 36 | matchFound = true; 37 | } 38 | else { 39 | matchFound = false; 40 | } 41 | 42 | if (matchFound) { 43 | result.add(beanName); 44 | } 45 | } 46 | return (String[]) result.toArray(); 47 | 48 | } 49 | 50 | @SuppressWarnings("unchecked") 51 | @Override 52 | public Map getBeansOfType(Class type) throws BeansException { 53 | String[] beanNames = getBeanNamesForType(type); 54 | Map result = new LinkedHashMap<>(beanNames.length); 55 | for (String beanName : beanNames) { 56 | Object beanInstance = getBean(beanName); 57 | result.put(beanName, (T) beanInstance); 58 | } 59 | return result; 60 | } 61 | 62 | public void setParent(ConfigurableListableBeanFactory beanFactory) { 63 | this.parentBeanFctory = beanFactory; 64 | } 65 | 66 | @Override 67 | public Object getBean(String beanName) throws BeansException{ 68 | Object result = super.getBean(beanName); 69 | if (result == null) { 70 | result = this.parentBeanFctory.getBean(beanName); 71 | } 72 | 73 | return result; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/com/minis/scheduling/annotation/AsyncAnnotationBeanPostProcessor.java: -------------------------------------------------------------------------------- 1 | package com.minis.scheduling.annotation; 2 | 3 | import java.lang.reflect.Field; 4 | import java.lang.reflect.Method; 5 | 6 | import com.minis.aop.framework.AopProxyFactory; 7 | import com.minis.aop.framework.DefaultAopProxyFactory; 8 | import com.minis.aop.framework.ProxyFactoryBean; 9 | import com.minis.beans.BeansException; 10 | import com.minis.beans.factory.BeanFactory; 11 | import com.minis.beans.factory.BeanFactoryAware; 12 | import com.minis.beans.factory.annotation.Autowired; 13 | import com.minis.beans.factory.config.BeanPostProcessor; 14 | import com.minis.scheduling.concurrent.ThreadPoolTaskExecutor; 15 | import com.minis.aop.Advisor; 16 | import com.minis.aop.AsyncExecutionInterceptor; 17 | import com.minis.aop.MethodInterceptor; 18 | 19 | public class AsyncAnnotationBeanPostProcessor implements BeanPostProcessor,BeanFactoryAware{ 20 | private BeanFactory beanFactory; 21 | 22 | @Override 23 | public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { 24 | Object result = bean; 25 | 26 | Class clazz = bean.getClass(); 27 | Method[] methods = clazz.getDeclaredMethods(); 28 | if(methods!=null){ 29 | for(Method method : methods){ 30 | boolean isAsync = method.isAnnotationPresent(Async.class); 31 | 32 | if(isAsync){ 33 | System.out.println("AsyncAnnotationBeanPostProcessor is Async. "); 34 | AopProxyFactory proxyFactory = new DefaultAopProxyFactory(); 35 | ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean(); 36 | Advisor advisor = (Advisor)beanFactory.getBean("asyncAnnotationAdvisor"); 37 | MethodInterceptor methodInterceptor = (AsyncExecutionInterceptor)beanFactory.getBean("asyncExecutionInterceptor"); 38 | advisor.setMethodInterceptor(methodInterceptor); 39 | proxyFactoryBean.setTarget(bean); 40 | proxyFactoryBean.setBeanFactory(beanFactory); 41 | proxyFactoryBean.setAopProxyFactory(proxyFactory); 42 | proxyFactoryBean.setInterceptorName("asyncAnnotationAdvisor"); 43 | bean = proxyFactoryBean; 44 | return proxyFactoryBean; 45 | 46 | } 47 | } 48 | } 49 | 50 | return result; 51 | } 52 | 53 | @Override 54 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { 55 | return bean; 56 | } 57 | 58 | 59 | public BeanFactory getBeanFactory() { 60 | return beanFactory; 61 | } 62 | 63 | public void setBeanFactory(BeanFactory beanFactory) { 64 | this.beanFactory = beanFactory; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/com/minis/beans/BeanWrapperImpl.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans; 2 | 3 | import java.lang.reflect.Field; 4 | import java.lang.reflect.InvocationTargetException; 5 | import java.lang.reflect.Method; 6 | 7 | public class BeanWrapperImpl extends AbstractPropertyAccessor { 8 | Object wrappedObject; 9 | Class clz; 10 | 11 | public BeanWrapperImpl(Object object) { 12 | super(); 13 | this.wrappedObject = object; 14 | this.clz = object.getClass(); 15 | } 16 | 17 | @Override 18 | public void setPropertyValue(PropertyValue pv) { 19 | BeanPropertyHandler propertyHandler = new BeanPropertyHandler(pv.getName()); 20 | PropertyEditor pe = this.getCustomEditor(propertyHandler.getPropertyClz()); 21 | if (pe == null) { 22 | pe = this.getDefaultEditor(propertyHandler.getPropertyClz()); 23 | 24 | } 25 | if (pe != null) { 26 | pe.setAsText((String) pv.getValue()); 27 | propertyHandler.setValue(pe.getValue()); 28 | } 29 | else { 30 | propertyHandler.setValue(pv.getValue()); 31 | } 32 | 33 | } 34 | 35 | class BeanPropertyHandler { 36 | Method writeMethod = null; 37 | Method readMethod = null; 38 | Class propertyClz = null; 39 | 40 | public Class getPropertyClz() { 41 | return propertyClz; 42 | } 43 | 44 | public BeanPropertyHandler(String propertyName) { 45 | try { 46 | Field field = clz.getDeclaredField(propertyName); 47 | propertyClz = field.getType(); 48 | this.writeMethod = clz.getDeclaredMethod("set"+propertyName.substring(0,1).toUpperCase()+propertyName.substring(1),propertyClz); 49 | this.readMethod = clz.getDeclaredMethod("get"+propertyName.substring(0,1).toUpperCase()+propertyName.substring(1)); 50 | } catch (NoSuchMethodException e) { 51 | e.printStackTrace(); 52 | } catch (SecurityException e) { 53 | e.printStackTrace(); 54 | } catch (NoSuchFieldException e) { 55 | // TODO Auto-generated catch block 56 | e.printStackTrace(); 57 | } 58 | } 59 | 60 | public Object getValue() { 61 | Object result = null; 62 | writeMethod.setAccessible(true); 63 | 64 | try { 65 | result = readMethod.invoke(wrappedObject); 66 | } catch (IllegalAccessException e) { 67 | e.printStackTrace(); 68 | } catch (IllegalArgumentException e) { 69 | e.printStackTrace(); 70 | } catch (InvocationTargetException e) { 71 | e.printStackTrace(); 72 | } 73 | return result; 74 | 75 | } 76 | 77 | public void setValue(Object value) { 78 | writeMethod.setAccessible(true); 79 | try { 80 | writeMethod.invoke(wrappedObject, value); 81 | } catch (IllegalAccessException e) { 82 | e.printStackTrace(); 83 | } catch (IllegalArgumentException e) { 84 | e.printStackTrace(); 85 | } catch (InvocationTargetException e) { 86 | e.printStackTrace(); 87 | } 88 | } 89 | 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /src/com/minis/jdbc/core/JdbcTemplate.java: -------------------------------------------------------------------------------- 1 | package com.minis.jdbc.core; 2 | 3 | import java.sql.Connection; 4 | import java.sql.DriverManager; 5 | import java.sql.PreparedStatement; 6 | import java.sql.ResultSet; 7 | import java.sql.Statement; 8 | import java.util.List; 9 | 10 | import javax.sql.DataSource; 11 | 12 | 13 | 14 | public class JdbcTemplate { 15 | private DataSource dataSource; 16 | 17 | public void setDataSource(DataSource dataSource) { 18 | this.dataSource = dataSource; 19 | } 20 | 21 | public DataSource getDataSource() { 22 | return this.dataSource; 23 | } 24 | 25 | public JdbcTemplate() { 26 | } 27 | 28 | public Object query(StatementCallback stmtcallback) { 29 | Connection con = null; 30 | Statement stmt = null; 31 | 32 | try { 33 | con = dataSource.getConnection(); 34 | 35 | stmt = con.createStatement(); 36 | 37 | return stmtcallback.doInStatement(stmt); 38 | } 39 | catch (Exception e) { 40 | e.printStackTrace(); 41 | } 42 | finally { 43 | try { 44 | stmt.close(); 45 | con.close(); 46 | } catch (Exception e) { 47 | 48 | } 49 | } 50 | 51 | return null; 52 | 53 | } 54 | public Object query(String sql, Object[] args, PreparedStatementCallback pstmtcallback) { 55 | Connection con = null; 56 | PreparedStatement pstmt = null; 57 | 58 | try { 59 | con = dataSource.getConnection(); 60 | 61 | pstmt = con.prepareStatement(sql); 62 | ArgumentPreparedStatementSetter argumentSetter = new ArgumentPreparedStatementSetter(args); 63 | argumentSetter.setValues(pstmt); 64 | 65 | return pstmtcallback.doInPreparedStatement(pstmt); 66 | } 67 | catch (Exception e) { 68 | e.printStackTrace(); 69 | } 70 | finally { 71 | try { 72 | pstmt.close(); 73 | con.close(); 74 | } catch (Exception e) { 75 | 76 | } 77 | } 78 | 79 | return null; 80 | 81 | } 82 | 83 | public List query(String sql, Object[] args, RowMapper rowMapper) { 84 | RowMapperResultSetExtractor resultExtractor = new RowMapperResultSetExtractor<>(rowMapper); 85 | Connection con = null; 86 | PreparedStatement pstmt = null; 87 | ResultSet rs = null; 88 | 89 | try { 90 | con = dataSource.getConnection(); 91 | 92 | pstmt = con.prepareStatement(sql); 93 | ArgumentPreparedStatementSetter argumentSetter = new ArgumentPreparedStatementSetter(args); 94 | argumentSetter.setValues(pstmt); 95 | rs = pstmt.executeQuery(); 96 | 97 | return resultExtractor.extractData(rs); 98 | } 99 | catch (Exception e) { 100 | e.printStackTrace(); 101 | } 102 | finally { 103 | try { 104 | pstmt.close(); 105 | con.close(); 106 | } catch (Exception e) { 107 | 108 | } 109 | } 110 | 111 | return null; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/com/minis/beans/PropertyEditorRegistrySupport.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans; 2 | 3 | import java.math.BigDecimal; 4 | import java.math.BigInteger; 5 | import java.util.HashMap; 6 | import java.util.LinkedHashMap; 7 | import java.util.Map; 8 | 9 | public class PropertyEditorRegistrySupport { 10 | private Map, PropertyEditor> defaultEditors; 11 | private Map, PropertyEditor> customEditors; 12 | 13 | public PropertyEditorRegistrySupport() { 14 | registerDefaultEditors(); 15 | } 16 | 17 | protected void registerDefaultEditors() { 18 | createDefaultEditors(); 19 | } 20 | 21 | public PropertyEditor getDefaultEditor(Class requiredType) { 22 | return this.defaultEditors.get(requiredType); 23 | } 24 | 25 | private void createDefaultEditors() { 26 | this.defaultEditors = new HashMap<>(64); 27 | 28 | // Default instances of collection editors. 29 | this.defaultEditors.put(int.class, new CustomNumberEditor(Integer.class, false)); 30 | this.defaultEditors.put(Integer.class, new CustomNumberEditor(Integer.class, true)); 31 | this.defaultEditors.put(long.class, new CustomNumberEditor(Long.class, false)); 32 | this.defaultEditors.put(Long.class, new CustomNumberEditor(Long.class, true)); 33 | this.defaultEditors.put(float.class, new CustomNumberEditor(Float.class, false)); 34 | this.defaultEditors.put(Float.class, new CustomNumberEditor(Float.class, true)); 35 | this.defaultEditors.put(double.class, new CustomNumberEditor(Double.class, false)); 36 | this.defaultEditors.put(Double.class, new CustomNumberEditor(Double.class, true)); 37 | this.defaultEditors.put(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, true)); 38 | this.defaultEditors.put(BigInteger.class, new CustomNumberEditor(BigInteger.class, true)); 39 | 40 | this.defaultEditors.put(String.class, new StringEditor(String.class, true)); 41 | 42 | } 43 | 44 | public void registerCustomEditor( Class requiredType, PropertyEditor propertyEditor) { 45 | if (this.customEditors == null) { 46 | this.customEditors = new LinkedHashMap<>(16); 47 | } 48 | this.customEditors.put(requiredType, propertyEditor); 49 | } 50 | 51 | public PropertyEditor findCustomEditor( Class requiredType) { 52 | Class requiredTypeToUse = requiredType; 53 | return getCustomEditor(requiredTypeToUse); 54 | } 55 | 56 | public boolean hasCustomEditorForElement( Class elementType) { 57 | // No property-specific editor -> check type-specific editor. 58 | return (elementType != null && this.customEditors != null && this.customEditors.containsKey(elementType)); 59 | } 60 | 61 | public PropertyEditor getCustomEditor( Class requiredType) { 62 | if (requiredType == null || this.customEditors == null) { 63 | return null; 64 | } 65 | // Check directly registered editor for type. 66 | PropertyEditor editor = this.customEditors.get(requiredType); 67 | 68 | return editor; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/com/minis/util/DefaultObjectMapper.java: -------------------------------------------------------------------------------- 1 | package com.minis.util; 2 | 3 | import java.lang.reflect.Field; 4 | import java.math.BigDecimal; 5 | import java.text.DecimalFormat; 6 | import java.time.LocalDate; 7 | import java.time.ZoneId; 8 | import java.time.format.DateTimeFormatter; 9 | import java.util.Date; 10 | import java.util.List; 11 | 12 | public class DefaultObjectMapper implements ObjectMapper{ 13 | String dateFormat = "yyyy-MM-dd"; 14 | DateTimeFormatter datetimeFormatter = DateTimeFormatter.ofPattern(dateFormat); 15 | 16 | String decimalFormat = "#,##0.00"; 17 | DecimalFormat decimalFormatter = new DecimalFormat(decimalFormat); 18 | 19 | public DefaultObjectMapper() { 20 | } 21 | 22 | @Override 23 | public void setDateFormat(String dateFormat) { 24 | this.dateFormat = dateFormat; 25 | this.datetimeFormatter = DateTimeFormatter.ofPattern(dateFormat); 26 | } 27 | 28 | @Override 29 | public void setDecimalFormat(String decimalFormat) { 30 | this.decimalFormat = decimalFormat; 31 | this.decimalFormatter = new DecimalFormat(decimalFormat); 32 | } 33 | 34 | @Override 35 | public String writeValuesAsString(Object obj) { 36 | if (obj instanceof List) { 37 | return writeListAsString((List)obj); 38 | } 39 | 40 | String sJsonStr = "{"; 41 | 42 | Class clz = obj.getClass(); 43 | 44 | Field[] fields = clz.getDeclaredFields(); 45 | for (Field field : fields) { 46 | String sField = ""; 47 | Object value = null; 48 | Class type = null; 49 | String name = field.getName(); 50 | String strValue = ""; 51 | try { 52 | field.setAccessible(true); 53 | value = field.get(obj); 54 | } catch (IllegalArgumentException e) { 55 | e.printStackTrace(); 56 | } catch (IllegalAccessException e) { 57 | e.printStackTrace(); 58 | } 59 | type = field.getType(); 60 | 61 | if (value instanceof Date) { 62 | LocalDate localDate = ((Date)value).toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); 63 | strValue = localDate.format(this.datetimeFormatter); 64 | } 65 | else if (value instanceof BigDecimal || value instanceof Double || value instanceof Float){ 66 | strValue = this.decimalFormatter.format(value); 67 | } 68 | else { 69 | strValue = value.toString(); 70 | } 71 | 72 | if (sJsonStr.equals("{")) { 73 | sField = "\"" + name + "\":\"" + strValue + "\""; 74 | } 75 | else { 76 | sField = ",\"" + name + "\":\"" + strValue + "\""; 77 | } 78 | 79 | sJsonStr += sField; 80 | } 81 | 82 | sJsonStr += "}"; 83 | 84 | return sJsonStr; 85 | } 86 | 87 | 88 | public String writeListAsString(List list) { 89 | String sJsonStr = "["; 90 | 91 | for (Object obj : list) { 92 | String sObj = writeValuesAsString(obj); 93 | if (sJsonStr.equals("[")) { 94 | sJsonStr += sObj; 95 | } 96 | else { 97 | sJsonStr += "," + sObj; 98 | } 99 | } 100 | 101 | sJsonStr += "]"; 102 | return sJsonStr; 103 | 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/com/minis/util/PatternMatchUtils.java: -------------------------------------------------------------------------------- 1 | package com.minis.util; 2 | 3 | import java.util.Arrays; 4 | 5 | public abstract class PatternMatchUtils { 6 | 7 | /** 8 | * Match a String against the given pattern, supporting the following simple 9 | * pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy" matches (with an 10 | * arbitrary number of pattern parts), as well as direct equality. 11 | * @param pattern the pattern to match against 12 | * @param str the String to match 13 | * @return whether the String matches the given pattern 14 | */ 15 | public static boolean simpleMatch( String pattern, String str) { 16 | if (pattern == null || str == null) { 17 | return false; 18 | } 19 | 20 | int firstIndex = pattern.indexOf('*'); 21 | if (firstIndex == -1) { 22 | return pattern.equals(str); 23 | } 24 | 25 | if (firstIndex == 0) { 26 | if (pattern.length() == 1) { 27 | return true; 28 | } 29 | int nextIndex = pattern.indexOf('*', 1); 30 | if (nextIndex == -1) { 31 | return str.endsWith(pattern.substring(1)); 32 | } 33 | String part = pattern.substring(1, nextIndex); 34 | if (part.isEmpty()) { 35 | return simpleMatch(pattern.substring(nextIndex), str); 36 | } 37 | int partIndex = str.indexOf(part); 38 | while (partIndex != -1) { 39 | if (simpleMatch(pattern.substring(nextIndex), str.substring(partIndex + part.length()))) { 40 | return true; 41 | } 42 | partIndex = str.indexOf(part, partIndex + 1); 43 | } 44 | return false; 45 | } 46 | 47 | return (str.length() >= firstIndex && 48 | pattern.substring(0, firstIndex).equals(str.substring(0, firstIndex)) && 49 | simpleMatch(pattern.substring(firstIndex), str.substring(firstIndex))); 50 | } 51 | 52 | /** 53 | * Match a String against the given patterns, supporting the following simple 54 | * pattern styles: "xxx*", "*xxx", "*xxx*" and "xxx*yyy" matches (with an 55 | * arbitrary number of pattern parts), as well as direct equality. 56 | * @param patterns the patterns to match against 57 | * @param str the String to match 58 | * @return whether the String matches any of the given patterns 59 | */ 60 | public static boolean simpleMatch( String[] patterns, String str) { 61 | if (patterns != null) { 62 | for (String pattern : patterns) { 63 | if (simpleMatch(pattern, str)) { 64 | return true; 65 | } 66 | } 67 | } 68 | return false; 69 | } 70 | 71 | public static boolean URIMatch( String patterns, String uri) { 72 | if (patterns != null) { 73 | String[] patternArr= patterns.split("/"); 74 | String[] uriArr= uri.split("/"); 75 | 76 | System.out.println(Arrays.toString(patternArr)); 77 | System.out.println(Arrays.toString(uriArr)); 78 | 79 | if (patternArr.length != uriArr.length) { 80 | return false; 81 | } 82 | for (int i=0; i constructorElements = element.elements("constructor-arg"); 31 | ConstructorArgumentValues AVS = new ConstructorArgumentValues(); 32 | for (Element e : constructorElements) { 33 | String pType = e.attributeValue("type"); 34 | String pName = e.attributeValue("name"); 35 | String pValue = e.attributeValue("value"); 36 | AVS.addArgumentValue(new ConstructorArgumentValue(pType,pName,pValue)); 37 | } 38 | beanDefinition.setConstructorArgumentValues(AVS); 39 | //end of handle constructor 40 | 41 | //handle properties 42 | List propertyElements = element.elements("property"); 43 | PropertyValues PVS = new PropertyValues(); 44 | List refs = new ArrayList<>(); 45 | for (Element e : propertyElements) { 46 | String pType = e.attributeValue("type"); 47 | String pName = e.attributeValue("name"); 48 | String pValue = e.attributeValue("value"); 49 | String pRef = e.attributeValue("ref"); 50 | String pV = ""; 51 | boolean isRef = false; 52 | if (pValue != null && !pValue.equals("")) { 53 | isRef = false; 54 | pV = pValue; 55 | } else if (pRef != null && !pRef.equals("")) { 56 | isRef = true; 57 | pV = pRef; 58 | refs.add(pRef); 59 | } 60 | PVS.addPropertyValue(new PropertyValue(pType, pName, pV, isRef)); 61 | } 62 | beanDefinition.setPropertyValues(PVS); 63 | String[] refArray = refs.toArray(new String[0]); 64 | beanDefinition.setDependsOn(refArray); 65 | //end of handle properties 66 | 67 | this.bf.registerBeanDefinition(beanID,beanDefinition); 68 | } 69 | } 70 | 71 | 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/com/minis/aop/ProxyFactoryBean.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop; 2 | 3 | import com.minis.beans.BeansException; 4 | import com.minis.beans.factory.BeanFactory; 5 | import com.minis.beans.factory.BeanFactoryAware; 6 | import com.minis.beans.factory.FactoryBean; 7 | import com.minis.util.ClassUtils; 8 | 9 | public class ProxyFactoryBean implements FactoryBean,BeanFactoryAware { 10 | private BeanFactory beanFactory; 11 | private AopProxyFactory aopProxyFactory; 12 | private String interceptorName; 13 | private String targetName; 14 | private Object target; 15 | private ClassLoader proxyClassLoader = ClassUtils.getDefaultClassLoader(); 16 | private Object singletonInstance; 17 | private PointcutAdvisor advisor; 18 | 19 | public ProxyFactoryBean() { 20 | this.aopProxyFactory = new DefaultAopProxyFactory(); 21 | } 22 | 23 | public void setBeanFactory(BeanFactory beanFactory) { 24 | this.beanFactory = beanFactory; 25 | } 26 | 27 | public void setAopProxyFactory(AopProxyFactory aopProxyFactory) { 28 | this.aopProxyFactory = aopProxyFactory; 29 | } 30 | public AopProxyFactory getAopProxyFactory() { 31 | return this.aopProxyFactory; 32 | } 33 | 34 | public void setAdvisor(PointcutAdvisor advisor) { 35 | this.advisor = advisor; 36 | } 37 | 38 | public void setInterceptorName(String interceptorName) { 39 | this.interceptorName = interceptorName; 40 | } 41 | public void setTargetName(String targetName) { 42 | this.targetName = targetName; 43 | } 44 | public Object getTarget() { 45 | return target; 46 | } 47 | public void setTarget(Object target) { 48 | this.target = target; 49 | } 50 | 51 | @Override 52 | public Object getObject() throws Exception { 53 | initializeAdvisor(); 54 | return getSingletonInstance(); 55 | } 56 | 57 | private synchronized void initializeAdvisor() { 58 | Object advice = null; 59 | // MethodInterceptor mi = null; 60 | try { 61 | advice = this.beanFactory.getBean(this.interceptorName); 62 | } catch (BeansException e) { 63 | e.printStackTrace(); 64 | } 65 | this.advisor = (PointcutAdvisor) advice; 66 | // if (advice instanceof BeforeAdvice) { 67 | // mi = new MethodBeforeAdviceInterceptor((MethodBeforeAdvice)advice); 68 | // } 69 | // else if (advice instanceof AfterAdvice){ 70 | // mi = new AfterReturningAdviceInterceptor((AfterReturningAdvice)advice); 71 | // } 72 | // else if (advice instanceof MethodInterceptor) { 73 | // mi = (MethodInterceptor)advice; 74 | // } 75 | 76 | //advisor = new NameMatchMethodPointcutAdvisor((Advice)advice); 77 | //advisor.setMethodInterceptor(mi); 78 | 79 | } 80 | 81 | private synchronized Object getSingletonInstance() { 82 | if (this.singletonInstance == null) { 83 | this.singletonInstance = getProxy(createAopProxy()); 84 | } 85 | return this.singletonInstance; 86 | } 87 | protected AopProxy createAopProxy() { 88 | return getAopProxyFactory().createAopProxy(target,this.advisor); 89 | } 90 | protected Object getProxy(AopProxy aopProxy) { 91 | return aopProxy.getProxy(); 92 | } 93 | 94 | @Override 95 | public Class getObjectType() { 96 | return null; 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/config/BeanDefinition.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory.config; 2 | 3 | import com.minis.beans.PropertyValues; 4 | 5 | public class BeanDefinition { 6 | String SCOPE_SINGLETON = "singleton"; 7 | String SCOPE_PROTOTYPE = "prototype"; 8 | 9 | private boolean lazyInit = true; 10 | private String[] dependsOn; 11 | private ConstructorArgumentValues constructorArgumentValues; 12 | 13 | private PropertyValues propertyValues; 14 | private String initMethodName; 15 | 16 | private volatile Object beanClass; 17 | private String id; 18 | private String className; 19 | private String scope=SCOPE_SINGLETON; 20 | 21 | public String getId() { 22 | return id; 23 | } 24 | public void setId(String id) { 25 | this.id = id; 26 | } 27 | public String getClassName() { 28 | return className; 29 | } 30 | public void setClassName(String className) { 31 | this.className = className; 32 | } 33 | 34 | public BeanDefinition(String id, String className) { 35 | this.id = id; 36 | this.className = className; 37 | } 38 | 39 | public boolean hasBeanClass() { 40 | return (this.beanClass instanceof Class); 41 | } 42 | 43 | public void setBeanClass(Class beanClass) { 44 | this.beanClass = beanClass; 45 | } 46 | 47 | public Class getBeanClass(){ 48 | 49 | return (Class) this.beanClass; 50 | } 51 | 52 | public void setScope(String scope) { 53 | this.scope = scope; 54 | } 55 | 56 | public String getScope() { 57 | return this.scope; 58 | } 59 | 60 | public boolean isSingleton() { 61 | return SCOPE_SINGLETON.equals(scope); 62 | } 63 | 64 | public boolean isPrototype() { 65 | return SCOPE_PROTOTYPE.equals(scope); 66 | } 67 | 68 | public void setLazyInit(boolean lazyInit) { 69 | this.lazyInit = lazyInit; 70 | } 71 | 72 | public boolean isLazyInit() { 73 | return this.lazyInit; 74 | } 75 | 76 | public void setDependsOn(String... dependsOn) { 77 | this.dependsOn = dependsOn; 78 | } 79 | 80 | public String[] getDependsOn() { 81 | return this.dependsOn; 82 | } 83 | 84 | public void setConstructorArgumentValues(ConstructorArgumentValues constructorArgumentValues) { 85 | this.constructorArgumentValues = 86 | (constructorArgumentValues != null ? constructorArgumentValues : new ConstructorArgumentValues()); 87 | } 88 | 89 | public ConstructorArgumentValues getConstructorArgumentValues() { 90 | return this.constructorArgumentValues; 91 | } 92 | 93 | public boolean hasConstructorArgumentValues() { 94 | return !this.constructorArgumentValues.isEmpty(); 95 | } 96 | public void setPropertyValues(PropertyValues propertyValues) { 97 | this.propertyValues = (propertyValues != null ? propertyValues : new PropertyValues()); 98 | } 99 | 100 | public PropertyValues getPropertyValues() { 101 | return this.propertyValues; 102 | } 103 | public void setInitMethodName(String initMethodName) { 104 | this.initMethodName = initMethodName; 105 | } 106 | 107 | public String getInitMethodName() { 108 | return this.initMethodName; 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/com/minis/aop/framework/ProxyFactoryBean.java: -------------------------------------------------------------------------------- 1 | package com.minis.aop.framework; 2 | 3 | import com.minis.aop.Advisor; 4 | import com.minis.aop.PointcutAdvisor; 5 | import com.minis.beans.BeansException; 6 | import com.minis.beans.factory.BeanFactory; 7 | import com.minis.beans.factory.BeanFactoryAware; 8 | import com.minis.beans.factory.FactoryBean; 9 | import com.minis.util.ClassUtils; 10 | 11 | public class ProxyFactoryBean implements FactoryBean,BeanFactoryAware { 12 | private BeanFactory beanFactory; 13 | private AopProxyFactory aopProxyFactory; 14 | private String interceptorName; 15 | private String targetName; 16 | private Object target; 17 | private ClassLoader proxyClassLoader = ClassUtils.getDefaultClassLoader(); 18 | private Object singletonInstance; 19 | private Advisor advisor; 20 | 21 | public ProxyFactoryBean() { 22 | this.aopProxyFactory = new DefaultAopProxyFactory(); 23 | } 24 | 25 | public void setBeanFactory(BeanFactory beanFactory) { 26 | this.beanFactory = beanFactory; 27 | } 28 | 29 | public void setAopProxyFactory(AopProxyFactory aopProxyFactory) { 30 | this.aopProxyFactory = aopProxyFactory; 31 | } 32 | public AopProxyFactory getAopProxyFactory() { 33 | return this.aopProxyFactory; 34 | } 35 | 36 | public void setAdvisor(PointcutAdvisor advisor) { 37 | this.advisor = advisor; 38 | } 39 | 40 | public void setInterceptorName(String interceptorName) { 41 | this.interceptorName = interceptorName; 42 | } 43 | public void setTargetName(String targetName) { 44 | this.targetName = targetName; 45 | } 46 | public Object getTarget() { 47 | return target; 48 | } 49 | public void setTarget(Object target) { 50 | this.target = target; 51 | } 52 | 53 | @Override 54 | public Object getObject() throws Exception { 55 | initializeAdvisor(); 56 | return getSingletonInstance(); 57 | } 58 | 59 | private synchronized void initializeAdvisor() { 60 | Object advice = null; 61 | // MethodInterceptor mi = null; 62 | try { 63 | advice = this.beanFactory.getBean(this.interceptorName); 64 | } catch (BeansException e) { 65 | e.printStackTrace(); 66 | } 67 | this.advisor = (Advisor) advice; 68 | // if (advice instanceof BeforeAdvice) { 69 | // mi = new MethodBeforeAdviceInterceptor((MethodBeforeAdvice)advice); 70 | // } 71 | // else if (advice instanceof AfterAdvice){ 72 | // mi = new AfterReturningAdviceInterceptor((AfterReturningAdvice)advice); 73 | // } 74 | // else if (advice instanceof MethodInterceptor) { 75 | // mi = (MethodInterceptor)advice; 76 | // } 77 | 78 | //advisor = new NameMatchMethodPointcutAdvisor((Advice)advice); 79 | //advisor.setMethodInterceptor(mi); 80 | 81 | } 82 | 83 | private synchronized Object getSingletonInstance() { 84 | if (this.singletonInstance == null) { 85 | this.singletonInstance = getProxy(createAopProxy()); 86 | } 87 | return this.singletonInstance; 88 | } 89 | protected AopProxy createAopProxy() { 90 | return getAopProxyFactory().createAopProxy(target,this.advisor); 91 | } 92 | protected Object getProxy(AopProxy aopProxy) { 93 | return aopProxy.getProxy(); 94 | } 95 | 96 | @Override 97 | public Class getObjectType() { 98 | return null; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/com/minis/jdbc/datasource/SingleConnectionDataSource.java: -------------------------------------------------------------------------------- 1 | package com.minis.jdbc.datasource; 2 | 3 | import java.io.PrintWriter; 4 | import java.sql.Connection; 5 | import java.sql.DriverManager; 6 | import java.sql.SQLException; 7 | import java.sql.SQLFeatureNotSupportedException; 8 | import java.util.Properties; 9 | import java.util.logging.Logger; 10 | 11 | import javax.sql.DataSource; 12 | 13 | public class SingleConnectionDataSource implements DataSource { 14 | private String driverClassName; 15 | private String url; 16 | private String username; 17 | private String password; 18 | private Properties connectionProperties; 19 | private Connection connection; 20 | 21 | public SingleConnectionDataSource() { 22 | } 23 | 24 | public String getUrl() { 25 | return url; 26 | } 27 | 28 | public void setUrl(String url) { 29 | this.url = url; 30 | } 31 | 32 | public String getUsername() { 33 | return username; 34 | } 35 | 36 | public void setUsername(String username) { 37 | this.username = username; 38 | } 39 | 40 | public String getPassword() { 41 | return password; 42 | } 43 | 44 | public void setPassword(String password) { 45 | this.password = password; 46 | } 47 | 48 | 49 | public Properties getConnectionProperties() { 50 | return connectionProperties; 51 | } 52 | 53 | public void setConnectionProperties(Properties connectionProperties) { 54 | this.connectionProperties = connectionProperties; 55 | } 56 | 57 | @Override 58 | public PrintWriter getLogWriter() throws SQLException { 59 | return null; 60 | } 61 | 62 | @Override 63 | public int getLoginTimeout() throws SQLException { 64 | return 0; 65 | } 66 | 67 | @Override 68 | public Logger getParentLogger() throws SQLFeatureNotSupportedException { 69 | return null; 70 | } 71 | 72 | @Override 73 | public void setLogWriter(PrintWriter arg0) throws SQLException { 74 | } 75 | 76 | @Override 77 | public void setLoginTimeout(int arg0) throws SQLException { 78 | } 79 | 80 | @Override 81 | public boolean isWrapperFor(Class arg0) throws SQLException { 82 | return false; 83 | } 84 | 85 | @Override 86 | public T unwrap(Class arg0) throws SQLException { 87 | return null; 88 | } 89 | 90 | public void setDriverClassName(String driverClassName) { 91 | this.driverClassName = driverClassName; 92 | try { 93 | Class.forName(this.driverClassName); 94 | } 95 | catch (ClassNotFoundException ex) { 96 | throw new IllegalStateException("Could not load JDBC driver class [" + driverClassName + "]", ex); 97 | } 98 | } 99 | 100 | @Override 101 | public Connection getConnection() throws SQLException { 102 | return getConnectionFromDriver(getUsername(), getPassword()); 103 | } 104 | 105 | @Override 106 | public Connection getConnection(String username, String password) throws SQLException { 107 | return getConnectionFromDriver(username, password); 108 | } 109 | 110 | protected Connection getConnectionFromDriver(String username, String password) throws SQLException { 111 | Properties mergedProps = new Properties(); 112 | Properties connProps = getConnectionProperties(); 113 | if (connProps != null) { 114 | mergedProps.putAll(connProps); 115 | } 116 | if (username != null) { 117 | mergedProps.setProperty("user", username); 118 | } 119 | if (password != null) { 120 | mergedProps.setProperty("password", password); 121 | } 122 | 123 | this.connection = getConnectionFromDriverManager(getUrl(),mergedProps); 124 | 125 | return this.connection; 126 | } 127 | 128 | protected Connection getConnectionFromDriverManager(String url, Properties props) throws SQLException { 129 | return DriverManager.getConnection(url, props); 130 | } 131 | 132 | 133 | } 134 | -------------------------------------------------------------------------------- /src/com/minis/beans/factory/support/DefaultSingletonBeanRegistry.java: -------------------------------------------------------------------------------- 1 | package com.minis.beans.factory.support; 2 | 3 | import java.util.ArrayList; 4 | import java.util.LinkedHashSet; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.Set; 8 | import java.util.concurrent.ConcurrentHashMap; 9 | 10 | import com.minis.beans.factory.config.SingletonBeanRegistry; 11 | 12 | public class DefaultSingletonBeanRegistry implements SingletonBeanRegistry { 13 | protected List beanNames=new ArrayList<>(); 14 | protected Map singletonObjects =new ConcurrentHashMap<>(256); 15 | protected Map> dependentBeanMap = new ConcurrentHashMap<>(64); 16 | protected Map> dependenciesForBeanMap = new ConcurrentHashMap<>(64); 17 | 18 | @Override 19 | public void registerSingleton(String beanName, Object singletonObject) { 20 | synchronized(this.singletonObjects) { 21 | Object oldObject = this.singletonObjects.get(beanName); 22 | if (oldObject != null) { 23 | throw new IllegalStateException("Could not register object [" + singletonObject + 24 | "] under bean name '" + beanName + "': there is already object [" + oldObject + "] bound"); 25 | } 26 | 27 | this.singletonObjects.put(beanName, singletonObject); 28 | this.beanNames.add(beanName); 29 | System.out.println(" bean registerded............. " + beanName); 30 | } 31 | } 32 | 33 | @Override 34 | public Object getSingleton(String beanName) { 35 | return this.singletonObjects.get(beanName); 36 | } 37 | 38 | @Override 39 | public boolean containsSingleton(String beanName) { 40 | return this.singletonObjects.containsKey(beanName); 41 | } 42 | 43 | @Override 44 | public String[] getSingletonNames() { 45 | return (String[]) this.beanNames.toArray(); 46 | } 47 | 48 | public void removeSingleton(String beanName) { 49 | synchronized (this.singletonObjects) { 50 | this.singletonObjects.remove(beanName); 51 | this.beanNames.remove(beanName); 52 | } 53 | } 54 | 55 | public void registerDependentBean(String beanName, String dependentBeanName) { 56 | Set dependentBeans = this.dependentBeanMap.get(beanName); 57 | if (dependentBeans != null && dependentBeans.contains(dependentBeanName)) { 58 | return; 59 | } 60 | 61 | // No entry yet -> fully synchronized manipulation of the dependentBeans Set 62 | synchronized (this.dependentBeanMap) { 63 | dependentBeans = this.dependentBeanMap.get(beanName); 64 | if (dependentBeans == null) { 65 | dependentBeans = new LinkedHashSet(8); 66 | this.dependentBeanMap.put(beanName, dependentBeans); 67 | } 68 | dependentBeans.add(dependentBeanName); 69 | } 70 | synchronized (this.dependenciesForBeanMap) { 71 | Set dependenciesForBean = this.dependenciesForBeanMap.get(dependentBeanName); 72 | if (dependenciesForBean == null) { 73 | dependenciesForBean = new LinkedHashSet(8); 74 | this.dependenciesForBeanMap.put(dependentBeanName, dependenciesForBean); 75 | } 76 | dependenciesForBean.add(beanName); 77 | } 78 | 79 | } 80 | 81 | public boolean hasDependentBean(String beanName) { 82 | return this.dependentBeanMap.containsKey(beanName); 83 | } 84 | public String[] getDependentBeans(String beanName) { 85 | Set dependentBeans = this.dependentBeanMap.get(beanName); 86 | if (dependentBeans == null) { 87 | return new String[0]; 88 | } 89 | return (String[]) dependentBeans.toArray(); 90 | } 91 | public String[] getDependenciesForBean(String beanName) { 92 | Set dependenciesForBean = this.dependenciesForBeanMap.get(beanName); 93 | if (dependenciesForBean == null) { 94 | return new String[0]; 95 | } 96 | return (String[]) dependenciesForBean.toArray(); 97 | 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/com/test/controller/HelloWorldBean.java: -------------------------------------------------------------------------------- 1 | package com.test.controller; 2 | 3 | import java.io.IOException; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import com.minis.beans.factory.annotation.Autowired; 11 | import com.minis.web.bind.annotation.RequestMapping; 12 | import com.minis.web.bind.annotation.ResponseBody; 13 | import com.minis.web.servlet.ModelAndView; 14 | import com.test.entity.User; 15 | import com.test.service.AService; 16 | import com.test.service.BaseService; 17 | import com.test.service.IAction; 18 | import com.test.service.UserService; 19 | 20 | public class HelloWorldBean { 21 | @Autowired 22 | BaseService baseservice; 23 | 24 | @Autowired 25 | UserService userService; 26 | 27 | 28 | @RequestMapping("/test2") 29 | public void doTest2(HttpServletRequest request, HttpServletResponse response) { 30 | String str = "test 2, hello world!"; 31 | try { 32 | response.getWriter().write(str); 33 | } catch (IOException e) { 34 | // TODO Auto-generated catch block 35 | e.printStackTrace(); 36 | } 37 | } 38 | @RequestMapping("/test5") 39 | public ModelAndView doTest5(User user) { 40 | ModelAndView mav = new ModelAndView("test","msg",user.getName()); 41 | return mav; 42 | } 43 | @RequestMapping("/test6") 44 | public String doTest6(User user) { 45 | return "error"; 46 | } 47 | 48 | @RequestMapping("/test7") 49 | @ResponseBody 50 | public User doTest7(User user) { 51 | user.setName(user.getName() + "---"); 52 | user.setBirthday(new Date()); 53 | return user; 54 | } 55 | 56 | @RequestMapping("/test8") 57 | @ResponseBody 58 | public User doTest8(HttpServletRequest request, HttpServletResponse response) { 59 | int userid = Integer.parseInt(request.getParameter("id")); 60 | User user = userService.getUserInfo(userid); 61 | return user; 62 | } 63 | 64 | @RequestMapping("/test9") 65 | @ResponseBody 66 | public List doTest9(HttpServletRequest request, HttpServletResponse response) { 67 | int userid = Integer.parseInt(request.getParameter("id")); 68 | List users = userService.getUsers(userid); 69 | return users; 70 | } 71 | 72 | @Autowired 73 | IAction action; 74 | 75 | @RequestMapping("/testaop") 76 | public void doTestAop(HttpServletRequest request, HttpServletResponse response) { 77 | System.out.println("testaop, call " + action.getClass()); 78 | action.doAction(); 79 | 80 | String str = "test aop, hello world!"; 81 | try { 82 | response.getWriter().write(str); 83 | } catch (IOException e) { 84 | // TODO Auto-generated catch block 85 | e.printStackTrace(); 86 | } 87 | } 88 | @RequestMapping("/testaop2") 89 | public void doTestAop2(HttpServletRequest request, HttpServletResponse response) { 90 | action.doSomething(); 91 | 92 | String str = "test aop 2, hello world!"; 93 | try { 94 | response.getWriter().write(str); 95 | } catch (IOException e) { 96 | // TODO Auto-generated catch block 97 | e.printStackTrace(); 98 | } 99 | } 100 | 101 | @Autowired 102 | IAction action2; 103 | 104 | @RequestMapping("/testaop3") 105 | public void doTestAop3(HttpServletRequest request, HttpServletResponse response) { 106 | action2.doAction(); 107 | 108 | String str = "test aop 3, hello world!"; 109 | try { 110 | response.getWriter().write(str); 111 | } catch (IOException e) { 112 | // TODO Auto-generated catch block 113 | e.printStackTrace(); 114 | } 115 | } 116 | 117 | @RequestMapping("/testaop4") 118 | public void doTestAop4(HttpServletRequest request, HttpServletResponse response) { 119 | action2.doSomething(); 120 | 121 | String str = "test aop 4, hello world!"; 122 | try { 123 | response.getWriter().write(str); 124 | } catch (IOException e) { 125 | // TODO Auto-generated catch block 126 | e.printStackTrace(); 127 | } 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /src/com/minis/batis/DefaultSqlSessionFactory.java: -------------------------------------------------------------------------------- 1 | package com.minis.batis; 2 | 3 | import java.io.File; 4 | import java.net.URL; 5 | import java.util.ArrayList; 6 | import java.util.HashMap; 7 | import java.util.Iterator; 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | import javax.sql.DataSource; 12 | 13 | import org.dom4j.Document; 14 | import org.dom4j.Element; 15 | import org.dom4j.io.SAXReader; 16 | 17 | import com.minis.beans.factory.annotation.Autowired; 18 | import com.minis.jdbc.core.JdbcTemplate; 19 | 20 | public class DefaultSqlSessionFactory implements SqlSessionFactory{ 21 | @Autowired 22 | JdbcTemplate jdbcTemplate; 23 | 24 | String mapperLocations; 25 | public String getMapperLocations() { 26 | return mapperLocations; 27 | } 28 | public void setMapperLocations(String mapperLocations) { 29 | this.mapperLocations = mapperLocations; 30 | } 31 | 32 | Map mapperNodeMap = new HashMap<>(); 33 | public Map getMapperNodeMap() { 34 | return mapperNodeMap; 35 | } 36 | 37 | // private DataSource dataSource; 38 | // 39 | // public void setDataSource(DataSource dataSource) { 40 | // this.dataSource = dataSource; 41 | // } 42 | // 43 | // public DataSource getDataSource() { 44 | // return this.dataSource; 45 | // } 46 | 47 | public DefaultSqlSessionFactory() { 48 | } 49 | 50 | public void init() { 51 | scanLocation(this.mapperLocations); 52 | for (Map.Entry entry : this.mapperNodeMap.entrySet()) { 53 | System.out.println(entry.getKey() + " : " + entry.getValue()); 54 | } 55 | } 56 | 57 | @Override 58 | public SqlSession openSession() { 59 | SqlSession newSqlSession = new DefaultSqlSession(); 60 | newSqlSession.setJdbcTemplate(jdbcTemplate); 61 | newSqlSession.setSqlSessionFactory(this); 62 | 63 | return newSqlSession; 64 | } 65 | 66 | 67 | private void scanLocation(String location) { 68 | String sLocationPath = this.getClass().getClassLoader().getResource("").getPath()+location; 69 | //URL url =this.getClass().getClassLoader().getResource("/"+location); 70 | System.out.println("mapper location : "+sLocationPath); 71 | File dir = new File(sLocationPath); 72 | for (File file : dir.listFiles()) { 73 | if(file.isDirectory()){ 74 | scanLocation(location+"/"+file.getName()); 75 | }else{ 76 | buildMapperNodes(location+"/"+file.getName()); 77 | } 78 | } 79 | } 80 | 81 | private Map buildMapperNodes(String filePath) { 82 | System.out.println(filePath); 83 | SAXReader saxReader=new SAXReader(); 84 | URL xmlPath=this.getClass().getClassLoader().getResource(filePath); 85 | try { 86 | Document document = saxReader.read(xmlPath); 87 | Element rootElement=document.getRootElement(); 88 | 89 | String namespace = rootElement.attributeValue("namespace"); 90 | 91 | Iterator nodes = rootElement.elementIterator();; 92 | while (nodes.hasNext()) { 93 | Element node = nodes.next(); 94 | String id = node.attributeValue("id"); 95 | String parameterType = node.attributeValue("parameterType"); 96 | String resultType = node.attributeValue("resultType"); 97 | String sql = node.getText(); 98 | 99 | MapperNode selectnode = new MapperNode(); 100 | selectnode.setNamespace(namespace); 101 | selectnode.setId(id); 102 | selectnode.setParameterType(parameterType); 103 | selectnode.setResultType(resultType); 104 | selectnode.setSql(sql); 105 | selectnode.setParameter(""); 106 | 107 | this.mapperNodeMap.put(namespace + "." + id, selectnode); 108 | } 109 | } catch (Exception ex) { 110 | ex.printStackTrace(); 111 | } 112 | return this.mapperNodeMap; 113 | } 114 | 115 | public MapperNode getMapperNode(String name) { 116 | return this.mapperNodeMap.get(name); 117 | } 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/com/minis/web/method/annotation/RequestMappingHandlerMapping.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.method.annotation; 2 | 3 | import java.lang.reflect.Method; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | 7 | import javax.servlet.http.HttpServletRequest; 8 | 9 | import com.minis.beans.BeansException; 10 | import com.minis.context.ApplicationContext; 11 | import com.minis.context.ApplicationContextAware; 12 | import com.minis.util.PatternMatchUtils; 13 | import com.minis.web.bind.annotation.RequestMapping; 14 | import com.minis.web.context.WebApplicationContext; 15 | import com.minis.web.method.HandlerMethod; 16 | import com.minis.web.servlet.HandlerMapping; 17 | 18 | public class RequestMappingHandlerMapping implements HandlerMapping,ApplicationContextAware { 19 | ApplicationContext applicationContext; 20 | private MappingRegistry mappingRegistry = null; 21 | 22 | public RequestMappingHandlerMapping() { 23 | } 24 | 25 | protected void initMappings() { 26 | Class clz = null; 27 | Object obj = null; 28 | String[] controllerNames = this.applicationContext.getBeanDefinitionNames(); 29 | for (String controllerName : controllerNames) { 30 | try { 31 | clz = Class.forName(controllerName); 32 | } catch (ClassNotFoundException e1) { 33 | e1.printStackTrace(); 34 | } 35 | try { 36 | obj = this.applicationContext.getBean(controllerName); 37 | } catch (BeansException e) { 38 | e.printStackTrace(); 39 | } 40 | Method[] methods = clz.getDeclaredMethods(); 41 | if(methods!=null){ 42 | for(Method method : methods){ 43 | boolean isRequestMapping = method.isAnnotationPresent(RequestMapping.class); 44 | if (isRequestMapping){ 45 | String methodName = method.getName(); 46 | String urlmapping = method.getAnnotation(RequestMapping.class).value(); 47 | String requestMethod = method.getAnnotation(RequestMapping.class).method(); 48 | if (requestMethod.equals("")) { 49 | requestMethod="GET"; 50 | } 51 | String qualifiedName = requestMethod + ":" + urlmapping; 52 | 53 | this.mappingRegistry.getUrlMappingNames().add(urlmapping); 54 | this.mappingRegistry.getRequestMethods().add(requestMethod); 55 | this.mappingRegistry.getQualifiedNames().add(qualifiedName); 56 | 57 | this.mappingRegistry.getMappingObjs().put(qualifiedName, obj); 58 | this.mappingRegistry.getMappingMethods().put(qualifiedName, method); 59 | this.mappingRegistry.getMappingMethodNames().put(qualifiedName, methodName); 60 | this.mappingRegistry.getMappingClasses().put(qualifiedName, clz); 61 | 62 | } 63 | } 64 | } 65 | } 66 | } 67 | 68 | 69 | @Override 70 | public HandlerMethod getHandler(HttpServletRequest request) throws Exception { 71 | if (this.mappingRegistry == null) { //to do initialization 72 | this.mappingRegistry = new MappingRegistry(); 73 | initMappings(); 74 | } 75 | 76 | for (int i=0; i clz = this.mappingRegistry.getMappingClasses().get(sPattern); 104 | String methodName = this.mappingRegistry.getMappingMethodNames().get(sPattern); 105 | 106 | HandlerMethod handlerMethod = new HandlerMethod(method, obj, clz, methodName); 107 | 108 | return handlerMethod; 109 | } 110 | 111 | @Override 112 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 113 | this.applicationContext = applicationContext; 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/com/minis/web/method/annotation/RequestMappingHandlerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.method.annotation; 2 | 3 | import java.io.PrintWriter; 4 | import java.lang.reflect.Method; 5 | import java.lang.reflect.Parameter; 6 | import java.util.Map; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | import com.minis.beans.BeansException; 12 | import com.minis.context.ApplicationContext; 13 | import com.minis.context.ApplicationContextAware; 14 | import com.minis.http.converter.HttpMessageConverter; 15 | import com.minis.web.bind.WebDataBinder; 16 | import com.minis.web.bind.annotation.PathVariable; 17 | import com.minis.web.bind.annotation.ResponseBody; 18 | import com.minis.web.bind.support.WebBindingInitializer; 19 | import com.minis.web.bind.support.WebDataBinderFactory; 20 | import com.minis.web.context.WebApplicationContext; 21 | import com.minis.web.method.HandlerMethod; 22 | import com.minis.web.servlet.HandlerAdapter; 23 | import com.minis.web.servlet.ModelAndView; 24 | 25 | public class RequestMappingHandlerAdapter implements HandlerAdapter,ApplicationContextAware { 26 | private ApplicationContext applicationContext= null; 27 | private WebBindingInitializer webBindingInitializer = null; 28 | private HttpMessageConverter messageConverter = null; 29 | 30 | public HttpMessageConverter getMessageConverter() { 31 | return messageConverter; 32 | } 33 | 34 | public void setMessageConverter(HttpMessageConverter messageConverter) { 35 | this.messageConverter = messageConverter; 36 | } 37 | 38 | public RequestMappingHandlerAdapter() { 39 | } 40 | 41 | @Override 42 | public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) 43 | throws Exception { 44 | return handleInternal(request, response, (HandlerMethod) handler); 45 | } 46 | 47 | private ModelAndView handleInternal(HttpServletRequest request, HttpServletResponse response, 48 | HandlerMethod handler) { 49 | ModelAndView mv = null; 50 | 51 | try { 52 | mv = invokeHandlerMethod(request, response, handler); 53 | } catch (Exception e) { 54 | e.printStackTrace(); 55 | } 56 | 57 | return mv; 58 | 59 | } 60 | 61 | protected ModelAndView invokeHandlerMethod(HttpServletRequest request, 62 | HttpServletResponse response, HandlerMethod handlerMethod) throws Exception { 63 | 64 | WebDataBinderFactory binderFactory = new WebDataBinderFactory(); 65 | 66 | Parameter[] methodParameters = handlerMethod.getMethod().getParameters(); 67 | Object[] methodParamObjs = new Object[methodParameters.length]; 68 | 69 | int i = 0; 70 | for (Parameter methodParameter : methodParameters) { 71 | if (methodParameter.getType()==HttpServletRequest.class) { 72 | methodParamObjs[i] = request; 73 | } 74 | else if (methodParameter.getType()==HttpServletResponse.class) { 75 | methodParamObjs[i] = response; 76 | } 77 | else if (methodParameter.isAnnotationPresent(PathVariable.class)) { 78 | String sServletPath = request.getServletPath(); 79 | int index = sServletPath.lastIndexOf("/"); 80 | String sParam = sServletPath.substring(index+1); 81 | if (int.class.isAssignableFrom(methodParameter.getType())) { 82 | methodParamObjs[i] = Integer.parseInt(sParam); 83 | } else if (String.class.isAssignableFrom(methodParameter.getType())) { 84 | methodParamObjs[i] = sParam; 85 | } 86 | } 87 | else if (methodParameter.getType()!=HttpServletRequest.class && methodParameter.getType()!=HttpServletResponse.class) { 88 | Object methodParamObj = methodParameter.getType().newInstance(); 89 | WebDataBinder wdb = binderFactory.createBinder(request, methodParamObj, methodParameter.getName()); 90 | webBindingInitializer.initBinder(wdb); 91 | wdb.bind(request); 92 | methodParamObjs[i] = methodParamObj; 93 | } 94 | 95 | i++; 96 | } 97 | 98 | Method invocableMethod = handlerMethod.getMethod(); 99 | Object returnObj = invocableMethod.invoke(handlerMethod.getBean(), methodParamObjs); 100 | Class returnType = invocableMethod.getReturnType(); 101 | 102 | ModelAndView mav = null; 103 | if (invocableMethod.isAnnotationPresent(ResponseBody.class)){ //ResponseBody 104 | this.messageConverter.write(returnObj, response); 105 | } 106 | else if (returnType == void.class) { 107 | 108 | } 109 | else { 110 | if (returnObj instanceof ModelAndView) { 111 | mav = (ModelAndView)returnObj; 112 | } 113 | else if(returnObj instanceof String) { 114 | String sTarget = (String)returnObj; 115 | mav = new ModelAndView(); 116 | mav.setViewName(sTarget); 117 | } 118 | } 119 | 120 | return mav; 121 | } 122 | 123 | 124 | public WebBindingInitializer getWebBindingInitializer() { 125 | return webBindingInitializer; 126 | } 127 | 128 | public void setWebBindingInitializer(WebBindingInitializer webBindingInitializer) { 129 | this.webBindingInitializer = webBindingInitializer; 130 | } 131 | 132 | @Override 133 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 134 | this.applicationContext = applicationContext; 135 | } 136 | 137 | 138 | } 139 | -------------------------------------------------------------------------------- /src/com/minis/jdbc/pool/PooledDataSource.java: -------------------------------------------------------------------------------- 1 | package com.minis.jdbc.pool; 2 | 3 | import java.io.PrintWriter; 4 | import java.sql.Connection; 5 | import java.sql.DriverManager; 6 | import java.sql.SQLException; 7 | import java.sql.SQLFeatureNotSupportedException; 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | import java.util.Properties; 11 | import java.util.concurrent.TimeUnit; 12 | import java.util.logging.Logger; 13 | 14 | import javax.sql.DataSource; 15 | 16 | public class PooledDataSource implements DataSource{ 17 | private List connections = null; 18 | private String driverClassName; 19 | private String url; 20 | private String username; 21 | private String password; 22 | private int initialSize = 2; 23 | private Properties connectionProperties; 24 | 25 | 26 | public PooledDataSource() { 27 | } 28 | 29 | private void initPool() { 30 | this.connections = new ArrayList<>(initialSize); 31 | try { 32 | for(int i = 0; i < initialSize; i++){ 33 | Connection connect = DriverManager.getConnection(url, username, password); 34 | PooledConnection pooledConnection = new PooledConnection(connect, false); 35 | this.connections.add(pooledConnection); 36 | System.out.println("********add connection pool*********"); 37 | } 38 | } catch (Exception e) { 39 | e.printStackTrace(); 40 | } 41 | } 42 | 43 | @Override 44 | public Connection getConnection() throws SQLException { 45 | return getConnectionFromDriver(getUsername(), getPassword()); 46 | } 47 | 48 | @Override 49 | public Connection getConnection(String username, String password) throws SQLException { 50 | return getConnectionFromDriver(username, password); 51 | } 52 | 53 | protected Connection getConnectionFromDriver(String username, String password) throws SQLException { 54 | Properties mergedProps = new Properties(); 55 | Properties connProps = getConnectionProperties(); 56 | if (connProps != null) { 57 | mergedProps.putAll(connProps); 58 | } 59 | if (username != null) { 60 | mergedProps.setProperty("user", username); 61 | } 62 | if (password != null) { 63 | mergedProps.setProperty("password", password); 64 | } 65 | 66 | if (this.connections == null) { 67 | initPool(); 68 | } 69 | 70 | PooledConnection pooledConnection= getAvailableConnection(); 71 | 72 | while(pooledConnection == null){ 73 | pooledConnection = getAvailableConnection(); 74 | 75 | if(pooledConnection == null){ 76 | try { 77 | TimeUnit.MILLISECONDS.sleep(30); 78 | } catch (InterruptedException e) { 79 | e.printStackTrace(); 80 | } 81 | } 82 | } 83 | 84 | return pooledConnection; 85 | } 86 | 87 | private PooledConnection getAvailableConnection() throws SQLException{ 88 | for(PooledConnection pooledConnection : this.connections){ 89 | if (!pooledConnection.isActive()){ 90 | pooledConnection.setActive(true); 91 | return pooledConnection; 92 | } 93 | } 94 | 95 | return null; 96 | } 97 | 98 | protected Connection getConnectionFromDriverManager(String url, Properties props) throws SQLException { 99 | return DriverManager.getConnection(url, props); 100 | } 101 | 102 | public String getDriverClassName() { 103 | return driverClassName; 104 | } 105 | 106 | public void setDriverClassName(String driverClassName) { 107 | this.driverClassName = driverClassName; 108 | try { 109 | Class.forName(this.driverClassName); 110 | } 111 | catch (ClassNotFoundException ex) { 112 | throw new IllegalStateException("Could not load JDBC driver class [" + driverClassName + "]", ex); 113 | } 114 | 115 | } 116 | 117 | public String getUrl() { 118 | return url; 119 | } 120 | 121 | public void setUrl(String url) { 122 | this.url = url; 123 | } 124 | 125 | public String getUsername() { 126 | return username; 127 | } 128 | 129 | public void setUsername(String username) { 130 | this.username = username; 131 | } 132 | 133 | public String getPassword() { 134 | return password; 135 | } 136 | 137 | public void setPassword(String password) { 138 | this.password = password; 139 | } 140 | 141 | public int getInitialSize() { 142 | return initialSize; 143 | } 144 | 145 | public void setInitialSize(int initialSize) { 146 | this.initialSize = initialSize; 147 | } 148 | 149 | public Properties getConnectionProperties() { 150 | return connectionProperties; 151 | } 152 | public void setConnectionProperties(Properties connectionProperties) { 153 | this.connectionProperties = connectionProperties; 154 | } 155 | 156 | @Override 157 | public PrintWriter getLogWriter() throws SQLException { 158 | return null; 159 | } 160 | 161 | @Override 162 | public int getLoginTimeout() throws SQLException { 163 | return 0; 164 | } 165 | 166 | @Override 167 | public Logger getParentLogger() throws SQLFeatureNotSupportedException { 168 | // TODO Auto-generated method stub 169 | return null; 170 | } 171 | 172 | @Override 173 | public void setLogWriter(PrintWriter arg0) throws SQLException { 174 | 175 | } 176 | 177 | @Override 178 | public void setLoginTimeout(int arg0) throws SQLException { 179 | 180 | } 181 | 182 | @Override 183 | public boolean isWrapperFor(Class arg0) throws SQLException { 184 | return false; 185 | } 186 | 187 | @Override 188 | public T unwrap(Class arg0) throws SQLException { 189 | return null; 190 | } 191 | 192 | 193 | 194 | 195 | } 196 | -------------------------------------------------------------------------------- /src/com/minis/context/ClassPathXmlApplicationContext.java: -------------------------------------------------------------------------------- 1 | package com.minis.context; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import com.minis.beans.BeansException; 8 | import com.minis.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; 9 | import com.minis.beans.factory.config.AbstractAutowireCapableBeanFactory; 10 | import com.minis.beans.factory.config.BeanDefinition; 11 | import com.minis.beans.factory.config.BeanFactoryPostProcessor; 12 | import com.minis.beans.factory.config.BeanPostProcessor; 13 | import com.minis.beans.factory.config.ConfigurableListableBeanFactory; 14 | import com.minis.beans.factory.support.DefaultListableBeanFactory; 15 | import com.minis.beans.factory.xml.XmlBeanDefinitionReader; 16 | import com.minis.core.ClassPathXmlResource; 17 | import com.minis.core.Resource; 18 | import com.minis.core.env.Environment; 19 | 20 | public class ClassPathXmlApplicationContext extends AbstractApplicationContext{ 21 | DefaultListableBeanFactory beanFactory; 22 | private final List beanFactoryPostProcessors = 23 | new ArrayList(); 24 | 25 | public ClassPathXmlApplicationContext(String fileName){ 26 | this(fileName, true); 27 | } 28 | 29 | public ClassPathXmlApplicationContext(String fileName, boolean isRefresh){ 30 | Resource res = new ClassPathXmlResource(fileName); 31 | DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); 32 | XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf); 33 | reader.loadBeanDefinitions(res); 34 | 35 | this.beanFactory = bf; 36 | 37 | if (isRefresh) { 38 | try { 39 | refresh(); 40 | } catch (IllegalStateException e) { 41 | e.printStackTrace(); 42 | } catch (BeansException e) { 43 | e.printStackTrace(); 44 | } 45 | } 46 | } 47 | 48 | @Override 49 | public 50 | void registerListeners() { 51 | String[] bdNames = this.beanFactory.getBeanDefinitionNames(); 52 | for (String bdName : bdNames) { 53 | Object bean = null; 54 | try { 55 | bean = getBean(bdName); 56 | } catch (BeansException e1) { 57 | e1.printStackTrace(); 58 | } 59 | 60 | if (bean instanceof ApplicationListener) { 61 | this.getApplicationEventPublisher().addApplicationListener((ApplicationListener) bean); 62 | } 63 | } 64 | 65 | } 66 | 67 | @Override 68 | public 69 | void initApplicationEventPublisher() { 70 | ApplicationEventPublisher aep = new SimpleApplicationEventPublisher(); 71 | this.setApplicationEventPublisher(aep); 72 | } 73 | 74 | @Override 75 | public 76 | void postProcessBeanFactory(ConfigurableListableBeanFactory bf) { 77 | 78 | String[] bdNames = this.beanFactory.getBeanDefinitionNames(); 79 | for (String bdName : bdNames) { 80 | BeanDefinition bd = this.beanFactory.getBeanDefinition(bdName); 81 | String clzName = bd.getClassName(); 82 | Class clz = null; 83 | try { 84 | clz = Class.forName(clzName); 85 | } catch (ClassNotFoundException e1) { 86 | e1.printStackTrace(); 87 | } 88 | if (BeanFactoryPostProcessor.class.isAssignableFrom(clz)) { 89 | try { 90 | this.beanFactoryPostProcessors.add((BeanFactoryPostProcessor) clz.newInstance()); 91 | } catch (InstantiationException e) { 92 | e.printStackTrace(); 93 | } catch (IllegalAccessException e) { 94 | e.printStackTrace(); 95 | } 96 | } 97 | } 98 | for (BeanFactoryPostProcessor processor : this.beanFactoryPostProcessors) { 99 | try { 100 | processor.postProcessBeanFactory(bf); 101 | } catch (BeansException e) { 102 | // TODO Auto-generated catch block 103 | e.printStackTrace(); 104 | } 105 | } 106 | } 107 | 108 | @Override 109 | public 110 | void registerBeanPostProcessors(ConfigurableListableBeanFactory bf) { 111 | System.out.println("try to registerBeanPostProcessors"); 112 | String[] bdNames = this.beanFactory.getBeanDefinitionNames(); 113 | for (String bdName : bdNames) { 114 | BeanDefinition bd = this.beanFactory.getBeanDefinition(bdName); 115 | String clzName = bd.getClassName(); 116 | Class clz = null; 117 | try { 118 | clz = Class.forName(clzName); 119 | } catch (ClassNotFoundException e1) { 120 | e1.printStackTrace(); 121 | } 122 | if (BeanPostProcessor.class.isAssignableFrom(clz)) { 123 | System.out.println(" registerBeanPostProcessors : " + clzName); 124 | try { 125 | //this.beanFactory.addBeanPostProcessor((BeanPostProcessor) clz.newInstance()); 126 | this.beanFactory.addBeanPostProcessor((BeanPostProcessor)(this.beanFactory.getBean(bdName))); 127 | } catch (BeansException e) { 128 | e.printStackTrace(); 129 | } 130 | } 131 | } 132 | } 133 | 134 | @Override 135 | public 136 | void onRefresh() { 137 | this.beanFactory.refresh(); 138 | } 139 | 140 | @Override 141 | public ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException { 142 | return this.beanFactory; 143 | } 144 | 145 | @Override 146 | public void addApplicationListener(ApplicationListener listener) { 147 | this.getApplicationEventPublisher().addApplicationListener(listener); 148 | 149 | } 150 | 151 | @Override 152 | public 153 | void finishRefresh() { 154 | publishEvent(new ContextRefreshedEvent(this)); 155 | 156 | } 157 | 158 | @Override 159 | public void publishEvent(ApplicationEvent event) { 160 | this.getApplicationEventPublisher().publishEvent(event); 161 | 162 | } 163 | 164 | 165 | } 166 | -------------------------------------------------------------------------------- /src/com/minis/web/servlet/DispatcherServlet.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.servlet; 2 | 3 | 4 | import java.util.Map; 5 | import java.util.Properties; 6 | 7 | import javax.servlet.ServletConfig; 8 | import javax.servlet.ServletException; 9 | import javax.servlet.http.HttpServlet; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import com.minis.beans.BeansException; 14 | import com.minis.web.context.WebApplicationContext; 15 | import com.minis.web.context.support.AnnotationConfigWebApplicationContext; 16 | import com.minis.web.method.HandlerMethod; 17 | import com.minis.web.method.annotation.RequestMappingHandlerMapping; 18 | 19 | /** 20 | * Servlet implementation class DispatcherServlet 21 | */ 22 | public class DispatcherServlet extends HttpServlet { 23 | private static final long serialVersionUID = 1L; 24 | public static final String WEB_APPLICATION_CONTEXT_ATTRIBUTE = DispatcherServlet.class.getName() + ".CONTEXT"; 25 | public static final String HANDLER_MAPPING_BEAN_NAME = "handlerMapping"; 26 | public static final String HANDLER_ADAPTER_BEAN_NAME = "handlerAdapter"; 27 | public static final String MULTIPART_RESOLVER_BEAN_NAME = "multipartResolver"; 28 | public static final String LOCALE_RESOLVER_BEAN_NAME = "localeResolver"; 29 | public static final String HANDLER_EXCEPTION_RESOLVER_BEAN_NAME = "handlerExceptionResolver"; 30 | public static final String REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME = "viewNameTranslator"; 31 | public static final String VIEW_RESOLVER_BEAN_NAME = "viewResolver"; 32 | private static final String DEFAULT_STRATEGIES_PATH = "DispatcherServlet.properties"; 33 | private static final Properties defaultStrategies = null; 34 | 35 | private WebApplicationContext webApplicationContext; 36 | private WebApplicationContext parentApplicationContext; 37 | 38 | private String sContextConfigLocation; 39 | 40 | //private MultipartResolver multipartResolver; 41 | //private LocaleResolver localeResolver; 42 | //private HandlerExceptionResolver handlerExceptionResolvers; 43 | //private RequestToViewNameTranslator viewNameTranslator; 44 | 45 | private HandlerMapping handlerMapping; 46 | private HandlerAdapter handlerAdapter; 47 | private ViewResolver viewResolver; 48 | 49 | public DispatcherServlet() { 50 | super(); 51 | } 52 | 53 | @Override 54 | public void init(ServletConfig config) throws ServletException { 55 | super.init(config); 56 | 57 | this.parentApplicationContext = 58 | (WebApplicationContext) this.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); 59 | 60 | this.sContextConfigLocation = config.getInitParameter("contextConfigLocation"); 61 | 62 | this.webApplicationContext = new AnnotationConfigWebApplicationContext(this.sContextConfigLocation,this.parentApplicationContext); 63 | 64 | Refresh(); 65 | 66 | } 67 | 68 | protected void Refresh() { 69 | initHandlerMappings(this.webApplicationContext); 70 | initHandlerAdapters(this.webApplicationContext); 71 | initViewResolvers(this.webApplicationContext); 72 | } 73 | 74 | protected void initHandlerMappings(WebApplicationContext wac) { 75 | try { 76 | this.handlerMapping = (HandlerMapping) wac.getBean(HANDLER_MAPPING_BEAN_NAME); 77 | } catch (BeansException e) { 78 | e.printStackTrace(); 79 | } 80 | 81 | } 82 | protected void initHandlerAdapters(WebApplicationContext wac) { 83 | try { 84 | this.handlerAdapter = (HandlerAdapter) wac.getBean(HANDLER_ADAPTER_BEAN_NAME); 85 | } catch (BeansException e) { 86 | e.printStackTrace(); 87 | } 88 | 89 | } 90 | protected void initViewResolvers(WebApplicationContext wac) { 91 | try { 92 | this.viewResolver = (ViewResolver) wac.getBean(VIEW_RESOLVER_BEAN_NAME); 93 | } catch (BeansException e) { 94 | e.printStackTrace(); 95 | } 96 | } 97 | 98 | @Override 99 | protected void service(HttpServletRequest request, HttpServletResponse response) { 100 | request.setAttribute(WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.webApplicationContext); 101 | 102 | try { 103 | doDispatch(request, response); 104 | } catch (Exception e) { 105 | e.printStackTrace(); 106 | } 107 | finally { 108 | } 109 | } 110 | 111 | protected void doDispatch(HttpServletRequest request, HttpServletResponse response) throws Exception { 112 | HttpServletRequest processedRequest = request; 113 | HandlerMethod handlerMethod = null; 114 | ModelAndView mv = null; 115 | 116 | handlerMethod = this.handlerMapping.getHandler(processedRequest); 117 | if (handlerMethod == null) { 118 | return; 119 | } 120 | 121 | HandlerAdapter ha = this.handlerAdapter; 122 | 123 | mv = ha.handle(processedRequest, response, handlerMethod); 124 | 125 | render(processedRequest, response, mv); 126 | } 127 | 128 | protected void render( HttpServletRequest request, HttpServletResponse response,ModelAndView mv) throws Exception { 129 | if (mv == null) { 130 | response.getWriter().flush(); 131 | response.getWriter().close(); 132 | return; 133 | } 134 | 135 | String sTarget = mv.getViewName(); 136 | Map modelMap = mv.getModel(); 137 | View view = resolveViewName(sTarget, modelMap, request); 138 | view.render(modelMap, request, response); 139 | 140 | } 141 | 142 | protected View resolveViewName(String viewName, Map model, 143 | HttpServletRequest request) throws Exception { 144 | if (this.viewResolver != null) { 145 | View view = viewResolver.resolveViewName(viewName); 146 | if (view != null) { 147 | return view; 148 | } 149 | } 150 | return null; 151 | } 152 | 153 | 154 | 155 | } 156 | -------------------------------------------------------------------------------- /src/com/minis/scheduling/concurrent/ThreadPoolTaskExecutor.java: -------------------------------------------------------------------------------- 1 | package com.minis.scheduling.concurrent; 2 | 3 | import java.util.concurrent.BlockingQueue; 4 | import java.util.concurrent.Callable; 5 | import java.util.concurrent.Executor; 6 | import java.util.concurrent.ExecutorService; 7 | import java.util.concurrent.Executors; 8 | import java.util.concurrent.Future; 9 | import java.util.concurrent.LinkedBlockingQueue; 10 | import java.util.concurrent.RejectedExecutionException; 11 | import java.util.concurrent.RejectedExecutionHandler; 12 | import java.util.concurrent.SynchronousQueue; 13 | import java.util.concurrent.ThreadFactory; 14 | import java.util.concurrent.ThreadPoolExecutor; 15 | import java.util.concurrent.TimeUnit; 16 | 17 | import com.minis.util.concurrent.ListenableFuture; 18 | import com.minis.util.concurrent.ListenableFutureTask; 19 | 20 | public class ThreadPoolTaskExecutor{ 21 | private final Object poolSizeMonitor = new Object(); 22 | 23 | private int corePoolSize = 1; 24 | private int maxPoolSize = Integer.MAX_VALUE; 25 | private int keepAliveSeconds = 60; 26 | private int queueCapacity = Integer.MAX_VALUE; 27 | private RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.DiscardPolicy(); 28 | 29 | private ThreadPoolExecutor threadPoolExecutor; 30 | 31 | public void setCorePoolSize(int corePoolSize) { 32 | synchronized (this.poolSizeMonitor) { 33 | this.corePoolSize = corePoolSize; 34 | if (this.threadPoolExecutor != null) { 35 | this.threadPoolExecutor.setCorePoolSize(corePoolSize); 36 | } 37 | } 38 | } 39 | 40 | public int getCorePoolSize() { 41 | synchronized (this.poolSizeMonitor) { 42 | return this.corePoolSize; 43 | } 44 | } 45 | 46 | public void setMaxPoolSize(int maxPoolSize) { 47 | synchronized (this.poolSizeMonitor) { 48 | this.maxPoolSize = maxPoolSize; 49 | if (this.threadPoolExecutor != null) { 50 | this.threadPoolExecutor.setMaximumPoolSize(maxPoolSize); 51 | } 52 | } 53 | } 54 | 55 | public int getMaxPoolSize() { 56 | synchronized (this.poolSizeMonitor) { 57 | return this.maxPoolSize; 58 | } 59 | } 60 | 61 | public void setKeepAliveSeconds(int keepAliveSeconds) { 62 | synchronized (this.poolSizeMonitor) { 63 | this.keepAliveSeconds = keepAliveSeconds; 64 | if (this.threadPoolExecutor != null) { 65 | this.threadPoolExecutor.setKeepAliveTime(keepAliveSeconds, TimeUnit.SECONDS); 66 | } 67 | } 68 | } 69 | 70 | public int getKeepAliveSeconds() { 71 | synchronized (this.poolSizeMonitor) { 72 | return this.keepAliveSeconds; 73 | } 74 | } 75 | 76 | public void setQueueCapacity(int queueCapacity) { 77 | this.queueCapacity = queueCapacity; 78 | } 79 | 80 | public ExecutorService initializeExecutor() { 81 | BlockingQueue queue = createQueue(this.queueCapacity); 82 | 83 | ThreadPoolExecutor executor; 84 | executor = new ThreadPoolExecutor( 85 | this.corePoolSize, this.maxPoolSize, this.keepAliveSeconds, TimeUnit.SECONDS, 86 | queue,Executors.defaultThreadFactory(),this.rejectedExecutionHandler); 87 | 88 | this.threadPoolExecutor = executor; 89 | return executor; 90 | } 91 | 92 | protected BlockingQueue createQueue(int queueCapacity) { 93 | if (queueCapacity > 0) { 94 | return new LinkedBlockingQueue<>(queueCapacity); 95 | } 96 | else { 97 | return new SynchronousQueue<>(); 98 | } 99 | } 100 | 101 | public ThreadPoolExecutor getThreadPoolExecutor() throws IllegalStateException { 102 | return this.threadPoolExecutor; 103 | } 104 | 105 | public int getPoolSize() { 106 | if (this.threadPoolExecutor == null) { 107 | return this.corePoolSize; 108 | } 109 | return this.threadPoolExecutor.getPoolSize(); 110 | } 111 | 112 | public int getActiveCount() { 113 | if (this.threadPoolExecutor == null) { 114 | return 0; 115 | } 116 | return this.threadPoolExecutor.getActiveCount(); 117 | } 118 | 119 | 120 | public void execute(Runnable task) { 121 | Executor executor = getThreadPoolExecutor(); 122 | try { 123 | executor.execute(task); 124 | } 125 | catch (RejectedExecutionException ex) { 126 | throw ex; 127 | } 128 | } 129 | 130 | public void execute(Runnable task, long startTimeout) { 131 | execute(task); 132 | } 133 | 134 | public Future submit(Runnable task) { 135 | ExecutorService executor = getThreadPoolExecutor(); 136 | try { 137 | return executor.submit(task); 138 | } 139 | catch (RejectedExecutionException ex) { 140 | throw ex; 141 | } 142 | } 143 | 144 | public Future submit(Callable task) { 145 | ExecutorService executor = getThreadPoolExecutor(); 146 | try { 147 | return executor.submit(task); 148 | } 149 | catch (RejectedExecutionException ex) { 150 | throw ex; 151 | } 152 | } 153 | 154 | public RejectedExecutionHandler getRejectedExecutionHandler() { 155 | return rejectedExecutionHandler; 156 | } 157 | 158 | public void setRejectedExecutionHandler(RejectedExecutionHandler rejectedExecutionHandler) { 159 | this.rejectedExecutionHandler = rejectedExecutionHandler; 160 | } 161 | 162 | public ListenableFuture submitListenable(Runnable task) { 163 | ExecutorService executor = getThreadPoolExecutor(); 164 | try { 165 | ListenableFutureTask future = new ListenableFutureTask<>(task, null); 166 | executor.execute(future); 167 | return future; 168 | } 169 | catch (RejectedExecutionException ex) { 170 | throw ex; 171 | } 172 | } 173 | 174 | public ListenableFuture submitListenable(Callable task) { 175 | ExecutorService executor = getThreadPoolExecutor(); 176 | try { 177 | ListenableFutureTask future = new ListenableFutureTask<>(task); 178 | executor.execute(future); 179 | return future; 180 | } 181 | catch (RejectedExecutionException ex) { 182 | throw ex; 183 | } 184 | } 185 | 186 | } 187 | -------------------------------------------------------------------------------- /src/com/minis/context/AbstractApplicationContext.java: -------------------------------------------------------------------------------- 1 | package com.minis.context; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Map; 6 | import java.util.concurrent.atomic.AtomicBoolean; 7 | 8 | import com.minis.beans.BeansException; 9 | import com.minis.beans.factory.config.BeanFactoryPostProcessor; 10 | import com.minis.beans.factory.config.BeanPostProcessor; 11 | import com.minis.beans.factory.config.ConfigurableListableBeanFactory; 12 | import com.minis.core.env.Environment; 13 | 14 | public abstract class AbstractApplicationContext implements ApplicationContext{ 15 | private Environment environment; 16 | 17 | private final List beanFactoryPostProcessors = new ArrayList<>(); 18 | private long startupDate; 19 | private final AtomicBoolean active = new AtomicBoolean(); 20 | private final AtomicBoolean closed = new AtomicBoolean(); 21 | private ApplicationEventPublisher applicationEventPublisher; 22 | 23 | 24 | 25 | @Override 26 | public Object getBean(String beanName) throws BeansException { 27 | Object returnObj = getBeanFactory().getBean(beanName); 28 | if (returnObj instanceof ApplicationContextAware) { 29 | ((ApplicationContextAware) returnObj).setApplicationContext(this); 30 | } 31 | return returnObj; 32 | 33 | } 34 | 35 | @Override 36 | public boolean containsBean(String name) { 37 | return getBeanFactory().containsBean(name); 38 | } 39 | 40 | // public void registerBean(String beanName, Object obj) { 41 | // getBeanFactory().registerBean(beanName, obj); 42 | // } 43 | 44 | @Override 45 | public boolean isSingleton(String name) { 46 | return getBeanFactory().isSingleton(name); 47 | } 48 | 49 | @Override 50 | public boolean isPrototype(String name) { 51 | return getBeanFactory().isPrototype(name); 52 | } 53 | 54 | @Override 55 | public Class getType(String name) { 56 | return getBeanFactory().getType(name); 57 | } 58 | 59 | public List getBeanFactoryPostProcessors() { 60 | return this.beanFactoryPostProcessors; 61 | } 62 | 63 | 64 | public void refresh() throws BeansException, IllegalStateException { 65 | postProcessBeanFactory(getBeanFactory()); 66 | 67 | registerBeanPostProcessors(getBeanFactory()); 68 | 69 | initApplicationEventPublisher(); 70 | 71 | onRefresh(); 72 | 73 | registerListeners(); 74 | 75 | finishRefresh(); 76 | } 77 | 78 | public abstract void registerListeners(); 79 | public abstract void initApplicationEventPublisher(); 80 | public abstract void postProcessBeanFactory(ConfigurableListableBeanFactory bf); 81 | public abstract void registerBeanPostProcessors(ConfigurableListableBeanFactory bf); 82 | public abstract void onRefresh(); 83 | public abstract void finishRefresh(); 84 | 85 | @Override 86 | public void registerSingleton(String beanName, Object singletonObject) { 87 | getBeanFactory().registerSingleton(beanName, singletonObject); 88 | } 89 | 90 | @Override 91 | public Object getSingleton(String beanName) { 92 | return getBeanFactory().getSingleton(beanName); 93 | } 94 | 95 | @Override 96 | public boolean containsSingleton(String beanName) { 97 | return getBeanFactory().containsSingleton(beanName); 98 | } 99 | 100 | @Override 101 | public String[] getSingletonNames() { 102 | return getBeanFactory().getSingletonNames(); 103 | } 104 | 105 | @Override 106 | public boolean containsBeanDefinition(String beanName) { 107 | return getBeanFactory().containsBeanDefinition(beanName); 108 | } 109 | 110 | @Override 111 | public int getBeanDefinitionCount() { 112 | return getBeanFactory().getBeanDefinitionCount(); 113 | } 114 | 115 | @Override 116 | public String[] getBeanDefinitionNames() { 117 | return getBeanFactory().getBeanDefinitionNames(); 118 | } 119 | 120 | @Override 121 | public String[] getBeanNamesForType(Class type) { 122 | return getBeanFactory().getBeanNamesForType(type); 123 | } 124 | 125 | @Override 126 | public Map getBeansOfType(Class type) throws BeansException { 127 | return getBeanFactory().getBeansOfType(type); 128 | } 129 | 130 | @Override 131 | public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor) { 132 | getBeanFactory().addBeanPostProcessor(beanPostProcessor); 133 | 134 | } 135 | 136 | @Override 137 | public int getBeanPostProcessorCount() { 138 | return getBeanFactory().getBeanPostProcessorCount(); 139 | } 140 | 141 | @Override 142 | public void registerDependentBean(String beanName, String dependentBeanName) { 143 | getBeanFactory().registerDependentBean(beanName, dependentBeanName); 144 | } 145 | 146 | @Override 147 | public String[] getDependentBeans(String beanName) { 148 | return getBeanFactory().getDependentBeans(beanName); 149 | } 150 | 151 | @Override 152 | public String[] getDependenciesForBean(String beanName) { 153 | return getBeanFactory().getDependenciesForBean(beanName); 154 | } 155 | 156 | 157 | @Override 158 | public String getApplicationName() { 159 | return ""; 160 | } 161 | @Override 162 | public long getStartupDate() { 163 | return this.startupDate; 164 | } 165 | @Override 166 | public abstract ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException; 167 | 168 | @Override 169 | public void setEnvironment(Environment environment) { 170 | this.environment = environment; 171 | } 172 | 173 | @Override 174 | public Environment getEnvironment() { 175 | return this.environment; 176 | } 177 | 178 | @Override 179 | public void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor) { 180 | this.beanFactoryPostProcessors.add(postProcessor); 181 | } 182 | 183 | 184 | @Override 185 | public void close() { 186 | } 187 | 188 | @Override 189 | public boolean isActive() { 190 | return true; 191 | } 192 | 193 | public ApplicationEventPublisher getApplicationEventPublisher() { 194 | return applicationEventPublisher; 195 | } 196 | 197 | public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) { 198 | this.applicationEventPublisher = applicationEventPublisher; 199 | } 200 | } 201 | -------------------------------------------------------------------------------- /resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 40 | 41 | 42 | 43 | 44 | 45 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 67 | 68 | 69 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | > 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /src/com/minis/web/context/support/AnnotationConfigWebApplicationContext.java: -------------------------------------------------------------------------------- 1 | package com.minis.web.context.support; 2 | 3 | 4 | import java.io.File; 5 | import java.net.MalformedURLException; 6 | import java.net.URL; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | import javax.servlet.ServletContext; 11 | 12 | import com.minis.aop.framework.autoproxy.BeanNameAutoProxyCreator; 13 | import com.minis.beans.BeansException; 14 | import com.minis.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; 15 | import com.minis.beans.factory.config.BeanDefinition; 16 | import com.minis.beans.factory.config.BeanFactoryPostProcessor; 17 | import com.minis.beans.factory.config.BeanPostProcessor; 18 | import com.minis.beans.factory.config.ConfigurableListableBeanFactory; 19 | import com.minis.beans.factory.support.DefaultListableBeanFactory; 20 | import com.minis.context.AbstractApplicationContext; 21 | import com.minis.context.ApplicationEvent; 22 | import com.minis.context.ApplicationEventPublisher; 23 | import com.minis.context.ApplicationListener; 24 | import com.minis.context.ContextRefreshedEvent; 25 | import com.minis.context.SimpleApplicationEventPublisher; 26 | import com.minis.web.context.WebApplicationContext; 27 | 28 | 29 | 30 | public class AnnotationConfigWebApplicationContext 31 | extends AbstractApplicationContext implements WebApplicationContext{ 32 | private WebApplicationContext parentApplicationContext; 33 | private ServletContext servletContext; 34 | DefaultListableBeanFactory beanFactory; 35 | private final List beanFactoryPostProcessors = 36 | new ArrayList(); 37 | 38 | public AnnotationConfigWebApplicationContext(String fileName) { 39 | this(fileName, null); 40 | } 41 | 42 | public AnnotationConfigWebApplicationContext(String fileName, WebApplicationContext parentApplicationContext) { 43 | this.parentApplicationContext = parentApplicationContext; 44 | this.servletContext = this.parentApplicationContext.getServletContext(); 45 | URL xmlPath = null; 46 | try { 47 | xmlPath = this.getServletContext().getResource(fileName); 48 | } catch (MalformedURLException e) { 49 | e.printStackTrace(); 50 | } 51 | 52 | List packageNames = XmlScanComponentHelper.getNodeValue(xmlPath); 53 | List controllerNames = scanPackages(packageNames); 54 | DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); 55 | this.beanFactory = bf; 56 | this.beanFactory.setParent(this.parentApplicationContext.getBeanFactory()); 57 | loadBeanDefinitions(controllerNames); 58 | 59 | if (true) { 60 | try { 61 | refresh(); 62 | } catch (IllegalStateException e) { 63 | e.printStackTrace(); 64 | } catch (BeansException e) { 65 | e.printStackTrace(); 66 | } 67 | } 68 | 69 | } 70 | 71 | public void loadBeanDefinitions(List controllerNames) { 72 | for (String controller : controllerNames) { 73 | String beanID=controller; 74 | String beanClassName=controller; 75 | 76 | BeanDefinition beanDefinition=new BeanDefinition(beanID,beanClassName); 77 | 78 | this.beanFactory.registerBeanDefinition(beanID,beanDefinition); 79 | } 80 | } 81 | 82 | 83 | private List scanPackages(List packages) { 84 | List tempControllerNames = new ArrayList<>(); 85 | for (String packageName : packages) { 86 | tempControllerNames.addAll(scanPackage(packageName)); 87 | } 88 | return tempControllerNames; 89 | } 90 | 91 | private List scanPackage(String packageName) { 92 | List tempControllerNames = new ArrayList<>(); 93 | URL url =this.getClass().getClassLoader().getResource("/"+packageName.replaceAll("\\.", "/")); 94 | File dir = new File(url.getFile()); 95 | for (File file : dir.listFiles()) { 96 | if(file.isDirectory()){ 97 | scanPackage(packageName+"."+file.getName()); 98 | }else{ 99 | String controllerName = packageName +"." +file.getName().replace(".class", ""); 100 | tempControllerNames.add(controllerName); 101 | } 102 | } 103 | return tempControllerNames; 104 | } 105 | 106 | 107 | public void setParent(WebApplicationContext parentApplicationContext) { 108 | this.parentApplicationContext = parentApplicationContext; 109 | this.beanFactory.setParent(this.parentApplicationContext.getBeanFactory()); 110 | } 111 | 112 | @Override 113 | public ServletContext getServletContext() { 114 | return this.servletContext; 115 | } 116 | 117 | @Override 118 | public void setServletContext(ServletContext servletContext) { 119 | this.servletContext = servletContext; 120 | } 121 | 122 | @Override 123 | public void publishEvent(ApplicationEvent event) { 124 | this.getApplicationEventPublisher().publishEvent(event); 125 | } 126 | 127 | @Override 128 | public void addApplicationListener(ApplicationListener listener) { 129 | this.getApplicationEventPublisher().addApplicationListener(listener); 130 | } 131 | 132 | @Override 133 | public void registerListeners() { 134 | String[] bdNames = this.beanFactory.getBeanDefinitionNames(); 135 | for (String bdName : bdNames) { 136 | Object bean = null; 137 | try { 138 | bean = getBean(bdName); 139 | } catch (BeansException e1) { 140 | e1.printStackTrace(); 141 | } 142 | 143 | if (bean instanceof ApplicationListener) { 144 | this.getApplicationEventPublisher().addApplicationListener((ApplicationListener) bean); 145 | } 146 | } 147 | 148 | } 149 | 150 | @Override 151 | public void initApplicationEventPublisher() { 152 | ApplicationEventPublisher aep = new SimpleApplicationEventPublisher(); 153 | this.setApplicationEventPublisher(aep); 154 | } 155 | 156 | @Override 157 | public void postProcessBeanFactory(ConfigurableListableBeanFactory bf) { 158 | } 159 | 160 | @Override 161 | public void registerBeanPostProcessors(ConfigurableListableBeanFactory bf) { 162 | //this.beanFactory.addBeanPostProcessor(new AutowiredAnnotationBeanPostProcessor()); 163 | // try { 164 | // this.beanFactory.addBeanPostProcessor((BeanPostProcessor)(this.beanFactory.getBean("autoProxyCreator"))); 165 | // } catch (BeansException e) { 166 | // // TODO Auto-generated catch block 167 | // e.printStackTrace(); 168 | // } 169 | try { 170 | this.beanFactory.addBeanPostProcessor((BeanPostProcessor)(this.beanFactory.getBean("autowiredAnnotationBeanPostProcessor"))); 171 | } catch (BeansException e) { 172 | // TODO Auto-generated catch block 173 | e.printStackTrace(); 174 | } 175 | // try { 176 | // this.beanFactory.addBeanPostProcessor((BeanPostProcessor)(this.beanFactory.getBean("logBeanPostProcessor"))); 177 | // } catch (BeansException e) { 178 | // // TODO Auto-generated catch block 179 | // e.printStackTrace(); 180 | // } 181 | 182 | 183 | 184 | 185 | } 186 | 187 | @Override 188 | public void onRefresh() { 189 | this.beanFactory.refresh(); 190 | } 191 | 192 | @Override 193 | public void finishRefresh() { 194 | publishEvent(new ContextRefreshedEvent(this)); 195 | } 196 | 197 | @Override 198 | public ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException { 199 | return this.beanFactory; 200 | } 201 | 202 | } 203 | --------------------------------------------------------------------------------