Class ModelBlock

java.lang.Object
org.apache.juneau.console.ModelBlock

public final class ModelBlock extends Object
The model block of one element: handler actions, lifecycle bindings and handler subscriptions.

Builders that implement Handled own one of these. Every mutator validates at once and throws IllegalArgumentException naming the element. These checks duplicate the client rules, which are the authority.

Since:
10.0.0
  • Constructor Details

    • ModelBlock

      public ModelBlock(String kind, String elementId)
      Creates a block.
      Parameters:
      kind - The element kind: page, card, table, row, rowdetail, detailtab, ribbonitem, pagetab, view or chart.
      elementId - The element id, used in messages.
      Throws:
      IllegalArgumentException - If the kind is unknown.
  • Method Details

    • action

      Adds an action.
      Parameters:
      a - The action; must have a handler.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If the kind takes no actions, the id repeats, or no handler is set.
    • on

      public ModelBlock on(String event, HandlerRef handler)
      Binds a lifecycle event.
      Parameters:
      event - A documented event of this kind.
      handler - The handler.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If the event is not documented for this kind.
    • subscribe

      public ModelBlock subscribe(String topic, HandlerRef handler)
      Subscribes a handler to a bus topic.
      Parameters:
      topic - A topic; the key may hold {rowKey}, {tabId} or {cardId} where this kind provides them.
      handler - The handler.
      Returns:
      This object.
      Throws:
      IllegalArgumentException - If the topic is invalid or a template is not available here.
    • validate

      public void validate()
      Re-checks the whole block.
      Throws:
      IllegalArgumentException - If any entry is invalid.
    • addAll

      public ModelBlock addAll(ModelBlock other)
      Appends every entry of another block to this one.
      Parameters:
      other - The block to copy from.
      Returns:
      This object.
    • isEmpty

      public boolean isEmpty()
      Returns whether the block holds nothing.
      Returns:
      true if empty.
    • hasInline

      public boolean hasInline()
      Returns whether any entry uses an inline handler.
      Returns:
      true if an inline reference is present.
    • actionMaps

      Returns the actions in insertion order.
      Returns:
      The actions, as contract maps.
    • elementId

      public String elementId()
      Returns the element id.
      Returns:
      The id.
    • kind

      public String kind()
      Returns the element kind.
      Returns:
      The kind.
    • toMap

      public Map<String,Object> toMap()
      Serializes to the contract model object.
      Returns:
      The map, or null when empty so that builders not using the model emit unchanged JSON.