1 | /**
|
---|
2 | * Peer.java
|
---|
3 | * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
|
---|
4 | *
|
---|
5 | * This program is free software: you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 | package org.expeditee.network;
|
---|
20 |
|
---|
21 | import java.net.InetAddress;
|
---|
22 | import java.net.UnknownHostException;
|
---|
23 |
|
---|
24 | import org.expeditee.gui.AttributeValuePair;
|
---|
25 | import org.expeditee.gui.MessageBay;
|
---|
26 |
|
---|
27 | public class Peer {
|
---|
28 | public static final int DEFAULT_PORT = 3000;
|
---|
29 |
|
---|
30 | private String name_ = null;
|
---|
31 |
|
---|
32 | private int port_ = DEFAULT_PORT;
|
---|
33 |
|
---|
34 | private InetAddress ip_ = null;
|
---|
35 |
|
---|
36 | public Peer(AttributeValuePair avp) throws UnknownHostException {
|
---|
37 | name_ = avp.getAttribute();
|
---|
38 | String[] address = avp.getValue().split("\\s+");
|
---|
39 |
|
---|
40 | ip_ = InetAddress.getByName(address[0]);
|
---|
41 |
|
---|
42 | if (address.length > 1) {
|
---|
43 | try {
|
---|
44 | port_ = Integer.parseInt(address[1]);
|
---|
45 | } catch (Exception e) {
|
---|
46 | MessageBay.errorMessage("Could not parse port in ["
|
---|
47 | + avp.toString() + "]");
|
---|
48 | }
|
---|
49 | }
|
---|
50 | }
|
---|
51 |
|
---|
52 | public int getPort() {
|
---|
53 | return port_;
|
---|
54 | }
|
---|
55 |
|
---|
56 | public InetAddress getAddress() {
|
---|
57 | return ip_;
|
---|
58 | }
|
---|
59 |
|
---|
60 | public String getName() {
|
---|
61 | return name_;
|
---|
62 | }
|
---|
63 | }
|
---|