package org.lucci.madhoc.simulation.projection;

import javax.naming.ConfigurationException;

import org.lucci.madhoc.network.Station;
import org.lucci.madhoc.network.net.NetworkingTechnology;

/*
 * Created on May 3, 2005
 */

/**
 * @author luc.hogie
 */
public class NetworkInterfaceBasedProjection extends Projection
{
    private NetworkingTechnology acceptedNetworkType;

    
    /* (non-Javadoc)
     * @see org.lucci.madhoc.simulation.DeviceRelevancy#deviceIsRelevant(null)
     */
    public boolean acceptComputer(Station computer)
    {
        return computer.getNetworkingUnit().getNetworkInterface(getAcceptedNetworkType()) != null;
    }

    /* (non-Javadoc)
     * @see org.lucci.madhoc.util.Configurable#configure(org.lucci.madhoc.simulation.Simulation)
     */
    public void configure() throws Throwable
    {
        String networkTypeName = getNetwork().getSimulation().getConfiguration().getConfigurationValue("network_interface_based_projection_network_type");
        NetworkingTechnology type = (NetworkingTechnology) getNetwork().getNetworkTypes().get(networkTypeName);
        
        if (type == null)
        {
            throw new ConfigurationException("Unknown network type: " + networkTypeName);
        }
        else
        {
            setAcceptedNetworkType(type);
        }
    }
    /* (non-Javadoc)
     * @see org.lucci.madhoc.simulation.projection.Projection#getName()
     */
    public String getName()
    {
        return getAcceptedNetworkType().getName() + " devices";
    }
    public NetworkingTechnology getAcceptedNetworkType()
    {
        return acceptedNetworkType;
    }
    public void setAcceptedNetworkType(NetworkingTechnology acceptedNetworkType)
    {
        this.acceptedNetworkType = acceptedNetworkType;
    }
}