Coverage Report - org.openpermis.editor.policy.command.CompositeCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
CompositeCommand
0%
0/9
0%
0/4
1.667
 
 1  
 /*
 2  
  * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport
 3  
  *                     (http://www.vbs.admin.ch)
 4  
  * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch)
 5  
  * All rights reserved.
 6  
  *
 7  
  * Licensed under the Open Permis License which accompanies this distribution,
 8  
  * and is available at http://www.openpermis.org/BSDlicenceKent.txt
 9  
  */
 10  
 package org.openpermis.editor.policy.command;
 11  
 
 12  
 import org.openpermis.policy.bean.PolicyBean;
 13  
 
 14  
 
 15  
 /**
 16  
  * Composite command.
 17  
  * @since 0.1.0
 18  
  */
 19  
 public class CompositeCommand extends AbstractCommand {
 20  
 
 21  
         //---- State
 22  
 
 23  
         /**
 24  
          * The first command to execute.
 25  
          * @since 0.1.0
 26  
          */
 27  
         private final Command[] commands;
 28  
 
 29  
         //---- Constructors
 30  
 
 31  
         /**
 32  
          * Creates a composite command.
 33  
          * @param commands commands to execute.
 34  
          * @since 0.1.0
 35  
          */
 36  
         public CompositeCommand (Command ... commands) {
 37  0
                 super(commands[0].getName());
 38  0
                 this.commands = commands;
 39  0
         }
 40  
 
 41  
         //---- Methods
 42  
 
 43  
         /**
 44  
          * @since 0.1.0
 45  
          */
 46  
         @Override
 47  
         public void execute (PolicyBean policy) throws Exception {
 48  0
                 for (int i = 0; i < this.commands.length; i++) {
 49  0
                         this.commands[i].execute(policy);
 50  
                 }
 51  0
         }
 52  
 
 53  
         /**
 54  
          * @since 0.1.0
 55  
          */
 56  
         @Override
 57  
         public void undo (PolicyBean policy) throws Exception {
 58  0
                 for (int i = this.commands.length - 1; i >= 0; i--) {
 59  0
                         this.commands[i].undo(policy);
 60  
                 }
 61  0
         }
 62  
 
 63  
 }