All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.uberfire.backend.vfs.FileSystemFactory Maven / Gradle / Ivy

There is a newer version: 7.74.1.Final
Show newest version
/*
 * Copyright 2015 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.uberfire.backend.vfs;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.jboss.errai.common.client.api.annotations.Portable;

import static org.uberfire.backend.vfs.PathFactory.newPath;
import static org.kie.soup.commons.validation.PortablePreconditions.checkNotNull;

/**
 *
 */
public final class FileSystemFactory {

    private FileSystemFactory() {

    }

    public static FileSystem newFS(final Map roots,
                                   final Set supportedViews) {
        return new FileSystemImpl(roots,
                                  supportedViews);
    }

    @Portable
    public static class FileSystemImpl implements FileSystem {

        private List rootDirectories = null;
        private Set supportedViews = null;

        public FileSystemImpl() {
        }

        public FileSystemImpl(final Map roots,
                              final Set supportedViews) {
            checkNotNull("roots",
                         roots);

            this.rootDirectories = new ArrayList(roots.size());

            for (final Map.Entry entry : roots.entrySet()) {
                this.rootDirectories.add(newPath(entry.getValue(),
                                                 entry.getKey()));
            }
            this.supportedViews = new HashSet(checkNotNull("supportedViews",
                                                                   supportedViews));
        }

        @Override
        public List getRootDirectories() {
            return rootDirectories;
        }

        @Override
        public Set supportedFileAttributeViews() {
            return supportedViews;
        }

        @Override
        public String toString() {
            final StringBuilder sb = new StringBuilder();
            if (rootDirectories != null) {
                for (final Path rootDirectory : rootDirectories) {
                    sb.append(rootDirectory.toString());
                }
            }
            return sb.toString();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy