/*
 * ICESOFT COMMERCIAL SOURCE CODE LICENSE V 1.1
 *
 * The contents of this file are subject to the ICEsoft Commercial Source
 * Code License Agreement V1.1 (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.icesoft.com/license/commercial-source-v1.1.html
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations under
 * the License.
 *
 * Copyright 2009-2015 ICEsoft Technologies Canada, Corp. All Rights Reserved.
 */
package com.icesoft.net.messaging.expression;

import com.icesoft.net.messaging.Message;

import java.util.logging.Level;
import java.util.logging.Logger;

public class IsNull
extends ComparisonOperator<Identifier>
implements Expression, Operand {
    private static final Logger LOGGER = Logger.getLogger(IsNull.class.getName());

    private static final int IDENTIFIER_INDEX = 0;

    public IsNull(final Identifier identifier)
    throws IllegalArgumentException {
        // throws IllegalArgumentException
        super(identifier);
    }

    public boolean evaluate(final Message message)
    throws IllegalArgumentException {
        if (message == null) {
            throw new IllegalArgumentException("Illegal value of argument 'message': null");
        }
        boolean _result = !message.propertyExists(getIdentifier().getValue());
        if (LOGGER.isLoggable(Level.FINEST)) {
            LOGGER.log(Level.FINEST, this + " evaluates to " + _result);
        }
        return _result;
    }

    public Identifier getIdentifier() {
        return getOperands()[IDENTIFIER_INDEX];
    }

    public String toString() {
        return getIdentifier() + " IS NULL";
    }
}
