Class TypedProperties
- java.lang.Object
-
- java.util.AbstractMap<java.lang.String,java.lang.Object>
-
- org.apache.felix.utils.properties.TypedProperties
-
- All Implemented Interfaces:
java.util.Map<java.lang.String,java.lang.Object>
public class TypedProperties extends java.util.AbstractMap<java.lang.String,java.lang.Object>
Map to load / store / update untyped or typed properties. The map is untyped if all properties are strings. When this is the case, the properties are stored without any encoding, else all properties are encoded using the
ConfigurationHandler
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TypedProperties.DynamicMap
static interface
TypedProperties.SubstitutionCallback
-
Field Summary
Fields Modifier and Type Field Description private TypedProperties.SubstitutionCallback
callback
static java.lang.String
ENV_PREFIX
private Properties
storage
private boolean
substitute
-
Constructor Summary
Constructors Constructor Description TypedProperties()
TypedProperties(boolean substitute)
TypedProperties(TypedProperties.SubstitutionCallback callback)
TypedProperties(TypedProperties.SubstitutionCallback callback, boolean substitute)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
private static java.lang.Object
convertFromString(java.lang.String value)
private static java.lang.String
convertToString(java.lang.Object value)
private void
ensureTyped()
java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>>
entrySet()
java.lang.Object
get(java.lang.Object key)
java.util.List<java.lang.String>
getComments(java.lang.String key)
java.util.List<java.lang.String>
getFooter()
Return the comment footer.java.util.List<java.lang.String>
getHeader()
Return the comment header.java.util.List<java.lang.String>
getRaw(java.lang.String key)
void
load(java.io.File location)
void
load(java.io.InputStream is)
void
load(java.io.Reader reader)
void
load(java.net.URL location)
static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>>
prepare(java.util.Map<java.lang.String,TypedProperties> properties)
java.lang.Object
put(java.lang.String key, java.lang.Object value)
java.lang.Object
put(java.lang.String key, java.lang.String comment, java.lang.Object value)
java.lang.Object
put(java.lang.String key, java.util.List<java.lang.String> commentLines, java.lang.Object value)
java.lang.Object
put(java.lang.String key, java.util.List<java.lang.String> commentLines, java.util.List<java.lang.String> valueLines)
java.lang.Object
remove(java.lang.Object key)
void
save(java.io.File location)
void
save(java.io.OutputStream os)
void
save(java.io.Writer writer)
void
setFooter(java.util.List<java.lang.String> footer)
Set the comment footer.void
setHeader(java.util.List<java.lang.String> header)
Set the comment header.void
store(java.io.OutputStream os, java.lang.String comment)
Store a properties into a output stream, preserving comments, special character, etc.static void
substitute(java.util.Map<java.lang.String,TypedProperties> properties, java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> dynamic, TypedProperties.SubstitutionCallback callback, boolean finalSubstitution)
void
substitute(TypedProperties.SubstitutionCallback cb)
boolean
update(java.util.Map<java.lang.String,java.lang.Object> props)
boolean
update(TypedProperties properties)
private static TypedProperties.SubstitutionCallback
wrap(InterpolationHelper.SubstitutionCallback cb)
-
Methods inherited from class java.util.AbstractMap
clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, size, toString, values
-
-
-
-
Field Detail
-
ENV_PREFIX
public static final java.lang.String ENV_PREFIX
- See Also:
- Constant Field Values
-
storage
private final Properties storage
-
callback
private final TypedProperties.SubstitutionCallback callback
-
substitute
private final boolean substitute
-
-
Constructor Detail
-
TypedProperties
public TypedProperties()
-
TypedProperties
public TypedProperties(boolean substitute)
-
TypedProperties
public TypedProperties(TypedProperties.SubstitutionCallback callback)
-
TypedProperties
public TypedProperties(TypedProperties.SubstitutionCallback callback, boolean substitute)
-
-
Method Detail
-
load
public void load(java.io.File location) throws java.io.IOException
- Throws:
java.io.IOException
-
load
public void load(java.net.URL location) throws java.io.IOException
- Throws:
java.io.IOException
-
load
public void load(java.io.InputStream is) throws java.io.IOException
- Throws:
java.io.IOException
-
load
public void load(java.io.Reader reader) throws java.io.IOException
- Throws:
java.io.IOException
-
save
public void save(java.io.File location) throws java.io.IOException
- Throws:
java.io.IOException
-
save
public void save(java.io.OutputStream os) throws java.io.IOException
- Throws:
java.io.IOException
-
save
public void save(java.io.Writer writer) throws java.io.IOException
- Throws:
java.io.IOException
-
store
public void store(java.io.OutputStream os, java.lang.String comment) throws java.io.IOException
Store a properties into a output stream, preserving comments, special character, etc. This method is mainly to be compatible with the java.util.Properties class.- Parameters:
os
- an output stream.comment
- this parameter is ignored as this Properties- Throws:
java.io.IOException
- If storing fails
-
entrySet
public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
- Specified by:
entrySet
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Specified by:
entrySet
in classjava.util.AbstractMap<java.lang.String,java.lang.Object>
-
put
public java.lang.Object put(java.lang.String key, java.lang.Object value)
- Specified by:
put
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
put
in classjava.util.AbstractMap<java.lang.String,java.lang.Object>
-
get
public java.lang.Object get(java.lang.Object key)
- Specified by:
get
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
get
in classjava.util.AbstractMap<java.lang.String,java.lang.Object>
-
put
public java.lang.Object put(java.lang.String key, java.util.List<java.lang.String> commentLines, java.lang.Object value)
-
put
public java.lang.Object put(java.lang.String key, java.lang.String comment, java.lang.Object value)
-
put
public java.lang.Object put(java.lang.String key, java.util.List<java.lang.String> commentLines, java.util.List<java.lang.String> valueLines)
-
ensureTyped
private void ensureTyped()
-
update
public boolean update(java.util.Map<java.lang.String,java.lang.Object> props)
-
update
public boolean update(TypedProperties properties)
-
getRaw
public java.util.List<java.lang.String> getRaw(java.lang.String key)
-
getComments
public java.util.List<java.lang.String> getComments(java.lang.String key)
-
remove
public java.lang.Object remove(java.lang.Object key)
- Specified by:
remove
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
remove
in classjava.util.AbstractMap<java.lang.String,java.lang.Object>
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Map<java.lang.String,java.lang.Object>
- Overrides:
clear
in classjava.util.AbstractMap<java.lang.String,java.lang.Object>
-
getHeader
public java.util.List<java.lang.String> getHeader()
Return the comment header.- Returns:
- the comment header
-
setHeader
public void setHeader(java.util.List<java.lang.String> header)
Set the comment header.- Parameters:
header
- the header to use
-
getFooter
public java.util.List<java.lang.String> getFooter()
Return the comment footer.- Returns:
- the comment footer
-
setFooter
public void setFooter(java.util.List<java.lang.String> footer)
Set the comment footer.- Parameters:
footer
- the footer to use
-
substitute
public void substitute(TypedProperties.SubstitutionCallback cb)
-
wrap
private static TypedProperties.SubstitutionCallback wrap(InterpolationHelper.SubstitutionCallback cb)
-
prepare
public static java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> prepare(java.util.Map<java.lang.String,TypedProperties> properties)
-
substitute
public static void substitute(java.util.Map<java.lang.String,TypedProperties> properties, java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> dynamic, TypedProperties.SubstitutionCallback callback, boolean finalSubstitution)
-
convertToString
private static java.lang.String convertToString(java.lang.Object value)
-
convertFromString
private static java.lang.Object convertFromString(java.lang.String value)
-
-