当前位置: 首页>>代码示例>>Java>>正文


Java Configuration.setBundleLocation方法代码示例

本文整理汇总了Java中org.osgi.service.cm.Configuration.setBundleLocation方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.setBundleLocation方法的具体用法?Java Configuration.setBundleLocation怎么用?Java Configuration.setBundleLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.osgi.service.cm.Configuration的用法示例。


在下文中一共展示了Configuration.setBundleLocation方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ConfigureThread

import org.osgi.service.cm.Configuration; //导入方法依赖的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

示例2: createConfiguration

import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
private void createConfiguration(String args, String pid,
  Configuration conf) throws IOException {
  conf.setBundleLocation(null);
  Dictionary dict = conf.getProperties();
  if (dict == null) {
    dict = new Properties();
  }
  StringTokenizer tok = new StringTokenizer(args, " ");
  while (tok.hasMoreTokens()) {
    String[] entry = tok.nextToken().split("=");
    dict.put(entry[0], entry[1]);
  }
  conf.update(dict);
}
 
开发者ID:mcculls,项目名称:osgi-in-action,代码行数:15,代码来源:ConfigAdminCommand.java

示例3: test_static_binding

import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
@Test
public void test_static_binding() throws BundleException
{
    final String pid = "test_static_binding";

    // install a bundle to get a location for binding
    bundle = installBundle( pid );
    final String location = bundle.getLocation();

    // create and statically bind the configuration
    configure( pid );
    final Configuration config = getConfiguration( pid );
    TestCase.assertEquals( pid, config.getPid() );
    TestCase.assertNull( config.getBundleLocation() );
    config.setBundleLocation( location );
    TestCase.assertEquals( location, config.getBundleLocation() );

    // start the bundle
    bundle.start();
    delay();
    TestCase.assertEquals( location, config.getBundleLocation() );

    // assert the configuration is supplied
    final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
    TestCase.assertNotNull( "Activator not started !!", tester );
    TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
    TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceUpdatedCalls );

    // remove the static binding and assert still bound
    config.setBundleLocation( null );
    TestCase.assertEquals( location, config.getBundleLocation() );

    // uninstall bundle and assert configuration unbound
    bundle.uninstall();
    bundle = null;
    delay();
    TestCase.assertNull( config.getBundleLocation() );
}
 
开发者ID:mcculls,项目名称:osgi-in-action,代码行数:39,代码来源:ConfigurationBindingTest.java

示例4: test_create_with_location_unbind_before_service_supply

import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
@Test
public void test_create_with_location_unbind_before_service_supply() throws BundleException, IOException
{

    final String pid = "test_create_with_location_unbind_before_service_supply";
    final String dummyLocation = "http://some/dummy/location";

    // 1. create and statically bind the configuration
    final Configuration config = configure( pid, dummyLocation, false );
    TestCase.assertEquals( pid, config.getPid() );
    TestCase.assertEquals( dummyLocation, config.getBundleLocation() );

    // 2. update configuration
    Hashtable<String, String> props = new Hashtable<String, String>();
    props.put( PROP_NAME, PROP_NAME );
    config.update( props );
    TestCase.assertEquals( PROP_NAME, config.getProperties().get( PROP_NAME ) );
    TestCase.assertEquals( pid, config.getPid() );
    TestCase.assertEquals( dummyLocation, config.getBundleLocation() );

    // 3. (statically) set location to null
    config.setBundleLocation( null );
    TestCase.assertNull( config.getBundleLocation() );

    // 4. install bundle with service
    bundle = installBundle( pid );
    bundle.start();
    delay();

    final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
    TestCase.assertNotNull( "Activator not started !!", tester );

    // assert activater has configuration (two calls, one per pid)
    TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
    TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceUpdatedCalls );

    TestCase.assertEquals( bundle.getLocation(), config.getBundleLocation() );

    bundle.uninstall();
    bundle = null;

    delay();

    // statically bound configurations must remain bound after bundle
    // uninstall
    TestCase.assertNull( config.getBundleLocation() );

    // remove the configuration for good
    deleteConfig( pid );
}
 
