com.microsoft.tfs.core.checkinpolicies
Class PolicyEvaluationStatus

java.lang.Object
  extended by com.microsoft.tfs.core.checkinpolicies.PolicyEvaluationStatus
All Implemented Interfaces:
com.microsoft.tfs.util.Closable

public class PolicyEvaluationStatus
extends java.lang.Object
implements com.microsoft.tfs.util.Closable

Contains status about a policy that is ready to be evaluated (or possibly already has). These objects are used exclusively by PolicyEvaluator to evaluate policies and report status.

This class is thread-safe, but caller threads must synchronize access to calls of initialize(PendingCheckin, PolicyContext), evaluate(PolicyContext), and getFailures() if they want meaningful failure information.

Since:
TEE-SDK-10.1
Thread-safety:
conditionally thread-safe

Constructor Summary
PolicyEvaluationStatus(PolicyInstance policy, int priority, java.lang.String[] scopeExpressions)
          Creates a PolicyEvaluationStatus for the given policy.
 
Method Summary
 void addPolicyStateChangedEventListener(PolicyStateChangedListener listener)
          Adds a listener of the PolicyStateChangedEvent, which is fired when the PolicyInstance in this status object changes its state.
 void close()
          Once a PolicyEvaluationStatus is closed, you cannot invoke getPolicy(), initialize(PendingCheckin, PolicyContext) or evaluate(PolicyContext) on it.
 void evaluate(PolicyContext policyContext)
          Evaluates the policy instance in this status.
 PolicyFailure[] getFailures()
           
 PolicyInstance getPolicy()
           
 PolicyType getPolicyType()
          Gets the type of policy this status is for.
 int getPriority()
           
 java.lang.String[] getScopeExpressions()
           
 void initialize(PendingCheckin pendingCheckin, PolicyContext context)
          Initializes (or re-initializes) the evaluatable policy instance.
 void removePolicyStateChangedEventListener(PolicyStateChangedListener listener)
          Removes a listener previously added via addPolicyStateChangedEventListener(PolicyStateChangedListener).
 void update(int priority, java.lang.String[] scopeExpressions, Memento configurationMemento)
          Updates this status for re-use with a new configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PolicyEvaluationStatus

public PolicyEvaluationStatus(PolicyInstance policy,
                              int priority,
                              java.lang.String[] scopeExpressions)
Creates a PolicyEvaluationStatus for the given policy. The policy is not initialized or evaluated automatically.

Parameters:
policy - the policy to wrap (must not be null)
priority - the evaluation priority of this status (lower numbers evaluate before higher numbers).
scopeExpressions - an array of strings that are regular expressions that define the scope of this policy (the server paths it affects). An empty array means all paths.
Method Detail

addPolicyStateChangedEventListener

public void addPolicyStateChangedEventListener(PolicyStateChangedListener listener)
Adds a listener of the PolicyStateChangedEvent, which is fired when the PolicyInstance in this status object changes its state.

Parameters:
listener - the listener to add (must not be null)

removePolicyStateChangedEventListener

public void removePolicyStateChangedEventListener(PolicyStateChangedListener listener)
Removes a listener previously added via addPolicyStateChangedEventListener(PolicyStateChangedListener).

Parameters:
listener - the listener to remove (must not be null)

initialize

public void initialize(PendingCheckin pendingCheckin,
                       PolicyContext context)
Initializes (or re-initializes) the evaluatable policy instance. Runtime exceptions from the policy instance's PolicyInstance.initialize(PendingCheckin, PolicyContext) method are thrown from here.

Throws:
java.lang.IllegalStateException - if close() has been called.
java.lang.Throwable - if PolicyInstance.initialize(PendingCheckin, PolicyContext) threw

evaluate

public void evaluate(PolicyContext policyContext)
              throws PolicyEvaluationCancelledException
Evaluates the policy instance in this status. Call getFailures() when this method returns to obtain any failures detected.

Parameters:
policyContext - contextual settings that may include information about the user interface, etc. (must not be null)
Throws:
PolicyEvaluationCancelledException - if the user canceled the evaluation of the policy.
java.lang.IllegalStateException - if close() has been called.

getFailures

public PolicyFailure[] getFailures()
Returns:
any failures returned by this policy, if it has been run.

getPolicyType

public PolicyType getPolicyType()
Gets the type of policy this status is for. Throws if close() has been called.

Returns:
the type of policy this status wraps.
Throws:
java.lang.IllegalStateException - if close() has been called.

close

public void close()
Once a PolicyEvaluationStatus is closed, you cannot invoke getPolicy(), initialize(PendingCheckin, PolicyContext) or evaluate(PolicyContext) on it.

Specified by:
close in interface com.microsoft.tfs.util.Closable
See Also:
Closable.close()

update

public void update(int priority,
                   java.lang.String[] scopeExpressions,
                   Memento configurationMemento)
Updates this status for re-use with a new configuration. This happens every time PolicyEvaluator reloads policies.

Parameters:
priority - the new priority.
scopeExpressions - the regular expression strings that define the server items this policy evaluates (an empty array means all paths) (must not be null)
configurationMemento - the policy definition's configuration memento.

getPolicy

public PolicyInstance getPolicy()
Returns:
the policy this status wraps.

getPriority

public int getPriority()
Returns:
the numeric priority by which this policy is evaluated (lower numbers evaluate before higher numbers).

getScopeExpressions

public java.lang.String[] getScopeExpressions()
Returns:
the regular expression strings that define the server items this policy evaluates (an empty array means all paths).


© 2015 Microsoft. All rights reserved.