| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| HostUtils |
|
| 3.5;3.5 |
| 1 | /* | |
| 2 | * This software is licensed under the Apache License, Version 2.0 | |
| 3 | * (the "License") agreement; you may not use this file except in compliance with | |
| 4 | * the License. You may obtain a copy of the License at | |
| 5 | * | |
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 7 | * | |
| 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 | package net.admin4j.util; | |
| 15 | ||
| 16 | import java.net.InetAddress; | |
| 17 | import java.net.UnknownHostException; | |
| 18 | ||
| 19 | /** | |
| 20 | * Generic host utilities. | |
| 21 | * @author D. Ashmore | |
| 22 | * @since 1.0 | |
| 23 | */ | |
| 24 | 0 | public class HostUtils { |
| 25 | ||
| 26 | public static String deriveServerName(String host) { | |
| 27 | 567 | if (host.indexOf(".") > 0) return host.substring(0, host.indexOf(".")); |
| 28 | 558 | else return host; |
| 29 | } | |
| 30 | ||
| 31 | public static String getHostName() { | |
| 32 | try { | |
| 33 | 537 | String host = InetAddress.getLocalHost().getHostName(); |
| 34 | 537 | return deriveServerName(host); |
| 35 | 0 | } catch (UnknownHostException e) { |
| 36 | 0 | throw new Admin4jRuntimeException(e); |
| 37 | } | |
| 38 | } | |
| 39 | ||
| 40 | } |