开发者ID:mcculls,项目名称:osgi-in-action,代码行数:51,代码来源:ConfigurationBindingTest.java

示例5: test_statically_bound

import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
@Test
public void test_statically_bound() throws BundleException
{
    final String pid = "test_statically_bound";

    // install the bundle (we need the location)
    bundle = installBundle( pid );
    final String location = bundle.getLocation();

    // create and statically bind the configuration
    configure( pid );
    final Configuration config = getConfiguration( pid );
    TestCase.assertEquals( pid, config.getPid() );
    TestCase.assertNull( config.getBundleLocation() );
    config.setBundleLocation( location );
    TestCase.assertEquals( location, config.getBundleLocation() );

    bundle.start();

    // give cm time for distribution
    delay();

    final ManagedServiceTestActivator tester = ManagedServiceTestActivator.INSTANCE;
    TestCase.assertNotNull( "Activator not started !!", tester );

    // assert activater has configuration (two calls, one per pid)
    TestCase.assertNotNull( "Expect Properties after Service Registration", tester.props );
    TestCase.assertEquals( "Expect a single update call", 1, tester.numManagedServiceUpdatedCalls );

    TestCase.assertEquals( location, config.getBundleLocation() );

    bundle.uninstall();
    bundle = null;

    delay();

    // statically bound configurations must remain bound after bundle
    // uninstall
    TestCase.assertEquals( location, config.getBundleLocation() );

    // remove the configuration for good
    deleteConfig( pid );
}
 
开发者ID:mcculls,项目名称:osgi-in-action,代码行数:44,代码来源:ConfigurationBindingTest.java

示例6: test_static_binding_and_unbinding

import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
@Test
public void test_static_binding_and_unbinding() throws BundleException
{
    final String pid = "test_static_binding_and_unbinding";
    final String location = bundleContext.getBundle().getLocation();

    // create and statically bind the configuration
    configure( pid );
    final Configuration config = getConfiguration( pid );
    TestCase.assertEquals( pid, config.getPid() );
    TestCase.assertNull( config.getBundleLocation() );

    // bind the configuration
    config.setBundleLocation( location );
    TestCase.assertEquals( location, config.getBundleLocation() );

    // restart CM bundle
    final Bundle cmBundle = getCmBundle();
    cmBundle.stop();
    delay();
    cmBundle.start();

    // assert configuration still bound
    final Configuration configAfterRestart = getConfiguration( pid );
    TestCase.assertEquals( pid, configAfterRestart.getPid() );
    TestCase.assertEquals( location, configAfterRestart.getBundleLocation() );

    // unbind the configuration
    configAfterRestart.setBundleLocation( null );
    TestCase.assertNull( configAfterRestart.getBundleLocation() );

    // restart CM bundle
    cmBundle.stop();
    delay();
    cmBundle.start();

    // assert configuration unbound
    final Configuration configUnboundAfterRestart = getConfiguration( pid );
    TestCase.assertEquals( pid, configUnboundAfterRestart.getPid() );
    TestCase.assertNull( configUnboundAfterRestart.getBundleLocation() );
}
 
开发者ID:mcculls,项目名称:osgi-in-action,代码行数:42,代码来源:ConfigurationBindingTest.java

示例7: test_switch_static_binding

