public void addPolicy ( Policy policy ) throws PolicyException { // Add BlueprintPolicy if ( policy instanceof BlueprintPolicy ) { if ( erectors . get ( policy . getTarget ( ) ) == null ) { throw new PolicyException ( "Blueprint does not exist for BlueprintPolicy target: " + policy . getTarget ( ) ) ; } List < BlueprintPolicy > policies = blueprintPolicies . get ( policy . getTarget ( ) ) ; if ( policies == null ) { policies = new ArrayList < BlueprintPolicy > ( ) ; } policies . add ( ( BlueprintPolicy ) policy ) ; logger . info ( "Setting BlueprintPolicy {} for {}" , policy , policy . getTarget ( ) ) ; blueprintPolicies . put ( policy . getTarget ( ) , policies ) ; // Add FieldPolicy } else if ( policy instanceof FieldPolicy ) { // XXX: force FieldPolicy's to be mapped to a blueprint? Limits their scope, but enables validation if ( erectors . get ( policy . getTarget ( ) ) == null ) { throw new PolicyException ( "Blueprint does not exist for FieldPolicy target: " + policy . getTarget ( ) ) ; } List < FieldPolicy > policies = fieldPolicies . get ( policy . getTarget ( ) ) ; if ( policies == null ) { policies = new ArrayList < FieldPolicy > ( ) ; } policies . add ( ( FieldPolicy ) policy ) ; logger . info ( "Setting FieldPolicy {} for {}" , policy , policy . getTarget ( ) ) ; fieldPolicies . put ( policy . getTarget ( ) , policies ) ; } }
Add Policy to ModelFactory