本文整理汇总了Java中org.osgi.service.cm.ConfigurationAdmin类的典型用法代码示例。如果您正苦于以下问题:Java ConfigurationAdmin类的具体用法?Java ConfigurationAdmin怎么用?Java ConfigurationAdmin使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConfigurationAdmin类属于org.osgi.service.cm包,在下文中一共展示了ConfigurationAdmin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.osgi.service.cm.ConfigurationAdmin; //导入依赖的package包/类
@Override
public void start(BundleContext bundleContext) throws Exception {
_context = bundleContext;
_log.info("start called");
ServiceReference configAdminServiceRef = bundleContext.getServiceReference(ConfigurationAdmin.class.getName());
ConfigurationAdmin configAdminService = (ConfigurationAdmin) bundleContext.getService( configAdminServiceRef );
Configuration configuration = configAdminService.createFactoryConfiguration("com.pronoia.controlservice");
Properties props = new Properties();
props.put( "control.name", "FredControlOne" );
configuration.update( (Dictionary)props );
configuration = configAdminService.createFactoryConfiguration( "com.pronoia.controlservice");
props = new Properties();
props.put( "control.name", "FredControlTwo" );
configuration.update( (Dictionary)props );
}
示例2: backendConfigsAreUsed
import org.osgi.service.cm.ConfigurationAdmin; //导入依赖的package包/类
@Test
public void backendConfigsAreUsed() throws IOException {
ServiceReference<ConfigurationAdmin> reference = bundleContext
.getServiceReference(ConfigurationAdmin.class);
ConfigurationAdmin configurationAdmin = bundleContext.getService(reference);
// No bundle location set
assertNull(configurationAdmin.getConfiguration("test", null).getBundleLocation());
Dictionary<String, Object> properties = configurationAdmin.getConfiguration("test").getProperties();
assertNotNull(properties);
assertEquals("value1", properties.get("test1"));
assertEquals("value2", properties.get("test2"));
bundleContext.ungetService(reference);
}
示例3: factory
import org.osgi.service.cm.ConfigurationAdmin; //导入依赖的package包/类
@Test
public void factory() throws IOException, InvalidSyntaxException {
ServiceReference<ConfigurationAdmin> reference = bundleContext
.getServiceReference(ConfigurationAdmin.class);
ConfigurationAdmin configurationAdmin = bundleContext.getService(reference);
org.osgi.service.cm.Configuration[] configurations = configurationAdmin
.listConfigurations("(service.factoryPid=test)");
assertNotNull(configurations);
Dictionary<String, Object> properties = configurations[0].getProperties();
assertNotNull(properties);
assertEquals("value3", properties.get("test3"));
bundleContext.ungetService(reference);
}
示例4: 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"));
}
示例5: 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;
}
示例6: 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);
}
}
}
}
示例7: 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());
}
}
示例8: 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);
}
}
示例9: resetConfiguration
import org.osgi.service.cm.ConfigurationAdmin; //导入依赖的package包/类
protected synchronized void resetConfiguration() throws IOException{
if(lastAppliedProperties == null){
return;
}
ServiceReference<ConfigurationAdmin> adminRef = null;
try{
logger.info("Resetting the configuration of "+ocd.getName()+"["+ocd.getID()+"] to "+ lastAppliedProperties);
adminRef = bundleContext.getServiceReference(ConfigurationAdmin.class);
ConfigurationAdmin admin = bundleContext.getService(adminRef);
admin.getConfiguration(ocd.getID()).update(lastAppliedProperties);
}finally{
if(adminRef != null){
bundleContext.ungetService(adminRef);
}
}
}
示例10: 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
}
}
示例11: createFactoryConfiguration
import org.osgi.service.cm.ConfigurationAdmin; //导入依赖的package包/类
protected Configuration createFactoryConfiguration( final String factoryPid, final String location,
final boolean withProps )
{
final ConfigurationAdmin ca = getConfigurationAdmin();
try
{
final Configuration config = ca.createFactoryConfiguration( factoryPid, null );
if ( withProps )
{
config.update( theConfig );
}
return config;
}
catch ( IOException ioe )
{
TestCase.fail( "Failed updating factory configuration " + factoryPid + ": " + ioe.toString() );
return null; // keep the compiler quiet
}
}
示例12: getConfiguration
import org.osgi.service.cm.ConfigurationAdmin; //导入依赖的package包/类
protected Configuration getConfiguration( final String pid )
{
final ConfigurationAdmin ca = getConfigurationAdmin();
try
{
final String filter = "(" + Constants.SERVICE_PID + "=" + pid + ")";
final Configuration[] configs = ca.listConfigurations( filter );
if ( configs != null && configs.length > 0 )
{
return configs[0];
}
}
catch ( InvalidSyntaxException ise )
{
// unexpected
}
catch ( IOException ioe )
{
TestCase.fail( "Failed listing configurations " + pid + ": " + ioe.toString() );
}
TestCase.fail( "No Configuration " + pid + " found" );
return null;
}
示例13: deleteFactoryConfigurations
import org.osgi.service.cm.ConfigurationAdmin; //导入依赖的package包/类
protected void deleteFactoryConfigurations( String factoryPid )
{
ConfigurationAdmin ca = getConfigurationAdmin();
try
{
final String filter = "(service.factoryPid=" + factoryPid + ")";
Configuration[] configs = ca.listConfigurations( filter );
if ( configs != null )
{
for ( Configuration configuration : configs )
{
configuration.delete();
}
}
}
catch ( InvalidSyntaxException ise )
{
// unexpected
}
catch ( IOException ioe )
{
TestCase.fail( "Failed deleting configurations " + factoryPid + ": " + ioe.toString() );
}
}
示例14: 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;
}
示例15: exec
import org.osgi.service.cm.ConfigurationAdmin; //导入依赖的package包/类
public void exec(String args, PrintStream out, PrintStream err)
throws Exception {
ConfigurationAdmin admin = getConfigurationAdmin();
if (admin != null) {
args = args.trim();
if (args.startsWith("list")) {
handleList(args, admin, out);
} else if (args.startsWith("add-factory")) {
handleAddFactory(args, admin);
} else if (args.startsWith("add")) {
handleAdd(args,admin);
} else if (args.startsWith("remove-factory")) {
handleRemoveFactory(args, admin);
} else if (args.startsWith("remove")) {
handleRemove(args, admin);
}
} else {
out.println("No ConfigurationAdmin service found!");
}
}