use of org.glassfish.api.deployment.archive.ArchiveDetector in project Payara by payara.
the class ApplicationLifecycle method getArchiveHandler.
/**
* Returns the ArchiveHandler for the passed archive abstraction or null
* if there are none.
*
* @param archive the archive to find the handler for
* @param type the type of the archive
* @return the archive handler or null if not found.
* @throws IOException when an error occur
*/
@Override
public ArchiveHandler getArchiveHandler(ReadableArchive archive, String type) throws IOException {
if (type != null) {
ArchiveDetector archiveDetector = habitat.<ArchiveDetector>getService(ArchiveDetector.class, type);
if (archiveDetector != null) {
return archiveDetector.getArchiveHandler();
}
}
List<ArchiveDetector> detectors = new ArrayList<>(habitat.<ArchiveDetector>getAllServices(ArchiveDetector.class));
Collections.sort(detectors, new Comparator<ArchiveDetector>() {
// rank 2 is considered lower than rank 1, let's sort them in inceasing order
@Override
public int compare(ArchiveDetector o1, ArchiveDetector o2) {
return o1.rank() - o2.rank();
}
});
for (ArchiveDetector ad : detectors) {
if (ad.handles(archive)) {
return ad.getArchiveHandler();
}
}
return null;
}
Aggregations