in winegrower-core/src/main/java/org/apache/winegrower/deployer/BundleImpl.java [405:458]
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;
}