Package com.singularsys.jep.misc.publishingvariable

# Class PublishingVariableFactory

java.lang.Object
com.singularsys.jep.VariableFactory
com.singularsys.jep.misc.publishingvariable.PublishingVariableFactory

All Implemented Interfaces:
  `JepComponent`, `Serializable`

public class PublishingVariableFactory extends VariableFactory
A factory for creating `PublishingVariable`s. Each variable created by this factory will use the same `SubmissionPublisher` to publish changes to its value, so by default all changes to variables will be reported by the same publisher.

If you only want to monitor some variables, set the publisher to null in the `PublishingVariableFactory(SubmissionPublisher)` constructor and set the individual variables publisher using the `PublishingVariable.setPublisher(SubmissionPublisher)` method.

The publisher can be shared with a `PublishingVariableTable` to also report changes to the table, such as adding and removing variables.

Since:
  Jep 4.1
See Also:
  - Serialized Form

- ## Field Summary

  ### Fields inherited from class com.singularsys.jep.VariableFactory

  `defaultValue`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PublishingVariableFactory(SubmissionPublisher<VariableTableAction> pub)`
  Constructor with a specified of SubmissionPublishers.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Variable`
  `createVariable(String name)`
  Create a variable with a name but not value Calls `VariableFactory.createVariable(String, Object)` so subclasses need not override this method.
  `Variable`
  `createVariable(String name, Object value)`
  Create a variable with a name and value.
  `JepComponent`
  `getLightWeightInstance()`
  Create a light weight instance of this factory.
  `SubmissionPublisher<VariableTableAction>`
  `getPublisher()`
  Get the current publisher for the variables created by this factory.
  `void`
  `init(Jep j)`
  Initialize the component.
  `void`
  `setPublisher(SubmissionPublisher<VariableTableAction> publisher)`
  Set the publisher for the variables created by this factory.

  ### Methods inherited from class com.singularsys.jep.VariableFactory

  `copyVariable, getDefaultValue, setDefaultValue`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### PublishingVariableFactory

    public PublishingVariableFactory(SubmissionPublisher<VariableTableAction> pub)
    Constructor with a specified of SubmissionPublishers.

    If the publisher is null, then the variables created by this factory will not, by default publish any changes, however, the publisher can be set later using the `PublishingVariable.setPublisher(SubmissionPublisher)`.

    Parameters:
      `pub` - the SubmissionPublishers, this can be null

- ## Method Details

  - ### init

    public void init(Jep j)
    Description copied from interface: `JepComponent`
    Initialize the component. This method is called whenever a component is added to Jep. Hence, it allows components to keep track of the other components they may rely on.
    Specified by:
      `init` in interface `JepComponent`
    Overrides:
      `init` in class `VariableFactory`
    Parameters:
      `j` - the current Jep instance

  - ### createVariable

    public Variable createVariable(String name, Object value)
    Description copied from class: `VariableFactory`
    Create a variable with a name and value. Subclasses should overwrite this method to return variables of the correct type
    Overrides:
      `createVariable` in class `VariableFactory`
    Parameters:
      `name` - name of variable
      `value` - initial value
    Returns:
      reference to Variable object

  - ### createVariable

    public Variable createVariable(String name)
    Description copied from class: `VariableFactory`
    Create a variable with a name but not value Calls `VariableFactory.createVariable(String, Object)` so subclasses need not override this method.
    Overrides:
      `createVariable` in class `VariableFactory`
    Parameters:
      `name` - name of variable
    Returns:
      reference to Variable object

  - ### getLightWeightInstance

    public JepComponent getLightWeightInstance()
    Create a light weight instance of this factory. This creates a new instance of this factory with a null publisher. The publisher can then be set by calling `setPublisher(SubmissionPublisher)` on the new instance.
    Specified by:
      `getLightWeightInstance` in interface `JepComponent`
    Overrides:
      `getLightWeightInstance` in class `VariableFactory`
    Returns:
      a new PublishingVariableFactory with a null publisher.

  - ### getPublisher

    public SubmissionPublisher<VariableTableAction> getPublisher()
    Get the current publisher for the variables created by this factory.
    Returns:
      the publisher

  - ### setPublisher

    public void setPublisher(SubmissionPublisher<VariableTableAction> publisher)
    Set the publisher for the variables created by this factory. Any variables created by this factory after setting the publisher will use the new publisher to publish changes to their value.
    Parameters:
      `publisher` - the publisher to set