serverside/src/main/java/org/apidesign/bck2brwsr/demo/serverside/MessageImpl.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sun, 05 May 2013 18:11:29 +0200
changeset 12 84266695c06f
parent 9 045360776205
permissions -rw-r--r--
Show some time indicator
jtulach@5
     1
/**
jtulach@5
     2
 * The MIT License (MIT)
jtulach@5
     3
 *
jtulach@5
     4
 * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jtulach@5
     5
 *
jtulach@5
     6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
jtulach@5
     7
 * of this software and associated documentation files (the "Software"), to deal
jtulach@5
     8
 * in the Software without restriction, including without limitation the rights
jtulach@5
     9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jtulach@5
    10
 * copies of the Software, and to permit persons to whom the Software is
jtulach@5
    11
 * furnished to do so, subject to the following conditions:
jtulach@5
    12
 *
jtulach@5
    13
 * The above copyright notice and this permission notice shall be included in
jtulach@5
    14
 * all copies or substantial portions of the Software.
jtulach@5
    15
 *
jtulach@5
    16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jtulach@5
    17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jtulach@5
    18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jtulach@5
    19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jtulach@5
    20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jtulach@5
    21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jtulach@5
    22
 * THE SOFTWARE.
jtulach@5
    23
 */
jtulach@5
    24
package org.apidesign.bck2brwsr.demo.serverside;
jtulach@5
    25
jtulach@5
    26
import net.java.html.json.ComputedProperty;
jtulach@5
    27
import net.java.html.json.Model;
jtulach@5
    28
import net.java.html.json.Property;
jtulach@5
    29
jtulach@5
    30
/**
jtulach@5
    31
 *
jtulach@5
    32
 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jtulach@5
    33
 */
jtulach@5
    34
@Model(className = "Message", properties = {
jtulach@5
    35
    @Property(name = "user", type = String.class),
jtulach@5
    36
    @Property(name = "comment", type = String.class),
jtulach@9
    37
    @Property(name = "when", type = long.class)    
jtulach@5
    38
})
jtulach@5
    39
class MessageImpl {
jtulach@12
    40
    private static final long start = System.currentTimeMillis();
jtulach@12
    41
    
jtulach@12
    42
    static long startTime() {
jtulach@12
    43
        return start;
jtulach@12
    44
    }
jtulach@12
    45
    
jtulach@12
    46
    @ComputedProperty static String at(long when) {
jtulach@12
    47
        long delta = (when - start) / 1000;
jtulach@12
    48
        if (delta <= 0) {
jtulach@12
    49
            return "Before BigBeng";
jtulach@12
    50
        }
jtulach@12
    51
        if (delta < 60) {
jtulach@12
    52
            return delta + "s";
jtulach@12
    53
        }
jtulach@12
    54
        delta /= 60;
jtulach@12
    55
        return delta + "min";
jtulach@5
    56
    }
jtulach@5
    57
jtulach@5
    58
    @Model(className = "Query", properties = {
jtulach@5
    59
        @Property(name = "messages", type = Message.class, array = true)
jtulach@5
    60
    })
jtulach@5
    61
    class QryMsgs {
jtulach@5
    62
    }
jtulach@5
    63
}