1 18 19 package org.apache.beehive.netui.tools.testrecorder.shared.config; 20 21 import org.apache.beehive.netui.tools.testrecorder.shared.util.StringHelper; 22 23 import java.util.Map ; 24 import java.util.HashMap ; 25 import java.util.List ; 26 import java.util.Set ; 27 import java.util.Collections ; 28 import java.io.File ; 29 30 import org.apache.beehive.netui.tools.testrecorder.shared.Logger; 31 32 37 public class Config { 38 39 private static final Logger log = Logger.getInstance( Config.class ); 40 41 private Map suffixMap; 42 private String servletURI; 43 private File baseDirectory; 44 45 public Config( List suffixList, String servletURI, String baseDirPath ) { 46 this( (String []) suffixList.toArray( new String [suffixList.size()] ), servletURI, baseDirPath ); 47 } 48 49 public Config( String [] suffixList, String servletURI, String baseDirPath ) { 50 this.servletURI = servletURI; 51 suffixMap = new HashMap (); 52 baseDirectory = new File ( baseDirPath ); 53 init( suffixList ); 54 } 55 56 private void init( String [] suffixList ) { 57 String suffix = null; 58 if ( suffixList != null ) { 59 for ( int i = 0; i < suffixList.length; i++ ) { 60 suffix = suffixList[i]; 61 if ( log.isDebugEnabled() ) { 62 log.debug( "suffix( " + suffix + " )" ); 63 } 64 suffixMap.put( suffix, suffix ); 65 } 66 } 67 } 68 69 public boolean handleSuffix( String suffix ) { 70 return suffixMap.containsKey( suffix ); 71 } 72 73 public String getServletURI() { 75 return servletURI; 76 } 77 78 public Set getSuffixes() { 79 return Collections.unmodifiableSet( getSuffixMap().keySet() ); 80 } 81 82 public File getBaseDirectory() { 83 return baseDirectory; 84 } 85 86 public boolean createBaseDirectory() { 87 if ( baseDirectory.exists() ) { 88 return true; 89 } 90 return baseDirectory.mkdirs(); 91 } 92 93 private Map getSuffixMap() { 94 return suffixMap; 95 } 96 97 public String toString() { 98 StringBuffer sb = new StringBuffer ( 256 ); 99 sb.append( "[ " ); 100 sb.append( "servletURI( " + getServletURI() + " )" ); 101 sb.append( ", suffixList( " + StringHelper.toString( getSuffixes().iterator(), "\n", "\n\t" ) + " )" ); 102 sb.append( " ]" ); 103 return sb.toString(); 104 } 105 106 } 107 | Popular Tags |