Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/client/Config.java @ 9:8facd8545a12
Added a global configuration for the client and classes providing methods to retrieve these information.
flys-client/trunk@1317 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 16 Feb 2011 14:50:06 +0000 |
parents | |
children | 924da6695800 |
comparison
equal
deleted
inserted
replaced
8:9cb3ee7ed8ba | 9:8facd8545a12 |
---|---|
1 package de.intevation.flys.client.client; | |
2 | |
3 import com.google.gwt.xml.client.Document; | |
4 import com.google.gwt.xml.client.Node; | |
5 | |
6 | |
7 /** | |
8 * A class that is used to handle the global configuration of this client. You | |
9 * can retrieve an instance of this class using the <code>getInstance</code> | |
10 * methods. <b>NOTE:</b> the configuration is initialized using {@link | |
11 * getInstance(Document)} the first time. | |
12 * | |
13 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
14 */ | |
15 public class Config { | |
16 | |
17 /** The instance of the configuration. */ | |
18 protected static Config INSTANCE; | |
19 | |
20 /** The xml document that contains the configuration options.*/ | |
21 protected Document config; | |
22 | |
23 | |
24 /** | |
25 * Get an instance by using {@link getInstance(Document)} or {@link | |
26 * getInstance()}. | |
27 */ | |
28 private Config(Document config) { | |
29 this.config = config; | |
30 } | |
31 | |
32 | |
33 /** | |
34 * Returns an instance of this class and initializes the configuration of | |
35 * this has not been done so far. | |
36 * | |
37 * @param config The client configuration. | |
38 * | |
39 * @return an instance of this Config class. | |
40 */ | |
41 public static Config getInstance(Document config) { | |
42 if (INSTANCE == null) { | |
43 INSTANCE = new Config(config); | |
44 } | |
45 | |
46 return INSTANCE; | |
47 } | |
48 | |
49 | |
50 /** | |
51 * Returns an instance of this class. If it has not been initialized with a | |
52 * valid configuration, null is returned. | |
53 * | |
54 * @return an instance of this class or null, if the Config has not been | |
55 * initialized using {@link getInstance(Document)} so far. | |
56 */ | |
57 public static Config getInstance() { | |
58 return INSTANCE; | |
59 } | |
60 | |
61 | |
62 /** | |
63 * Returns the URL of the artifact server. | |
64 * | |
65 * @return the artifact server url. | |
66 */ | |
67 public String getServerUrl() { | |
68 Node server = config.getElementsByTagName("server").item(0); | |
69 return server.getFirstChild().getNodeValue(); | |
70 } | |
71 } | |
72 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |