Coverage Report - org.openpermis.editor.policy.gui.binding.UriConverter
 
Classes in this File Line Coverage Branch Coverage Complexity
UriConverter
0%
0/7
0%
0/6
4.5
 
 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.net.URI;
 13  
 import java.net.URISyntaxException;
 14  
 
 15  
 import org.jdesktop.beansbinding.Converter;
 16  
 
 17  
 
 18  
 /**
 19  
  * Converter that converts {@link String} to {@link URI} and vice versa.
 20  
  * @since 0.1.0
 21  
  */
 22  0
 public class UriConverter
 23  
         extends Converter<URI, String>
 24  
 {
 25  
 
 26  
         //---- Converter
 27  
         
 28  
         /**
 29  
          * @since 0.1.0
 30  
          */
 31  
         @Override
 32  
         public String convertForward (URI value) {
 33  0
                 return value == null ? "" : value.toString();
 34  
         }
 35  
 
 36  
         /**
 37  
          * @since 0.1.0
 38  
          */
 39  
         @Override
 40  
         public URI convertReverse (String value) {
 41  0
                 if (value == null || value.length() == 0) {
 42  0
                         return null;
 43  
                 }
 44  
                 try {
 45  0
                         return new URI(value);
 46  0
                 } catch (URISyntaxException e) {
 47  0
                         throw new RuntimeException("Invalid URI [" + value + "].");
 48  
                 }
 49  
         }
 50  
 
 51  
 }