The next step is to create a MessageSource implementation that fires our new message and can be triggered by setting its location property from a JSP or a JHTML page. It will use a fixed Patch Bay port named Link and a message type of test.scenario.Link. (For more information, see Patch Bay: Configuring the Dynamo Message System in the ATG Platform Programming Guide.)

package test.scenario;
import javax.jms.*;
import javax.transaction.*;
import java.io.Serializable;
import atg.dms.patchbay.MessageSource;
import atg.dms.patchbay.MessageSourceContext;
import atg.nucleus.GenericService;

/**
 * A Nucleus component used for firing LinkMessages.
 */
public
class LinkMessageSource extends GenericService implements MessageSource
{
  //-------------------------------------
  // Constants
  //-------------------------------------
  public static final String PORT_NAME = "Link";
  public static final String MESSAGE_TYPE = "test.scenario.Link";
  //-------------------------------------
  // Member Variables
  //-------------------------------------
  /** Message source context for message creation */
  MessageSourceContext mMessageSourceContext;
  /** Flag gating whether this message source is active or not. */
  boolean mSendingMessages = false;

  //-------------------------------------
  // Properties
  //-------------------------------------
  public MessageSourceContext getMessageSourceContext ()
  {
    return mMessageSourceContext;
  }

  //----------------------------------------
  // MessageSource Interface Implementation
  //----------------------------------------
  public void setMessageSourceContext (MessageSourceContext pContext)
  {
    mMessageSourceContext = pContext;
  }
  public void startMessageSource ()
  {
    mSendingMessages = true;
  }
  public void stopMessageSource ()
  {
    mSendingMessages = false;
  }
  //----------------------------------------
  // Public Methods
  //----------------------------------------
  //----------------------------------------
  /**
   * Called by Dynamo when a link of the form <A HREF="..."
   * BEAN="/test/scenario/LinkMessageSource.location" VALUE="...">>
   * is clicked.
   *
   * @param pLocation the symbolic name of the link location being
   * fired, as given in the value tag above.
   */
  public void setLocation (String pLocation)
  {
    fireLinkMessage(pLocation);
  }

  /**
   * Fires a LinkMessage reporting a clickthrough location.
   */
  public void fireLinkMessage(String pLocation)
  {
    try {
      ObjectMessage message;
      message = mMessageSourceContext.createObjectMessage(PORT_NAME);
      message.setJMSType(MESSAGE_TYPE);
      message.setObject(new LinkMessage(pLocation));
      mMessageSourceContext.sendMessage(PORT_NAME, message);
    }
    catch (JMSException jmse) {
      if (isLoggingError())
        logError(jmse);
    }
  }
}

We also need to configure the above class as a Nucleus component by creating a file named test/scenario/LinkMessageSource.properties in the localconfig directory. There are no properties to configure; just specify the component’s class:

$class=test.scenario.LinkMessageSource

Copyright © 1997, 2012 Oracle and/or its affiliates. All rights reserved. Legal Notices