Shuyi Chen | d7955ce | 2013-05-22 14:51:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2009 Mike Cumings |
| 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 | |
| 17 | package com.kenai.jbosh; |
| 18 | |
| 19 | import java.util.concurrent.TimeUnit; |
| 20 | |
| 21 | /** |
| 22 | * Data type representing the getValue of the {@code pause} attribute of the |
| 23 | * {@code bosh} element. |
| 24 | */ |
| 25 | final class AttrPause extends AbstractIntegerAttr { |
| 26 | |
| 27 | /** |
| 28 | * Creates a new attribute object. |
| 29 | * |
| 30 | * @param val attribute getValue |
| 31 | * @throws BOSHException on parse or validation failure |
| 32 | */ |
| 33 | private AttrPause(final String val) throws BOSHException { |
| 34 | super(val); |
| 35 | checkMinValue(1); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Creates a new attribute instance from the provided String. |
| 40 | * |
| 41 | * @param str string representation of the attribute |
| 42 | * @return attribute instance or {@code null} if provided string is |
| 43 | * {@code null} |
| 44 | * @throws BOSHException on parse or validation failure |
| 45 | */ |
| 46 | static AttrPause createFromString(final String str) |
| 47 | throws BOSHException { |
| 48 | if (str == null) { |
| 49 | return null; |
| 50 | } else { |
| 51 | return new AttrPause(str); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Get the pause time in milliseconds. |
| 57 | * |
| 58 | * @return pause tme in milliseconds |
| 59 | */ |
| 60 | public int getInMilliseconds() { |
| 61 | return (int) TimeUnit.MILLISECONDS.convert( |
| 62 | intValue(), TimeUnit.SECONDS); |
| 63 | } |
| 64 | |
| 65 | } |