Copying arrays or collection domains

You can copy collection domains or arrays if they have the right return type.

To copy collection domains or arrays, you must declare a BOM method with the appropriate return type:

  1. In the BOM you declare two methods:

    • Collection domains:

      public static java.util.Collection copy(java.util.Collection items domain 0,* class object) domain 0,* class object
      property noTypeConversion "true";
    • Arrays:

      public static java.lang.Object[] copy(java.lang.Object[] items);

      Only one of the two methods is verbalized in the vocabulary, to make sure you have only one sentence in the BAL. The method overriding mechanism selects the most appropriate method to apply.

  2. If you use these methods in a rule, the information relative to the type of the returned collection is lost, and it is considered as a collection of objects. You must declare a BOM method with the right return type.

    If you do not specify the correct return type, Rule Designer raises an error. For example, in the following rule, you have a ruleset parameter named myArray of type Item[]:

    definitions 
    set items to all items;
    then
    set myArray to a copy of items;

    You get an error because the type returned by the copy (java.lang.Object[]) method is not a subtype of Item[].