Created
November 24, 2014 06:14
-
-
Save yupadhyay/bc1407acbe50de8ac580 to your computer and use it in GitHub Desktop.
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
import java.io.IOException; | |
import java.util.Dictionary; | |
import org.apache.felix.scr.annotations.Component; | |
import org.apache.felix.scr.annotations.Reference; | |
import org.apache.felix.scr.annotations.ReferenceCardinality; | |
import org.apache.felix.scr.annotations.ReferencePolicy; | |
import org.apache.felix.scr.annotations.Service; | |
import org.osgi.service.cm.Configuration; | |
import org.osgi.service.cm.ConfigurationAdmin; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
/** | |
* Service to return configuration based on pid and Key | |
* @author yogeshupadhyay | |
* | |
*/ | |
@Component | |
@Service | |
public class ConfigurationUtilImpl implements ConfigurationUtil{ | |
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY, policy = ReferencePolicy.STATIC) | |
private ConfigurationAdmin configAdmin; | |
private Configuration conf = null; | |
private Logger logger = LoggerFactory.getLogger(ConfigurationUtilImpl.class); | |
public String getConfig(String pid,String key){ | |
try { | |
if(configAdmin!=null){ | |
conf = configAdmin.getConfiguration(pid); | |
if(conf!=null){ | |
if(null!=conf.getProperties() && null!=conf.getProperties().get(key)){ | |
return conf.getProperties().get(key).toString(); | |
} | |
} | |
} | |
else | |
logger.error("Configuration for pid "+pid+" is Null"); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
/** | |
Get Configuration based on PID | |
*/ | |
public Dictionary<?, ?> getConfig(String pid) { | |
try { | |
if(configAdmin!=null){ | |
conf = configAdmin.getConfiguration(pid); | |
if(conf!=null){ | |
return conf.getProperties(); | |
} | |
} | |
else | |
logger.error("Configuration for pid "+pid+" is Null"); | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment