001package org.andromda.translation.ocl.validation;
002
003/**
004 * <p/>
005 * Ensures that the result of the OCL expression is a boolean value. This is necessary because some expressions' results
006 * will actually be wrapped in an instance of <code>Object</code> because of the fact that OCLIntropector is
007 * used. </p>
008 *
009 * @author Chad Brandon
010 */
011public final class OCLResultEnsurer
012{
013    /**
014     * Needed in case OCL syntax is invalid - no boolean parameter is added to ensure() method
015     *
016     * @return true always - the boolean result.
017     */
018    public static boolean ensure()
019    {
020        return true;
021    }
022
023    /**
024     * Does nothing but return the passed in <code>result</code> argument.
025     *
026     * @param result the result.
027     * @return the boolean result.
028     */
029    public static boolean ensure(boolean result)
030    {
031        return result;
032    }
033
034    /**
035     * Converts the passed in <code>result</code> to a <code>boolean</code> value and returns it. If <code>result</code>
036     * is null, false will be assumed.
037     *
038     * @param result
039     * @return the boolean result.
040     */
041    public static boolean ensure(Object result)
042    {
043        return result != null && Boolean.valueOf(result.toString());
044    }
045}