KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > tools > testrecorder > shared > config > Config


1 /*
2  * Copyright 2004 The Apache Software Foundation.
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  * $Header:$
17  */

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 JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Set JavaDoc;
27 import java.util.Collections JavaDoc;
28 import java.io.File JavaDoc;
29
30 import org.apache.beehive.netui.tools.testrecorder.shared.Logger;
31
32 /**
33  * User: ozzy
34  * Date: Apr 13, 2004
35  * Time: 4:19:09 PM
36  */

37 public class Config {
38
39     private static final Logger log = Logger.getInstance( Config.class );
40
41     private Map JavaDoc suffixMap;
42     private String JavaDoc servletURI;
43     private File JavaDoc baseDirectory;
44
45     public Config( List JavaDoc suffixList, String JavaDoc servletURI, String JavaDoc baseDirPath ) {
46         this( (String JavaDoc[]) suffixList.toArray( new String JavaDoc[suffixList.size()] ), servletURI, baseDirPath );
47     }
48
49     public Config( String JavaDoc[] suffixList, String JavaDoc servletURI, String JavaDoc baseDirPath ) {
50         this.servletURI = servletURI;
51         suffixMap = new HashMap JavaDoc();
52         baseDirectory = new File JavaDoc( baseDirPath );
53         init( suffixList );
54     }
55
56     private void init( String JavaDoc[] suffixList ) {
57         String JavaDoc 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 JavaDoc suffix ) {
70         return suffixMap.containsKey( suffix );
71     }
72
73     // this URI specifies the portion to the right of the context root, not including the root.
74
public String JavaDoc getServletURI() {
75         return servletURI;
76     }
77
78     public Set JavaDoc getSuffixes() {
79         return Collections.unmodifiableSet( getSuffixMap().keySet() );
80     }
81
82     public File JavaDoc 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 JavaDoc getSuffixMap() {
94         return suffixMap;
95     }
96
97     public String JavaDoc toString() {
98         StringBuffer JavaDoc sb = new StringBuffer JavaDoc( 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