1 | package geniusweb.profileconnection;
|
---|
2 |
|
---|
3 | import java.io.IOException;
|
---|
4 | import java.net.URI;
|
---|
5 |
|
---|
6 | import javax.websocket.ContainerProvider;
|
---|
7 | import javax.websocket.DeploymentException;
|
---|
8 |
|
---|
9 | import geniusweb.profile.Profile;
|
---|
10 | import tudelft.utilities.logging.Reporter;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * factory that provides a ProfileInterface given an URI, supporting both the ws
|
---|
14 | * and the file scheme for the uri
|
---|
15 | */
|
---|
16 | public class ProfileConnectionFactory {
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * @param uri the URI that can provide the {@link Profile}. Support
|
---|
20 | * both the ws and the file scheme for the uri.
|
---|
21 | * @param reporter the {@link Reporter} to log issues to
|
---|
22 | * @return a {@link ProfileInterface}
|
---|
23 | * @throws IOException if connection can't be made
|
---|
24 | * @throws DeploymentException if endpoint can't be published
|
---|
25 | */
|
---|
26 | public static ProfileInterface create(URI uri, Reporter reporter)
|
---|
27 | throws IOException, DeploymentException {
|
---|
28 | switch (uri.getScheme()) {
|
---|
29 | case "ws":
|
---|
30 | return new WebsocketProfileConnector(uri, reporter,
|
---|
31 | ContainerProvider.getWebSocketContainer());
|
---|
32 | case "file":
|
---|
33 | return new FileProfileConnector(uri.getSchemeSpecificPart());
|
---|
34 | default:
|
---|
35 | }
|
---|
36 | throw new IllegalArgumentException(
|
---|
37 | "Unsupported profile scheme " + uri.getScheme());
|
---|
38 | }
|
---|
39 |
|
---|
40 | }
|
---|