In our example case of a document exchange gear, there are two parts to extending the GearMessage
class. The first part involves creating the DocExchMessage
class, which extends GearMessage
for the document exchange gear. The second part is creating a subclass for each message type that the document exchange gear will need to send (for example, DocumentCreatedMessage
, DocumentUpdatedMessage
, DocumentDeletedMessage
).
Extending GearMessage for the Gear
The following sample shows an example of a Java class called DocExchMessage
, which extends the atg.portal.alert.GearMessage
class for the purposes of a document exchange gear, as mentioned in Step 2 of Adding Custom Alert Messages to Gears above.
package atg.portal.gear.docexch; import atg.portal.framework.*; import atg.portal.alert.*; public class DocExchMessage extends GearMessage { //------------------------------------------- // Member variables specific to DocExch Messages //------------------------------------------- /** Document Id **/ private String mDocumentId; /** Document Name **/ private String mDocumentName; //------------------------------------- // Constructors //------------------------------------- public DocExchMessage() { } public DocExchMessage(GearEnvironment pGearEnv, String pMessageType) { super(pGearEnv, pMessageType); } //------------------------------------- // Property Accessors //------------------------------------- public String getDocumentId() { return mDocumentId; } public void setDocumentId(String pDocumentId) { mDocumentId = pDocumentId; } public String getDocumentName() { return MdocumentName; } public void setDocumentName(String pName) { mDocumentName = pName } }
Extending Gear Message for the Message Type
The following sample shows an example of a Java class called DocumentCreatedMessage
, which simply extends the DocExchMessage
class for the DocumentCreated
message type. You would create similar additional classes for any other message types (DocumentUpdated
or DocumentDeleted
, for example).
The most important point to notice in the DocumentCreatedMessage
class is that it sets the message type for the GearMessage
. Each different gear message needs a unique message type string. This string is used to identify the message in the ATG Message System configuration (see step 5 above). The message type string can be anything you choose, but to ensure that it is unique, you may wish to follow a naming scheme similar to a package naming scheme. (In the case of the sample code below, the name atg.portal.gear.docexch.DocumentCreatedMessage
happens to be the same as the package name of the class, but this is not required.)
package atg.portal.gear.docexch; import atg.portal.framework.*; public class DocumentCreatedMessage extends DocExchMessage { //------------------------------------- // Member variables //------------------------------------- static final String MESSAGE_TYPE = "atg.portal.gear.docexch.DocumentCreatedMessage"; //------------------------------------- // Constructors //------------------------------------- public DocumentCreatedMessage(GearEnvironment pGearEnv) { super(pGearEnv, MESSAGE_TYPE); } }