當前位置: 首頁>>代碼示例>>Java>>正文


Java ConfigurationAdmin類代碼示例

本文整理匯總了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 );
}
 
開發者ID:hqstevenson,項目名稱:osgi-dynamic-service,代碼行數:20,代碼來源:ManagedControlServiceClientActivator.java

示例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);
}
 
開發者ID:yrashk,項目名稱:etcetera,代碼行數:19,代碼來源:BackendConfigurationTest.java

示例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);
}
 
開發者ID:yrashk,項目名稱:etcetera,代碼行數:19,代碼來源:BackendConfigurationTest.java

示例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"));

}
 
開發者ID:yrashk,項目名稱:etcetera,代碼行數:22,代碼來源:BackendConfigurationTest.java

示例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;
}
 
開發者ID:semiotproject,項目名稱:semiot-platform,代碼行數:23,代碼來源:WebConfigurator.java

示例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);
      }
    }
  }
}
 
開發者ID:semiotproject,項目名稱:semiot-platform,代碼行數:21,代碼來源:ABundle.java

示例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());
	}
}
 
開發者ID:WASdev,項目名稱:sample.osgi.blueprint-cm,代碼行數:23,代碼來源:TestServlet.java

示例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);
    }
}
 
開發者ID:TDC-Netdesign,項目名稱:ManagedProperties,代碼行數:18,代碼來源:ConfigurationAdminProvider.java

示例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);
    }
}
   }
 
開發者ID:TDC-Netdesign,項目名稱:ManagedProperties,代碼行數:17,代碼來源:ConfigurationAdminProvider.java

示例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
    }
}
 
開發者ID:mcculls,項目名稱:osgi-in-action,代碼行數:19,代碼來源:ConfigurationTestBase.java

示例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
    }
}
 
開發者ID:mcculls,項目名稱:osgi-in-action,代碼行數:20,代碼來源:ConfigurationTestBase.java

示例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;
}
 
開發者ID:mcculls,項目名稱:osgi-in-action,代碼行數:25,代碼來源:ConfigurationTestBase.java

示例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() );
    }
}
 
開發者ID:mcculls,項目名稱:osgi-in-action,代碼行數:25,代碼來源:ConfigurationTestBase.java

示例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;
}
 
開發者ID:mcculls,項目名稱:osgi-in-action,代碼行數:23,代碼來源:ConfigureThread.java

示例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!");
  }
}
 
開發者ID:mcculls,項目名稱:osgi-in-action,代碼行數:21,代碼來源:ConfigAdminCommand.java


注:本文中的org.osgi.service.cm.ConfigurationAdmin類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。