class SwiftObjectListService implements ListService {

    @Override
    public AttributedList<Path> list(final Path directory, final ListProgressListener listener) throws BackgroundException {
        try {
            final AttributedList<Path> children = new AttributedList<Path>();
            final int limit = PreferencesFactory.get().getInteger("openstack.list.object.limit");
            String marker = null;
            List<StorageObject> list;
            final Path container = containerService.getContainer(directory);
            do {
                list = session.getClient().listObjectsStartingWith(regionService.lookup(container), container.getName(),
                    containerService.isContainer(directory) ? StringUtils.EMPTY : containerService.getKey(directory) + Path.DELIMITER,
                    null, limit, marker, Path.DELIMITER);
                for(StorageObject object : list) {
                    final PathAttributes attr = attributes.toAttributes(object);
                    final EnumSet<Path.Type> types = "application/directory"
                        .equals(object.getMimeType()) ? EnumSet.of(Path.Type.directory) : EnumSet.of(Path.Type.file);
                    if(StringUtils.endsWith(object.getName(), String.valueOf(Path.DELIMITER))) {
                        if(children.contains(new Path(directory, PathNormalizer.name(object.getName()), EnumSet.of(Path.Type.directory), attr))) {
                            // There is already a real placeholder file with application/directory MIME type. Only
                            // add virtual directory if the placeholder object is missing
                            continue;
                        }
                    }
                    attr.setOwner(container.attributes().getOwner());
                    attr.setRegion(container.attributes().getRegion());
                    children.add(new Path(directory, PathNormalizer.name(object.getName()), types, attr));
                    marker = object.getName();
                }
                listener.chunk(directory, children);
            }
            while(list.size() == limit);
            if(!containerService.isContainer(directory) && children.isEmpty()) {
                if(!new SwiftFindFeature(session).find(directory)) {
                    throw new NotfoundException(directory.getAbsolute());
                }
            }
            return children;
        }
        catch(GenericException e) {
            throw new SwiftExceptionMappingService().map("Listing directory {0} failed", e, directory);
        }
        catch(IOException e) {
            throw new DefaultIOExceptionMappingService().map(e, directory);
        }
    }

    public  SwiftObjectListService(final SwiftSession session);
    public  SwiftObjectListService(final SwiftSession session, final SwiftRegionService regionService);

}