本文整理汇总了Java中org.osgi.service.cm.ConfigurationAdmin.getConfiguration方法的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationAdmin.getConfiguration方法的具体用法?Java ConfigurationAdmin.getConfiguration怎么用?Java ConfigurationAdmin.getConfiguration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.osgi.service.cm.ConfigurationAdmin
的用法示例。
在下文中一共展示了ConfigurationAdmin.getConfiguration方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: creating
import org.osgi.service.cm.ConfigurationAdmin; //导入方法依赖的package包/类
@Test(timeout = 5000)
public void creating() throws IOException {
ServiceReference<ConfigurationAdmin> reference = bundleContext
.getServiceReference(ConfigurationAdmin.class);
ConfigurationAdmin configurationAdmin = bundleContext.getService(reference);
org.osgi.service.cm.Configuration configuration = configurationAdmin.getConfiguration("new");
Hashtable<String, Object> update = new Hashtable<>();
update.put("test", "passed");
configuration.update(update);
Map<String, String> config = new HashMap<>();
do {
try {
config = ConfigFileReader.read("lib/new.cfg", new FileInputStream("lib/new.cfg"));
} catch (IOException e) {}
} while (config.get("test") == null || !config.get("test").contentEquals("passed"));
}
示例2: getConfig
import org.osgi.service.cm.ConfigurationAdmin; //导入方法依赖的package包/类
private Configuration getConfig(String pid) throws IOException {
//If bundle's serviceReference is null (e.g., when you only install driver without start),
//use loc, it setup bundle's location forcibly
//String loc = null;
BundleContext ctx = context;
Bundle[] bundles = ctx.getBundles();
for (Bundle bun : bundles) {
if (bun.getSymbolicName().contains(pid)) {
ctx = bun.getBundleContext();
//loc = bun.getLocation();
break;
}
}
ServiceReference configurationAdminReference
= ctx.getServiceReference(ConfigurationAdmin.class.getName());
if (configurationAdminReference != null) {
ConfigurationAdmin configurationAdmin = (ConfigurationAdmin) ctx.getService(configurationAdminReference);
Configuration config = (Configuration) configurationAdmin.getConfiguration(pid);
return config;
}
return null;
}
示例3: configuringBundle
import org.osgi.service.cm.ConfigurationAdmin; //导入方法依赖的package包/类
public void configuringBundle(BundleContext ctx, HashMap<String, BundleContext> contextBundles) {
if (pid != null && properties != null) {
if(contextBundles.containsKey(pid)) {
ctx = contextBundles.get(pid);
}
ServiceReference configurationAdminReference =
ctx.getServiceReference(ConfigurationAdmin.class.getName());
if (configurationAdminReference != null) {
ConfigurationAdmin configurationAdmin =
(ConfigurationAdmin) ctx.getService(configurationAdminReference);
try {
Configuration config = configurationAdmin.getConfiguration(pid);
config.update(properties);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
}
}
示例4: doPost
import org.osgi.service.cm.ConfigurationAdmin; //导入方法依赖的package包/类
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String length = request.getParameter("length");
String width = request.getParameter("width");
String height = request.getParameter("height");
try {
ConfigurationAdmin c = (ConfigurationAdmin) new InitialContext().lookup("blueprint:comp/configAdminRef");
Configuration config = c.getConfiguration (PID, null);
Dictionary<String, Object> dict = new Hashtable<String, Object>();
dict.put("length", length);
dict.put("width", width);
dict.put("height", height);
config.update(dict);
response.getWriter().println ("<html><head/><body>Config updated. Click <a href=\"/test.wab.frontEnd/index.html\">here</a> to input new configuration.</body></html>");
// Exercise the custom blueprint namespace handler
SomeService s = (SomeService) new InitialContext().lookup("blueprint:comp/someServiceRef");
s.doSomething();
} catch (Exception e) {
e.printStackTrace(response.getWriter());
}
}
示例5: persistConfiguration
import org.osgi.service.cm.ConfigurationAdmin; //导入方法依赖的package包/类
@Override
public void persistConfiguration(Map<String, Object> newConfiguration) throws InvocationException {
Dictionary<String, Object> newConfigDictionary = new Hashtable<>();
for(String key : newConfiguration.keySet()){
newConfigDictionary.put(key, newConfiguration.get(key));
}
ConfigurationAdmin admin = configurationAdminTracker.getService();
try {
Configuration config = admin.getConfiguration(ocd.getID());
config.update(newConfigDictionary);
} catch (IOException | IllegalArgumentException | IllegalStateException ex) {
throw new InvocationException("Failed to update configuration", ex);
}
}
示例6: configure
import org.osgi.service.cm.ConfigurationAdmin; //导入方法依赖的package包/类
protected Configuration configure( final String pid, final String location, final boolean withProps )
{
final ConfigurationAdmin ca = getConfigurationAdmin();
try
{
final Configuration config = ca.getConfiguration( pid, location );
if ( withProps )
{
config.update( theConfig );
}
return config;
}
catch ( IOException ioe )
{
TestCase.fail( "Failed updating configuration " + pid + ": " + ioe.toString() );
return null; // keep the compiler quiet
}
}
示例7: ConfigureThread
import org.osgi.service.cm.ConfigurationAdmin; //导入方法依赖的package包/类
public ConfigureThread( final ConfigurationAdmin configAdmin, final String pid, final boolean isFactory )
throws IOException
{
// ensure configuration and disown it
final Configuration config;
if ( isFactory )
{
config = configAdmin.createFactoryConfiguration( pid );
}
else
{
config = configAdmin.getConfiguration( pid );
}
config.setBundleLocation( null );
Hashtable<String, Object> props = new Hashtable<String, Object>();
props.put( "prop1", "aValue" );
props.put( "prop2", 4711 );
this.config = config;
this.props = props;
}
示例8: getConfiguration
import org.osgi.service.cm.ConfigurationAdmin; //导入方法依赖的package包/类
/**
*
* @return
*/
protected Properties getConfiguration() {
ConfigurationAdmin ca = getConfigurationAdmin();
Properties props = null;
if(ca != null) {
try {
Configuration configuration = ca.getConfiguration(m_pid);
if(configuration != null) {
props = getConfiguration(configuration.getProperties());
}
} catch(Exception e) {
LOGGER.warn("Exception",e);
}
}
if(props == null) {
LOGGER.warn("No configuration for {}",m_pid);
}
return props;
}
示例9: prepareConfiguration
import org.osgi.service.cm.ConfigurationAdmin; //导入方法依赖的package包/类
protected void prepareConfiguration(ConfigurationAdmin configAdmin) throws Exception {
initProperties();
Properties localCopy = (Properties) props.clone();
localCopy.setProperty("string", SIMPLE);
// prepare simple
Configuration cfg = configAdmin.getConfiguration(SIMPLE);
cfg.update(localCopy);
// prepare simple prototype
cfg = configAdmin.getConfiguration(PROTO);
localCopy.setProperty("string", PROTO);
cfg.update(localCopy);
// prepare container managed
cfg = configAdmin.getConfiguration(CMNG);
localCopy.setProperty("string", CMNG);
cfg.update(localCopy);
// bean managed
cfg = configAdmin.getConfiguration(BMNG);
localCopy.setProperty("string", BMNG);
cfg.update(localCopy);
}
示例10: prepareConfiguration
import org.osgi.service.cm.ConfigurationAdmin; //导入方法依赖的package包/类
private void prepareConfiguration() throws Exception {
ServiceReference ref = OsgiServiceReferenceUtils.getServiceReference(bundleContext,
ConfigurationAdmin.class.getName(), null);
ConfigurationAdmin admin = (ConfigurationAdmin) bundleContext.getService(ref);
Configuration config = admin.getConfiguration(ID);
config.update(DICT);
}
示例11: testConfigAdmin
import org.osgi.service.cm.ConfigurationAdmin; //导入方法依赖的package包/类
@Test
public void testConfigAdmin() throws IOException {
final String pid = "TEST_" + getClass().getName() + UUID.randomUUID();
final ConfigurationAdmin ca = teleporter.getService(ConfigurationAdmin.class);
assertNotNull("Teleporter should provide a ConfigurationAdmin", ca);
final Configuration cfg = ca.getConfiguration(pid);
assertNotNull("Expecting to get a Configuration", cfg);
assertEquals("Expecting the correct pid", pid, cfg.getPid());
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:12,代码来源:BasicTeleporterTest.java
示例12: configureLogger
import org.osgi.service.cm.ConfigurationAdmin; //导入方法依赖的package包/类
/**
* Replaces the PAX logging configuration against a more sane minecraft-like configuration.
* TODO: This might be better located in the development bundle and/or flange.
*/
private void configureLogger(@Nonnull BundleContext ctx) throws IOException {
// extract configuration to an accessible location
File configFile = ctx.getDataFile("log4j2.xml");
try (InputStream inputStream = this.getClass().getResourceAsStream("/log4j2.xml")) {
try (FileOutputStream outputStream = new FileOutputStream(configFile)) {
ByteStreams.copy(inputStream, outputStream);
}
}
// push config to pax logging
ServiceReference<?> serviceReference = ctx
.getServiceReference(ConfigurationAdmin.class.getName());
if (serviceReference == null) {
logger.warn("Could not replace logging configuration");
logger.warn("You are about to experience a mindboggling amount of log messages!");
return;
}
ConfigurationAdmin configurationAdmin = (ConfigurationAdmin) ctx.getService(serviceReference);
Configuration configuration = configurationAdmin
.getConfiguration("org.ops4j.pax.logging", null);
Dictionary<String, Object> properties = configuration.getProperties();
if (properties == null) {
properties = new Hashtable<>();
}
properties.put("org.ops4j.pax.logging.log4j2.config.file", configFile.toString());
configuration.update(properties);
logger.info("Loggers have been adjusted to sane levels.");
}
示例13: afterPropertiesSet
import org.osgi.service.cm.ConfigurationAdmin; //导入方法依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
BundleContext bandleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
ServiceReference refrenceByConfigAdmin = bandleContext.getServiceReference(ConfigurationAdmin.class.getName());
Assert.notNull(refrenceByConfigAdmin, "Failed to get the configuration admin, it is null.");
ConfigurationAdmin configAdmin = (ConfigurationAdmin) bandleContext.getService(refrenceByConfigAdmin);
Configuration config = configAdmin.getConfiguration(osmp_PID);
Assert.notNull(config, "Could not find the PID configuration information, PID : " + osmp_PID);
this.updated(config.getProperties());
}
示例14: updating
import org.osgi.service.cm.ConfigurationAdmin; //导入方法依赖的package包/类
@Test(timeout = 5000)
public void updating() throws IOException {
ServiceReference<ConfigurationAdmin> reference = bundleContext
.getServiceReference(ConfigurationAdmin.class);
ConfigurationAdmin configurationAdmin = bundleContext.getService(reference);
org.osgi.service.cm.Configuration configuration = configurationAdmin.getConfiguration("test");
Hashtable<String, Object> update = new Hashtable<>();
update.put("test2", "updated2");
update.put("test3", "updated3");
configuration.update(update);
Map<String, String> config;
do {
config = ConfigFileReader.read("data/test.cfg", new FileInputStream("data/test.cfg"));
} while (config.get("test2") == null || !config.get("test2").contentEquals("updated2"));
// No other keys have leaked
assertEquals(1, config.size());
do {
config = ConfigFileReader.read("bin/test.cfg", new FileInputStream("bin/test.cfg"));
} while (config.get("test2") == null || !config.get("test2").contentEquals("updated2"));
// Unknown keys should propagate here
assertEquals("updated3", config.get("test3"));
// service.pid should not leak
assertNull(config.get("service.pid"));
}
示例15: configureLogger
import org.osgi.service.cm.ConfigurationAdmin; //导入方法依赖的package包/类
/**
* Replaces the PAX logging configuration against a more sane minecraft-like configuration.
* TODO: This might be better located in the development bundle and/or flange.
*/
private void configureLogger(@Nonnull BundleContext ctx) throws IOException {
// extract configuration to an accessible location
File configFile = ctx.getDataFile("log4j2.xml");
try (InputStream inputStream = this.getClass().getResourceAsStream("/log4j2.xml")) {
try (FileOutputStream outputStream = new FileOutputStream(configFile)) {
ByteStreams.copy(inputStream, outputStream);
}
}
// push config to pax logging
ServiceReference<?> serviceReference = ctx
.getServiceReference(ConfigurationAdmin.class.getName());
if (serviceReference == null) {
logger.warn("Could not replace logging configuration");
logger.warn("You are about to experience a mindboggling amount of log messages!");
return;
}
ConfigurationAdmin configurationAdmin = (ConfigurationAdmin) ctx.getService(serviceReference);
Configuration configuration = configurationAdmin
.getConfiguration("org.ops4j.pax.logging", null);
Dictionary<String, Object> properties = configuration.getProperties();
if (properties == null) {
properties = new Hashtable<>();
}
properties.put("org.ops4j.pax.logging.log4j2.config.file", configFile.toString());
configuration.update(properties);
logger.info("Loggers have been adjusted to sane levels.");
}