1 | |
package org.apache.onami.autobind.configuration; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
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 | |
} |