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 java.util.HashSet;
19  import java.util.Set;
20  
21  import net.sf.beep4j.StartSessionRequest;
22  import net.sf.beep4j.internal.util.Assert;
23  
24  /**
25   * Default implementation of the StartSessionRequest interface.
26   * 
27   * @author Simon Raess
28   */
29  public class DefaultStartSessionRequest implements StartSessionRequest {
30  	
31  	private final Set<String> profiles = new HashSet<String>();
32  	
33  	private boolean cancellable;
34  	
35  	private boolean cancelled;
36  	
37  	private int code;
38  	
39  	private String message;
40  	
41  	public DefaultStartSessionRequest(boolean cancellable) {
42  		this.cancellable = cancellable;
43  	}
44  	
45  	public boolean isCancellable() {
46  		return cancellable;
47  	}
48  	
49  	public boolean isCancelled() {
50  		return cancelled;
51  	}
52  	
53  	public int getReplyCode() {
54  		return code;
55  	}
56  	
57  	public String getMessage() {
58  		return message;
59  	}
60  	
61  	public String[] getProfiles() {
62  		return profiles.toArray(new String[profiles.size()]);
63  	}
64  	
65  	public void cancel() {
66  		this.cancelled = true;
67  		this.code = 421;
68  		this.message = "service not available";
69  	}
70  
71  	public void registerProfile(String profileUri) {
72  		Assert.notNull("profileUri", profileUri);
73  		profiles.add(profileUri);
74  	}
75  
76  }