1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 package org.astrogrid.filemanager.server ;
33
34 import org.apache.commons.logging.Log ;
35 import org.apache.commons.logging.LogFactory ;
36
37 import org.astrogrid.store.Ivorn ;
38
39 import org.astrogrid.config.Config ;
40 import org.astrogrid.config.SimpleConfig ;
41 import org.astrogrid.config.PropertyNotFoundException ;
42
43 import org.astrogrid.filemanager.common.FileManagerConfig ;
44 import org.astrogrid.filemanager.common.exception.FileManagerServiceException ;
45
46 /***
47 * Server implementation of the FileManager configuration.
48 * This uses the default AstroGrid configuration to get the properties.
49 *
50 */
51 public class FileManagerConfigImpl
52 implements FileManagerConfig
53 {
54 /***
55 * Our debug logger.
56 *
57 */
58 private static Log log = LogFactory.getLog(FileManagerConfigImpl.class);
59
60 /***
61 * The config property key for our service name.
62 *
63 */
64 public static final String SERVICE_NAME = "org.astrogrid.filemanager.service.name" ;
65
66 /***
67 * Reference to our AstroGrid config.
68 *
69 */
70 private Config config ;
71
72 /***
73 * Public constructor, using the default AstroGrid config.
74 *
75 */
76 public FileManagerConfigImpl()
77 {
78 this(
79 SimpleConfig.getSingleton()
80 ) ;
81 }
82
83 /***
84 * Public constructor, using a specific config.
85 * @param config Reference to the config to use.
86 *
87 */
88 public FileManagerConfigImpl(Config config)
89 {
90 this.config = config ;
91 }
92
93 /***
94 * Access to the local service name.
95 *
96 */
97 public String getServiceName()
98 {
99 return (String) config.getProperty(
100 SERVICE_NAME
101 ) ;
102 }
103
104 /***
105 * Access to a config property, using the service name prefix.
106 * @param name The property name (this is combined with the service name to make the full property key).
107 *
108 */
109 public String getServiceProperty(String name)
110 {
111 log.debug("");
112 log.debug("FileStoreConfigImpl.getServiceProperty()");
113 log.debug(" Name : " + name);
114 String index = getServiceName() + "." + name ;
115 log.debug(" Index : " + index);
116 String value = (String) config.getProperty(
117 index
118 ) ;
119 log.debug(" Value : " + value);
120 return value ;
121 }
122
123 /***
124 * Access to the local service ivorn.
125 * @throws FileManagerServiceException if unable to read the property.
126 *
127 */
128 public Ivorn getFileManagerIvorn()
129 throws FileManagerServiceException
130 {
131 try {
132 return new Ivorn(
133 getServiceProperty(
134 "service.ivorn"
135 )
136 ) ;
137 }
138 catch (Throwable ouch)
139 {
140 throw new FileManagerServiceException(
141 "Unable to read FileManager ivorn from config.",
142 ouch
143 ) ;
144 }
145 }
146
147 /***
148 * Access to the local service ivorn.
149 * @throws FileManagerServiceException if unable to read the property.
150 *
151 */
152 public Ivorn getFileStoreIvorn()
153 throws FileManagerServiceException
154 {
155 try {
156 return new Ivorn(
157 getServiceProperty(
158 "filestore.ivorn"
159 )
160 ) ;
161 }
162 catch (Throwable ouch)
163 {
164 throw new FileManagerServiceException(
165 "Unable to read FileStore ivorn from config.",
166 ouch
167 ) ;
168 }
169 }
170
171 }