Changeset 1422


Ignore:
Timestamp:
02/28/14 13:13:05 (11 years ago)
Author:
pharms
Message:
  • added some checks to prevent creation of invalid task trees
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/autoquest-core-tasktrees/src/main/java/de/ugoe/cs/autoquest/tasktrees/treeimpl/TaskBuilder.java

    r1362 r1422  
    1919import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 
    2020import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 
     21import de.ugoe.cs.autoquest.tasktrees.treeifc.IMarkingTemporalRelationship; 
    2122import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 
    2223import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; 
     
    2526import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 
    2627import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; 
     28import de.ugoe.cs.autoquest.tasktrees.treeifc.IStructuringTemporalRelationship; 
    2729import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 
    2830import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; 
     
    6062        } 
    6163         
    62         /*IStructuringTemporalRelationship parentTask = 
    63             (IStructuringTemporalRelationship) parent.getTask(); 
    64          
     64        SequenceInstance seqInstance = (SequenceInstance) instance; 
     65         
     66        // check if new child instance matches the model, if this can be checked 
     67        IStructuringTemporalRelationship parentTask = 
     68            (IStructuringTemporalRelationship) instance.getTask(); 
     69         
     70        if (((parentTask.getChildren() != null) && (parentTask.getChildren().size() > 0)) && 
     71            ((parentTask.getChildren().size() <= seqInstance.size()) || 
     72             (!parentTask.getChildren().get(seqInstance.size()).equals(child.getTask())))) 
     73        { 
     74            throw new IllegalArgumentException 
     75                ("the task of the child instance to be added does not belong to the children " + 
     76                 "of the task of the parent instance"); 
     77        } 
     78 
     79        seqInstance.addChild(child); 
     80    } 
     81 
     82    /* (non-Javadoc) 
     83     * @see ITaskBuilder#addChild(ISequenceInstance, int, ITaskInstance) 
     84     */ 
     85    public void addChild(ISequenceInstance instance, int index, ITaskInstance child) 
     86        throws IllegalArgumentException 
     87    { 
     88        if (!(instance instanceof SequenceInstance)) { 
     89            throw new IllegalArgumentException 
     90                ("illegal type of sequence instance provided: " + instance.getClass()); 
     91        } 
     92 
     93        if (!(child instanceof TaskInstance)) { 
     94            throw new IllegalArgumentException 
     95                ("illegal type of task instance provided: " + child.getClass()); 
     96        } 
     97         
     98        SequenceInstance seqInstance = (SequenceInstance) instance; 
     99         
     100        // check if new child instance matches the model, if this can be checked 
     101        IStructuringTemporalRelationship parentTask = 
     102            (IStructuringTemporalRelationship) instance.getTask(); 
     103         
     104        if (((parentTask.getChildren() != null) && (parentTask.getChildren().size() > 0)) && 
     105            ((parentTask.getChildren().size() <= index) || 
     106             (!parentTask.getChildren().get(index).equals(child.getTask())))) 
     107        { 
     108            throw new IllegalArgumentException 
     109                ("the task of the child instance to be added does not belong to the children " + 
     110                 "of the task of the parent instance"); 
     111        } 
     112         
     113        seqInstance.addChild(index, child); 
     114    } 
     115 
     116    /* (non-Javadoc) 
     117     * @see ITaskBuilder#addChild(IIterationInstance, ITaskInstance) 
     118     */ 
     119    @Override 
     120    public void addChild(IIterationInstance instance, ITaskInstance child) 
     121        throws IllegalArgumentException 
     122    { 
     123        if (!(instance instanceof IterationInstance)) { 
     124            throw new IllegalArgumentException 
     125                ("illegal type of iteration instance provided: " + instance.getClass()); 
     126        } 
     127 
     128        if (!(child instanceof TaskInstance)) { 
     129            throw new IllegalArgumentException 
     130                ("illegal type of task instance provided: " + child.getClass()); 
     131        } 
     132         
     133        // check if new child instance matches the model, if this can be checked 
     134        IMarkingTemporalRelationship parentTask = 
     135            (IMarkingTemporalRelationship) instance.getTask(); 
     136                 
     137        boolean foundChildTask = parentTask.getMarkedTask() != null ? 
     138            parentTask.getMarkedTask().equals(child.getTask()) : true; 
     139                 
     140        if (!foundChildTask) { 
     141            throw new IllegalArgumentException 
     142                ("the task of the child instance does not match the model of the task of the " + 
     143                 "iteration instance: " + parentTask.getMarkedTask() + " <> " + child.getTask()); 
     144        } 
     145 
     146        ((IterationInstance) instance).addChild(child); 
     147    } 
     148 
     149    /* (non-Javadoc) 
     150     * @see ITaskBuilder#addChild(IIterationInstance, int, ITaskInstance) 
     151     */ 
     152    public void addChild(IIterationInstance instance, int index, ITaskInstance child) 
     153        throws IllegalArgumentException 
     154    { 
     155        if (!(instance instanceof IterationInstance)) { 
     156            throw new IllegalArgumentException 
     157                ("illegal type of iteration instance provided: " + instance.getClass()); 
     158        } 
     159 
     160        if (!(child instanceof TaskInstance)) { 
     161            throw new IllegalArgumentException 
     162                ("illegal type of task instance provided: " + child.getClass()); 
     163        } 
     164         
     165        // check if new child instance matches the model, if this can be checked 
     166        IMarkingTemporalRelationship parentTask = 
     167            (IMarkingTemporalRelationship) instance.getTask(); 
     168                 
     169        boolean foundChildTask = parentTask.getMarkedTask() != null ? 
     170            parentTask.getMarkedTask().equals(child.getTask()) : true; 
     171                 
     172        if (!foundChildTask) { 
     173            throw new IllegalArgumentException 
     174                ("the task of the child instance does not match the model of the task of the " + 
     175                 "iteration instance: " + parentTask.getMarkedTask() + " <> " + child.getTask()); 
     176        } 
     177 
     178        ((IterationInstance) instance).addChild(index, child); 
     179    } 
     180 
     181    /* (non-Javadoc) 
     182     * @see ITaskBuilder#setChild(ISelectionInstance, ITaskInstance) 
     183     */ 
     184    @Override 
     185    public void setChild(ISelectionInstance instance, ITaskInstance child) 
     186        throws IllegalArgumentException 
     187    { 
     188        if (!(instance instanceof SelectionInstance)) { 
     189            throw new IllegalArgumentException 
     190                ("illegal type of selection instance provided: " + instance.getClass()); 
     191        } 
     192 
     193        if (!(child instanceof TaskInstance)) { 
     194            throw new IllegalArgumentException("illegal type of task instance provided: " + 
     195                                               (child == null ? null : child.getClass())); 
     196        } 
     197         
     198        // check if new child instance matches the model, if this can be checked 
     199        IStructuringTemporalRelationship parentTask = 
     200            (IStructuringTemporalRelationship) instance.getTask(); 
     201         
     202        boolean foundChildTask = false; 
    65203        for (ITask parentTaskChild : parentTask.getChildren()) { 
    66204            if (parentTaskChild.equals(child.getTask())) { 
     
    73211            throw new IllegalArgumentException 
    74212                ("the task of the child instance to be added does not belong to the children " + 
    75                  "of the task of the parent instance"); 
    76         }*/ 
    77  
    78         ((SequenceInstance) instance).addChild(child); 
    79     } 
    80  
    81     /* (non-Javadoc) 
    82      * @see ITaskBuilder#addChild(ISequenceInstance, int, ITaskInstance) 
    83      */ 
    84     public void addChild(ISequenceInstance instance, int index, ITaskInstance child) 
     213                 "of the selection task model of the parent instance"); 
     214        } 
     215 
     216        ((SelectionInstance) instance).setChild(child); 
     217    } 
     218 
     219    /* (non-Javadoc) 
     220     * @see ITaskBuilder#setChild(IOptionalInstance, ITaskInstance) 
     221     */ 
     222    @Override 
     223    public void setChild(IOptionalInstance instance, ITaskInstance child) 
    85224        throws IllegalArgumentException 
    86225    { 
    87         if (!(instance instanceof SequenceInstance)) { 
    88             throw new IllegalArgumentException 
    89                 ("illegal type of sequence instance provided: " + instance.getClass()); 
     226        if (!(instance instanceof OptionalInstance)) { 
     227            throw new IllegalArgumentException 
     228                ("illegal type of optional instance provided: " + instance.getClass()); 
    90229        } 
    91230 
     
    95234        } 
    96235         
    97         /*IStructuringTemporalRelationship parentTask = 
    98             (IStructuringTemporalRelationship) parent.getTask(); 
    99          
    100         for (ITask parentTaskChild : parentTask.getChildren()) { 
    101             if (parentTaskChild.equals(child.getTask())) { 
    102                 foundChildTask = true; 
    103                 break; 
    104             } 
    105         } 
     236        // check if new child instance matches the model, if this can be checked 
     237        IMarkingTemporalRelationship parentTask = 
     238            (IMarkingTemporalRelationship) instance.getTask(); 
     239             
     240        boolean foundChildTask = parentTask.getMarkedTask() != null ? 
     241            parentTask.getMarkedTask().equals(child.getTask()) : true; 
    106242             
    107243        if (!foundChildTask) { 
    108244            throw new IllegalArgumentException 
    109                 ("the task of the child instance to be added does not belong to the children " + 
    110                  "of the task of the parent instance"); 
    111         }*/ 
    112  
    113         ((SequenceInstance) instance).addChild(index, child); 
    114     } 
    115  
    116     /* (non-Javadoc) 
    117      * @see ITaskBuilder#addChild(IIterationInstance, ITaskInstance) 
    118      */ 
    119     @Override 
    120     public void addChild(IIterationInstance instance, ITaskInstance child) 
    121         throws IllegalArgumentException 
    122     { 
    123         if (!(instance instanceof IterationInstance)) { 
    124             throw new IllegalArgumentException 
    125                 ("illegal type of iteration instance provided: " + instance.getClass()); 
    126         } 
    127  
    128         if (!(child instanceof TaskInstance)) { 
    129             throw new IllegalArgumentException 
    130                 ("illegal type of task instance provided: " + child.getClass()); 
    131         } 
    132          
    133         /*IStructuringTemporalRelationship parentTask = 
    134             (IStructuringTemporalRelationship) parent.getTask(); 
    135          
    136         IMarkingTemporalRelationship parentTask = 
    137             (IMarkingTemporalRelationship) parent.getTask(); 
    138              
    139         foundChildTask = parentTask.getMarkedTask() != null ? 
    140             parentTask.getMarkedTask().equals(child.getTask()) : false; 
    141              
    142         if (!foundChildTask) { 
    143             throw new IllegalArgumentException 
    144                 ("the task of the child instance to be added does not belong to the children " + 
    145                  "of the task of the parent instance"); 
    146         }*/ 
    147  
    148         ((IterationInstance) instance).addChild(child); 
    149     } 
    150  
    151     /* (non-Javadoc) 
    152      * @see ITaskBuilder#addChild(IIterationInstance, int, ITaskInstance) 
    153      */ 
    154     public void addChild(IIterationInstance instance, int index, ITaskInstance child) 
    155         throws IllegalArgumentException 
    156     { 
    157         if (!(instance instanceof IterationInstance)) { 
    158             throw new IllegalArgumentException 
    159                 ("illegal type of iteration instance provided: " + instance.getClass()); 
    160         } 
    161  
    162         if (!(child instanceof TaskInstance)) { 
    163             throw new IllegalArgumentException 
    164                 ("illegal type of task instance provided: " + child.getClass()); 
    165         } 
    166          
    167         /*IStructuringTemporalRelationship parentTask = 
    168             (IStructuringTemporalRelationship) parent.getTask(); 
    169          
    170         IMarkingTemporalRelationship parentTask = 
    171             (IMarkingTemporalRelationship) parent.getTask(); 
    172              
    173         foundChildTask = parentTask.getMarkedTask() != null ? 
    174             parentTask.getMarkedTask().equals(child.getTask()) : false; 
    175              
    176         if (!foundChildTask) { 
    177             throw new IllegalArgumentException 
    178                 ("the task of the child instance to be added does not belong to the children " + 
    179                  "of the task of the parent instance"); 
    180         }*/ 
    181  
    182         ((IterationInstance) instance).addChild(index, child); 
    183     } 
    184  
    185     /* (non-Javadoc) 
    186      * @see ITaskBuilder#setChild(ISelectionInstance, ITaskInstance) 
    187      */ 
    188     @Override 
    189     public void setChild(ISelectionInstance instance, ITaskInstance child) 
    190         throws IllegalArgumentException 
    191     { 
    192         if (!(instance instanceof SelectionInstance)) { 
    193             throw new IllegalArgumentException 
    194                 ("illegal type of selection instance provided: " + instance.getClass()); 
    195         } 
    196  
    197         if (!(child instanceof TaskInstance)) { 
    198             throw new IllegalArgumentException("illegal type of task instance provided: " + 
    199                                                (child == null ? null : child.getClass())); 
    200         } 
    201          
    202         /*IStructuringTemporalRelationship parentTask = 
    203             (IStructuringTemporalRelationship) parent.getTask(); 
    204          
    205         for (ITask parentTaskChild : parentTask.getChildren()) { 
    206             if (parentTaskChild.equals(child.getTask())) { 
    207                 foundChildTask = true; 
    208                 break; 
    209             } 
    210         } 
    211              
    212         if (!foundChildTask) { 
    213             throw new IllegalArgumentException 
    214                 ("the task of the child instance to be added does not belong to the children " + 
    215                  "of the task of the parent instance"); 
    216         }*/ 
    217  
    218         ((SelectionInstance) instance).setChild(child); 
    219     } 
    220  
    221     /* (non-Javadoc) 
    222      * @see ITaskBuilder#setChild(IOptionalInstance, ITaskInstance) 
    223      */ 
    224     @Override 
    225     public void setChild(IOptionalInstance instance, ITaskInstance child) 
    226         throws IllegalArgumentException 
    227     { 
    228         if (!(instance instanceof OptionalInstance)) { 
    229             throw new IllegalArgumentException 
    230                 ("illegal type of optional instance provided: " + instance.getClass()); 
    231         } 
    232  
    233         if (!(child instanceof TaskInstance)) { 
    234             throw new IllegalArgumentException 
    235                 ("illegal type of task instance provided: " + child.getClass()); 
    236         } 
    237          
    238         /*IStructuringTemporalRelationship parentTask = 
    239             (IStructuringTemporalRelationship) parent.getTask(); 
    240          
    241         IMarkingTemporalRelationship parentTask = 
    242             (IMarkingTemporalRelationship) parent.getTask(); 
    243              
    244         foundChildTask = parentTask.getMarkedTask() != null ? 
    245             parentTask.getMarkedTask().equals(child.getTask()) : false; 
    246              
    247         if (!foundChildTask) { 
    248             throw new IllegalArgumentException 
    249                 ("the task of the child instance to be added does not belong to the children " + 
    250                  "of the task of the parent instance"); 
    251         }*/ 
     245                ("the task of the child instance does not match the model of the task of the " + 
     246                 "optional instance: " + parentTask.getMarkedTask() + " <> " + child.getTask()); 
     247        } 
    252248 
    253249        ((OptionalInstance) instance).setChild(child); 
Note: See TracChangeset for help on using the changeset viewer.