KickJava   Java API By Example, From Geeks To Geeks.

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


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;
20
21 import java.util.List JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collections JavaDoc;
24
25 /**
26  */

27 public class RecordSessionBean extends SessionBean {
28
29     private List JavaDoc requestData;
30     private List JavaDoc responseData;
31     // if true indicates an error has occured in the session
32
protected boolean error = false;
33
34     public RecordSessionBean( String JavaDoc sessionName ) {
35         this.sessionName = sessionName;
36         requestData = new ArrayList JavaDoc();
37         responseData = new ArrayList JavaDoc();
38     }
39
40     public void setError() {
41         error = true;
42     }
43
44     public void setError( boolean error ) {
45         this.error = error;
46     }
47
48     public boolean isError() {
49         return error;
50     }
51
52
53     public List JavaDoc getRequestData() {
54         return Collections.unmodifiableList( requestData );
55     }
56
57     /**
58      *
59      * @param index
60      * @return
61      * @throws IndexOutOfBoundsException
62      */

63     public RequestData getRequestData( int index ) {
64         return (RequestData) requestData.get( index );
65     }
66
67     public List JavaDoc getResponseData() {
68         return Collections.unmodifiableList( responseData );
69     }
70
71     /**
72      * @param index
73      * @return
74      * @throws IndexOutOfBoundsException
75      */

76     public ResponseData getResponseData( int index ) {
77         return (ResponseData) responseData.get( index );
78     }
79
80     public void addRequestResponseData( RequestData request, ResponseData response ) {
81         requestData.add( request );
82         responseData.add( response );
83     }
84
85     /**
86      * update the data for the most recent test
87      * @param request
88      * @param response
89      */

90     public void updateRequestResponseData( RequestData request, ResponseData response ) {
91         if ( requestData.size() == 0 || responseData.size() == 0 ) {
92             throw new IllegalStateException JavaDoc( "data size is zero, unable to update");
93         }
94         requestData.set( requestData.size() -1, request );
95         responseData.add( responseData.size() -1, response );
96     }
97
98     public int getTestCount() {
99         return requestData.size();
100     }
101
102     public String JavaDoc toString() {
103         StringBuffer JavaDoc sb = new StringBuffer JavaDoc( 256 );
104         sb.append( "[ " );
105         sb.append( "sessionName( " + getSessionName() + " )" );
106         sb.append( ", tester( " + getTester() + " )" );
107         sb.append( ", startDate( " + getStartDateString() + " )" );
108         sb.append( ", endDate( " + getEndDateString() + " )" );
109         sb.append( ", testCount( " + getTestCount() + " )" );
110         sb.append( ", description( " + getDescription() + " )" );
111         sb.append( " ]" );
112         return sb.toString();
113     }
114
115 }
116
Popular Tags