litesoft
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
package org.litesoft.configuration;
import java.io.*;
import java.util.*;
import org.litesoft.util.*;
public class ConfigAccessorFactoryProperties implements ConfigAccessorFactory
{
public static final ConfigAccessorFactory INSTANCE = new ConfigAccessorFactoryProperties();
private ConfigAccessorFactoryProperties()
{
}
public ConfigDataAccessor create( String pLoadedFromDirectory, String pLoadedFromName, InputStream pInputStream )
throws IOException
{
Utils.assertNotNull( "LoadedFromDirectory", pLoadedFromDirectory );
Utils.assertNotNull( "LoadedFromName", pLoadedFromName );
Utils.assertNotNull( "InputStream", pInputStream );
Properties props = new Properties();
props.load( pInputStream );
return new ConfigDataAccessorImpl( pLoadedFromDirectory, pLoadedFromName, props );
}
private static class ConfigDataAccessorImpl implements ConfigDataAccessor
{
private String mLoadedFromDirectory;
private String mLoadedFromName;
private Properties mProperties;
public ConfigDataAccessorImpl( String pLoadedFromDirectory, String pLoadedFromName, Properties pProperties )
{
mLoadedFromDirectory = pLoadedFromDirectory;
mLoadedFromName = pLoadedFromName;
mProperties = pProperties;
}
public String loadedFrom()
{
return mLoadedFromName + " from '" + loadedFromDirectory() + "'";
}
public String loadedFromDirectory()
{
return mLoadedFromDirectory;
}
/**
* All implementations MUST support RUN level, but may not support other levels
*
* @return an array with at least 1 (RUN) entry
*/
public Level[] getSetableSupportedLevels()
{
return new Level[]{Level.RUN};
}
/**
* All implementations MUST support RUN level, but may not support other levels
*
* @param pLevel null interpreted as RUN
* @param pKey not null or empty
* @param pValue null means remove
*
* @throws UnsupportedOperationException if requested level not supported
*/
public void setKeyValue( Level pLevel, String pKey, String pValue )
throws UnsupportedOperationException
{
if ( !Level.RUN.equals( Utils.deNull( pLevel, Level.RUN ) ) )
{
throw new UnsupportedOperationException( "setKeyValue for Level '" + pLevel + "' not supported" );
}
pKey = Utils.assertNotNullNotEmpty( "Key", pKey );
if ( pValue == null )
{
mProperties.remove( pKey );
}
else
{
mProperties.put( pKey, pValue );
}
}
public String[] getAllKeys()
{
List<String> keys = new ArrayList<String>();
for ( Object key : mProperties.keySet() )
{
if ( key instanceof String )
{
keys.add( (String) key );
}
}
return keys.toArray( new String[keys.size()] );
}
/**
* @param pKey not null or empty
*
* @return null if not found or value associated with key
*/
public String getString( String pKey )
{
Object o = mProperties.get( Utils.assertNotNullNotEmpty( "Key", pKey ) );
return (o == null) ? null : o.toString();
}
}
}
|
Revision |
Author |
Commited |
Message |
2
|
GeorgeS
|
Sun 07 Feb, 2010 12:50:58 +0000 |
|