webidor/src/main/java/cz/xelfi/quoridor/webidor/User.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 07 Nov 2009 15:23:14 +0100
changeset 143 4eb88f05c207
child 171 524c7f359c4e
permissions -rw-r--r--
Support for properties associated with every user
jaroslav@143
     1
/*
jaroslav@143
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
jaroslav@143
     3
 *
jaroslav@143
     4
 * The contents of this file are subject to the terms of either the GNU
jaroslav@143
     5
 * General Public License Version 2 only ("GPL") or the Common
jaroslav@143
     6
 * Development and Distribution License("CDDL") (collectively, the
jaroslav@143
     7
 * "License"). You may not use this file except in compliance with the
jaroslav@143
     8
 * License. You can obtain a copy of the License at
jaroslav@143
     9
 * http://www.netbeans.org/cddl-gplv2.html
jaroslav@143
    10
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
jaroslav@143
    11
 * specific language governing permissions and limitations under the
jaroslav@143
    12
 * License.  When distributing the software, include this License Header
jaroslav@143
    13
 * Notice in each file and include the License file at
jaroslav@143
    14
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
jaroslav@143
    15
 * particular file as subject to the "Classpath" exception as provided
jaroslav@143
    16
 * by Sun in the GPL Version 2 section of the License file that
jaroslav@143
    17
 * accompanied this code. If applicable, add the following below the
jaroslav@143
    18
 * License Header, with the fields enclosed by brackets [] replaced by
jaroslav@143
    19
 * your own identifying information:
jaroslav@143
    20
 * "Portions Copyrighted [year] [name of copyright owner]"
jaroslav@143
    21
 *
jaroslav@143
    22
 * Contributor(s):
jaroslav@143
    23
 *
jaroslav@143
    24
 * Portions Copyrighted 2009 Jaroslav Tulach
jaroslav@143
    25
 */
jaroslav@143
    26
jaroslav@143
    27
package cz.xelfi.quoridor.webidor;
jaroslav@143
    28
jaroslav@143
    29
import java.util.ArrayList;
jaroslav@143
    30
import java.util.List;
jaroslav@143
    31
import javax.xml.bind.annotation.XmlAccessType;
jaroslav@143
    32
import javax.xml.bind.annotation.XmlAccessorType;
jaroslav@143
    33
import javax.xml.bind.annotation.XmlAttribute;
jaroslav@143
    34
import javax.xml.bind.annotation.XmlElement;
jaroslav@143
    35
import javax.xml.bind.annotation.XmlRootElement;
jaroslav@143
    36
import javax.xml.bind.annotation.XmlValue;
jaroslav@143
    37
jaroslav@143
    38
/**
jaroslav@143
    39
 *
jaroslav@143
    40
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@143
    41
 */
jaroslav@143
    42
@XmlRootElement
jaroslav@143
    43
@XmlAccessorType(XmlAccessType.NONE)
jaroslav@143
    44
public final class User extends Object {
jaroslav@143
    45
    @XmlAttribute
jaroslav@143
    46
    private String id;
jaroslav@143
    47
    @XmlElement(name="property")
jaroslav@143
    48
    private List<Property> properties;
jaroslav@143
    49
jaroslav@143
    50
    User() {
jaroslav@143
    51
    }
jaroslav@143
    52
jaroslav@143
    53
    public User(String id) {
jaroslav@143
    54
        this.id = id;
jaroslav@143
    55
    }
jaroslav@143
    56
jaroslav@143
    57
    public void addProperty(String name, String value) {
jaroslav@143
    58
        if (properties == null) {
jaroslav@143
    59
            properties = new ArrayList<Property>();
jaroslav@143
    60
        }
jaroslav@143
    61
        properties.add(new Property(name, value));
jaroslav@143
    62
    }
jaroslav@143
    63
jaroslav@143
    64
    public String getProperty(String name) {
jaroslav@143
    65
        if (properties == null) {
jaroslav@143
    66
            return null;
jaroslav@143
    67
        }
jaroslav@143
    68
        for (Property p : properties) {
jaroslav@143
    69
            if (p.name.equals(name)) {
jaroslav@143
    70
                return p.value;
jaroslav@143
    71
            }
jaroslav@143
    72
        }
jaroslav@143
    73
        return null;
jaroslav@143
    74
    }
jaroslav@143
    75
jaroslav@143
    76
    public String getId() {
jaroslav@143
    77
        return id;
jaroslav@143
    78
    }
jaroslav@143
    79
jaroslav@143
    80
    public static final class Property {
jaroslav@143
    81
        @XmlAttribute
jaroslav@143
    82
        private String name;
jaroslav@143
    83
        @XmlValue
jaroslav@143
    84
        private String value;
jaroslav@143
    85
jaroslav@143
    86
        private Property() {
jaroslav@143
    87
        }
jaroslav@143
    88
jaroslav@143
    89
        Property(String name, String value) {
jaroslav@143
    90
            this.name = name;
jaroslav@143
    91
            this.value = value;
jaroslav@143
    92
        }
jaroslav@143
    93
    }
jaroslav@143
    94
}