View Javadoc

1   /*
2    *  Copyright 2006 Simon Raess
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  package net.sf.beep4j.internal;
17  
18  import net.sf.beep4j.ChannelHandler;
19  import net.sf.beep4j.ProfileInfo;
20  
21  public abstract class StartChannelResponse {
22  
23  	private StartChannelResponse() {
24  		// hidden constructor
25  	}
26  	
27  	public abstract boolean isCancelled();
28  	
29  	public int getCode() {
30  		throw new IllegalStateException("StartChannelRequest is not cancelled");
31  	}
32  	
33  	public String getMessage() {
34  		throw new IllegalStateException("StartChannelRequest is not cancelled");
35  	}
36  	
37  	public ProfileInfo getProfile() {
38  		throw new IllegalStateException("StartChannelRequest is cancelled");
39  	}
40  	
41  	public ChannelHandler getChannelHandler() {
42  		throw new IllegalStateException("StartChannelRequest is cancelled");
43  	}
44  
45  	public static final StartChannelResponse createCancelledResponse(
46  			final int code, final String message) {
47  		return new StartChannelResponse() {
48  			@Override
49  			public boolean isCancelled() {
50  				return true;
51  			}
52  			@Override
53  			public int getCode() {
54  				return code;
55  			}
56  			@Override
57  			public String getMessage() {
58  				return message;
59  			}
60  		};
61  	}
62  	
63  	public static final StartChannelResponse createSuccessResponse(
64  			final ProfileInfo profile, final ChannelHandler channelHandler) {
65  		return new StartChannelResponse() {
66  			@Override
67  			public boolean isCancelled() {
68  				return false;
69  			}
70  			@Override
71  			public ChannelHandler getChannelHandler() {
72  				return channelHandler;
73  			}
74  			@Override
75  			public ProfileInfo getProfile() {
76  				return profile;
77  			}
78  		};
79  	}
80  	
81  }