Package org.jboss.aesh.console.command.registry

Source Code of org.jboss.aesh.console.command.registry.AeshInternalCommandRegistry

/*
* Copyright 2012 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.aesh.console.command.registry;

import org.jboss.aesh.console.command.Command;
import org.jboss.aesh.console.command.container.AeshCommandContainerBuilder;
import org.jboss.aesh.console.command.container.CommandContainer;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
* Only used by AeshConsoleImpl to store built-in commands
*
* @author <a href="mailto:stale.pedersen@jboss.org">Ståle W. Pedersen</a>
*/
public class AeshInternalCommandRegistry {

    private final Map<String, CommandContainer> registry = new HashMap<String, CommandContainer>();

    public void addCommand(Command command) {
        putIntoRegistry(new AeshCommandContainerBuilder().build(command));
    }

    private void putIntoRegistry(CommandContainer commandContainer) {
        if(!commandContainer.haveBuildError() &&
                !registry.containsKey(commandContainer.getParser().getProcessedCommand().getName()))
            registry.put(commandContainer.getParser().getProcessedCommand().getName(), commandContainer);
    }

    public CommandContainer getCommand(String name) {
        return registry.get(name);
    }

    public Set<String> getAllCommandNames() {
        return registry.keySet();
    }
}
TOP

Related Classes of org.jboss.aesh.console.command.registry.AeshInternalCommandRegistry

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.