package examples.workspace.monitor;

import weblogic.common.*;

/**
 * This code example shows how a Workspace Monitor can be used to
 * alter/encode a Workspace value when set. For example, you might
 * use a class like this to compress or encrypt Workspace values.
 * <p>
 *<h3>To set up this example:</h3>
 *<ol>
 *<li>Set up your development shell as described in <a
 *href=../../../techstart/environment.html>Setting up your environment</a>.
 *<p>
 *<li>Compile this example by executing the following command in your development shell:
 *
 *<p>
 *<font face="Courier New"><b>$ javac -d %SERVER_CLASSES% XXXMonitor.java</b></font>
 *<p>
 *
 *<p>	
 *
 *<p>
 *<li>You do not execute this example directly; it is called by the
 *<font face="Courier New" size=-1>MonitorDemo</font> class. You must
 *compile all the other examples in this package before running <font face="Courier New" size=-1><a href=examples.workspace.monitor.MonitorDemo.html>MonitorDemo</a></font>.
 *
 *</ol>
 *
 * @author                    Copyright (c) 1997-2000 by BEA Systems, Inc.
 *                            All Rights Reserved.
 */
public class XXXMonitor implements SetMonitor {
  
  boolean isMaster;
  
  /**
   * Initializes a monitor. This allows passing of initialization
   * parameters even when the object is instantiated remotely on
   * the WebLogic Server with a default constructor (which cannot
   * have arguments).
   *
   * @param params            ParamSet of initialization values
   * @param isMaster          true if this is a Master Monitor
   * @exception               weblogic.common.ParamSetException
   *                          if the Monitor cannot be initialized or
   *                          there is a problem with the ParamSet
   */
  public void monitorInit(ParamSet params, boolean isMaster) {
    this.isMaster = isMaster;
  }
  
  /**
   * Sets the services stub for this class. It allows you to write a class that
   * can be instantiated by a client or a WebLogic Server -- how this class
   * accesses WebLogic services is determined by the services stub, which is
   * set at runtime.
   */
  public void setServices(T3ServicesDef services) { }

  /**
   * Implement this method to carry out some arbitrary operations before
   * the target object's <tt>set()</tt> method is called. The target
   * object must implement the <tt>weblogic.common.Setable</tt> interface.
   * In this example, we illustrate how a Master Monitor can alter the
   * state of a target object; here we set a new value in the target
   * object to "XXX". A regular Monitor cannot alter a target's state; this
   * operation will fail if not invoked by a Master Monitor.
   *
   * @param target            Object to be set
   * @param callbackData      ParamSet of potential data for callback
   * @exception               weblogic.common.MonitorException if a
   *                          Monitor vetoes the operation
   */
  public void preSet(Setable target, ParamSet callbackData) throws MonitorException {
    if (isMaster) {
      target.newValue("XXX");
    }
  }
  
  /**
   * Implement this method to carry out some arbitrary operations after
   * the target object's <tt>set()</tt> method is called. The target
   * object must implement the <tt>weblogic.common.Setable</tt> interface.
   *
   * @param target            Object to be set
   * @param callbackData      ParamSet of potential data for callback
   * @param e                 Exception to be thrown if the monitor is vetoed
   *                          or does not complete
   */
  public void postSet(Setable target, ParamSet callbackData, Exception e) { }
  
}
