BundleImpl implements Bundle { @Override public <A> A adapt(final Class<A> type) { if (BundleWiring.class == type) { if (bundleWiring == null) { synchronized (this) { if (bundleWiring == null) { bundleWiring = new BundleWiringImpl(this, registry); } } } return type.cast(bundleWiring); } if (BundleRevision.class == type) { if (bundleRevision == null) { synchronized (this) { if (bundleRevision == null) { bundleRevision = new BundleRevisionImpl(this); } } } return type.cast(bundleRevision); } if (BundleRevisions.class == type) { return type.cast(new BundleRevisions() { @Override public Bundle getBundle() { return BundleImpl.this; } @Override public List<BundleRevision> getRevisions() { return singletonList(bundleRevision); } }); } if (BundleContext.class == type) { return type.cast(context); } if (ServiceReferenceDTO[].class == type) { return type.cast(Stream.of(getRegisteredServices()) .map(s -> { final ServiceReferenceDTO dto = new ServiceReferenceDTO(); dto.bundle = getBundleId(); dto.id = Long.class.cast(s.getProperty(Constants.SERVICE_ID)); dto.properties = list(s.getProperties().keys()).stream() .collect(toMap(identity(), s::getProperty)); dto.usingBundles = ofNullable(s.getUsingBundles()) .map(bundles -> Stream.of(bundles).mapToLong(Bundle::getBundleId).toArray()) .orElseGet(() -> new long[0]); return dto; }) .toArray(ServiceReferenceDTO[]::new)); } return null; } BundleImpl(final Manifest manifest, final File file, final BundleContextImpl context,
               final Ripener.Configuration configuration, final long id,
               final Collection<String> includedResources, final BundleRegistry registry); @Override int getState(); @Override void start(final int options); @Override void start(); @Override void stop(final int options); @Override void stop(); @Override void update(final InputStream input); @Override void update(); @Override void uninstall(); @Override Dictionary<String, String> getHeaders(); @Override long getBundleId(); @Override String getLocation(); @Override ServiceReference<?>[] getRegisteredServices(); @Override ServiceReference<?>[] getServicesInUse(); @Override boolean hasPermission(final Object permission); @Override URL getResource(final String name); @Override Dictionary<String, String> getHeaders(final String locale); @Override String getSymbolicName(); @Override Class<?> loadClass(final String name); @Override Enumeration<URL> getResources(final String name); @Override Enumeration<String> getEntryPaths(final String path); @Override URL getEntry(final String path); @Override long getLastModified(); @Override Enumeration<URL> findEntries(final String path, final String filePattern, final boolean recurse); @Override BundleContext getBundleContext(); @Override Map<X509Certificate, List<X509Certificate>> getSignerCertificates(final int signersType); @Override Version getVersion(); @Override A adapt(final Class<A> type); @Override File getDataFile(final String filename); @Override int compareTo(final Bundle o); @Override String toString();  }
@Test void adaptBundleWiring() { assertNotNull(bundle.adapt(BundleWiring.class)); }
@Test void adaptMissing() { assertNull(bundle.adapt(String.class)); }