View Javadoc

1   /* 
2    * Copyright (c) 2007, Fraunhofer-Gesellschaft
3    * All rights reserved.
4    * 
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are
7    * met:
8    * 
9    * (1) Redistributions of source code must retain the above copyright
10   *     notice, this list of conditions and the disclaimer at the end.
11   *     Redistributions in binary form must reproduce the above copyright
12   *     notice, this list of conditions and the following disclaimer in
13   *     the documentation and/or other materials provided with the
14   *     distribution.
15   * 
16   * (2) Neither the name of Fraunhofer nor the names of its
17   *     contributors may be used to endorse or promote products derived
18   *     from this software without specific prior written permission.
19   * 
20   * DISCLAIMER
21   * 
22   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33   *  
34   */
35  package org.ogf.graap.wsag.api.configuration;
36  
37  import org.apache.log4j.Logger;
38  import org.ogf.graap.wsag.api.logging.LogMessage;
39  
40  /**
41   * MSSEnvironment
42   * 
43   * @author Oliver Waeldrich
44   */
45  public class WSAG4JEnvironment
46      implements WSAG4JConfigurationEnvironment
47  {
48  
49      private static final Logger LOG = Logger.getLogger( WSAG4JEnvironment.class );
50  
51      /**
52       * System property to lookup default WSAG4J configuration path.
53       */
54      public static final String DEFAULT_CONFIGURATION_PATH_KEY = "wsag4j.configuration.path";
55  
56      /**
57       * Default WSAG4J configuration path.
58       */
59      public static final String DEFAULT_CONFIGURATION_PATH = "/etc/wsag4j";
60  
61      /**
62       * Default WSAG4J configuration file.
63       */
64      public static final String DEFAULT_CONFIGURATION_FILE = "wsag4j.properties";
65  
66      private String configurationPath = null;
67  
68      /**
69       * default constructor
70       */
71      public WSAG4JEnvironment()
72      {
73          String message =
74              "WSAG4J environment properties file not found. Using default configuration path {0}.";
75          LOG.debug( LogMessage.getMessage( message, DEFAULT_CONFIGURATION_PATH ) );
76  
77          configurationPath = DEFAULT_CONFIGURATION_PATH;
78      }
79  
80      /**
81       * Creates a configuration environment with the specified configuration path.
82       * 
83       * @param path
84       *            the WSAG4J configuration path
85       */
86      public WSAG4JEnvironment( String path )
87      {
88          if ( path == null )
89          {
90              path = DEFAULT_CONFIGURATION_PATH;
91  
92              String message =
93                  "Configuration path not specified in WSAG4J environment properties file. "
94                      + "Using default configuration path {0}.";
95              LOG.debug( LogMessage.getMessage( message, DEFAULT_CONFIGURATION_PATH ) );
96          }
97          else
98          {
99              String message = "Configuration path specified in WSAG4J environment properties file. Path: {0}";
100             LOG.debug( LogMessage.getMessage( message, path ) );
101         }
102 
103         configurationPath = path;
104     }
105 
106     /**
107      * {@inheritDoc}
108      * 
109      * @see WSAG4JConfigurationEnvironment#getConfigurationPath()
110      */
111     public String getConfigurationPath()
112     {
113         String defaultPath = System.getProperty( DEFAULT_CONFIGURATION_PATH_KEY );
114         if ( defaultPath != null )
115         {
116             String message =
117                 "Found system property {0} with value {1} (overwriting directory from configuration file {2}).";
118 
119             LOG.info( LogMessage.getMessage( message, DEFAULT_CONFIGURATION_PATH_KEY, defaultPath,
120                 configurationPath ) );
121 
122             return defaultPath;
123         }
124 
125         return configurationPath;
126     }
127 
128 }