1 /**
2 * Copyright (C) 2007 Joern Krueger surething@users.sourceforge.net
3 *
4 * This program is free software; you can redistribute
5 * it and/or modify it under the terms of the GNU General
6 * Public License version 2 as published by the Free Software
7 * Foundation.
8 *
9 * This program is distributed in the hope that it will be
10 * useful, but WITHOUT ANY WARRANTY; without even the implied
11 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place,
18 * Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21 package de.surething.lda.locations;
22
23 import java.net.InetAddress;
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import de.surethingies.properties.ParameterFactory;
28 import de.surethingies.properties.TypedParameter;
29
30 public class LocationFactory {
31
32 private static LocationFactory instance;
33
34 public static LocationFactory instance() {
35 if (instance == null) {
36 instance = new LocationFactory();
37 }
38
39 return instance;
40 }
41
42 /**
43 * If a location could not be identified with a unique Name, it shows a list
44 * of possible Locations. If there is only one Location Identified. There
45 * will be only one Location in the Result. If something goes wrong, an
46 * Exception is thrown.
47 *
48 * @return A List of identified Locations for this Place
49 * @throws Exception
50 * If something goes wrong (UnknownHostException i.e.)
51 */
52 public List<Location> getLocations() throws Exception {
53 List<Location> result = new ArrayList<Location>();
54
55
56 List<TypedParameter> params = ParameterFactory.instance().get(LocationSettings.DISPLAY_NAME.param());
57 for (TypedParameter param : params) {
58 result.add(new IpLocation(param.getIdentifier()));
59 }
60
61
62 InetAddress[] addresses = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
63 for (InetAddress address : addresses) {
64 IpLocation location = new IpLocation(address.getHostName());
65
66 if (!result.contains(location)) {
67 result.add(location);
68 }
69 }
70
71 return result;
72 }
73 }