├── .project ├── 1-hi-utils ├── .classpath ├── .project ├── license.txt ├── pom.xml └── src │ ├── main │ └── java │ │ ├── META-INF │ │ └── MANIFEST.MF │ │ └── com │ │ └── helpinput │ │ ├── core │ │ ├── Consts.java │ │ ├── FileUtils.java │ │ ├── LoggerBase.java │ │ ├── MD5.java │ │ ├── MapConvertor.java │ │ ├── MapFormat.java │ │ ├── PathUtil.java │ │ ├── Utils.java │ │ └── WebPathUtils.java │ │ └── maps │ │ ├── CaseInsensitiveHashMap.java │ │ ├── ConcurrentCaseInsensitiveHashMap.java │ │ ├── ConcurrentHashSet.java │ │ ├── ConcurrentMap.java │ │ ├── MapBackedSet.java │ │ ├── OnceMap.java │ │ ├── RequestValues.java │ │ ├── ResponsValues.java │ │ └── Values.java │ └── test │ └── java │ ├── commons │ ├── PatternTest.java │ ├── ReplaceTest.java │ └── UtilsTest.java │ ├── logback-test.xml │ └── maven │ └── delelastupdate │ └── DelLastUpdated.java ├── 2-hi-spring-dynamic ├── .classpath ├── .project ├── license.txt ├── override │ └── org │ │ ├── hibernate │ │ ├── annotations │ │ │ └── common │ │ │ │ └── util │ │ │ │ └── ReflectHelper.java │ │ └── internal │ │ │ └── util │ │ │ └── ReflectHelper.java │ │ └── springframework │ │ └── core │ │ └── GenericTypeResolver.java ├── pom.xml └── src │ └── main │ └── java │ ├── com │ └── helpinput │ │ ├── annotation │ │ ├── Dynamic.java │ │ ├── Mapping.java │ │ ├── MappingExclude.java │ │ ├── Parent.java │ │ ├── Properties.java │ │ ├── Property.java │ │ ├── Prototype.java │ │ └── TargetType.java │ │ ├── holder │ │ ├── ContextHolder.java │ │ └── SafeHolder.java │ │ ├── propertyeditors │ │ ├── GLClassEditor.java │ │ └── PropertyEditorRegister.java │ │ ├── settings │ │ └── Options.java │ │ └── spring │ │ ├── BeanDefinitionWrap.java │ │ ├── BeanInfo.java │ │ ├── BeanRegister.java │ │ ├── Commons.java │ │ ├── Consts.java │ │ ├── FileReader.java │ │ ├── Interceptor.java │ │ ├── ParserUtils.java │ │ ├── ScanedType.java │ │ ├── SourceFileMonitor.java │ │ ├── SourceScaner.java │ │ ├── proxy │ │ └── OptimizeTransactionProxyFactoryBean.java │ │ ├── refresher │ │ ├── CommonRefresher.java │ │ ├── ContextRefresher.java │ │ ├── SessiontRefresher.java │ │ ├── mvc │ │ │ └── MvcContextRefresher.java │ │ └── web │ │ │ └── WebContextRefresher.java │ │ ├── registinerceptor │ │ ├── AbstractBeanRegistInterceptor.java │ │ ├── BeanRegistInterceptor.java │ │ ├── ProxybeanRegistInterceptor.java │ │ └── mvc │ │ │ └── UrlInterceptorBeanRegistInterceptor.java │ │ ├── servlet │ │ └── mvc │ │ │ └── EnhanceDispachServlet.java │ │ └── support │ │ ├── ClassLoaderHolder.java │ │ └── SourceFileMonitorListener.java │ └── groovy │ └── lang │ └── HiGroovyClassLoader.java ├── 3-hi-spring-Dynamic-mvc-demo ├── .classpath ├── .mymetadata ├── .project ├── WebRoot │ ├── META-INF │ │ └── MANIFEST.MF │ ├── WEB-INF │ │ ├── classes │ │ │ ├── config │ │ │ │ └── spring │ │ │ │ │ ├── spring-beans.xml │ │ │ │ │ ├── spring-common.xml │ │ │ │ │ └── spring-mvc.xml │ │ │ ├── log4j.properties │ │ │ └── logback-test.xml │ │ ├── logback.xml │ │ ├── script │ │ │ └── com │ │ │ │ └── script │ │ │ │ ├── context │ │ │ │ └── refreshers │ │ │ │ │ ├── CommonRefresher.java │ │ │ │ │ ├── MvcContextRefresher.java │ │ │ │ │ └── SessiontRefresher.java │ │ │ │ ├── dao │ │ │ │ ├── TeacherDao.java │ │ │ │ └── TeacherDaoImpl.java │ │ │ │ ├── entity │ │ │ │ └── Teacher.groovy │ │ │ │ ├── interceptor │ │ │ │ └── TeacherIntercepptor.java │ │ │ │ ├── manager │ │ │ │ ├── TeacherManager.java │ │ │ │ └── TeacherManagerImpl.java │ │ │ │ ├── propertyEditors │ │ │ │ └── DatePropertyEditor.java │ │ │ │ ├── settings │ │ │ │ └── IntervalSetting.java │ │ │ │ └── web │ │ │ │ └── TeacherController.java │ │ └── web.xml │ ├── addTeacher.jsp │ ├── addUser.jsp │ ├── editTeacher.jsp │ ├── editUser.jsp │ ├── error.jsp │ ├── index.jsp │ ├── js │ │ └── jquery-1.7.1.js │ ├── login.jsp │ ├── success.jsp │ └── teacherList.jsp ├── license.txt ├── pom.xml ├── spring-dynamic-mvc-demo.sql └── src │ ├── com │ └── tgb │ │ ├── dao │ │ ├── UserDao.java │ │ └── UserDaoImpl.java │ │ ├── entity │ │ └── User.java │ │ ├── interceptor │ │ └── UserIntercepptor.java │ │ ├── manager │ │ ├── UserManager.java │ │ └── UserManagerImpl.java │ │ └── web │ │ └── UserController.java │ ├── config │ └── spring │ │ ├── spring-beans.xml │ │ ├── spring-common.xml │ │ └── spring-mvc.xml │ ├── log4j.properties │ └── logback-test.xml ├── 3-hi-spring-dynamic-mvc-demo-script ├── .classpath ├── .project ├── license.txt ├── pom.xml └── readme.txt ├── README.md ├── license.txt └── pom.xml /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1-hi-parent 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /1-hi-utils/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /1-hi-utils/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1-hi-utils 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.common.project.facet.core.builder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.validation.validationbuilder 20 | 21 | 22 | 23 | 24 | com.genuitec.eclipse.ast.deploy.core.DeploymentBuilder 25 | 26 | 27 | 28 | 29 | com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator 30 | 31 | 32 | 33 | 34 | org.eclipse.m2e.core.maven2Builder 35 | 36 | 37 | 38 | 39 | 40 | org.eclipse.jem.workbench.JavaEMFNature 41 | com.genuitec.eclipse.ast.deploy.core.deploymentnature 42 | org.eclipse.jdt.core.javanature 43 | org.eclipse.m2e.core.maven2Nature 44 | org.eclipse.wst.common.project.facet.core.nature 45 | org.eclipse.wst.common.modulecore.ModuleCoreNature 46 | 47 | 48 | -------------------------------------------------------------------------------- /1-hi-utils/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | com.helpinput.hi 7 | helpinput-parent 8 | 1.2.4 9 | 10 | helpinput-utils 11 | 12 | 13 | 14 | 15 | commons-lang 16 | commons-lang 17 | 2.6 18 | 19 | 20 | 21 | org.json 22 | json 23 | 20090211 24 | 25 | 26 | 27 | com.alibaba 28 | fastjson 29 | 1.1.27 30 | 31 | 32 | 33 | net.sourceforge.cpdetector 34 | cpdetector 35 | 1.0.7 36 | 37 | 38 | 39 | commons-beanutils 40 | commons-beanutils 41 | 1.8.3 42 | 43 | 44 | 45 | org.slf4j 46 | slf4j-api 47 | 1.7.5 48 | provided 49 | 50 | 51 | commons-io 52 | commons-io 53 | 2.4 54 | 55 | 56 | 57 | junit 58 | junit 59 | 4.11 60 | test 61 | 62 | 63 | 64 | 65 | 66 | 67 | org.apache.maven.plugins 68 | maven-compiler-plugin 69 | 2.5 70 | 71 | 1.8 72 | 1.8 73 | 74 | 75 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /1-hi-utils/src/main/java/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /1-hi-utils/src/main/java/com/helpinput/core/Consts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-10 21 | */ 22 | package com.helpinput.core; 23 | 24 | public class Consts{ 25 | public static final String ONCE = "once"; 26 | 27 | public static final String WEB_INF = "WEB-INF"; 28 | 29 | public static final String META_INF = "META-INF"; 30 | 31 | public static final String WEB_INF_CLASSES = "WEB-INF/classes"; 32 | 33 | public static final String RESOURCES = "resources"; 34 | 35 | public static final String CONTEXT_PARAM_SECURITY_KEY = "SECURITY_KEY"; 36 | 37 | public static final String DEDUALT_SECURITY_KEY = "1234567890123456"; 38 | 39 | public static final String EL_MAP_VALUES = ".values."; 40 | 41 | public static final String EL_FIELDNAME_SUFFIX = "}"; 42 | 43 | public static final String BRACE_L = "{"; 44 | 45 | public static final String BRACE_R = "{"; 46 | 47 | public static final String EL_PREFIX = "#{"; 48 | 49 | public static final String EL_SUFFIX = "}"; 50 | 51 | public static final String ISO_8859_1 = "ISO-8859-1"; 52 | 53 | public static final String UTF_8 = "UTF-8"; 54 | 55 | public static final String MONGODB_ID = "_id"; 56 | 57 | public static final String JDBC_NAME_L = "`"; 58 | 59 | public static final String JDBC_NAME_R ="`"; 60 | 61 | public static final String SPACE = " "; 62 | 63 | public static final String ALL_FIELD = "*"; 64 | 65 | public static final String JDBC_SPLIT = ","; 66 | 67 | public static final String JDBC_QUERY = "?"; 68 | 69 | public static final String JDBC_SELECT = "SELECT"; 70 | 71 | public static final String JDBC_INSERT = "INSERT INTO"; 72 | 73 | public static final String JDBC_UPDATE = "UPDATE"; 74 | 75 | public static final String JDBC_DELETE = "DELETE"; 76 | 77 | public static final String JDBC_WHERE = "WHERE"; 78 | 79 | public static final String JDBC_LIMIT = "LIMIT"; 80 | 81 | public static final String JDBC_SKIP = "SKIP"; 82 | 83 | public static final String JDBC_OFFSET = "OFFSET"; 84 | 85 | public static final String JDBC_ORDER_BY = "ORDER BY"; 86 | 87 | public static final String JDBC_VALUES = "VALUES"; 88 | 89 | public static final String JDBC_SET = "SET"; 90 | 91 | public static final String JDBC_FROM = "FROM"; 92 | 93 | public static final String JDBC_EQU = "="; 94 | 95 | public static final String JDBC_AND = "AND"; 96 | 97 | public static final String JDBC_AS = "AS"; 98 | 99 | public static final String JDBC_OR = "OR"; 100 | 101 | public static final String JDBC_BR_L = "("; 102 | 103 | public static final String JDBC_BR_R = ")"; 104 | 105 | public static final String JDBC_COUNT = "COUNT(*)"; 106 | 107 | public static final String JDBC_COUNT_SIMPLE = "COUNT"; 108 | 109 | public static final String JDBC_GROUPBY = "GROUP BY"; 110 | 111 | public static final String JDBC_LEFT_JOIN = "LEFT JOIN"; 112 | 113 | public static final String JDBC_ON = "ON"; 114 | 115 | public static final String FIELDS = "fields"; 116 | 117 | public static final String VALUES_SELECTED = "_valuesSelected_"; 118 | 119 | public static final String VALIDATORBUNDLE = "_validatorBundle"; 120 | 121 | public static final String TABLENAME = "tableName"; 122 | 123 | public static final String TABLENAME_ = "tableName_"; 124 | 125 | public static final String BEANNAME_ = "beanName_"; 126 | 127 | public static final String APP_SCOPE = "appScope"; 128 | 129 | public static final String COLON = ":"; 130 | 131 | public static final String DOT = "."; 132 | 133 | public static final String SLASH = "/"; 134 | 135 | public static final String DOUBLE_QUOTATION="\""; 136 | 137 | public static final String UPDATE_NOT_UNIQUE = "_updateNotUnique_"; 138 | 139 | public static final String SUB = "sub"; 140 | 141 | public static final String ROLE_ROLE = "role"; 142 | 143 | public static final String ROLE_ROLE_FIELD = "roles"; 144 | 145 | public static final String ROLE_FAIL_URL = "failUrl"; 146 | 147 | public static final String ROLE_URL = "role_url"; 148 | 149 | public static final String ROLE_URL_FIELD = "url"; 150 | 151 | public static final String ROLE_NAME = "roleName"; 152 | 153 | public static final String NODE_ROOT = "┣"; 154 | 155 | public static final String NODE_LINDE = "━"; 156 | 157 | public static final String ROLE_ACCESS = "access"; 158 | 159 | public static final String FACES_REDIRECT = "?faces-redirect=true"; 160 | 161 | public static final String VIEW = "view"; 162 | 163 | public static final String XHTML_EXT_NAME = ".xhtml"; 164 | 165 | public static final String SUB_LINE ="_"; 166 | 167 | } 168 | -------------------------------------------------------------------------------- /1-hi-utils/src/main/java/com/helpinput/core/FileUtils.java: -------------------------------------------------------------------------------- 1 | /* Copyright 2013-2015 the original author or authors. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with 4 | * the License. You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on 9 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the 10 | * specific language governing permissions and limitations under the License. */ 11 | 12 | /** @Author: niaoge(Zhengsheng Xia) 13 | * @Email 78493244@qq.com 14 | * @Date: 2015-6-10 */ 15 | package com.helpinput.core; 16 | 17 | import info.monitorenter.cpdetector.io.ASCIIDetector; 18 | import info.monitorenter.cpdetector.io.CodepageDetectorProxy; 19 | import info.monitorenter.cpdetector.io.JChardetFacade; 20 | import info.monitorenter.cpdetector.io.ParsingDetector; 21 | import info.monitorenter.cpdetector.io.UnicodeDetector; 22 | 23 | import java.io.BufferedReader; 24 | import java.io.Closeable; 25 | import java.io.File; 26 | import java.io.FileInputStream; 27 | import java.io.FileNotFoundException; 28 | import java.io.IOException; 29 | import java.io.InputStreamReader; 30 | import java.io.UnsupportedEncodingException; 31 | 32 | public class FileUtils { 33 | 34 | /** 利用第三方开源包cpdetector获取文件编码格式 35 | * 36 | * @param path 37 | * 要判断文件编码格式的源文件的路径 38 | * @author huanglei 39 | * @version 2012-7-12 14:05 */ 40 | public static String getFileEncode(File f) { 41 | /* 42 | * detector是探测器,它把探测任务交给具体的探测实现类的实例完成。 43 | * cpDetector内置了一些常用的探测实现类,这些探测实现类的实例可以通过add方法 加进来,如ParsingDetector、 44 | * JChardetFacade、ASCIIDetector、UnicodeDetector。 45 | * detector按照“谁最先返回非空的探测结果,就以该结果为准”的原则返回探测到的 46 | * 字符集编码。使用需要用到三个第三方JAR包:antlr.jar、chardet.jar和cpdetector.jar 47 | * cpDetector是基于统计学原理的,不保证完全正确。 48 | */ 49 | CodepageDetectorProxy detector = CodepageDetectorProxy.getInstance(); 50 | /* 51 | * ParsingDetector可用于检查HTML、XML等文件或字符流的编码,构造方法中的参数用于 52 | * 指示是否显示探测过程的详细信息,为false不显示。 53 | */ 54 | detector.add(new ParsingDetector(false)); 55 | /* 56 | * JChardetFacade封装了由Mozilla组织提供的JChardet,它可以完成大多数文件的编码 57 | * 测定。所以,一般有了这个探测器就可满足大多数项目的要求,如果你还不放心,可以 58 | * 再多加几个探测器,比如下面的ASCIIDetector、UnicodeDetector等。 59 | */ 60 | detector.add(JChardetFacade.getInstance());// 用到antlr.jar、chardet.jar 61 | // ASCIIDetector用于ASCII编码测定 62 | detector.add(ASCIIDetector.getInstance()); 63 | // UnicodeDetector用于Unicode家族编码的测定 64 | detector.add(UnicodeDetector.getInstance()); 65 | java.nio.charset.Charset charset = null; 66 | try { 67 | charset = detector.detectCodepage(f.toURI().toURL()); 68 | } 69 | catch (Exception ex) { 70 | ex.printStackTrace(); 71 | } 72 | if (charset != null) 73 | return charset.name(); 74 | else 75 | return null; 76 | } 77 | 78 | public static String getFileEncode(String path) { 79 | return getFileEncode(new File(path)); 80 | } 81 | 82 | public static BufferedReader getFileBufferedReader(String path) throws UnsupportedEncodingException, 83 | FileNotFoundException { 84 | String charsetName = getFileEncode(path); 85 | BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path), charsetName)); 86 | return reader; 87 | } 88 | 89 | public static void closeWithWarning(Closeable c) { 90 | if (c != null) { 91 | try { 92 | c.close(); 93 | } 94 | catch (IOException e) { 95 | //LOG.warning("Caught exception during close(): " + e); 96 | } 97 | } 98 | } 99 | 100 | public static String getReaderText(BufferedReader reader) throws IOException { 101 | StringBuilder answer = new StringBuilder(); 102 | // reading the content of the file within a char buffer 103 | // allow to keep the correct line endings 104 | char[] charBuffer = new char[8192]; 105 | int nbCharRead /* = 0 */; 106 | try { 107 | reader.read(charBuffer); 108 | 109 | while ((nbCharRead = reader.read(charBuffer)) != -1) { 110 | // appends buffer 111 | answer.append(charBuffer, 0, nbCharRead); 112 | } 113 | } 114 | finally { 115 | closeWithWarning(reader); 116 | reader = null; 117 | } 118 | return answer.toString(); 119 | } 120 | 121 | public static String getfileText(String path) throws IOException { 122 | BufferedReader reader = getFileBufferedReader(path); 123 | return getReaderText(reader); 124 | } 125 | 126 | public static String getFileExtension(File file) { 127 | String fileName = file.getName(); 128 | int lastIdx = fileName.lastIndexOf("."); 129 | if (lastIdx != -1 && lastIdx != 0) { 130 | return fileName.substring(lastIdx + 1); 131 | } 132 | else { 133 | return ""; 134 | } 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /1-hi-utils/src/main/java/com/helpinput/core/LoggerBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-10 21 | */ 22 | package com.helpinput.core; 23 | 24 | 25 | import org.slf4j.Logger; 26 | import org.slf4j.LoggerFactory; 27 | 28 | 29 | public class LoggerBase { 30 | public static final Logger logger =LoggerFactory.getLogger(LoggerBase.class); 31 | } 32 | -------------------------------------------------------------------------------- /1-hi-utils/src/main/java/com/helpinput/core/MD5.java: -------------------------------------------------------------------------------- 1 | package com.helpinput.core; 2 | 3 | import java.security.*; 4 | 5 | public class MD5 { 6 | public final static String encode(String s) { 7 | if(s==null){ 8 | return null; 9 | } 10 | char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 11 | 'a', 'b', 'c', 'd', 'e', 'f' }; 12 | try { 13 | byte[] strTemp = s.getBytes(); 14 | MessageDigest mdTemp = MessageDigest.getInstance("MD5"); 15 | mdTemp.update(strTemp); 16 | byte[] md = mdTemp.digest(); 17 | int j = md.length; 18 | char str[] = new char[j * 2]; 19 | int k = 0; 20 | for (int i = 0; i < j; i++) { 21 | byte byte0 = md[i]; 22 | str[k++] = hexDigits[byte0 >>> 4 & 0xf]; 23 | str[k++] = hexDigits[byte0 & 0xf]; 24 | } 25 | return new String(str); 26 | } catch (Exception e) { 27 | return null; 28 | } 29 | } 30 | 31 | public static void main(String[] args) { 32 | System.out.println(encode("jhkj")); 33 | } 34 | } -------------------------------------------------------------------------------- /1-hi-utils/src/main/java/com/helpinput/core/MapConvertor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-10 21 | */ 22 | package com.helpinput.core; 23 | 24 | import java.lang.reflect.Method; 25 | import java.text.ParseException; 26 | import java.util.HashMap; 27 | import java.util.Iterator; 28 | import java.util.Map; 29 | 30 | import org.json.JSONException; 31 | import org.json.JSONObject; 32 | 33 | /** 34 | * 转换器 1:将JavaBean 转换成Map、JSONObject 2:将JSONObject 转换成Map 35 | * 36 | */ 37 | public class MapConvertor { 38 | /** 39 | * 将javaBean转换成Map 40 | * 41 | * @param javaBean 42 | * javaBean 43 | * @return Map对象 44 | */ 45 | public static Map toMap(Object javaBean) { 46 | Map result = new HashMap(); 47 | Method[] methods = javaBean.getClass().getDeclaredMethods(); 48 | 49 | for (Method method : methods) { 50 | try { 51 | if (method.getName().startsWith("get")) { 52 | String field = method.getName(); 53 | field = field.substring(field.indexOf("get") + 3); 54 | field = field.toLowerCase().charAt(0) + field.substring(1); 55 | 56 | Object value = method.invoke(javaBean, (Object[]) null); 57 | result.put(field, null == value ? "" : value.toString()); 58 | } 59 | } 60 | catch (Exception e) { 61 | } 62 | } 63 | 64 | return result; 65 | } 66 | 67 | /** 68 | * 将json对象转换成Map 69 | * 70 | * @param jsonObject 71 | * json对象 72 | * @return Map对象 73 | * @throws JSONException 74 | */ 75 | public static Map toMap(JSONObject jsonObject) throws JSONException { 76 | Map result = new HashMap(); 77 | @SuppressWarnings("unchecked") 78 | Iterator iterator = jsonObject.keys(); 79 | String key = null; 80 | String value = null; 81 | while (iterator.hasNext()) { 82 | key = iterator.next(); 83 | value = jsonObject.getString(key); 84 | result.put(key, value); 85 | } 86 | return result; 87 | } 88 | 89 | /** 90 | * 将javaBean转换成JSONObject 91 | * 92 | * @param bean 93 | * javaBean 94 | * @return json对象 95 | */ 96 | public static JSONObject toJSON(Object bean) { 97 | return new JSONObject(toMap(bean)); 98 | } 99 | 100 | public static String methodNameGetFieldName(String methodName) { 101 | StringBuffer sb = new StringBuffer(); 102 | sb.append(Character.toLowerCase(methodName.charAt(3))); 103 | sb.append(methodName.substring(4)); 104 | return sb.toString(); 105 | } 106 | 107 | /** 108 | * 将map转换成Javabean 109 | * 110 | * @param javabean 111 | * javaBean 112 | * @param values 113 | * map数据 114 | */ 115 | public static Object toJavaBean(Object javabean, Map data) { 116 | Method[] methods = javabean.getClass().getDeclaredMethods(); 117 | for (Method method : methods) { 118 | try { 119 | if (method.getName().startsWith("set")) { 120 | Class[] parmaTypes = method.getParameterTypes(); 121 | if (parmaTypes.length == 1) { 122 | String fieldName = methodNameGetFieldName(method.getName()); 123 | Object value = Utils.convert(data.get(fieldName), parmaTypes[0]); 124 | method.invoke(javabean, value); 125 | // String field = method.getName(); 126 | // field = field.substring(field.indexOf("set") + 3); 127 | // field = field.toLowerCase().charAt(0) + field.substring(1); 128 | // method.invoke(javabean, new Object[] { data.get(field) }); 129 | } 130 | } 131 | } 132 | catch (Exception e) { 133 | } 134 | } 135 | return javabean; 136 | } 137 | 138 | public static Object toJavaBeanNotClean(Object javabean, Map data) { 139 | Method[] methods = javabean.getClass().getDeclaredMethods(); 140 | for (Method method : methods) { 141 | try { 142 | if (method.getName().startsWith("set")) { 143 | String fieldName = methodNameGetFieldName(method.getName()); 144 | Object object = data.get(fieldName); 145 | if (object != null) 146 | method.invoke(javabean, object); 147 | // String field = method.getName(); 148 | // field = field.substring(field.indexOf("set") + 3); 149 | // field = field.toLowerCase().charAt(0) + field.substring(1); 150 | // method.invoke(javabean, new Object[] { data.get(field) }); 151 | } 152 | } 153 | catch (Exception e) { 154 | } 155 | } 156 | return javabean; 157 | } 158 | 159 | public static boolean checkHasFieldName(Object javabean, String fieldName) { 160 | Method[] methods = javabean.getClass().getDeclaredMethods(); 161 | for (Method method : methods) { 162 | try { 163 | if (method.getName().startsWith("set")) { 164 | String scanedFieldName = methodNameGetFieldName(method.getName()); 165 | if (scanedFieldName.equals(fieldName)) 166 | return true; 167 | } 168 | } 169 | catch (Exception e) { 170 | } 171 | } 172 | return false; 173 | } 174 | 175 | /** 176 | * 将javaBean转换成JSONObject 177 | * 178 | * @param bean 179 | * javaBean 180 | * @return json对象 181 | * @throws ParseException 182 | * json解析异常 183 | * @throws JSONException 184 | */ 185 | public static void toJavaBean(Object javabean, String data) throws ParseException, JSONException { 186 | JSONObject jsonObject = new JSONObject(data); 187 | Map datas = toMap(jsonObject); 188 | toJavaBean(javabean, datas); 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /1-hi-utils/src/main/java/com/helpinput/core/PathUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-10 21 | */ 22 | package com.helpinput.core; 23 | 24 | import java.util.ArrayList ; 25 | import java.util.List; 26 | 27 | import org.apache.commons.lang.StringUtils; 28 | 29 | import static com.helpinput.core.LoggerBase.logger; 30 | 31 | 32 | /** 33 | * 类 名: PathUtils 描 述: 对于路径问题处理的工具类 作 者: Vv 创 建: 2012-11-29 版 本: 34 | * 历 史: (版本) 作者 时间 注释 35 | */ 36 | public class PathUtil { 37 | public static final String PATH_OLD_SPLIT = "\\\\"; 38 | public static final String PATH_OTHER_SPLIT = "//"; 39 | public static final String PATH_SPLIT = "/"; 40 | public static final String UPPER_PATH = ".."; 41 | public static final String PATH_HTML = "http://"; 42 | 43 | /** 44 | * 45 | * 描 述:追加目录 作 者:Vv 历 史: (版本) 作者 时间 注释 46 | * 47 | * @param parentPath 48 | * 上级目录 如:D:/AA 49 | * @param subPath 50 | * 子目录 如:BB 51 | * @return 以目录名结尾 如: D:/AA/BB 52 | */ 53 | public static String appendPath(String parentPath, String subPath) { 54 | 55 | if (StringUtils.isNotBlank(parentPath) && !parentPath.endsWith(PATH_SPLIT)) { 56 | parentPath += PATH_SPLIT; 57 | } 58 | if (StringUtils.isNotBlank(subPath)) { 59 | parentPath = parentPath + subPath; 60 | } 61 | 62 | return processPath(parentPath); 63 | } 64 | 65 | /** 66 | * 67 | * 描 述:根据当前路径获取目标路径的相对路径(传入参数为绝对路径) 算法: 1.将路径分割为文件名的数组 68 | * 2.循环当前目录(currentPath)的文件名数组,分别与目标路径(targetPath)的文件数组里的同一位置(索引值i相同)比较 69 | * 2a.如果同一索引值对应的文件夹名相同,则表示存在相对路径,循环继续(continue),直到一索引值对应的文件夹名不相同时,跳出循环 70 | * 2b.如果两个路径的起始部分不一致,则表示不存在相对路径,返回目标路径 3.根据2中循环结束时的索引值,获取相对路径文件名的集合并组成String 71 | * 作 者:Vv 历 史: (版本) 作者 时间 注释 72 | * 73 | * @param currentPath 74 | * @param targetPath 75 | * @return 存在相对路径,则返回相对路径;否则,返回目标路径 76 | * @throws ProcessPathException 77 | */ 78 | public static String getRelativePath(String currentPath, String targetPath) { 79 | if (StringUtils.isBlank(currentPath) || StringUtils.isBlank(targetPath)) { 80 | logger.error("The currentPath or targetPath parameter is required and can't be null or blank."); 81 | return currentPath; 82 | } 83 | currentPath = processPath(currentPath); 84 | targetPath = processPath(targetPath); 85 | 86 | String[] cpNames = currentPath.split(PATH_SPLIT); 87 | String[] tpNames = targetPath.split(PATH_SPLIT); 88 | 89 | List rpNames = new ArrayList(); 90 | 91 | /** 92 | * 2.循环当前目录(currentPath)的文件名数组,分别与目标路径(targetPath)的文件数组里的同一位置(索引值i相同)比较 93 | * 2a.如果同一索引值对应的文件夹名相同,则表示存在相对路径,循环继续(continue),直到一索引值对应的文件夹名不相同时,跳出循环 94 | * 2b.如果两个路径的起始部分不一致,则表示不存在相对路径,返回目标路径 95 | */ 96 | int i = 0; 97 | for (i = 0; i < cpNames.length; i++) { 98 | if (i > tpNames.length - 1) 99 | break; 100 | 101 | if (cpNames[i].equals(tpNames[i])) { 102 | continue; 103 | } 104 | else if (i == 0) {// 如果currentPath与targetPath的起始目录不相同,则说明不存在相对路径 105 | break; 106 | } 107 | else { 108 | rpNames.add(UPPER_PATH); 109 | break; 110 | } 111 | } 112 | 113 | /** 114 | * 3.根据2中循环结束时的索引值 "i",获取相对路径文件名的集合并组成String 115 | */ 116 | for (int j = i; j < tpNames.length; j++) { 117 | rpNames.add(tpNames[j]); 118 | } 119 | 120 | String relativePath = ""; 121 | for (String rp : rpNames) { 122 | relativePath = relativePath + rp + PATH_SPLIT; 123 | } 124 | 125 | return processPath(relativePath); 126 | } 127 | 128 | /** 129 | * 描 述:处理路径问题 如:传入 ///localhost//uuzz/admin/main.action; 返回 130 | * /localhost/uuzz/admin/main.action 作 者:Vv 历 史: (版本) 作者 时间 注释 131 | * 132 | * @param path 133 | * @return 134 | */ 135 | public static String processPath(String path) { 136 | path = path.replaceAll(PATH_OLD_SPLIT, PATH_SPLIT); 137 | if (path.endsWith(PATH_SPLIT)) { 138 | path = path.substring(0, path.length() - 1); 139 | } 140 | 141 | boolean isHttp = false; 142 | if (path.startsWith(PATH_HTML)) { 143 | isHttp = true; 144 | path = path.substring(PATH_HTML.length()); 145 | } 146 | 147 | // 循环处理,将"//"替换为"/" 148 | while (path.contains(PATH_OTHER_SPLIT)) { 149 | path = path.replaceAll(PATH_OTHER_SPLIT, PATH_SPLIT); 150 | } 151 | 152 | if (isHttp) { 153 | path = PATH_HTML + path; 154 | } 155 | 156 | return path; 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /1-hi-utils/src/main/java/com/helpinput/core/WebPathUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-10 21 | */ 22 | package com.helpinput.core; 23 | 24 | import static com.helpinput.core.Consts.*; 25 | 26 | 27 | public class WebPathUtils { 28 | public static final String classpath; 29 | public static final String webInfPath; 30 | public static final String webRoot; 31 | static { 32 | classpath = Thread.currentThread().getContextClassLoader().getResource("").getPath(); 33 | String dest = classpath; 34 | if (dest.indexOf(WEB_INF) > 0) { 35 | dest = dest.substring(0, dest.indexOf(WEB_INF) + 8); 36 | } 37 | webInfPath = dest; 38 | 39 | dest = classpath; 40 | if (dest.indexOf(WEB_INF) > 0) { 41 | dest = dest.substring(0, dest.indexOf(WEB_INF_CLASSES)); 42 | } 43 | webRoot = dest; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /1-hi-utils/src/main/java/com/helpinput/maps/CaseInsensitiveHashMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-10 21 | */ 22 | 23 | 24 | package com.helpinput.maps; 25 | 26 | import java.util.HashMap; 27 | import java.util.LinkedHashMap; 28 | import java.util.Locale; 29 | import java.util.Map; 30 | 31 | 32 | public class CaseInsensitiveHashMap extends LinkedHashMap { 33 | 34 | private static final long serialVersionUID = 1L; 35 | 36 | 37 | private final Map caseInsensitiveKeys; 38 | 39 | private final Locale locale; 40 | 41 | 42 | 43 | public CaseInsensitiveHashMap() { 44 | this(null); 45 | } 46 | 47 | 48 | public CaseInsensitiveHashMap(Locale locale) { 49 | super(); 50 | this.caseInsensitiveKeys = new HashMap(); 51 | this.locale = (locale != null ? locale : Locale.getDefault()); 52 | } 53 | 54 | 55 | public CaseInsensitiveHashMap(int initialCapacity) { 56 | this(initialCapacity, null); 57 | } 58 | 59 | public CaseInsensitiveHashMap(int initialCapacity, Locale locale) { 60 | super(initialCapacity); 61 | this.caseInsensitiveKeys = new HashMap(initialCapacity); 62 | this.locale = (locale != null ? locale : Locale.getDefault()); 63 | } 64 | 65 | 66 | 67 | @Override 68 | public V put(String key, V value) { 69 | String oldKey = this.caseInsensitiveKeys.put(convertKey(key), key); 70 | if (oldKey != null && !oldKey.equals(key)) { 71 | super.remove(oldKey); 72 | } 73 | return super.put(key, value); 74 | } 75 | 76 | 77 | @Override 78 | public void putAll(Map map) { 79 | if (map.isEmpty()) { 80 | return; 81 | } 82 | for (Map.Entry entry : map.entrySet()) { 83 | put(entry.getKey(), entry.getValue()); 84 | } 85 | } 86 | 87 | 88 | @Override 89 | public boolean containsKey(Object key) { 90 | return (key instanceof String && this.caseInsensitiveKeys.containsKey(convertKey((String) key))); 91 | } 92 | 93 | 94 | @Override 95 | public V get(Object key) { 96 | if (key instanceof String) { 97 | return super.get(this.caseInsensitiveKeys.get(convertKey((String) key))); 98 | } 99 | else { 100 | return null; 101 | } 102 | } 103 | 104 | 105 | @Override 106 | public V remove(Object key) { 107 | if (key instanceof String ) { 108 | return super.remove(this.caseInsensitiveKeys.remove(convertKey((String) key))); 109 | } 110 | else { 111 | return null; 112 | } 113 | } 114 | 115 | 116 | @Override 117 | public void clear() { 118 | this.caseInsensitiveKeys.clear(); 119 | super.clear(); 120 | } 121 | 122 | 123 | 124 | protected String convertKey(String key) { 125 | return key.toLowerCase(this.locale); 126 | } 127 | 128 | } -------------------------------------------------------------------------------- /1-hi-utils/src/main/java/com/helpinput/maps/ConcurrentCaseInsensitiveHashMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-10 21 | */ 22 | 23 | package com.helpinput.maps; 24 | 25 | import java.util.Map; 26 | 27 | import org.slf4j.Logger; 28 | 29 | import com.helpinput.core.LoggerBase; 30 | 31 | 32 | 33 | public class ConcurrentCaseInsensitiveHashMap extends ConcurrentMap { 34 | private static final long serialVersionUID = 1L; 35 | public static Logger logger=LoggerBase.logger; 36 | 37 | private final ConcurrentMap caseInsensitiveKeys; 38 | 39 | 40 | 41 | /** 42 | * Create a new LinkedCaseInsensitiveMap for the default Locale. 43 | * @see java.lang.String#toLowerCase() 44 | */ 45 | public ConcurrentCaseInsensitiveHashMap() { 46 | super(); 47 | this.caseInsensitiveKeys = new ConcurrentMap(); 48 | } 49 | 50 | 51 | /** 52 | * Create a new LinkedCaseInsensitiveMap that wraps a {@link LinkedHashMap} 53 | * with the given initial capacity and stores lower-case keys according 54 | * to the default Locale. 55 | * @param initialCapacity the initial capacity 56 | * @see java.lang.String#toLowerCase() 57 | */ 58 | public ConcurrentCaseInsensitiveHashMap(int initialCapacity) { 59 | super(initialCapacity); 60 | this.caseInsensitiveKeys = new ConcurrentMap(); 61 | } 62 | 63 | 64 | 65 | @Override 66 | public V put(String key, V value) { 67 | String oldKey = this.caseInsensitiveKeys.put(convertKey(key), key); 68 | if (oldKey != null && !oldKey.equals(key)) { 69 | super.remove(oldKey); 70 | } 71 | return super.put(key, value); 72 | } 73 | 74 | @Override 75 | public void putAll(Map map) { 76 | if (map.isEmpty()) { 77 | return; 78 | } 79 | for (Map.Entry entry : map.entrySet()) { 80 | put(entry.getKey(), entry.getValue()); 81 | } 82 | } 83 | 84 | @Override 85 | public boolean containsKey(Object key) { 86 | return (key instanceof String && this.caseInsensitiveKeys.containsKey(convertKey((String) key))); 87 | } 88 | 89 | @Override 90 | public V get(Object key) { 91 | if (key instanceof String) { 92 | return super.get(this.caseInsensitiveKeys.get(convertKey((String)key))); 93 | } 94 | else { 95 | return null; 96 | } 97 | } 98 | 99 | @Override 100 | public V remove(Object key) { 101 | if (key instanceof String ) { 102 | return super.remove(this.caseInsensitiveKeys.remove(convertKey((String) key))); 103 | } 104 | else { 105 | return null; 106 | } 107 | } 108 | 109 | @Override 110 | public void clear() { 111 | this.caseInsensitiveKeys.clear(); 112 | super.clear(); 113 | } 114 | 115 | 116 | /** 117 | * Convert the given key to a case-insensitive key. 118 | *

The default implementation converts the key 119 | * to lower-case according to this Map's Locale. 120 | * @param key the user-specified key 121 | * @return the key to use for storing 122 | * @see java.lang.String#toLowerCase(java.util.Locale) 123 | */ 124 | protected String convertKey(String key) { 125 | return key.toLowerCase(); 126 | } 127 | 128 | } -------------------------------------------------------------------------------- /1-hi-utils/src/main/java/com/helpinput/maps/ConcurrentHashSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-10 21 | */ 22 | 23 | package com.helpinput.maps; 24 | 25 | 26 | import java.util.Collection; 27 | import java.util.concurrent.ConcurrentHashMap; 28 | import java.util.concurrent.ConcurrentMap; 29 | 30 | public class ConcurrentHashSet extends MapBackedSet { 31 | 32 | private static final long serialVersionUID = 8518578988740277828L; 33 | 34 | public ConcurrentHashSet() { 35 | super(new ConcurrentHashMap()); 36 | } 37 | 38 | public ConcurrentHashSet(Collection c) { 39 | super(new ConcurrentHashMap(), c); 40 | } 41 | 42 | @Override 43 | public boolean add(E o) { 44 | Boolean answer = ((ConcurrentMap) map).putIfAbsent(o, Boolean.TRUE); 45 | return answer == null; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /1-hi-utils/src/main/java/com/helpinput/maps/ConcurrentMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-10 21 | */ 22 | 23 | package com.helpinput.maps; 24 | 25 | import java.util.concurrent.ConcurrentHashMap; 26 | 27 | public class ConcurrentMap extends ConcurrentHashMap{ 28 | private static final long serialVersionUID = 1L; 29 | 30 | public ConcurrentMap() { 31 | super(); 32 | } 33 | 34 | public ConcurrentMap(int initialCapacity) { 35 | super(initialCapacity); 36 | } 37 | 38 | 39 | @Override 40 | public V get(Object key) { 41 | if (key==null) 42 | return null; 43 | return super.get(key); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /1-hi-utils/src/main/java/com/helpinput/maps/MapBackedSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-10 21 | */ 22 | package com.helpinput.maps; 23 | 24 | import java.io.Serializable; 25 | import java.util.AbstractSet; 26 | import java.util.Collection; 27 | import java.util.Iterator; 28 | import java.util.Map; 29 | 30 | public class MapBackedSet extends AbstractSet implements Serializable { 31 | 32 | private static final long serialVersionUID = -8347878570391674042L; 33 | 34 | protected final Map map; 35 | 36 | public MapBackedSet(Map map) { 37 | this.map = map; 38 | } 39 | 40 | public MapBackedSet(Map map, Collection c) { 41 | this.map = map; 42 | addAll(c); 43 | } 44 | 45 | @Override 46 | public int size() { 47 | return map.size(); 48 | } 49 | 50 | @Override 51 | public boolean contains(Object o) { 52 | return map.containsKey(o); 53 | } 54 | 55 | @Override 56 | public Iterator iterator() { 57 | return map.keySet().iterator(); 58 | } 59 | 60 | @Override 61 | public boolean add(E o) { 62 | return map.put(o, Boolean.TRUE) == null; 63 | } 64 | 65 | @Override 66 | public boolean remove(Object o) { 67 | return map.remove(o) != null; 68 | } 69 | 70 | @Override 71 | public void clear() { 72 | map.clear(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /1-hi-utils/src/main/java/com/helpinput/maps/OnceMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-10 21 | */ 22 | package com.helpinput.maps; 23 | 24 | import java.util.Map; 25 | 26 | 27 | 28 | public class OnceMap extends RequestValues { 29 | private static final long serialVersionUID = 1L; 30 | //private static Logger logger = LoggerBase.logger; 31 | 32 | private String ownKey; 33 | private Map parent; 34 | 35 | public OnceMap(String ownKey, Map parent) { 36 | this.ownKey = ownKey; 37 | this.parent = parent; 38 | parent.put(ownKey, this); 39 | 40 | } 41 | 42 | /* (non-Javadoc) 43 | * @see com.helpinput.map.CaseInsensitiveHashMap#get(java.lang.Object) 44 | */ 45 | public Object get(Object key) { 46 | Object result = remove(key); 47 | if (this.size() == 0) { 48 | this.parent.remove(ownKey); 49 | } 50 | return result; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /1-hi-utils/src/main/java/com/helpinput/maps/RequestValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-10 21 | */ 22 | package com.helpinput.maps; 23 | 24 | import com.helpinput.core.Utils; 25 | 26 | /** Map,内装从数据库转换的数据,key:fieldName,object:values 有顺序,不区分大小写 27 | * 28 | * @param */ 29 | public class RequestValues extends CaseInsensitiveHashMap implements Values { 30 | 31 | private static final long serialVersionUID = 1L; 32 | 33 | /** 34 | * 35 | */ 36 | public RequestValues() { 37 | super(); 38 | } 39 | 40 | public RequestValues(int initialCapacity) { 41 | super(initialCapacity); 42 | } 43 | 44 | @Override 45 | public Object put(String key, Object value) { 46 | if (value instanceof Object[]) { 47 | Object[] values = (Object[]) value; 48 | if (values.length == 1) { 49 | return super.put(key, values[0]); 50 | } 51 | } 52 | return super.put(key, value); 53 | } 54 | 55 | @Override 56 | public Object set(Object key, Object value) { 57 | return Utils.put(this, key, value); 58 | } 59 | 60 | @Override 61 | public T got(Object key, Object defaultValue) { 62 | return Utils.get(this,key, defaultValue); 63 | } 64 | 65 | @Override 66 | public T got(Object key) { 67 | return Utils.get(this,key); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /1-hi-utils/src/main/java/com/helpinput/maps/ResponsValues.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-10 21 | */ 22 | package com.helpinput.maps; 23 | 24 | import com.helpinput.core.Utils; 25 | 26 | /** 27 | * Map,内装从数据库转换的数据,key:fieldName,object:values 有顺序,不区分大小写 28 | * 29 | * @param 30 | * */ 31 | public class ResponsValues extends CaseInsensitiveHashMap implements Values { 32 | private static final long serialVersionUID = 1L; 33 | 34 | public ResponsValues() { 35 | super(); 36 | } 37 | 38 | public ResponsValues(int initialCapacity) { 39 | super(initialCapacity); 40 | } 41 | 42 | @Override 43 | public Object set(Object key, Object value) { 44 | return Utils.put(this, key, value); 45 | } 46 | 47 | @Override 48 | public T got(Object key, Object defaultValue) { 49 | return Utils.get(this,key, defaultValue); 50 | } 51 | 52 | @Override 53 | public T got(Object key) { 54 | return Utils.get(this,key); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /1-hi-utils/src/main/java/com/helpinput/maps/Values.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-10 21 | */ 22 | package com.helpinput.maps; 23 | 24 | import java.util.Map; 25 | 26 | /** The Interface Values. */ 27 | public interface Values extends Map { 28 | T got(Object key,Object defaultValue); 29 | T got(Object key); 30 | Object set(Object key,Object value); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /1-hi-utils/src/test/java/commons/PatternTest.java: -------------------------------------------------------------------------------- 1 | package commons; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | import org.junit.Test; 7 | 8 | public class PatternTest { 9 | // @Test 10 | // public void testNotHave(){ 11 | // String reg="^(?!.*(不合谐)).*$";//用到了前瞻 12 | // System.out.println("不管信不信,反正现在很不合谐".matches(reg));//false不通过 13 | // System.out.println("不管信不信,反正现在非常合谐".matches(reg));//true通过 14 | // System.out.println("不合谐在某国是普遍存在的".matches(reg));//false不通过 15 | // } 16 | 17 | //@Test 18 | // public void testNotHave(){ 19 | // Pattern p=Pattern.compile("(?!.*(\\s{1,}class\\s{1,})).*$"); 20 | // System.out.println(p.matcher("public class User").find()); 21 | // System.out.println(p.matcher("User user").find()); 22 | // System.out.println(p.matcher("myclass User").find()); 23 | // } 24 | 25 | @Test 26 | public void testNotHave() { 27 | String s; 28 | 29 | //String reg="^((? getAllUser()"; 94 | m = p.matcher(s); 95 | System.out.println(m.find() + " " + s); 96 | 97 | s = "return (User)query.uniqueResult()"; 98 | m = p.matcher(s); 99 | System.out.println(m.find() + " " + s); 100 | 101 | // System.out.println("xcalendar ".matches("((.*calendar.*)(?!.*simple.*))")); 102 | // System.out.println("simple ".matches("((.*calendar.*)(?!.*simple.*))")); 103 | // System.out.println("calendar simple ".matches("((.*calendar.*)(?!.*simple.*))")); 104 | // System.out.println("simple calendar".matches("((.*calendar.*)(?!.*simple.*))")); 105 | 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /1-hi-utils/src/test/java/commons/ReplaceTest.java: -------------------------------------------------------------------------------- 1 | package commons; 2 | 3 | import org.junit.Test; 4 | 5 | import com.helpinput.core.Utils; 6 | 7 | public class ReplaceTest { 8 | 9 | 10 | 11 | @Test 12 | public void test1() { 13 | //String s = "public User getUser(String id) {"; 14 | //String s = "User u=\"sl fr User wh\"+\"User.id=\\\"11\\\"\""; 15 | String s="{\n"+ 16 | " String hql = \"from User u where u.id=?\";\n"+ 17 | " Query query = sessionFactory.getCurrentSession().createQuery(hql);\n"+ 18 | " query.setString(0, id);\n"+ 19 | " return (User) query.uniqueResult();\n"+ 20 | "}\n"; 21 | String o = "User"; 22 | String n = "java.lang.Object"; 23 | System.out.println(s + " " + s.length()); 24 | 25 | StringBuilder sb = new StringBuilder(s.length() + 100); 26 | Utils.replaceWholeWord(sb, 0, s, o, n, '"'); 27 | System.out.println(sb.toString()); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /1-hi-utils/src/test/java/commons/UtilsTest.java: -------------------------------------------------------------------------------- 1 | package commons; 2 | 3 | import org.junit.Test; 4 | 5 | 6 | 7 | 8 | public class UtilsTest { 9 | 10 | // void pro1(String v){ 11 | // v="xxxxxx"; 12 | // } 13 | // 14 | // @Test 15 | // public void pro(){ 16 | // String v = null; 17 | // pro1(v); 18 | // System.out.println("vxxxxxxxxxxxxxxxxxxyyyyyyyyy:"+v); 19 | // } 20 | // 21 | // @Test 22 | // public void test() { 23 | // Class kClass = int.class; 24 | // System.out.println("kClass:"+kClass.getName()); 25 | // } 26 | @Test 27 | public void testx(){ 28 | Long lg=new Long(100L); 29 | Float ft =new Float(100.0f); 30 | 31 | System.out.println(lg>ft); 32 | System.out.println(ft); 33 | //System.out.println((lg==ft)); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /1-hi-utils/src/test/java/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | %d{yyyy/MM/dd HH:mm:ss.SSS} %-5level [%thread] %n%msg%n%caller{10} 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /1-hi-utils/src/test/java/maven/delelastupdate/DelLastUpdated.java: -------------------------------------------------------------------------------- 1 | package maven.delelastupdate; 2 | 3 | import java.io.File; 4 | import java.io.FilenameFilter; 5 | 6 | import org.apache.commons.io.filefilter.FileFilterUtils; 7 | 8 | 9 | 10 | 11 | public class DelLastUpdated { 12 | 13 | private static final String KEY_MAVEN_REPO = "maven.repo"; 14 | private static final String FILE_SUFFIX = "lastUpdated"; 15 | 16 | /** 17 | * @param args 18 | */ 19 | public static void main(String[] args) { 20 | File mavenRep = new File("e:/.m2/"); 21 | if (!mavenRep.exists()) { 22 | //logger.warn("Maven repos is not exist."); 23 | return; 24 | } 25 | File[] files = mavenRep.listFiles((FilenameFilter) FileFilterUtils 26 | .directoryFileFilter()); 27 | delFileRecr(files,null); 28 | System.out.println("Clean lastUpdated files finished."); 29 | } 30 | 31 | private static void delFileRecr(File[] dirs, File[] files) { 32 | if (dirs != null && dirs.length > 0) { 33 | for(File dir: dirs){ 34 | File[] childDir = dir.listFiles((FilenameFilter) FileFilterUtils 35 | .directoryFileFilter()); 36 | File[] childFiles = dir.listFiles((FilenameFilter) FileFilterUtils 37 | .suffixFileFilter(FILE_SUFFIX)); 38 | delFileRecr(childDir,childFiles); 39 | } 40 | } 41 | if(files!=null&&files.length>0){ 42 | for(File file: files){ 43 | if(file.delete()){ 44 | System.out.println("File: ["+file.getName()+"] has been deleted."); 45 | } 46 | } 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2-hi-spring-Dynamic 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.common.project.facet.core.builder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.m2e.core.maven2Builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | com.genuitec.eclipse.ast.deploy.core.DeploymentBuilder 30 | 31 | 32 | 33 | 34 | 35 | com.genuitec.eclipse.ast.deploy.core.deploymentnature 36 | org.eclipse.jem.workbench.JavaEMFNature 37 | org.eclipse.wst.common.modulecore.ModuleCoreNature 38 | org.eclipse.jdt.core.javanature 39 | org.eclipse.m2e.core.maven2Nature 40 | org.eclipse.wst.common.project.facet.core.nature 41 | 42 | 43 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | 6 | 7 | com.helpinput.hi 8 | helpinput-parent 9 | 1.2.4 10 | 11 | 12 | 13 | helpinput-spring-dynamic 14 | 15 | 16 | 17 | 18 | javax.servlet 19 | jstl 20 | 1.2 21 | provided 22 | 23 | 24 | javax.servlet.jsp 25 | jsp-api 26 | 2.1 27 | provided 28 | 29 | 30 | org.glassfish 31 | javax.annotation 32 | 3.0.1 33 | provided 34 | 35 | 36 | org.glassfish 37 | javax.ejb 38 | 3.0.1 39 | provided 40 | 41 | 42 | 43 | org.glassfish 44 | javax.servlet 45 | 3.0.1 46 | provided 47 | 48 | 49 | 50 | org.hibernate 51 | hibernate-core 52 | 4.2.0.Final 53 | provided 54 | 55 | 56 | 57 | org.springframework 58 | spring-orm 59 | 3.2.9.RELEASE 60 | provided 61 | 62 | 63 | 64 | 65 | org.springframework 66 | spring-webmvc 67 | 3.2.9.RELEASE 68 | 69 | 70 | 71 | javax.inject 72 | javax.inject 73 | 1 74 | provided 75 | 76 | 77 | 78 | javax.persistence 79 | persistence-api 80 | 1.0 81 | provided 82 | 83 | 84 | 85 | org.codehaus.groovy 86 | groovy-all 87 | 2.1.6 88 | 89 | 90 | 91 | cglib 92 | cglib 93 | 2.2 94 | 95 | 96 | 97 | org.slf4j 98 | slf4j-api 99 | 1.7.5 100 | provided 101 | 102 | 103 | 104 | 105 | junit 106 | junit 107 | 4.11 108 | test 109 | 110 | 111 | 112 | com.github.javaparser 113 | javaparser-core 114 | 2.1.0 115 | 116 | 117 | 118 | net.java.dev.rome 119 | rome 120 | 1.0.0 121 | 122 | 123 | com.helpinput.hi 124 | helpinput-utils 125 | ${parent.version} 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | org.apache.maven.plugins 135 | maven-compiler-plugin 136 | 137 | 1.7 138 | 1.7 139 | 140 | 141 | 142 | maven-source-plugin 143 | 144 | true 145 | 146 | 147 | 148 | compile 149 | 150 | jar 151 | 152 | 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/annotation/Dynamic.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-30 21 | */ 22 | package com.helpinput.annotation; 23 | 24 | import static java.lang.annotation.ElementType.PARAMETER; 25 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 26 | 27 | import java.lang.annotation.Documented; 28 | import java.lang.annotation.Inherited; 29 | import java.lang.annotation.Retention; 30 | import java.lang.annotation.Target; 31 | 32 | @Target({ PARAMETER }) 33 | @Retention(RUNTIME) 34 | @Documented 35 | @Inherited 36 | public @interface Dynamic { 37 | String value(); 38 | } 39 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/annotation/Mapping.java: -------------------------------------------------------------------------------- 1 | package com.helpinput.annotation; 2 | 3 | import static java.lang.annotation.ElementType.TYPE; 4 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 5 | 6 | import java.lang.annotation.Documented; 7 | import java.lang.annotation.Inherited; 8 | import java.lang.annotation.Retention; 9 | import java.lang.annotation.Target; 10 | 11 | @Target({ TYPE }) 12 | @Retention(RUNTIME) 13 | @Documented 14 | @Inherited 15 | public @interface Mapping { 16 | String[] value() default {}; 17 | } 18 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/annotation/MappingExclude.java: -------------------------------------------------------------------------------- 1 | package com.helpinput.annotation; 2 | 3 | import static java.lang.annotation.ElementType.TYPE; 4 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 5 | 6 | import java.lang.annotation.Documented; 7 | import java.lang.annotation.Inherited; 8 | import java.lang.annotation.Retention; 9 | import java.lang.annotation.Target; 10 | 11 | @Target({ TYPE }) 12 | @Retention(RUNTIME) 13 | @Documented 14 | @Inherited 15 | public @interface MappingExclude { 16 | String[] value() default {}; 17 | } 18 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/annotation/Parent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-30 21 | */ 22 | package com.helpinput.annotation; 23 | 24 | import static java.lang.annotation.ElementType.TYPE; 25 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 26 | 27 | import java.lang.annotation.Documented; 28 | import java.lang.annotation.Inherited; 29 | import java.lang.annotation.Retention; 30 | import java.lang.annotation.Target; 31 | 32 | @Target({ TYPE }) 33 | @Retention(RUNTIME) 34 | @Documented 35 | @Inherited 36 | public @interface Parent { 37 | String value(); 38 | String property() default "target"; 39 | } 40 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/annotation/Properties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-7-5 21 | */ 22 | package com.helpinput.annotation; 23 | 24 | import static java.lang.annotation.ElementType.TYPE; 25 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 26 | 27 | import java.lang.annotation.Documented; 28 | import java.lang.annotation.Inherited; 29 | import java.lang.annotation.Retention; 30 | import java.lang.annotation.Target; 31 | 32 | 33 | 34 | @Target({ TYPE }) 35 | @Retention(RUNTIME) 36 | @Documented 37 | @Inherited 38 | public @interface Properties { 39 | Property[] value() default {}; 40 | } 41 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/annotation/Property.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-7-5 21 | */ 22 | package com.helpinput.annotation; 23 | 24 | import static java.lang.annotation.ElementType.*; 25 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 26 | 27 | import java.lang.annotation.Documented; 28 | import java.lang.annotation.Inherited; 29 | import java.lang.annotation.Retention; 30 | import java.lang.annotation.Target; 31 | 32 | 33 | @Target({ TYPE }) 34 | @Retention(RUNTIME) 35 | @Documented 36 | @Inherited 37 | public @interface Property { 38 | 39 | String name(); 40 | String value(); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/annotation/Prototype.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-30 21 | */ 22 | package com.helpinput.annotation; 23 | 24 | import static java.lang.annotation.ElementType.TYPE; 25 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 26 | 27 | import java.lang.annotation.Documented; 28 | import java.lang.annotation.Inherited; 29 | import java.lang.annotation.Retention; 30 | import java.lang.annotation.Target; 31 | 32 | @Target({ TYPE }) 33 | @Retention(RUNTIME) 34 | @Documented 35 | @Inherited 36 | public @interface Prototype { 37 | 38 | } 39 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/annotation/TargetType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-7-5 21 | */ 22 | package com.helpinput.annotation; 23 | 24 | import static java.lang.annotation.ElementType.TYPE; 25 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 26 | 27 | import java.lang.annotation.Documented; 28 | import java.lang.annotation.Inherited; 29 | import java.lang.annotation.Retention; 30 | import java.lang.annotation.Target; 31 | 32 | 33 | 34 | @Target({ TYPE }) 35 | @Retention(RUNTIME) 36 | @Documented 37 | @Inherited 38 | public @interface TargetType { 39 | Class value(); 40 | } 41 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/holder/ContextHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-7-6 21 | */ 22 | package com.helpinput.holder; 23 | 24 | import com.helpinput.spring.registinerceptor.BeanRegistInterceptor; 25 | 26 | public class ContextHolder { 27 | public static SafeHolder refreshers = new SafeHolder<>(); 28 | 29 | public static SafeHolder beanRegistIntercpterHolder = new SafeHolder<>(); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/holder/SafeHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-7-6 21 | */ 22 | package com.helpinput.holder; 23 | 24 | import java.util.LinkedList; 25 | import java.util.List; 26 | 27 | public class SafeHolder { 28 | private List holder = new LinkedList<>(); 29 | 30 | public void register(T item) { 31 | synchronized (holder) { 32 | if (!holder.contains(item)) { 33 | holder.add(item); 34 | } 35 | } 36 | } 37 | 38 | public void remover(T item) { 39 | synchronized (holder) { 40 | holder.remove(item); 41 | } 42 | } 43 | 44 | public List getList() { 45 | synchronized (holder) { 46 | return new LinkedList<>(holder); 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/propertyeditors/GLClassEditor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-7-6 21 | */ 22 | 23 | package com.helpinput.propertyeditors; 24 | 25 | import java.beans.PropertyEditorSupport; 26 | 27 | import org.springframework.util.ClassUtils; 28 | import org.springframework.util.StringUtils; 29 | 30 | import com.helpinput.annotation.TargetType; 31 | import com.helpinput.spring.support.ClassLoaderHolder; 32 | import org.slf4j.Logger; 33 | import com.helpinput.core.LoggerBase; 34 | 35 | @TargetType(Class.class) 36 | public class GLClassEditor extends PropertyEditorSupport { 37 | static Logger logger = LoggerBase.logger; 38 | 39 | private final ClassLoader classLoader; 40 | 41 | public GLClassEditor() { 42 | this(null); 43 | } 44 | 45 | public GLClassEditor(ClassLoader classLoader) { 46 | this.classLoader = (classLoader != null ? classLoader : GLClassEditor.class.getClassLoader()); 47 | } 48 | 49 | @Override 50 | public void setAsText(String text) throws IllegalArgumentException { 51 | if (StringUtils.hasText(text)) { 52 | Class result; 53 | try { 54 | result = ClassUtils.resolveClassName(text.trim(), this.classLoader); 55 | } 56 | catch (IllegalArgumentException e) { 57 | //for sessionFactory annotatedClasses 58 | result = ClassUtils.resolveClassName(text.trim(), ClassLoaderHolder.gcl); 59 | try { 60 | throw new Exception(); 61 | } 62 | catch (Exception e1) { 63 | e1.printStackTrace(); 64 | } 65 | } 66 | setValue(result); 67 | } 68 | else { 69 | setValue(null); 70 | } 71 | } 72 | 73 | @Override 74 | public String getAsText() { 75 | Class clazz = (Class) getValue(); 76 | if (clazz != null) { 77 | return ClassUtils.getQualifiedName(clazz); 78 | } 79 | else { 80 | return ""; 81 | } 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/propertyeditors/PropertyEditorRegister.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-7-3 21 | */ 22 | package com.helpinput.propertyeditors; 23 | 24 | import java.beans.PropertyEditor; 25 | 26 | import java.beans.PropertyEditorSupport; 27 | import java.lang.reflect.Method; 28 | import java.util.HashMap; 29 | import java.util.Map; 30 | import java.util.Map.Entry; 31 | 32 | import org.apache.commons.beanutils.ConvertUtils; 33 | import org.springframework.beans.PropertyEditorRegistrar; 34 | import org.springframework.beans.PropertyEditorRegistry; 35 | import org.springframework.beans.factory.support.DefaultListableBeanFactory; 36 | 37 | import com.helpinput.core.Utils; 38 | import com.helpinput.spring.Commons; 39 | import com.helpinput.annotation.Properties; 40 | import com.helpinput.annotation.Property; 41 | import com.helpinput.annotation.TargetType; 42 | import org.slf4j.Logger; 43 | import com.helpinput.core.LoggerBase; 44 | 45 | public class PropertyEditorRegister { 46 | static Logger logger = LoggerBase.logger; 47 | 48 | private static boolean addProperty(Class propertyEditorType, Property propertyAnn, 49 | Map setMethodAndValues) { 50 | 51 | final String methodName = Commons.getSetterName(propertyAnn.name()); 52 | 53 | if (!Utils.hasLength(methodName)) 54 | return false; 55 | 56 | Method method = Utils.findMethod(propertyEditorType, methodName); 57 | 58 | if (method == null || !method.getReturnType().equals(Void.TYPE)) 59 | return false; 60 | 61 | Class[] parameterTypes = method.getParameterTypes(); 62 | 63 | if (parameterTypes == null || parameterTypes.length != 1) 64 | return false; 65 | 66 | try { 67 | Class parameterType = parameterTypes[0]; 68 | Object realValue = ConvertUtils.convert(propertyAnn.value(), parameterType); 69 | setMethodAndValues.put(method, realValue); 70 | } 71 | catch (Exception e) { 72 | e.printStackTrace(); 73 | return false; 74 | } 75 | return true; 76 | } 77 | 78 | public static Class getTargetType(Class propertyEditorType, Class... targetType) { 79 | Class tmpTargetType = null; 80 | if (!Utils.hasLength(targetType)) { 81 | TargetType targetTypeAnn = propertyEditorType.getAnnotation(TargetType.class); 82 | if (targetTypeAnn == null) 83 | return null; 84 | tmpTargetType = targetTypeAnn.value(); 85 | } 86 | else 87 | tmpTargetType = targetType[0]; 88 | 89 | return tmpTargetType; 90 | } 91 | 92 | public static PropertyEditor newProtertyEditor(Class propertyEditorType, 93 | Class... targetType) { 94 | 95 | final Class theTargetType = getTargetType(propertyEditorType, targetType); 96 | if (theTargetType == null) 97 | return null; 98 | 99 | Map setMethodAndValues = null; 100 | 101 | Properties propertiesAnn = propertyEditorType.getAnnotation(Properties.class); 102 | if (propertiesAnn != null) { 103 | Property[] properties = propertiesAnn.value(); 104 | if (Utils.hasLength(properties)) { 105 | setMethodAndValues = new HashMap<>(properties.length + 1); 106 | for (Property property : properties) { 107 | if (!addProperty(propertyEditorType, property, setMethodAndValues)) 108 | return null; 109 | } 110 | } 111 | } 112 | 113 | Property propertyAnn = propertyEditorType.getAnnotation(Property.class); 114 | if (propertyAnn != null) { 115 | if (setMethodAndValues == null) 116 | setMethodAndValues = new HashMap<>(1); 117 | if (!addProperty(propertyEditorType, propertyAnn, setMethodAndValues)) 118 | return null; 119 | } 120 | 121 | PropertyEditor propertyEditor; 122 | try { 123 | propertyEditor = propertyEditorType.newInstance(); 124 | } 125 | catch (InstantiationException | IllegalAccessException e) { 126 | e.printStackTrace(); 127 | return null; 128 | } 129 | 130 | if (Utils.hasLength(setMethodAndValues)) { 131 | for (Entry entry : setMethodAndValues.entrySet()) { 132 | try { 133 | Utils.InvokedMethod(propertyEditor, entry.getKey(), entry.getValue()); 134 | } 135 | catch (Exception e) { 136 | e.printStackTrace(); 137 | return null; 138 | } 139 | } 140 | } 141 | return propertyEditor; 142 | } 143 | 144 | public static void registerProtertyEditor(DefaultListableBeanFactory dlbf, 145 | Class propertyEditorType, 146 | Class... targetType) { 147 | final Class theTargetType = getTargetType(propertyEditorType, targetType); 148 | if (theTargetType == null) 149 | return; 150 | 151 | final PropertyEditor propertyEditor = newProtertyEditor(propertyEditorType, theTargetType); 152 | if (propertyEditor == null) 153 | return; 154 | 155 | PropertyEditorRegistrar myPropertyEditorRegistrar = new PropertyEditorRegistrar() { 156 | public void registerCustomEditors(PropertyEditorRegistry registry) { 157 | registry.registerCustomEditor(theTargetType, propertyEditor); 158 | } 159 | }; 160 | 161 | dlbf.addPropertyEditorRegistrar(myPropertyEditorRegistrar); 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/settings/Options.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-7-3 21 | */ 22 | package com.helpinput.settings; 23 | 24 | 25 | public class Options { 26 | public static volatile Long scanInterval = 6000L; 27 | } 28 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/BeanDefinitionWrap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-16 21 | */ 22 | package com.helpinput.spring; 23 | 24 | import org.springframework.beans.factory.config.BeanDefinition; 25 | 26 | public class BeanDefinitionWrap { 27 | public String beanName; 28 | public BeanDefinition beanDefinition; 29 | 30 | public BeanDefinitionWrap(String beanName, BeanDefinition beanDefinition){ 31 | this.beanName =beanName; 32 | this.beanDefinition =beanDefinition; 33 | } 34 | 35 | public String getBeanName() { 36 | return beanName; 37 | } 38 | 39 | public BeanDefinition getBeanDefinition() { 40 | return beanDefinition; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/BeanInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-16 21 | */ 22 | package com.helpinput.spring; 23 | 24 | import java.util.regex.Pattern; 25 | 26 | import com.github.javaparser.ast.CompilationUnit; 27 | 28 | 29 | // 上一次更新的脚本,前一个string 是path,后一个路径是beanName,用于释放不用的bean; 30 | class BeanInfo { 31 | 32 | 33 | String fileName=null; 34 | String scanName=null; 35 | String importName=null; 36 | 37 | String beanName=null; 38 | String actionName=null; 39 | String relativePath=null; 40 | String packageName=null; 41 | Long lastModified=0L; 42 | CompilationUnit cu=null; 43 | Pattern referencWrapPt=null; 44 | Class beanClass =null; 45 | 46 | boolean needParse=true; 47 | boolean isUpdate=false; 48 | boolean scaned=false; 49 | boolean isNew=false; 50 | boolean isInterface =false; 51 | 52 | BeanInfo(String fileName, String relativePath, Long lastModified) { 53 | this.fileName = fileName; 54 | this.relativePath = relativePath; 55 | this.lastModified = lastModified; 56 | } 57 | } -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/Commons.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-16 21 | */ 22 | package com.helpinput.spring; 23 | 24 | import javax.inject.Named; 25 | 26 | import org.slf4j.Logger; 27 | import org.springframework.beans.factory.support.DefaultListableBeanFactory; 28 | import org.springframework.context.ApplicationContext; 29 | import org.springframework.context.support.AbstractApplicationContext; 30 | import org.springframework.stereotype.Component; 31 | 32 | import com.helpinput.core.LoggerBase; 33 | import com.helpinput.core.Utils; 34 | 35 | public class Commons { 36 | static Logger logger = LoggerBase.logger; 37 | 38 | public static DefaultListableBeanFactory getDefaultListableBeanFactory(ApplicationContext context) { 39 | if (context instanceof AbstractApplicationContext) { 40 | return (DefaultListableBeanFactory) ((AbstractApplicationContext) context).getBeanFactory(); 41 | } 42 | return (DefaultListableBeanFactory) context.getAutowireCapableBeanFactory(); 43 | } 44 | 45 | public static String getBeanName(Class beanClass) { 46 | String beanName = null; 47 | Named nameAnn = beanClass.getAnnotation(Named.class); 48 | //todo 如果没有named标注,则不加入bean; 49 | if (nameAnn != null) { 50 | if (Utils.hasLength(nameAnn.value())) 51 | beanName = nameAnn.value(); 52 | } 53 | else { 54 | Component componentAnn = beanClass.getAnnotation(Component.class); 55 | if (componentAnn != null) { 56 | if (Utils.hasLength(componentAnn.value())) 57 | beanName = componentAnn.value(); 58 | } 59 | } 60 | 61 | if (!Utils.hasLength(beanName)) { 62 | beanName = Utils.beanName(beanClass.getSimpleName()); 63 | } 64 | return beanName; 65 | } 66 | 67 | public static String getSetterName(String name) { 68 | if (Utils.hasLength(name)) { 69 | return "set" + name.substring(0, 1).toUpperCase() + name.substring(1); 70 | } 71 | return null; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/Consts.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-16 21 | */ 22 | package com.helpinput.spring; 23 | 24 | public class Consts { 25 | 26 | public static final String RequestScoped="RequestScoped"; 27 | public static final String FlashScoped="FlashScoped"; 28 | public static final String ViewScoped="ViewScoped"; 29 | public static final String SessionScoped="SessionScoped"; 30 | public static final String ApplicatoinScoped="SessionScoped"; 31 | public static final String Prototype = "Prototype"; 32 | public static final String Singleton = "Singleton"; 33 | 34 | public static final String application_scope = "application"; 35 | public static final String session_scope = "session"; 36 | public static final String view_scope = "view"; 37 | public static final String request_scope = "request"; 38 | public static final String flash_scope = "flash"; 39 | public static final String prototype_scope = "prototype"; 40 | public static final String singleton_scope = "singleton"; 41 | 42 | public static final String relativePath = "_relativePath_"; 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/FileReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-16 21 | */ 22 | package com.helpinput.spring; 23 | 24 | import java.io.BufferedReader; 25 | import java.io.Closeable; 26 | import java.io.IOException; 27 | import java.io.Reader; 28 | 29 | import static com.helpinput.core.LoggerBase.logger; 30 | 31 | 32 | 33 | class FileReader { 34 | private static void closeWithWarning(Closeable c) { 35 | if (c != null) { 36 | try { 37 | c.close(); 38 | } catch (IOException e) { 39 | logger.warn("Caught exception during close(): " + e); 40 | } 41 | } 42 | } 43 | 44 | public static String getText(BufferedReader reader) throws IOException { 45 | StringBuilder answer = new StringBuilder(); 46 | 47 | // reading the content of the file within a char buffer 48 | // allow to keep the correct line endings 49 | char[] charBuffer = new char[8192]; 50 | int nbCharRead /* = 0*/; 51 | try { 52 | while ((nbCharRead = reader.read(charBuffer)) != -1) { 53 | // appends buffer 54 | answer.append(charBuffer, 0, nbCharRead); 55 | } 56 | Reader temp = reader; 57 | reader = null; 58 | temp.close(); 59 | } finally { 60 | closeWithWarning(reader); 61 | } 62 | return answer.toString(); 63 | } 64 | 65 | 66 | } 67 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/Interceptor.java: -------------------------------------------------------------------------------- 1 | /** 2 | *@Author: 夏政生 qq:78493244 3 | *@Date: 2014-4-22 4 | *@Copyright: 2014 www.inputhelp.com Inc. All rights reserved. 5 | */ 6 | package com.helpinput.spring; 7 | 8 | import java.io.Serializable; 9 | import java.lang.reflect.Method; 10 | 11 | import net.sf.cglib.proxy.Enhancer; 12 | import net.sf.cglib.proxy.MethodInterceptor; 13 | import net.sf.cglib.proxy.MethodProxy; 14 | 15 | import com.helpinput.core.LoggerBase; 16 | 17 | /** 18 | *
 19 |  * cglib生成的拦截器
 20 |  * 
21 | * 22 | *
 23 |  * author: auwa, date:2013-12-4
 24 |  * 
25 | */ 26 | 27 | public class Interceptor extends LoggerBase implements MethodInterceptor, Serializable { 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | *
 32 | 	 * cglib生成的子类实例
 33 | 	 * 
34 | * 35 | * @param supperClass 36 | * @return 37 | */ 38 | public static Object getInstance(Class supperClass) { 39 | Enhancer enhancer = new Enhancer(); 40 | //enhancer.setClassLoader(Thread.currentThread().getContextClassLoader()); 41 | enhancer.setSuperclass(supperClass); 42 | enhancer.setCallback(new Interceptor()); 43 | enhancer.setUseCache(false); 44 | Object dest = enhancer.create(); 45 | //logger.info(dest.toString()); 46 | return dest; 47 | } 48 | 49 | @Override 50 | public Object intercept(Object target, Method method, Object[] args, MethodProxy proxy) throws Throwable { 51 | return null; 52 | // 53 | // boolean proceeded = false; 54 | // Object result = null; 55 | // Set interceptors = null; 56 | // PostValidate postValidateAnn = method.getAnnotation(PostValidate.class); 57 | // if (postValidateAnn != null) { 58 | // interceptors = new LinkedHashSet(); 59 | // String postValidatorName = postValidateAnn.value(); 60 | // if (!Utils.hasLength(postValidatorName)) 61 | // postValidatorName = WebSettings.getValidator(); 62 | // 63 | // if (Utils.hasLength(postValidatorName)) { 64 | // interceptors.add(postValidatorName); 65 | // } 66 | // } 67 | // 68 | // Handled handleAnnotation = method.getAnnotation(Handled.class); 69 | // if (handleAnnotation != null) { 70 | // if (interceptors == null) 71 | // interceptors = new LinkedHashSet(); 72 | // String[] handlerNames = handleAnnotation.value(); 73 | // 74 | // if (!Utils.hasLength(handlerNames)) { 75 | // //经过cglib生成的子类,其父类才是 76 | // String className = SpringUtils.getBeanName(target.getClass()); 77 | // handlerNames = new String[] { className + "_" + method.getName() }; 78 | // } 79 | // 80 | // interceptors = Utils.arrayToLinkSet(interceptors, handlerNames); 81 | // } 82 | // 83 | // if (Utils.hasLength(interceptors)) { 84 | // JoinPoint_Cglib joinPoint_Cglib = new JoinPoint_Cglib(target, method, args, proxy); 85 | // for (String handlerName : interceptors) { 86 | // if (!Utils.hasLength(handlerName)) 87 | // continue; 88 | // if (!joinPoint_Cglib.doNext) 89 | // break; 90 | // Object bean = SpringUtils.bean(handlerName); 91 | // if (bean != null && bean instanceof Handler) { 92 | // Handler handler = (Handler) bean; 93 | // result = handler.proceed(joinPoint_Cglib); 94 | // proceeded = true; 95 | // } 96 | // } 97 | // if (joinPoint_Cglib.doNext && !joinPoint_Cglib.invoked) { 98 | // return proxy.invokeSuper(target, args); 99 | // } 100 | // } 101 | // 102 | // if (!proceeded) 103 | // result = proxy.invokeSuper(target, args); 104 | // return result; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/ParserUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-30 21 | */ 22 | package com.helpinput.spring; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | import com.github.javaparser.ast.CompilationUnit; 28 | import com.github.javaparser.ast.Node; 29 | import com.github.javaparser.ast.body.BodyDeclaration; 30 | import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; 31 | import com.github.javaparser.ast.body.FieldDeclaration; 32 | import com.github.javaparser.ast.body.TypeDeclaration; 33 | import com.helpinput.core.Utils; 34 | import org.slf4j.Logger; 35 | import com.helpinput.core.LoggerBase; 36 | 37 | public class ParserUtils { 38 | static Logger logger = LoggerBase.logger; 39 | 40 | public static String getPackageName(CompilationUnit cu) { 41 | return cu.getPackage().getName().toString(); 42 | } 43 | 44 | public static ClassOrInterfaceDeclaration getClassName(CompilationUnit cu) { 45 | List types = cu.getTypes(); 46 | if (Utils.hasLength(types)) { 47 | TypeDeclaration real = types.get(0); 48 | if (real instanceof ClassOrInterfaceDeclaration) { 49 | ClassOrInterfaceDeclaration rl = (ClassOrInterfaceDeclaration) real; 50 | return rl; 51 | } 52 | } 53 | return null; 54 | } 55 | 56 | public static BodyDeclaration getBody(CompilationUnit cu) { 57 | List nodes = cu.getChildrenNodes(); 58 | for (Node node : nodes) { 59 | if (node instanceof BodyDeclaration) { 60 | return (BodyDeclaration) node; 61 | } 62 | } 63 | return null; 64 | } 65 | 66 | public static List getFields(CompilationUnit cu) { 67 | List result = new ArrayList<>(); 68 | BodyDeclaration body = getBody(cu); 69 | if (body != null) { 70 | List nodes = body.getChildrenNodes(); 71 | for (Node node : nodes) { 72 | if (node instanceof FieldDeclaration) { 73 | result.add((FieldDeclaration) node); 74 | } 75 | 76 | } 77 | } 78 | return result; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/ScanedType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-7-1 21 | */ 22 | package com.helpinput.spring; 23 | 24 | public enum ScanedType { 25 | SAME(0), NEW(1), DELETED(2); 26 | 27 | private int value; 28 | 29 | ScanedType(int value) { 30 | this.value = value; 31 | } 32 | 33 | public int getValue() { 34 | return this.value; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/SourceFileMonitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-16 21 | */ 22 | package com.helpinput.spring; 23 | 24 | import java.util.List; 25 | import java.util.concurrent.ThreadFactory; 26 | 27 | import org.springframework.context.ApplicationContext; 28 | 29 | import com.helpinput.settings.Options; 30 | 31 | 32 | public class SourceFileMonitor implements Runnable { 33 | 34 | private SourceScaner scaner; 35 | 36 | private Thread thread = null; 37 | private ThreadFactory threadFactory; 38 | private volatile boolean running = false; 39 | 40 | public boolean isRunning() { 41 | return running; 42 | } 43 | 44 | public SourceFileMonitor( List dirs, ApplicationContext applicationContext) { 45 | scaner = new SourceScaner(dirs, applicationContext); 46 | } 47 | 48 | public synchronized void setThreadFactory(ThreadFactory threadFactory) { 49 | this.threadFactory = threadFactory; 50 | } 51 | 52 | public synchronized void start() throws Exception { 53 | if (running) { 54 | throw new IllegalStateException("Monitor is already running"); 55 | } 56 | 57 | running = true; 58 | if (threadFactory != null) { 59 | thread = threadFactory.newThread(this); 60 | } 61 | else { 62 | thread = new Thread(this); 63 | } 64 | thread.start(); 65 | } 66 | 67 | public synchronized void stop() throws Exception { 68 | stop(Options.scanInterval); 69 | } 70 | 71 | public synchronized void stop(long stopInterval) throws Exception { 72 | if (running == false) { 73 | throw new IllegalStateException("Monitor is not running"); 74 | } 75 | running = false; 76 | try { 77 | thread.join(stopInterval); 78 | } 79 | catch (InterruptedException e) { 80 | Thread.currentThread().interrupt(); 81 | } 82 | 83 | scaner.stop(); 84 | } 85 | 86 | public void run() { 87 | while (running) { 88 | scaner.scanSource(); 89 | if (!running) { 90 | break; 91 | } 92 | try { 93 | Thread.sleep(Options.scanInterval); 94 | } 95 | catch (final InterruptedException ignored) { 96 | } 97 | } 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/proxy/OptimizeTransactionProxyFactoryBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-7-3 21 | */ 22 | package com.helpinput.spring.proxy; 23 | 24 | import org.springframework.aop.TargetSource; 25 | import org.springframework.aop.framework.ProxyFactory; 26 | import org.springframework.aop.framework.adapter.AdvisorAdapterRegistry; 27 | import org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry; 28 | import org.springframework.beans.factory.FactoryBeanNotInitializedException; 29 | import org.springframework.transaction.interceptor.TransactionProxyFactoryBean; 30 | import org.springframework.util.ClassUtils; 31 | 32 | @SuppressWarnings("serial") 33 | public class OptimizeTransactionProxyFactoryBean extends TransactionProxyFactoryBean { 34 | private Object target; 35 | 36 | private Class[] proxyInterfaces; 37 | 38 | private Object[] preInterceptors; 39 | 40 | private Object[] postInterceptors; 41 | 42 | /** Default is global AdvisorAdapterRegistry */ 43 | private AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance(); 44 | 45 | 46 | private Object proxy; 47 | 48 | @Override 49 | public void setTarget(Object target) { 50 | this.target = target; 51 | } 52 | 53 | @Override 54 | public void setProxyInterfaces(Class[] proxyInterfaces) { 55 | this.proxyInterfaces = proxyInterfaces; 56 | } 57 | 58 | @Override 59 | public void setPreInterceptors(Object[] preInterceptors) { 60 | this.preInterceptors = preInterceptors; 61 | } 62 | 63 | @Override 64 | public void setPostInterceptors(Object[] postInterceptors) { 65 | this.postInterceptors = postInterceptors; 66 | } 67 | 68 | @Override 69 | public void setAdvisorAdapterRegistry(AdvisorAdapterRegistry advisorAdapterRegistry) { 70 | this.advisorAdapterRegistry = advisorAdapterRegistry; 71 | } 72 | 73 | public void afterPropertiesSet() { 74 | if (this.target == null) { 75 | throw new IllegalArgumentException("Property 'target' is required"); 76 | } 77 | if (this.target instanceof String) { 78 | throw new IllegalArgumentException("'target' needs to be a bean reference, not a bean name as value"); 79 | } 80 | 81 | 82 | ClassLoader proxyClassLoader=target.getClass().getClassLoader(); 83 | 84 | ProxyFactory proxyFactory = new ProxyFactory(); 85 | 86 | if (this.preInterceptors != null) { 87 | for (Object interceptor : this.preInterceptors) { 88 | proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(interceptor)); 89 | } 90 | } 91 | 92 | // Add the main interceptor (typically an Advisor). 93 | proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(createMainInterceptor())); 94 | 95 | if (this.postInterceptors != null) { 96 | for (Object interceptor : this.postInterceptors) { 97 | proxyFactory.addAdvisor(this.advisorAdapterRegistry.wrap(interceptor)); 98 | } 99 | } 100 | 101 | proxyFactory.copyFrom(this); 102 | 103 | TargetSource targetSource = createTargetSource(this.target); 104 | proxyFactory.setTargetSource(targetSource); 105 | 106 | if (this.proxyInterfaces != null) { 107 | proxyFactory.setInterfaces(this.proxyInterfaces); 108 | } 109 | else if (!isProxyTargetClass()) { 110 | // Rely on AOP infrastructure to tell us what interfaces to proxy. 111 | proxyFactory.setInterfaces(ClassUtils.getAllInterfacesForClass(targetSource.getTargetClass(), 112 | proxyClassLoader)); 113 | } 114 | 115 | /** 116 | * use this option to let proxyFactory user cglib to create proxy,otherwise in dynamic script ,this is no dynamic interface 117 | * 使用这个选荋 将使用cglib 产生代理类,否则在动动的java中,没有动态的接口 118 | */ 119 | proxyFactory.setOptimize(true); 120 | this.proxy = proxyFactory.getProxy(proxyClassLoader); 121 | } 122 | 123 | public Object getObject() { 124 | if (this.proxy == null) { 125 | throw new FactoryBeanNotInitializedException(); 126 | } 127 | return this.proxy; 128 | } 129 | 130 | public Class getObjectType() { 131 | if (this.proxy != null) { 132 | return this.proxy.getClass(); 133 | } 134 | if (this.proxyInterfaces != null && this.proxyInterfaces.length == 1) { 135 | return this.proxyInterfaces[0]; 136 | } 137 | if (this.target instanceof TargetSource) { 138 | return ((TargetSource) this.target).getTargetClass(); 139 | } 140 | if (this.target != null) { 141 | return this.target.getClass(); 142 | } 143 | return null; 144 | } 145 | 146 | } 147 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/refresher/CommonRefresher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-7-3 21 | */ 22 | package com.helpinput.spring.refresher; 23 | 24 | import javax.inject.Named; 25 | 26 | @Named 27 | public abstract class CommonRefresher implements ContextRefresher{ 28 | 29 | } 30 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/refresher/ContextRefresher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-30 21 | */ 22 | package com.helpinput.spring.refresher; 23 | 24 | import java.util.Map; 25 | 26 | import org.springframework.context.ApplicationContext; 27 | 28 | import com.helpinput.spring.ScanedType; 29 | 30 | public interface ContextRefresher { 31 | public void refresh(ApplicationContext context,Map, ScanedType> refreshedClass) ; 32 | } 33 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/refresher/SessiontRefresher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-27 21 | */ 22 | package com.helpinput.spring.refresher; 23 | 24 | import java.lang.reflect.Method; 25 | import java.util.HashSet; 26 | import java.util.List; 27 | import java.util.Map; 28 | import java.util.Map.Entry; 29 | import java.util.Set; 30 | 31 | import javax.persistence.Entity; 32 | 33 | import org.hibernate.SessionFactory; 34 | import org.slf4j.Logger; 35 | import org.springframework.beans.MutablePropertyValues; 36 | import org.springframework.beans.PropertyValue; 37 | import org.springframework.beans.PropertyValues; 38 | import org.springframework.beans.factory.config.BeanDefinition; 39 | import org.springframework.beans.factory.config.TypedStringValue; 40 | import org.springframework.beans.factory.support.BeanDefinitionBuilder; 41 | import org.springframework.beans.factory.support.DefaultListableBeanFactory; 42 | import org.springframework.beans.factory.support.ManagedList; 43 | import org.springframework.context.ApplicationContext; 44 | import org.springframework.context.support.AbstractApplicationContext; 45 | import org.springframework.util.ClassUtils; 46 | 47 | import com.helpinput.core.LoggerBase; 48 | import com.helpinput.core.Utils; 49 | import com.helpinput.spring.ScanedType; 50 | public class SessiontRefresher implements ContextRefresher { 51 | static Logger logger = LoggerBase.logger; 52 | 53 | @SuppressWarnings("unchecked") 54 | ManagedList getManageList(DefaultListableBeanFactory dlbf, PropertyValue oldPropertyValue) { 55 | Set oldClasses = null; 56 | 57 | if (oldPropertyValue != null) { 58 | Object value = oldPropertyValue.getValue(); 59 | if (value != null && value instanceof ManagedList) { 60 | ManagedList real = (ManagedList) value; 61 | oldClasses = new HashSet<>(real.size() >>> 1); 62 | ClassLoader parentClassLoader = ClassUtils.getDefaultClassLoader(); 63 | for (Object object : real) { 64 | TypedStringValue typedStringValue = (TypedStringValue) object; 65 | String className = typedStringValue.getValue(); 66 | try { 67 | parentClassLoader.loadClass(className); 68 | oldClasses.add(className); 69 | } 70 | catch (ClassNotFoundException e) { 71 | } 72 | } 73 | } 74 | } 75 | 76 | 77 | int oldClassSize = (Utils.hasLength(oldClasses) ? oldClasses.size() : 0); 78 | Map beans = dlbf.getBeansWithAnnotation(Entity.class); 79 | HashSet totalClasses = new HashSet<>(beans.size() + oldClassSize); 80 | if (oldClassSize > 0) { 81 | totalClasses.addAll(oldClasses); 82 | } 83 | 84 | for (Object entity : beans.values()) { 85 | String clzName = entity.getClass().getName(); 86 | if (!totalClasses.contains(clzName)) { 87 | totalClasses.add(clzName); 88 | } 89 | } 90 | 91 | ManagedList list = new ManagedList<>(totalClasses.size()); 92 | for (String clzName : totalClasses) { 93 | TypedStringValue typedStringValue = new TypedStringValue(clzName); 94 | list.add(typedStringValue); 95 | } 96 | return list; 97 | } 98 | 99 | @Override 100 | public void refresh(ApplicationContext context, Map, ScanedType> scanedClasses) { 101 | 102 | boolean needRefreshSessionFactory = false; 103 | for (Entry, ScanedType> entry : scanedClasses.entrySet()) { 104 | if (entry.getValue().getValue() > ScanedType.SAME.getValue() 105 | && entry.getKey().getAnnotation(Entity.class) != null) { 106 | needRefreshSessionFactory = true; 107 | break; 108 | } 109 | } 110 | if (needRefreshSessionFactory) { 111 | DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory) ((AbstractApplicationContext) context) 112 | .getBeanFactory(); 113 | 114 | //testUserManager(dlbf); 115 | 116 | final String sessionFactory = "sessionFactory"; 117 | final String annotatedClasses = "annotatedClasses"; 118 | final String setSessionFactory = "setSessionFactory"; 119 | 120 | BeanDefinition oldSessionFactoryDef = dlbf.getBeanDefinition(sessionFactory); 121 | 122 | if (oldSessionFactoryDef != null) { 123 | dlbf.removeBeanDefinition(sessionFactory); 124 | MutablePropertyValues propertyValues = oldSessionFactoryDef.getPropertyValues(); 125 | PropertyValue oldPropertyValue = propertyValues.getPropertyValue(annotatedClasses); 126 | 127 | propertyValues.removePropertyValue(annotatedClasses); 128 | 129 | BeanDefinition newSessionFactoryDef = BeanDefinitionBuilder.rootBeanDefinition( 130 | oldSessionFactoryDef.getBeanClassName()).getBeanDefinition(); 131 | 132 | List propertyValueList = newSessionFactoryDef.getPropertyValues().getPropertyValueList(); 133 | 134 | propertyValueList.addAll(propertyValues.getPropertyValueList()); 135 | propertyValueList.add(new PropertyValue(annotatedClasses, getManageList(dlbf, oldPropertyValue))); 136 | 137 | dlbf.registerBeanDefinition(sessionFactory, newSessionFactoryDef); 138 | 139 | SessionFactory sessionFactoryImpl = (SessionFactory) dlbf.getBean(sessionFactory); 140 | 141 | String[] beanNames = dlbf.getBeanDefinitionNames(); 142 | for (String beanName : beanNames) { 143 | BeanDefinition beanDefinition = dlbf.getBeanDefinition(beanName); 144 | 145 | PropertyValues pValues = beanDefinition.getPropertyValues(); 146 | if (pValues.getPropertyValue(sessionFactory) != null) { 147 | Object theBean = dlbf.getBean(beanName); 148 | Method method = Utils.findMethod(theBean, setSessionFactory, sessionFactoryImpl); 149 | if (method != null) 150 | Utils.InvokedMethod(theBean, method, sessionFactoryImpl); 151 | } 152 | } 153 | } 154 | } 155 | } 156 | 157 | } 158 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/refresher/mvc/MvcContextRefresher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-27 21 | */ 22 | package com.helpinput.spring.refresher.mvc; 23 | 24 | import java.lang.reflect.Field; 25 | import java.lang.reflect.Method; 26 | import java.util.List; 27 | import java.util.Map; 28 | import java.util.Map.Entry; 29 | 30 | import org.slf4j.Logger; 31 | import org.springframework.beans.factory.support.DefaultListableBeanFactory; 32 | import org.springframework.context.ApplicationContext; 33 | import org.springframework.context.support.AbstractApplicationContext; 34 | import org.springframework.stereotype.Controller; 35 | import org.springframework.web.servlet.HandlerInterceptor; 36 | import org.springframework.web.servlet.handler.AbstractHandlerMapping; 37 | import org.springframework.web.servlet.handler.MappedInterceptor; 38 | 39 | import com.helpinput.core.LoggerBase; 40 | import com.helpinput.core.Utils; 41 | import com.helpinput.spring.ScanedType; 42 | import com.helpinput.spring.refresher.ContextRefresher; 43 | 44 | public class MvcContextRefresher implements ContextRefresher { 45 | static Logger logger = LoggerBase.logger; 46 | 47 | @Override 48 | public void refresh(ApplicationContext context, Map, ScanedType> scanedClasses) { 49 | 50 | boolean needUpdateHandlerMapping = false; 51 | boolean needUpdateInterceptor = false; 52 | 53 | for (Entry, ScanedType> entry : scanedClasses.entrySet()) { 54 | if ((entry.getValue().getValue() > ScanedType.SAME.getValue()) 55 | && entry.getKey().getAnnotation(Controller.class) != null) { 56 | needUpdateHandlerMapping = true; 57 | break; 58 | } 59 | } 60 | 61 | for (Entry, ScanedType> entry : scanedClasses.entrySet()) { 62 | if ((entry.getValue().getValue() > ScanedType.SAME.getValue()) 63 | && HandlerInterceptor.class.isAssignableFrom(entry.getKey())) { 64 | needUpdateInterceptor = true; 65 | break; 66 | } 67 | } 68 | 69 | if (needUpdateInterceptor) { 70 | DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory) ((AbstractApplicationContext) context) 71 | .getBeanFactory(); 72 | Map mappings = dlbf.getBeansOfType(AbstractHandlerMapping.class); 73 | 74 | if (Utils.hasLength(mappings)) { 75 | Field interceptorsField = Utils.findField(AbstractHandlerMapping.class, "interceptors"); 76 | Field mappedInterceptorsFeild = Utils.findField(AbstractHandlerMapping.class, "mappedInterceptors"); 77 | Method initApplicationContext = Utils 78 | .findMethod(AbstractHandlerMapping.class, "initApplicationContext"); 79 | if (interceptorsField != null && mappedInterceptorsFeild != null && initApplicationContext != null) { 80 | for (AbstractHandlerMapping mapping : mappings.values()) { 81 | synchronized (mapping) { 82 | final List interceptors = Utils.getFieldValue(mapping, interceptorsField); 83 | if (Utils.hasLength(interceptors)) 84 | interceptors.clear(); 85 | final List mappedInterceptors = Utils.getFieldValue(mapping, 86 | mappedInterceptorsFeild); 87 | if (Utils.hasLength(mappedInterceptors)) 88 | mappedInterceptors.clear(); 89 | Utils.InvokedMethod(mapping, initApplicationContext); 90 | } 91 | } 92 | } 93 | } 94 | } 95 | 96 | if (needUpdateHandlerMapping) { 97 | final String mapName = "org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0"; 98 | Object mappingHandler = context.getBean(mapName); 99 | if (mappingHandler != null) { 100 | Method method = Utils.findMethod(mappingHandler, "initHandlerMethods"); 101 | Map handlerMethods = Utils.getFieldValue(mappingHandler, "handlerMethods"); 102 | Map urlMap = Utils.getFieldValue(mappingHandler, "urlMap"); 103 | if (method != null && handlerMethods != null && urlMap != null) { 104 | synchronized (mappingHandler) { 105 | handlerMethods.clear(); 106 | urlMap.clear(); 107 | Utils.InvokedMethod(mappingHandler, method); 108 | } 109 | } 110 | } 111 | } 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/refresher/web/WebContextRefresher.java: -------------------------------------------------------------------------------- 1 | package com.helpinput.spring.refresher.web; 2 | 3 | public class WebContextRefresher { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/registinerceptor/AbstractBeanRegistInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-7-7 21 | */ 22 | package com.helpinput.spring.registinerceptor; 23 | 24 | import static com.helpinput.spring.Consts.application_scope; 25 | import static com.helpinput.spring.Consts.singleton_scope; 26 | 27 | import org.springframework.beans.factory.support.DefaultListableBeanFactory; 28 | 29 | public abstract class AbstractBeanRegistInterceptor implements BeanRegistInterceptor { 30 | protected String beanNameSuffix = "$$$$"; 31 | 32 | @Override 33 | public boolean afterRemove(Class clz, String beanName, String scope, DefaultListableBeanFactory dlbf) { 34 | if (getCondition(clz)) { 35 | String refBeanName = beanName + beanNameSuffix; 36 | if (application_scope.equals(scope)) 37 | dlbf.destroyScopedBean(refBeanName); 38 | else if (singleton_scope.equals(scope)) 39 | dlbf.destroySingleton(refBeanName); 40 | dlbf.removeBeanDefinition(refBeanName); 41 | return true; 42 | } 43 | return false; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/registinerceptor/BeanRegistInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-7-7 21 | */ 22 | package com.helpinput.spring.registinerceptor; 23 | 24 | import org.springframework.beans.factory.config.BeanDefinition; 25 | import org.springframework.beans.factory.support.BeanDefinitionBuilder; 26 | import org.springframework.beans.factory.support.DefaultListableBeanFactory; 27 | 28 | public interface BeanRegistInterceptor { 29 | BeanDefinition beforeRegist(Class clz, String beanName, String scope, DefaultListableBeanFactory dlbf, 30 | BeanDefinitionBuilder builder); 31 | 32 | boolean afterRemove(Class clz, String beanName, String scope, DefaultListableBeanFactory dlbf); 33 | 34 | boolean getCondition(Class clz); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/registinerceptor/ProxybeanRegistInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-7-6 21 | */ 22 | package com.helpinput.spring.registinerceptor; 23 | 24 | import java.util.List; 25 | 26 | import org.springframework.beans.PropertyValue; 27 | import org.springframework.beans.factory.config.BeanDefinition; 28 | import org.springframework.beans.factory.config.RuntimeBeanReference; 29 | import org.springframework.beans.factory.support.BeanDefinitionBuilder; 30 | import org.springframework.beans.factory.support.DefaultListableBeanFactory; 31 | import org.springframework.beans.factory.support.GenericBeanDefinition; 32 | 33 | import com.helpinput.annotation.Parent; 34 | import com.helpinput.core.Utils; 35 | import com.helpinput.spring.BeanRegister; 36 | 37 | public class ProxybeanRegistInterceptor extends AbstractBeanRegistInterceptor { 38 | 39 | @Override 40 | public BeanDefinition beforeRegist(Class clz, String beanName, String scope, DefaultListableBeanFactory dlbf, 41 | BeanDefinitionBuilder builder) { 42 | BeanDefinition bd = null; 43 | 44 | if (getCondition(clz)){ 45 | Parent ann=clz.getAnnotation(Parent.class); 46 | String parentName = ann.value(); 47 | String property = ann.property(); 48 | if (Utils.hasLength(parentName) && Utils.hasLength(property)) { 49 | 50 | BeanDefinition parent = (GenericBeanDefinition) dlbf.getBeanDefinition(parentName); 51 | if (parent != null) { 52 | String baseBeanName = beanName + "$$$$"; 53 | BeanRegister.removeBean(dlbf, null, baseBeanName); 54 | BeanDefinition basebd = builder.getBeanDefinition(); 55 | basebd.setScope(scope); 56 | dlbf.registerBeanDefinition(baseBeanName, basebd); 57 | 58 | bd = new GenericBeanDefinition(); 59 | 60 | bd.setParentName(parentName); 61 | List propertyValueList = bd.getPropertyValues().getPropertyValueList(); 62 | RuntimeBeanReference reference = new RuntimeBeanReference(baseBeanName); 63 | PropertyValue pValue = new PropertyValue(property, reference); 64 | propertyValueList.add(pValue); 65 | 66 | //dlbf.getBean(baseBeanName); 67 | return bd; 68 | } 69 | } 70 | } 71 | return null; 72 | } 73 | 74 | @Override 75 | public boolean getCondition(Class clz) { 76 | return clz.getAnnotation(Parent.class)!=null; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/registinerceptor/mvc/UrlInterceptorBeanRegistInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-7-7 21 | */ 22 | package com.helpinput.spring.registinerceptor.mvc; 23 | 24 | import org.slf4j.Logger; 25 | import org.springframework.beans.factory.config.BeanDefinition; 26 | import org.springframework.beans.factory.config.RuntimeBeanReference; 27 | import org.springframework.beans.factory.support.BeanDefinitionBuilder; 28 | import org.springframework.beans.factory.support.DefaultListableBeanFactory; 29 | import org.springframework.beans.factory.support.ManagedList; 30 | import org.springframework.beans.factory.support.RootBeanDefinition; 31 | import org.springframework.web.servlet.HandlerInterceptor; 32 | import org.springframework.web.servlet.handler.MappedInterceptor; 33 | 34 | import com.helpinput.annotation.Mapping; 35 | import com.helpinput.annotation.MappingExclude; 36 | import com.helpinput.core.LoggerBase; 37 | import com.helpinput.core.Utils; 38 | import com.helpinput.spring.registinerceptor.BeanRegistInterceptor; 39 | 40 | public class UrlInterceptorBeanRegistInterceptor implements BeanRegistInterceptor { 41 | static Logger logger = LoggerBase.logger; 42 | 43 | @Override 44 | public BeanDefinition beforeRegist(Class clz, String beanName, String scope, DefaultListableBeanFactory dlbf, 45 | BeanDefinitionBuilder builder) { 46 | if (getCondition(clz)) { 47 | String refDefname = beanName + "$$$$"; 48 | 49 | RootBeanDefinition refDef = new RootBeanDefinition(); 50 | refDef.setBeanClass(clz); 51 | refDef.setScope(scope); 52 | dlbf.registerBeanDefinition(refDefname, refDef); 53 | 54 | RootBeanDefinition mappedInterceptorDef = new RootBeanDefinition(MappedInterceptor.class); 55 | mappedInterceptorDef.setScope(scope); 56 | 57 | ManagedList includePatterns = null; 58 | ManagedList excludePatterns = null; 59 | Object interceptorBean; 60 | 61 | Mapping mapAnn = clz.getAnnotation(Mapping.class); 62 | if (mapAnn != null) { 63 | String[] includes = mapAnn.value(); 64 | if (Utils.hasLength(includes)) { 65 | includePatterns = new ManagedList<>(includes.length); 66 | for (String s : includes) 67 | includePatterns.add(s); 68 | } 69 | } 70 | 71 | MappingExclude unMapAnn = clz.getAnnotation(MappingExclude.class); 72 | if (unMapAnn != null) { 73 | String[] excludes = unMapAnn.value(); 74 | if (Utils.hasLength(excludes)) { 75 | excludePatterns = new ManagedList<>(excludes.length); 76 | for (String s : excludes) 77 | excludePatterns.add(s); 78 | } 79 | } 80 | 81 | interceptorBean = new RuntimeBeanReference(refDefname); 82 | mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(0, includePatterns); 83 | mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(1, excludePatterns); 84 | mappedInterceptorDef.getConstructorArgumentValues().addIndexedArgumentValue(2, interceptorBean); 85 | return mappedInterceptorDef; 86 | } 87 | return null; 88 | } 89 | 90 | @Override 91 | public boolean afterRemove(Class clz, String beanName, String scope, DefaultListableBeanFactory dlbf) { 92 | // TODO Auto-generated method stub 93 | return false; 94 | } 95 | 96 | @Override 97 | public boolean getCondition(Class clz) { 98 | return HandlerInterceptor.class.isAssignableFrom(clz); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/servlet/mvc/EnhanceDispachServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-20 21 | */ 22 | package com.helpinput.spring.servlet.mvc; 23 | 24 | import org.slf4j.Logger; 25 | import org.springframework.beans.BeanUtils; 26 | import org.springframework.context.ApplicationContext; 27 | import org.springframework.context.ApplicationContextException; 28 | import org.springframework.web.context.ConfigurableWebApplicationContext; 29 | import org.springframework.web.context.WebApplicationContext; 30 | import org.springframework.web.servlet.DispatcherServlet; 31 | 32 | import com.helpinput.core.LoggerBase; 33 | import com.helpinput.holder.ContextHolder; 34 | import com.helpinput.spring.registinerceptor.mvc.UrlInterceptorBeanRegistInterceptor; 35 | 36 | @SuppressWarnings("serial") 37 | public class EnhanceDispachServlet extends DispatcherServlet { 38 | static Logger logger = LoggerBase.logger; 39 | 40 | @Override 41 | protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) { 42 | ContextHolder.beanRegistIntercpterHolder.register(new UrlInterceptorBeanRegistInterceptor()); 43 | 44 | Class contextClass = getContextClass(); 45 | if (logger.isDebugEnabled()) { 46 | logger.debug("Servlet with name '" + getServletName() 47 | + "' will try to create custom WebApplicationContext context of class '" + contextClass.getName() 48 | + "'" + ", using parent context [" + parent + "]"); 49 | } 50 | if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) { 51 | throw new ApplicationContextException("Fatal initialization error in servlet with name '" 52 | + getServletName() + "': custom WebApplicationContext class [" + contextClass.getName() 53 | + "] is not of type ConfigurableWebApplicationContext"); 54 | } 55 | ConfigurableWebApplicationContext wac; 56 | if (parent instanceof ConfigurableWebApplicationContext) 57 | wac = (ConfigurableWebApplicationContext) parent; 58 | else { 59 | wac = (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass); 60 | wac.setEnvironment(getEnvironment()); 61 | wac.setParent(parent); 62 | wac.setConfigLocation(getContextConfigLocation()); 63 | configureAndRefreshWebApplicationContext(wac); 64 | } 65 | return wac; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/support/ClassLoaderHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-30 21 | */ 22 | package com.helpinput.spring.support; 23 | 24 | 25 | import groovy.lang.HiGroovyClassLoader; 26 | 27 | public class ClassLoaderHolder { 28 | public static HiGroovyClassLoader gcl = new HiGroovyClassLoader(); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /2-hi-spring-dynamic/src/main/java/com/helpinput/spring/support/SourceFileMonitorListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013-2015 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-16 21 | */ 22 | package com.helpinput.spring.support; 23 | 24 | import java.util.List; 25 | 26 | import org.slf4j.Logger; 27 | import org.springframework.beans.factory.support.DefaultListableBeanFactory; 28 | import org.springframework.context.ApplicationContext; 29 | import org.springframework.context.ApplicationListener; 30 | import org.springframework.context.event.ContextRefreshedEvent; 31 | import org.springframework.context.support.AbstractApplicationContext; 32 | 33 | import com.helpinput.core.LoggerBase; 34 | import com.helpinput.holder.ContextHolder; 35 | import com.helpinput.propertyeditors.GLClassEditor; 36 | import com.helpinput.propertyeditors.PropertyEditorRegister; 37 | import com.helpinput.settings.Options; 38 | import com.helpinput.spring.SourceFileMonitor; 39 | import com.helpinput.spring.registinerceptor.ProxybeanRegistInterceptor; 40 | 41 | public class SourceFileMonitorListener implements ApplicationListener { 42 | static Logger logger = LoggerBase.logger; 43 | SourceFileMonitor monitor = null; 44 | 45 | private List dirs = null; 46 | 47 | @Override 48 | public void onApplicationEvent(ContextRefreshedEvent event) { 49 | ContextHolder.beanRegistIntercpterHolder.register(new ProxybeanRegistInterceptor()); 50 | 51 | ApplicationContext applicationContext = event.getApplicationContext(); 52 | DefaultListableBeanFactory dlbf = (DefaultListableBeanFactory) ((AbstractApplicationContext) applicationContext) 53 | .getBeanFactory(); 54 | 55 | PropertyEditorRegister.registerProtertyEditor(dlbf, GLClassEditor.class); 56 | //get root applicationContext 57 | while (applicationContext.getParent() != null) { 58 | applicationContext = applicationContext.getParent(); 59 | } 60 | 61 | if (monitor == null) 62 | monitor = new SourceFileMonitor(dirs, applicationContext); 63 | 64 | if (!monitor.isRunning()) { 65 | try { 66 | monitor.start(); 67 | } 68 | catch (Exception e) { 69 | e.printStackTrace(); 70 | } 71 | } 72 | 73 | } 74 | 75 | public void setInterval(long interval) { 76 | synchronized (Options.scanInterval) { 77 | Options.scanInterval = interval; 78 | } 79 | } 80 | 81 | public void setDirs(List dirs) { 82 | this.dirs = dirs; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/.mymetadata: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | 3-hi-spring-Dynamic-mvc-demo 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.common.project.facet.core.builder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.jsdt.core.javascriptValidator 15 | 16 | 17 | 18 | 19 | com.genuitec.eclipse.j2eedt.core.WebClasspathBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.jdt.core.javabuilder 25 | 26 | 27 | 28 | 29 | com.genuitec.eclipse.j2eedt.core.J2EEProjectValidator 30 | 31 | 32 | 33 | 34 | com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator 35 | 36 | 37 | 38 | 39 | org.eclipse.wst.validation.validationbuilder 40 | 41 | 42 | 43 | 44 | org.eclipse.m2e.core.maven2Builder 45 | 46 | 47 | 48 | 49 | com.genuitec.eclipse.ast.deploy.core.DeploymentBuilder 50 | 51 | 52 | 53 | 54 | 55 | com.genuitec.eclipse.ast.deploy.core.deploymentnature 56 | org.eclipse.m2e.core.maven2Nature 57 | org.eclipse.jem.workbench.JavaEMFNature 58 | com.genuitec.eclipse.j2eedt.core.webnature 59 | org.eclipse.jdt.core.javanature 60 | org.eclipse.wst.jsdt.core.jsNature 61 | org.eclipse.wst.common.project.facet.core.nature 62 | org.eclipse.wst.common.modulecore.ModuleCoreNature 63 | 64 | 65 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | 3 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/classes/config/spring/spring-beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 34 | 35 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/classes/config/spring/spring-common.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | org.hibernate.dialect.MySQLDialect 22 | update 23 | true 24 | true 25 | 26 | 27 | 28 | 29 | com.tgb.entity.User 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | 52 | 53 | PROPAGATION_REQUIRED,-Exception 54 | PROPAGATION_REQUIRED,-myException 55 | PROPAGATION_REQUIRED 56 | PROPAGATION_REQUIRED 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/classes/config/spring/spring-mvc.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 16 | 17 | 18 | /WEB-INF/script/**/*.java 19 | /WEB-INF/script/**/*.groovy 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/classes/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=info,stdout 2 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 3 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 4 | #dwr log config 5 | log4j.logger.uk.ltd.getahead.dwr= 6 | # Pattern to output the caller's file name and line number. 7 | log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%c:%L) %d{yyyy-MM-dd HH:mm:ss,SSS} ---- %m%n 8 | 9 | #log4j.appender.R=org.apache.log4j.RollingFileAppender 10 | #log4j.appender.R.File=D:\\logs\\web_log.log 11 | #log4j.appender.R.MaxFileSize=100KB 12 | 13 | # Keep one backup file 14 | #log4j.appender.R.MaxBackupIndex=100 15 | 16 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 17 | log4j.appender.R.layout.ConversionPattern=%p %d{yyyy-MM-dd HH\:mm\:ss,SSS} %n%t %c ---- %m%n 18 | #disable dwr log 19 | #log4j.logger.org.directwebremoting=ERROR -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/classes/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | %d{yyyy/MM/dd HH:mm:ss.SSS} %-5level [%thread] %n%msg%n%caller{20} 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | 20 | 21 | %d{yyyy/MM/dd HH:mm:ss.SSS} %-5level [%thread] %n%msg%n%caller{20} aaaaaaaaaaaaaaaaaaaaaaaaa 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/script/com/script/context/refreshers/CommonRefresher.java: -------------------------------------------------------------------------------- 1 | package com.script.context.refreshers; 2 | 3 | import java.util.Map; 4 | 5 | import org.springframework.context.ApplicationContext; 6 | 7 | import com.helpinput.spring.ScanedType; 8 | 9 | public class CommonRefresher extends com.helpinput.spring.refresher.CommonRefresher{ 10 | 11 | @Override 12 | public void refresh(ApplicationContext context, Map, ScanedType> refreshedClass) { 13 | // do some refrer here.... ,this is script , execute where update 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/script/com/script/context/refreshers/MvcContextRefresher.java: -------------------------------------------------------------------------------- 1 | package com.script.context.refreshers; 2 | 3 | import javax.inject.Named; 4 | 5 | //do not del this class if you use sping mvc framework 6 | //如果你使用 sping mvc 框架 ,不要删除这个类 7 | @Named 8 | public class MvcContextRefresher extends com.helpinput.spring.refresher.mvc.MvcContextRefresher { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/script/com/script/context/refreshers/SessiontRefresher.java: -------------------------------------------------------------------------------- 1 | package com.script.context.refreshers; 2 | 3 | import javax.inject.Named; 4 | 5 | //do not del this class if you use sping sessionfactry 6 | //如果你使用 sping sessionfactry,不要删除个类 7 | @Named 8 | public class SessiontRefresher extends com.helpinput.spring.refresher.SessiontRefresher{ 9 | 10 | } 11 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/script/com/script/dao/TeacherDao.java: -------------------------------------------------------------------------------- 1 | package com.script.dao; 2 | 3 | import java.util.List; 4 | 5 | import com.script.entity.Teacher; 6 | 7 | public interface TeacherDao { 8 | 9 | public Teacher getTeacher(String id); 10 | 11 | public List getAllTeacher(); 12 | 13 | public void addTeacher(Teacher teacher); 14 | 15 | public boolean delTeacher(String id); 16 | 17 | public boolean updateTeacher(Teacher teacher); 18 | } 19 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/script/com/script/dao/TeacherDaoImpl.java: -------------------------------------------------------------------------------- 1 | package com.script.dao; 2 | 3 | import java.util.List; 4 | 5 | import javax.annotation.Resource; 6 | 7 | import org.hibernate.Query; 8 | import org.hibernate.SessionFactory; 9 | import org.slf4j.Logger; 10 | 11 | import com.helpinput.core.LoggerBase; 12 | import com.script.entity.Teacher; 13 | public class TeacherDaoImpl implements TeacherDao { 14 | static Logger logger = LoggerBase.logger; 15 | 16 | @Resource 17 | private SessionFactory sessionFactory; 18 | 19 | public void setSessionFactory(SessionFactory sessionFactory) { 20 | this.sessionFactory = sessionFactory; 21 | } 22 | 23 | @Override 24 | public Teacher getTeacher(String id) { 25 | 26 | String hql = "from Teacher t where t.id=?"; 27 | Query query = sessionFactory.getCurrentSession().createQuery(hql); 28 | query.setString(0, id); 29 | 30 | return (Teacher)query.uniqueResult(); 31 | } 32 | 33 | @Override 34 | public List getAllTeacher() { 35 | 36 | 37 | String hql = "from Teacher"; 38 | Query query = sessionFactory.getCurrentSession().createQuery(hql); 39 | 40 | return query.list(); 41 | } 42 | 43 | @Override 44 | public void addTeacher(Teacher teacher) { 45 | sessionFactory.getCurrentSession().save(teacher); 46 | } 47 | 48 | @Override 49 | public boolean delTeacher(String id) { 50 | 51 | String hql = "delete Teacher t where t.id = ?"; 52 | Query query = sessionFactory.getCurrentSession().createQuery(hql); 53 | query.setString(0, id); 54 | 55 | return (query.executeUpdate() > 0); 56 | } 57 | 58 | @Override 59 | public boolean updateTeacher(Teacher teacher) { 60 | System.out.println(teacher.toString()); 61 | String hql = "update Teacher t set t.teacherName = ?,t.age=? ,t.birthday=? where t.id = ?"; 62 | Query query = sessionFactory.getCurrentSession().createQuery(hql); 63 | query.setString(0, teacher.getTeacherName()); 64 | query.setString(1, teacher.getAge()); 65 | query.setDate(2, teacher.getBirthday()); 66 | query.setString(3, teacher.getId()); 67 | 68 | return (query.executeUpdate() > 0); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/script/com/script/entity/Teacher.groovy: -------------------------------------------------------------------------------- 1 | package com.script.entity; 2 | 3 | import java.io.Serializable; 4 | import java.util.Date; 5 | 6 | import javax.persistence.Column; 7 | import javax.persistence.Entity; 8 | import javax.persistence.GeneratedValue; 9 | import javax.persistence.Id; 10 | import javax.persistence.Table; 11 | 12 | import org.hibernate.annotations.GenericGenerator; 13 | import org.springframework.context.annotation.Scope; 14 | 15 | import com.helpinput.annotation.Parent; 16 | import com.helpinput.annotation.Prototype; 17 | 18 | @Entity 19 | @Table(name="T_Teacher") 20 | @Prototype 21 | public class Teacher implements Serializable { 22 | 23 | @Id 24 | @GeneratedValue(generator="system-uuid") 25 | @GenericGenerator(name = "system-uuid",strategy="uuid") 26 | @Column(length=32) 27 | String id; 28 | 29 | @Column(length=32) 30 | String teacherName; 31 | 32 | @Column(length=32) 33 | String age; 34 | 35 | Date birthday; 36 | 37 | @Override 38 | public String toString() { 39 | return this.getClass().toString()+"[id:"+id+",teacherName:"+teacherName+",age:"+age+",birthday:"+birthday+"]"; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/script/com/script/interceptor/TeacherIntercepptor.java: -------------------------------------------------------------------------------- 1 | package com.script.interceptor; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.slf4j.Logger; 7 | import org.springframework.web.servlet.HandlerInterceptor; 8 | import org.springframework.web.servlet.ModelAndView; 9 | 10 | import com.helpinput.annotation.Mapping; 11 | import com.helpinput.annotation.MappingExclude; 12 | import com.helpinput.core.LoggerBase; 13 | 14 | /** 15 | * 动态拦截器 16 | * dyanmic interceptor 17 | */ 18 | @Mapping({ "/teacher/*" }) 19 | @MappingExclude("/login") 20 | public class TeacherIntercepptor implements HandlerInterceptor { 21 | static Logger logger = LoggerBase.logger; 22 | 23 | @Override 24 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 25 | String url = request.getRequestURL().toString(); 26 | logger.info("teacherIntercepptor preHandle........xxxxxxxxxxxxxx...................." + url); 27 | return true; 28 | } 29 | 30 | //在业务处理器处理请求执行完成后,生成视图之前执行的动作 31 | @Override 32 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, 33 | ModelAndView modelAndView) throws Exception { 34 | } 35 | 36 | @Override 37 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) 38 | throws Exception { 39 | } 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/script/com/script/manager/TeacherManager.java: -------------------------------------------------------------------------------- 1 | package com.script.manager; 2 | 3 | import java.util.List; 4 | 5 | import com.script.entity.Teacher; 6 | 7 | public interface TeacherManager { 8 | 9 | public Teacher getTeacher(String id); 10 | 11 | public List getAllTeacher(); 12 | 13 | public void addTeacher(Teacher teacher); 14 | 15 | public boolean delTeacher(String id); 16 | 17 | public boolean updateTeacher(Teacher teacher); 18 | } 19 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/script/com/script/manager/TeacherManagerImpl.java: -------------------------------------------------------------------------------- 1 | package com.script.manager; 2 | 3 | import java.util.List; 4 | 5 | import javax.annotation.Resource; 6 | 7 | import com.helpinput.annotation.Parent; 8 | import com.script.dao.TeacherDao; 9 | import com.script.entity.Teacher; 10 | 11 | @Parent("transactionProxy") 12 | public class TeacherManagerImpl implements TeacherManager { 13 | 14 | @Resource 15 | private TeacherDao teacherDao; 16 | 17 | public void setTeacherDao(TeacherDao teacherDao) { 18 | this.teacherDao = teacherDao; 19 | } 20 | 21 | @Override 22 | public Teacher getTeacher(String id) { 23 | return teacherDao.getTeacher(id); 24 | } 25 | 26 | @Override 27 | public List getAllTeacher() { 28 | return teacherDao.getAllTeacher(); 29 | } 30 | 31 | @Override 32 | public void addTeacher(Teacher teacher) { 33 | teacherDao.addTeacher(teacher); 34 | } 35 | 36 | @Override 37 | public boolean delTeacher(String id) { 38 | return teacherDao.delTeacher(id); 39 | } 40 | 41 | @Override 42 | public boolean updateTeacher(Teacher teacher) { 43 | return teacherDao.updateTeacher(teacher); 44 | } 45 | 46 | public void test1() { 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/script/com/script/propertyEditors/DatePropertyEditor.java: -------------------------------------------------------------------------------- 1 | package com.script.propertyEditors; 2 | 3 | import java.beans.PropertyEditorSupport; 4 | 5 | import java.text.ParseException; 6 | import java.text.SimpleDateFormat; 7 | import java.util.Date; 8 | 9 | import com.helpinput.core.Utils; 10 | import com.helpinput.annotation.Property; 11 | import com.helpinput.annotation.Prototype; 12 | import com.helpinput.annotation.Properties; 13 | import com.helpinput.annotation.TargetType; 14 | import org.slf4j.Logger; 15 | import com.helpinput.core.LoggerBase; 16 | 17 | @Prototype 18 | @TargetType(Date.class) 19 | @Properties({ @Property(name = "format", value = "yyyy-MM-dd") }) 20 | // or @Property(name = "format", value = "yyyy-MM-dd") when has 1 setter 21 | public class DatePropertyEditor extends PropertyEditorSupport { 22 | static Logger logger = LoggerBase.logger; 23 | 24 | private String format = "yyyy-MM-dd"; 25 | 26 | public void setFormat(String format) { 27 | this.format = format; 28 | 29 | } 30 | 31 | public void setAsText(String text) throws IllegalArgumentException { 32 | if (Utils.hasLength(text) && Utils.hasLength(format)) { 33 | SimpleDateFormat sdf = new SimpleDateFormat(format); 34 | try { 35 | Date date = sdf.parse(text); 36 | this.setValue(date); 37 | return; 38 | } 39 | catch (ParseException e) { 40 | throw new IllegalArgumentException("data format error!"); 41 | } 42 | } 43 | setValue(null); 44 | } 45 | 46 | @Override 47 | public String getAsText() { 48 | if (Utils.hasLength(format)) { 49 | Object value = getValue(); 50 | if (value != null) { 51 | SimpleDateFormat sdf = new SimpleDateFormat(format); 52 | return sdf.format((Date) value); 53 | } 54 | } 55 | return ""; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/script/com/script/settings/IntervalSetting.java: -------------------------------------------------------------------------------- 1 | package com.script.settings; 2 | 3 | import javax.annotation.PostConstruct; 4 | 5 | import org.slf4j.Logger; 6 | import com.helpinput.core.LoggerBase; 7 | import com.helpinput.settings.Options; 8 | 9 | public class IntervalSetting { 10 | static Logger logger = LoggerBase.logger; 11 | 12 | //can overide the source monitor interval dynamic 13 | @PostConstruct 14 | public void setInteval() { 15 | Options.scanInterval = 6000L; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/script/com/script/web/TeacherController.java: -------------------------------------------------------------------------------- 1 | package com.script.web; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | import java.text.SimpleDateFormat; 6 | import java.util.Date; 7 | 8 | import javax.annotation.Resource; 9 | import javax.servlet.ServletException; 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | import org.slf4j.Logger; 14 | import org.springframework.beans.propertyeditors.CustomDateEditor; 15 | import org.springframework.context.annotation.Scope; 16 | import org.springframework.stereotype.Controller; 17 | import org.springframework.web.bind.WebDataBinder; 18 | import org.springframework.web.bind.annotation.InitBinder; 19 | import org.springframework.web.bind.annotation.RequestMapping; 20 | 21 | import com.helpinput.core.LoggerBase; 22 | import com.script.entity.Teacher; 23 | import com.script.manager.TeacherManager; 24 | import com.script.propertyEditors.DatePropertyEditor; 25 | 26 | @Controller 27 | @RequestMapping("/teacher") 28 | @Scope("request") 29 | public class TeacherController { 30 | static Logger logger = LoggerBase.logger; 31 | 32 | @Resource 33 | TeacherManager teacherManager; 34 | 35 | @RequestMapping("/getAllTeacher") 36 | public String getAllTeacher(HttpServletRequest request) { 37 | 38 | request.setAttribute("teacherList", teacherManager.getAllTeacher()); 39 | 40 | return "/teacherList"; 41 | } 42 | 43 | @RequestMapping("/getTeacher") 44 | public String getTeacher(String id, HttpServletRequest request) { 45 | 46 | request.setAttribute("teacher", teacherManager.getTeacher(id)); 47 | 48 | return "/editTeacher"; 49 | } 50 | 51 | @RequestMapping("/toAddTeacher") 52 | public String toAddTeacher() { 53 | return "/addTeacher"; 54 | } 55 | 56 | @RequestMapping("/addTeacher") 57 | public String addTeacher(Teacher teacher, HttpServletRequest request) { 58 | teacherManager.addTeacher(teacher); 59 | return "redirect:/teacher/getAllTeacher"; 60 | } 61 | 62 | @RequestMapping("/delTeacher") 63 | public void delTeacher(String id, HttpServletResponse response) { 64 | 65 | String result = "{\"result\":\"error\"}"; 66 | 67 | if (teacherManager.delTeacher(id)) { 68 | result = "{\"result\":\"success\"}"; 69 | } 70 | 71 | response.setContentType("application/json"); 72 | 73 | try { 74 | PrintWriter out = response.getWriter(); 75 | out.write(result); 76 | } 77 | catch (IOException e) { 78 | e.printStackTrace(); 79 | } 80 | } 81 | 82 | @RequestMapping("/updateTeacher") 83 | public String updateTeacher(Teacher teacher, HttpServletRequest request) { 84 | if (teacherManager.updateTeacher(teacher)) { 85 | teacher = teacherManager.getTeacher(teacher.getId()); 86 | request.setAttribute("teacher", teacher); 87 | return "redirect:/teacher/getAllTeacher"; 88 | } 89 | else { 90 | return "/error"; 91 | } 92 | } 93 | 94 | @InitBinder 95 | protected void initBinder(WebDataBinder binder) throws ServletException { 96 | 97 | // SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 98 | // dateFormat.setLenient(false); 99 | // binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); 100 | binder.registerCustomEditor(Date.class, new DatePropertyEditor()); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | springDynamicMvc 4 | 5 | login.jsp 6 | 7 | 8 | contextConfigLocation 9 | classpath*:config/spring/spring-*.xml 10 | 11 | 12 | springDynamicMvc 13 | com.helpinput.spring.servlet.mvc.EnhanceDispachServlet 14 | 15 | contextConfigLocation 16 | classpath*:config/spring/spring-mvc.xml 17 | 18 | 1 19 | 20 | 21 | springDynamicMvc 22 | / 23 | 24 | 25 | org.springframework.web.context.ContextLoaderListener 26 | 27 | 28 | encodingFilter 29 | org.springframework.web.filter.CharacterEncodingFilter 30 | 31 | encoding 32 | UTF-8 33 | 34 | 35 | forceEncoding 36 | true 37 | 38 | 39 | 40 | encodingFilter 41 | /* 42 | 43 | 44 | openSession 45 | org.springframework.orm.hibernate4.support.OpenSessionInViewFilter 46 | 47 | 48 | openSession 49 | /* 50 | 51 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/addTeacher.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 16 | 17 | 18 |

add teacher

19 |
20 | name: 21 |
22 | age: 23 |
24 | birthday : 25 |
26 | 27 |
28 | 29 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/addUser.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 16 | 17 | 18 |

add user

19 |
20 | name: 21 |
22 | age: 23 |
24 | birthday: 25 |
26 | 27 |
28 | 29 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/editTeacher.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | 5 | 6 | 7 | 8 | 9 | Insert title here 10 | 11 | 12 |

eidt teacher

13 |
14 | 15 | name: 16 |
17 | age: 18 |
19 | birthday: 20 |
21 | 22 |
23 | 24 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/editUser.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | 5 | 6 | 7 | 8 | 9 | Insert title here 10 | 11 | 12 |

edit user

13 |
14 | 15 | name: 16 |
17 | age: 18 |
19 | birthday: 20 |
21 | 22 |
23 | 24 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/error.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 | error!!! 11 | 12 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/index.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | 5 | 6 | 7 | 8 | 9 | Insert title here 10 | 22 | 23 | 24 |

to add user>>>

25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 44 | 45 | 46 | 47 | 48 |
nameagebirthdayoption
${user.userName }${user.age }${user.birthday } 41 | edit 42 | del 43 |
49 | 50 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | 8 | Insert title here 9 | 10 | 11 |

go to user manager page(staitc java)

12 |

go to teacher manager page(all things dynamic!!!)

13 | 14 | 15 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/success.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | 4 | 5 | 6 | 7 | Insert title here 8 | 9 | 10 | success!!! 11 | 12 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/WebRoot/teacherList.jsp: -------------------------------------------------------------------------------- 1 | <%@ page language="java" contentType="text/html; charset=UTF-8" 2 | pageEncoding="UTF-8"%> 3 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 4 | 5 | 6 | 7 | 8 | 9 | Insert title here 10 | 22 | 23 | 24 |

to add teacher>>>

25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 44 | 45 | 46 | 47 | 48 |
namepagebirthdayoption
${teacher.teacherName }${teacher.age }${teacher.birthday } 41 | edit 42 | del 43 |
49 | 50 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 5 | 4.0.0 6 | 7 | 8 | com.helpinput.hi 9 | helpinput-parent 10 | 1.2.4 11 | 12 | springDynamicMvc 13 | war 14 | 15 | 16 | 17 | UTF-8 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | javax.servlet 27 | jstl 28 | 1.2 29 | provided 30 | 31 | 32 | javax.servlet.jsp 33 | jsp-api 34 | 2.1 35 | provided 36 | 37 | 38 | org.glassfish 39 | javax.annotation 40 | 3.0.1 41 | 42 | 43 | org.glassfish 44 | javax.ejb 45 | 3.0.1 46 | 47 | 48 | 49 | 50 | org.hibernate.javax.persistence 51 | hibernate-jpa-2.0-api 52 | 1.0.1.Final 53 | 54 | 55 | org.springframework 56 | spring-webmvc 57 | 3.2.9.RELEASE 58 | 59 | 60 | org.springframework 61 | spring-orm 62 | 3.2.9.RELEASE 63 | 64 | 65 | org.hibernate 66 | hibernate-entitymanager 67 | 4.2.0.Final 68 | 74 | 75 | 76 | 77 | mysql 78 | mysql-connector-java 79 | 5.1.22 80 | 81 | 82 | com.helpinput.hi 83 | helpinput-spring-dynamic 84 | ${parent.version} 85 | 86 | 87 | 88 | 89 | ch.qos.logback 90 | logback-classic 91 | 1.0.13 92 | 93 | 94 | 95 | javax.inject 96 | javax.inject 97 | 1 98 | 99 | 100 | 101 | org.glassfish 102 | javax.servlet 103 | 3.0.1 104 | 105 | 106 | 107 | ${basedir}/src 108 | ${basedir}/WebRoot/WEB-INF/classes 109 | ${basedir}/WebRoot/WEB-INF/script 110 | 111 | 112 | 113 | ${basedir}/src 114 | 115 | **/*.java 116 | 117 | 118 | 119 | 120 | 121 | 122 | maven-war-plugin 123 | 124 | ${basedir}/WebRoot 125 | ${basedir}/WebRoot 126 | 127 | 128 | 129 | maven-compiler-plugin 130 | 131 | 1.6 132 | 1.6 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/spring-dynamic-mvc-demo.sql: -------------------------------------------------------------------------------- 1 | 2 | SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 3 | SET time_zone = "+00:00"; 4 | 5 | 6 | CREATE DATABASE IF NOT EXISTS `springmvc` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; 7 | USE `springmvc`; 8 | 9 | 10 | 11 | DROP TABLE IF EXISTS `t_teacher`; 12 | CREATE TABLE IF NOT EXISTS `t_teacher` ( 13 | `id` varchar(32) COLLATE utf8_unicode_ci NOT NULL, 14 | `teacherName` varchar(32) COLLATE utf8_unicode_ci NOT NULL, 15 | `age` varchar(32) COLLATE utf8_unicode_ci NOT NULL, 16 | `birthday` date DEFAULT NULL, 17 | PRIMARY KEY (`id`) 18 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 19 | 20 | 21 | DROP TABLE IF EXISTS `t_user`; 22 | CREATE TABLE IF NOT EXISTS `t_user` ( 23 | `id` varchar(32) COLLATE utf8_unicode_ci NOT NULL, 24 | `username` varchar(32) COLLATE utf8_unicode_ci NOT NULL, 25 | `age` varchar(32) COLLATE utf8_unicode_ci NOT NULL, 26 | `birthday` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL, 27 | PRIMARY KEY (`id`) 28 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; 29 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/src/com/tgb/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | /** 2 | * thanks langgufu for static demo source(http://langgufu.iteye.com/blog/2088355) 3 | */ 4 | package com.tgb.dao; 5 | 6 | import java.util.List; 7 | 8 | import com.tgb.entity.User; 9 | 10 | public interface UserDao { 11 | 12 | public User getUser(String id); 13 | 14 | public List getAllUser(); 15 | 16 | public void addUser(User user); 17 | 18 | public boolean delUser(String id); 19 | 20 | public boolean updateUser(User user); 21 | } 22 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/src/com/tgb/dao/UserDaoImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * thanks langgufu for static demo source(http://langgufu.iteye.com/blog/2088355) 3 | */ 4 | package com.tgb.dao; 5 | 6 | import java.util.List; 7 | 8 | 9 | import org.hibernate.Query; 10 | import org.hibernate.SessionFactory; 11 | 12 | import com.tgb.entity.User; 13 | import org.slf4j.Logger; 14 | import com.helpinput.core.LoggerBase; 15 | import com.helpinput.core.Utils; 16 | public class UserDaoImpl implements UserDao { 17 | static Logger logger = LoggerBase.logger; 18 | 19 | 20 | private SessionFactory sessionFactory; 21 | 22 | public void setSessionFactory(SessionFactory sessionFactory) { 23 | this.sessionFactory = sessionFactory; 24 | } 25 | 26 | @Override 27 | public User getUser(String id) { 28 | 29 | String hql = "from User u where u.id=?"; 30 | Query query = sessionFactory.getCurrentSession().createQuery(hql); 31 | query.setString(0, id); 32 | 33 | return (User)query.uniqueResult(); 34 | } 35 | 36 | @Override 37 | public List getAllUser() { 38 | 39 | 40 | String hql = "from User"; 41 | Query query = sessionFactory.getCurrentSession().createQuery(hql); 42 | 43 | return query.list(); 44 | } 45 | 46 | @Override 47 | public void addUser(User user) { 48 | sessionFactory.getCurrentSession().save(user); 49 | } 50 | 51 | @Override 52 | public boolean delUser(String id) { 53 | 54 | String hql = "delete User u where u.id = ?"; 55 | Query query = sessionFactory.getCurrentSession().createQuery(hql); 56 | query.setString(0, id); 57 | 58 | return (query.executeUpdate() > 0); 59 | } 60 | 61 | @Override 62 | public boolean updateUser(User user) { 63 | 64 | String hql = "update User u set u.userName = ?,u.age=?,u.birthday=? where u.id = ?"; 65 | Query query = sessionFactory.getCurrentSession().createQuery(hql); 66 | query.setString(0, user.getUserName()); 67 | query.setString(1, user.getAge()); 68 | query.setDate(2, user.getBirthday()); 69 | query.setString(3, user.getId()); 70 | 71 | return (query.executeUpdate() > 0); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/src/com/tgb/entity/User.java: -------------------------------------------------------------------------------- 1 | /** 2 | * thanks langgufu for static demo source(http://langgufu.iteye.com/blog/2088355) 3 | */ 4 | package com.tgb.entity; 5 | 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.GeneratedValue; 12 | import javax.persistence.Id; 13 | import javax.persistence.Table; 14 | 15 | import org.hibernate.annotations.GenericGenerator; 16 | 17 | @Entity 18 | @Table(name = "T_USER") 19 | public class User implements Serializable { 20 | 21 | @Id 22 | @GeneratedValue(generator = "system-uuid") 23 | @GenericGenerator(name = "system-uuid", strategy = "uuid") 24 | @Column(length = 32) 25 | private String id; 26 | 27 | @Column(length = 32) 28 | private String userName; 29 | 30 | @Column(length = 32) 31 | private String age; 32 | 33 | Date birthday; 34 | 35 | public String getId() { 36 | return id; 37 | } 38 | 39 | public void setId(String id) { 40 | this.id = id; 41 | } 42 | 43 | public String getUserName() { 44 | return userName; 45 | } 46 | 47 | public void setUserName(String userName) { 48 | this.userName = userName; 49 | } 50 | 51 | public String getAge() { 52 | return age; 53 | } 54 | 55 | public void setAge(String age) { 56 | this.age = age; 57 | } 58 | 59 | public Date getBirthday() { 60 | return birthday; 61 | } 62 | 63 | public void setBirthday(Date birthday) { 64 | this.birthday = birthday; 65 | } 66 | 67 | 68 | 69 | } 70 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/src/com/tgb/interceptor/UserIntercepptor.java: -------------------------------------------------------------------------------- 1 | package com.tgb.interceptor; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | import javax.servlet.http.HttpServletResponse; 5 | 6 | import org.slf4j.Logger; 7 | import org.springframework.web.servlet.HandlerInterceptor; 8 | import org.springframework.web.servlet.ModelAndView; 9 | 10 | import com.helpinput.annotation.Mapping; 11 | import com.helpinput.annotation.MappingExclude; 12 | import com.helpinput.core.LoggerBase; 13 | 14 | @Mapping({ "/user/*" }) 15 | @MappingExclude("/login") 16 | public class UserIntercepptor implements HandlerInterceptor { 17 | static Logger logger = LoggerBase.logger; 18 | 19 | @Override 20 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 21 | String url = request.getRequestURL().toString(); 22 | logger.info("userIntercepptor preHandle............................" + url); 23 | return true; 24 | } 25 | 26 | //在业务处理器处理请求执行完成后,生成视图之前执行的动作 27 | @Override 28 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, 29 | ModelAndView modelAndView) throws Exception { 30 | } 31 | 32 | @Override 33 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) 34 | throws Exception { 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/src/com/tgb/manager/UserManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * thanks langgufu for static demo source(http://langgufu.iteye.com/blog/2088355) 3 | */ 4 | package com.tgb.manager; 5 | 6 | import java.util.List; 7 | 8 | import com.tgb.entity.User; 9 | 10 | public interface UserManager { 11 | 12 | public User getUser(String id); 13 | 14 | public List getAllUser(); 15 | 16 | public void addUser(User user); 17 | 18 | public boolean delUser(String id); 19 | 20 | public boolean updateUser(User user); 21 | } 22 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/src/com/tgb/manager/UserManagerImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * thanks langgufu for static demo source(http://langgufu.iteye.com/blog/2088355) 3 | */ 4 | package com.tgb.manager; 5 | 6 | import java.util.List; 7 | 8 | import com.helpinput.annotation.Parent; 9 | import com.tgb.dao.UserDao; 10 | import com.tgb.entity.User; 11 | 12 | 13 | public class UserManagerImpl implements UserManager { 14 | 15 | private UserDao userDao; 16 | 17 | public void setUserDao(UserDao userDao) { 18 | this.userDao = userDao; 19 | } 20 | 21 | @Override 22 | public User getUser(String id) { 23 | return userDao.getUser(id); 24 | } 25 | 26 | @Override 27 | public List getAllUser() { 28 | return userDao.getAllUser(); 29 | } 30 | 31 | @Override 32 | public void addUser(User user) { 33 | userDao.addUser(user); 34 | } 35 | 36 | @Override 37 | public boolean delUser(String id) { 38 | 39 | return userDao.delUser(id); 40 | } 41 | 42 | @Override 43 | public boolean updateUser(User user) { 44 | return userDao.updateUser(user); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/src/com/tgb/web/UserController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * thanks langgufu for static demo source(http://langgufu.iteye.com/blog/2088355) 3 | */ 4 | package com.tgb.web; 5 | 6 | import java.io.IOException; 7 | import java.io.PrintWriter; 8 | import java.text.SimpleDateFormat; 9 | import java.util.Date; 10 | 11 | import javax.annotation.Resource; 12 | import javax.servlet.ServletException; 13 | import javax.servlet.http.HttpServletRequest; 14 | import javax.servlet.http.HttpServletResponse; 15 | 16 | import org.slf4j.Logger; 17 | import org.springframework.beans.propertyeditors.CustomDateEditor; 18 | import org.springframework.stereotype.Controller; 19 | import org.springframework.web.bind.WebDataBinder; 20 | import org.springframework.web.bind.annotation.InitBinder; 21 | import org.springframework.web.bind.annotation.RequestMapping; 22 | 23 | import com.helpinput.core.LoggerBase; 24 | import com.tgb.entity.User; 25 | import com.tgb.manager.UserManager; 26 | 27 | @Controller 28 | @RequestMapping("/user") 29 | public class UserController { 30 | static Logger logger = LoggerBase.logger; 31 | 32 | @Resource(name = "userManager") 33 | private UserManager userManager; 34 | 35 | @RequestMapping("/getAllUser") 36 | public String getAllUser(HttpServletRequest request) { 37 | request.setAttribute("userList", userManager.getAllUser()); 38 | return "/index"; 39 | } 40 | 41 | @RequestMapping("/getUser") 42 | public String getUser(String id, HttpServletRequest request) { 43 | 44 | request.setAttribute("user", userManager.getUser(id)); 45 | 46 | return "/editUser"; 47 | } 48 | 49 | @RequestMapping("/toAddUser") 50 | public String toAddUser() { 51 | return "/addUser"; 52 | } 53 | 54 | @RequestMapping("/addUser") 55 | public String addUser(User user, HttpServletRequest request) { 56 | userManager.addUser(user); 57 | 58 | return "redirect:/user/getAllUser"; 59 | } 60 | 61 | @RequestMapping("/delUser") 62 | public void delUser(String id, HttpServletResponse response) { 63 | 64 | String result = "{\"result\":\"error\"}"; 65 | 66 | if (userManager.delUser(id)) { 67 | result = "{\"result\":\"success\"}"; 68 | } 69 | 70 | response.setContentType("application/json"); 71 | 72 | try { 73 | PrintWriter out = response.getWriter(); 74 | out.write(result); 75 | } 76 | catch (IOException e) { 77 | e.printStackTrace(); 78 | } 79 | } 80 | 81 | @RequestMapping("/updateUser") 82 | public String updateUser(User user, HttpServletRequest request) { 83 | if (userManager.updateUser(user)) { 84 | user = userManager.getUser(user.getId()); 85 | request.setAttribute("user", user); 86 | return "redirect:/user/getAllUser"; 87 | } 88 | else { 89 | return "/error"; 90 | } 91 | } 92 | 93 | @InitBinder 94 | protected void initBinder(WebDataBinder binder) throws ServletException { 95 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 96 | dateFormat.setLenient(false); 97 | binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false)); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/src/config/spring/spring-beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 34 | 35 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/src/config/spring/spring-common.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | org.hibernate.dialect.MySQLDialect 22 | update 23 | true 24 | true 25 | 26 | 27 | 28 | 29 | com.tgb.entity.User 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | 52 | 53 | PROPAGATION_REQUIRED,-Exception 54 | PROPAGATION_REQUIRED,-myException 55 | PROPAGATION_REQUIRED 56 | PROPAGATION_REQUIRED 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/src/config/spring/spring-mvc.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 16 | 17 | 18 | /WEB-INF/script/**/*.java 19 | /WEB-INF/script/**/*.groovy 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/src/log4j.properties: -------------------------------------------------------------------------------- 1 | log4j.rootLogger=info,stdout 2 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender 3 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout 4 | #dwr log config 5 | log4j.logger.uk.ltd.getahead.dwr= 6 | # Pattern to output the caller's file name and line number. 7 | log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%c:%L) %d{yyyy-MM-dd HH:mm:ss,SSS} ---- %m%n 8 | 9 | #log4j.appender.R=org.apache.log4j.RollingFileAppender 10 | #log4j.appender.R.File=D:\\logs\\web_log.log 11 | #log4j.appender.R.MaxFileSize=100KB 12 | 13 | # Keep one backup file 14 | #log4j.appender.R.MaxBackupIndex=100 15 | 16 | log4j.appender.R.layout=org.apache.log4j.PatternLayout 17 | log4j.appender.R.layout.ConversionPattern=%p %d{yyyy-MM-dd HH\:mm\:ss,SSS} %n%t %c ---- %m%n 18 | #disable dwr log 19 | #log4j.logger.org.directwebremoting=ERROR -------------------------------------------------------------------------------- /3-hi-spring-Dynamic-mvc-demo/src/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | %d{yyyy/MM/dd HH:mm:ss.SSS} %-5level [%thread] %n%msg%n%caller{20} 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /3-hi-spring-dynamic-mvc-demo-script/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /3-hi-spring-dynamic-mvc-demo-script/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | 3-hi-spring-dynamic-mvc-demo-script 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.groovy.core.groovyNature 21 | org.eclipse.jdt.core.javanature 22 | org.eclipse.m2e.core.maven2Nature 23 | 24 | 25 | 26 | script 27 | 2 28 | WORKSPACE_LOC/1-hi-parent/3-hi-spring-Dynamic-mvc-demo/WebRoot/WEB-INF/script 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /3-hi-spring-dynamic-mvc-demo-script/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | 5 | com.helpinput.hi 6 | helpinput-parent 7 | 1.2.4 8 | 9 | helpinput-script 10 | 11 | 12 | 13 | javax.servlet 14 | jstl 15 | 1.2 16 | provided 17 | 18 | 19 | javax.servlet.jsp 20 | jsp-api 21 | 2.1 22 | provided 23 | 24 | 25 | org.glassfish 26 | javax.annotation 27 | 3.0.1 28 | 29 | 30 | org.glassfish 31 | javax.ejb 32 | 3.0.1 33 | 34 | 35 | 36 | 37 | org.hibernate.javax.persistence 38 | hibernate-jpa-2.0-api 39 | 1.0.1.Final 40 | 41 | 42 | org.springframework 43 | spring-webmvc 44 | 3.2.9.RELEASE 45 | 46 | 47 | org.springframework 48 | spring-jdbc 49 | 3.2.9.RELEASE 50 | 51 | 52 | org.springframework 53 | spring-orm 54 | 3.2.9.RELEASE 55 | 56 | 57 | org.hibernate 58 | hibernate-entitymanager 59 | 4.2.0.Final 60 | 66 | 67 | 68 | 69 | mysql 70 | mysql-connector-java 71 | 5.1.22 72 | 73 | 74 | com.helpinput.hi 75 | helpinput-spring-dynamic 76 | ${parent.version} 77 | 78 | 79 | 80 | 81 | ch.qos.logback 82 | logback-classic 83 | 1.0.13 84 | 85 | 86 | 87 | javax.inject 88 | javax.inject 89 | 1 90 | 91 | 92 | org.glassfish 93 | javax.servlet 94 | 3.0.1 95 | 96 | 97 | com.helpinput.hi 98 | springDynamicMvc 99 | ${parent.version} 100 | war 101 | 102 | 103 | -------------------------------------------------------------------------------- /3-hi-spring-dynamic-mvc-demo-script/readme.txt: -------------------------------------------------------------------------------- 1 | tomcat运行起来后,试着改变增加删除 3-hi-spring-dynamic-mvc-demo-script项目下的script文件夹 2 | 的java或groovy文件,就知道了 3 | 4 | after run tomcat ,try to change/add/delete java/groovy file in script source folder of 5 | 3-hi-spring-dynamic-mvc-demo-script project ,you will know 6 | 7 | 8 | 9 | script is a Link source folder ,Link to WORKSPACE_LOC\1-hi-parent\3-hi-springMvcWeb\WebRoot\WEB-INF\script 10 | you and add or edit entity, dao, manager,controller ...etc. 11 | there are all dynamic, when finished just ctrl+s or copy to your webapp's folder ,the tomcat where read and compile the source as class and add to spring context 12 | 13 | script 是一个链接的文件夹,指向 WORKSPACE_LOC\1-hi-parent\3-hi-spring-Dynamic-mvc-demo\WebRoot\WEB-INF\script 14 | 在这里,你可以动态地增加修改entity, dao, manager,controller等等, 15 | 这些代码是动态的,当完成编辑,按ctrl+s 或者复制到到你的webapp 相应的文件夹下,tomcat 将会读取并编译相应的source,这些类在spring容器内可以找到 16 | 17 | /** 18 | *@Author: niaoge(Zhengsheng Xia) 19 | *@Email 78493244@qq.com 20 | *@Date: 2015-6-16 21 | */ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | tomcat运行起来后,试着改变增加删除 3-hi-spring-dynamic-mvc-demo-script项目下的script文件夹 2 | 的java或groovy文件,就知道了 3 | 4 | after run tomcat ,try to change/add/delete java/groovy file in script source folder of 5 | 3-hi-spring-dynamic-mvc-demo-script project ,you will know 6 | 7 | 8 | one bean make project dynamic 9 |
10 |     <bean class="com.helpinput.spring.support.SourceFileMonitorListener">
11 |         <property name="dirs">
12 |             <list>
13 |                 <value>/WEB-INF/script/**/*.java</value>
14 |                 <value>/WEB-INF/script/**/*.groovy</value>
15 |             </list>
16 |         </property>
17 |     </bean>
18 | 
19 | 20 | 21 |
 
22 | The spring-dynamic project and it'samples(spring mvc3+hibernate4+spring-dynimic1.24)
23 |  
24 | the spring-dynamic project can generate spring bean dynamically,The dynamic java/groovy 
25 | file can be import to another dynamic java/groovy file. They all can be add ,modify,
26 | delete,and then the spring context does the same.
27 | In spring-dyanmaic ,.java/.groovy can be deployed just 
28 | like other dynamic lang .jsp/php/ruby/go ...
29 | 
30 | 1-hi-utils folder is tool project and depended by the spring-dyamic project
31 | 2-hi-spring-dynamic folder contains spring-dynamic project
32 | 3-hi-spring-Dynamic-mvc-demo is the sample(spring mvc+hibernate+spring-dynimic)
33 | 3-hi-spring-dynamic-mvc-demo-script js java(scprit) project,it has a linked source 
34 | folder to 3-hi-springMvcWeb\WebRoot\WEB-INF\script
35 | java/groovy file in 3-hi-spring-dynamic-mvc-demo-script can be deployed as .jsp file,
36 | and not need restart the webapp container(tomcat) 
37 | 
38 | It 's not a anather framework but a project integrate to your existing projects and 
39 | let them dynamic
40 | 
41 | 42 | 43 |
44 | 这是一个动态的spring项目及范例
45 | 
46 | 动态地生成spring bean,包括entity,dao,manager(service),controller等等 动态类之间可以相互
47 | 引用,修改的代码(.java/.groovy)直接增加到app相应目录下,在不需要重启app的情况下,自动
48 | 被编译成java class 字节码,并添加(替换)到spring bean中,而且可以重复替换.同时删除的java文件
49 | 相应的class也会从spring bean 中删除
50 | 在本项目中,.java/.groovy的增删修改如同.jsp/php/ruby/go一样
51 | 它的优点不是另一个框架,而是最大限度地集成到现有的框架中,将之变为动态
52 | 
53 | 1-hi-utils 是工具包
54 | 
55 | 2-hi-spring-dynamic 是本项目
56 | 
57 | 3-hi-spring-Dynamic-mvc-demo 范例(spring mvc3+hibernate4+spring-dynimic1.24)
58 | 
59 | 3-hi-spring-dynamic-mvc-demo-script 是上面demo的scrit包,也可以指通常的业务层,因为是动态,
60 | 除业务层外,propertyEditor、
61 | interceptor也可以写在里面,它有一个 linked source类型的文件夹,
62 | 指向 3-hi-springMvcWeb\WebRoot\WEB-INF\script ,而不是在
63 | 本地文件夹下,在3-hi-spring-dynamic-mvc-demo-script项目中修改后的代码,在测式环境下如同.jsp
64 | 一样发布即生效,在生产环境下(升级),直接将(.java/.grooy)拷贝到相应的文件夹下
65 | WebRoot\WEB-INF\script,随即生效,不用重启web容器(tomcat)
66 | 
67 | 68 | 69 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.helpinput.hi 5 | helpinput-parent 6 | 1.2.4 7 | pom 8 | 9 | UTF-8 10 | 3.2.4.RELEASE 11 | ${parent.version} 12 | 20140124 13 | 2.2.7 14 | 15 | 16 | 17 | spring-relase 18 | spring-relase 19 | http://repo.spring.io/release/ 20 | 21 | 22 | cpdetector-id 23 | cpdetector-name 24 | http://maven.nuiton.org/nexus/content/groups/releases/ 25 | 26 | 27 | ibiblio 28 | ibiblio 29 | http://mirrors.ibiblio.org/pub/mirrors/maven2/ 30 | 31 | 32 | 33 | 34 | 35 | --------------------------------------------------------------------------------