View Javadoc

1   package org.apache.onami.autobind.configuration;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   *
11   *  http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import javax.inject.Singleton;
24  
25  import org.apache.onami.autobind.annotations.GuiceModule;
26  import org.apache.onami.configuration.PropertiesURLReader;
27  
28  @Singleton
29  @GuiceModule
30  public class ConfigurationModule
31      extends org.apache.onami.configuration.ConfigurationModule
32  {
33  	
34  	protected List<PropertiesURLReader> readers = new ArrayList<PropertiesURLReader>();
35  	
36  	protected boolean bindSystemProperties;
37  
38  	protected boolean bindEnvironment;
39  
40  
41      @Override
42      protected void bindConfigurations()
43      {
44          // TODO what was the default implementation in rocoto 4.x?
45      	for(PropertiesURLReader reader : readers){
46      		 try
47               {
48                   bindProperties( reader.readConfiguration() );
49               }
50               catch ( Exception e )
51               {
52                   addError( "An error occurred while reading properties from '%s': %s", reader.getUrl(),
53                             e.getMessage() );
54               }
55      	}
56      	
57      	if(bindEnvironment){
58      		super.bindEnvironmentVariables();	
59      	}
60      	if(bindSystemProperties){
61      		super.bindSystemProperties();	
62      	}
63      }
64      
65      @Override
66      protected void bindEnvironmentVariables() {
67      	bindEnvironment = true;
68      }
69      
70      @Override
71      protected void bindSystemProperties() {
72      	bindSystemProperties = true;
73      }
74      
75      public void addConfigurationReader(PropertiesURLReader reader){
76      	this.readers.add(reader);
77      }
78  
79  }