View Javadoc

1   /*
2    *
3    * <cvs:source>$Source: /devel/astrogrid/filestore/server/src/java/org/astrogrid/filestore/server/FileStoreConfigImpl.java,v $</cvs:source>
4    * <cvs:author>$Author: clq2 $</cvs:author>
5    * <cvs:date>$Date: 2005/01/28 10:44:04 $</cvs:date>
6    * <cvs:version>$Revision: 1.4 $</cvs:version>
7    * <cvs:log>
8    *   $Log: FileStoreConfigImpl.java,v $
9    *   Revision 1.4  2005/01/28 10:44:04  clq2
10   *   dave_dev_200501141257 (filemanager)
11   *
12   *   Revision 1.3.8.1  2005/01/17 17:19:21  dave
13   *   Fixed bug in FileManagerImpl test (missing '/' in repository path on Unix) ...
14   *   Changed tabs to spaces ..
15   *
16   *   Revision 1.3  2004/12/13 00:51:56  jdt
17   *   merge from FLS_JDT_861
18   *
19   *   Revision 1.2.2.1  2004/12/09 11:54:53  jdt
20   *   Made file:// windows-friendly.
21   *
22   *   Revision 1.2  2004/11/25 00:19:27  jdt
23   *   Merge from dave-dev-200410061224-200411221626
24   *
25   *   Revision 1.1.2.2  2004/11/17 19:06:30  dave
26   *   Updated server configuration ...
27   *
28   *   Revision 1.1.2.1  2004/10/19 14:56:16  dave
29   *   Refactored config and resolver to enable multiple instances of mock implementation.
30   *   Required to implement handling of multiple FileStore(s) in FileManager.
31   *
32   *   Revision 1.3  2004/08/18 19:00:01  dave
33   *   Myspace manager modified to use remote filestore.
34   *   Tested before checkin - integration tests at 91%.
35   *
36   *   Revision 1.2.22.2  2004/08/09 10:16:28  dave
37   *   Added resource URL to the properties.
38   *
39   *   Revision 1.2.22.1  2004/08/06 22:25:06  dave
40   *   Refactored bits and broke a few tests ...
41   *
42   *   Revision 1.2  2004/07/14 13:50:29  dave
43   *   Merged development branch, dave-dev-200406301228, into HEAD
44   *
45   *   Revision 1.1.2.1  2004/07/12 14:39:03  dave
46   *   Added server repository classes
47   *
48   *   Revision 1.1.2.1  2004/07/08 07:31:30  dave
49   *   Added container impl and tests
50   *
51   * </cvs:log>
52   *
53   */
54  package org.astrogrid.filestore.server ;
55  
56  import java.io.File ;
57  
58  import java.net.URL ;
59  import java.net.URLConnection ;
60  import java.net.MalformedURLException ;
61  
62  import org.apache.commons.logging.Log ;
63  import org.apache.commons.logging.LogFactory ;
64  
65  import org.astrogrid.store.Ivorn ;
66  
67  import org.astrogrid.config.Config ;
68  import org.astrogrid.config.SimpleConfig ;
69  import org.astrogrid.config.PropertyNotFoundException ;
70  
71  import org.astrogrid.filestore.common.ivorn.FileStoreIvornFactory ;
72  import org.astrogrid.filestore.common.exception.FileStoreServiceException ;
73  
74  import org.astrogrid.filestore.common.FileStoreConfig ;
75  
76  /***
77   * Configuration implementation using the AstroGrid Config.
78   *
79   */
80  public class FileStoreConfigImpl
81      implements FileStoreConfig
82      {
83      /***
84       * Our debug logger.
85       *
86       */
87      private static Log log = LogFactory.getLog(FileStoreConfigImpl.class);
88  
89      /***
90       * The config property key for our service name.
91       *
92       */
93      public static final String SERVICE_NAME = "org.astrogrid.filestore.service.name" ;
94  
95      /***
96       * Reference to our AstroGrid config.
97       *
98       */
99      private Config config ;
100 
101     /***
102      * Public constructor, using the default AstroGrid config.
103      *
104      */
105     public FileStoreConfigImpl()
106         {
107         this(
108             SimpleConfig.getSingleton()
109             ) ;
110         }
111 
112     /***
113      * Public constructor, using a specific config.
114      * @param config Reference to the config to use.
115      *
116      */
117     public FileStoreConfigImpl(Config config)
118         {
119         this.config = config ;
120         }
121 
122     /***
123      * Access to the local service name.
124      *
125      */
126     public String getServiceName()
127         {
128         String name = (String) config.getProperty(
129             SERVICE_NAME
130             ) ;
131         return name ;
132         }
133 
134     /***
135      * Access to a config property, using the service name prefix.
136      * @param name The property name (this is combined with the service name to make the full property key).
137      *
138      */
139     public String getServiceProperty(String name)
140         {
141         log.debug("");
142         log.debug("FileStoreConfigImpl.getServiceProperty()");
143         log.debug("  Name  : " + name);
144         String index = getServiceName() + "." + name ;
145         log.debug("  Index : " + index);
146         String value = (String) config.getProperty(
147             index
148             ) ;
149         log.debug("  Value : " + value);
150         return value ;
151         }
152 
153     /***
154      * Access to the local service ivorn.
155      * @throws FileStoreServiceException if unable to read the property.
156      *
157      */
158     public Ivorn getServiceIvorn()
159         throws FileStoreServiceException
160         {
161         log.debug("");
162         log.debug("FileStoreConfigImpl.getServiceIvorn()");
163         try {
164             return new Ivorn(
165                 getServiceProperty(
166                     "service.ivorn"
167                     )
168                 ) ;
169             }
170         catch (Throwable ouch)
171             {
172             log.error("Unable to read service ivorn from config", ouch);
173             throw new FileStoreServiceException(
174                 "Unable to read service ivorn from config.",
175                 ouch
176                 ) ;
177             }
178         }
179 
180     /***
181      * The local service URL.
182      * @throws FileStoreServiceException if unable to read the property.
183      *
184      */
185     public URL getServiceUrl()
186         throws FileStoreServiceException
187         {
188         log.debug("");
189         log.debug("FileStoreConfigImpl.getServiceUrl()");
190         try {
191             return new URL(
192                 getServiceProperty(
193                     "service.url"
194                     )
195                 ) ;
196             }
197         catch (Throwable ouch)
198             {
199             throw new FileStoreServiceException(
200                 "Unable to generate service URL.",
201                 ouch
202                 ) ;
203             }
204         }
205 
206     /***
207      * Generate a resource ivorn.
208      * @param ident - the resource identifier.
209      * @throws FileStoreServiceException if unable to read the property.
210      *
211      */
212     public Ivorn getResourceIvorn(String ident)
213         throws FileStoreServiceException
214         {
215         log.debug("");
216         log.debug("FileStoreConfigImpl.getResourceIvorn()");
217         log.debug("  Ident : " + ident);
218         try {
219             return FileStoreIvornFactory.createIvorn(
220                 getServiceProperty(
221                     "service.ivorn"
222                     ),
223                 ident
224                 ) ;
225             }
226         catch (Throwable ouch)
227             {
228             throw new FileStoreServiceException(
229                 "Unable to generate resource ivorn.",
230                 ouch
231                 ) ;
232             }
233         }
234 
235     /***
236      * Generate a resource URL.
237      * @param ident - the resource identifier.
238      * @throws FileStoreServiceException if unable to read the property.
239      *
240      */
241     public URL getResourceUrl(String ident)
242         throws FileStoreServiceException
243         {
244         log.debug("");
245         log.debug("FileStoreConfigImpl.getResourceUrl()");
246         log.debug("  Ident : " + ident);
247         try {
248             return new URL(
249                 getServiceProperty(
250                     "service.url"
251                     )
252                 + "/" + ident
253                 ) ;
254             }
255         catch (Throwable ouch)
256             {
257             throw new FileStoreServiceException(
258                 "Unable to generate resource URL.",
259                 ouch
260                 ) ;
261             }
262         }
263 
264     /***
265      * The repository data directory.
266      * @throws FileStoreServiceException if unable to read the property.
267      *
268      */
269     public File getDataDirectory()
270         throws FileStoreServiceException
271         {
272         log.debug("");
273         log.debug("FileStoreConfigImpl.getDataDirectory()");
274         try {
275             return new File(
276                 getServiceProperty(
277                     "repository"
278                     )
279                 ) ;
280             }
281         catch (Throwable ouch)
282             {
283             throw new FileStoreServiceException(
284                 "Unable to read data directory from config.",
285                 ouch
286                 ) ;
287             }
288         }
289 
290     /***
291      * The repository info directory.
292      * @throws FileStoreServiceException if unable to read the property.
293      *
294      */
295     public File getInfoDirectory()
296         throws FileStoreServiceException
297         {
298         log.debug("");
299         log.debug("FileStoreConfigImpl.getInfoDirectory()");
300         try {
301             return new File(
302                 getServiceProperty(
303                     "repository"
304                     )
305                 ) ;
306             }
307         catch (Throwable ouch)
308             {
309             throw new FileStoreServiceException(
310                 "Unable to read info directory from config.",
311                 ouch
312                 ) ;
313             }
314         }
315     }
316 
317 
318