1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.limmen.crs.client.locator;
17
18 import static org.limmen.crs.Constants.SERVICE_CONTEXTPATH_PROPERTY;
19 import static org.limmen.crs.Constants.SERVICE_HOSTNAME_PROPERTY;
20 import static org.limmen.crs.Constants.SERVICE_PORT_PROPERTY;
21
22 public class StaticServiceLocator implements ServiceLocator {
23
24 @Override
25 public Service locate() throws ServiceLocatorException {
26
27 Service service = null;
28
29 if (System.getProperty(SERVICE_HOSTNAME_PROPERTY) != null
30 && System.getProperty(SERVICE_PORT_PROPERTY) != null) {
31
32 String hostname = System.getProperty(SERVICE_HOSTNAME_PROPERTY);
33 int port = Integer.parseInt(System.getProperty(SERVICE_PORT_PROPERTY));
34 String contextPath = System.getProperty(SERVICE_CONTEXTPATH_PROPERTY);
35
36 service = new Service(hostname, port, contextPath);
37 }
38 else {
39
40 if (System.getProperty(SERVICE_HOSTNAME_PROPERTY) == null) {
41
42 throw new ServiceLocatorException(String.format("Property '%0$s' not found!", SERVICE_HOSTNAME_PROPERTY));
43 }
44 if (System.getProperty(SERVICE_PORT_PROPERTY) == null) {
45
46 throw new ServiceLocatorException(String.format("Property '%0$s' not found!", SERVICE_PORT_PROPERTY));
47 }
48 }
49
50 return service;
51 }
52 }