本文整理匯總了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;
}
示例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);
}
示例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() );
}
示例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 );
}
示例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 );
}
示例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() );
}
示例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 );
}
}
示例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 );
}
示例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 );
}
示例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 );
}