Coverage Report - org.openpermis.editor.policy.presenter.PolicyPool
 
Classes in this File Line Coverage Branch Coverage Complexity
PolicyPool
38%
10/26
N/A
1
PolicyPool$1
100%
2/2
N/A
1
PolicyPool$2
100%
2/2
N/A
1
 
 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.presenter;
 11  
 
 12  
 import java.util.List;
 13  
 
 14  
 import org.openpermis.policy.bean.ActionBean;
 15  
 import org.openpermis.policy.bean.AuthorityBean;
 16  
 import org.openpermis.policy.bean.DomainBean;
 17  
 import org.openpermis.policy.bean.ObligationBean;
 18  
 import org.openpermis.policy.bean.PolicyBean;
 19  
 import org.openpermis.policy.bean.TargetBean;
 20  
 
 21  
 /**
 22  
  * Pool Handling for a policy presenter.
 23  
  * @since 0.1.0
 24  
  */
 25  
 public class PolicyPool
 26  
 {
 27  
         //---- State
 28  
 
 29  
         private final PolicyPartPool<DomainBean> resourceDomainPool;
 30  
         
 31  
         private final PolicyPartPool<DomainBean> subjectDomainPool;
 32  
 
 33  
         private final PolicyPartPool<TargetBean> targetPool;
 34  
         
 35  
         private final PolicyPartPool<ObligationBean> obligationPool;
 36  
 
 37  
         private final PolicyRoleRefPool rolePool;
 38  
 
 39  
         private final PolicyPartPool<ActionBean> actionPool;
 40  
 
 41  
         private final PolicyPartPool<AuthorityBean> authorityPool;
 42  
 
 43  
         //---- Constructors
 44  
 
 45  
         /**
 46  
          * Creates a new presenter for the specified policy.
 47  
          * @param policy the policy to create the presenter for, must not be {@code null}.
 48  
          * @since 0.1.0
 49  
          */
 50  
         public PolicyPool (PolicyBean policy) {
 51  1
                 super();
 52  1
                 this.resourceDomainPool =
 53  
                         new PolicyPartPool<DomainBean>(
 54  
                                 policy, 
 55  
                                 new PolicyPartPool.PartFinder<DomainBean>() {
 56  1
                                         public List<DomainBean> getParts (PolicyBean policy) {
 57  1
                                                 return policy.getResourceDomains();
 58  
                                         }
 59  
                                 }
 60  
                         );
 61  1
                 this.subjectDomainPool =
 62  
                         new PolicyPartPool<DomainBean>(
 63  
                                 policy, 
 64  
                                 new PolicyPartPool.PartFinder<DomainBean>() {
 65  1
                                         public List<DomainBean> getParts (PolicyBean policy) {
 66  1
                                                 return policy.getSubjectDomains();
 67  
                                         }
 68  
                                 }
 69  
                         );
 70  1
                 this.targetPool =
 71  
                         new PolicyPartPool<TargetBean>(policy, TargetBean.class);
 72  1
                 this.obligationPool =
 73  
                         new PolicyPartPool<ObligationBean>(policy, ObligationBean.class);
 74  1
                 this.rolePool =
 75  
                         new PolicyRoleRefPool(policy);
 76  1
                 this.actionPool =
 77  
                         new PolicyPartPool<ActionBean>(policy, ActionBean.class);
 78  1
                 this.authorityPool =
 79  
                         new PolicyPartPool<AuthorityBean>(policy, AuthorityBean.class);
 80  1
         }
 81  
 
 82  
         //---- Methods
 83  
 
 84  
         /**
 85  
          * Returns the policy pool for resourceDomains.
 86  
          * @return Returns the policy pool for resourceDomains.
 87  
          * @since 0.1.0
 88  
          */
 89  
         public PolicyPartPool<DomainBean> getResourceDomainPool () {
 90  0
                 return this.resourceDomainPool;
 91  
         }
 92  
         
 93  
         /**
 94  
          * Returns the policy pool for subjectDomains.
 95  
          * @return Returns the policy pool for subjectDomains.
 96  
          * @since 0.3.0
 97  
          */
 98  
         public PolicyPartPool<DomainBean> getSubjectDomainPool () {
 99  0
                 return this.subjectDomainPool;
 100  
         }
 101  
 
 102  
         /**
 103  
          * Returns the policy pool for targets.
 104  
          * @return Returns the policy pool for targets.
 105  
          * @since 0.1.0
 106  
          */
 107  
         public PolicyPartPool<TargetBean> getTargetPool () {
 108  0
                 return this.targetPool;
 109  
         }
 110  
         
 111  
         /**
 112  
          * Returns the policy pool for obligations.
 113  
          * @return Returns the policy pool for obligations.
 114  
          * @since 0.3.0
 115  
          */
 116  
         public PolicyPartPool<ObligationBean> getObligationPool () {
 117  0
                 return this.obligationPool;
 118  
         }
 119  
 
 120  
         /**
 121  
          * Returns the policy pool for roles.
 122  
          * @return Returns the policy pool for roles.
 123  
          * @since 0.1.0
 124  
          */
 125  
         public PolicyRoleRefPool getRolePool () {
 126  0
                 return this.rolePool;
 127  
         }
 128  
 
 129  
         /**
 130  
          * Returns the policy pool for actions.
 131  
          * @return Returns the policy pool for actions.
 132  
          * @since 0.1.0
 133  
          */
 134  
         public PolicyPartPool<ActionBean> getActionPool () {
 135  0
                 return this.actionPool;
 136  
         }
 137  
 
 138  
         /**
 139  
          * Returns the policy pool for authorities.
 140  
          * @return a part pool for authorities.
 141  
          * @since 0.3.0
 142  
          */
 143  
         public PolicyPartPool<AuthorityBean> getAuthorityPool () {
 144  1
                 return this.authorityPool;
 145  
         }
 146  
 
 147  
         /**
 148  
          * Merges all pools.
 149  
          * @param policy the policy.
 150  
          * @param expunge indicates if unused parts are removed from the list.
 151  
          * @since 0.1.0
 152  
          */
 153  
         public void mergePool (PolicyBean policy, boolean expunge) {
 154  0
                 this.getResourceDomainPool().mergePool(policy, expunge);
 155  0
                 this.getSubjectDomainPool().mergePool(policy, expunge);
 156  0
                 this.getTargetPool().mergePool(policy, expunge);
 157  0
                 this.getActionPool().mergePool(policy, expunge);
 158  0
                 this.getRolePool().mergePool(policy, expunge);
 159  0
                 this.getAuthorityPool().mergePool(policy, expunge);
 160  0
                 this.getObligationPool().mergePool(policy, expunge);
 161  0
         }
 162  
 
 163  
         /**
 164  
          * Merges role pool.
 165  
          * @param policy the policy.
 166  
          * @param expunge indicates if unused parts are removed from the list.
 167  
          * @since 0.3.0
 168  
          */
 169  
         public void mergeRolePool (PolicyBean policy, boolean expunge) {
 170  0
                 this.getRolePool().mergePool(policy, expunge);
 171  0
         }
 172  
 
 173  
 
 174  
 }