import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
@Test
public void test_switch_static_binding() throws BundleException
{
    // 1. create config with pid and locationA
    // 2. update config with properties
    final String pid = "test_switch_static_binding";
    final String locationA = "test:location/A/" + pid;
    final Configuration config = configure( pid, locationA, true );

    // 3. register ManagedService ms1 with pid from said locationA
    final Bundle bundleA = installBundle( pid, ManagedServiceTestActivator.class, locationA );
    bundleA.start();
    delay();

    // ==> configuration supplied to the service ms1
    final ManagedServiceTestActivator testerA1 = ManagedServiceTestActivator.INSTANCE;
    TestCase.assertNotNull( testerA1.props );
    TestCase.assertEquals( 1, testerA1.numManagedServiceUpdatedCalls );

    // 4. register ManagedService ms2 with pid from locationB
    final String locationB = "test:location/B/" + pid;
    final Bundle bundleB = installBundle( pid, ManagedServiceTestActivator2.class, locationB );
    bundleB.start();
    delay();

    // ==> configuration not supplied to service ms2
    final ManagedServiceTestActivator2 testerB1 = ManagedServiceTestActivator2.INSTANCE;
    TestCase.assertNull( testerB1.props );
    TestCase.assertEquals( 0, testerB1.numManagedServiceUpdatedCalls );

    // 5. Call Configuration.setBundleLocation( "locationB" )
    config.setBundleLocation( locationB );
    delay();

    // ==> configuration is bound to locationB
    TestCase.assertEquals( locationB, config.getBundleLocation() );

    /*
     * According to BJ Hargrave configuration is not re-dispatched
     * due to setting the bundle location.
     * <p>
     * Therefore, we have two sets one with re-dispatch expectation and
     * one without re-dispatch expectation.
     */
    if ( REDISPATCH_CONFIGURATION_ON_SET_BUNDLE_LOCATION )
    {
        // ==> configuration removed from service ms1
        TestCase.assertNull( testerA1.props );
        TestCase.assertEquals( 2, testerA1.numManagedServiceUpdatedCalls );

        // ==> configuration supplied to the service ms2
        TestCase.assertNotNull( testerB1.props );
        TestCase.assertEquals( 1, testerB1.numManagedServiceUpdatedCalls );
    }
    else
    {
        // ==> configuration remains for service ms1
        TestCase.assertNotNull( testerA1.props );
        TestCase.assertEquals( 1, testerA1.numManagedServiceUpdatedCalls );

        // ==> configuration not supplied to the service ms2
        TestCase.assertNull( testerB1.props );
        TestCase.assertEquals( 0, testerB1.numManagedServiceUpdatedCalls );
    }
}
 
开发者ID:mcculls,项目名称:osgi-in-action,代码行数:66,代码来源:ConfigurationBindingTest.java

示例8: test_switch_dynamic_binding

import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
@Test
public void test_switch_dynamic_binding() throws BundleException, IOException
{
    // 1. create config with pid with null location
    // 2. update config with properties
    final String pid = "test_switch_dynamic_binding";
    final String locationA = "test:location/A/" + pid;
    final Configuration config = configure( pid, null, true );

    // 3. register ManagedService ms1 with pid from locationA
    final Bundle bundleA = installBundle( pid, ManagedServiceTestActivator.class, locationA );
    bundleA.start();
    delay();

    // ==> configuration supplied to the service ms1
    final ManagedServiceTestActivator testerA1 = ManagedServiceTestActivator.INSTANCE;
    TestCase.assertNotNull( testerA1.props );
    TestCase.assertEquals( 1, testerA1.numManagedServiceUpdatedCalls );

    // ==> configuration is dynamically bound to locationA
    TestCase.assertEquals( locationA, config.getBundleLocation() );

    // 4. register ManagedService ms2 with pid from locationB
    final String locationB = "test:location/B/" + pid;
    final Bundle bundleB = installBundle( pid, ManagedServiceTestActivator2.class, locationB );
    bundleB.start();
    delay();

    // ==> configuration not supplied to service ms2
    final ManagedServiceTestActivator2 testerB1 = ManagedServiceTestActivator2.INSTANCE;
    TestCase.assertNull( testerB1.props );
    TestCase.assertEquals( 0, testerB1.numManagedServiceUpdatedCalls );

    // 5. Call Configuration.setBundleLocation( "locationB" )
    config.setBundleLocation( locationB );
    delay();

    // ==> configuration is bound to locationB
    TestCase.assertEquals( locationB, config.getBundleLocation() );

    /*
     * According to BJ Hargrave configuration is not re-dispatched
     * due to setting the bundle location.
     * <p>
     * Therefore, we have two sets one with re-dispatch expectation and
     * one without re-dispatch expectation.
     */
    if ( REDISPATCH_CONFIGURATION_ON_SET_BUNDLE_LOCATION )
    {
        // ==> configuration removed from service ms1
        TestCase.assertNull( testerA1.props );
        TestCase.assertEquals( 2, testerA1.numManagedServiceUpdatedCalls );

        // ==> configuration supplied to the service ms2
        TestCase.assertNotNull( testerB1.props );
        TestCase.assertEquals( 1, testerB1.numManagedServiceUpdatedCalls );
    }
    else
    {
        // ==> configuration remains for service ms1
        TestCase.assertNotNull( testerA1.props );
        TestCase.assertEquals( 1, testerA1.numManagedServiceUpdatedCalls );

        // ==> configuration not supplied to the service ms2
        TestCase.assertNull( testerB1.props );
        TestCase.assertEquals( 0, testerB1.numManagedServiceUpdatedCalls );
    }

    // 6. Update configuration now
    config.update();
    delay();

    // ==> configuration supplied to the service ms2
    TestCase.assertNotNull( testerB1.props );
    TestCase.assertEquals( 1, testerB1.numManagedServiceUpdatedCalls );
}
 
开发者ID:mcculls,项目名称:osgi-in-action,代码行数:77,代码来源:ConfigurationBindingTest.java

示例9: test_switch_static_binding_factory

import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
@Test
 public void test_switch_static_binding_factory() throws BundleException, IOException
 {
     // 1. create config with pid and locationA
     // 2. update config with properties
     final String factoryPid = "test_switch_static_binding_factory";
     final String locationA = "test:location/A/" + factoryPid;
     final Configuration config = createFactoryConfiguration( factoryPid, locationA, true );
     final String pid = config.getPid();

     // 3. register ManagedService ms1 with pid from said locationA
     final Bundle bundleA = installBundle( factoryPid, ManagedServiceFactoryTestActivator.class, locationA );
     bundleA.start();
     delay();

     // ==> configuration supplied to the service ms1
     final ManagedServiceFactoryTestActivator testerA1 = ManagedServiceFactoryTestActivator.INSTANCE;
     TestCase.assertNotNull( testerA1.configs.get( pid ) );
     TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryUpdatedCalls );

     // 4. register ManagedService ms2 with pid from locationB
     final String locationB = "test:location/B/" + factoryPid;
     final Bundle bundleB = installBundle( factoryPid, ManagedServiceFactoryTestActivator2.class, locationB );
     bundleB.start();
     delay();

     // ==> configuration not supplied to service ms2
     final ManagedServiceFactoryTestActivator2 testerB1 = ManagedServiceFactoryTestActivator2.INSTANCE;
     TestCase.assertNull( testerB1.configs.get( pid ));
     TestCase.assertEquals( 0, testerB1.numManagedServiceFactoryUpdatedCalls );

     // 5. Call Configuration.setBundleLocation( "locationB" )
     config.setBundleLocation( locationB );
     delay();

     // ==> configuration is bound to locationB
     TestCase.assertEquals( locationB, config.getBundleLocation() );

     /*
      * According to BJ Hargrave configuration is not re-dispatched
      * due to setting the bundle location.
      * <p>
      * Therefore, we have two sets one with re-dispatch expectation and
      * one without re-dispatch expectation.
      */
     if ( REDISPATCH_CONFIGURATION_ON_SET_BUNDLE_LOCATION )
     {
         // ==> configuration removed from service ms1
         TestCase.assertNull( testerA1.configs.get( pid ));
         TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryUpdatedCalls );
         TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryDeleteCalls );

         // ==> configuration supplied to the service ms2
         TestCase.assertNotNull( testerB1.configs.get( pid ) );
         TestCase.assertEquals( 1, testerB1.numManagedServiceFactoryUpdatedCalls );
     }
     else
     {
         // ==> configuration not removed from service ms1
         TestCase.assertNotNull( testerA1.configs.get( pid ));
         TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryUpdatedCalls );
         TestCase.assertEquals( 0, testerA1.numManagedServiceFactoryDeleteCalls );

         // ==> configuration not supplied to the service ms2
         TestCase.assertNull( testerB1.configs.get( pid ) );
         TestCase.assertEquals( 0, testerB1.numManagedServiceFactoryUpdatedCalls );
     }

     // 6. Update configuration now
     config.update();
     delay();

     // ==> configuration supplied to the service ms2
     TestCase.assertNotNull( testerB1.configs.get( pid ) );
     TestCase.assertEquals( 1, testerB1.numManagedServiceFactoryUpdatedCalls );
}
 
