com.ibm.websphere.fabric.da.plugin
Interface PolicyBasedGuard


public interface PolicyBasedGuard

Provides custom logic for determining whether a pending request should be rejected outright based on the combination of context and (selection) policy.

An Instance of this plugin is invoked by Dynamic Assembler instances that have been wired to it.

Implementations should be thread safe.

Implementations should not maintain any state other than caches of stable results. State that has impact on subsequent usages' results should be persisted using J2EE principles.

Note that any changes made to the PendingRequest object (including changes to the context included therein) will NOT be saved.

A sample implementation:
 public class Refuse implements PolicyBasedGuard {
   private static final String EXPEDITED_DELIVERY_ASSERTION_URI = ...;
   private static final String EXPEDITED_DELIVERY_PROPERTY_URI = ...;
   private static final String REQUESTOR_ZIPCODE_PROPERTY_URI = ...;
 
   public GuardResponse inspect(PendingRequest request) {
     Context context = request.getContext();
     CompositePolicy policy = request.getCompositePolicy();
     TypedValue ziptv = context.getSelectionProperty(REQUESTOR_ZIPCODE_PROPERTY_URI);
     String zipcode = ziptv.getValue();
     if (cannotShipExpedited(zipcode)) {
      if (isExpeditedRequired(policy)) {
        String msg = "Cannot ship expedited to zipcode " + zipcode;
        return GuardResponse.newPreventResponse(msg, msg);
      }
     return GuardResponse.getContinueResponse();
   }
 
   private boolean cannotShipExpedited(String zipcode) {
     ...
   }
 
   private boolean isExpeditedRequired(CompositePolicy policy) {
     for (int i = 0; i < policy.getAssertionCount(); ++i) {
       // look through the assertions
       PolicyAssertion astn = policy.getAssertionAt(i);
       if (EXPEDITED_DELIVERY_ASSERTION_URI.equals(astn.getTypeUri())) {
         // IF the assertion is what we want to look at..
         if (astn.isRequired()) {
           // AND it is a required assertion
           PropertyMap props = astn.getInstanceProperties();
           TypedValue setting = props.getProperty(EXPEDITED_DELIVERY_PROPERTY_URI);
           if (null != setting) {
             // AND the assertion requests expedited delivery, then return true.
             return "true".equals(setting.getValue());
           }
         }
       }
       // in cases where assertion is not found or not required, return false.
       return false;
   }
 }
 

Version:
$Id: $
Author:
alvinr@us.ibm.com, dilumr@us.ibm.com
See Also:
CompositePolicy, PolicyAssertion, PropertyMap, TypedValue

Method Summary
 GuardResponse inspect(PendingRequest request)
           
 

Method Detail

inspect

GuardResponse inspect(PendingRequest request)


Copyright © 2002-2009 IBM. All Rights Reserved.