Created
May 16, 2014 20:46
-
-
Save gbutt/eeb5fc06b54d922517f6 to your computer and use it in GitHub Desktop.
configloader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0" | |
xsi:schemaLocation=" | |
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd | |
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd"> | |
<cm:property-placeholder persistent-id="com.example.configloader"> | |
<cm:default-properties> | |
<cm:property name="configPath" value=""/> | |
</cm:default-properties> | |
</cm:property-placeholder> | |
<bean id="configLoader" class="com.example.ConfigLoader" init-method="init"> | |
<property name="configPath" value="${configPath}" /> | |
</bean> | |
</blueprint> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
configPath=profile:config.json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
active: true | |
} | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import org.apache.commons.lang.NullArgumentException; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.io.FileReader; | |
import java.io.IOException; | |
public class ConfigLoader { | |
private static final Logger log = LoggerFactory.getLogger(ConfigLoader.class); | |
private String configPath; | |
public String getConfigPath() { | |
return configPath; | |
} | |
public void setConfigPath(String value) { | |
configPath = value; | |
} | |
private File configFile; | |
public File getConfigFile() { | |
return configFile; | |
} | |
public void setConfigFile(File value) { | |
configFile = value; | |
} | |
public void init() throws FileNotFoundException, IOException { | |
if (configPath == null) { | |
throw new NullArgumentException("configPath"); | |
} | |
File file = new File(configPath); | |
setConfigFile(file); | |
log.info("Loaded config file from: " + configPath); | |
FileReader reader = new FileReader(configFile); | |
char[] contents = new char[(int)file.length()]; | |
reader.read(contents); | |
log.info("Contents: " + String.valueOf(contents)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attribute.parents = karaf | |
bundle.configloader = mvn:com.example/LoadJsonFromProfile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment