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

com.cookingfox.chefling.impl.command.AddChildContainerCommandImpl Maven / Gradle / Ivy

Go to download

Chefling is a very minimal dependency injection container written in pure Java.

There is a newer version: 7.1.1
Show newest version
package com.cookingfox.chefling.impl.command;

import com.cookingfox.chefling.api.CheflingContainer;
import com.cookingfox.chefling.api.command.AddChildContainerCommand;
import com.cookingfox.chefling.api.exception.InvalidChildContainerException;

/**
 * @see AddChildContainerCommand
 */
public class AddChildContainerCommandImpl extends AbstractCommand implements AddChildContainerCommand {

    //----------------------------------------------------------------------------------------------
    // CONSTRUCTORS
    //----------------------------------------------------------------------------------------------

    public AddChildContainerCommandImpl(CommandContainer container) {
        super(container);
    }

    //----------------------------------------------------------------------------------------------
    // PUBLIC METHODS
    //----------------------------------------------------------------------------------------------

    @Override
    public void addChildContainer(CheflingContainer container) {
        if (container == null) {
            throw new InvalidChildContainerException("Child container cannot be null");
        } else if (container.equals(_container)) {
            throw new InvalidChildContainerException("Child container can not be the same " +
                    "instance as the container it is being added to");
        } else if (!(container instanceof CommandContainer)) {
            throw new InvalidChildContainerException("Child container must be an instance of " +
                    "CommandContainer");
        }

        CommandContainer child = (CommandContainer) container;

        if (child.parent != null) {
            throw new InvalidChildContainerException("Child container has already been added");
        }

        checkMappingConflicts(child);

        child.parent = _container;

        _container.children.add(child);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy