View Javadoc

1   //========================================================================
2   //Copyright 2008 Mort Bay Consulting Pty. Ltd.
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   //http://www.apache.org/licenses/LICENSE-2.0
8   //Unless required by applicable law or agreed to in writing, software
9   //distributed under the License is distributed on an "AS IS" BASIS,
10  //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  //See the License for the specific language governing permissions and
12  //limitations under the License.
13  //========================================================================
14  
15  
16  package org.mortbay.jetty.client;
17  
18  import java.io.IOException;
19  
20  import org.mortbay.io.Buffer;
21  
22  public class HttpEventListenerWrapper implements HttpEventListener
23  {
24      HttpEventListener _listener;
25      boolean _delegatingRequests;
26      boolean _delegatingResponses;
27  
28      public HttpEventListenerWrapper()
29      {
30          _listener=null;
31          _delegatingRequests=false;
32          _delegatingResponses=false;
33      }
34      
35      public HttpEventListenerWrapper(HttpEventListener eventListener,boolean delegating)
36      {
37          _listener=eventListener;
38          _delegatingRequests=delegating;
39          _delegatingResponses=delegating;
40      }
41      
42      public HttpEventListener getEventListener()
43      {
44          return _listener;
45      }
46  
47      public void setEventListener(HttpEventListener listener)
48      {
49          _listener = listener;
50      }
51  
52      public boolean isDelegatingRequests()
53      {
54          return _delegatingRequests;
55      }
56      
57      public boolean isDelegatingResponses()
58      {
59          return _delegatingResponses;
60      }
61  
62      public void setDelegatingRequests(boolean delegating)
63      {
64          _delegatingRequests = delegating;
65      }
66      
67      public void setDelegatingResponses(boolean delegating)
68      {
69          _delegatingResponses = delegating;
70      }
71      
72      public void onConnectionFailed(Throwable ex)
73      {
74          if (_delegatingRequests)
75              _listener.onConnectionFailed(ex);
76      }
77  
78      public void onException(Throwable ex)
79      {
80          if (_delegatingRequests||_delegatingResponses)
81              _listener.onException(ex);
82      }
83  
84      public void onExpire()
85      {
86          if (_delegatingRequests||_delegatingResponses)
87              _listener.onExpire();
88      }
89  
90      public void onRequestCommitted() throws IOException
91      {
92          if (_delegatingRequests)
93              _listener.onRequestCommitted();
94      }
95  
96      public void onRequestComplete() throws IOException
97      {
98          if (_delegatingRequests)
99              _listener.onRequestComplete();
100     }
101 
102     public void onResponseComplete() throws IOException
103     {
104         if (_delegatingResponses)
105             _listener.onResponseComplete();
106     }
107 
108     public void onResponseContent(Buffer content) throws IOException
109     {
110         if (_delegatingResponses)
111             _listener.onResponseContent(content);
112     }
113 
114     public void onResponseHeader(Buffer name, Buffer value) throws IOException
115     {
116         if (_delegatingResponses)
117             _listener.onResponseHeader(name,value);
118     }
119 
120     public void onResponseHeaderComplete() throws IOException
121     {
122         if (_delegatingResponses)
123             _listener.onResponseHeaderComplete();
124     }
125 
126     public void onResponseStatus(Buffer version, int status, Buffer reason) throws IOException
127     {
128         if (_delegatingResponses)
129             _listener.onResponseStatus(version,status,reason);
130     }
131 
132     public void onRetry()
133     {
134         if (_delegatingRequests)
135             _listener.onRetry();
136     }
137     
138     
139     
140 }