View Javadoc
1   package org.pojomatic.internal;
2   
3   import java.util.Collections;
4   import java.util.Set;
5   
6   import org.pojomatic.annotations.DefaultPojomaticPolicy;
7   import org.pojomatic.annotations.PojomaticPolicy;
8   
9   public class PropertyFilter {
10    private PropertyFilter() {}
11  
12    /**
13     * Get the roles specified by a property policy and class policy.
14     * @param elementPolicy the policy on the property ({@code null} if unspecified)
15     * @param classPolicy the policy on the class ({@code null} if unspecified).
16     * @return the roles specified by the policies.
17     * @throws IllegalArgumentException if both {@code elementPolicy} and {@code classPolicy} are
18     * {@code null}.
19     */
20    public static Set<PropertyRole> getRoles(
21      PojomaticPolicy elementPolicy, DefaultPojomaticPolicy classPolicy) {
22      if (elementPolicy != null) {
23        Set<PropertyRole> roles = elementPolicy.getRoles();
24        if (roles == null) { // this will be the case for PojomaticPolicy.DEFAULT
25            return classPolicy != null ? classPolicy.getRoles() : PojomaticPolicy.ALL.getRoles();
26        }
27        else {
28          return roles;
29        }
30      }
31      else if(classPolicy != null) {
32        return classPolicy.getRoles();
33      }
34      else {
35        return Collections.emptySet();
36      }
37    }
38  }