public final class DynamicAdtMessageTranslator extends MessageTypeTranslatorImp implements AdtMessageTranslator
Translates between oracle.jms.AdtMessage
s and AdaptrisMessage
s and vice versa.
This translator makes use of reflection in order to map specific fields from the AdaptrisMessage object to the AdtMessage object. Prior to using this generic message translator, you will need to use the Oracle JPublisher tool to create a java class that can be used as the AdtMessage.
If you have created an abstract data type and queue within Oracle thus:
CREATE TYPE queue_message_type_clob AS OBJECT (
no NUMBER,
title VARCHAR2(30),
text CLOB
);
/
EXEC DBMS_AQADM.CREATE_QUEUE_TABLE (queue_table => 'queue_message_table', queue_payload_type => 'aqadm.queue_message_type_clob');
EXEC DBMS_AQADM.CREATE_QUEUE (queue_name => 'message_queue', queue_table => 'queue_message_table');
Then run the jpublisher tool (e.g. jpub -user=aqadm/aqadm -input=input.txt
) where input.txt simply contains
SQL QUEUE_MESSAGE_TYPE_CLOB GENERATE QueueMessageTypeClob
. This will output a number of files, the most important of
which is QueueMessageTypeClob.java which will contain something along the lines of
public class QueueMessageTypeClob implements ORAData, ORADataFactory {
public static final String _SQL_NAME = "AQADM.QUEUE_MESSAGE_TYPE_CLOB";
public static final int _SQL_TYPECODE = OracleTypes.STRUCT;
protected MutableStruct _struct;
private static int[] _sqlType =
{
2, 12, 2005
};
private static ORADataFactory[] _factory = new ORADataFactory[3];
protected static final QueueMessageTypeClob _QueueMessageTypeClobFactory = new QueueMessageTypeClob();
public static ORADataFactory getORADataFactory() {
return _QueueMessageTypeClobFactory;
}
protected void _init_struct(boolean init) {
if (init) _struct = new MutableStruct(new Object[3], _sqlType, _factory);
}
public QueueMessageTypeClob() {
_init_struct(true);
}
public QueueMessageTypeClob(java.math.BigDecimal no, String title,
oracle.sql.CLOB text) throws SQLException {
_init_struct(true);
setNo(no);
setTitle(title);
setText(text);
}
public Datum toDatum(Connection c) throws SQLException {
return _struct.toDatum(c, _SQL_NAME);
}
public ORAData create(Datum d, int sqlType) throws SQLException {
return create(null, d, sqlType);
}
protected ORAData create(QueueMessageTypeClob o, Datum d, int sqlType)
throws SQLException {
if (d == null) return null;
if (o == null) o = new QueueMessageTypeClob();
o._struct = new MutableStruct((STRUCT) d, _sqlType, _factory);
return o;
}
public java.math.BigDecimal getNo() throws SQLException {
return (java.math.BigDecimal) _struct.getAttribute(0);
}
public void setNo(java.math.BigDecimal no) throws SQLException {
_struct.setAttribute(0, no);
}
public String getTitle() throws SQLException {
return (String) _struct.getAttribute(1);
}
public void setTitle(String title) throws SQLException {
_struct.setAttribute(1, title);
}
public oracle.sql.CLOB getText() throws SQLException {
return (oracle.sql.CLOB) _struct.getOracleAttribute(2);
}
public void setText(oracle.sql.CLOB text) throws SQLException {
_struct.setOracleAttribute(2, text);
}
}
This class needs to be compiled and made available on the classpath of the adapter, the fully qualified classname becomes the field adtClassname
In the adapter configuration file this class is aliased as oracleaq-dynamic-adt-message-translator which is the preferred alternative to the fully qualified classname when building your configuration.
License Required: ENTERPRISE
helper, log, session
Constructor and Description |
---|
DynamicAdtMessageTranslator()
Default Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addFieldMapper(FieldMapper f)
Add a mapper to use.
|
java.lang.Object |
createPayloadFactory()
Create a payload factory suitable for operations such as createReceiver().
|
java.lang.String |
getAdtClassname() |
java.util.List<FieldMapper> |
getFieldMappers() |
void |
init() |
boolean |
isEnabled(License license) |
void |
setAdtClassname(java.lang.String s)
Set the classname that encapsulates that AdtMessage type.
|
void |
setFieldMappers(java.util.List<FieldMapper> s)
Set the list of mappers to use when attempting to parse a AdtMessage.
|
javax.jms.Message |
translate(AdaptrisMessage msg) |
AdaptrisMessage |
translate(javax.jms.Message msg) |
copyConfiguration, currentMessageFactory, currentSession, getMetadataConverters, getMetadataFilter, getMoveJmsHeaders, getReportAllErrors, metadataConverters, metadataFilter, moveJmsHeaders, registerMessageFactory, registerSession, reportAllErrors, setMetadataConverters, setMetadataFilter, setMoveJmsHeaders, setReportAllErrors, start, stop, translate, withMetadataConverters, withMetadataConverters, withMetadataFilter, withMoveJmsHeaders, withReportAllErrors
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
currentSession, registerSession
close, start, stop
currentMessageFactory, registerMessageFactory
public DynamicAdtMessageTranslator()
This constructor overrides some defaults from MessageTypeTranslatorImp as they have no meaning
when interacting with a AdtMessage within Oracle. Metadata is filtered using
RemoveAllMetadataFilter
and MessageTypeTranslatorImp.setMoveJmsHeaders(Boolean)
is set to false,
public java.lang.Object createPayloadFactory() throws javax.jms.JMSException
AdtMessageTranslator
createPayloadFactory
in interface AdtMessageTranslator
javax.jms.JMSException
AdtMessageTranslator.createPayloadFactory()
public javax.jms.Message translate(AdaptrisMessage msg) throws javax.jms.JMSException
translate
in interface MessageTypeTranslator
javax.jms.JMSException
MessageTypeTranslator.translate(AdaptrisMessage)
public AdaptrisMessage translate(javax.jms.Message msg) throws javax.jms.JMSException
translate
in interface MessageTypeTranslator
javax.jms.JMSException
MessageTypeTranslator.translate(Message)
public void init() throws CoreException
init
in interface ComponentLifecycle
CoreException
public boolean isEnabled(License license)
isEnabled
in interface LicensedComponent
public java.util.List<FieldMapper> getFieldMappers()
public void setFieldMappers(java.util.List<FieldMapper> s)
s
- the fieldMappers to setpublic void addFieldMapper(FieldMapper f)
f
- a Field mapper.public java.lang.String getAdtClassname()
public void setAdtClassname(java.lang.String s)
s
- the adtMessageClassname to set