KickJava   Java API By Example, From Geeks To Geeks.

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


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.List JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.HashMap JavaDoc;
27
28 /**
29  * Client side object that defines server access info.
30  * <p/>
31  * User: ozzy
32  */

33 public class ServerDefinition {
34
35     private String JavaDoc name;
36     private String JavaDoc hostname;
37     private int port;
38     private List JavaDoc webappList;
39     private Map JavaDoc webappMap;
40     private Map JavaDoc testDefMap;
41     private List JavaDoc testDefList;
42
43     public ServerDefinition( String JavaDoc name, String JavaDoc hostname, int port ) {
44         this.name = name;
45         this.hostname = hostname;
46         this.port = port;
47         webappList = new ArrayList JavaDoc();
48         webappMap = new HashMap JavaDoc();
49         testDefMap = new HashMap JavaDoc();
50         testDefList = new ArrayList JavaDoc();
51     }
52
53     public void addWebapp( WebappDefinition webapp ) {
54         webappList.add( webapp );
55         webappMap.put( webapp.getName(), webapp );
56     }
57
58     public WebappDefinition getWebapp( String JavaDoc webappName ) {
59         return (WebappDefinition) webappMap.get( webappName );
60     }
61
62     public WebappDefinition[] getWebapps() {
63         return (WebappDefinition[]) webappList.toArray( new WebappDefinition[webappList.size()] );
64     }
65
66     public int getWebappCount() {
67         return webappList.size();
68     }
69
70     public void addTestDefinitions( WebappDefinition webapp, TestDefinitions tests ) {
71         testDefMap.put( webapp, tests );
72         testDefList.add( tests );
73     }
74
75     public TestDefinitions getTestDefinitions( String JavaDoc webappName ) throws ConfigException {
76         WebappDefinition webapp = getWebapp( webappName );
77         if ( webapp == null ) {
78             throw new ConfigException( "No webapp exists for webapp with name( " + webappName );
79         }
80         return getTestDefinitions( webapp );
81     }
82
83     public TestDefinitions getTestDefinitions( WebappDefinition webapp ) {
84         return (TestDefinitions) testDefMap.get( webapp );
85     }
86
87     public TestDefinitions[] getTestDefinitions() {
88         return (TestDefinitions[]) testDefList.toArray( new TestDefinitions[testDefList.size()] );
89     }
90
91     public int getTestDefinitionsCount() {
92         return testDefList.size();
93     }
94
95     public String JavaDoc getName() {
96         return name;
97     }
98
99     public String JavaDoc getHostname() {
100         return hostname;
101     }
102
103     public int getPort() {
104         return port;
105     }
106
107     public String JavaDoc toString() {
108         StringBuffer JavaDoc sb = new StringBuffer JavaDoc( 48 );
109         sb.append( "[ " );
110         sb.append( "name( " + getName() + " )" );
111         sb.append( ", hostname( " + getHostname() + " )" );
112         sb.append( ", port( " + getPort() + " )" );
113         sb.append( ", webappList( " + StringHelper.toString( webappList, "\n", "\n\t" ) + " )" );
114         sb.append( " ]" );
115         return sb.toString();
116     }
117
118 }
119
Popular Tags