Coverage Report - org.apache.onami.autobind.configuration.PropertiesProvider
 
Classes in this File Line Coverage Branch Coverage Complexity
PropertiesProvider
0%
0/14
0%
0/2
2.5
 
 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 static java.lang.String.format;
 21  
 import static java.util.logging.Level.WARNING;
 22  
 import static java.util.logging.Logger.getLogger;
 23  
 
 24  
 import java.net.URL;
 25  
 import java.util.Properties;
 26  
 import java.util.logging.Logger;
 27  
 
 28  
 import javax.inject.Provider;
 29  
 
 30  
 import org.apache.onami.configuration.PropertiesURLReader;
 31  
 
 32  0
 public class PropertiesProvider
 33  
     implements Provider<Properties>
 34  
 {
 35  
 
 36  0
     private final Logger _logger = getLogger( getClass().getName() );
 37  
 
 38  
     private URL url;
 39  
 
 40  
     private boolean isXML;
 41  
 
 42  
     public PropertiesProvider( URL url, boolean isXML )
 43  
     {
 44  0
         super();
 45  0
         this.url = url;
 46  0
         this.isXML = isXML;
 47  0
     }
 48  
 
 49  
     @Override
 50  
     public Properties get()
 51  
     {
 52  
         try
 53  
         {
 54  0
             _logger.info( format( "Doing lazy Loading for Configuration %s", url ) );
 55  0
             PropertiesURLReader reader = new PropertiesURLReader( url );
 56  0
             if(isXML){
 57  0
                     reader.inXMLFormat();
 58  
             }
 59  0
                         return reader.readConfiguration();
 60  
         }
 61  0
         catch ( Exception e )
 62  
         {
 63  0
             _logger.log( WARNING, format( "Configuration in %s couldn't be read.", url), e );
 64  0
             return new Properties();
 65  
         }
 66  
     }
 67  
 
 68  
 }