| 1 | //  Copyright 2004-2007 Jean-Francois Poilpret | 
| 2 | // | 
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
| 4 | // you may not use this file except in compliance with the License. | 
| 5 | // You may obtain a copy of the License at | 
| 6 | // | 
| 7 | //     http://www.apache.org/licenses/LICENSE-2.0 | 
| 8 | // | 
| 9 | // Unless required by applicable law or agreed to in writing, software | 
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, | 
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
| 12 | // See the License for the specific language governing permissions and | 
| 13 | // limitations under the License. | 
| 14 |   | 
| 15 | package net.sourceforge.hiveboard.main; | 
| 16 |   | 
| 17 | import java.util.Map; | 
| 18 |   | 
| 19 | import net.sourceforge.hiveboard.util.VersionContext; | 
| 20 | import net.sourceforge.hiveboard.util.VersionMismatchException; | 
| 21 | import net.sourceforge.hiveremoting.caucho.RemoteContextHandler; | 
| 22 |   | 
| 23 | public class VersionContextHandler implements RemoteContextHandler | 
| 24 | { | 
| 25 |         public VersionContextHandler(String clientVersion) | 
| 26 |         { | 
| 27 |                 _clientVersion = clientVersion; | 
| 28 |         } | 
| 29 |          | 
| 30 |         @SuppressWarnings("unchecked") | 
| 31 |         public void                initContext(Map<String, String> context) | 
| 32 |         { | 
| 33 |                 context.put(VersionContext.CLIENT_VERSION_KEY, _clientVersion); | 
| 34 |         } | 
| 35 |   | 
| 36 |         public void                extractContext(Map<String, String> context) | 
| 37 |         { | 
| 38 |                 String serverVersion = context.get(VersionContext.SERVER_VERSION_KEY); | 
| 39 |                 if (serverVersion == null) | 
| 40 |                 { | 
| 41 |                         // The only server that does not support version checking is HiveBoard 0.1.0 | 
| 42 |                         throw new VersionMismatchException(        "Obsolete server version", | 
| 43 |                                                                                                 _clientVersion, | 
| 44 |                                                                                                 "0.1.0", | 
| 45 |                                                                                                 "0.1.0"); | 
| 46 |                 } | 
| 47 |         } | 
| 48 |          | 
| 49 |         private String        _clientVersion; | 
| 50 | } |