summaryrefslogtreecommitdiff
path: root/java/demo/Ice/optional/ContactDBI.java
blob: 10ec853de981d45e74aee737bd7655b2e5647c23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// **********************************************************************
//
// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

import Demo.*;

public class ContactDBI extends _ContactDBDisp
{
    private java.util.Map<String, Contact> _contacts = new java.util.HashMap<String, Contact>();

    @Override
    public final void
    addContact(String name, Ice.Optional<NumberType> type, Ice.Optional<String> number, Ice.IntOptional dialGroup,
               Ice.Current current)
    {
        Contact contact = new Contact();
        contact.name = name;
        if(type.isSet())
        {
            contact.setType(type.get());
        }
        if(number.isSet())
        {
            contact.setNumber(number.get());
        }
        if(dialGroup.isSet())
        {
            contact.setDialGroup(dialGroup.get());
        }
        _contacts.put(name, contact);
    }

    @Override
    public final void
    updateContact(String name, Ice.Optional<NumberType> type, Ice.Optional<String> number, Ice.IntOptional dialGroup,
                  Ice.Current current)
    {
        Contact c = _contacts.get(name);
        if(c != null)
        {
            if(type.isSet())
            {
                c.setType(type.get());
            }
            if(number.isSet())
            {
                c.setNumber(number.get());
            }
            if(dialGroup.isSet())
            {
                c.setDialGroup(dialGroup.get());
            }
        }
    }

    @Override
    public final Contact
    query(String name, Ice.Current current)
    {
        return _contacts.get(name);
    }

    @Override
    public final void
    queryDialgroup(String name, Ice.IntOptional dialGroup, Ice.Current current)
    {
        Contact c = _contacts.get(name);
        if(c != null)
        {
            dialGroup.set(c.optionalDialGroup());
        }
    }

    @Override
    public final Ice.Optional<String>
    queryNumber(String name, Ice.Current current)
    {
        Ice.Optional<String> ret = null;
        Contact c = _contacts.get(name);
        if(c != null)
        {
            ret = c.optionalNumber();
        }
        return ret;
    }

    @Override
    public void
    shutdown(Ice.Current current)
    {
        System.out.println("Shutting down...");
        current.adapter.getCommunicator().shutdown();
    }
}