/** * Creates an instance of {@link org.jclouds.management.ViewMBeanFactory} from the {@link org.osgi.framework.Bundle}. * * @param bundle * @return */ public Iterable<ViewMBeanFactory> listManagedViewFactories(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle("/META-INF/services/" + ViewMBeanFactory.class.getName(), bundle); return instantiateAvailableClasses(bundle, classNames, ViewMBeanFactory.class); } }
/** * Creates an instance of {@link ProviderMetadata} from the {@link Bundle}. * * @param bundle * @return */ public Iterable<ProviderMetadata> listProviderMetadata(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle( "/META-INF/services/org.jclouds.providers.ProviderMetadata", bundle); return instantiateAvailableClasses(bundle, classNames, ProviderMetadata.class); }
/** * Creates an instance of {@link ProviderMetadata} from the {@link Bundle}. * * @param bundle * @return */ public Iterable<ProviderMetadata> listProviderMetadata(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle( "/META-INF/services/org.jclouds.providers.ProviderMetadata", bundle); return instantiateAvailableClasses(bundle, classNames, ProviderMetadata.class); }
/** * Creates an instance of {@link ApiMetadata} from the {@link Bundle}. * * @param bundle * @return */ public Iterable<ApiMetadata> listApiMetadata(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle("/META-INF/services/org.jclouds.apis.ApiMetadata", bundle); return instantiateAvailableClasses(bundle, classNames, ApiMetadata.class); }
/** * Creates an instance of {@link ProviderMetadata} from the {@link Bundle}. * * @param bundle * @return */ public Iterable<ProviderMetadata> listProviderMetadata(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle( "/META-INF/services/org.jclouds.providers.ProviderMetadata", bundle); return instantiateAvailableClasses(bundle, classNames, ProviderMetadata.class); }
/** * Creates an instance of {@link ProviderMetadata} from the {@link Bundle}. * * @param bundle * @return */ public Iterable<ProviderMetadata> listProviderMetadata(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle( "/META-INF/services/org.jclouds.providers.ProviderMetadata", bundle); return instantiateAvailableClasses(bundle, classNames, ProviderMetadata.class); }
/** * Creates an instance of {@link ApiMetadata} from the {@link Bundle}. * * @param bundle * @return */ public Iterable<ApiMetadata> listApiMetadata(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle("/META-INF/services/org.jclouds.apis.ApiMetadata", bundle); return instantiateAvailableClasses(bundle, classNames, ApiMetadata.class); }
/** * Creates an instance of {@link ApiMetadata} from the {@link Bundle}. * * @param bundle * @return */ public Iterable<ApiMetadata> listApiMetadata(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle("/META-INF/services/org.jclouds.apis.ApiMetadata", bundle); return instantiateAvailableClasses(bundle, classNames, ApiMetadata.class); }
/** * Creates an instance of {@link ApiMetadata} from the {@link Bundle}. * * @param bundle * @return */ public Iterable<ApiMetadata> listApiMetadata(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle("/META-INF/services/org.jclouds.apis.ApiMetadata", bundle); return instantiateAvailableClasses(bundle, classNames, ApiMetadata.class); }
/** * Creates an instance of {@link ApiMetadata} from the {@link Bundle}. * * @param bundle * @return */ public Iterable<ApiMetadata> listApiMetadata(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle("/META-INF/services/org.jclouds.apis.ApiMetadata", bundle); return instantiateAvailableClasses(bundle, classNames, ApiMetadata.class); }
/** * Creates an instance of {@link ApiMetadata} from the {@link Bundle}. * * @param bundle * @return */ public Iterable<ApiMetadata> listApiMetadata(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle("/META-INF/services/org.jclouds.apis.ApiMetadata", bundle); return instantiateAvailableClasses(bundle, classNames, ApiMetadata.class); }
/** * Creates an instance of {@link ProviderMetadata} from the {@link Bundle}. * * @param bundle * @return */ public Iterable<ProviderMetadata> listProviderMetadata(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle( "/META-INF/services/org.jclouds.providers.ProviderMetadata", bundle); return instantiateAvailableClasses(bundle, classNames, ProviderMetadata.class); }
/** * Creates an instance of {@link ProviderMetadata} from the {@link Bundle}. * * @param bundle * @return */ public Iterable<ProviderMetadata> listProviderMetadata(Bundle bundle) { Iterable<String> classNames = stringsForResourceInBundle( "/META-INF/services/org.jclouds.providers.ProviderMetadata", bundle); return instantiateAvailableClasses(bundle, classNames, ProviderMetadata.class); }
@Test public void testInstantiateAvailableClassesWhenNotAllAssignable() throws ClassNotFoundException { Bundle bundle = createMock(Bundle.class); expect(bundle.loadClass("org.jclouds.providers.JcloudsTestBlobStoreProviderMetadata")).andReturn( JcloudsTestBlobStoreProviderMetadata.class); expect(bundle.loadClass("org.jclouds.apis.JcloudsTestComputeApiMetadata")).andReturn( JcloudsTestComputeApiMetadata.class); expect(bundle.loadClass("org.jclouds.providers.JcloudsTestYetAnotherComputeProviderMetadata")).andReturn( JcloudsTestYetAnotherComputeProviderMetadata.class); replay(bundle); Iterable<ProviderMetadata> providers = Bundles.instantiateAvailableClasses(bundle, ImmutableSet.of( "org.jclouds.providers.JcloudsTestBlobStoreProviderMetadata", "org.jclouds.apis.JcloudsTestComputeApiMetadata", "org.jclouds.providers.JcloudsTestYetAnotherComputeProviderMetadata"), ProviderMetadata.class); assertEquals(providers, ImmutableSet.of(new JcloudsTestBlobStoreProviderMetadata(), new JcloudsTestYetAnotherComputeProviderMetadata())); verify(bundle); }
@Test public void testInstantiateAvailableClassesWhenAllAssignable() throws ClassNotFoundException { Bundle bundle = createMock(Bundle.class); expect(bundle.loadClass("org.jclouds.providers.JcloudsTestBlobStoreProviderMetadata")).andReturn( JcloudsTestBlobStoreProviderMetadata.class); expect(bundle.loadClass("org.jclouds.providers.JcloudsTestComputeProviderMetadata")).andReturn( JcloudsTestComputeProviderMetadata.class); expect(bundle.loadClass("org.jclouds.providers.JcloudsTestYetAnotherComputeProviderMetadata")).andReturn( JcloudsTestYetAnotherComputeProviderMetadata.class); replay(bundle); Iterable<ProviderMetadata> providers = Bundles.instantiateAvailableClasses(bundle, ImmutableSet.of( "org.jclouds.providers.JcloudsTestBlobStoreProviderMetadata", "org.jclouds.providers.JcloudsTestComputeProviderMetadata", "org.jclouds.providers.JcloudsTestYetAnotherComputeProviderMetadata"), ProviderMetadata.class); assertEquals(providers, ImmutableSet.of(new JcloudsTestBlobStoreProviderMetadata(), new JcloudsTestComputeProviderMetadata(), new JcloudsTestYetAnotherComputeProviderMetadata())); verify(bundle); }
@SuppressWarnings("rawtypes") @Test public void testInstantiateAvailableClassesWhenNotAllAssignable() throws ClassNotFoundException { Bundle bundle = createMock(Bundle.class); expect((Class) bundle.loadClass("org.jclouds.providers.JcloudsTestBlobStoreProviderMetadata")).andReturn( JcloudsTestBlobStoreProviderMetadata.class); expect((Class) bundle.loadClass("org.jclouds.apis.JcloudsTestComputeApiMetadata")).andReturn( JcloudsTestComputeApiMetadata.class); expect((Class) bundle.loadClass("org.jclouds.providers.JcloudsTestYetAnotherComputeProviderMetadata")).andReturn( JcloudsTestYetAnotherComputeProviderMetadata.class); replay(bundle); Iterable<ProviderMetadata> providers = Bundles.instantiateAvailableClasses(bundle, ImmutableSet.of( "org.jclouds.providers.JcloudsTestBlobStoreProviderMetadata", "org.jclouds.apis.JcloudsTestComputeApiMetadata", "org.jclouds.providers.JcloudsTestYetAnotherComputeProviderMetadata"), ProviderMetadata.class); assertEquals(providers, ImmutableSet.of(new JcloudsTestBlobStoreProviderMetadata(), new JcloudsTestYetAnotherComputeProviderMetadata())); verify(bundle); }
@SuppressWarnings("rawtypes") @Test public void testInstantiateAvailableClassesWhenAllAssignable() throws ClassNotFoundException { Bundle bundle = createMock(Bundle.class); expect((Class) bundle.loadClass("org.jclouds.providers.JcloudsTestBlobStoreProviderMetadata")).andReturn( JcloudsTestBlobStoreProviderMetadata.class); expect((Class) bundle.loadClass("org.jclouds.providers.JcloudsTestComputeProviderMetadata")).andReturn( JcloudsTestComputeProviderMetadata.class); expect((Class) bundle.loadClass("org.jclouds.providers.JcloudsTestYetAnotherComputeProviderMetadata")).andReturn( JcloudsTestYetAnotherComputeProviderMetadata.class); replay(bundle); Iterable<ProviderMetadata> providers = Bundles.instantiateAvailableClasses(bundle, ImmutableSet.of( "org.jclouds.providers.JcloudsTestBlobStoreProviderMetadata", "org.jclouds.providers.JcloudsTestComputeProviderMetadata", "org.jclouds.providers.JcloudsTestYetAnotherComputeProviderMetadata"), ProviderMetadata.class); assertEquals(providers, ImmutableSet.of(new JcloudsTestBlobStoreProviderMetadata(), new JcloudsTestComputeProviderMetadata(), new JcloudsTestYetAnotherComputeProviderMetadata())); verify(bundle); }