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

org.uberfire.ext.apps.api.Directory Maven / Gradle / Ivy

There is a newer version: 7.74.1.Final
Show newest version
/*
 * Copyright 2015 JBoss, by Red Hat, Inc
 *
 * 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.ext.apps.api;

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

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

@Portable
public class Directory {

    private String name;
    private Map> tagMap;

    private String fullPath;
    private Directory parent;
    private String URI;

    private List childsDirectories = new ArrayList();
    private List childComponents = new ArrayList();

    public Directory() {
    }

    public Directory(String name,
                     String fullPath,
                     String URI,
                     Directory parent) {
        this.name = name;
        this.fullPath = fullPath;
        this.parent = parent;
        this.URI = URI;
        this.tagMap = parent.getTagMap();
        setupChildComponents();
    }

    public Directory(String name,
                     String fullPath,
                     String URI,
                     Map> tagMap) {
        this.fullPath = fullPath;
        this.name = name;
        this.URI = URI;
        this.tagMap = tagMap;
        setupChildComponents();
    }

    private void setupChildComponents() {
        final List components = tagMap.get(name.toUpperCase());
        if (components != null) {
            childComponents.addAll(components);
        }
    }

    public String getName() {
        return name;
    }

    public List getChildsDirectories() {
        return childsDirectories;
    }

    public void addChildDirectory(Directory directory) {
        childsDirectories.add(directory);
    }

    public void addChildDirectories(List directories) {
        childsDirectories.addAll(directories);
    }

    public Directory getParent() {
        return parent;
    }

    public String getURI() {
        return URI;
    }

    public Map> getTagMap() {
        return tagMap;
    }

    public List getChildComponents() {
        return childComponents;
    }

    public void removeChildDirectoryByURI(String uri) {
        Directory candidate = null;
        for (Directory child : childsDirectories) {
            if (child.getURI().equalsIgnoreCase(uri)) {
                candidate = child;
                break;
            }
        }
        if (candidate != null) {
            childsDirectories.remove(candidate);
        }
    }

    public String getFullPath() {
        return fullPath;
    }

    public boolean alreadyHasChild(String dirName) {
        for (Directory child : childsDirectories) {
            if (child.getName().equalsIgnoreCase(dirName)) {
                return true;
            }
        }
        return false;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy