Coverage Report - org.openpermis.policy.io.StrictPolicyReader
 
Classes in this File Line Coverage Branch Coverage Complexity
StrictPolicyReader
100%
9/9
100%
4/4
3
 
 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.policy.io;
 11  
 
 12  
 
 13  
 import org.openpermis.policy.Policy;
 14  
 
 15  
 /**
 16  
  * Strict policy reader, which only successfully reads valid policies.
 17  
  * @since 0.4.0
 18  
  */
 19  
 public class StrictPolicyReader
 20  
         implements PolicyReader
 21  
 {
 22  
 
 23  
         //---- Static
 24  
 
 25  
         //---- State
 26  
 
 27  
         private PolicyReader policyReader;
 28  
 
 29  
         //---- Constructors
 30  
         
 31  
         /**
 32  
          * Creates a new strict policy reader that uses the specified reader.
 33  
          * @param policyReader the policy reader.
 34  
          * @throws PolicyException if the XML reader cannot be created.
 35  
          * @since 0.4.0
 36  
          */
 37  3
         public StrictPolicyReader (PolicyReader policyReader) throws PolicyException {
 38  3
                 if (policyReader == null) {
 39  1
                         throw new IllegalArgumentException("Policy reader is null.");
 40  
                 }
 41  2
                 this.policyReader = policyReader;
 42  2
         }
 43  
 
 44  
         //---- Methods
 45  
 
 46  
         /**
 47  
          * @since 0.4.0
 48  
          */
 49  
         public Policy readPolicy () throws PolicyException {
 50  2
                 final Policy policy = this.policyReader.readPolicy();
 51  2
                 if (!policy.isValid(null)) {
 52  1
                         throw new PolicyException("Policy is not valid.");
 53  
                 }
 54  1
                 return policy;
 55  
         }
 56  
 
 57  
 }