View Javadoc
1   package org.andromda.translation.ocl.validation;
2   
3   /**
4    * <p/>
5    * Ensures that the result of the OCL expression is a boolean value. This is necessary because some expressions' results
6    * will actually be wrapped in an instance of <code>Object</code> because of the fact that OCLIntropector is
7    * used. </p>
8    *
9    * @author Chad Brandon
10   */
11  public final class OCLResultEnsurer
12  {
13      /**
14       * Needed in case OCL syntax is invalid - no boolean parameter is added to ensure() method
15       *
16       * @return true always - the boolean result.
17       */
18      public static boolean ensure()
19      {
20          return true;
21      }
22  
23      /**
24       * Does nothing but return the passed in <code>result</code> argument.
25       *
26       * @param result the result.
27       * @return the boolean result.
28       */
29      public static boolean ensure(boolean result)
30      {
31          return result;
32      }
33  
34      /**
35       * Converts the passed in <code>result</code> to a <code>boolean</code> value and returns it. If <code>result</code>
36       * is null, false will be assumed.
37       *
38       * @param result
39       * @return the boolean result.
40       */
41      public static boolean ensure(Object result)
42      {
43          return result != null && Boolean.valueOf(result.toString());
44      }
45  }