You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by st...@apache.org on 2005/09/13 17:27:54 UTC
svn commit: r280575 -
/beehive/trunk/docs/forrest/release/src/documentation/content/xdocs/controls/programming.xml
Author: steveh
Date: Tue Sep 13 08:27:52 2005
New Revision: 280575
URL: http://svn.apache.org/viewcvs?rev=280575&view=rev
Log:
Makes the code samples in the Appendixes compilable.
Modified:
beehive/trunk/docs/forrest/release/src/documentation/content/xdocs/controls/programming.xml
Modified: beehive/trunk/docs/forrest/release/src/documentation/content/xdocs/controls/programming.xml
URL: http://svn.apache.org/viewcvs/beehive/trunk/docs/forrest/release/src/documentation/content/xdocs/controls/programming.xml?rev=280575&r1=280574&r2=280575&view=diff
==============================================================================
--- beehive/trunk/docs/forrest/release/src/documentation/content/xdocs/controls/programming.xml (original)
+++ beehive/trunk/docs/forrest/release/src/documentation/content/xdocs/controls/programming.xml Tue Sep 13 08:27:52 2005
@@ -1238,13 +1238,13 @@
* Sends a simple TextMessage to the Controlâs destination
* @param text the contents of the TextMessage
*/
- public void sendTextMessage(String text);
+ public void sendTextMessage(String text) throws javax.jms.JMSException;
/**
* Sends a simple ObjectMessage to the Controlâs destination
* @param object the object to use as the contents of the message
*/
- public void sendObjectMessage(java.io.Serializable object);
+ public void sendObjectMessage(java.io.Serializable object) throws javax.jms.JMSException;
// EVENTS
@@ -1268,15 +1268,16 @@
/**
* The Connection property defines the attributes of the connection
* and session used to enqueue the message. This annotation
- * can appear on both class and Control field declarations.
+ * can appear on both class and Control type declarations.
*/
@PropertySet
- @Target({FIELD, TYPE})
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.FIELD, ElementType.TYPE})
public @interface Connection
{
public String factoryName();
public boolean transacted() default true;
- public int acknowledgeMode() default Session.CLIENT_ACKNOWLEDGE;
+ public int acknowledgeMode() default Session.CLIENT_ACKNOWLEDGE;
}
/** An enumeration that defines the value set of destination types */
@@ -1288,10 +1289,11 @@
* be the target of any enqueued messages.
*/
@PropertySet
- @Target({FIELD, TYPE})
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target({ElementType.FIELD, ElementType.TYPE})
public @interface Destination
{
- public DestinationType type() default QUEUE;
+ public DestinationType type() default DestinationType.QUEUE;
public String name();
}
@@ -1300,7 +1302,7 @@
/**
* The set of supported message types for extended operations
*/
- public enum MessageType { TEXT, OBJECT, BYTES }
+ public enum MessageType { TEXT, OBJECT, BYTES }
/**
* The Message attribute can be placed on an
@@ -1312,10 +1314,10 @@
* parameters with the Property attribute
* defining message properties.
*/
- @Target({METHOD})
- public @interface Message
+ @Target({ElementType.METHOD})
+ public @interface Message
{
- public MessageType value() default TEXT;
+ public MessageType value() default MessageType.TEXT;
}
/**
@@ -1323,8 +1325,8 @@
* method parameter on an extended operation
* contains the message body.
*/
- @Target({PARAMETER}
- public interface Body {}
+ @Target({ElementType.PARAMETER})
+ public @interface Body {}
/**
* The Property attribute can be used to define
@@ -1333,7 +1335,7 @@
* property to set will be inferred based upon
* the type of the parameter.
*/
- @Target({PARAMETER})
+ @Target({ElementType.PARAMETER})
public @interface Property
{
public String name();
@@ -1345,8 +1347,10 @@
<title>Appendix B: The JmsMessageControl Implementation Class</title>
<source>package org.apache.beehive.controls.examples;
+import org.apache.beehive.controls.api.ControlException;
import org.apache.beehive.controls.api.bean.ControlImplementation;
import org.apache.beehive.controls.api.bean.Extensible;
+import org.apache.beehive.controls.api.context.Context;
import org.apache.beehive.controls.api.context.ControlBeanContext;
import org.apache.beehive.controls.api.context.ResourceContext;
import org.apache.beehive.controls.api.events.Client;
@@ -1354,15 +1358,20 @@
import javax.naming.InitialContext;
import javax.naming.NamingException;
-import javax.jms.QueueConnectionFactory
+import javax.jms.Queue;
+import javax.jms.QueueConnectionFactory;
import javax.jms.QueueConnection;
import javax.jms.QueueSession;
import javax.jms.QueueSender;
-import javax.jms.TopicConnectionFactory
+import javax.jms.Topic;
+import javax.jms.TopicConnectionFactory;
import javax.jms.TopicConnection;
import javax.jms.TopicSession;
import javax.jms.TopicPublisher;
import javax.jms.Message;
+import javax.jms.JMSException;
+
+import java.lang.reflect.*;
/**
* The JmsMessageControlImpl class is the
@@ -1373,7 +1382,7 @@
* message formats to be defined and associated with
* extended method signatures.
*/
-@ControlImplementation
+@ControlImplementation(isTransient=true)
public class JmsMessageControlImpl implements JmsMessageControl, Extensible
{
/**
@@ -1393,12 +1402,13 @@
*/
transient javax.jms.Connection _connection;
transient javax.jms.Session _session;
- transient javax.jms.MessageProduction _producer;
+ transient javax.jms.MessageProducer _producer;
+ transient javax.jms.Destination _dest;
/**
* The Resourceontext instance associated with the Control
*/
- @Context ResouceContext resourceContext;
+ @Context ResourceContext resourceContext;
/*
* The onAcquire event handler
@@ -1428,28 +1438,28 @@
// Obtain the JMS Destination instance based upon the Destination property
//
InitialContext jndiContext = new InitialContext();
- _dest = (javax.jms.Destination)initContext.lookup(destProp.name());
+ _dest = (javax.jms.Destination)jndiContext.lookup(destProp.name());
//
// Obtain Connection, Session, and MessageProducer resources based upon the
// destination type and the values in the Connection PropertySet
//
- if (destProp.type() = JmsControl.QUEUE)
+ if (destProp.type() == JmsMessageControl.DestinationType.QUEUE)
{
javax.jms.QueueConnectionFactory connFactory =
(QueueConnectionFactory)jndiContext.lookup(connProp.factoryName());
_connection = connFactory.createQueueConnection();
- _session = (QueueConnection)_connection).createQueueConnection(
+ _session = ((QueueConnection)_connection).createQueueSession(
connProp.transacted(),
connProp.acknowledgeMode());
- _producer = (QueueSession)_session).createSender((Queue)_dest);
+ _producer = ((QueueSession)_session).createSender((Queue)_dest);
}
else
{
javax.jms.TopicConnectionFactory connFactory =
(TopicConnectionFactory)jndiContext.lookup(connProp.factoryName());
_connection = connFactory.createTopicConnection();
- _session = ((TopicConnection)_connection).createTopicConnection(
+ _session = ((TopicConnection)_connection).createTopicSession(
connProp.transacted(),
connProp.acknowledgeMode());
_producer = ((TopicSession)_session).createPublisher((Topic)_dest);
@@ -1508,10 +1518,10 @@
/**
* Helper method used to send a message once constructed
*/
- private void sendMessage(Message msg) throws JMSException
+ private void sendMessage(javax.jms.Message msg) throws JMSException
{
client.onMessage(msg);
- if (_producer instanceof java.jms.QueueSender)
+ if (_producer instanceof javax.jms.QueueSender)
((QueueSender)_producer).send(msg);
else
((TopicPublisher)_producer).publish(msg);
@@ -1532,7 +1542,7 @@
* Sends a simple ObjectMessage to the Controlâs destination
* @param object the object to use as the contents of the message
*/
- public void sendObjectMessage(java.io.Serializable object)
+ public void sendObjectMessage(java.io.Serializable object) throws JMSException
{
javax.jms.ObjectMessage msg = _session.createObjectMessage(object);
sendMessage(msg);
@@ -1548,9 +1558,9 @@
public Object invoke(Method m, Object [] args) throws Throwable
{
int bodyIndex = -1;
- for (int i= 0; i< args.length; i++)
+ for (int i= 0; i < args.length; i++)
{
- if (context.getParametertPropertySet(m, I, JmsMessageControl.Body.class) != null)
+ if (context.getParameterPropertySet(m, i, JmsMessageControl.Body.class) != null)
{
bodyIndex = i;
break;
@@ -1566,25 +1576,26 @@
// Create a message based upon the value of the Message property of the method
//
javax.jms.Message msg = null;
- Message msgProp = context.getMethodPropertySet(m.JmsMessageControl.Message.class);
+ Message msgProp = context.getMethodPropertySet(m, JmsMessageControl.Message.class);
try
{
switch(msgProp.value())
{
- case MessageType.TEXT:
- msg = session.createTextMessage((String)args[bodyIndex]);
+ case TEXT:
+ msg = _session.createTextMessage((String)args[bodyIndex]);
break;
- case MessageType.OBJECT:
- msg = session.createObjectMessage(args[bodyIndex]);
+ case OBJECT:
+ msg = _session.createObjectMessage((java.io.Serializable)args[bodyIndex]);
break;
- case MessageType.BYTES:
- msg = session.createBytesMessage()
- msg.writeBytes((byte []) args[bodyIndex]);
+ case BYTES:
+ javax.jms.BytesMessage bmsg;
+ msg = bmsg = _session.createBytesMessage();
+ bmsg.writeBytes((byte []) args[bodyIndex]);
break;
}
}
- catch (ClassCastException)
+ catch (ClassCastException cce)
{
throw new ControlException("Invalid type for Body parameter", cce);
}
@@ -1592,27 +1603,27 @@
//
// Now decorate the message with any Property-annotated parameters
//
- for (int i= 0; i< args.length; i++)
+ for (int i= 0; i < args.length; i++)
{
- JMSMessageControl.Property prop =
- context.getParameterPropertySet(m, i,.JmsMessageControl.Property.class);
+ JmsMessageControl.Property prop =
+ context.getParameterPropertySet(m, i, JmsMessageControl.Property.class);
if (prop != null)
{
String propName = prop.name();
if (args[i] instanceof String)
- msg.setStringProperty((String)args[i]);
+ msg.setStringProperty(propName, (String)args[i]);
else if (args[i] instanceof Integer)
- msg.setStringProperty(((Integer)args[i])intValue());
+ msg.setIntProperty(propName, ((Integer)args[i]).intValue());
else if (args[i] instanceof Short)
- msg.setStringProperty(((Short)args[i]).shortValue());
+ msg.setShortProperty(propName, ((Short)args[i]).shortValue());
else if (args[i] instanceof Boolean)
- msg.setBooleanProperty(((Boolean)args[i]).booleanValue());
+ msg.setBooleanProperty(propName, ((Boolean)args[i]).booleanValue());
else if (args[i] instanceof Float)
- msg.setFloatProperty(((Float)args[i]).floatValue());
+ msg.setFloatProperty(propName, ((Float)args[i]).floatValue());
else if (args[i] instanceof Double)
- msg.setDoubleProperty(((Double)args[i]).doubleValue());
+ msg.setDoubleProperty(propName, ((Double)args[i]).doubleValue());
else
- msg.setObjectProperty(args[i]);
+ msg.setObjectProperty(propName, args[i]);
}
}
@@ -1620,6 +1631,7 @@
// Send it
//
sendMessage(msg);
+ return msg;
}
}</source>
</section>