开发者ID:mcculls,项目名称:osgi-in-action,代码行数:77,代码来源:ConfigurationBindingTest.java

示例10: test_switch_dynamic_binding_factory

import org.osgi.service.cm.Configuration; //导入方法依赖的package包/类
@Test
public void test_switch_dynamic_binding_factory() throws BundleException, IOException
{
    // 1. create config with pid and locationA
    // 2. update config with properties
    final String factoryPid = "test_switch_static_binding_factory";
    final String locationA = "test:location/A/" + factoryPid;
    final Configuration config = createFactoryConfiguration( factoryPid, null, true );
    final String pid = config.getPid();

    TestCase.assertNull( config.getBundleLocation() );

    // 3. register ManagedService ms1 with pid from said locationA
    final Bundle bundleA = installBundle( factoryPid, ManagedServiceFactoryTestActivator.class, locationA );
    bundleA.start();
    delay();

    // ==> configuration supplied to the service ms1
    final ManagedServiceFactoryTestActivator testerA1 = ManagedServiceFactoryTestActivator.INSTANCE;
    TestCase.assertNotNull( testerA1.configs.get( pid ) );
    TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryUpdatedCalls );
    TestCase.assertEquals( locationA, config.getBundleLocation() );

    // 4. register ManagedService ms2 with pid from locationB
    final String locationB = "test:location/B/" + factoryPid;
    final Bundle bundleB = installBundle( factoryPid, ManagedServiceFactoryTestActivator2.class, locationB );
    bundleB.start();
    delay();

    // ==> configuration not supplied to service ms2
    final ManagedServiceFactoryTestActivator2 testerB1 = ManagedServiceFactoryTestActivator2.INSTANCE;
    TestCase.assertNull( testerB1.configs.get( pid ));
    TestCase.assertEquals( 0, testerB1.numManagedServiceFactoryUpdatedCalls );
    TestCase.assertEquals( locationA, config.getBundleLocation() );

    // 5. Call Configuration.setBundleLocation( "locationB" )
    config.setBundleLocation( locationB );
    delay();

    // ==> configuration is bound to locationB
    TestCase.assertEquals( locationB, config.getBundleLocation() );

    /*
     * According to BJ Hargrave configuration is not re-dispatched
     * due to setting the bundle location.
     * <p>
     * Therefore, we have two sets one with re-dispatch expectation and
     * one without re-dispatch expectation.
     */
    if ( REDISPATCH_CONFIGURATION_ON_SET_BUNDLE_LOCATION )
    {
        // ==> configuration removed from service ms1
        TestCase.assertNull( testerA1.configs.get( pid ));
        TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryUpdatedCalls );
        TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryDeleteCalls );

        // ==> configuration supplied to the service ms2
        TestCase.assertNotNull( testerB1.configs.get( pid ) );
        TestCase.assertEquals( 1, testerB1.numManagedServiceFactoryUpdatedCalls );
    }
    else
    {
        // ==> configuration not removed from service ms1
        TestCase.assertNotNull( testerA1.configs.get( pid ));
        TestCase.assertEquals( 1, testerA1.numManagedServiceFactoryUpdatedCalls );
        TestCase.assertEquals( 0, testerA1.numManagedServiceFactoryDeleteCalls );

        // ==> configuration not supplied to the service ms2
        TestCase.assertNull( testerB1.configs.get( pid ) );
        TestCase.assertEquals( 0, testerB1.numManagedServiceFactoryUpdatedCalls );
    }

    // 6. Update configuration now
    config.update();
    delay();

    // ==> configuration supplied to the service ms2
    TestCase.assertNotNull( testerB1.configs.get( pid ) );
    TestCase.assertEquals( 1, testerB1.numManagedServiceFactoryUpdatedCalls );
}
 
开发者ID:mcculls,项目名称:osgi-in-action,代码行数:81,代码来源:ConfigurationBindingTest.java


注:本文中的org.osgi.service.cm.Configuration.setBundleLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。