View Javadoc

1   /*
2    * $Id: FileResourcePlugin.java,v 1.2 2005/03/21 18:45:55 mch Exp $
3    *
4    * (C) Copyright Astrogrid...
5    */
6   
7   package org.astrogrid.dataservice.metadata;
8   
9   import java.io.IOException;
10  import java.net.URL;
11  import org.astrogrid.cfg.ConfigReader;
12  import org.astrogrid.cfg.ConfigException;
13  import org.astrogrid.cfg.ConfigFactory;
14  
15  /***
16   * Serves a metadata resource from a file on disk.
17   * <p>
18   * @author M Hill
19   */
20  
21  public class FileResourcePlugin extends UrlResourcePlugin
22  {
23     /*** Configuration key to where the metadata file is located */
24     public static final String METADATA_FILE_LOC_KEY = "datacenter.resource.filename";
25     
26     /*** Returns the URLs to the metadata files given by the configuration properties */
27     public URL[] getResourceUrls() throws IOException {
28  
29        Object[] filenames = ConfigFactory.getCommonConfig().getProperties(METADATA_FILE_LOC_KEY);
30        
31        if (filenames.length == 0 ) {
32           throw new ConfigException("Server not configured properly: no '"+METADATA_FILE_LOC_KEY+"' keys are set in config ("+ConfigFactory.getCommonConfig().loadedFrom()+") to locate metadata file.");
33        }
34  
35        URL[] resourceUrls = new URL[filenames.length];
36  
37        for (int f = 0; f < filenames.length; f++) {
38           resourceUrls[f] = ConfigReader.resolveFilename(filenames[f].toString());
39           
40           if (resourceUrls[f] == null) {
41              throw new IOException("Resource file at '"+filenames[f]+"' not found");
42           }
43        }
44        return resourceUrls;
45     }
46     
47     
48  }
49  
50