View Javadoc

1   /*
2    * <cvs:source>$Source: /devel/astrogrid/filemanager/server/src/java/org/astrogrid/filemanager/server/FileManagerConfigImpl.java,v $</cvs:source>
3    * <cvs:author>$Author: jdt $</cvs:author>
4    * <cvs:date>$Date: 2005/01/13 17:23:15 $</cvs:date>
5    * <cvs:version>$Revision: 1.3 $</cvs:version>
6    * <cvs:log>
7    *   $Log: FileManagerConfigImpl.java,v $
8    *   Revision 1.3  2005/01/13 17:23:15  jdt
9    *   merges from dave-dev-200412201250
10   *
11   *   Revision 1.2.4.2  2005/01/12 14:28:46  dave
12   *   Changed tabs to spaces ...
13   *
14   *   Revision 1.2.4.1  2005/01/10 15:36:28  dave
15   *   Refactored store into a separate interface and mock impl ...
16   *
17   *   Revision 1.2  2004/11/25 00:20:30  jdt
18   *   Merge from dave-dev-200410061224-200411221626
19   *
20   *   Revision 1.1.2.3  2004/11/18 14:39:32  dave
21   *   Added SOAP delegate, RemoteException decoding and test case.
22   *
23   *   Revision 1.1.2.2  2004/11/17 19:33:17  dave
24   *   Fixed imports ...
25   *
26   *   Revision 1.1.2.1  2004/11/17 19:05:17  dave
27   *   Added manager config ...
28   *
29   * </cvs:log>
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     }