001 package railo.runtime.listener; 002 003 import java.util.ArrayList; 004 import java.util.List; 005 006 import railo.commons.io.res.Resource; 007 import railo.commons.io.res.util.ResourceUtil; 008 import railo.runtime.type.util.ArrayUtil; 009 010 public class JavaSettingsImpl implements JavaSettings { 011 012 private final Resource[] resources; 013 private Resource[] resourcesTranslated; 014 private final boolean loadCFMLClassPath; 015 private final boolean reloadOnChange; 016 private final int watchInterval; 017 private final String[] watchedExtensions; 018 019 public JavaSettingsImpl(){ 020 this.resources=new Resource[0]; 021 this.loadCFMLClassPath=false; 022 this.reloadOnChange=false; 023 this.watchInterval=60; 024 this.watchedExtensions=new String[]{"jar","class"}; 025 } 026 027 public JavaSettingsImpl(Resource[] resources, Boolean loadCFMLClassPath,boolean reloadOnChange, int watchInterval, String[] watchedExtensions) { 028 029 this.resources=resources; 030 this.loadCFMLClassPath=loadCFMLClassPath; 031 this.reloadOnChange=reloadOnChange; 032 this.watchInterval=watchInterval; 033 this.watchedExtensions=watchedExtensions; 034 } 035 036 @Override 037 public Resource[] getResources() { 038 return resources; 039 } 040 041 // FUTURE add to interface 042 public Resource[] getResourcesTranslated() { 043 if(resourcesTranslated==null) { 044 List<Resource> list=new ArrayList<Resource>(); 045 _getResourcesTranslated(list,resources, true); 046 resourcesTranslated=list.toArray(new Resource[list.size()]); 047 } 048 return resourcesTranslated; 049 } 050 051 public static void _getResourcesTranslated(List<Resource> list, Resource[] resources, boolean deep) { 052 if(ArrayUtil.isEmpty(resources)) return; 053 for(int i=0;i<resources.length;i++){ 054 if(resources[i].isFile()) { 055 if(ResourceUtil.getExtension(resources[i], "").equalsIgnoreCase("jar")) 056 list.add(resources[i]); 057 } 058 else if(deep && resources[i].isDirectory()){ 059 list.add(resources[i]); // add as possible classes dir 060 _getResourcesTranslated(list,resources[i].listResources(),false); 061 062 } 063 } 064 } 065 066 @Override 067 public boolean loadCFMLClassPath() { 068 return loadCFMLClassPath; 069 } 070 071 @Override 072 public boolean reloadOnChange() { 073 return reloadOnChange; 074 } 075 076 @Override 077 public int watchInterval() { 078 return watchInterval; 079 } 080 081 @Override 082 public String[] watchedExtensions() { 083 return watchedExtensions; 084 } 085 086 }