Coverage Report - org.openpermis.editor.policy.gui.binding.ActionNameConverter
 
Classes in this File Line Coverage Branch Coverage Complexity
ActionNameConverter
0%
0/15
0%
0/8
2.75
 
 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.gui.binding;
 11  
 
 12  
 import java.util.List;
 13  
 
 14  
 import org.jdesktop.beansbinding.Converter;
 15  
 
 16  
 import org.openpermis.editor.policy.presenter.ActionPresenter;
 17  
 import org.openpermis.policy.bean.ActionBean;
 18  
 
 19  
 
 20  
 /**
 21  
  * Converter that converts {@link String} to {@link String} and vice versa.
 22  
  * @since 0.3.0
 23  
  */
 24  0
 public class ActionNameConverter extends Converter<String, String>
 25  
 {
 26  
         //---- State
 27  
 
 28  
         private ActionPresenter presenter;
 29  
 
 30  
 
 31  
         //---- Constructor
 32  
 
 33  
         /**
 34  
          * @since 0.3.0
 35  
          */
 36  
         public ActionNameConverter (ActionPresenter presenter) {
 37  0
                 super();
 38  0
                 this.presenter = presenter;
 39  0
         }
 40  
 
 41  
 
 42  
         //---- Converter
 43  
 
 44  
         /**
 45  
          * @note Add name validity rule and auto-extensions here.
 46  
          * @since 0.3.0
 47  
          */
 48  
         @Override
 49  
         public String convertForward (String value) {
 50  0
                 return value;
 51  
         }
 52  
 
 53  
         /**
 54  
          * Check if a action name is already used by another action.
 55  
          * @param name name of the action
 56  
          * @return if name if already used
 57  
          * @since 0.3.0
 58  
          */
 59  
         private boolean actionNameInUse (String name) {
 60  0
                 List<ActionBean> list = this.presenter.getActionPool().getPoolList();
 61  0
                 for (ActionBean action : list) {
 62  0
                         if (action.getName().equals(name)) {
 63  0
                                 return true;
 64  
                         }
 65  
                 }
 66  0
                 return false;
 67  
         }
 68  
 
 69  
         /**
 70  
          * @since 0.3.0
 71  
          */
 72  
         @Override
 73  
         public String convertReverse (String value) {
 74  0
                 if (value.equals("")) {
 75  0
                         throw new RuntimeException("actionname must not be empty");
 76  0
                 } else if (actionNameInUse(value)) {
 77  0
                         throw new RuntimeException("actionname already in use");
 78  
                 }
 79  0
                 return value;
 80  
         }
 81  
 
 82  
 }