mirror of https://github.com/apache/activemq.git
In an attempt to make the openwire generator easier to maintain and use from the now seperate activemq-cpp and
activemq-dotnet modules, I converted the groovy scripts to plain java and you can now execute them with just plain Ant. git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@450289 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
32f0612059
commit
bd0ad6860a
|
@ -287,7 +287,25 @@
|
|||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<configuration>
|
||||
<tasks>
|
||||
<taskdef name="generate" classname="org.apache.activemq.openwire.tool.JavaGenerator"/>
|
||||
<generate version="2" basedir="${basedir}"/>
|
||||
</tasks>
|
||||
</configuration>
|
||||
<dependency>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>activemq-openwire-generator</artifactId>
|
||||
<version>${pom.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
|
||||
<!-- Use Gram to Gernerate the OpenWire Marshallers -->
|
||||
<!--
|
||||
<plugin>
|
||||
<groupId>org.apache.activemq</groupId>
|
||||
<artifactId>maven-gram-plugin</artifactId>
|
||||
|
@ -310,6 +328,7 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
-->
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
|
|
|
@ -40,67 +40,67 @@ public class MarshallerFactory {
|
|||
static final private DataStreamMarshaller marshaller[] = new DataStreamMarshaller[256];
|
||||
static {
|
||||
|
||||
add(new LocalTransactionIdMarshaller());
|
||||
add(new PartialCommandMarshaller());
|
||||
add(new IntegerResponseMarshaller());
|
||||
add(new ActiveMQQueueMarshaller());
|
||||
add(new ActiveMQObjectMessageMarshaller());
|
||||
add(new ConnectionIdMarshaller());
|
||||
add(new ConnectionInfoMarshaller());
|
||||
add(new ProducerInfoMarshaller());
|
||||
add(new MessageDispatchNotificationMarshaller());
|
||||
add(new SessionInfoMarshaller());
|
||||
add(new TransactionInfoMarshaller());
|
||||
add(new ActiveMQStreamMessageMarshaller());
|
||||
add(new MessageAckMarshaller());
|
||||
add(new ProducerIdMarshaller());
|
||||
add(new MessageIdMarshaller());
|
||||
add(new ActiveMQTempQueueMarshaller());
|
||||
add(new RemoveSubscriptionInfoMarshaller());
|
||||
add(new SessionIdMarshaller());
|
||||
add(new DataArrayResponseMarshaller());
|
||||
add(new JournalQueueAckMarshaller());
|
||||
add(new ResponseMarshaller());
|
||||
add(new ConnectionErrorMarshaller());
|
||||
add(new ConsumerInfoMarshaller());
|
||||
add(new XATransactionIdMarshaller());
|
||||
add(new JournalTraceMarshaller());
|
||||
add(new ConsumerIdMarshaller());
|
||||
add(new ActiveMQTextMessageMarshaller());
|
||||
add(new SubscriptionInfoMarshaller());
|
||||
add(new JournalTransactionMarshaller());
|
||||
add(new ControlCommandMarshaller());
|
||||
add(new LastPartialCommandMarshaller());
|
||||
add(new NetworkBridgeFilterMarshaller());
|
||||
add(new MessagePullMarshaller());
|
||||
add(new ActiveMQBytesMessageMarshaller());
|
||||
add(new WireFormatInfoMarshaller());
|
||||
add(new ActiveMQTempTopicMarshaller());
|
||||
add(new DiscoveryEventMarshaller());
|
||||
add(new ReplayCommandMarshaller());
|
||||
add(new ActiveMQTopicMarshaller());
|
||||
add(new BrokerInfoMarshaller());
|
||||
add(new DestinationInfoMarshaller());
|
||||
add(new ShutdownInfoMarshaller());
|
||||
add(new DataResponseMarshaller());
|
||||
add(new ConnectionControlMarshaller());
|
||||
add(new KeepAliveInfoMarshaller());
|
||||
add(new FlushCommandMarshaller());
|
||||
add(new ConsumerControlMarshaller());
|
||||
add(new JournalTopicAckMarshaller());
|
||||
add(new BrokerIdMarshaller());
|
||||
add(new MessageDispatchMarshaller());
|
||||
add(new ActiveMQMapMessageMarshaller());
|
||||
add(new ActiveMQMessageMarshaller());
|
||||
add(new RemoveInfoMarshaller());
|
||||
add(new ActiveMQObjectMessageMarshaller());
|
||||
add(new ActiveMQQueueMarshaller());
|
||||
add(new ActiveMQStreamMessageMarshaller());
|
||||
add(new ActiveMQTempQueueMarshaller());
|
||||
add(new ActiveMQTempTopicMarshaller());
|
||||
add(new ActiveMQTextMessageMarshaller());
|
||||
add(new ActiveMQTopicMarshaller());
|
||||
add(new BrokerIdMarshaller());
|
||||
add(new BrokerInfoMarshaller());
|
||||
add(new ConnectionControlMarshaller());
|
||||
add(new ConnectionErrorMarshaller());
|
||||
add(new ConnectionIdMarshaller());
|
||||
add(new ConnectionInfoMarshaller());
|
||||
add(new ConsumerControlMarshaller());
|
||||
add(new ConsumerIdMarshaller());
|
||||
add(new ConsumerInfoMarshaller());
|
||||
add(new ControlCommandMarshaller());
|
||||
add(new DataArrayResponseMarshaller());
|
||||
add(new DataResponseMarshaller());
|
||||
add(new DestinationInfoMarshaller());
|
||||
add(new DiscoveryEventMarshaller());
|
||||
add(new ExceptionResponseMarshaller());
|
||||
add(new FlushCommandMarshaller());
|
||||
add(new IntegerResponseMarshaller());
|
||||
add(new JournalQueueAckMarshaller());
|
||||
add(new JournalTopicAckMarshaller());
|
||||
add(new JournalTraceMarshaller());
|
||||
add(new JournalTransactionMarshaller());
|
||||
add(new KeepAliveInfoMarshaller());
|
||||
add(new LastPartialCommandMarshaller());
|
||||
add(new LocalTransactionIdMarshaller());
|
||||
add(new MessageAckMarshaller());
|
||||
add(new MessageDispatchMarshaller());
|
||||
add(new MessageDispatchNotificationMarshaller());
|
||||
add(new MessageIdMarshaller());
|
||||
add(new MessagePullMarshaller());
|
||||
add(new NetworkBridgeFilterMarshaller());
|
||||
add(new PartialCommandMarshaller());
|
||||
add(new ProducerIdMarshaller());
|
||||
add(new ProducerInfoMarshaller());
|
||||
add(new RemoveInfoMarshaller());
|
||||
add(new RemoveSubscriptionInfoMarshaller());
|
||||
add(new ReplayCommandMarshaller());
|
||||
add(new ResponseMarshaller());
|
||||
add(new SessionIdMarshaller());
|
||||
add(new SessionInfoMarshaller());
|
||||
add(new ShutdownInfoMarshaller());
|
||||
add(new SubscriptionInfoMarshaller());
|
||||
add(new TransactionInfoMarshaller());
|
||||
add(new WireFormatInfoMarshaller());
|
||||
add(new XATransactionIdMarshaller());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static private void add(DataStreamMarshaller dsm) {
|
||||
static private void add(DataStreamMarshaller dsm) {
|
||||
marshaller[dsm.getDataStructureType()] = dsm;
|
||||
}
|
||||
|
||||
|
||||
static public DataStreamMarshaller[] createMarshallerMap(OpenWireFormat wireFormat) {
|
||||
return marshaller;
|
||||
}
|
||||
|
|
|
@ -42,16 +42,15 @@ public class BrokerIdTest extends DataFileGeneratorTestSupport {
|
|||
public static BrokerIdTest SINGLETON = new BrokerIdTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
BrokerId info = new BrokerId();
|
||||
populateObject(info);
|
||||
return info;
|
||||
BrokerId info = new BrokerId();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
BrokerId info = (BrokerId) object;
|
||||
info.setValue("Value:1");
|
||||
super.populateObject(object);
|
||||
BrokerId info = (BrokerId) object;
|
||||
|
||||
}
|
||||
}
|
||||
info.setValue("Value:1");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,29 +42,27 @@ public class BrokerInfoTest extends BaseCommandTestSupport {
|
|||
public static BrokerInfoTest SINGLETON = new BrokerInfoTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
BrokerInfo info = new BrokerInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
BrokerInfo info = new BrokerInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
BrokerInfo info = (BrokerInfo) object;
|
||||
super.populateObject(object);
|
||||
BrokerInfo info = (BrokerInfo) object;
|
||||
|
||||
info.setBrokerId(createBrokerId("BrokerId:1"));
|
||||
info.setBrokerURL("BrokerURL:2");
|
||||
|
||||
{
|
||||
BrokerInfo value[] = new BrokerInfo[0];
|
||||
for( int i=0; i < 0; i++ ) {
|
||||
value[i] = createBrokerInfo("PeerBrokerInfos:3");
|
||||
}
|
||||
info.setPeerBrokerInfos(value);
|
||||
{
|
||||
BrokerInfo value[] = new BrokerInfo[0];
|
||||
for( int i=0; i < 0; i++ ) {
|
||||
value[i] = createBrokerInfo("PeerBrokerInfos:3");
|
||||
}
|
||||
info.setPeerBrokerInfos(value);
|
||||
}
|
||||
info.setBrokerName("BrokerName:4");
|
||||
info.setSlaveBroker(true);
|
||||
info.setMasterBroker(false);
|
||||
info.setFaultTolerantConfiguration(true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,20 +42,19 @@ public class ConnectionControlTest extends BaseCommandTestSupport {
|
|||
public static ConnectionControlTest SINGLETON = new ConnectionControlTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
ConnectionControl info = new ConnectionControl();
|
||||
populateObject(info);
|
||||
return info;
|
||||
ConnectionControl info = new ConnectionControl();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
ConnectionControl info = (ConnectionControl) object;
|
||||
super.populateObject(object);
|
||||
ConnectionControl info = (ConnectionControl) object;
|
||||
|
||||
info.setClose(true);
|
||||
info.setExit(false);
|
||||
info.setFaultTolerant(true);
|
||||
info.setResume(false);
|
||||
info.setSuspend(true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,17 +42,16 @@ public class ConnectionErrorTest extends BaseCommandTestSupport {
|
|||
public static ConnectionErrorTest SINGLETON = new ConnectionErrorTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
ConnectionError info = new ConnectionError();
|
||||
populateObject(info);
|
||||
return info;
|
||||
ConnectionError info = new ConnectionError();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
ConnectionError info = (ConnectionError) object;
|
||||
super.populateObject(object);
|
||||
ConnectionError info = (ConnectionError) object;
|
||||
|
||||
info.setException(createThrowable("Exception:1"));
|
||||
info.setConnectionId(createConnectionId("ConnectionId:2"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,16 +42,15 @@ public class ConnectionIdTest extends DataFileGeneratorTestSupport {
|
|||
public static ConnectionIdTest SINGLETON = new ConnectionIdTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
ConnectionId info = new ConnectionId();
|
||||
populateObject(info);
|
||||
return info;
|
||||
ConnectionId info = new ConnectionId();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
ConnectionId info = (ConnectionId) object;
|
||||
info.setValue("Value:1");
|
||||
super.populateObject(object);
|
||||
ConnectionId info = (ConnectionId) object;
|
||||
|
||||
}
|
||||
}
|
||||
info.setValue("Value:1");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,29 +42,27 @@ public class ConnectionInfoTest extends BaseCommandTestSupport {
|
|||
public static ConnectionInfoTest SINGLETON = new ConnectionInfoTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
ConnectionInfo info = new ConnectionInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
ConnectionInfo info = new ConnectionInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
ConnectionInfo info = (ConnectionInfo) object;
|
||||
super.populateObject(object);
|
||||
ConnectionInfo info = (ConnectionInfo) object;
|
||||
|
||||
info.setConnectionId(createConnectionId("ConnectionId:1"));
|
||||
info.setClientId("ClientId:2");
|
||||
info.setPassword("Password:3");
|
||||
info.setUserName("UserName:4");
|
||||
|
||||
{
|
||||
BrokerId value[] = new BrokerId[2];
|
||||
for( int i=0; i < 2; i++ ) {
|
||||
value[i] = createBrokerId("BrokerPath:5");
|
||||
}
|
||||
info.setBrokerPath(value);
|
||||
{
|
||||
BrokerId value[] = new BrokerId[2];
|
||||
for( int i=0; i < 2; i++ ) {
|
||||
value[i] = createBrokerId("BrokerPath:5");
|
||||
}
|
||||
info.setBrokerPath(value);
|
||||
}
|
||||
info.setBrokerMasterConnector(true);
|
||||
info.setManageable(false);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,18 +42,17 @@ public class ConsumerControlTest extends BaseCommandTestSupport {
|
|||
public static ConsumerControlTest SINGLETON = new ConsumerControlTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
ConsumerControl info = new ConsumerControl();
|
||||
populateObject(info);
|
||||
return info;
|
||||
ConsumerControl info = new ConsumerControl();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
ConsumerControl info = (ConsumerControl) object;
|
||||
super.populateObject(object);
|
||||
ConsumerControl info = (ConsumerControl) object;
|
||||
|
||||
info.setClose(true);
|
||||
info.setConsumerId(createConsumerId("ConsumerId:1"));
|
||||
info.setPrefetch(1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,18 +42,17 @@ public class ConsumerIdTest extends DataFileGeneratorTestSupport {
|
|||
public static ConsumerIdTest SINGLETON = new ConsumerIdTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
ConsumerId info = new ConsumerId();
|
||||
populateObject(info);
|
||||
return info;
|
||||
ConsumerId info = new ConsumerId();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
ConsumerId info = (ConsumerId) object;
|
||||
super.populateObject(object);
|
||||
ConsumerId info = (ConsumerId) object;
|
||||
|
||||
info.setConnectionId("ConnectionId:1");
|
||||
info.setSessionId(1);
|
||||
info.setValue(2);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,15 +42,15 @@ public class ConsumerInfoTest extends BaseCommandTestSupport {
|
|||
public static ConsumerInfoTest SINGLETON = new ConsumerInfoTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
ConsumerInfo info = new ConsumerInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
ConsumerInfo info = new ConsumerInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
ConsumerInfo info = (ConsumerInfo) object;
|
||||
super.populateObject(object);
|
||||
ConsumerInfo info = (ConsumerInfo) object;
|
||||
|
||||
info.setConsumerId(createConsumerId("ConsumerId:1"));
|
||||
info.setBrowser(true);
|
||||
info.setDestination(createActiveMQDestination("Destination:2"));
|
||||
|
@ -63,18 +63,16 @@ public class ConsumerInfoTest extends BaseCommandTestSupport {
|
|||
info.setExclusive(false);
|
||||
info.setRetroactive(true);
|
||||
info.setPriority((byte) 1);
|
||||
|
||||
{
|
||||
BrokerId value[] = new BrokerId[2];
|
||||
for( int i=0; i < 2; i++ ) {
|
||||
value[i] = createBrokerId("BrokerPath:5");
|
||||
}
|
||||
info.setBrokerPath(value);
|
||||
{
|
||||
BrokerId value[] = new BrokerId[2];
|
||||
for( int i=0; i < 2; i++ ) {
|
||||
value[i] = createBrokerId("BrokerPath:5");
|
||||
}
|
||||
info.setBrokerPath(value);
|
||||
}
|
||||
info.setAdditionalPredicate(createBooleanExpression("AdditionalPredicate:6"));
|
||||
info.setNetworkSubscription(false);
|
||||
info.setOptimizedAcknowledge(true);
|
||||
info.setNoRangeAcks(false);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,16 +42,15 @@ public class ControlCommandTest extends BaseCommandTestSupport {
|
|||
public static ControlCommandTest SINGLETON = new ControlCommandTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
ControlCommand info = new ControlCommand();
|
||||
populateObject(info);
|
||||
return info;
|
||||
ControlCommand info = new ControlCommand();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
ControlCommand info = (ControlCommand) object;
|
||||
info.setCommand("Command:1");
|
||||
super.populateObject(object);
|
||||
ControlCommand info = (ControlCommand) object;
|
||||
|
||||
}
|
||||
}
|
||||
info.setCommand("Command:1");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,23 +42,21 @@ public class DataArrayResponseTest extends ResponseTest {
|
|||
public static DataArrayResponseTest SINGLETON = new DataArrayResponseTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
DataArrayResponse info = new DataArrayResponse();
|
||||
populateObject(info);
|
||||
return info;
|
||||
DataArrayResponse info = new DataArrayResponse();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
DataArrayResponse info = (DataArrayResponse) object;
|
||||
|
||||
{
|
||||
DataStructure value[] = new DataStructure[2];
|
||||
for( int i=0; i < 2; i++ ) {
|
||||
value[i] = createDataStructure("Data:1");
|
||||
}
|
||||
info.setData(value);
|
||||
}
|
||||
super.populateObject(object);
|
||||
DataArrayResponse info = (DataArrayResponse) object;
|
||||
|
||||
{
|
||||
DataStructure value[] = new DataStructure[2];
|
||||
for( int i=0; i < 2; i++ ) {
|
||||
value[i] = createDataStructure("Data:1");
|
||||
}
|
||||
info.setData(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,16 +42,15 @@ public class DataResponseTest extends ResponseTest {
|
|||
public static DataResponseTest SINGLETON = new DataResponseTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
DataResponse info = new DataResponse();
|
||||
populateObject(info);
|
||||
return info;
|
||||
DataResponse info = new DataResponse();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
DataResponse info = (DataResponse) object;
|
||||
info.setData(createDataStructure("Data:1"));
|
||||
super.populateObject(object);
|
||||
DataResponse info = (DataResponse) object;
|
||||
|
||||
}
|
||||
}
|
||||
info.setData(createDataStructure("Data:1"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,27 +42,25 @@ public class DestinationInfoTest extends BaseCommandTestSupport {
|
|||
public static DestinationInfoTest SINGLETON = new DestinationInfoTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
DestinationInfo info = new DestinationInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
DestinationInfo info = new DestinationInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
DestinationInfo info = (DestinationInfo) object;
|
||||
super.populateObject(object);
|
||||
DestinationInfo info = (DestinationInfo) object;
|
||||
|
||||
info.setConnectionId(createConnectionId("ConnectionId:1"));
|
||||
info.setDestination(createActiveMQDestination("Destination:2"));
|
||||
info.setOperationType((byte) 1);
|
||||
info.setTimeout(1);
|
||||
|
||||
{
|
||||
BrokerId value[] = new BrokerId[2];
|
||||
for( int i=0; i < 2; i++ ) {
|
||||
value[i] = createBrokerId("BrokerPath:3");
|
||||
}
|
||||
info.setBrokerPath(value);
|
||||
}
|
||||
|
||||
{
|
||||
BrokerId value[] = new BrokerId[2];
|
||||
for( int i=0; i < 2; i++ ) {
|
||||
value[i] = createBrokerId("BrokerPath:3");
|
||||
}
|
||||
info.setBrokerPath(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,17 +42,16 @@ public class DiscoveryEventTest extends DataFileGeneratorTestSupport {
|
|||
public static DiscoveryEventTest SINGLETON = new DiscoveryEventTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
DiscoveryEvent info = new DiscoveryEvent();
|
||||
populateObject(info);
|
||||
return info;
|
||||
DiscoveryEvent info = new DiscoveryEvent();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
DiscoveryEvent info = (DiscoveryEvent) object;
|
||||
super.populateObject(object);
|
||||
DiscoveryEvent info = (DiscoveryEvent) object;
|
||||
|
||||
info.setServiceName("ServiceName:1");
|
||||
info.setBrokerName("BrokerName:2");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,16 +42,15 @@ public class ExceptionResponseTest extends ResponseTest {
|
|||
public static ExceptionResponseTest SINGLETON = new ExceptionResponseTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
ExceptionResponse info = new ExceptionResponse();
|
||||
populateObject(info);
|
||||
return info;
|
||||
ExceptionResponse info = new ExceptionResponse();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
ExceptionResponse info = (ExceptionResponse) object;
|
||||
info.setException(createThrowable("Exception:1"));
|
||||
super.populateObject(object);
|
||||
ExceptionResponse info = (ExceptionResponse) object;
|
||||
|
||||
}
|
||||
}
|
||||
info.setException(createThrowable("Exception:1"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,15 +42,14 @@ public class FlushCommandTest extends BaseCommandTestSupport {
|
|||
public static FlushCommandTest SINGLETON = new FlushCommandTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
FlushCommand info = new FlushCommand();
|
||||
populateObject(info);
|
||||
return info;
|
||||
FlushCommand info = new FlushCommand();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
FlushCommand info = (FlushCommand) object;
|
||||
super.populateObject(object);
|
||||
FlushCommand info = (FlushCommand) object;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,16 +42,15 @@ public class IntegerResponseTest extends ResponseTest {
|
|||
public static IntegerResponseTest SINGLETON = new IntegerResponseTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
IntegerResponse info = new IntegerResponse();
|
||||
populateObject(info);
|
||||
return info;
|
||||
IntegerResponse info = new IntegerResponse();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
IntegerResponse info = (IntegerResponse) object;
|
||||
info.setResult(1);
|
||||
super.populateObject(object);
|
||||
IntegerResponse info = (IntegerResponse) object;
|
||||
|
||||
}
|
||||
}
|
||||
info.setResult(1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,17 +42,16 @@ public class JournalQueueAckTest extends DataFileGeneratorTestSupport {
|
|||
public static JournalQueueAckTest SINGLETON = new JournalQueueAckTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
JournalQueueAck info = new JournalQueueAck();
|
||||
populateObject(info);
|
||||
return info;
|
||||
JournalQueueAck info = new JournalQueueAck();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
JournalQueueAck info = (JournalQueueAck) object;
|
||||
super.populateObject(object);
|
||||
JournalQueueAck info = (JournalQueueAck) object;
|
||||
|
||||
info.setDestination(createActiveMQDestination("Destination:1"));
|
||||
info.setMessageAck(createMessageAck("MessageAck:2"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,21 +42,20 @@ public class JournalTopicAckTest extends DataFileGeneratorTestSupport {
|
|||
public static JournalTopicAckTest SINGLETON = new JournalTopicAckTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
JournalTopicAck info = new JournalTopicAck();
|
||||
populateObject(info);
|
||||
return info;
|
||||
JournalTopicAck info = new JournalTopicAck();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
JournalTopicAck info = (JournalTopicAck) object;
|
||||
super.populateObject(object);
|
||||
JournalTopicAck info = (JournalTopicAck) object;
|
||||
|
||||
info.setDestination(createActiveMQDestination("Destination:1"));
|
||||
info.setMessageId(createMessageId("MessageId:2"));
|
||||
info.setMessageSequenceId(1);
|
||||
info.setSubscritionName("SubscritionName:3");
|
||||
info.setClientId("ClientId:4");
|
||||
info.setTransactionId(createTransactionId("TransactionId:5"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,16 +42,15 @@ public class JournalTraceTest extends DataFileGeneratorTestSupport {
|
|||
public static JournalTraceTest SINGLETON = new JournalTraceTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
JournalTrace info = new JournalTrace();
|
||||
populateObject(info);
|
||||
return info;
|
||||
JournalTrace info = new JournalTrace();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
JournalTrace info = (JournalTrace) object;
|
||||
info.setMessage("Message:1");
|
||||
super.populateObject(object);
|
||||
JournalTrace info = (JournalTrace) object;
|
||||
|
||||
}
|
||||
}
|
||||
info.setMessage("Message:1");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,18 +42,17 @@ public class JournalTransactionTest extends DataFileGeneratorTestSupport {
|
|||
public static JournalTransactionTest SINGLETON = new JournalTransactionTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
JournalTransaction info = new JournalTransaction();
|
||||
populateObject(info);
|
||||
return info;
|
||||
JournalTransaction info = new JournalTransaction();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
JournalTransaction info = (JournalTransaction) object;
|
||||
super.populateObject(object);
|
||||
JournalTransaction info = (JournalTransaction) object;
|
||||
|
||||
info.setTransactionId(createTransactionId("TransactionId:1"));
|
||||
info.setType((byte) 1);
|
||||
info.setWasPrepared(true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,15 +42,14 @@ public class KeepAliveInfoTest extends BaseCommandTestSupport {
|
|||
public static KeepAliveInfoTest SINGLETON = new KeepAliveInfoTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
KeepAliveInfo info = new KeepAliveInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
KeepAliveInfo info = new KeepAliveInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
KeepAliveInfo info = (KeepAliveInfo) object;
|
||||
super.populateObject(object);
|
||||
KeepAliveInfo info = (KeepAliveInfo) object;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,15 +42,14 @@ public class LastPartialCommandTest extends PartialCommandTest {
|
|||
public static LastPartialCommandTest SINGLETON = new LastPartialCommandTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
LastPartialCommand info = new LastPartialCommand();
|
||||
populateObject(info);
|
||||
return info;
|
||||
LastPartialCommand info = new LastPartialCommand();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
LastPartialCommand info = (LastPartialCommand) object;
|
||||
super.populateObject(object);
|
||||
LastPartialCommand info = (LastPartialCommand) object;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,17 +42,16 @@ public class LocalTransactionIdTest extends TransactionIdTestSupport {
|
|||
public static LocalTransactionIdTest SINGLETON = new LocalTransactionIdTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
LocalTransactionId info = new LocalTransactionId();
|
||||
populateObject(info);
|
||||
return info;
|
||||
LocalTransactionId info = new LocalTransactionId();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
LocalTransactionId info = (LocalTransactionId) object;
|
||||
super.populateObject(object);
|
||||
LocalTransactionId info = (LocalTransactionId) object;
|
||||
|
||||
info.setValue(1);
|
||||
info.setConnectionId(createConnectionId("ConnectionId:1"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,15 +42,15 @@ public class MessageAckTest extends BaseCommandTestSupport {
|
|||
public static MessageAckTest SINGLETON = new MessageAckTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
MessageAck info = new MessageAck();
|
||||
populateObject(info);
|
||||
return info;
|
||||
MessageAck info = new MessageAck();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
MessageAck info = (MessageAck) object;
|
||||
super.populateObject(object);
|
||||
MessageAck info = (MessageAck) object;
|
||||
|
||||
info.setDestination(createActiveMQDestination("Destination:1"));
|
||||
info.setTransactionId(createTransactionId("TransactionId:2"));
|
||||
info.setConsumerId(createConsumerId("ConsumerId:3"));
|
||||
|
@ -58,6 +58,5 @@ public class MessageAckTest extends BaseCommandTestSupport {
|
|||
info.setFirstMessageId(createMessageId("FirstMessageId:4"));
|
||||
info.setLastMessageId(createMessageId("LastMessageId:5"));
|
||||
info.setMessageCount(1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,19 +42,18 @@ public class MessageDispatchNotificationTest extends BaseCommandTestSupport {
|
|||
public static MessageDispatchNotificationTest SINGLETON = new MessageDispatchNotificationTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
MessageDispatchNotification info = new MessageDispatchNotification();
|
||||
populateObject(info);
|
||||
return info;
|
||||
MessageDispatchNotification info = new MessageDispatchNotification();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
MessageDispatchNotification info = (MessageDispatchNotification) object;
|
||||
super.populateObject(object);
|
||||
MessageDispatchNotification info = (MessageDispatchNotification) object;
|
||||
|
||||
info.setConsumerId(createConsumerId("ConsumerId:1"));
|
||||
info.setDestination(createActiveMQDestination("Destination:2"));
|
||||
info.setDeliverySequenceId(1);
|
||||
info.setMessageId(createMessageId("MessageId:3"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,19 +42,18 @@ public class MessageDispatchTest extends BaseCommandTestSupport {
|
|||
public static MessageDispatchTest SINGLETON = new MessageDispatchTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
MessageDispatch info = new MessageDispatch();
|
||||
populateObject(info);
|
||||
return info;
|
||||
MessageDispatch info = new MessageDispatch();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
MessageDispatch info = (MessageDispatch) object;
|
||||
super.populateObject(object);
|
||||
MessageDispatch info = (MessageDispatch) object;
|
||||
|
||||
info.setConsumerId(createConsumerId("ConsumerId:1"));
|
||||
info.setDestination(createActiveMQDestination("Destination:2"));
|
||||
info.setMessage(createMessage("Message:3"));
|
||||
info.setRedeliveryCounter(1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,18 +42,17 @@ public class MessageIdTest extends DataFileGeneratorTestSupport {
|
|||
public static MessageIdTest SINGLETON = new MessageIdTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
MessageId info = new MessageId();
|
||||
populateObject(info);
|
||||
return info;
|
||||
MessageId info = new MessageId();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
MessageId info = (MessageId) object;
|
||||
super.populateObject(object);
|
||||
MessageId info = (MessageId) object;
|
||||
|
||||
info.setProducerId(createProducerId("ProducerId:1"));
|
||||
info.setProducerSequenceId(1);
|
||||
info.setBrokerSequenceId(2);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,18 +42,17 @@ public class MessagePullTest extends BaseCommandTestSupport {
|
|||
public static MessagePullTest SINGLETON = new MessagePullTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
MessagePull info = new MessagePull();
|
||||
populateObject(info);
|
||||
return info;
|
||||
MessagePull info = new MessagePull();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
MessagePull info = (MessagePull) object;
|
||||
super.populateObject(object);
|
||||
MessagePull info = (MessagePull) object;
|
||||
|
||||
info.setConsumerId(createConsumerId("ConsumerId:1"));
|
||||
info.setDestination(createActiveMQDestination("Destination:2"));
|
||||
info.setTimeout(1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,10 +38,11 @@ import org.apache.activemq.command.*;
|
|||
*/
|
||||
public abstract class MessageTestSupport extends BaseCommandTestSupport {
|
||||
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
Message info = (Message) object;
|
||||
super.populateObject(object);
|
||||
Message info = (Message) object;
|
||||
|
||||
info.setProducerId(createProducerId("ProducerId:1"));
|
||||
info.setDestination(createActiveMQDestination("Destination:2"));
|
||||
info.setTransactionId(createTransactionId("TransactionId:3"));
|
||||
|
@ -57,33 +58,27 @@ public abstract class MessageTestSupport extends BaseCommandTestSupport {
|
|||
info.setReplyTo(createActiveMQDestination("ReplyTo:9"));
|
||||
info.setTimestamp(2);
|
||||
info.setType("Type:10");
|
||||
|
||||
{
|
||||
byte data[] = "Content:11".getBytes();
|
||||
info.setContent(new org.apache.activemq.util.ByteSequence(data,0,data.length));
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
byte data[] = "MarshalledProperties:12".getBytes();
|
||||
info.setMarshalledProperties(new org.apache.activemq.util.ByteSequence(data,0,data.length));
|
||||
}
|
||||
|
||||
{
|
||||
byte data[] = "Content:11".getBytes();
|
||||
info.setContent(new org.apache.activemq.util.ByteSequence(data,0,data.length));
|
||||
}
|
||||
{
|
||||
byte data[] = "MarshalledProperties:12".getBytes();
|
||||
info.setMarshalledProperties(new org.apache.activemq.util.ByteSequence(data,0,data.length));
|
||||
}
|
||||
info.setDataStructure(createDataStructure("DataStructure:13"));
|
||||
info.setTargetConsumerId(createConsumerId("TargetConsumerId:14"));
|
||||
info.setCompressed(false);
|
||||
info.setRedeliveryCounter(2);
|
||||
|
||||
{
|
||||
BrokerId value[] = new BrokerId[2];
|
||||
for( int i=0; i < 2; i++ ) {
|
||||
value[i] = createBrokerId("BrokerPath:15");
|
||||
}
|
||||
info.setBrokerPath(value);
|
||||
{
|
||||
BrokerId value[] = new BrokerId[2];
|
||||
for( int i=0; i < 2; i++ ) {
|
||||
value[i] = createBrokerId("BrokerPath:15");
|
||||
}
|
||||
info.setBrokerPath(value);
|
||||
}
|
||||
info.setArrival(3);
|
||||
info.setUserID("UserID:16");
|
||||
info.setRecievedByDFBridge(true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,17 +42,16 @@ public class NetworkBridgeFilterTest extends DataFileGeneratorTestSupport {
|
|||
public static NetworkBridgeFilterTest SINGLETON = new NetworkBridgeFilterTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
NetworkBridgeFilter info = new NetworkBridgeFilter();
|
||||
populateObject(info);
|
||||
return info;
|
||||
NetworkBridgeFilter info = new NetworkBridgeFilter();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
NetworkBridgeFilter info = (NetworkBridgeFilter) object;
|
||||
super.populateObject(object);
|
||||
NetworkBridgeFilter info = (NetworkBridgeFilter) object;
|
||||
|
||||
info.setNetworkTTL(1);
|
||||
info.setNetworkBrokerId(createBrokerId("NetworkBrokerId:1"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,17 +42,16 @@ public class PartialCommandTest extends DataFileGeneratorTestSupport {
|
|||
public static PartialCommandTest SINGLETON = new PartialCommandTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
PartialCommand info = new PartialCommand();
|
||||
populateObject(info);
|
||||
return info;
|
||||
PartialCommand info = new PartialCommand();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
PartialCommand info = (PartialCommand) object;
|
||||
super.populateObject(object);
|
||||
PartialCommand info = (PartialCommand) object;
|
||||
|
||||
info.setCommandId(1);
|
||||
info.setData("Data:1".getBytes());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,18 +42,17 @@ public class ProducerIdTest extends DataFileGeneratorTestSupport {
|
|||
public static ProducerIdTest SINGLETON = new ProducerIdTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
ProducerId info = new ProducerId();
|
||||
populateObject(info);
|
||||
return info;
|
||||
ProducerId info = new ProducerId();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
ProducerId info = (ProducerId) object;
|
||||
super.populateObject(object);
|
||||
ProducerId info = (ProducerId) object;
|
||||
|
||||
info.setConnectionId("ConnectionId:1");
|
||||
info.setValue(1);
|
||||
info.setSessionId(2);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,25 +42,23 @@ public class ProducerInfoTest extends BaseCommandTestSupport {
|
|||
public static ProducerInfoTest SINGLETON = new ProducerInfoTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
ProducerInfo info = new ProducerInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
ProducerInfo info = new ProducerInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
ProducerInfo info = (ProducerInfo) object;
|
||||
super.populateObject(object);
|
||||
ProducerInfo info = (ProducerInfo) object;
|
||||
|
||||
info.setProducerId(createProducerId("ProducerId:1"));
|
||||
info.setDestination(createActiveMQDestination("Destination:2"));
|
||||
|
||||
{
|
||||
BrokerId value[] = new BrokerId[2];
|
||||
for( int i=0; i < 2; i++ ) {
|
||||
value[i] = createBrokerId("BrokerPath:3");
|
||||
}
|
||||
info.setBrokerPath(value);
|
||||
}
|
||||
|
||||
{
|
||||
BrokerId value[] = new BrokerId[2];
|
||||
for( int i=0; i < 2; i++ ) {
|
||||
value[i] = createBrokerId("BrokerPath:3");
|
||||
}
|
||||
info.setBrokerPath(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,16 +42,15 @@ public class RemoveInfoTest extends BaseCommandTestSupport {
|
|||
public static RemoveInfoTest SINGLETON = new RemoveInfoTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
RemoveInfo info = new RemoveInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
RemoveInfo info = new RemoveInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
RemoveInfo info = (RemoveInfo) object;
|
||||
info.setObjectId(createDataStructure("ObjectId:1"));
|
||||
super.populateObject(object);
|
||||
RemoveInfo info = (RemoveInfo) object;
|
||||
|
||||
}
|
||||
}
|
||||
info.setObjectId(createDataStructure("ObjectId:1"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,18 +42,17 @@ public class RemoveSubscriptionInfoTest extends BaseCommandTestSupport {
|
|||
public static RemoveSubscriptionInfoTest SINGLETON = new RemoveSubscriptionInfoTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
RemoveSubscriptionInfo info = new RemoveSubscriptionInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
RemoveSubscriptionInfo info = new RemoveSubscriptionInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
RemoveSubscriptionInfo info = (RemoveSubscriptionInfo) object;
|
||||
super.populateObject(object);
|
||||
RemoveSubscriptionInfo info = (RemoveSubscriptionInfo) object;
|
||||
|
||||
info.setConnectionId(createConnectionId("ConnectionId:1"));
|
||||
info.setSubcriptionName("SubcriptionName:2");
|
||||
info.setClientId("ClientId:3");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,17 +42,16 @@ public class ReplayCommandTest extends BaseCommandTestSupport {
|
|||
public static ReplayCommandTest SINGLETON = new ReplayCommandTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
ReplayCommand info = new ReplayCommand();
|
||||
populateObject(info);
|
||||
return info;
|
||||
ReplayCommand info = new ReplayCommand();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
ReplayCommand info = (ReplayCommand) object;
|
||||
super.populateObject(object);
|
||||
ReplayCommand info = (ReplayCommand) object;
|
||||
|
||||
info.setFirstNakNumber(1);
|
||||
info.setLastNakNumber(2);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,16 +42,15 @@ public class ResponseTest extends BaseCommandTestSupport {
|
|||
public static ResponseTest SINGLETON = new ResponseTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
Response info = new Response();
|
||||
populateObject(info);
|
||||
return info;
|
||||
Response info = new Response();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
Response info = (Response) object;
|
||||
info.setCorrelationId(1);
|
||||
super.populateObject(object);
|
||||
Response info = (Response) object;
|
||||
|
||||
}
|
||||
}
|
||||
info.setCorrelationId(1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,17 +42,16 @@ public class SessionIdTest extends DataFileGeneratorTestSupport {
|
|||
public static SessionIdTest SINGLETON = new SessionIdTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
SessionId info = new SessionId();
|
||||
populateObject(info);
|
||||
return info;
|
||||
SessionId info = new SessionId();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
SessionId info = (SessionId) object;
|
||||
super.populateObject(object);
|
||||
SessionId info = (SessionId) object;
|
||||
|
||||
info.setConnectionId("ConnectionId:1");
|
||||
info.setValue(1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,16 +42,15 @@ public class SessionInfoTest extends BaseCommandTestSupport {
|
|||
public static SessionInfoTest SINGLETON = new SessionInfoTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
SessionInfo info = new SessionInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
SessionInfo info = new SessionInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
SessionInfo info = (SessionInfo) object;
|
||||
info.setSessionId(createSessionId("SessionId:1"));
|
||||
super.populateObject(object);
|
||||
SessionInfo info = (SessionInfo) object;
|
||||
|
||||
}
|
||||
}
|
||||
info.setSessionId(createSessionId("SessionId:1"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,15 +42,14 @@ public class ShutdownInfoTest extends BaseCommandTestSupport {
|
|||
public static ShutdownInfoTest SINGLETON = new ShutdownInfoTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
ShutdownInfo info = new ShutdownInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
ShutdownInfo info = new ShutdownInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
ShutdownInfo info = (ShutdownInfo) object;
|
||||
super.populateObject(object);
|
||||
ShutdownInfo info = (ShutdownInfo) object;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,19 +42,18 @@ public class SubscriptionInfoTest extends DataFileGeneratorTestSupport {
|
|||
public static SubscriptionInfoTest SINGLETON = new SubscriptionInfoTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
SubscriptionInfo info = new SubscriptionInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
SubscriptionInfo info = new SubscriptionInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
SubscriptionInfo info = (SubscriptionInfo) object;
|
||||
super.populateObject(object);
|
||||
SubscriptionInfo info = (SubscriptionInfo) object;
|
||||
|
||||
info.setClientId("ClientId:1");
|
||||
info.setDestination(createActiveMQDestination("Destination:2"));
|
||||
info.setSelector("Selector:3");
|
||||
info.setSubcriptionName("SubcriptionName:4");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,10 +38,10 @@ import org.apache.activemq.command.*;
|
|||
*/
|
||||
public abstract class TransactionIdTestSupport extends DataFileGeneratorTestSupport {
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
TransactionId info = (TransactionId) object;
|
||||
|
||||
}
|
||||
}
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
TransactionId info = (TransactionId) object;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,18 +42,17 @@ public class TransactionInfoTest extends BaseCommandTestSupport {
|
|||
public static TransactionInfoTest SINGLETON = new TransactionInfoTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
TransactionInfo info = new TransactionInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
TransactionInfo info = new TransactionInfo();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
TransactionInfo info = (TransactionInfo) object;
|
||||
super.populateObject(object);
|
||||
TransactionInfo info = (TransactionInfo) object;
|
||||
|
||||
info.setConnectionId(createConnectionId("ConnectionId:1"));
|
||||
info.setTransactionId(createTransactionId("TransactionId:2"));
|
||||
info.setType((byte) 1);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,18 +42,17 @@ public class XATransactionIdTest extends TransactionIdTestSupport {
|
|||
public static XATransactionIdTest SINGLETON = new XATransactionIdTest();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
XATransactionId info = new XATransactionId();
|
||||
populateObject(info);
|
||||
return info;
|
||||
XATransactionId info = new XATransactionId();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
XATransactionId info = (XATransactionId) object;
|
||||
super.populateObject(object);
|
||||
XATransactionId info = (XATransactionId) object;
|
||||
|
||||
info.setFormatId(1);
|
||||
info.setGlobalTransactionId("GlobalTransactionId:1".getBytes());
|
||||
info.setBranchQualifier("BranchQualifier:2".getBytes());
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.Task;
|
||||
import org.codehaus.jam.JamService;
|
||||
import org.codehaus.jam.JamServiceFactory;
|
||||
import org.codehaus.jam.JamServiceParams;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 384826 $
|
||||
*/
|
||||
public class CGeneratorTask extends Task {
|
||||
|
||||
int version = 2;
|
||||
File source = new File(".");
|
||||
File target = new File(".");
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Project project = new Project();
|
||||
project.init();
|
||||
CGeneratorTask generator = new CGeneratorTask();
|
||||
generator.setProject(project);
|
||||
|
||||
if( args.length > 0 ) {
|
||||
generator.version = Integer.parseInt(args[0]);
|
||||
}
|
||||
|
||||
if( args.length > 1 ) {
|
||||
generator.source = new File(args[1]);
|
||||
}
|
||||
|
||||
if( args.length > 2 ) {
|
||||
generator.target = new File(args[2]);
|
||||
}
|
||||
|
||||
generator.execute();
|
||||
}
|
||||
|
||||
public void execute() throws BuildException {
|
||||
try {
|
||||
|
||||
String sourceDir = source+"/src/main/java";
|
||||
|
||||
System.out.println("Parsing source files in: " + sourceDir);
|
||||
|
||||
JamServiceFactory jamServiceFactory = JamServiceFactory.getInstance();
|
||||
JamServiceParams params = jamServiceFactory.createServiceParams();
|
||||
File[] dirs = new File[]{new File(sourceDir)};
|
||||
params.includeSourcePattern(dirs, "**/*.java");
|
||||
JamService jam = jamServiceFactory.createService(params);
|
||||
|
||||
{
|
||||
CHeadersGenerator script = new CHeadersGenerator();
|
||||
script.setJam(jam);
|
||||
script.setTargetDir(target+"/src/libopenwire");
|
||||
script.setOpenwireVersion(version);
|
||||
script.run();
|
||||
}
|
||||
{
|
||||
CSourcesGenerator script = new CSourcesGenerator();
|
||||
script.setJam(jam);
|
||||
script.setTargetDir(target+"/src/libopenwire");
|
||||
script.setOpenwireVersion(version);
|
||||
script.run();
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new BuildException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public File getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(File basedir) {
|
||||
this.source = basedir;
|
||||
}
|
||||
|
||||
public File getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(File target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,261 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.codehaus.jam.JAnnotation;
|
||||
import org.codehaus.jam.JAnnotationValue;
|
||||
import org.codehaus.jam.JClass;
|
||||
import org.codehaus.jam.JProperty;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 383749 $
|
||||
*/
|
||||
public class CHeadersGenerator extends SingleSourceGenerator {
|
||||
|
||||
protected String targetDir = "./src/lib/openwire";
|
||||
|
||||
public Object run() {
|
||||
filePostFix = ".h";
|
||||
if (destFile == null) {
|
||||
destFile = new File(targetDir + "/ow_commands_v" + getOpenwireVersion() + ".h");
|
||||
}
|
||||
return super.run();
|
||||
}
|
||||
|
||||
public String getTargetDir() {
|
||||
return targetDir;
|
||||
}
|
||||
|
||||
public void setTargetDir(String targetDir) {
|
||||
this.targetDir = targetDir;
|
||||
}
|
||||
|
||||
protected void generateLicence(PrintWriter out) {
|
||||
out.println("/**");
|
||||
out.println(" *");
|
||||
out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
|
||||
out.println(" * contributor license agreements. See the NOTICE file distributed with");
|
||||
out.println(" * this work for additional information regarding copyright ownership.");
|
||||
out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
|
||||
out.println(" * (the \"License\"); you may not use this file except in compliance with");
|
||||
out.println(" * the License. You may obtain a copy of the License at");
|
||||
out.println(" *");
|
||||
out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
|
||||
out.println(" *");
|
||||
out.println(" * Unless required by applicable law or agreed to in writing, software");
|
||||
out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
|
||||
out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
|
||||
out.println(" * See the License for the specific language governing permissions and");
|
||||
out.println(" * limitations under the License.");
|
||||
out.println(" */");
|
||||
}
|
||||
|
||||
String changeCase(String value) {
|
||||
StringBuffer b = new StringBuffer();
|
||||
char[] cs = value.toCharArray();
|
||||
for (int i = 0; i < cs.length; i++) {
|
||||
char c = cs[i];
|
||||
if (Character.isUpperCase((char) c)) {
|
||||
b.append('_');
|
||||
b.append(Character.toLowerCase((char) c));
|
||||
} else {
|
||||
b.append(c);
|
||||
}
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
String toPropertyCase(String value) {
|
||||
return value.substring(0, 1).toLowerCase() + value.substring(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the class list so that base classes come up first.
|
||||
*/
|
||||
protected List sort(List source) {
|
||||
LinkedHashMap rc = new LinkedHashMap();
|
||||
ArrayList classes = new ArrayList(source);
|
||||
Collections.sort(classes, new Comparator(){
|
||||
public int compare(Object o1, Object o2) {
|
||||
JClass c1 = (JClass) o1;
|
||||
JClass c2 = (JClass) o2;
|
||||
return c1.getSimpleName().compareTo(c2.getSimpleName());
|
||||
}});
|
||||
|
||||
// lets make a map of all the class names
|
||||
HashMap classNames = new HashMap();
|
||||
for (Iterator iter = classes.iterator(); iter.hasNext();) {
|
||||
JClass c = (JClass) iter.next();
|
||||
classNames.put(c, c);
|
||||
}
|
||||
|
||||
// Add all classes that have no parent first
|
||||
for (Iterator iter = classes.iterator(); iter.hasNext();) {
|
||||
JClass c = (JClass) iter.next();
|
||||
if (!classNames.containsKey(c.getSuperclass()))
|
||||
rc.put(c, c);
|
||||
}
|
||||
|
||||
// now lets add the rest
|
||||
for (Iterator iter = classes.iterator(); iter.hasNext();) {
|
||||
JClass c = (JClass) iter.next();
|
||||
if (!rc.containsKey(c))
|
||||
rc.put(c,c);
|
||||
}
|
||||
|
||||
return new ArrayList(rc.keySet());
|
||||
}
|
||||
|
||||
void generateFields(PrintWriter out, JClass jclass) {
|
||||
|
||||
if (jclass.getSuperclass() == null || jclass.getSuperclass().getSimpleName().equals("Object")) {
|
||||
out.println("");
|
||||
out.println(" ow_byte structType;");
|
||||
} else {
|
||||
generateFields(out, jclass.getSuperclass());
|
||||
}
|
||||
|
||||
ArrayList properties = new ArrayList();
|
||||
jclass.getDeclaredProperties();
|
||||
for (int i = 0; i < jclass.getDeclaredProperties().length; i++) {
|
||||
JProperty p = jclass.getDeclaredProperties()[i];
|
||||
if (isValidProperty(p)) {
|
||||
properties.add(p);
|
||||
}
|
||||
}
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
|
||||
JAnnotationValue size = annotation.getValue("size");
|
||||
String name = toPropertyCase(property.getSimpleName());
|
||||
boolean cached = isCachedProperty(property);
|
||||
|
||||
String type = property.getType().getQualifiedName();
|
||||
if (type.equals("boolean")) {
|
||||
out.println(" ow_"+type+" "+name+";");
|
||||
} else if (type.equals("byte")) {
|
||||
out.println(" ow_"+type+" "+name+";");
|
||||
} else if (type.equals("char")) {
|
||||
out.println(" ow_"+type+" "+name+";");
|
||||
} else if (type.equals("short")) {
|
||||
out.println(" ow_"+type+" "+name+";");
|
||||
} else if (type.equals("int")) {
|
||||
out.println(" ow_"+type+" "+name+";");
|
||||
} else if (type.equals("long")) {
|
||||
out.println(" ow_"+type+" "+name+";");
|
||||
} else if (type.equals("byte[]")) {
|
||||
out.println(" ow_byte_array *"+name+";");
|
||||
} else if (type.equals("org.apache.activeio.packet.ByteSequence")) {
|
||||
out.println(" ow_byte_array *"+name+";");
|
||||
} else if (type.equals("org.apache.activeio.packet.ByteSequence")) {
|
||||
out.println(" ow_byte_array *"+name+";");
|
||||
} else if (type.equals("java.lang.String")) {
|
||||
out.println(" ow_string *"+name+";");
|
||||
} else {
|
||||
if (property.getType().isArrayType()) {
|
||||
out.println(" ow_DataStructure_array *"+name+";");
|
||||
} else if (isThrowable(property.getType())) {
|
||||
out.println(" ow_throwable *"+name+";");
|
||||
} else {
|
||||
out.println(" struct ow_" + property.getType().getSimpleName() + " *"+name+";");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void generateSetup(PrintWriter out) {
|
||||
generateLicence(out);
|
||||
out.println("");
|
||||
out.println("/*****************************************************************************************");
|
||||
out.println(" * ");
|
||||
out.println(" * NOTE!: This file is auto generated - do not modify!");
|
||||
out.println(" * if you need to make a change, please see the modify the groovy scripts in the");
|
||||
out.println(" * under src/gram/script and then use maven openwire:generate to regenerate ");
|
||||
out.println(" * this file.");
|
||||
out.println(" * ");
|
||||
out.println(" *****************************************************************************************/");
|
||||
out.println(" ");
|
||||
out.println("#ifndef OW_COMMANDS_V"+openwireVersion+"_H");
|
||||
out.println("#define OW_COMMANDS_V"+openwireVersion+"_H");
|
||||
out.println("");
|
||||
out.println("#include \"ow.h\"");
|
||||
out.println("");
|
||||
out.println("#ifdef __cplusplus");
|
||||
out.println("extern \"C\" {");
|
||||
out.println("#endif /* __cplusplus */");
|
||||
out.println(" ");
|
||||
out.println("#define OW_WIREFORMAT_VERSION "+openwireVersion+"");
|
||||
|
||||
out.println("#define OW_WIREFORMAT_STACK_TRACE_MASK 0x00000001;");
|
||||
out.println("#define OW_WIREFORMAT_TCP_NO_DELAY_MASK 0x00000002;");
|
||||
out.println("#define OW_WIREFORMAT_CACHE_MASK 0x00000004;");
|
||||
out.println("#define OW_WIREFORMAT_COMPRESSION_MASK 0x00000008;");
|
||||
|
||||
for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
|
||||
JClass jclass = (JClass) iterator.next();
|
||||
String name = jclass.getSimpleName();
|
||||
String type = ("ow_"+name).toUpperCase()+"_TYPE";
|
||||
if( !isAbstract(jclass) ) {
|
||||
out.println("#define "+type+" "+getOpenWireOpCode(jclass));
|
||||
}
|
||||
}
|
||||
|
||||
out.println(" ");
|
||||
out.println("apr_status_t ow_bitmarshall(ow_bit_buffer *buffer, ow_DataStructure *object);");
|
||||
out.println("apr_status_t ow_marshall(ow_byte_buffer *buffer, ow_DataStructure *object);");
|
||||
}
|
||||
|
||||
protected void generateFile(PrintWriter out) throws Exception {
|
||||
|
||||
String structName = jclass.getSimpleName();
|
||||
String type = "OW_" + structName.toUpperCase() + "_TYPE";
|
||||
|
||||
out.println("");
|
||||
out.println("typedef struct ow_"+structName+" {");
|
||||
|
||||
// This recusivly generates the field definitions of the class and it's supper classes.
|
||||
generateFields(out, jclass);
|
||||
|
||||
out.println("");
|
||||
out.println("} ow_"+structName+";");
|
||||
out.println("ow_"+structName+" *ow_"+structName+"_create(apr_pool_t *pool);");
|
||||
out.println("ow_boolean ow_is_a_"+structName+"(ow_DataStructure *object);");
|
||||
|
||||
}
|
||||
|
||||
protected void generateTearDown(PrintWriter out) {
|
||||
out.println("");
|
||||
out.println("#ifdef __cplusplus");
|
||||
out.println("}");
|
||||
out.println("#endif");
|
||||
out.println("");
|
||||
out.println("#endif /* ! OW_COMMANDS_V"+openwireVersion+"_H */");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,222 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.codehaus.jam.JClass;
|
||||
import org.codehaus.jam.JProperty;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 383749 $
|
||||
*/
|
||||
public class CSharpClassesGenerator extends MultiSourceGenerator {
|
||||
|
||||
protected String targetDir="./src/main/csharp";
|
||||
|
||||
public Object run() {
|
||||
filePostFix = ".cs";
|
||||
if (destDir == null) {
|
||||
destDir = new File(targetDir+"/ActiveMQ/Commands");
|
||||
}
|
||||
return super.run();
|
||||
}
|
||||
|
||||
public String makeHashCodeBody() throws Exception {
|
||||
if (simpleName.endsWith("Id")) {
|
||||
StringWriter buffer = new StringWriter();
|
||||
PrintWriter out = new PrintWriter(buffer);
|
||||
out.println(" int answer = 0;");
|
||||
Iterator iter = getProperties().iterator();
|
||||
while (iter.hasNext()) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
out.println(" answer = (answer * 37) + HashCode(" + property.getSimpleName() + ");");
|
||||
}
|
||||
out.println(" return answer;");
|
||||
return buffer.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String makeEqualsBody() throws Exception {
|
||||
if (simpleName.endsWith("Id")) {
|
||||
StringWriter buffer = new StringWriter();
|
||||
PrintWriter out = new PrintWriter(buffer);
|
||||
|
||||
Iterator iter = getProperties().iterator();
|
||||
while (iter.hasNext()) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
String name = property.getSimpleName();
|
||||
out.println(" if (! Equals(this." + name + ", that." + name + ")) return false;");
|
||||
}
|
||||
out.println(" return true;");
|
||||
return buffer.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String makeToStringBody() throws Exception {
|
||||
StringWriter buffer = new StringWriter();
|
||||
PrintWriter out = new PrintWriter(buffer);
|
||||
out.println(" return GetType().Name + \"[\"");
|
||||
Iterator iter = getProperties().iterator();
|
||||
while (iter.hasNext()) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
String name = property.getSimpleName();
|
||||
out.println(" + \" " + name + "=\" + " + name);
|
||||
}
|
||||
out.println(" + \" ]\";");
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
private void generateLicence(PrintWriter out) {
|
||||
out.println("/*");
|
||||
out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
|
||||
out.println(" * contributor license agreements. See the NOTICE file distributed with");
|
||||
out.println(" * this work for additional information regarding copyright ownership.");
|
||||
out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
|
||||
out.println(" * (the \"License\"); you may not use this file except in compliance with");
|
||||
out.println(" * the License. You may obtain a copy of the License at");
|
||||
out.println(" *");
|
||||
out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
|
||||
out.println(" *");
|
||||
out.println(" * Unless required by applicable law or agreed to in writing, software");
|
||||
out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
|
||||
out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
|
||||
out.println(" * See the License for the specific language governing permissions and");
|
||||
out.println(" * limitations under the License.");
|
||||
out.println(" */");
|
||||
}
|
||||
|
||||
|
||||
protected void generateFile(PrintWriter out) throws Exception {
|
||||
generateLicence(out);
|
||||
|
||||
out.println("//");
|
||||
out.println("// NOTE!: This file is autogenerated - do not modify!");
|
||||
out.println("// if you need to make a change, please see the Groovy scripts in the");
|
||||
out.println("// activemq-core module");
|
||||
out.println("//");
|
||||
out.println("");
|
||||
out.println("using System;");
|
||||
out.println("using System.Collections;");
|
||||
out.println("");
|
||||
out.println("using ActiveMQ.OpenWire;");
|
||||
out.println("using ActiveMQ.Commands;");
|
||||
out.println("");
|
||||
out.println("namespace ActiveMQ.Commands");
|
||||
out.println("{");
|
||||
out.println(" /// <summary>");
|
||||
out.println(" /// The ActiveMQ "+jclass.getSimpleName()+" Command");
|
||||
out.println(" /// </summary>");
|
||||
out.print(" public class "+jclass.getSimpleName()+" : "+baseClass);
|
||||
|
||||
|
||||
for (int i = 0; i < jclass.getInterfaces().length; i++) {
|
||||
JClass intf = jclass.getInterfaces()[i];
|
||||
out.print(", "+intf.getSimpleName());
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" {");
|
||||
out.println(" public const byte ID_"+jclass.getSimpleName()+" = "+getOpenWireOpCode(jclass)+";");
|
||||
out.println(" ");
|
||||
|
||||
List properties = getProperties();
|
||||
String type;
|
||||
Object name;
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
type = toCSharpType(property.getType());
|
||||
name = decapitalize(property.getSimpleName());
|
||||
out.println(" "+type+" "+name+";");
|
||||
}
|
||||
|
||||
String text = makeHashCodeBody();
|
||||
if (text != null) {
|
||||
out.println("");
|
||||
out.println(" public override int GetHashCode() {");
|
||||
out.println(""+text+"");
|
||||
out.println(" }");
|
||||
}
|
||||
|
||||
text = makeEqualsBody();
|
||||
if (text != null) {
|
||||
out.println("");
|
||||
out.println(" public override bool Equals(object that) {");
|
||||
out.println(" if (that is "+className+") {");
|
||||
out.println(" return Equals(("+className+") that);");
|
||||
out.println(" }");
|
||||
out.println(" return false;");
|
||||
out.println(" }");
|
||||
out.println("");
|
||||
out.println(" public virtual bool Equals("+className+" that) {");
|
||||
out.println(""+text+"");
|
||||
out.println(" }");
|
||||
}
|
||||
|
||||
text = makeToStringBody();
|
||||
if (text != null) {
|
||||
out.println("");
|
||||
out.println(" public override string ToString() {");
|
||||
out.println(""+text+"");
|
||||
out.println(" }");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" public override byte GetDataStructureType() {");
|
||||
out.println(" return ID_"+jclass.getSimpleName()+";");
|
||||
out.println(" }");
|
||||
out.println("");
|
||||
out.println("");
|
||||
out.println(" // Properties");
|
||||
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
type = toCSharpType(property.getType());
|
||||
name = decapitalize(property.getSimpleName());
|
||||
String propertyName = property.getSimpleName();
|
||||
String getter = capitalize(property.getGetter().getSimpleName());
|
||||
String setter = capitalize(property.getSetter().getSimpleName());
|
||||
|
||||
out.println("");
|
||||
out.println(" public "+type+" "+propertyName+"");
|
||||
out.println(" {");
|
||||
out.println(" get { return "+name+"; }");
|
||||
out.println(" set { this."+name+" = value; } ");
|
||||
out.println(" }");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" }");
|
||||
out.println("}");
|
||||
}
|
||||
|
||||
public String getTargetDir() {
|
||||
return targetDir;
|
||||
}
|
||||
|
||||
public void setTargetDir(String targetDir) {
|
||||
this.targetDir = targetDir;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,118 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.Task;
|
||||
import org.codehaus.jam.JamService;
|
||||
import org.codehaus.jam.JamServiceFactory;
|
||||
import org.codehaus.jam.JamServiceParams;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 384826 $
|
||||
*/
|
||||
public class CSharpGeneratorTask extends Task {
|
||||
|
||||
int version = 2;
|
||||
File source = new File(".");
|
||||
File target = new File(".");
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Project project = new Project();
|
||||
project.init();
|
||||
CSharpGeneratorTask generator = new CSharpGeneratorTask();
|
||||
generator.setProject(project);
|
||||
|
||||
if( args.length > 0 ) {
|
||||
generator.version = Integer.parseInt(args[0]);
|
||||
}
|
||||
|
||||
if( args.length > 1 ) {
|
||||
generator.source = new File(args[1]);
|
||||
}
|
||||
|
||||
if( args.length > 2 ) {
|
||||
generator.target = new File(args[2]);
|
||||
}
|
||||
|
||||
generator.execute();
|
||||
}
|
||||
|
||||
public void execute() throws BuildException {
|
||||
try {
|
||||
|
||||
String sourceDir = source+"/src/main/java";
|
||||
|
||||
System.out.println("Parsing source files in: " + sourceDir);
|
||||
|
||||
JamServiceFactory jamServiceFactory = JamServiceFactory.getInstance();
|
||||
JamServiceParams params = jamServiceFactory.createServiceParams();
|
||||
File[] dirs = new File[]{new File(sourceDir)};
|
||||
params.includeSourcePattern(dirs, "**/*.java");
|
||||
JamService jam = jamServiceFactory.createService(params);
|
||||
|
||||
{
|
||||
CSharpClassesGenerator script = new CSharpClassesGenerator();
|
||||
script.setJam(jam);
|
||||
script.setTargetDir(target+"/src/main/csharp");
|
||||
script.setOpenwireVersion(version);
|
||||
script.run();
|
||||
}
|
||||
{
|
||||
CSharpMarshallingGenerator script = new CSharpMarshallingGenerator();
|
||||
script.setJam(jam);
|
||||
script.setTargetDir(target+"/src/main/csharp");
|
||||
script.setOpenwireVersion(version);
|
||||
script.run();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new BuildException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public File getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(File basedir) {
|
||||
this.source = basedir;
|
||||
}
|
||||
|
||||
public File getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(File target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
}
|
|
@ -29,14 +29,15 @@ import java.util.*;
|
|||
*
|
||||
* @version $Revision: 384390 $
|
||||
*/
|
||||
public abstract class OpenWireCSharpMarshallingScript extends OpenWireJavaMarshallingScript {
|
||||
public class CSharpMarshallingGenerator extends JavaMarshallingGenerator {
|
||||
|
||||
protected String targetDir="./src/main/csharp";
|
||||
|
||||
public Object run() {
|
||||
filePostFix = ".cs";
|
||||
if (destDir == null) {
|
||||
destDir = new File("../activemq-dotnet/src/main/csharp/ActiveMQ/OpenWire/V"+getOpenwireVersion());
|
||||
}
|
||||
|
||||
destDir = new File(targetDir+"/ActiveMQ/OpenWire/V"+getOpenwireVersion());
|
||||
}
|
||||
return super.run();
|
||||
}
|
||||
|
||||
|
@ -391,4 +392,250 @@ public abstract class OpenWireCSharpMarshallingScript extends OpenWireJavaMarsha
|
|||
}
|
||||
}
|
||||
|
||||
public String getTargetDir() {
|
||||
return targetDir;
|
||||
}
|
||||
|
||||
public void setTargetDir(String targetDir) {
|
||||
this.targetDir = targetDir;
|
||||
}
|
||||
|
||||
private void generateLicence(PrintWriter out) {
|
||||
out.println("/*");
|
||||
out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
|
||||
out.println(" * contributor license agreements. See the NOTICE file distributed with");
|
||||
out.println(" * this work for additional information regarding copyright ownership.");
|
||||
out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
|
||||
out.println(" * (the \"License\"); you may not use this file except in compliance with");
|
||||
out.println(" * the License. You may obtain a copy of the License at");
|
||||
out.println(" *");
|
||||
out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
|
||||
out.println(" *");
|
||||
out.println(" * Unless required by applicable law or agreed to in writing, software");
|
||||
out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
|
||||
out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
|
||||
out.println(" * See the License for the specific language governing permissions and");
|
||||
out.println(" * limitations under the License.");
|
||||
out.println(" */");
|
||||
}
|
||||
|
||||
protected void generateFile(PrintWriter out) throws Exception {
|
||||
generateLicence(out);
|
||||
out.println("");
|
||||
out.println("//");
|
||||
out.println("// NOTE!: This file is autogenerated - do not modify!");
|
||||
out.println("// if you need to make a change, please see the Groovy scripts in the");
|
||||
out.println("// activemq-core module");
|
||||
out.println("//");
|
||||
out.println("");
|
||||
out.println("using System;");
|
||||
out.println("using System.Collections;");
|
||||
out.println("using System.IO;");
|
||||
out.println("");
|
||||
out.println("using ActiveMQ.Commands;");
|
||||
out.println("using ActiveMQ.OpenWire;");
|
||||
out.println("using ActiveMQ.OpenWire.V"+getOpenwireVersion()+";");
|
||||
out.println("");
|
||||
out.println("namespace ActiveMQ.OpenWire.V"+getOpenwireVersion()+"");
|
||||
out.println("{");
|
||||
out.println(" /// <summary>");
|
||||
out.println(" /// Marshalling code for Open Wire Format for "+jclass.getSimpleName()+"");
|
||||
out.println(" /// </summary>");
|
||||
out.println(" "+getAbstractClassText()+"class "+getClassName()+" : "+getBaseClass()+"");
|
||||
out.println(" {");
|
||||
|
||||
if( !isAbstractClass() ) {
|
||||
out.println("");
|
||||
out.println("");
|
||||
out.println(" public override DataStructure CreateObject() ");
|
||||
out.println(" {");
|
||||
out.println(" return new "+jclass.getSimpleName()+"();");
|
||||
out.println(" }");
|
||||
out.println("");
|
||||
out.println(" public override byte GetDataStructureType() ");
|
||||
out.println(" {");
|
||||
out.println(" return "+jclass.getSimpleName()+".ID_"+jclass.getSimpleName()+";");
|
||||
out.println(" }");
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate the tight encoding marshallers
|
||||
*/
|
||||
out.println("");
|
||||
out.println(" // ");
|
||||
out.println(" // Un-marshal an object instance from the data input stream");
|
||||
out.println(" // ");
|
||||
out.println(" public override void TightUnmarshal(OpenWireFormat wireFormat, Object o, BinaryReader dataIn, BooleanStream bs) ");
|
||||
out.println(" {");
|
||||
out.println(" base.TightUnmarshal(wireFormat, o, dataIn, bs);");
|
||||
|
||||
if( !getProperties().isEmpty() || isMarshallerAware() ) {
|
||||
out.println("");
|
||||
out.println(" "+jclass.getSimpleName()+" info = ("+jclass.getSimpleName()+")o;");
|
||||
}
|
||||
|
||||
if( isMarshallerAware() ){
|
||||
out.println("");
|
||||
out.println(" info.BeforeUnmarshall(wireFormat);");
|
||||
out.println("");
|
||||
}
|
||||
|
||||
generateTightUnmarshalBody(out);
|
||||
|
||||
if( isMarshallerAware() ){
|
||||
out.println("");
|
||||
out.println(" info.AfterUnmarshall(wireFormat);");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" }");
|
||||
out.println("");
|
||||
out.println(" //");
|
||||
out.println(" // Write the booleans that this object uses to a BooleanStream");
|
||||
out.println(" //");
|
||||
out.println(" public override int TightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) {");
|
||||
out.println(" "+jclass.getSimpleName()+" info = ("+jclass.getSimpleName()+")o;");
|
||||
|
||||
if( isMarshallerAware() ) {
|
||||
out.println("");
|
||||
out.println(" info.BeforeMarshall(wireFormat);");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" int rc = base.TightMarshal1(wireFormat, info, bs);");
|
||||
|
||||
int baseSize = generateTightMarshal1Body(out);
|
||||
|
||||
out.println("");
|
||||
out.println(" return rc + "+baseSize+";");
|
||||
out.println(" }");
|
||||
out.println("");
|
||||
out.println(" // ");
|
||||
out.println(" // Write a object instance to data output stream");
|
||||
out.println(" //");
|
||||
out.println(" public override void TightMarshal2(OpenWireFormat wireFormat, Object o, BinaryWriter dataOut, BooleanStream bs) {");
|
||||
out.println(" base.TightMarshal2(wireFormat, o, dataOut, bs);");
|
||||
|
||||
if( !getProperties().isEmpty() || isMarshallerAware() ) {
|
||||
out.println("");
|
||||
out.println(" "+jclass.getSimpleName()+" info = ("+jclass.getSimpleName()+")o;");
|
||||
}
|
||||
|
||||
generateTightMarshal2Body(out);
|
||||
|
||||
if( isMarshallerAware() ) {
|
||||
out.println("");
|
||||
out.println(" info.AfterMarshall(wireFormat);");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" }");
|
||||
|
||||
out.println("");
|
||||
out.println(" // ");
|
||||
out.println(" // Un-marshal an object instance from the data input stream");
|
||||
out.println(" // ");
|
||||
out.println(" public override void LooseUnmarshal(OpenWireFormat wireFormat, Object o, BinaryReader dataIn) ");
|
||||
out.println(" {");
|
||||
out.println(" base.LooseUnmarshal(wireFormat, o, dataIn);");
|
||||
|
||||
if( !getProperties().isEmpty() || isMarshallerAware() ) {
|
||||
out.println("");
|
||||
out.println(" "+jclass.getSimpleName()+" info = ("+jclass.getSimpleName()+")o;");
|
||||
}
|
||||
|
||||
if( isMarshallerAware() ) {
|
||||
out.println("");
|
||||
out.println(" info.BeforeUnmarshall(wireFormat);");
|
||||
out.println("");
|
||||
}
|
||||
|
||||
generateLooseUnmarshalBody(out);
|
||||
|
||||
if( isMarshallerAware() ) {
|
||||
out.println("");
|
||||
out.println(" info.AfterUnmarshall(wireFormat);");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" }");
|
||||
out.println("");
|
||||
out.println(" // ");
|
||||
out.println(" // Write a object instance to data output stream");
|
||||
out.println(" //");
|
||||
out.println(" public override void LooseMarshal(OpenWireFormat wireFormat, Object o, BinaryWriter dataOut) {");
|
||||
|
||||
if( !getProperties().isEmpty() || isMarshallerAware() ) {
|
||||
out.println("");
|
||||
out.println(" "+jclass.getSimpleName()+" info = ("+jclass.getSimpleName()+")o;");
|
||||
}
|
||||
|
||||
if( isMarshallerAware() ) {
|
||||
out.println("");
|
||||
out.println(" info.BeforeMarshall(wireFormat);");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" base.LooseMarshal(wireFormat, o, dataOut);");
|
||||
|
||||
generateLooseMarshalBody(out);
|
||||
|
||||
if( isMarshallerAware() ) {
|
||||
out.println("");
|
||||
out.println(" info.AfterMarshall(wireFormat);");
|
||||
}
|
||||
out.println("");
|
||||
out.println(" }");
|
||||
out.println(" }");
|
||||
out.println("}");
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void generateFactory(PrintWriter out) {
|
||||
generateLicence(out);
|
||||
out.println("");
|
||||
out.println("//");
|
||||
out.println("// NOTE!: This file is autogenerated - do not modify!");
|
||||
out.println("// if you need to make a change, please see the Groovy scripts in the");
|
||||
out.println("// activemq-core module");
|
||||
out.println("//");
|
||||
out.println("");
|
||||
out.println("using System;");
|
||||
out.println("using System.Collections;");
|
||||
out.println("using System.IO;");
|
||||
out.println("");
|
||||
out.println("using ActiveMQ.Commands;");
|
||||
out.println("using ActiveMQ.OpenWire;");
|
||||
out.println("using ActiveMQ.OpenWire.V"+getOpenwireVersion()+";");
|
||||
out.println("");
|
||||
out.println("namespace ActiveMQ.OpenWire.V"+getOpenwireVersion()+"");
|
||||
out.println("{");
|
||||
out.println(" /// <summary>");
|
||||
out.println(" /// Used to create marshallers for a specific version of the wire protocol");
|
||||
out.println(" /// </summary>");
|
||||
out.println(" public class MarshallerFactory");
|
||||
out.println(" {");
|
||||
out.println(" public void configure(OpenWireFormat format) ");
|
||||
out.println(" {");
|
||||
|
||||
List list = new ArrayList(getConcreteClasses());
|
||||
Collections.sort(list, new Comparator(){
|
||||
public int compare(Object o1, Object o2) {
|
||||
JClass c1 = (JClass) o1;
|
||||
JClass c2 = (JClass) o2;
|
||||
return c1.getSimpleName().compareTo(c2.getSimpleName());
|
||||
}});
|
||||
|
||||
for (Iterator iter = list.iterator(); iter.hasNext();) {
|
||||
JClass jclass = (JClass) iter.next();
|
||||
out.println(" format.addMarshaller(new "+jclass.getSimpleName()+"Marshaller());");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" }");
|
||||
out.println(" }");
|
||||
out.println("}");
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,381 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.codehaus.jam.JAnnotation;
|
||||
import org.codehaus.jam.JAnnotationValue;
|
||||
import org.codehaus.jam.JClass;
|
||||
import org.codehaus.jam.JProperty;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 383749 $
|
||||
*/
|
||||
public class CSourcesGenerator extends CHeadersGenerator {
|
||||
|
||||
public Object run() {
|
||||
filePostFix = ".c";
|
||||
if (destFile == null) {
|
||||
destFile = new File(targetDir + "/ow_commands_v" + getOpenwireVersion() + ".c");
|
||||
}
|
||||
return super.run();
|
||||
}
|
||||
|
||||
protected List sort(List source) {
|
||||
return source;
|
||||
}
|
||||
|
||||
protected void generateSetup(PrintWriter out) {
|
||||
generateLicence(out);
|
||||
out.println("");
|
||||
out.println("/*****************************************************************************************");
|
||||
out.println(" * ");
|
||||
out.println(" * NOTE!: This file is auto generated - do not modify!");
|
||||
out.println(" * if you need to make a change, please see the modify the groovy scripts in the");
|
||||
out.println(" * under src/gram/script and then use maven openwire:generate to regenerate ");
|
||||
out.println(" * this file.");
|
||||
out.println(" * ");
|
||||
out.println(" *****************************************************************************************/");
|
||||
out.println("");
|
||||
out.println("");
|
||||
out.println("#include \"ow_commands_v"+openwireVersion+".h\"");
|
||||
out.println("");
|
||||
out.println("#define SUCCESS_CHECK( f ) { apr_status_t rc=f; if(rc!=APR_SUCCESS) return rc; }");
|
||||
out.println("");
|
||||
}
|
||||
|
||||
protected void generateFile(PrintWriter out) throws Exception {
|
||||
|
||||
ArrayList properties = new ArrayList();
|
||||
jclass.getDeclaredProperties();
|
||||
for (int i = 0; i < jclass.getDeclaredProperties().length; i++) {
|
||||
JProperty p = jclass.getDeclaredProperties()[i];
|
||||
if (isValidProperty(p)) {
|
||||
properties.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
String name = jclass.getSimpleName();
|
||||
String type = ("ow_"+name).toUpperCase()+"_TYPE";
|
||||
String baseName = "DataStructure";
|
||||
JClass superclass = jclass.getSuperclass();
|
||||
while( superclass.getSuperclass() != null ) {
|
||||
if( sortedClasses.contains(superclass) ) {
|
||||
baseName = superclass.getSimpleName();
|
||||
break;
|
||||
} else {
|
||||
superclass = superclass.getSuperclass();
|
||||
}
|
||||
}
|
||||
|
||||
out.println("ow_boolean ow_is_a_"+name+"(ow_DataStructure *object) {");
|
||||
out.println(" if( object == 0 )");
|
||||
out.println(" return 0;");
|
||||
out.println(" ");
|
||||
out.println(" switch(object->structType) {");
|
||||
|
||||
for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
|
||||
JClass sub = (JClass) iterator.next();
|
||||
String subtype = "OW_"+sub.getSimpleName().toUpperCase()+"_TYPE";
|
||||
if( jclass.isAssignableFrom(sub) && !isAbstract(sub) ) {
|
||||
out.println("");
|
||||
out.println(" case "+subtype+":");
|
||||
}
|
||||
}
|
||||
out.println("");
|
||||
out.println(" return 1;");
|
||||
out.println(" }");
|
||||
out.println(" return 0;");
|
||||
out.println("}");
|
||||
|
||||
if( !isAbstract(jclass) ) {
|
||||
out.println("");
|
||||
out.println("");
|
||||
out.println("ow_"+name+" *ow_"+name+"_create(apr_pool_t *pool) ");
|
||||
out.println("{");
|
||||
out.println(" ow_"+name+" *value = apr_pcalloc(pool,sizeof(ow_"+name+"));");
|
||||
out.println(" if( value!=0 ) {");
|
||||
out.println(" ((ow_DataStructure*)value)->structType = "+type+";");
|
||||
out.println(" }");
|
||||
out.println(" return value;");
|
||||
out.println("}");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println("");
|
||||
out.println("apr_status_t ow_marshal1_"+name+"(ow_bit_buffer *buffer, ow_"+name+" *object)");
|
||||
out.println("{");
|
||||
out.println(" ow_marshal1_"+baseName+"(buffer, (ow_"+baseName+"*)object);");
|
||||
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
String propname = toPropertyCase(property.getSimpleName());
|
||||
boolean cached = isCachedProperty(property);
|
||||
JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
|
||||
JAnnotationValue size = annotation.getValue("size");
|
||||
|
||||
type = property.getType().getQualifiedName();
|
||||
if( type.equals("boolean")) {
|
||||
out.println(" ow_bit_buffer_append(buffer, object->"+propname+");");
|
||||
} else if( type.equals("byte")) {
|
||||
} else if( type.equals("char")) {
|
||||
} else if( type.equals("short")) {
|
||||
} else if( type.equals("int")) {
|
||||
} else if( type.equals("long")) {
|
||||
out.println(" ow_marshal1_long(buffer, object->"+propname+");");
|
||||
} else if( type.equals("byte[]")) {
|
||||
if( size ==null ) {
|
||||
out.println(" ow_bit_buffer_append(buffer, object->"+propname+"!=0 );");
|
||||
}
|
||||
} else if( type.equals("org.apache.activeio.packet.ByteSequence")) {
|
||||
if( size ==null ) {
|
||||
out.println(" ow_bit_buffer_append(buffer, object->"+propname+"!=0 );");
|
||||
}
|
||||
} else if( type.equals("java.lang.String")) {
|
||||
out.println(" ow_marshal1_string(buffer, object->"+propname+");");
|
||||
} else {
|
||||
if( property.getType().isArrayType() ) {
|
||||
if( size!=null ) {
|
||||
out.println(" SUCCESS_CHECK(ow_marshal1_DataStructure_array_const_size(buffer, object->"+propname+", "+size.asInt()+"));");
|
||||
} else {
|
||||
out.println(" SUCCESS_CHECK(ow_marshal1_DataStructure_array(buffer, object->"+propname+"));");
|
||||
}
|
||||
} else if( isThrowable(property.getType()) ) {
|
||||
out.println(" SUCCESS_CHECK(ow_marshal1_throwable(buffer, object->"+propname+"));");
|
||||
} else {
|
||||
if( cached ) {
|
||||
out.println(" SUCCESS_CHECK(ow_marshal1_cached_object(buffer, (ow_DataStructure*)object->"+propname+"));");
|
||||
} else {
|
||||
out.println(" SUCCESS_CHECK(ow_marshal1_nested_object(buffer, (ow_DataStructure*)object->"+propname+"));");
|
||||
}
|
||||
}
|
||||
}
|
||||
out.println("");
|
||||
}
|
||||
|
||||
|
||||
out.println(" ");
|
||||
out.println(" return APR_SUCCESS;");
|
||||
out.println("}");
|
||||
out.println("apr_status_t ow_marshal2_"+name+"(ow_byte_buffer *buffer, ow_bit_buffer *bitbuffer, ow_"+name+" *object)");
|
||||
out.println("{");
|
||||
out.println(" ow_marshal2_"+baseName+"(buffer, bitbuffer, (ow_"+baseName+"*)object); ");
|
||||
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
|
||||
JAnnotationValue size = annotation.getValue("size");
|
||||
Object propname = toPropertyCase(property.getSimpleName());
|
||||
boolean cached = isCachedProperty(property);
|
||||
|
||||
type = property.getType().getQualifiedName();
|
||||
if( type.equals("boolean") ) {
|
||||
out.println(" ow_bit_buffer_read(bitbuffer);");
|
||||
} else if( type.equals("byte") ) {
|
||||
out.println(" SUCCESS_CHECK(ow_byte_buffer_append_"+type+"(buffer, object->"+propname+"));");
|
||||
} else if( type.equals("char") ) {
|
||||
out.println(" SUCCESS_CHECK(ow_byte_buffer_append_"+type+"(buffer, object->"+propname+"));");
|
||||
} else if( type.equals("short") ) {
|
||||
out.println(" SUCCESS_CHECK(ow_byte_buffer_append_"+type+"(buffer, object->"+propname+"));");
|
||||
} else if( type.equals("int") ) {
|
||||
out.println(" SUCCESS_CHECK(ow_byte_buffer_append_"+type+"(buffer, object->"+propname+"));");
|
||||
} else if( type.equals("long") ) {
|
||||
out.println(" SUCCESS_CHECK(ow_marshal2_long(buffer, bitbuffer, object->"+propname+"));");
|
||||
} else if( type.equals("byte[]") ) {
|
||||
if( size!=null ) {
|
||||
out.println(" SUCCESS_CHECK(ow_marshal2_byte_array_const_size(buffer, object->"+propname+", "+size.asInt()+"));");
|
||||
} else {
|
||||
out.println(" SUCCESS_CHECK(ow_marshal2_byte_array(buffer, bitbuffer, object->"+propname+"));");
|
||||
}
|
||||
} else if( type.equals("org.apache.activeio.packet.ByteSequence") ) {
|
||||
if( size!=null ) {
|
||||
out.println(" SUCCESS_CHECK(ow_marshal2_byte_array_const_size(buffer, object->"+propname+", "+size.asInt()+"));");
|
||||
} else {
|
||||
out.println(" SUCCESS_CHECK(ow_marshal2_byte_array(buffer, bitbuffer, object->"+propname+"));");
|
||||
}
|
||||
} else if( type.equals("java.lang.String") ) {
|
||||
out.println(" SUCCESS_CHECK(ow_marshal2_string(buffer, bitbuffer, object->"+propname+"));");
|
||||
} else {
|
||||
if( property.getType().isArrayType() ) {
|
||||
if( size!=null ) {
|
||||
out.println(" SUCCESS_CHECK(ow_marshal2_DataStructure_array_const_size(buffer, bitbuffer, object->"+propname+", "+size.asInt()+"));");
|
||||
} else {
|
||||
out.println(" SUCCESS_CHECK(ow_marshal2_DataStructure_array(buffer, bitbuffer, object->"+propname+"));");
|
||||
}
|
||||
} else if( isThrowable(property.getType()) ) {
|
||||
out.println(" SUCCESS_CHECK(ow_marshal2_throwable(buffer, bitbuffer, object->"+propname+"));");
|
||||
} else {
|
||||
if( cached ) {
|
||||
out.println(" SUCCESS_CHECK(ow_marshal2_cached_object(buffer, bitbuffer, (ow_DataStructure*)object->"+propname+"));");
|
||||
} else {
|
||||
out.println(" SUCCESS_CHECK(ow_marshal2_nested_object(buffer, bitbuffer, (ow_DataStructure*)object->"+propname+"));");
|
||||
}
|
||||
}
|
||||
}
|
||||
out.println("");
|
||||
}
|
||||
|
||||
out.println(" ");
|
||||
out.println(" return APR_SUCCESS;");
|
||||
out.println("}");
|
||||
out.println("");
|
||||
out.println("apr_status_t ow_unmarshal_"+name+"(ow_byte_array *buffer, ow_bit_buffer *bitbuffer, ow_"+name+" *object, apr_pool_t *pool)");
|
||||
out.println("{");
|
||||
out.println(" ow_unmarshal_"+baseName+"(buffer, bitbuffer, (ow_"+baseName+"*)object, pool); ");
|
||||
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
JAnnotation annotation = property.getGetter().getAnnotation("openwire:property");
|
||||
JAnnotationValue size = annotation.getValue("size");
|
||||
String propname = toPropertyCase(property.getSimpleName());
|
||||
boolean cached = isCachedProperty(property);
|
||||
|
||||
type = property.getType().getQualifiedName();
|
||||
|
||||
if( type.equals("boolean") ) {
|
||||
out.println(" object->"+propname+" = ow_bit_buffer_read(bitbuffer);");
|
||||
} else if( type.equals("byte") ) {
|
||||
out.println(" SUCCESS_CHECK(ow_byte_array_read_"+type+"(buffer, &object->"+propname+"));");
|
||||
} else if( type.equals("char") ) {
|
||||
out.println(" SUCCESS_CHECK(ow_byte_array_read_"+type+"(buffer, &object->"+propname+"));");
|
||||
} else if( type.equals("short") ) {
|
||||
out.println(" SUCCESS_CHECK(ow_byte_array_read_"+type+"(buffer, &object->"+propname+"));");
|
||||
} else if( type.equals("int") ) {
|
||||
out.println(" SUCCESS_CHECK(ow_byte_array_read_"+type+"(buffer, &object->"+propname+"));");
|
||||
} else if( type.equals("long") ) {
|
||||
out.println(" SUCCESS_CHECK(ow_unmarshal_long(buffer, bitbuffer, &object->"+propname+", pool));");
|
||||
} else if( type.equals("byte[]") ) {
|
||||
if( size!=null ) {
|
||||
out.println(" SUCCESS_CHECK(ow_unmarshal_byte_array_const_size(buffer, &object->"+propname+", "+size.asInt()+", pool));");
|
||||
} else {
|
||||
out.println(" SUCCESS_CHECK(ow_unmarshal_byte_array(buffer, bitbuffer, &object->"+propname+", pool));");
|
||||
}
|
||||
} else if( type.equals("org.apache.activeio.packet.ByteSequence") ) {
|
||||
if( size!=null ) {
|
||||
out.println(" SUCCESS_CHECK(ow_unmarshal_byte_array_const_size(buffer, &object->"+propname+", "+size.asInt()+", pool));");
|
||||
} else {
|
||||
out.println(" SUCCESS_CHECK(ow_unmarshal_byte_array(buffer, bitbuffer, &object->"+propname+", pool));");
|
||||
}
|
||||
} else if( type.equals("java.lang.String") ) {
|
||||
out.println(" SUCCESS_CHECK(ow_unmarshal_string(buffer, bitbuffer, &object->"+propname+", pool));");
|
||||
} else {
|
||||
if( property.getType().isArrayType() ) {
|
||||
if( size!=null ) {
|
||||
out.println(" SUCCESS_CHECK(ow_unmarshal_DataStructure_array_const_size(buffer, bitbuffer, &object->"+propname+", "+size.asInt()+", pool));");
|
||||
} else {
|
||||
out.println(" SUCCESS_CHECK(ow_unmarshal_DataStructure_array(buffer, bitbuffer, &object->"+propname+", pool));");
|
||||
}
|
||||
} else if( isThrowable(property.getType()) ) {
|
||||
out.println(" SUCCESS_CHECK(ow_unmarshal_throwable(buffer, bitbuffer, &object->"+propname+", pool));");
|
||||
} else {
|
||||
if( cached ) {
|
||||
out.println(" SUCCESS_CHECK(ow_unmarshal_cached_object(buffer, bitbuffer, (ow_DataStructure**)&object->"+propname+", pool));");
|
||||
} else {
|
||||
out.println(" SUCCESS_CHECK(ow_unmarshal_nested_object(buffer, bitbuffer, (ow_DataStructure**)&object->"+propname+", pool));");
|
||||
}
|
||||
}
|
||||
}
|
||||
out.println("");
|
||||
}
|
||||
|
||||
out.println(" ");
|
||||
out.println(" return APR_SUCCESS;");
|
||||
out.println("}");
|
||||
}
|
||||
|
||||
protected void generateTearDown(PrintWriter out) {
|
||||
out.println("");
|
||||
out.println("ow_DataStructure *ow_create_object(ow_byte type, apr_pool_t *pool)");
|
||||
out.println("{");
|
||||
out.println(" switch( type ) {");
|
||||
for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
|
||||
JClass jclass = (JClass) iterator.next();
|
||||
String name = jclass.getSimpleName();
|
||||
String type = ("ow_"+name).toUpperCase()+"_TYPE";
|
||||
if( !isAbstract(jclass) ) {
|
||||
out.println(" case "+type+": return (ow_DataStructure *)ow_"+name+"_create(pool);");
|
||||
}
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" }");
|
||||
out.println(" return 0;");
|
||||
out.println("}");
|
||||
out.println("");
|
||||
out.println("apr_status_t ow_marshal1_object(ow_bit_buffer *buffer, ow_DataStructure *object)");
|
||||
out.println("{");
|
||||
out.println(" switch( object->structType ) {");
|
||||
|
||||
for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
|
||||
JClass jclass = (JClass) iterator.next();
|
||||
String name = jclass.getSimpleName();
|
||||
String type = ("ow_"+name).toUpperCase()+"_TYPE";
|
||||
if( !isAbstract(jclass) ) {
|
||||
out.println(" case "+type+": return ow_marshal1_"+name+"(buffer, (ow_"+name+"*)object);");
|
||||
}
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" }");
|
||||
out.println(" return APR_EGENERAL;");
|
||||
out.println("}");
|
||||
out.println("");
|
||||
out.println("apr_status_t ow_marshal2_object(ow_byte_buffer *buffer, ow_bit_buffer *bitbuffer, ow_DataStructure *object)");
|
||||
out.println("{");
|
||||
out.println(" switch( object->structType ) {");
|
||||
|
||||
for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
|
||||
JClass jclass = (JClass) iterator.next();
|
||||
String name = jclass.getSimpleName();
|
||||
String type = ("ow_"+name).toUpperCase()+"_TYPE";
|
||||
if( !isAbstract(jclass) ) {
|
||||
out.println(" case "+type+": return ow_marshal2_"+name+"(buffer, bitbuffer, (ow_"+name+"*)object);");
|
||||
}
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" }");
|
||||
out.println(" return APR_EGENERAL;");
|
||||
out.println("}");
|
||||
out.println("");
|
||||
out.println("apr_status_t ow_unmarshal_object(ow_byte_array *buffer, ow_bit_buffer *bitbuffer, ow_DataStructure *object, apr_pool_t *pool)");
|
||||
out.println("{");
|
||||
out.println(" switch( object->structType ) {");
|
||||
|
||||
for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
|
||||
JClass jclass = (JClass) iterator.next();
|
||||
String name = jclass.getSimpleName();
|
||||
String type = ("ow_"+name).toUpperCase()+"_TYPE";
|
||||
if( !isAbstract(jclass) ) {
|
||||
out.println(" case "+type+": return ow_unmarshal_"+name+"(buffer, bitbuffer, (ow_"+name+"*)object, pool);");
|
||||
}
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" }");
|
||||
out.println(" return APR_EGENERAL;");
|
||||
out.println("}");
|
||||
|
||||
}
|
||||
}
|
|
@ -17,20 +17,26 @@
|
|||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
import org.codehaus.jam.JClass;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.codehaus.jam.JClass;
|
||||
import org.codehaus.jam.JProperty;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 409828 $
|
||||
*/
|
||||
public abstract class OpenWireCppClassesScript extends OpenWireClassesScript {
|
||||
public class CppClassesGenerator extends MultiSourceGenerator {
|
||||
|
||||
protected String targetDir="./src/main/cpp";
|
||||
|
||||
public Object run() {
|
||||
filePostFix = getFilePostFix();
|
||||
if (destDir == null) {
|
||||
destDir = new File("../openwire-cpp/src/main/cpp/activemq/command");
|
||||
destDir = new File(targetDir+"/activemq/command");
|
||||
}
|
||||
return super.run();
|
||||
}
|
||||
|
@ -207,4 +213,117 @@ public abstract class OpenWireCppClassesScript extends OpenWireClassesScript {
|
|||
else
|
||||
return "" ;
|
||||
}
|
||||
|
||||
|
||||
protected void generateLicence(PrintWriter out) {
|
||||
out.println("/*");
|
||||
out.println(" *");
|
||||
out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
|
||||
out.println(" * contributor license agreements. See the NOTICE file distributed with");
|
||||
out.println(" * this work for additional information regarding copyright ownership.");
|
||||
out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
|
||||
out.println(" * (the \"License\"); you may not use this file except in compliance with");
|
||||
out.println(" * the License. You may obtain a copy of the License at");
|
||||
out.println(" *");
|
||||
out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
|
||||
out.println(" *");
|
||||
out.println(" * Unless required by applicable law or agreed to in writing, software");
|
||||
out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
|
||||
out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
|
||||
out.println(" * See the License for the specific language governing permissions and");
|
||||
out.println(" * limitations under the License.");
|
||||
out.println(" */");
|
||||
}
|
||||
|
||||
protected void generateFile(PrintWriter out) throws Exception {
|
||||
generateLicence(out);
|
||||
out.println("#include \"activemq/command/"+className+".hpp\"");
|
||||
out.println("");
|
||||
out.println("using namespace apache::activemq::command;");
|
||||
out.println("");
|
||||
out.println("/*");
|
||||
out.println(" *");
|
||||
out.println(" * Command and marshalling code for OpenWire format for "+className+"");
|
||||
out.println(" *");
|
||||
out.println(" *");
|
||||
out.println(" * NOTE!: This file is autogenerated - do not modify!");
|
||||
out.println(" * if you need to make a change, please see the Groovy scripts in the");
|
||||
out.println(" * activemq-core module");
|
||||
out.println(" *");
|
||||
out.println(" */");
|
||||
out.println(""+className+"::"+className+"()");
|
||||
out.println("{");
|
||||
|
||||
List properties = getProperties();
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
String value = toCppDefaultValue(property.getType());
|
||||
String propertyName = property.getSimpleName();
|
||||
String parameterName = decapitalize(propertyName);
|
||||
out.println(" this->"+parameterName+" = "+value+" ;");
|
||||
}
|
||||
out.println("}");
|
||||
out.println("");
|
||||
out.println(""+className+"::~"+className+"()");
|
||||
out.println("{");
|
||||
out.println("}");
|
||||
out.println("");
|
||||
out.println("unsigned char "+className+"::getDataStructureType()");
|
||||
out.println("{");
|
||||
out.println(" return "+className+"::TYPE ; ");
|
||||
out.println("}");
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
String type = toCppType(property.getType());
|
||||
String propertyName = property.getSimpleName();
|
||||
String parameterName = decapitalize(propertyName);
|
||||
out.println("");
|
||||
out.println(" ");
|
||||
out.println(""+type+" "+className+"::get"+propertyName+"()");
|
||||
out.println("{");
|
||||
out.println(" return "+parameterName+" ;");
|
||||
out.println("}");
|
||||
out.println("");
|
||||
out.println("void "+className+"::set"+propertyName+"("+type+" "+parameterName+")");
|
||||
out.println("{");
|
||||
out.println(" this->"+parameterName+" = "+parameterName+" ;");
|
||||
out.println("}");
|
||||
}
|
||||
out.println("");
|
||||
out.println("int "+className+"::marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException)");
|
||||
out.println("{");
|
||||
out.println(" int size = 0 ;");
|
||||
out.println("");
|
||||
out.println(" size += "+baseClass+"::marshal(marshaller, mode, ostream) ; ");
|
||||
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
String marshalMethod = toMarshalMethodName(property.getType());
|
||||
String propertyName = decapitalize(property.getSimpleName());
|
||||
out.println(" size += marshaller->"+marshalMethod+"("+propertyName+", mode, ostream) ; ");
|
||||
}
|
||||
out.println(" return size ;");
|
||||
out.println("}");
|
||||
out.println("");
|
||||
out.println("void "+className+"::unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException)");
|
||||
out.println("{");
|
||||
out.println(" "+baseClass+"::unmarshal(marshaller, mode, istream) ; ");
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
String cast = toUnmarshalCast(property.getType());
|
||||
String unmarshalMethod = toUnmarshalMethodName(property.getType());
|
||||
String propertyName = decapitalize(property.getSimpleName());
|
||||
out.println(" "+propertyName+" = "+cast+"(marshaller->"+unmarshalMethod+"(mode, istream)) ; ");
|
||||
}
|
||||
out.println("}");
|
||||
}
|
||||
|
||||
public String getTargetDir() {
|
||||
return targetDir;
|
||||
}
|
||||
|
||||
public void setTargetDir(String targetDir) {
|
||||
this.targetDir = targetDir;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,133 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.Task;
|
||||
import org.codehaus.jam.JamService;
|
||||
import org.codehaus.jam.JamServiceFactory;
|
||||
import org.codehaus.jam.JamServiceParams;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 384826 $
|
||||
*/
|
||||
public class CppGeneratorTask extends Task {
|
||||
|
||||
int version = 2;
|
||||
File source = new File(".");
|
||||
File target = new File(".");
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Project project = new Project();
|
||||
project.init();
|
||||
CppGeneratorTask generator = new CppGeneratorTask();
|
||||
generator.setProject(project);
|
||||
|
||||
if( args.length > 0 ) {
|
||||
generator.version = Integer.parseInt(args[0]);
|
||||
}
|
||||
|
||||
if( args.length > 1 ) {
|
||||
generator.source = new File(args[1]);
|
||||
}
|
||||
|
||||
if( args.length > 2 ) {
|
||||
generator.target = new File(args[2]);
|
||||
}
|
||||
|
||||
generator.execute();
|
||||
}
|
||||
|
||||
public void execute() throws BuildException {
|
||||
try {
|
||||
|
||||
String sourceDir = source+"/src/main/java";
|
||||
|
||||
System.out.println("Parsing source files in: " + sourceDir);
|
||||
|
||||
JamServiceFactory jamServiceFactory = JamServiceFactory.getInstance();
|
||||
JamServiceParams params = jamServiceFactory.createServiceParams();
|
||||
File[] dirs = new File[]{new File(sourceDir)};
|
||||
params.includeSourcePattern(dirs, "**/*.java");
|
||||
JamService jam = jamServiceFactory.createService(params);
|
||||
|
||||
{
|
||||
CppClassesGenerator script = new CppClassesGenerator();
|
||||
script.setJam(jam);
|
||||
script.setTargetDir(target+"/src/main/cpp");
|
||||
script.setOpenwireVersion(version);
|
||||
script.run();
|
||||
}
|
||||
{
|
||||
CppHeadersGenerator script = new CppHeadersGenerator();
|
||||
script.setJam(jam);
|
||||
script.setTargetDir(target+"/src/main/cpp");
|
||||
script.setOpenwireVersion(version);
|
||||
script.run();
|
||||
}
|
||||
{
|
||||
CppMarshallingHeadersGenerator script = new CppMarshallingHeadersGenerator();
|
||||
script.setJam(jam);
|
||||
script.setTargetDir(target+"/src");
|
||||
script.setOpenwireVersion(version);
|
||||
script.run();
|
||||
}
|
||||
{
|
||||
CppMarshallingClassesGenerator script = new CppMarshallingClassesGenerator();
|
||||
script.setJam(jam);
|
||||
script.setTargetDir(target+"/src");
|
||||
script.setOpenwireVersion(version);
|
||||
script.run();
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new BuildException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public File getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
public void setSource(File basedir) {
|
||||
this.source = basedir;
|
||||
}
|
||||
|
||||
public File getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public void setTarget(File target) {
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.codehaus.jam.JClass;
|
||||
import org.codehaus.jam.JProperty;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 379734 $
|
||||
*/
|
||||
public class CppHeadersGenerator extends CppClassesGenerator {
|
||||
|
||||
protected String getFilePostFix() {
|
||||
return ".hpp";
|
||||
}
|
||||
|
||||
protected void generateFile(PrintWriter out) {
|
||||
generateLicence(out);
|
||||
|
||||
out.println("#ifndef ActiveMQ_"+className+"_hpp_");
|
||||
out.println("#define ActiveMQ_"+className+"_hpp_");
|
||||
out.println("");
|
||||
out.println("// Turn off warning message for ignored exception specification");
|
||||
out.println("#ifdef _MSC_VER");
|
||||
out.println("#pragma warning( disable : 4290 )");
|
||||
out.println("#endif");
|
||||
out.println("");
|
||||
out.println("#include <string>");
|
||||
out.println("#include \"activemq/command/"+baseClass+".hpp\"");
|
||||
|
||||
List properties = getProperties();
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
if( !property.getType().isPrimitiveType() &&
|
||||
!property.getType().getSimpleName().equals("String") &&
|
||||
!property.getType().getSimpleName().equals("ByteSequence") )
|
||||
{
|
||||
String includeName = toCppType(property.getType());
|
||||
if( property.getType().isArrayType() )
|
||||
{
|
||||
JClass arrayType = property.getType().getArrayComponentType();
|
||||
if( arrayType.isPrimitiveType() )
|
||||
continue ;
|
||||
}
|
||||
if( includeName.startsWith("array<") )
|
||||
includeName = includeName.substring(6, includeName.length()-1);
|
||||
else if( includeName.startsWith("p<") )
|
||||
includeName = includeName.substring(2, includeName.length()-1);
|
||||
|
||||
if( includeName.equals("IDataStructure") ) {
|
||||
out.println("#include \"activemq/"+includeName+".hpp\"");
|
||||
} else {
|
||||
out.println("#include \"activemq/command/"+includeName+".hpp\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
out.println("");
|
||||
out.println("#include \"activemq/protocol/IMarshaller.hpp\"");
|
||||
out.println("#include \"ppr/io/IOutputStream.hpp\"");
|
||||
out.println("#include \"ppr/io/IInputStream.hpp\"");
|
||||
out.println("#include \"ppr/io/IOException.hpp\"");
|
||||
out.println("#include \"ppr/util/ifr/array\"");
|
||||
out.println("#include \"ppr/util/ifr/p\"");
|
||||
out.println("");
|
||||
out.println("namespace apache");
|
||||
out.println("{");
|
||||
out.println(" namespace activemq");
|
||||
out.println(" {");
|
||||
out.println(" namespace command");
|
||||
out.println(" {");
|
||||
out.println(" using namespace ifr;");
|
||||
out.println(" using namespace std;");
|
||||
out.println(" using namespace apache::activemq;");
|
||||
out.println(" using namespace apache::activemq::protocol;");
|
||||
out.println(" using namespace apache::ppr::io;");
|
||||
out.println("");
|
||||
out.println("/*");
|
||||
out.println(" *");
|
||||
out.println(" * Command and marshalling code for OpenWire format for "+className+"");
|
||||
out.println(" *");
|
||||
out.println(" *");
|
||||
out.println(" * NOTE!: This file is autogenerated - do not modify!");
|
||||
out.println(" * if you need to make a change, please see the Groovy scripts in the");
|
||||
out.println(" * activemq-core module");
|
||||
out.println(" *");
|
||||
out.println(" */");
|
||||
out.println("class "+className+" : public "+baseClass+"");
|
||||
out.println("{");
|
||||
out.println("protected:");
|
||||
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
String type = toCppType(property.getType());
|
||||
String name = decapitalize(property.getSimpleName());
|
||||
out.println(" "+type+" "+name+" ;");
|
||||
}
|
||||
out.println("");
|
||||
out.println("public:");
|
||||
out.println(" const static unsigned char TYPE = "+getOpenWireOpCode(jclass)+";");
|
||||
out.println("");
|
||||
out.println("public:");
|
||||
out.println(" "+className+"() ;");
|
||||
out.println(" virtual ~"+className+"() ;");
|
||||
out.println("");
|
||||
out.println(" virtual unsigned char getDataStructureType() ;");
|
||||
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
String type = toCppType(property.getType());
|
||||
String propertyName = property.getSimpleName();
|
||||
String parameterName = decapitalize(propertyName);
|
||||
out.println("");
|
||||
out.println(" virtual "+type+" get"+propertyName+"() ;");
|
||||
out.println(" virtual void set"+propertyName+"("+type+" "+parameterName+") ;");
|
||||
}
|
||||
out.println("");
|
||||
out.println(" virtual int marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException) ;");
|
||||
out.println(" virtual void unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException) ;");
|
||||
out.println("} ;");
|
||||
out.println("");
|
||||
out.println("/* namespace */");
|
||||
out.println(" }");
|
||||
out.println(" }");
|
||||
out.println("}");
|
||||
out.println("");
|
||||
out.println("#endif /*ActiveMQ_"+className+"_hpp_*/");
|
||||
}
|
||||
|
||||
}
|
|
@ -23,6 +23,9 @@ import org.codehaus.jam.JClass;
|
|||
import org.codehaus.jam.JProperty;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -30,7 +33,7 @@ import java.util.List;
|
|||
*
|
||||
* @version $Revision: 381410 $
|
||||
*/
|
||||
public abstract class OpenWireCppMarshallingClassesScript extends OpenWireCppMarshallingHeadersScript {
|
||||
public class CppMarshallingClassesGenerator extends CppMarshallingHeadersGenerator {
|
||||
|
||||
protected String getFilePostFix() {
|
||||
return ".cpp";
|
||||
|
@ -239,4 +242,165 @@ public abstract class OpenWireCppMarshallingClassesScript extends OpenWireCppMar
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void generateFile(PrintWriter out) throws Exception {
|
||||
generateLicence(out);
|
||||
|
||||
out.println("#include \"marshal/"+className+".hpp\"");
|
||||
out.println("");
|
||||
out.println("using namespace apache::activemq::client::marshal;");
|
||||
out.println("");
|
||||
out.println("/*");
|
||||
out.println(" * Marshalling code for Open Wire Format for "+jclass.getSimpleName()+"");
|
||||
out.println(" *");
|
||||
out.println(" * NOTE!: This file is autogenerated - do not modify!");
|
||||
out.println(" * if you need to make a change, please see the Groovy scripts in the");
|
||||
out.println(" * activemq-core module");
|
||||
out.println(" */");
|
||||
out.println("");
|
||||
out.println(""+className+"::"+className+"()");
|
||||
out.println("{");
|
||||
out.println(" // no-op");
|
||||
out.println("}");
|
||||
out.println("");
|
||||
out.println(""+className+"::~"+className+"()");
|
||||
out.println("{");
|
||||
out.println(" // no-op");
|
||||
out.println("}");
|
||||
out.println("");
|
||||
|
||||
if( !isAbstractClass() ) {
|
||||
out.println("");
|
||||
out.println("");
|
||||
out.println("IDataStructure* "+className+"::createObject() ");
|
||||
out.println("{");
|
||||
out.println(" return new "+jclass.getSimpleName()+"();");
|
||||
out.println("}");
|
||||
out.println("");
|
||||
out.println("char "+className+"::getDataStructureType() ");
|
||||
out.println("{");
|
||||
out.println(" return "+jclass.getSimpleName()+".ID_"+jclass.getSimpleName()+";");
|
||||
out.println("}");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" /* ");
|
||||
out.println(" * Un-marshal an object instance from the data input stream");
|
||||
out.println(" */ ");
|
||||
out.println("void "+className+"::unmarshal(ProtocolFormat& wireFormat, Object o, BinaryReader& dataIn, BooleanStream& bs) ");
|
||||
out.println("{");
|
||||
out.println(" base.unmarshal(wireFormat, o, dataIn, bs);");
|
||||
|
||||
List properties = getProperties();
|
||||
boolean marshallerAware = isMarshallerAware();
|
||||
if( !properties.isEmpty() || marshallerAware ) {
|
||||
out.println("");
|
||||
out.println(" "+jclass.getSimpleName()+"& info = ("+jclass.getSimpleName()+"&) o;");
|
||||
}
|
||||
|
||||
if( marshallerAware ) {
|
||||
out.println("");
|
||||
out.println(" info.beforeUnmarshall(wireFormat);");
|
||||
out.println(" ");
|
||||
}
|
||||
|
||||
generateTightUnmarshalBody(out);
|
||||
|
||||
if( marshallerAware ) {
|
||||
out.println("");
|
||||
out.println(" info.afterUnmarshall(wireFormat);");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println("}");
|
||||
out.println("");
|
||||
out.println("");
|
||||
out.println("/*");
|
||||
out.println(" * Write the booleans that this object uses to a BooleanStream");
|
||||
out.println(" */");
|
||||
out.println("int "+className+"::marshal1(ProtocolFormat& wireFormat, Object& o, BooleanStream& bs) {");
|
||||
out.println(" "+jclass.getSimpleName()+"& info = ("+jclass.getSimpleName()+"&) o;");
|
||||
|
||||
|
||||
if( marshallerAware ) {
|
||||
out.println("");
|
||||
out.println(" info.beforeMarshall(wireFormat);");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" int rc = base.marshal1(wireFormat, info, bs);");
|
||||
|
||||
int baseSize = generateMarshal1Body(out);
|
||||
|
||||
out.println("");
|
||||
out.println(" return rc + "+baseSize+";");
|
||||
out.println("}");
|
||||
out.println("");
|
||||
out.println("/* ");
|
||||
out.println(" * Write a object instance to data output stream");
|
||||
out.println(" */");
|
||||
out.println("void "+className+"::marshal2(ProtocolFormat& wireFormat, Object& o, BinaryWriter& dataOut, BooleanStream& bs) {");
|
||||
out.println(" base.marshal2(wireFormat, o, dataOut, bs);");
|
||||
|
||||
if( !properties.isEmpty() || marshallerAware ) {
|
||||
out.println("");
|
||||
out.println(" "+jclass.getSimpleName()+"& info = ("+jclass.getSimpleName()+"&) o;");
|
||||
}
|
||||
|
||||
generateMarshal2Body(out);
|
||||
|
||||
if( marshallerAware ) {
|
||||
out.println("");
|
||||
out.println(" info.afterMarshall(wireFormat);");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println("}");
|
||||
}
|
||||
|
||||
public void generateFactory(PrintWriter out) {
|
||||
generateLicence(out);
|
||||
out.println("");
|
||||
out.println("// Marshalling code for Open Wire Format");
|
||||
out.println("//");
|
||||
out.println("//");
|
||||
out.println("// NOTE!: This file is autogenerated - do not modify!");
|
||||
out.println("// if you need to make a change, please see the Groovy scripts in the");
|
||||
out.println("// activemq-openwire module");
|
||||
out.println("//");
|
||||
out.println("");
|
||||
out.println("#include \"marshal/"+className+".hpp\"");
|
||||
out.println("");
|
||||
|
||||
List list = new ArrayList(getConcreteClasses());
|
||||
Collections.sort(list, new Comparator(){
|
||||
public int compare(Object o1, Object o2) {
|
||||
JClass c1 = (JClass) o1;
|
||||
JClass c2 = (JClass) o2;
|
||||
return c1.getSimpleName().compareTo(c2.getSimpleName());
|
||||
}});
|
||||
|
||||
for (Iterator iter = list.iterator(); iter.hasNext();) {
|
||||
JClass jclass = (JClass) iter.next();
|
||||
out.println("#include \"marshal/"+jclass.getSimpleName()+"Marshaller.hpp\"");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println("");
|
||||
out.println("using namespace apache::activemq::client::marshal;");
|
||||
out.println("");
|
||||
out.println("");
|
||||
out.println("void MarshallerFactory::configure(ProtocolFormat& format) ");
|
||||
out.println("{");
|
||||
|
||||
for (Iterator iter = list.iterator(); iter.hasNext();) {
|
||||
JClass jclass = (JClass) iter.next();
|
||||
out.println(" format.addMarshaller(new "+jclass.getSimpleName()+"Marshaller());");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println("}");
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,185 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 381410 $
|
||||
*/
|
||||
public class CppMarshallingHeadersGenerator extends JavaMarshallingGenerator {
|
||||
|
||||
protected String targetDir="./src";
|
||||
|
||||
public Object run() {
|
||||
filePostFix = getFilePostFix();
|
||||
if (destDir == null) {
|
||||
destDir = new File(targetDir+"/marshal");
|
||||
}
|
||||
return super.run();
|
||||
}
|
||||
|
||||
protected String getFilePostFix() {
|
||||
return ".hpp";
|
||||
}
|
||||
|
||||
|
||||
protected void generateLicence(PrintWriter out) {
|
||||
out.println("/*");
|
||||
out.println(" *");
|
||||
out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
|
||||
out.println(" * contributor license agreements. See the NOTICE file distributed with");
|
||||
out.println(" * this work for additional information regarding copyright ownership.");
|
||||
out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
|
||||
out.println(" * (the \"License\"); you may not use this file except in compliance with");
|
||||
out.println(" * the License. You may obtain a copy of the License at");
|
||||
out.println(" *");
|
||||
out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
|
||||
out.println(" *");
|
||||
out.println(" * Unless required by applicable law or agreed to in writing, software");
|
||||
out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
|
||||
out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
|
||||
out.println(" * See the License for the specific language governing permissions and");
|
||||
out.println(" * limitations under the License.");
|
||||
out.println(" */");
|
||||
}
|
||||
|
||||
protected void generateFile(PrintWriter out) throws Exception {
|
||||
generateLicence(out);
|
||||
|
||||
out.println("#ifndef "+className+"_hpp_");
|
||||
out.println("#define "+className+"_hpp_");
|
||||
out.println("");
|
||||
out.println("#include <string>");
|
||||
out.println("");
|
||||
out.println("#include \"command/IDataStructure.hpp\"");
|
||||
out.println("");
|
||||
out.println("/* we could cut this down - for now include all possible headers */");
|
||||
out.println("#include \"command/BrokerId.hpp\"");
|
||||
out.println("#include \"command/ConnectionId.hpp\"");
|
||||
out.println("#include \"command/ConsumerId.hpp\"");
|
||||
out.println("#include \"command/ProducerId.hpp\"");
|
||||
out.println("#include \"command/SessionId.hpp\"");
|
||||
out.println("");
|
||||
out.println("#include \"io/BinaryReader.hpp\"");
|
||||
out.println("#include \"io/BinaryWriter.hpp\"");
|
||||
out.println("");
|
||||
out.println("#include \"command/"+baseClass+".hpp\"");
|
||||
out.println("#include \"util/ifr/p.hpp\"");
|
||||
out.println("");
|
||||
out.println("#include \"protocol/ProtocolFormat.hpp\"");
|
||||
out.println("");
|
||||
out.println("namespace apache");
|
||||
out.println("{");
|
||||
out.println(" namespace activemq");
|
||||
out.println(" {");
|
||||
out.println(" namespace client");
|
||||
out.println(" {");
|
||||
out.println(" namespace marshal");
|
||||
out.println(" {");
|
||||
out.println(" using namespace ifr ;");
|
||||
out.println(" using namespace apache::activemq::client::command;");
|
||||
out.println(" using namespace apache::activemq::client::io;");
|
||||
out.println(" using namespace apache::activemq::client::protocol;");
|
||||
out.println("");
|
||||
out.println("/*");
|
||||
out.println(" *");
|
||||
out.println(" */");
|
||||
out.println("class "+className+" : public "+baseClass+"");
|
||||
out.println("{");
|
||||
out.println("public:");
|
||||
out.println(" "+className+"() ;");
|
||||
out.println(" virtual ~"+className+"() ;");
|
||||
out.println("");
|
||||
out.println(" virtual IDataStructure* createCommand() ;");
|
||||
out.println(" virtual char getDataStructureType() ;");
|
||||
out.println(" ");
|
||||
out.println(" virtual void unmarshal(ProtocolFormat& wireFormat, Object o, BinaryReader& dataIn, BooleanStream& bs) ;");
|
||||
out.println(" virtual int marshal1(ProtocolFormat& wireFormat, Object& o, BooleanStream& bs) ;");
|
||||
out.println(" virtual void marshal2(ProtocolFormat& wireFormat, Object& o, BinaryWriter& dataOut, BooleanStream& bs) ;");
|
||||
out.println("} ;");
|
||||
out.println("");
|
||||
out.println("/* namespace */");
|
||||
out.println(" }");
|
||||
out.println(" }");
|
||||
out.println(" }");
|
||||
out.println("}");
|
||||
out.println("#endif /*"+className+"_hpp_*/");
|
||||
}
|
||||
|
||||
public void generateFactory(PrintWriter out) {
|
||||
generateLicence(out);
|
||||
out.println("");
|
||||
out.println("// Marshalling code for Open Wire Format ");
|
||||
out.println("//");
|
||||
out.println("//");
|
||||
out.println("// NOTE!: This file is autogenerated - do not modify!");
|
||||
out.println("// if you need to make a change, please see the Groovy scripts in the");
|
||||
out.println("// activemq-openwire module");
|
||||
out.println("//");
|
||||
out.println("");
|
||||
out.println("#ifndef MarshallerFactory_hpp_");
|
||||
out.println("#define MarshallerFactory_hpp_");
|
||||
out.println("");
|
||||
out.println("");
|
||||
out.println("namespace apache");
|
||||
out.println("{");
|
||||
out.println(" namespace activemq");
|
||||
out.println(" {");
|
||||
out.println(" namespace client");
|
||||
out.println(" {");
|
||||
out.println(" namespace marshal");
|
||||
out.println(" {");
|
||||
out.println(" using namespace ifr ;");
|
||||
out.println(" using namespace std ;");
|
||||
out.println(" using namespace apache::activemq::client;");
|
||||
out.println(" using namespace apache::activemq::client::command;");
|
||||
out.println(" using namespace apache::activemq::client::io;");
|
||||
out.println("");
|
||||
out.println("/*");
|
||||
out.println(" * ");
|
||||
out.println(" */");
|
||||
out.println("class MarshallerFactory");
|
||||
out.println("{");
|
||||
out.println("public:");
|
||||
out.println(" MarshallerFactory() ;");
|
||||
out.println(" virtual ~MarshallerFactory() ;");
|
||||
out.println("");
|
||||
out.println(" virtual void configure(ProtocolFormat& format) ;");
|
||||
out.println("} ;");
|
||||
out.println("");
|
||||
out.println("/* namespace */");
|
||||
out.println(" }");
|
||||
out.println(" }");
|
||||
out.println(" }");
|
||||
out.println("}");
|
||||
out.println("");
|
||||
out.println("#endif /*MarshallerFactory_hpp_*/");
|
||||
out.println("");
|
||||
}
|
||||
|
||||
public String getTargetDir() {
|
||||
return targetDir;
|
||||
}
|
||||
|
||||
public void setTargetDir(String targetDir) {
|
||||
this.targetDir = targetDir;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.tools.ant.BuildException;
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.Task;
|
||||
import org.codehaus.jam.JamService;
|
||||
import org.codehaus.jam.JamServiceFactory;
|
||||
import org.codehaus.jam.JamServiceParams;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 384826 $
|
||||
*/
|
||||
public class JavaGeneratorTask extends Task {
|
||||
|
||||
int version = 2;
|
||||
File basedir = new File(".");
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Project project = new Project();
|
||||
project.init();
|
||||
JavaGeneratorTask generator = new JavaGeneratorTask();
|
||||
generator.setProject(project);
|
||||
|
||||
if( args.length > 0 ) {
|
||||
generator.version = Integer.parseInt(args[0]);
|
||||
}
|
||||
|
||||
if( args.length > 1 ) {
|
||||
generator.basedir = new File(args[1]);
|
||||
}
|
||||
|
||||
generator.execute();
|
||||
}
|
||||
|
||||
public void execute() throws BuildException {
|
||||
try {
|
||||
|
||||
String sourceDir = basedir+"/src/main/java";
|
||||
|
||||
System.out.println("Parsing source files in: " + sourceDir);
|
||||
|
||||
JamServiceFactory jamServiceFactory = JamServiceFactory.getInstance();
|
||||
JamServiceParams params = jamServiceFactory.createServiceParams();
|
||||
File[] dirs = new File[]{new File(sourceDir)};
|
||||
params.includeSourcePattern(dirs, "**/*.java");
|
||||
JamService jam = jamServiceFactory.createService(params);
|
||||
|
||||
{
|
||||
JavaMarshallingGenerator script = new JavaMarshallingGenerator();
|
||||
script.setJam(jam);
|
||||
script.setTargetDir(basedir+"/src/main/java");
|
||||
script.setOpenwireVersion(version);
|
||||
script.run();
|
||||
}
|
||||
{
|
||||
JavaTestsGenerator script = new JavaTestsGenerator();
|
||||
script.setJam(jam);
|
||||
script.setTargetDir(basedir+"/src/test/java");
|
||||
script.setOpenwireVersion(version);
|
||||
script.run();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new BuildException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(int version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public File getBasedir() {
|
||||
return basedir;
|
||||
}
|
||||
|
||||
public void setBasedir(File basedir) {
|
||||
this.basedir = basedir;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,733 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.codehaus.jam.JAnnotation;
|
||||
import org.codehaus.jam.JAnnotationValue;
|
||||
import org.codehaus.jam.JClass;
|
||||
import org.codehaus.jam.JPackage;
|
||||
import org.codehaus.jam.JProperty;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 384826 $
|
||||
*/
|
||||
public class JavaMarshallingGenerator extends MultiSourceGenerator {
|
||||
|
||||
protected List concreteClasses = new ArrayList();
|
||||
protected File factoryFile;
|
||||
protected String factoryFileName = "MarshallerFactory";
|
||||
protected String indent = " ";
|
||||
protected String targetDir="src/main/java";
|
||||
|
||||
public Object run() {
|
||||
if (destDir == null) {
|
||||
destDir = new File(targetDir+"/org/apache/activemq/openwire/v" + getOpenwireVersion());
|
||||
}
|
||||
Object answer = super.run();
|
||||
processFactory();
|
||||
return answer;
|
||||
}
|
||||
|
||||
protected void generateFile(PrintWriter out) throws Exception {
|
||||
|
||||
generateLicence(out);
|
||||
out.println("");
|
||||
out.println("package org.apache.activemq.openwire.v" + getOpenwireVersion() + ";");
|
||||
out.println("");
|
||||
out.println("import java.io.DataInputStream;");
|
||||
out.println("import java.io.DataOutputStream;");
|
||||
out.println("import java.io.IOException;");
|
||||
out.println("");
|
||||
out.println("import org.apache.activemq.openwire.*;");
|
||||
out.println("import org.apache.activemq.command.*;");
|
||||
out.println("");
|
||||
out.println("");
|
||||
for (int i = 0; i < getJclass().getImportedPackages().length; i++) {
|
||||
JPackage pkg = getJclass().getImportedPackages()[i];
|
||||
for (int j = 0; j < pkg.getClasses().length; j++) {
|
||||
JClass clazz = pkg.getClasses()[j];
|
||||
out.println("import " + clazz.getQualifiedName() + ";");
|
||||
}
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println("/**");
|
||||
out.println(" * Marshalling code for Open Wire Format for "+getClassName()+"");
|
||||
out.println(" *");
|
||||
out.println(" *");
|
||||
out.println(" * NOTE!: This file is auto generated - do not modify!");
|
||||
out.println(" * if you need to make a change, please see the modify the groovy scripts in the");
|
||||
out.println(" * under src/gram/script and then use maven openwire:generate to regenerate ");
|
||||
out.println(" * this file.");
|
||||
out.println(" *");
|
||||
out.println(" * @version $Revision$");
|
||||
out.println(" */");
|
||||
out.println("public " + getAbstractClassText() + "class " + getClassName() + " extends " + getBaseClass() + " {");
|
||||
out.println("");
|
||||
|
||||
if (!isAbstractClass()) {
|
||||
|
||||
out.println(" /**");
|
||||
out.println(" * Return the type of Data Structure we marshal");
|
||||
out.println(" * @return short representation of the type data structure");
|
||||
out.println(" */");
|
||||
out.println(" public byte getDataStructureType() {");
|
||||
out.println(" return "+getJclass().getSimpleName()+".DATA_STRUCTURE_TYPE;");
|
||||
out.println(" }");
|
||||
out.println(" ");
|
||||
out.println(" /**");
|
||||
out.println(" * @return a new object instance");
|
||||
out.println(" */");
|
||||
out.println(" public DataStructure createObject() {");
|
||||
out.println(" return new "+getJclass().getSimpleName()+"();");
|
||||
out.println(" }");
|
||||
out.println("");
|
||||
}
|
||||
|
||||
out.println(" /**");
|
||||
out.println(" * Un-marshal an object instance from the data input stream");
|
||||
out.println(" *");
|
||||
out.println(" * @param o the object to un-marshal");
|
||||
out.println(" * @param dataIn the data input stream to build the object from");
|
||||
out.println(" * @throws IOException");
|
||||
out.println(" */");
|
||||
out.println(" public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInputStream dataIn, BooleanStream bs) throws IOException {");
|
||||
out.println(" super.tightUnmarshal(wireFormat, o, dataIn, bs);");
|
||||
|
||||
if (!getProperties().isEmpty()) {
|
||||
out.println("");
|
||||
out.println(" " + getJclass().getSimpleName() + " info = (" + getJclass().getSimpleName() + ")o;");
|
||||
}
|
||||
|
||||
if (isMarshallerAware()) {
|
||||
out.println("");
|
||||
out.println(" info.beforeUnmarshall(wireFormat);");
|
||||
out.println(" ");
|
||||
}
|
||||
|
||||
generateTightUnmarshalBody(out);
|
||||
|
||||
if (isMarshallerAware()) {
|
||||
out.println("");
|
||||
out.println(" info.afterUnmarshall(wireFormat);");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" }");
|
||||
out.println("");
|
||||
out.println("");
|
||||
out.println(" /**");
|
||||
out.println(" * Write the booleans that this object uses to a BooleanStream");
|
||||
out.println(" */");
|
||||
out.println(" public int tightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) throws IOException {");
|
||||
|
||||
if (!getProperties().isEmpty()) {
|
||||
out.println("");
|
||||
out.println(" " + getJclass().getSimpleName() + " info = (" + getJclass().getSimpleName() + ")o;");
|
||||
}
|
||||
|
||||
if (isMarshallerAware()) {
|
||||
out.println("");
|
||||
out.println(" info.beforeMarshall(wireFormat);");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" int rc = super.tightMarshal1(wireFormat, o, bs);");
|
||||
int baseSize = generateTightMarshal1Body(out);
|
||||
|
||||
out.println("");
|
||||
out.println(" return rc + " + baseSize + ";");
|
||||
out.println(" }");
|
||||
out.println("");
|
||||
out.println(" /**");
|
||||
out.println(" * Write a object instance to data output stream");
|
||||
out.println(" *");
|
||||
out.println(" * @param o the instance to be marshaled");
|
||||
out.println(" * @param dataOut the output stream");
|
||||
out.println(" * @throws IOException thrown if an error occurs");
|
||||
out.println(" */");
|
||||
out.println(" public void tightMarshal2(OpenWireFormat wireFormat, Object o, DataOutputStream dataOut, BooleanStream bs) throws IOException {");
|
||||
out.println(" super.tightMarshal2(wireFormat, o, dataOut, bs);");
|
||||
if (!getProperties().isEmpty()) {
|
||||
out.println("");
|
||||
out.println(" " + getJclass().getSimpleName() + " info = (" + getJclass().getSimpleName() + ")o;");
|
||||
}
|
||||
|
||||
generateTightMarshal2Body(out);
|
||||
|
||||
if (isMarshallerAware()) {
|
||||
out.println("");
|
||||
out.println(" info.afterMarshall(wireFormat);");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" }");
|
||||
out.println("");
|
||||
out.println(" /**");
|
||||
out.println(" * Un-marshal an object instance from the data input stream");
|
||||
out.println(" *");
|
||||
out.println(" * @param o the object to un-marshal");
|
||||
out.println(" * @param dataIn the data input stream to build the object from");
|
||||
out.println(" * @throws IOException");
|
||||
out.println(" */");
|
||||
out.println(" public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInputStream dataIn) throws IOException {");
|
||||
out.println(" super.looseUnmarshal(wireFormat, o, dataIn);");
|
||||
|
||||
if (!getProperties().isEmpty()) {
|
||||
out.println("");
|
||||
out.println(" " + getJclass().getSimpleName() + " info = (" + getJclass().getSimpleName() + ")o;");
|
||||
}
|
||||
|
||||
if (isMarshallerAware()) {
|
||||
out.println("");
|
||||
out.println(" info.beforeUnmarshall(wireFormat);");
|
||||
out.println(" ");
|
||||
}
|
||||
|
||||
generateLooseUnmarshalBody(out);
|
||||
|
||||
if (isMarshallerAware()) {
|
||||
out.println("");
|
||||
out.println(" info.afterUnmarshall(wireFormat);");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" }");
|
||||
out.println("");
|
||||
out.println("");
|
||||
out.println(" /**");
|
||||
out.println(" * Write the booleans that this object uses to a BooleanStream");
|
||||
out.println(" */");
|
||||
out.println(" public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutputStream dataOut) throws IOException {");
|
||||
|
||||
if (!getProperties().isEmpty()) {
|
||||
out.println("");
|
||||
out.println(" " + getJclass().getSimpleName() + " info = (" + getJclass().getSimpleName() + ")o;");
|
||||
}
|
||||
|
||||
if (isMarshallerAware()) {
|
||||
out.println("");
|
||||
out.println(" info.beforeMarshall(wireFormat);");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" super.looseMarshal(wireFormat, o, dataOut);");
|
||||
|
||||
generateLooseMarshalBody(out);
|
||||
|
||||
out.println("");
|
||||
out.println(" }");
|
||||
out.println("}");
|
||||
}
|
||||
|
||||
private void generateLicence(PrintWriter out) {
|
||||
out.println("/**");
|
||||
out.println(" *");
|
||||
out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
|
||||
out.println(" * contributor license agreements. See the NOTICE file distributed with");
|
||||
out.println(" * this work for additional information regarding copyright ownership.");
|
||||
out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
|
||||
out.println(" * (the \"License\"); you may not use this file except in compliance with");
|
||||
out.println(" * the License. You may obtain a copy of the License at");
|
||||
out.println(" *");
|
||||
out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
|
||||
out.println(" *");
|
||||
out.println(" * Unless required by applicable law or agreed to in writing, software");
|
||||
out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
|
||||
out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
|
||||
out.println(" * See the License for the specific language governing permissions and");
|
||||
out.println(" * limitations under the License.");
|
||||
out.println(" */");
|
||||
}
|
||||
|
||||
protected void processFactory() {
|
||||
if (factoryFile == null) {
|
||||
factoryFile = new File(destDir, factoryFileName + filePostFix);
|
||||
}
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
out = new PrintWriter(new FileWriter(factoryFile));
|
||||
generateFactory(out);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateFactory(PrintWriter out) {
|
||||
generateLicence(out);
|
||||
out.println("");
|
||||
out.println("package org.apache.activemq.openwire.v"+getOpenwireVersion()+";");
|
||||
out.println("");
|
||||
out.println("import org.apache.activemq.openwire.DataStreamMarshaller;");
|
||||
out.println("import org.apache.activemq.openwire.OpenWireFormat;");
|
||||
out.println("");
|
||||
out.println("/**");
|
||||
out.println(" * MarshallerFactory for Open Wire Format.");
|
||||
out.println(" *");
|
||||
out.println(" *");
|
||||
out.println(" * NOTE!: This file is auto generated - do not modify!");
|
||||
out.println(" * if you need to make a change, please see the modify the groovy scripts in the");
|
||||
out.println(" * under src/gram/script and then use maven openwire:generate to regenerate ");
|
||||
out.println(" * this file.");
|
||||
out.println(" *");
|
||||
out.println(" * @version $Revision$");
|
||||
out.println(" */");
|
||||
out.println("public class MarshallerFactory {");
|
||||
out.println("");
|
||||
out.println(" /**");
|
||||
out.println(" * Creates a Map of command type -> Marshallers");
|
||||
out.println(" */");
|
||||
out.println(" static final private DataStreamMarshaller marshaller[] = new DataStreamMarshaller[256];");
|
||||
out.println(" static {");
|
||||
out.println("");
|
||||
|
||||
List list = new ArrayList(getConcreteClasses());
|
||||
Collections.sort(list, new Comparator(){
|
||||
public int compare(Object o1, Object o2) {
|
||||
JClass c1 = (JClass) o1;
|
||||
JClass c2 = (JClass) o2;
|
||||
return c1.getSimpleName().compareTo(c2.getSimpleName());
|
||||
}});
|
||||
|
||||
for (Iterator iter = list.iterator(); iter.hasNext();) {
|
||||
JClass jclass = (JClass) iter.next();
|
||||
out.println(" add(new " + jclass.getSimpleName() + "Marshaller());");
|
||||
}
|
||||
|
||||
out.println("");
|
||||
out.println(" }");
|
||||
out.println("");
|
||||
out.println(" static private void add(DataStreamMarshaller dsm) {");
|
||||
out.println(" marshaller[dsm.getDataStructureType()] = dsm;");
|
||||
out.println(" }");
|
||||
out.println(" ");
|
||||
out.println(" static public DataStreamMarshaller[] createMarshallerMap(OpenWireFormat wireFormat) {");
|
||||
out.println(" return marshaller;");
|
||||
out.println(" }");
|
||||
out.println("}");
|
||||
}
|
||||
|
||||
protected void processClass(JClass jclass) {
|
||||
super.processClass(jclass);
|
||||
|
||||
if (!jclass.isAbstract()) {
|
||||
concreteClasses.add(jclass);
|
||||
}
|
||||
}
|
||||
|
||||
protected String getClassName(JClass jclass) {
|
||||
return super.getClassName(jclass) + "Marshaller";
|
||||
}
|
||||
|
||||
protected String getBaseClassName(JClass jclass) {
|
||||
String answer = "BaseDataStreamMarshaller";
|
||||
JClass superclass = jclass.getSuperclass();
|
||||
if (superclass != null) {
|
||||
String superName = superclass.getSimpleName();
|
||||
if (!superName.equals("Object") && !superName.equals("JNDIBaseStorable") && !superName.equals("DataStructureSupport")) {
|
||||
answer = superName + "Marshaller";
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
protected void initialiseManuallyMaintainedClasses() {
|
||||
}
|
||||
|
||||
protected void generateTightUnmarshalBody(PrintWriter out) {
|
||||
List properties = getProperties();
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
JAnnotation annotation = property.getAnnotation("openwire:property");
|
||||
JAnnotationValue size = annotation.getValue("size");
|
||||
JClass propertyType = property.getType();
|
||||
String propertyTypeName = propertyType.getSimpleName();
|
||||
|
||||
if (propertyType.isArrayType() && !propertyTypeName.equals("byte[]")) {
|
||||
generateTightUnmarshalBodyForArrayProperty(out, property, size);
|
||||
} else {
|
||||
generateTightUnmarshalBodyForProperty(out, property, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateTightUnmarshalBodyForProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
|
||||
String setter = property.getSetter().getSimpleName();
|
||||
String type = property.getType().getSimpleName();
|
||||
|
||||
if (type.equals("boolean")) {
|
||||
out.println(" info." + setter + "(bs.readBoolean());");
|
||||
} else if (type.equals("byte")) {
|
||||
out.println(" info." + setter + "(dataIn.readByte());");
|
||||
} else if (type.equals("char")) {
|
||||
out.println(" info." + setter + "(dataIn.readChar());");
|
||||
} else if (type.equals("short")) {
|
||||
out.println(" info." + setter + "(dataIn.readShort());");
|
||||
} else if (type.equals("int")) {
|
||||
out.println(" info." + setter + "(dataIn.readInt());");
|
||||
} else if (type.equals("long")) {
|
||||
out.println(" info." + setter + "(tightUnmarshalLong(wireFormat, dataIn, bs));");
|
||||
} else if (type.equals("String")) {
|
||||
out.println(" info." + setter + "(tightUnmarshalString(dataIn, bs));");
|
||||
} else if (type.equals("byte[]")) {
|
||||
if (size != null) {
|
||||
out.println(" info." + setter + "(tightUnmarshalConstByteArray(dataIn, bs, " + size.asInt() + "));");
|
||||
} else {
|
||||
out.println(" info." + setter + "(tightUnmarshalByteArray(dataIn, bs));");
|
||||
}
|
||||
} else if (type.equals("ByteSequence")) {
|
||||
out.println(" info." + setter + "(tightUnmarshalByteSequence(dataIn, bs));");
|
||||
} else if (isThrowable(property.getType())) {
|
||||
out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") tightUnmarsalThrowable(wireFormat, dataIn, bs));");
|
||||
} else if (isCachedProperty(property)) {
|
||||
out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") tightUnmarsalCachedObject(wireFormat, dataIn, bs));");
|
||||
} else {
|
||||
out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") tightUnmarsalNestedObject(wireFormat, dataIn, bs));");
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateTightUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
|
||||
JClass propertyType = property.getType();
|
||||
String arrayType = propertyType.getArrayComponentType().getQualifiedName();
|
||||
String setter = property.getSetter().getSimpleName();
|
||||
out.println();
|
||||
if (size != null) {
|
||||
out.println(" {");
|
||||
out.println(" " + arrayType + " value[] = new " + arrayType + "[" + size.asInt() + "];");
|
||||
out.println(" " + "for( int i=0; i < " + size.asInt() + "; i++ ) {");
|
||||
out.println(" value[i] = (" + arrayType + ") tightUnmarsalNestedObject(wireFormat,dataIn, bs);");
|
||||
out.println(" }");
|
||||
out.println(" info." + setter + "(value);");
|
||||
out.println(" }");
|
||||
} else {
|
||||
out.println(" if (bs.readBoolean()) {");
|
||||
out.println(" short size = dataIn.readShort();");
|
||||
out.println(" " + arrayType + " value[] = new " + arrayType + "[size];");
|
||||
out.println(" for( int i=0; i < size; i++ ) {");
|
||||
out.println(" value[i] = (" + arrayType + ") tightUnmarsalNestedObject(wireFormat,dataIn, bs);");
|
||||
out.println(" }");
|
||||
out.println(" info." + setter + "(value);");
|
||||
out.println(" }");
|
||||
out.println(" else {");
|
||||
out.println(" info." + setter + "(null);");
|
||||
out.println(" }");
|
||||
}
|
||||
}
|
||||
|
||||
protected int generateTightMarshal1Body(PrintWriter out) {
|
||||
List properties = getProperties();
|
||||
int baseSize = 0;
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
JAnnotation annotation = property.getAnnotation("openwire:property");
|
||||
JAnnotationValue size = annotation.getValue("size");
|
||||
JClass propertyType = property.getType();
|
||||
String type = propertyType.getSimpleName();
|
||||
String getter = "info." + property.getGetter().getSimpleName() + "()";
|
||||
|
||||
if (type.equals("boolean")) {
|
||||
out.println(" bs.writeBoolean(" + getter + ");");
|
||||
} else if (type.equals("byte")) {
|
||||
baseSize += 1;
|
||||
} else if (type.equals("char")) {
|
||||
baseSize += 2;
|
||||
} else if (type.equals("short")) {
|
||||
baseSize += 2;
|
||||
} else if (type.equals("int")) {
|
||||
baseSize += 4;
|
||||
} else if (type.equals("long")) {
|
||||
out.println(" rc+=tightMarshalLong1(wireFormat, " + getter + ", bs);");
|
||||
} else if (type.equals("String")) {
|
||||
out.println(" rc += tightMarshalString1(" + getter + ", bs);");
|
||||
} else if (type.equals("byte[]")) {
|
||||
if (size == null) {
|
||||
out.println(" rc += tightMarshalByteArray1(" + getter + ", bs);");
|
||||
} else {
|
||||
out.println(" rc += tightMarshalConstByteArray1(" + getter + ", bs, " + size.asInt() + ");");
|
||||
}
|
||||
} else if (type.equals("ByteSequence")) {
|
||||
out.println(" rc += tightMarshalByteSequence1(" + getter + ", bs);");
|
||||
} else if (propertyType.isArrayType()) {
|
||||
if (size != null) {
|
||||
out.println(" rc += tightMarshalObjectArrayConstSize1(wireFormat, " + getter + ", bs, " + size.asInt() + ");");
|
||||
} else {
|
||||
out.println(" rc += tightMarshalObjectArray1(wireFormat, " + getter + ", bs);");
|
||||
}
|
||||
} else if (isThrowable(propertyType)) {
|
||||
out.println(" rc += tightMarshalThrowable1(wireFormat, " + getter + ", bs);");
|
||||
} else {
|
||||
if (isCachedProperty(property)) {
|
||||
out.println(" rc += tightMarshalCachedObject1(wireFormat, (DataStructure)" + getter + ", bs);");
|
||||
} else {
|
||||
out.println(" rc += tightMarshalNestedObject1(wireFormat, (DataStructure)" + getter + ", bs);");
|
||||
}
|
||||
}
|
||||
}
|
||||
return baseSize;
|
||||
}
|
||||
|
||||
protected void generateTightMarshal2Body(PrintWriter out) {
|
||||
List properties = getProperties();
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
JAnnotation annotation = property.getAnnotation("openwire:property");
|
||||
JAnnotationValue size = annotation.getValue("size");
|
||||
JClass propertyType = property.getType();
|
||||
String type = propertyType.getSimpleName();
|
||||
String getter = "info." + property.getGetter().getSimpleName() + "()";
|
||||
|
||||
if (type.equals("boolean")) {
|
||||
out.println(" bs.readBoolean();");
|
||||
} else if (type.equals("byte")) {
|
||||
out.println(" dataOut.writeByte(" + getter + ");");
|
||||
} else if (type.equals("char")) {
|
||||
out.println(" dataOut.writeChar(" + getter + ");");
|
||||
} else if (type.equals("short")) {
|
||||
out.println(" dataOut.writeShort(" + getter + ");");
|
||||
} else if (type.equals("int")) {
|
||||
out.println(" dataOut.writeInt(" + getter + ");");
|
||||
} else if (type.equals("long")) {
|
||||
out.println(" tightMarshalLong2(wireFormat, " + getter + ", dataOut, bs);");
|
||||
} else if (type.equals("String")) {
|
||||
out.println(" tightMarshalString2(" + getter + ", dataOut, bs);");
|
||||
} else if (type.equals("byte[]")) {
|
||||
String mandatory = getMandatoryFlag(annotation);
|
||||
if (size != null) {
|
||||
out.println(" tightMarshalConstByteArray2(" + getter + ", dataOut, bs, " + size.asInt() + ");");
|
||||
} else {
|
||||
out.println(" tightMarshalByteArray2(" + getter + ", dataOut, bs);");
|
||||
}
|
||||
} else if (type.equals("ByteSequence")) {
|
||||
out.println(" tightMarshalByteSequence2(" + getter + ", dataOut, bs);");
|
||||
} else if (propertyType.isArrayType()) {
|
||||
if (size != null) {
|
||||
out.println(" tightMarshalObjectArrayConstSize2(wireFormat, " + getter + ", dataOut, bs, " + size.asInt() + ");");
|
||||
} else {
|
||||
out.println(" tightMarshalObjectArray2(wireFormat, " + getter + ", dataOut, bs);");
|
||||
}
|
||||
} else if (isThrowable(propertyType)) {
|
||||
out.println(" tightMarshalThrowable2(wireFormat, " + getter + ", dataOut, bs);");
|
||||
} else {
|
||||
if (isCachedProperty(property)) {
|
||||
out.println(" tightMarshalCachedObject2(wireFormat, (DataStructure)" + getter + ", dataOut, bs);");
|
||||
} else {
|
||||
out.println(" tightMarshalNestedObject2(wireFormat, (DataStructure)" + getter + ", dataOut, bs);");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateLooseMarshalBody(PrintWriter out) {
|
||||
List properties = getProperties();
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
JAnnotation annotation = property.getAnnotation("openwire:property");
|
||||
JAnnotationValue size = annotation.getValue("size");
|
||||
JClass propertyType = property.getType();
|
||||
String type = propertyType.getSimpleName();
|
||||
String getter = "info." + property.getGetter().getSimpleName() + "()";
|
||||
|
||||
if (type.equals("boolean")) {
|
||||
out.println(" dataOut.writeBoolean(" + getter + ");");
|
||||
} else if (type.equals("byte")) {
|
||||
out.println(" dataOut.writeByte(" + getter + ");");
|
||||
} else if (type.equals("char")) {
|
||||
out.println(" dataOut.writeChar(" + getter + ");");
|
||||
} else if (type.equals("short")) {
|
||||
out.println(" dataOut.writeShort(" + getter + ");");
|
||||
} else if (type.equals("int")) {
|
||||
out.println(" dataOut.writeInt(" + getter + ");");
|
||||
} else if (type.equals("long")) {
|
||||
out.println(" looseMarshalLong(wireFormat, " + getter + ", dataOut);");
|
||||
} else if (type.equals("String")) {
|
||||
out.println(" looseMarshalString(" + getter + ", dataOut);");
|
||||
} else if (type.equals("byte[]")) {
|
||||
if (size != null) {
|
||||
out.println(" looseMarshalConstByteArray(wireFormat, " + getter + ", dataOut, " + size.asInt() + ");");
|
||||
} else {
|
||||
out.println(" looseMarshalByteArray(wireFormat, " + getter + ", dataOut);");
|
||||
}
|
||||
} else if (type.equals("ByteSequence")) {
|
||||
out.println(" looseMarshalByteSequence(wireFormat, " + getter + ", dataOut);");
|
||||
} else if (propertyType.isArrayType()) {
|
||||
if (size != null) {
|
||||
out.println(" looseMarshalObjectArrayConstSize(wireFormat, " + getter + ", dataOut, " + size.asInt() + ");");
|
||||
} else {
|
||||
out.println(" looseMarshalObjectArray(wireFormat, " + getter + ", dataOut);");
|
||||
}
|
||||
} else if (isThrowable(propertyType)) {
|
||||
out.println(" looseMarshalThrowable(wireFormat, " + getter + ", dataOut);");
|
||||
} else {
|
||||
if (isCachedProperty(property)) {
|
||||
out.println(" looseMarshalCachedObject(wireFormat, (DataStructure)" + getter + ", dataOut);");
|
||||
} else {
|
||||
out.println(" looseMarshalNestedObject(wireFormat, (DataStructure)" + getter + ", dataOut);");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateLooseUnmarshalBody(PrintWriter out) {
|
||||
List properties = getProperties();
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
JAnnotation annotation = property.getAnnotation("openwire:property");
|
||||
JAnnotationValue size = annotation.getValue("size");
|
||||
JClass propertyType = property.getType();
|
||||
String propertyTypeName = propertyType.getSimpleName();
|
||||
|
||||
if (propertyType.isArrayType() && !propertyTypeName.equals("byte[]")) {
|
||||
generateLooseUnmarshalBodyForArrayProperty(out, property, size);
|
||||
} else {
|
||||
generateLooseUnmarshalBodyForProperty(out, property, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateLooseUnmarshalBodyForProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
|
||||
String setter = property.getSetter().getSimpleName();
|
||||
String type = property.getType().getSimpleName();
|
||||
|
||||
if (type.equals("boolean")) {
|
||||
out.println(" info." + setter + "(dataIn.readBoolean());");
|
||||
} else if (type.equals("byte")) {
|
||||
out.println(" info." + setter + "(dataIn.readByte());");
|
||||
} else if (type.equals("char")) {
|
||||
out.println(" info." + setter + "(dataIn.readChar());");
|
||||
} else if (type.equals("short")) {
|
||||
out.println(" info." + setter + "(dataIn.readShort());");
|
||||
} else if (type.equals("int")) {
|
||||
out.println(" info." + setter + "(dataIn.readInt());");
|
||||
} else if (type.equals("long")) {
|
||||
out.println(" info." + setter + "(looseUnmarshalLong(wireFormat, dataIn));");
|
||||
} else if (type.equals("String")) {
|
||||
out.println(" info." + setter + "(looseUnmarshalString(dataIn));");
|
||||
} else if (type.equals("byte[]")) {
|
||||
if (size != null) {
|
||||
out.println(" info." + setter + "(looseUnmarshalConstByteArray(dataIn, " + size.asInt() + "));");
|
||||
} else {
|
||||
out.println(" info." + setter + "(looseUnmarshalByteArray(dataIn));");
|
||||
}
|
||||
} else if (type.equals("ByteSequence")) {
|
||||
out.println(" info." + setter + "(looseUnmarshalByteSequence(dataIn));");
|
||||
} else if (isThrowable(property.getType())) {
|
||||
out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") looseUnmarsalThrowable(wireFormat, dataIn));");
|
||||
} else if (isCachedProperty(property)) {
|
||||
out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") looseUnmarsalCachedObject(wireFormat, dataIn));");
|
||||
} else {
|
||||
out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") looseUnmarsalNestedObject(wireFormat, dataIn));");
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateLooseUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
|
||||
JClass propertyType = property.getType();
|
||||
String arrayType = propertyType.getArrayComponentType().getQualifiedName();
|
||||
String setter = property.getSetter().getSimpleName();
|
||||
out.println();
|
||||
if (size != null) {
|
||||
out.println(" {");
|
||||
out.println(" " + arrayType + " value[] = new " + arrayType + "[" + size.asInt() + "];");
|
||||
out.println(" " + "for( int i=0; i < " + size.asInt() + "; i++ ) {");
|
||||
out.println(" value[i] = (" + arrayType + ") looseUnmarsalNestedObject(wireFormat,dataIn);");
|
||||
out.println(" }");
|
||||
out.println(" info." + setter + "(value);");
|
||||
out.println(" }");
|
||||
} else {
|
||||
out.println(" if (dataIn.readBoolean()) {");
|
||||
out.println(" short size = dataIn.readShort();");
|
||||
out.println(" " + arrayType + " value[] = new " + arrayType + "[size];");
|
||||
out.println(" for( int i=0; i < size; i++ ) {");
|
||||
out.println(" value[i] = (" + arrayType + ") looseUnmarsalNestedObject(wireFormat,dataIn);");
|
||||
out.println(" }");
|
||||
out.println(" info." + setter + "(value);");
|
||||
out.println(" }");
|
||||
out.println(" else {");
|
||||
out.println(" info." + setter + "(null);");
|
||||
out.println(" }");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the given annotation has a mandatory flag on it or
|
||||
* not
|
||||
*/
|
||||
protected String getMandatoryFlag(JAnnotation annotation) {
|
||||
JAnnotationValue value = annotation.getValue("mandatory");
|
||||
if (value != null) {
|
||||
String text = value.asString();
|
||||
if (text != null && text.equalsIgnoreCase("true")) {
|
||||
return "true";
|
||||
}
|
||||
}
|
||||
return "false";
|
||||
}
|
||||
|
||||
public List getConcreteClasses() {
|
||||
return concreteClasses;
|
||||
}
|
||||
|
||||
public void setConcreteClasses(List concreteClasses) {
|
||||
this.concreteClasses = concreteClasses;
|
||||
}
|
||||
|
||||
public File getFactoryFile() {
|
||||
return factoryFile;
|
||||
}
|
||||
|
||||
public void setFactoryFile(File factoryFile) {
|
||||
this.factoryFile = factoryFile;
|
||||
}
|
||||
|
||||
public String getFactoryFileName() {
|
||||
return factoryFileName;
|
||||
}
|
||||
|
||||
public void setFactoryFileName(String factoryFileName) {
|
||||
this.factoryFileName = factoryFileName;
|
||||
}
|
||||
|
||||
public String getIndent() {
|
||||
return indent;
|
||||
}
|
||||
|
||||
public void setIndent(String indent) {
|
||||
this.indent = indent;
|
||||
}
|
||||
|
||||
public String getTargetDir() {
|
||||
return targetDir;
|
||||
}
|
||||
|
||||
public void setTargetDir(String sourceDir) {
|
||||
this.targetDir = sourceDir;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,216 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.codehaus.jam.JAnnotation;
|
||||
import org.codehaus.jam.JClass;
|
||||
import org.codehaus.jam.JPackage;
|
||||
import org.codehaus.jam.JProperty;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 384826 $
|
||||
*/
|
||||
public class JavaTestsGenerator extends MultiSourceGenerator {
|
||||
|
||||
protected String targetDir="src/test/java";
|
||||
|
||||
public Object run() {
|
||||
if (destDir == null) {
|
||||
destDir = new File(targetDir+"/org/apache/activemq/openwire/v" + getOpenwireVersion());
|
||||
}
|
||||
return super.run();
|
||||
}
|
||||
|
||||
protected String getClassName(JClass jclass) {
|
||||
if( isAbstract(jclass) ) {
|
||||
return super.getClassName(jclass) + "TestSupport";
|
||||
} else {
|
||||
return super.getClassName(jclass) + "Test";
|
||||
}
|
||||
}
|
||||
|
||||
protected String getBaseClassName(JClass jclass) {
|
||||
String answer = "DataFileGeneratorTestSupport";
|
||||
if (superclass != null) {
|
||||
String name = superclass.getSimpleName();
|
||||
if (name!=null
|
||||
&& !name.equals("JNDIBaseStorable")
|
||||
&& !name.equals("DataStructureSupport")
|
||||
&& !name.equals("Object")) {
|
||||
answer = name + "Test";
|
||||
if (isAbstract(getJclass().getSuperclass()))
|
||||
answer += "Support";
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
private void generateLicence(PrintWriter out) {
|
||||
out.println("/**");
|
||||
out.println(" *");
|
||||
out.println(" * Licensed to the Apache Software Foundation (ASF) under one or more");
|
||||
out.println(" * contributor license agreements. See the NOTICE file distributed with");
|
||||
out.println(" * this work for additional information regarding copyright ownership.");
|
||||
out.println(" * The ASF licenses this file to You under the Apache License, Version 2.0");
|
||||
out.println(" * (the \"License\"); you may not use this file except in compliance with");
|
||||
out.println(" * the License. You may obtain a copy of the License at");
|
||||
out.println(" *");
|
||||
out.println(" * http://www.apache.org/licenses/LICENSE-2.0");
|
||||
out.println(" *");
|
||||
out.println(" * Unless required by applicable law or agreed to in writing, software");
|
||||
out.println(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
|
||||
out.println(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
|
||||
out.println(" * See the License for the specific language governing permissions and");
|
||||
out.println(" * limitations under the License.");
|
||||
out.println(" */");
|
||||
}
|
||||
|
||||
protected void generateFile(PrintWriter out) {
|
||||
|
||||
generateLicence(out);
|
||||
|
||||
out.println("package org.apache.activemq.openwire.v"+openwireVersion+";");
|
||||
out.println("");
|
||||
out.println("import java.io.DataInputStream;");
|
||||
out.println("import java.io.DataOutputStream;");
|
||||
out.println("import java.io.IOException;");
|
||||
out.println("");
|
||||
out.println("import org.apache.activemq.openwire.*;");
|
||||
out.println("import org.apache.activemq.command.*;");
|
||||
out.println("");
|
||||
for (int i = 0; i < getJclass().getImportedPackages().length; i++) {
|
||||
JPackage pkg = getJclass().getImportedPackages()[i];
|
||||
for (int j = 0; j < pkg.getClasses().length; j++) {
|
||||
JClass clazz = pkg.getClasses()[j];
|
||||
out.println("import " + clazz.getQualifiedName() + ";");
|
||||
}
|
||||
}
|
||||
|
||||
boolean marshallerAware = isMarshallAware(jclass);
|
||||
|
||||
out.println("");
|
||||
out.println("/**");
|
||||
out.println(" * Test case for the OpenWire marshalling for "+jclass.getSimpleName()+"");
|
||||
out.println(" *");
|
||||
out.println(" *");
|
||||
out.println(" * NOTE!: This file is auto generated - do not modify!");
|
||||
out.println(" * if you need to make a change, please see the modify the groovy scripts in the");
|
||||
out.println(" * under src/gram/script and then use maven openwire:generate to regenerate ");
|
||||
out.println(" * this file.");
|
||||
out.println(" *");
|
||||
out.println(" * @version $Revision: $");
|
||||
out.println(" */");
|
||||
out.println("public "+getAbstractClassText()+"class "+className+" extends "+baseClass+" {");
|
||||
out.println("");
|
||||
if (!isAbstractClass()) {
|
||||
out.println("");
|
||||
out.println(" public static "+jclass.getSimpleName()+"Test SINGLETON = new "+jclass.getSimpleName()+"Test();");
|
||||
out.println("");
|
||||
out.println(" public Object createObject() throws Exception {");
|
||||
out.println(" "+jclass.getSimpleName()+" info = new "+jclass.getSimpleName()+"();");
|
||||
out.println(" populateObject(info);");
|
||||
out.println(" return info;");
|
||||
out.println(" }");
|
||||
}
|
||||
out.println("");
|
||||
out.println(" protected void populateObject(Object object) throws Exception {");
|
||||
out.println(" super.populateObject(object);");
|
||||
out.println(" "+getJclass().getSimpleName()+" info = ("+getJclass().getSimpleName()+") object;");
|
||||
out.println("");
|
||||
|
||||
TestDataGenerator generator = new TestDataGenerator();
|
||||
|
||||
List properties = getProperties();
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
|
||||
JAnnotation annotation = property.getAnnotation("openwire:property");
|
||||
String size = stringValue(annotation, "size");
|
||||
String testSize = stringValue(annotation, "testSize");
|
||||
String type = property.getType().getSimpleName();
|
||||
boolean cached = isCachedProperty(property);
|
||||
String propertyName = property.getSimpleName();
|
||||
if ("-1".equals(testSize))
|
||||
continue;
|
||||
|
||||
|
||||
String setterName = property.getSetter().getSimpleName();
|
||||
|
||||
if( type.equals("boolean")) {
|
||||
out.println(" info."+setterName+"("+generator.createBool()+");");
|
||||
} else if( type.equals("byte")) {
|
||||
out.println(" info."+setterName+"("+generator.createByte()+");");
|
||||
} else if( type.equals("char")) {
|
||||
out.println(" info."+setterName+"("+generator.createChar()+");");
|
||||
} else if( type.equals("short")) {
|
||||
out.println(" info."+setterName+"("+generator.createShort()+");");
|
||||
} else if( type.equals("int")) {
|
||||
out.println(" info."+setterName+"("+generator.createInt()+");");
|
||||
} else if( type.equals("long")) {
|
||||
out.println(" info."+setterName+"("+generator.createLong()+");");
|
||||
} else if( type.equals("byte[]")) {
|
||||
out.println(" info."+setterName+"("+generator.createByteArray(propertyName)+");");
|
||||
} else if( type.equals("String")) {
|
||||
out.println(" info."+setterName+"(\""+generator.createString(propertyName)+"\");");
|
||||
} else if( type.equals("ByteSequence")) {
|
||||
out.println(" {");
|
||||
out.println(" byte data[] = "+generator.createByteArray(propertyName)+";");
|
||||
out.println(" info."+setterName+"(new org.apache.activemq.util.ByteSequence(data,0,data.length));");
|
||||
out.println( "}");
|
||||
} else if( type.equals("Throwable")) {
|
||||
out.println(" info."+setterName+"(createThrowable(\""+generator.createString(propertyName)+"\"));");
|
||||
} else {
|
||||
if( property.getType().isArrayType() ) {
|
||||
String arrayType = property.getType().getArrayComponentType().getSimpleName();
|
||||
if (size == null)
|
||||
size = "2";
|
||||
if (arrayType == jclass.getSimpleName())
|
||||
size = "0";
|
||||
out.println(" {");
|
||||
out.println(" "+arrayType+" value[] = new "+arrayType+"["+size+"];");
|
||||
out.println(" for( int i=0; i < "+size+"; i++ ) {");
|
||||
out.println(" value[i] = create"+arrayType+"(\""+generator.createString(propertyName)+"\");");
|
||||
out.println(" }");
|
||||
out.println(" info."+setterName+"(value);");
|
||||
out.println(" }");
|
||||
} else {
|
||||
out.println(" info."+setterName+"(create"+type+"(\""+generator.createString(propertyName)+"\"));");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
out.println(" }");
|
||||
out.println("}");
|
||||
}
|
||||
|
||||
public String getTargetDir() {
|
||||
return targetDir;
|
||||
}
|
||||
|
||||
public void setTargetDir(String targetDir) {
|
||||
this.targetDir = targetDir;
|
||||
}
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ import org.codehaus.jam.JamClassIterator;
|
|||
*
|
||||
* @version $Revision: 386442 $
|
||||
*/
|
||||
public abstract class OpenWireClassesScript extends OpenWireScript {
|
||||
public abstract class MultiSourceGenerator extends OpenWireGenerator {
|
||||
protected Set manuallyMaintainedClasses = new HashSet();
|
||||
protected File destDir;
|
||||
protected File destFile;
|
||||
|
@ -47,7 +47,7 @@ public abstract class OpenWireClassesScript extends OpenWireScript {
|
|||
protected String baseClass;
|
||||
protected StringBuffer buffer;
|
||||
|
||||
public OpenWireClassesScript() {
|
||||
public MultiSourceGenerator() {
|
||||
initialiseManuallyMaintainedClasses();
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ public abstract class OpenWireClassesScript extends OpenWireScript {
|
|||
fixCRLF.execute();
|
||||
}
|
||||
|
||||
protected abstract void generateFile(PrintWriter out);
|
||||
protected abstract void generateFile(PrintWriter out) throws Exception;
|
||||
|
||||
protected String getBaseClassName(JClass jclass) {
|
||||
String answer = "BaseDataStructure";
|
|
@ -1,90 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.codehaus.jam.JProperty;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 383749 $
|
||||
*/
|
||||
public abstract class OpenWireCSharpClassesScript extends OpenWireClassesScript {
|
||||
|
||||
public Object run() {
|
||||
filePostFix = ".cs";
|
||||
if (destDir == null) {
|
||||
destDir = new File("../activemq-dotnet/src/main/csharp/ActiveMQ/Commands");
|
||||
}
|
||||
|
||||
return super.run();
|
||||
}
|
||||
|
||||
public String makeHashCodeBody() throws Exception {
|
||||
if (simpleName.endsWith("Id")) {
|
||||
StringWriter buffer = new StringWriter();
|
||||
PrintWriter out = new PrintWriter(buffer);
|
||||
out.println(" int answer = 0;");
|
||||
Iterator iter = getProperties().iterator();
|
||||
while (iter.hasNext()) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
out.println(" answer = (answer * 37) + HashCode(" + property.getSimpleName() + ");");
|
||||
}
|
||||
out.println(" return answer;");
|
||||
return buffer.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String makeEqualsBody() throws Exception {
|
||||
if (simpleName.endsWith("Id")) {
|
||||
StringWriter buffer = new StringWriter();
|
||||
PrintWriter out = new PrintWriter(buffer);
|
||||
|
||||
Iterator iter = getProperties().iterator();
|
||||
while (iter.hasNext()) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
String name = property.getSimpleName();
|
||||
out.println(" if (! Equals(this." + name + ", that." + name + ")) return false;");
|
||||
}
|
||||
out.println(" return true;");
|
||||
return buffer.toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String makeToStringBody() throws Exception {
|
||||
StringWriter buffer = new StringWriter();
|
||||
PrintWriter out = new PrintWriter(buffer);
|
||||
out.println(" return GetType().Name + \"[\"");
|
||||
Iterator iter = getProperties().iterator();
|
||||
while (iter.hasNext()) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
String name = property.getSimpleName();
|
||||
out.println(" + \" " + name + "=\" + " + name);
|
||||
}
|
||||
out.println(" + \" ]\";");
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 379734 $
|
||||
*/
|
||||
public abstract class OpenWireCppHeadersScript extends OpenWireCppClassesScript {
|
||||
|
||||
protected String getFilePostFix() {
|
||||
return ".hpp";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 381410 $
|
||||
*/
|
||||
public abstract class OpenWireCppMarshallingHeadersScript extends OpenWireJavaMarshallingScript {
|
||||
|
||||
public Object run() {
|
||||
filePostFix = getFilePostFix();
|
||||
if (destDir == null) {
|
||||
destDir = new File("../openwire-cpp/src/marshal");
|
||||
}
|
||||
return super.run();
|
||||
}
|
||||
|
||||
protected String getFilePostFix() {
|
||||
return ".hpp";
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
import org.codehaus.gram.GramSupport;
|
||||
import org.codehaus.jam.JAnnotation;
|
||||
import org.codehaus.jam.JAnnotationValue;
|
||||
import org.codehaus.jam.JClass;
|
||||
import org.codehaus.jam.JField;
|
||||
|
@ -29,12 +29,14 @@ import org.codehaus.jam.JamService;
|
|||
/**
|
||||
* @version $Revision$
|
||||
*/
|
||||
public abstract class OpenWireScript extends GramSupport {
|
||||
public abstract class OpenWireGenerator {
|
||||
|
||||
private String openwireVersion;
|
||||
protected int openwireVersion;
|
||||
protected String filePostFix = ".java";
|
||||
protected JamService jam;
|
||||
|
||||
|
||||
public boolean isValidProperty(JProperty it) {
|
||||
public boolean isValidProperty(JProperty it) {
|
||||
JMethod getter = it.getGetter();
|
||||
return getter != null && it.getSetter() != null && getter.isStatic() == false && getter.getAnnotation("openwire:property") != null;
|
||||
}
|
||||
|
@ -74,8 +76,7 @@ public abstract class OpenWireScript extends GramSupport {
|
|||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
String simpleName = j.getSimpleName();
|
||||
return simpleName.equals("ActiveMQMessage") || simpleName.equals("WireFormatInfo");
|
||||
}
|
||||
|
@ -88,21 +89,18 @@ public abstract class OpenWireScript extends GramSupport {
|
|||
}
|
||||
|
||||
public JamService getJam() {
|
||||
return (JamService) getBinding().getVariable("jam");
|
||||
return jam;
|
||||
}
|
||||
|
||||
public JamClassIterator getClasses() {
|
||||
return getJam().getClasses();
|
||||
}
|
||||
|
||||
public String getOpenwireVersion() {
|
||||
if (openwireVersion == null) {
|
||||
openwireVersion = (String) getProperty("version");
|
||||
}
|
||||
public int getOpenwireVersion() {
|
||||
return openwireVersion;
|
||||
}
|
||||
|
||||
public void setOpenwireVersion(String openwireVersion) {
|
||||
public void setOpenwireVersion(int openwireVersion) {
|
||||
this.openwireVersion = openwireVersion;
|
||||
}
|
||||
|
||||
|
@ -128,7 +126,43 @@ public abstract class OpenWireScript extends GramSupport {
|
|||
}
|
||||
}
|
||||
|
||||
public String getOpenWireOpCode(JClass aClass) {
|
||||
return annotationValue(aClass, "openwire:marshaller", "code", "0");
|
||||
public String getOpenWireOpCode(JClass element) {
|
||||
if (element != null) {
|
||||
JAnnotation annotation = element.getAnnotation("openwire:marshaller");
|
||||
return stringValue(annotation, "code", "0");
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
|
||||
protected String stringValue(JAnnotation annotation, String name) {
|
||||
return stringValue(annotation, name, null);
|
||||
}
|
||||
|
||||
protected String stringValue(JAnnotation annotation, String name, String defaultValue) {
|
||||
if (annotation != null) {
|
||||
JAnnotationValue value = annotation.getValue(name);
|
||||
if (value != null) {
|
||||
return value.asString();
|
||||
}
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setJam(JamService jam) {
|
||||
this.jam = jam;
|
||||
}
|
||||
|
||||
public String decapitalize(String text) {
|
||||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
return text.substring(0, 1).toLowerCase() + text.substring(1);
|
||||
}
|
||||
|
||||
public String capitalize(String text) {
|
||||
if (text == null) {
|
||||
return null;
|
||||
}
|
||||
return text.substring(0, 1).toUpperCase() + text.substring(1);
|
||||
}
|
||||
}
|
|
@ -1,530 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.codehaus.jam.JAnnotation;
|
||||
import org.codehaus.jam.JAnnotationValue;
|
||||
import org.codehaus.jam.JClass;
|
||||
import org.codehaus.jam.JProperty;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 384826 $
|
||||
*/
|
||||
public abstract class OpenWireJavaMarshallingScript extends OpenWireClassesScript {
|
||||
|
||||
protected List concreteClasses = new ArrayList();
|
||||
protected File factoryFile;
|
||||
protected String factoryFileName = "MarshallerFactory";
|
||||
protected String indent = " ";
|
||||
|
||||
public Object run() {
|
||||
if (destDir == null) {
|
||||
destDir = new File("src/main/java/org/apache/activemq/openwire/v" + getOpenwireVersion());
|
||||
}
|
||||
Object answer = super.run();
|
||||
processFactory();
|
||||
return answer;
|
||||
}
|
||||
|
||||
protected void processFactory() {
|
||||
if (factoryFile == null) {
|
||||
factoryFile = new File(destDir, factoryFileName + filePostFix);
|
||||
}
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
out = new PrintWriter(new FileWriter(factoryFile));
|
||||
generateFactory(out);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void generateFactory(PrintWriter out);
|
||||
|
||||
protected void processClass(JClass jclass) {
|
||||
super.processClass(jclass);
|
||||
|
||||
if (!jclass.isAbstract()) {
|
||||
concreteClasses.add(jclass);
|
||||
}
|
||||
}
|
||||
|
||||
protected String getClassName(JClass jclass) {
|
||||
return super.getClassName(jclass) + "Marshaller";
|
||||
}
|
||||
|
||||
protected String getBaseClassName(JClass jclass) {
|
||||
String answer = "BaseDataStreamMarshaller";
|
||||
JClass superclass = jclass.getSuperclass();
|
||||
if (superclass != null) {
|
||||
String superName = superclass.getSimpleName();
|
||||
if (!superName.equals("Object") && !superName.equals("JNDIBaseStorable") && !superName.equals("DataStructureSupport")) {
|
||||
answer = superName + "Marshaller";
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
protected void initialiseManuallyMaintainedClasses() {
|
||||
}
|
||||
|
||||
protected void generateTightUnmarshalBody(PrintWriter out) {
|
||||
List properties = getProperties();
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
JAnnotation annotation = property.getAnnotation("openwire:property");
|
||||
JAnnotationValue size = annotation.getValue("size");
|
||||
JClass propertyType = property.getType();
|
||||
String propertyTypeName = propertyType.getSimpleName();
|
||||
|
||||
if (propertyType.isArrayType() && !propertyTypeName.equals("byte[]")) {
|
||||
generateTightUnmarshalBodyForArrayProperty(out, property, size);
|
||||
}
|
||||
else {
|
||||
generateTightUnmarshalBodyForProperty(out, property, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateTightUnmarshalBodyForProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
|
||||
String setter = property.getSetter().getSimpleName();
|
||||
String type = property.getType().getSimpleName();
|
||||
|
||||
if (type.equals("boolean")) {
|
||||
out.println(" info." + setter + "(bs.readBoolean());");
|
||||
}
|
||||
else if (type.equals("byte")) {
|
||||
out.println(" info." + setter + "(dataIn.readByte());");
|
||||
}
|
||||
else if (type.equals("char")) {
|
||||
out.println(" info." + setter + "(dataIn.readChar());");
|
||||
}
|
||||
else if (type.equals("short")) {
|
||||
out.println(" info." + setter + "(dataIn.readShort());");
|
||||
}
|
||||
else if (type.equals("int")) {
|
||||
out.println(" info." + setter + "(dataIn.readInt());");
|
||||
}
|
||||
else if (type.equals("long")) {
|
||||
out.println(" info." + setter + "(tightUnmarshalLong(wireFormat, dataIn, bs));");
|
||||
}
|
||||
else if (type.equals("String")) {
|
||||
out.println(" info." + setter + "(tightUnmarshalString(dataIn, bs));");
|
||||
}
|
||||
else if (type.equals("byte[]")) {
|
||||
if (size != null) {
|
||||
out.println(" info." + setter + "(tightUnmarshalConstByteArray(dataIn, bs, "+ size.asInt() +"));");
|
||||
}
|
||||
else {
|
||||
out.println(" info." + setter + "(tightUnmarshalByteArray(dataIn, bs));");
|
||||
}
|
||||
}
|
||||
else if (type.equals("ByteSequence")) {
|
||||
out.println(" info." + setter + "(tightUnmarshalByteSequence(dataIn, bs));");
|
||||
}
|
||||
else if (isThrowable(property.getType())) {
|
||||
out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") tightUnmarsalThrowable(wireFormat, dataIn, bs));");
|
||||
}
|
||||
else if (isCachedProperty(property)) {
|
||||
out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") tightUnmarsalCachedObject(wireFormat, dataIn, bs));");
|
||||
}
|
||||
else {
|
||||
out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") tightUnmarsalNestedObject(wireFormat, dataIn, bs));");
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateTightUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
|
||||
JClass propertyType = property.getType();
|
||||
String arrayType = propertyType.getArrayComponentType().getQualifiedName();
|
||||
String setter = property.getSetter().getSimpleName();
|
||||
out.println();
|
||||
if (size != null) {
|
||||
out.println(" {");
|
||||
out.println(" " + arrayType + " value[] = new " + arrayType + "[" + size.asInt() + "];");
|
||||
out.println(" " + "for( int i=0; i < " + size.asInt() + "; i++ ) {");
|
||||
out.println(" value[i] = (" + arrayType + ") tightUnmarsalNestedObject(wireFormat,dataIn, bs);");
|
||||
out.println(" }");
|
||||
out.println(" info." + setter + "(value);");
|
||||
out.println(" }");
|
||||
}
|
||||
else {
|
||||
out.println(" if (bs.readBoolean()) {");
|
||||
out.println(" short size = dataIn.readShort();");
|
||||
out.println(" " + arrayType + " value[] = new " + arrayType + "[size];");
|
||||
out.println(" for( int i=0; i < size; i++ ) {");
|
||||
out.println(" value[i] = (" + arrayType + ") tightUnmarsalNestedObject(wireFormat,dataIn, bs);");
|
||||
out.println(" }");
|
||||
out.println(" info." + setter + "(value);");
|
||||
out.println(" }");
|
||||
out.println(" else {");
|
||||
out.println(" info." + setter + "(null);");
|
||||
out.println(" }");
|
||||
}
|
||||
}
|
||||
|
||||
protected int generateTightMarshal1Body(PrintWriter out) {
|
||||
List properties = getProperties();
|
||||
int baseSize = 0;
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
JAnnotation annotation = property.getAnnotation("openwire:property");
|
||||
JAnnotationValue size = annotation.getValue("size");
|
||||
JClass propertyType = property.getType();
|
||||
String type = propertyType.getSimpleName();
|
||||
String getter = "info." + property.getGetter().getSimpleName() + "()";
|
||||
|
||||
if (type.equals("boolean")) {
|
||||
out.println(" bs.writeBoolean(" + getter + ");");
|
||||
}
|
||||
else if (type.equals("byte")) {
|
||||
baseSize += 1;
|
||||
}
|
||||
else if (type.equals("char")) {
|
||||
baseSize += 2;
|
||||
}
|
||||
else if (type.equals("short")) {
|
||||
baseSize += 2;
|
||||
}
|
||||
else if (type.equals("int")) {
|
||||
baseSize += 4;
|
||||
}
|
||||
else if (type.equals("long")) {
|
||||
out.println(" rc+=tightMarshalLong1(wireFormat, " + getter + ", bs);");
|
||||
}
|
||||
else if (type.equals("String")) {
|
||||
out.println(" rc += tightMarshalString1(" + getter + ", bs);");
|
||||
}
|
||||
else if (type.equals("byte[]")) {
|
||||
if (size == null) {
|
||||
out.println(" rc += tightMarshalByteArray1(" + getter + ", bs);");
|
||||
}
|
||||
else {
|
||||
out.println(" rc += tightMarshalConstByteArray1(" + getter + ", bs, "+size.asInt()+");");
|
||||
}
|
||||
}
|
||||
else if (type.equals("ByteSequence")) {
|
||||
out.println(" rc += tightMarshalByteSequence1(" + getter + ", bs);");
|
||||
}
|
||||
else if (propertyType.isArrayType()) {
|
||||
if (size != null) {
|
||||
out.println(" rc += tightMarshalObjectArrayConstSize1(wireFormat, " + getter + ", bs, " + size.asInt() + ");");
|
||||
}
|
||||
else {
|
||||
out.println(" rc += tightMarshalObjectArray1(wireFormat, " + getter + ", bs);");
|
||||
}
|
||||
}
|
||||
else if (isThrowable(propertyType)) {
|
||||
out.println(" rc += tightMarshalThrowable1(wireFormat, " + getter + ", bs);");
|
||||
}
|
||||
else {
|
||||
if (isCachedProperty(property)) {
|
||||
out.println(" rc += tightMarshalCachedObject1(wireFormat, (DataStructure)" + getter + ", bs);");
|
||||
}
|
||||
else {
|
||||
out.println(" rc += tightMarshalNestedObject1(wireFormat, (DataStructure)" + getter + ", bs);");
|
||||
}
|
||||
}
|
||||
}
|
||||
return baseSize;
|
||||
}
|
||||
|
||||
protected void generateTightMarshal2Body(PrintWriter out) {
|
||||
List properties = getProperties();
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
JAnnotation annotation = property.getAnnotation("openwire:property");
|
||||
JAnnotationValue size = annotation.getValue("size");
|
||||
JClass propertyType = property.getType();
|
||||
String type = propertyType.getSimpleName();
|
||||
String getter = "info." + property.getGetter().getSimpleName() + "()";
|
||||
|
||||
if (type.equals("boolean")) {
|
||||
out.println(" bs.readBoolean();");
|
||||
}
|
||||
else if (type.equals("byte")) {
|
||||
out.println(" dataOut.writeByte(" + getter + ");");
|
||||
}
|
||||
else if (type.equals("char")) {
|
||||
out.println(" dataOut.writeChar(" + getter + ");");
|
||||
}
|
||||
else if (type.equals("short")) {
|
||||
out.println(" dataOut.writeShort(" + getter + ");");
|
||||
}
|
||||
else if (type.equals("int")) {
|
||||
out.println(" dataOut.writeInt(" + getter + ");");
|
||||
}
|
||||
else if (type.equals("long")) {
|
||||
out.println(" tightMarshalLong2(wireFormat, " + getter + ", dataOut, bs);");
|
||||
}
|
||||
else if (type.equals("String")) {
|
||||
out.println(" tightMarshalString2(" + getter + ", dataOut, bs);");
|
||||
}
|
||||
else if (type.equals("byte[]")) {
|
||||
String mandatory = getMandatoryFlag(annotation);
|
||||
if (size != null) {
|
||||
out.println(" tightMarshalConstByteArray2(" + getter + ", dataOut, bs, " + size.asInt() + ");");
|
||||
}
|
||||
else {
|
||||
out.println(" tightMarshalByteArray2(" + getter + ", dataOut, bs);");
|
||||
}
|
||||
}
|
||||
else if (type.equals("ByteSequence")) {
|
||||
out.println(" tightMarshalByteSequence2(" + getter + ", dataOut, bs);");
|
||||
}
|
||||
else if (propertyType.isArrayType()) {
|
||||
if (size != null) {
|
||||
out.println(" tightMarshalObjectArrayConstSize2(wireFormat, " + getter + ", dataOut, bs, " + size.asInt() + ");");
|
||||
}
|
||||
else {
|
||||
out.println(" tightMarshalObjectArray2(wireFormat, " + getter + ", dataOut, bs);");
|
||||
}
|
||||
}
|
||||
else if (isThrowable(propertyType)) {
|
||||
out.println(" tightMarshalThrowable2(wireFormat, " + getter + ", dataOut, bs);");
|
||||
}
|
||||
else {
|
||||
if (isCachedProperty(property)) {
|
||||
out.println(" tightMarshalCachedObject2(wireFormat, (DataStructure)" + getter + ", dataOut, bs);");
|
||||
}
|
||||
else {
|
||||
out.println(" tightMarshalNestedObject2(wireFormat, (DataStructure)" + getter + ", dataOut, bs);");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void generateLooseMarshalBody(PrintWriter out) {
|
||||
List properties = getProperties();
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
JAnnotation annotation = property.getAnnotation("openwire:property");
|
||||
JAnnotationValue size = annotation.getValue("size");
|
||||
JClass propertyType = property.getType();
|
||||
String type = propertyType.getSimpleName();
|
||||
String getter = "info." + property.getGetter().getSimpleName() + "()";
|
||||
|
||||
if (type.equals("boolean")) {
|
||||
out.println(" dataOut.writeBoolean("+ getter + ");");
|
||||
}
|
||||
else if (type.equals("byte")) {
|
||||
out.println(" dataOut.writeByte(" + getter + ");");
|
||||
}
|
||||
else if (type.equals("char")) {
|
||||
out.println(" dataOut.writeChar(" + getter + ");");
|
||||
}
|
||||
else if (type.equals("short")) {
|
||||
out.println(" dataOut.writeShort(" + getter + ");");
|
||||
}
|
||||
else if (type.equals("int")) {
|
||||
out.println(" dataOut.writeInt(" + getter + ");");
|
||||
}
|
||||
else if (type.equals("long")) {
|
||||
out.println(" looseMarshalLong(wireFormat, " + getter + ", dataOut);");
|
||||
}
|
||||
else if (type.equals("String")) {
|
||||
out.println(" looseMarshalString(" + getter + ", dataOut);");
|
||||
}
|
||||
else if (type.equals("byte[]")) {
|
||||
if (size != null) {
|
||||
out.println(" looseMarshalConstByteArray(wireFormat, " + getter + ", dataOut, " + size.asInt() + ");");
|
||||
}
|
||||
else {
|
||||
out.println(" looseMarshalByteArray(wireFormat, " + getter + ", dataOut);");
|
||||
}
|
||||
}
|
||||
else if (type.equals("ByteSequence")) {
|
||||
out.println(" looseMarshalByteSequence(wireFormat, " + getter + ", dataOut);");
|
||||
}
|
||||
else if (propertyType.isArrayType()) {
|
||||
if (size != null) {
|
||||
out.println(" looseMarshalObjectArrayConstSize(wireFormat, " + getter + ", dataOut, " + size.asInt() + ");");
|
||||
}
|
||||
else {
|
||||
out.println(" looseMarshalObjectArray(wireFormat, " + getter + ", dataOut);");
|
||||
}
|
||||
}
|
||||
else if (isThrowable(propertyType)) {
|
||||
out.println(" looseMarshalThrowable(wireFormat, " + getter + ", dataOut);");
|
||||
}
|
||||
else {
|
||||
if (isCachedProperty(property)) {
|
||||
out.println(" looseMarshalCachedObject(wireFormat, (DataStructure)" + getter + ", dataOut);");
|
||||
}
|
||||
else {
|
||||
out.println(" looseMarshalNestedObject(wireFormat, (DataStructure)" + getter + ", dataOut);");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void generateLooseUnmarshalBody(PrintWriter out) {
|
||||
List properties = getProperties();
|
||||
for (Iterator iter = properties.iterator(); iter.hasNext();) {
|
||||
JProperty property = (JProperty) iter.next();
|
||||
JAnnotation annotation = property.getAnnotation("openwire:property");
|
||||
JAnnotationValue size = annotation.getValue("size");
|
||||
JClass propertyType = property.getType();
|
||||
String propertyTypeName = propertyType.getSimpleName();
|
||||
|
||||
if (propertyType.isArrayType() && !propertyTypeName.equals("byte[]")) {
|
||||
generateLooseUnmarshalBodyForArrayProperty(out, property, size);
|
||||
}
|
||||
else {
|
||||
generateLooseUnmarshalBodyForProperty(out, property, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateLooseUnmarshalBodyForProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
|
||||
String setter = property.getSetter().getSimpleName();
|
||||
String type = property.getType().getSimpleName();
|
||||
|
||||
if (type.equals("boolean")) {
|
||||
out.println(" info." + setter + "(dataIn.readBoolean());");
|
||||
}
|
||||
else if (type.equals("byte")) {
|
||||
out.println(" info." + setter + "(dataIn.readByte());");
|
||||
}
|
||||
else if (type.equals("char")) {
|
||||
out.println(" info." + setter + "(dataIn.readChar());");
|
||||
}
|
||||
else if (type.equals("short")) {
|
||||
out.println(" info." + setter + "(dataIn.readShort());");
|
||||
}
|
||||
else if (type.equals("int")) {
|
||||
out.println(" info." + setter + "(dataIn.readInt());");
|
||||
}
|
||||
else if (type.equals("long")) {
|
||||
out.println(" info." + setter + "(looseUnmarshalLong(wireFormat, dataIn));");
|
||||
}
|
||||
else if (type.equals("String")) {
|
||||
out.println(" info." + setter + "(looseUnmarshalString(dataIn));");
|
||||
}
|
||||
else if (type.equals("byte[]")) {
|
||||
if (size != null) {
|
||||
out.println(" info." + setter + "(looseUnmarshalConstByteArray(dataIn, " + size.asInt() + "));");
|
||||
}
|
||||
else {
|
||||
out.println(" info." + setter + "(looseUnmarshalByteArray(dataIn));");
|
||||
}
|
||||
}
|
||||
else if (type.equals("ByteSequence")) {
|
||||
out.println(" info." + setter + "(looseUnmarshalByteSequence(dataIn));");
|
||||
}
|
||||
else if (isThrowable(property.getType())) {
|
||||
out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") looseUnmarsalThrowable(wireFormat, dataIn));");
|
||||
}
|
||||
else if (isCachedProperty(property)) {
|
||||
out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") looseUnmarsalCachedObject(wireFormat, dataIn));");
|
||||
}
|
||||
else {
|
||||
out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") looseUnmarsalNestedObject(wireFormat, dataIn));");
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateLooseUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
|
||||
JClass propertyType = property.getType();
|
||||
String arrayType = propertyType.getArrayComponentType().getQualifiedName();
|
||||
String setter = property.getSetter().getSimpleName();
|
||||
out.println();
|
||||
if (size != null) {
|
||||
out.println(" {");
|
||||
out.println(" " + arrayType + " value[] = new " + arrayType + "[" + size.asInt() + "];");
|
||||
out.println(" " + "for( int i=0; i < " + size.asInt() + "; i++ ) {");
|
||||
out.println(" value[i] = (" + arrayType + ") looseUnmarsalNestedObject(wireFormat,dataIn);");
|
||||
out.println(" }");
|
||||
out.println(" info." + setter + "(value);");
|
||||
out.println(" }");
|
||||
}
|
||||
else {
|
||||
out.println(" if (dataIn.readBoolean()) {");
|
||||
out.println(" short size = dataIn.readShort();");
|
||||
out.println(" " + arrayType + " value[] = new " + arrayType + "[size];");
|
||||
out.println(" for( int i=0; i < size; i++ ) {");
|
||||
out.println(" value[i] = (" + arrayType + ") looseUnmarsalNestedObject(wireFormat,dataIn);");
|
||||
out.println(" }");
|
||||
out.println(" info." + setter + "(value);");
|
||||
out.println(" }");
|
||||
out.println(" else {");
|
||||
out.println(" info." + setter + "(null);");
|
||||
out.println(" }");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the given annotation has a mandatory flag on it or not
|
||||
*/
|
||||
protected String getMandatoryFlag(JAnnotation annotation) {
|
||||
JAnnotationValue value = annotation.getValue("mandatory");
|
||||
if (value != null) {
|
||||
String text = value.asString();
|
||||
if (text != null && text.equalsIgnoreCase("true")) {
|
||||
return "true";
|
||||
}
|
||||
}
|
||||
return "false";
|
||||
}
|
||||
|
||||
public List getConcreteClasses() {
|
||||
return concreteClasses;
|
||||
}
|
||||
|
||||
public void setConcreteClasses(List concreteClasses) {
|
||||
this.concreteClasses = concreteClasses;
|
||||
}
|
||||
|
||||
public File getFactoryFile() {
|
||||
return factoryFile;
|
||||
}
|
||||
|
||||
public void setFactoryFile(File factoryFile) {
|
||||
this.factoryFile = factoryFile;
|
||||
}
|
||||
|
||||
public String getFactoryFileName() {
|
||||
return factoryFileName;
|
||||
}
|
||||
|
||||
public void setFactoryFileName(String factoryFileName) {
|
||||
this.factoryFileName = factoryFileName;
|
||||
}
|
||||
|
||||
public String getIndent() {
|
||||
return indent;
|
||||
}
|
||||
|
||||
public void setIndent(String indent) {
|
||||
this.indent = indent;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,238 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.openwire.tool;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.taskdefs.FixCRLF;
|
||||
import org.codehaus.jam.JClass;
|
||||
import org.codehaus.jam.JProperty;
|
||||
import org.codehaus.jam.JamClassIterator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision: 386442 $
|
||||
*/
|
||||
public abstract class SingleSourceGenerator extends OpenWireGenerator {
|
||||
|
||||
protected Set manuallyMaintainedClasses = new HashSet();
|
||||
protected File destFile;
|
||||
|
||||
protected JClass jclass;
|
||||
protected JClass superclass;
|
||||
protected String simpleName;
|
||||
protected String className;
|
||||
protected String baseClass;
|
||||
protected List sortedClasses;
|
||||
|
||||
public SingleSourceGenerator() {
|
||||
initialiseManuallyMaintainedClasses();
|
||||
}
|
||||
|
||||
public Object run() {
|
||||
|
||||
if (destFile == null) {
|
||||
throw new IllegalArgumentException("No destFile defined!");
|
||||
}
|
||||
destFile.getParentFile().mkdirs();
|
||||
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
out = new PrintWriter(new FileWriter(destFile));
|
||||
|
||||
ArrayList classes = new ArrayList();
|
||||
JamClassIterator iter = getClasses();
|
||||
while (iter.hasNext()) {
|
||||
jclass = iter.nextClass();
|
||||
if (isValidClass(jclass)) {
|
||||
classes.add(jclass);
|
||||
}
|
||||
}
|
||||
sortedClasses = sort(classes);
|
||||
|
||||
generateSetup(out);
|
||||
for (Iterator iterator = sortedClasses.iterator(); iterator.hasNext();) {
|
||||
jclass = (JClass) iterator.next();
|
||||
simpleName = jclass.getSimpleName();
|
||||
superclass = jclass.getSuperclass();
|
||||
className = getClassName(jclass);
|
||||
baseClass = getBaseClassName(jclass);
|
||||
|
||||
System.out.println(getClass().getName() + " processing class: " + simpleName);
|
||||
generateFile(out);
|
||||
}
|
||||
generateTearDown(out);
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Use the FixCRLF Ant Task to make sure the file has consistent newlines
|
||||
// so that SVN does not complain on checkin.
|
||||
Project project = new Project();
|
||||
project.init();
|
||||
FixCRLF fixCRLF = new FixCRLF();
|
||||
fixCRLF.setProject(project);
|
||||
fixCRLF.setSrcdir(destFile.getParentFile());
|
||||
fixCRLF.setIncludes(destFile.getName());
|
||||
fixCRLF.execute();
|
||||
return null;
|
||||
}
|
||||
|
||||
protected List sort(List classes) {
|
||||
return classes;
|
||||
}
|
||||
|
||||
protected void generateTearDown(PrintWriter out) {
|
||||
}
|
||||
|
||||
protected void generateSetup(PrintWriter out) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the valid properties available on the current class
|
||||
*/
|
||||
public List getProperties() {
|
||||
List answer = new ArrayList();
|
||||
JProperty[] properties = jclass.getDeclaredProperties();
|
||||
for (int i = 0; i < properties.length; i++) {
|
||||
JProperty property = properties[i];
|
||||
if (isValidProperty(property)) {
|
||||
answer.add(property);
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
protected boolean isValidClass(JClass jclass) {
|
||||
if (jclass==null || jclass.getAnnotation("openwire:marshaller") == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
//return !manuallyMaintainedClasses.contains(jclass.getSimpleName());
|
||||
}
|
||||
|
||||
|
||||
protected abstract void generateFile(PrintWriter out) throws Exception;
|
||||
|
||||
protected String getBaseClassName(JClass jclass) {
|
||||
String answer = "BaseDataStructure";
|
||||
if (superclass != null) {
|
||||
String name = superclass.getSimpleName();
|
||||
if (name != null && !name.equals("Object")) {
|
||||
answer = name;
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
protected String getClassName(JClass jclass) {
|
||||
return jclass.getSimpleName();
|
||||
}
|
||||
|
||||
public boolean isAbstractClass() {
|
||||
return jclass != null & jclass.isAbstract();
|
||||
}
|
||||
|
||||
public String getAbstractClassText() {
|
||||
return isAbstractClass() ? "abstract " : "";
|
||||
}
|
||||
|
||||
public boolean isMarshallerAware() {
|
||||
return isMarshallAware(jclass);
|
||||
}
|
||||
|
||||
protected void initialiseManuallyMaintainedClasses() {
|
||||
String[] names = { "ActiveMQDestination", "ActiveMQTempDestination", "ActiveMQQueue", "ActiveMQTopic", "ActiveMQTempQueue", "ActiveMQTempTopic",
|
||||
"BaseCommand", "ActiveMQMessage", "ActiveMQTextMessage", "ActiveMQMapMessage", "ActiveMQBytesMessage", "ActiveMQStreamMessage",
|
||||
"ActiveMQStreamMessage", "DataStructureSupport", "WireFormatInfo", "ActiveMQObjectMessage" };
|
||||
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
manuallyMaintainedClasses.add(names[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public String getBaseClass() {
|
||||
return baseClass;
|
||||
}
|
||||
|
||||
public void setBaseClass(String baseClass) {
|
||||
this.baseClass = baseClass;
|
||||
}
|
||||
|
||||
public String getClassName() {
|
||||
return className;
|
||||
}
|
||||
|
||||
public void setClassName(String className) {
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
public File getDestFile() {
|
||||
return destFile;
|
||||
}
|
||||
|
||||
public void setDestFile(File destFile) {
|
||||
this.destFile = destFile;
|
||||
}
|
||||
|
||||
public JClass getJclass() {
|
||||
return jclass;
|
||||
}
|
||||
|
||||
public void setJclass(JClass jclass) {
|
||||
this.jclass = jclass;
|
||||
}
|
||||
|
||||
public Set getManuallyMaintainedClasses() {
|
||||
return manuallyMaintainedClasses;
|
||||
}
|
||||
|
||||
public void setManuallyMaintainedClasses(Set manuallyMaintainedClasses) {
|
||||
this.manuallyMaintainedClasses = manuallyMaintainedClasses;
|
||||
}
|
||||
|
||||
public String getSimpleName() {
|
||||
return simpleName;
|
||||
}
|
||||
|
||||
public void setSimpleName(String simpleName) {
|
||||
this.simpleName = simpleName;
|
||||
}
|
||||
|
||||
public JClass getSuperclass() {
|
||||
return superclass;
|
||||
}
|
||||
|
||||
public void setSuperclass(JClass superclass) {
|
||||
this.superclass = superclass;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,636 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.apache.activemq.openwire.tool.OpenWireScript
|
||||
|
||||
/**
|
||||
* Generates the Java marshalling code for the Open Wire Format
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
class GenerateCMarshalling extends OpenWireScript {
|
||||
|
||||
String changeCase(String value) {
|
||||
StringBuffer b = new StringBuffer();
|
||||
value.each { c |
|
||||
if( Character.isUpperCase((char)c) ) {
|
||||
b.append('_');
|
||||
b.append(Character.toLowerCase((char)c));
|
||||
} else {
|
||||
b.append(c);
|
||||
}
|
||||
}
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
String toPropertyCase(String value) {
|
||||
return value.substring(0,1).toLowerCase()+value.substring(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the class list so that base classes come up first.
|
||||
*/
|
||||
def sort(classes) {
|
||||
|
||||
classes = (java.util.List)classes;
|
||||
def rc = [];
|
||||
def objectClass;
|
||||
|
||||
// lets make a map of all the class names
|
||||
def classNames = [:]
|
||||
for (c in classes) {
|
||||
def name = c.simpleName
|
||||
classNames[name] = name
|
||||
}
|
||||
|
||||
// Add all classes that have no parent first
|
||||
for (c in classes) {
|
||||
if( !classNames.containsKey(c.superclass))
|
||||
rc.add(c)
|
||||
}
|
||||
|
||||
// now lets add the rest
|
||||
for (c in classes) {
|
||||
if (!rc.contains(c))
|
||||
rc.add(c)
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
def generateFields(out, jclass) {
|
||||
|
||||
// println("getting fields for: ${jclass.simpleName}");
|
||||
if( jclass.superclass == null || jclass.superclass.simpleName.equals("Object") ) {
|
||||
out << """
|
||||
ow_byte structType;
|
||||
""";
|
||||
} else {
|
||||
generateFields(out, jclass.superclass);
|
||||
}
|
||||
|
||||
def properties = jclass.declaredProperties.findAll { isValidProperty(it) }
|
||||
for (property in properties) {
|
||||
def annotation = property.getter.getAnnotation("openwire:property");
|
||||
def size = annotation.getValue("size");
|
||||
def name = toPropertyCase(property.simpleName);
|
||||
def cached = isCachedProperty(property);
|
||||
|
||||
out << " "
|
||||
def type = property.type.qualifiedName
|
||||
switch (type) {
|
||||
case "boolean":
|
||||
out << "ow_$type $name;"; break;
|
||||
break;
|
||||
case "byte":
|
||||
out << "ow_$type $name;"; break;
|
||||
break;
|
||||
case "char":
|
||||
out << "ow_$type $name;"; break;
|
||||
break;
|
||||
case "short":
|
||||
out << "ow_$type $name;"; break;
|
||||
break;
|
||||
case "int":
|
||||
out << "ow_$type $name;"; break;
|
||||
break;
|
||||
case "long":
|
||||
out << "ow_$type $name;"; break;
|
||||
break;
|
||||
case "byte[]":
|
||||
out << "ow_byte_array *$name;"; break;
|
||||
break;
|
||||
case "org.apache.activeio.packet.ByteSequence":
|
||||
out << "ow_byte_array *$name;"; break;
|
||||
break;
|
||||
case "org.apache.activeio.packet.ByteSequence":
|
||||
out << "ow_byte_array *$name;"; break;
|
||||
break;
|
||||
case "java.lang.String":
|
||||
out << "ow_string *$name;"; break;
|
||||
break;
|
||||
default:
|
||||
if( property.type.arrayType ) {
|
||||
out << "ow_DataStructure_array *$name;"; break;
|
||||
} else if( isThrowable(property.type) ) {
|
||||
out << "ow_throwable *$name;"; break;
|
||||
} else {
|
||||
out << "struct ow_"+property.type.simpleName+" *$name;"; break;
|
||||
}
|
||||
}
|
||||
out << """
|
||||
"""
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Object run() {
|
||||
|
||||
def openwireVersion = getProperty("version");
|
||||
|
||||
def destDir = new File("../openwire-c/src/libopenwire")
|
||||
println "Generating C marshalling code to directory ${destDir}"
|
||||
|
||||
def openwireClasses = classes.findAll {
|
||||
it.getAnnotation("openwire:marshaller")!=null
|
||||
}
|
||||
|
||||
println "Sorting classes..."
|
||||
openwireClasses = sort(openwireClasses);
|
||||
|
||||
def concreteClasses = new ArrayList()
|
||||
int counter = 0
|
||||
Map map = [:]
|
||||
|
||||
destDir.mkdirs()
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Start generateing the ow_commands_v1.h File
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
def file = new File(destDir, "ow_commands_v${openwireVersion}.h")
|
||||
file.withWriter { out |
|
||||
|
||||
out << """/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*****************************************************************************************
|
||||
*
|
||||
* NOTE!: This file is auto generated - do not modify!
|
||||
* if you need to make a change, please see the modify the groovy scripts in the
|
||||
* under src/gram/script and then use maven openwire:generate to regenerate
|
||||
* this file.
|
||||
*
|
||||
*****************************************************************************************/
|
||||
|
||||
#ifndef OW_COMMANDS_V${openwireVersion}_H
|
||||
#define OW_COMMANDS_V${openwireVersion}_H
|
||||
|
||||
#include "ow.h"
|
||||
#include "ow_command_types_v${openwireVersion}.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define OW_WIREFORMAT_VERSION ${openwireVersion}
|
||||
|
||||
apr_status_t ow_bitmarshall(ow_bit_buffer *buffer, ow_DataStructure *object);
|
||||
apr_status_t ow_marshall(ow_byte_buffer *buffer, ow_DataStructure *object);
|
||||
"""
|
||||
|
||||
for (jclass in openwireClasses) {
|
||||
|
||||
println "Processing ${jclass.simpleName}"
|
||||
|
||||
def structName = jclass.simpleName;
|
||||
def type = "OW_"+structName.toUpperCase()+"_TYPE"
|
||||
|
||||
counter++;
|
||||
out << """
|
||||
typedef struct ow_${structName} {
|
||||
"""
|
||||
// This recusivly generates the field definitions of the class and it's supper classes.
|
||||
generateFields(out, jclass);
|
||||
|
||||
out << """
|
||||
} ow_${structName};
|
||||
ow_${structName} *ow_${structName}_create(apr_pool_t *pool);
|
||||
ow_boolean ow_is_a_${structName}(ow_DataStructure *object);
|
||||
"""
|
||||
}
|
||||
|
||||
out << """
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ! OW_COMMANDS_V${openwireVersion}_H */
|
||||
"""
|
||||
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Start generateing the ow_commands_v1.c File
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
file = new File(destDir, "ow_commands_v${openwireVersion}.c")
|
||||
file.withWriter { out |
|
||||
|
||||
out << """/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*****************************************************************************************
|
||||
*
|
||||
* NOTE!: This file is auto generated - do not modify!
|
||||
* if you need to make a change, please see the modify the groovy scripts in the
|
||||
* under src/gram/script and then use maven openwire:generate to regenerate
|
||||
* this file.
|
||||
*
|
||||
*****************************************************************************************/
|
||||
|
||||
|
||||
#include "ow_commands_v${openwireVersion}.h"
|
||||
|
||||
#define SUCCESS_CHECK( f ) { apr_status_t rc=f; if(rc!=APR_SUCCESS) return rc; }
|
||||
|
||||
"""
|
||||
for (jclass in openwireClasses) {
|
||||
|
||||
properties = jclass.declaredProperties.findAll { isValidProperty(it) }
|
||||
def name = jclass.simpleName;
|
||||
def type = ("ow_"+name).toUpperCase()+"_TYPE"
|
||||
|
||||
def baseName="DataStructure";
|
||||
|
||||
def superclass = jclass.superclass;
|
||||
while( superclass.superclass != null ) {
|
||||
if( openwireClasses.contains(superclass) ) {
|
||||
baseName = superclass.simpleName;
|
||||
break;
|
||||
} else {
|
||||
superclass = superclass.superclass;
|
||||
}
|
||||
}
|
||||
|
||||
out << """
|
||||
ow_boolean ow_is_a_${name}(ow_DataStructure *object) {
|
||||
if( object == 0 )
|
||||
return 0;
|
||||
|
||||
switch(object->structType) {"""
|
||||
for (sub in openwireClasses) {
|
||||
def subtype = "OW_"+sub.simpleName.toUpperCase()+"_TYPE"
|
||||
if( jclass.isAssignableFrom(sub) && !isAbstract(sub) ) {
|
||||
out << """
|
||||
case $subtype:"""
|
||||
|
||||
}
|
||||
}
|
||||
out << """
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
if( !isAbstract(jclass) ) {
|
||||
out << """
|
||||
|
||||
ow_${name} *ow_${name}_create(apr_pool_t *pool)
|
||||
{
|
||||
ow_${name} *value = apr_pcalloc(pool,sizeof(ow_${name}));
|
||||
if( value!=0 ) {
|
||||
((ow_DataStructure*)value)->structType = ${type};
|
||||
}
|
||||
return value;
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
out << """
|
||||
|
||||
apr_status_t ow_marshal1_${name}(ow_bit_buffer *buffer, ow_${name} *object)
|
||||
{
|
||||
ow_marshal1_${baseName}(buffer, (ow_${baseName}*)object);
|
||||
"""
|
||||
|
||||
properties = jclass.declaredProperties.findAll { isValidProperty(it) }
|
||||
for (property in properties) {
|
||||
def propname = toPropertyCase(property.simpleName);
|
||||
def cached = isCachedProperty(property);
|
||||
def annotation = property.getter.getAnnotation("openwire:property");
|
||||
def size = annotation.getValue("size");
|
||||
|
||||
out << " ";
|
||||
type = property.type.qualifiedName
|
||||
switch (type) {
|
||||
|
||||
case "boolean":
|
||||
out << "ow_bit_buffer_append(buffer, object->$propname);"; break;
|
||||
break;
|
||||
case "byte":break;
|
||||
case "char":break;
|
||||
case "short":break;
|
||||
case "int":break;
|
||||
case "long":
|
||||
out << "ow_marshal1_long(buffer, object->$propname);"; break;
|
||||
break;
|
||||
case "byte[]":
|
||||
if( size ==null ) {
|
||||
out << """
|
||||
ow_bit_buffer_append(buffer, object->$propname!=0 );
|
||||
""";
|
||||
}
|
||||
break;
|
||||
case "org.apache.activeio.packet.ByteSequence":
|
||||
if( size ==null ) {
|
||||
out << """
|
||||
ow_bit_buffer_append(buffer, object->$propname!=0 );
|
||||
""";
|
||||
}
|
||||
break;
|
||||
case "java.lang.String":
|
||||
out << "ow_marshal1_string(buffer, object->$propname);"; break;
|
||||
default:
|
||||
if( property.type.arrayType ) {
|
||||
if( size!=null ) {
|
||||
out << "SUCCESS_CHECK(ow_marshal1_DataStructure_array_const_size(buffer, object->$propname, ${size.asInt()}));"; break;
|
||||
} else {
|
||||
out << "SUCCESS_CHECK(ow_marshal1_DataStructure_array(buffer, object->$propname));"; break;
|
||||
}
|
||||
} else if( isThrowable(property.type) ) {
|
||||
out << "SUCCESS_CHECK(ow_marshal1_throwable(buffer, object->$propname));"; break;
|
||||
} else {
|
||||
if( cached ) {
|
||||
out << "SUCCESS_CHECK(ow_marshal1_cached_object(buffer, (ow_DataStructure*)object->$propname));"; break;
|
||||
} else {
|
||||
out << "SUCCESS_CHECK(ow_marshal1_nested_object(buffer, (ow_DataStructure*)object->$propname));"; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
out << """
|
||||
"""
|
||||
}
|
||||
|
||||
|
||||
out << """
|
||||
return APR_SUCCESS;
|
||||
}
|
||||
apr_status_t ow_marshal2_${name}(ow_byte_buffer *buffer, ow_bit_buffer *bitbuffer, ow_${name} *object)
|
||||
{
|
||||
ow_marshal2_${baseName}(buffer, bitbuffer, (ow_${baseName}*)object);
|
||||
"""
|
||||
|
||||
properties = jclass.declaredProperties.findAll { isValidProperty(it) }
|
||||
for (property in properties) {
|
||||
def annotation = property.getter.getAnnotation("openwire:property");
|
||||
def size = annotation.getValue("size");
|
||||
def propname = toPropertyCase(property.simpleName);
|
||||
def cached = isCachedProperty(property);
|
||||
|
||||
out << " "
|
||||
type = property.type.qualifiedName
|
||||
switch (type) {
|
||||
case "boolean":
|
||||
out << "ow_bit_buffer_read(bitbuffer);"; break;
|
||||
case "byte":
|
||||
out << "SUCCESS_CHECK(ow_byte_buffer_append_${type}(buffer, object->$propname));"; break;
|
||||
break;
|
||||
case "char":
|
||||
out << "SUCCESS_CHECK(ow_byte_buffer_append_${type}(buffer, object->$propname));"; break;
|
||||
break;
|
||||
case "short":
|
||||
out << "SUCCESS_CHECK(ow_byte_buffer_append_${type}(buffer, object->$propname));"; break;
|
||||
break;
|
||||
case "int":
|
||||
out << "SUCCESS_CHECK(ow_byte_buffer_append_${type}(buffer, object->$propname));"; break;
|
||||
break;
|
||||
case "long":
|
||||
out << "SUCCESS_CHECK(ow_marshal2_long(buffer, bitbuffer, object->$propname));"; break;
|
||||
break;
|
||||
case "byte[]":
|
||||
if( size!=null ) {
|
||||
out << "SUCCESS_CHECK(ow_marshal2_byte_array_const_size(buffer, object->$propname, ${size.asInt()}));"; break;
|
||||
} else {
|
||||
out << "SUCCESS_CHECK(ow_marshal2_byte_array(buffer, bitbuffer, object->$propname));"; break;
|
||||
}
|
||||
break;
|
||||
case "org.apache.activeio.packet.ByteSequence":
|
||||
if( size!=null ) {
|
||||
out << "SUCCESS_CHECK(ow_marshal2_byte_array_const_size(buffer, object->$propname, ${size.asInt()}));"; break;
|
||||
} else {
|
||||
out << "SUCCESS_CHECK(ow_marshal2_byte_array(buffer, bitbuffer, object->$propname));"; break;
|
||||
}
|
||||
break;
|
||||
case "java.lang.String":
|
||||
out << "SUCCESS_CHECK(ow_marshal2_string(buffer, bitbuffer, object->$propname));"; break;
|
||||
break;
|
||||
default:
|
||||
if( property.type.arrayType ) {
|
||||
if( size!=null ) {
|
||||
out << "SUCCESS_CHECK(ow_marshal2_DataStructure_array_const_size(buffer, bitbuffer, object->$propname, ${size.asInt()}));"; break;
|
||||
} else {
|
||||
out << "SUCCESS_CHECK(ow_marshal2_DataStructure_array(buffer, bitbuffer, object->$propname));"; break;
|
||||
}
|
||||
} else if( isThrowable(property.type) ) {
|
||||
out << "SUCCESS_CHECK(ow_marshal2_throwable(buffer, bitbuffer, object->$propname));"; break;
|
||||
} else {
|
||||
if( cached ) {
|
||||
out << "SUCCESS_CHECK(ow_marshal2_cached_object(buffer, bitbuffer, (ow_DataStructure*)object->$propname));"; break;
|
||||
} else {
|
||||
out << "SUCCESS_CHECK(ow_marshal2_nested_object(buffer, bitbuffer, (ow_DataStructure*)object->$propname));"; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
out << """
|
||||
"""
|
||||
}
|
||||
|
||||
out << """
|
||||
return APR_SUCCESS;
|
||||
}
|
||||
|
||||
apr_status_t ow_unmarshal_${name}(ow_byte_array *buffer, ow_bit_buffer *bitbuffer, ow_${name} *object, apr_pool_t *pool)
|
||||
{
|
||||
ow_unmarshal_${baseName}(buffer, bitbuffer, (ow_${baseName}*)object, pool);
|
||||
"""
|
||||
|
||||
properties = jclass.declaredProperties.findAll { isValidProperty(it) }
|
||||
for (property in properties) {
|
||||
def annotation = property.getter.getAnnotation("openwire:property");
|
||||
def size = annotation.getValue("size");
|
||||
def propname = toPropertyCase(property.simpleName);
|
||||
def cached = isCachedProperty(property);
|
||||
|
||||
out << " "
|
||||
type = property.type.qualifiedName
|
||||
switch (type) {
|
||||
case "boolean":
|
||||
out << "object->$propname = ow_bit_buffer_read(bitbuffer);"; break;
|
||||
break;
|
||||
case "byte":
|
||||
out << "SUCCESS_CHECK(ow_byte_array_read_${type}(buffer, &object->$propname));"; break;
|
||||
break;
|
||||
case "char":
|
||||
out << "SUCCESS_CHECK(ow_byte_array_read_${type}(buffer, &object->$propname));"; break;
|
||||
break;
|
||||
case "short":
|
||||
out << "SUCCESS_CHECK(ow_byte_array_read_${type}(buffer, &object->$propname));"; break;
|
||||
break;
|
||||
case "int":
|
||||
out << "SUCCESS_CHECK(ow_byte_array_read_${type}(buffer, &object->$propname));"; break;
|
||||
break;
|
||||
case "long":
|
||||
out << "SUCCESS_CHECK(ow_unmarshal_long(buffer, bitbuffer, &object->$propname, pool));"; break;
|
||||
break;
|
||||
case "byte[]":
|
||||
if( size!=null ) {
|
||||
out << "SUCCESS_CHECK(ow_unmarshal_byte_array_const_size(buffer, &object->$propname, ${size.asInt()}, pool));"; break;
|
||||
} else {
|
||||
out << "SUCCESS_CHECK(ow_unmarshal_byte_array(buffer, bitbuffer, &object->$propname, pool));"; break;
|
||||
}
|
||||
break;
|
||||
case "org.apache.activeio.packet.ByteSequence":
|
||||
if( size!=null ) {
|
||||
out << "SUCCESS_CHECK(ow_unmarshal_byte_array_const_size(buffer, &object->$propname, ${size.asInt()}, pool));"; break;
|
||||
} else {
|
||||
out << "SUCCESS_CHECK(ow_unmarshal_byte_array(buffer, bitbuffer, &object->$propname, pool));"; break;
|
||||
}
|
||||
break;
|
||||
case "java.lang.String":
|
||||
out << "SUCCESS_CHECK(ow_unmarshal_string(buffer, bitbuffer, &object->$propname, pool));"; break;
|
||||
break;
|
||||
default:
|
||||
if( property.type.arrayType ) {
|
||||
if( size!=null ) {
|
||||
out << "SUCCESS_CHECK(ow_unmarshal_DataStructure_array_const_size(buffer, bitbuffer, &object->$propname, ${size.asInt()}, pool));"; break;
|
||||
} else {
|
||||
out << "SUCCESS_CHECK(ow_unmarshal_DataStructure_array(buffer, bitbuffer, &object->$propname, pool));"; break;
|
||||
}
|
||||
} else if( isThrowable(property.type) ) {
|
||||
out << "SUCCESS_CHECK(ow_unmarshal_throwable(buffer, bitbuffer, &object->$propname, pool));"; break;
|
||||
} else {
|
||||
if( cached ) {
|
||||
out << "SUCCESS_CHECK(ow_unmarshal_cached_object(buffer, bitbuffer, (ow_DataStructure**)&object->$propname, pool));"; break;
|
||||
} else {
|
||||
out << "SUCCESS_CHECK(ow_unmarshal_nested_object(buffer, bitbuffer, (ow_DataStructure**)&object->$propname, pool));"; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
out << """
|
||||
"""
|
||||
}
|
||||
|
||||
out << """
|
||||
return APR_SUCCESS;
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
|
||||
out << """
|
||||
ow_DataStructure *ow_create_object(ow_byte type, apr_pool_t *pool)
|
||||
{
|
||||
switch( type ) {
|
||||
"""
|
||||
for (jclass in openwireClasses) {
|
||||
def name = jclass.simpleName;
|
||||
def type = ("ow_"+name).toUpperCase()+"_TYPE";
|
||||
if( !isAbstract(jclass) ) {
|
||||
out << """
|
||||
case ${type}: return (ow_DataStructure *)ow_${name}_create(pool);"""
|
||||
}
|
||||
}
|
||||
|
||||
out << """
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
apr_status_t ow_marshal1_object(ow_bit_buffer *buffer, ow_DataStructure *object)
|
||||
{
|
||||
switch( object->structType ) {
|
||||
"""
|
||||
for (jclass in openwireClasses) {
|
||||
def name = jclass.simpleName;
|
||||
def type = ("ow_"+name).toUpperCase()+"_TYPE";
|
||||
if( !isAbstract(jclass) ) {
|
||||
out << """
|
||||
case ${type}: return ow_marshal1_${name}(buffer, (ow_${name}*)object);"""
|
||||
}
|
||||
}
|
||||
|
||||
out << """
|
||||
}
|
||||
return APR_EGENERAL;
|
||||
}
|
||||
|
||||
apr_status_t ow_marshal2_object(ow_byte_buffer *buffer, ow_bit_buffer *bitbuffer, ow_DataStructure *object)
|
||||
{
|
||||
switch( object->structType ) {
|
||||
"""
|
||||
for (jclass in openwireClasses) {
|
||||
def name = jclass.simpleName;
|
||||
def type = ("ow_"+name).toUpperCase()+"_TYPE";
|
||||
if( !isAbstract(jclass) ) {
|
||||
out << """
|
||||
case ${type}: return ow_marshal2_${name}(buffer, bitbuffer, (ow_${name}*)object);"""
|
||||
}
|
||||
}
|
||||
|
||||
out << """
|
||||
}
|
||||
return APR_EGENERAL;
|
||||
}
|
||||
|
||||
apr_status_t ow_unmarshal_object(ow_byte_array *buffer, ow_bit_buffer *bitbuffer, ow_DataStructure *object, apr_pool_t *pool)
|
||||
{
|
||||
switch( object->structType ) {
|
||||
"""
|
||||
for (jclass in openwireClasses) {
|
||||
def name = jclass.simpleName;
|
||||
def type = ("ow_"+name).toUpperCase()+"_TYPE";
|
||||
if( !isAbstract(jclass) ) {
|
||||
out << """
|
||||
case ${type}: return ow_unmarshal_${name}(buffer, bitbuffer, (ow_${name}*)object, pool);"""
|
||||
}
|
||||
}
|
||||
|
||||
out << """
|
||||
}
|
||||
return APR_EGENERAL;
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,144 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.apache.activemq.openwire.tool.OpenWireCSharpClassesScript
|
||||
|
||||
/**
|
||||
* Generates the C# commands for the Open Wire Format
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
class GenerateCSharpClasses extends OpenWireCSharpClassesScript {
|
||||
|
||||
void generateFile(PrintWriter out) {
|
||||
out << """/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//
|
||||
// NOTE!: This file is autogenerated - do not modify!
|
||||
// if you need to make a change, please see the Groovy scripts in the
|
||||
// activemq-core module
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
using ActiveMQ.OpenWire;
|
||||
using ActiveMQ.Commands;
|
||||
|
||||
namespace ActiveMQ.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// The ActiveMQ ${jclass.simpleName} Command
|
||||
/// </summary>
|
||||
public class ${jclass.simpleName} : $baseClass"""
|
||||
|
||||
for( i in jclass.interfaces ) {
|
||||
out << ", ${i.simpleName}";
|
||||
}
|
||||
|
||||
out << """
|
||||
{
|
||||
public const byte ID_${jclass.simpleName} = ${getOpenWireOpCode(jclass)};
|
||||
|
||||
"""
|
||||
for (property in properties) {
|
||||
def type = toCSharpType(property.type)
|
||||
def name = decapitalize(property.simpleName)
|
||||
out << """ $type $name;
|
||||
"""
|
||||
}
|
||||
|
||||
def text = makeHashCodeBody()
|
||||
if (text != null) out <<
|
||||
"""
|
||||
public override int GetHashCode() {
|
||||
$text
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
text = makeEqualsBody()
|
||||
if (text != null) out <<
|
||||
"""
|
||||
public override bool Equals(object that) {
|
||||
if (that is ${className}) {
|
||||
return Equals((${className}) that);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual bool Equals(${className} that) {
|
||||
$text
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
text = makeToStringBody()
|
||||
if (text != null) out << """
|
||||
public override string ToString() {
|
||||
$text
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
out << """
|
||||
|
||||
public override byte GetDataStructureType() {
|
||||
return ID_${jclass.simpleName};
|
||||
}
|
||||
|
||||
|
||||
// Properties
|
||||
"""
|
||||
for (property in properties) {
|
||||
def type = toCSharpType(property.type)
|
||||
def name = decapitalize(property.simpleName)
|
||||
def propertyName = property.simpleName
|
||||
def getter = capitalize(property.getter.simpleName)
|
||||
def setter = capitalize(property.setter.simpleName)
|
||||
|
||||
|
||||
out << """
|
||||
public $type $propertyName
|
||||
{
|
||||
get { return $name; }
|
||||
set { this.$name = value; }
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
out << """
|
||||
}
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
|
@ -1,277 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.apache.activemq.openwire.tool.OpenWireCSharpMarshallingScript
|
||||
|
||||
/**
|
||||
* Generates the C# marshalling code for the Open Wire Format
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
class GenerateCSharpMarshalling extends OpenWireCSharpMarshallingScript {
|
||||
|
||||
void generateFile(PrintWriter out) {
|
||||
out << """/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//
|
||||
// NOTE!: This file is autogenerated - do not modify!
|
||||
// if you need to make a change, please see the Groovy scripts in the
|
||||
// activemq-core module
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
using ActiveMQ.Commands;
|
||||
using ActiveMQ.OpenWire;
|
||||
using ActiveMQ.OpenWire.V${openwireVersion};
|
||||
|
||||
namespace ActiveMQ.OpenWire.V${openwireVersion}
|
||||
{
|
||||
/// <summary>
|
||||
/// Marshalling code for Open Wire Format for ${jclass.simpleName}
|
||||
/// </summary>
|
||||
${abstractClassText}class $className : $baseClass
|
||||
{
|
||||
"""
|
||||
|
||||
if( !abstractClass ) out << """
|
||||
|
||||
public override DataStructure CreateObject()
|
||||
{
|
||||
return new ${jclass.simpleName}();
|
||||
}
|
||||
|
||||
public override byte GetDataStructureType()
|
||||
{
|
||||
return ${jclass.simpleName}.ID_${jclass.simpleName};
|
||||
}
|
||||
"""
|
||||
|
||||
/*
|
||||
* Generate the tight encoding marshallers
|
||||
*/
|
||||
out << """
|
||||
//
|
||||
// Un-marshal an object instance from the data input stream
|
||||
//
|
||||
public override void TightUnmarshal(OpenWireFormat wireFormat, Object o, BinaryReader dataIn, BooleanStream bs)
|
||||
{
|
||||
base.TightUnmarshal(wireFormat, o, dataIn, bs);
|
||||
"""
|
||||
|
||||
if( !properties.isEmpty() || marshallerAware ) out << """
|
||||
${jclass.simpleName} info = (${jclass.simpleName})o;
|
||||
"""
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.BeforeUnmarshall(wireFormat);
|
||||
|
||||
"""
|
||||
|
||||
generateTightUnmarshalBody(out)
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.AfterUnmarshall(wireFormat);
|
||||
"""
|
||||
|
||||
out << """
|
||||
}
|
||||
"""
|
||||
|
||||
out << """
|
||||
//
|
||||
// Write the booleans that this object uses to a BooleanStream
|
||||
//
|
||||
public override int TightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) {
|
||||
${jclass.simpleName} info = (${jclass.simpleName})o;
|
||||
"""
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.BeforeMarshall(wireFormat);
|
||||
"""
|
||||
|
||||
out << """
|
||||
int rc = base.TightMarshal1(wireFormat, info, bs);
|
||||
"""
|
||||
|
||||
def baseSize = generateTightMarshal1Body(out)
|
||||
|
||||
out << """
|
||||
return rc + ${baseSize};
|
||||
}
|
||||
|
||||
//
|
||||
// Write a object instance to data output stream
|
||||
//
|
||||
public override void TightMarshal2(OpenWireFormat wireFormat, Object o, BinaryWriter dataOut, BooleanStream bs) {
|
||||
base.TightMarshal2(wireFormat, o, dataOut, bs);
|
||||
"""
|
||||
|
||||
if( !properties.isEmpty() || marshallerAware ) out << """
|
||||
${jclass.simpleName} info = (${jclass.simpleName})o;
|
||||
"""
|
||||
|
||||
generateTightMarshal2Body(out)
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.AfterMarshall(wireFormat);
|
||||
"""
|
||||
|
||||
out << """
|
||||
}
|
||||
"""
|
||||
|
||||
/*
|
||||
* Generate the loose encoding marshallers
|
||||
*/
|
||||
out << """
|
||||
//
|
||||
// Un-marshal an object instance from the data input stream
|
||||
//
|
||||
public override void LooseUnmarshal(OpenWireFormat wireFormat, Object o, BinaryReader dataIn)
|
||||
{
|
||||
base.LooseUnmarshal(wireFormat, o, dataIn);
|
||||
"""
|
||||
|
||||
if( !properties.isEmpty() || marshallerAware ) out << """
|
||||
${jclass.simpleName} info = (${jclass.simpleName})o;
|
||||
"""
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.BeforeUnmarshall(wireFormat);
|
||||
|
||||
"""
|
||||
|
||||
generateLooseUnmarshalBody(out)
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.AfterUnmarshall(wireFormat);
|
||||
"""
|
||||
|
||||
out << """
|
||||
}
|
||||
"""
|
||||
|
||||
out << """
|
||||
//
|
||||
// Write a object instance to data output stream
|
||||
//
|
||||
public override void LooseMarshal(OpenWireFormat wireFormat, Object o, BinaryWriter dataOut) {
|
||||
"""
|
||||
|
||||
if( !properties.isEmpty() || marshallerAware ) out << """
|
||||
${jclass.simpleName} info = (${jclass.simpleName})o;
|
||||
"""
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.BeforeMarshall(wireFormat);
|
||||
"""
|
||||
|
||||
out << """
|
||||
base.LooseMarshal(wireFormat, o, dataOut);
|
||||
"""
|
||||
|
||||
generateLooseMarshalBody(out)
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.AfterMarshall(wireFormat);
|
||||
"""
|
||||
out << """
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
out << """
|
||||
}
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
|
||||
void generateFactory(PrintWriter out) {
|
||||
out << """/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//
|
||||
// NOTE!: This file is autogenerated - do not modify!
|
||||
// if you need to make a change, please see the Groovy scripts in the
|
||||
// activemq-core module
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
|
||||
using ActiveMQ.Commands;
|
||||
using ActiveMQ.OpenWire;
|
||||
using ActiveMQ.OpenWire.V${openwireVersion};
|
||||
|
||||
namespace ActiveMQ.OpenWire.V${openwireVersion}
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to create marshallers for a specific version of the wire protocol
|
||||
/// </summary>
|
||||
public class MarshallerFactory
|
||||
{
|
||||
public void configure(OpenWireFormat format)
|
||||
{
|
||||
"""
|
||||
|
||||
for (jclass in concreteClasses) {
|
||||
out << """
|
||||
format.addMarshaller(new ${jclass.simpleName}Marshaller());"""
|
||||
}
|
||||
|
||||
out << """
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.apache.activemq.openwire.tool.OpenWireCppClassesScript
|
||||
|
||||
/**
|
||||
* Generates the C++ commands for the Open Wire Format
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
class GenerateCppClasses extends OpenWireCppClassesScript {
|
||||
|
||||
void generateFile(PrintWriter out) {
|
||||
out << """/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "activemq/command/${className}.hpp"
|
||||
|
||||
using namespace apache::activemq::command;
|
||||
|
||||
/*
|
||||
*
|
||||
* Command and marshalling code for OpenWire format for ${className}
|
||||
*
|
||||
*
|
||||
* NOTE!: This file is autogenerated - do not modify!
|
||||
* if you need to make a change, please see the Groovy scripts in the
|
||||
* activemq-core module
|
||||
*
|
||||
*/
|
||||
${className}::${className}()
|
||||
{"""
|
||||
for (property in properties) {
|
||||
def value = toCppDefaultValue(property.type)
|
||||
def propertyName = property.simpleName
|
||||
def parameterName = decapitalize(propertyName)
|
||||
out << """
|
||||
this->${parameterName} = ${value} ;"""
|
||||
}
|
||||
out << """
|
||||
}
|
||||
|
||||
${className}::~${className}()
|
||||
{
|
||||
}
|
||||
|
||||
unsigned char ${className}::getDataStructureType()
|
||||
{
|
||||
return ${className}::TYPE ;
|
||||
}
|
||||
"""
|
||||
for (property in properties) {
|
||||
def type = toCppType(property.type)
|
||||
def propertyName = property.simpleName
|
||||
def parameterName = decapitalize(propertyName)
|
||||
out << """
|
||||
|
||||
${type} ${className}::get${propertyName}()
|
||||
{
|
||||
return ${parameterName} ;
|
||||
}
|
||||
|
||||
void ${className}::set${propertyName}(${type} ${parameterName})
|
||||
{
|
||||
this->${parameterName} = ${parameterName} ;
|
||||
}
|
||||
"""
|
||||
}
|
||||
out << """
|
||||
int ${className}::marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException)
|
||||
{
|
||||
int size = 0 ;
|
||||
|
||||
size += ${baseClass}::marshal(marshaller, mode, ostream) ; """
|
||||
for (property in properties) {
|
||||
def marshalMethod = toMarshalMethodName(property.type)
|
||||
def propertyName = decapitalize(property.simpleName)
|
||||
out << """
|
||||
size += marshaller->${marshalMethod}(${propertyName}, mode, ostream) ; """
|
||||
}
|
||||
out << """
|
||||
return size ;
|
||||
}
|
||||
|
||||
void ${className}::unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException)
|
||||
{
|
||||
${baseClass}::unmarshal(marshaller, mode, istream) ; """
|
||||
for (property in properties) {
|
||||
def cast = toUnmarshalCast(property.type)
|
||||
def unmarshalMethod = toUnmarshalMethodName(property.type)
|
||||
def propertyName = decapitalize(property.simpleName)
|
||||
out << """
|
||||
${propertyName} = ${cast}(marshaller->${unmarshalMethod}(mode, istream)) ; """
|
||||
}
|
||||
out << """
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
|
@ -1,155 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.apache.activemq.openwire.tool.OpenWireCppHeadersScript
|
||||
|
||||
/**
|
||||
* Generates the C++ commands for the Open Wire Format
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
class GenerateCppHeaders extends OpenWireCppHeadersScript {
|
||||
|
||||
void generateFile(PrintWriter out) {
|
||||
out << """/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef ActiveMQ_${className}_hpp_
|
||||
#define ActiveMQ_${className}_hpp_
|
||||
|
||||
// Turn off warning message for ignored exception specification
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning( disable : 4290 )
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
"""
|
||||
out << """#include "activemq/command/${baseClass}.hpp"
|
||||
"""
|
||||
for (property in properties)
|
||||
{
|
||||
if( !property.type.isPrimitiveType() &&
|
||||
property.type.simpleName != "String" &&
|
||||
property.type.simpleName != "ByteSequence" )
|
||||
{
|
||||
def includeName = toCppType(property.type)
|
||||
if( property.type.isArrayType() )
|
||||
{
|
||||
def arrayType = property.type.arrayComponentType ;
|
||||
if( arrayType.isPrimitiveType() )
|
||||
continue ;
|
||||
}
|
||||
if( includeName.startsWith("array<") )
|
||||
includeName = includeName.substring(6, includeName.length()-1) ;
|
||||
else if( includeName.startsWith("p<") )
|
||||
includeName = includeName.substring(2, includeName.length()-1)
|
||||
|
||||
if( includeName.equals("IDataStructure") )
|
||||
out << """#include "activemq/${includeName}.hpp"
|
||||
"""
|
||||
else
|
||||
out << """#include "activemq/command/${includeName}.hpp"
|
||||
"""
|
||||
}
|
||||
}
|
||||
out << """
|
||||
#include "activemq/protocol/IMarshaller.hpp"
|
||||
#include "ppr/io/IOutputStream.hpp"
|
||||
#include "ppr/io/IInputStream.hpp"
|
||||
#include "ppr/io/IOException.hpp"
|
||||
#include "ppr/util/ifr/array"
|
||||
#include "ppr/util/ifr/p"
|
||||
|
||||
namespace apache
|
||||
{
|
||||
namespace activemq
|
||||
{
|
||||
namespace command
|
||||
{
|
||||
using namespace ifr;
|
||||
using namespace std;
|
||||
using namespace apache::activemq;
|
||||
using namespace apache::activemq::protocol;
|
||||
using namespace apache::ppr::io;
|
||||
|
||||
/*
|
||||
*
|
||||
* Command and marshalling code for OpenWire format for ${className}
|
||||
*
|
||||
*
|
||||
* NOTE!: This file is autogenerated - do not modify!
|
||||
* if you need to make a change, please see the Groovy scripts in the
|
||||
* activemq-core module
|
||||
*
|
||||
*/
|
||||
class ${className} : public ${baseClass}
|
||||
{
|
||||
protected:
|
||||
"""
|
||||
for (property in properties) {
|
||||
def type = toCppType(property.type)
|
||||
def name = decapitalize(property.simpleName)
|
||||
out << """ $type $name ;
|
||||
"""
|
||||
}
|
||||
out << """
|
||||
public:
|
||||
const static unsigned char TYPE = ${getOpenWireOpCode(jclass)};
|
||||
|
||||
public:
|
||||
${className}() ;
|
||||
virtual ~${className}() ;
|
||||
|
||||
virtual unsigned char getDataStructureType() ;
|
||||
"""
|
||||
for (property in properties) {
|
||||
def type = toCppType(property.type)
|
||||
def propertyName = property.simpleName
|
||||
def parameterName = decapitalize(propertyName)
|
||||
out << """
|
||||
virtual ${type} get${propertyName}() ;
|
||||
virtual void set${propertyName}(${type} ${parameterName}) ;
|
||||
"""
|
||||
}
|
||||
out << """
|
||||
virtual int marshal(p<IMarshaller> marshaller, int mode, p<IOutputStream> ostream) throw (IOException) ;
|
||||
virtual void unmarshal(p<IMarshaller> marshaller, int mode, p<IInputStream> istream) throw (IOException) ;
|
||||
} ;
|
||||
|
||||
/* namespace */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /*ActiveMQ_${className}_hpp_*/
|
||||
"""
|
||||
}
|
||||
}
|
|
@ -1,208 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.apache.activemq.openwire.tool.OpenWireCppMarshallingClassesScript
|
||||
|
||||
/**
|
||||
* Generates the C++ marshalling classes for the Open Wire Format
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
class GenerateCppMarshallingClasses extends OpenWireCppMarshallingClassesScript {
|
||||
|
||||
void generateFile(PrintWriter out) {
|
||||
out << """/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "marshal/${className}.hpp"
|
||||
|
||||
using namespace apache::activemq::client::marshal;
|
||||
|
||||
/*
|
||||
* Marshalling code for Open Wire Format for ${jclass.simpleName}
|
||||
*
|
||||
* NOTE!: This file is autogenerated - do not modify!
|
||||
* if you need to make a change, please see the Groovy scripts in the
|
||||
* activemq-core module
|
||||
*/
|
||||
|
||||
${className}::${className}()
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
|
||||
${className}::~${className}()
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
if( !abstractClass ) out << """
|
||||
|
||||
IDataStructure* ${className}::createObject()
|
||||
{
|
||||
return new ${jclass.simpleName}();
|
||||
}
|
||||
|
||||
char ${className}::getDataStructureType()
|
||||
{
|
||||
return ${jclass.simpleName}.ID_${jclass.simpleName};
|
||||
}
|
||||
"""
|
||||
|
||||
out << """
|
||||
/*
|
||||
* Un-marshal an object instance from the data input stream
|
||||
*/
|
||||
void ${className}::unmarshal(ProtocolFormat& wireFormat, Object o, BinaryReader& dataIn, BooleanStream& bs)
|
||||
{
|
||||
base.unmarshal(wireFormat, o, dataIn, bs);
|
||||
"""
|
||||
|
||||
if( !properties.isEmpty() || marshallerAware ) out << """
|
||||
${jclass.simpleName}& info = (${jclass.simpleName}&) o;
|
||||
"""
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.beforeUnmarshall(wireFormat);
|
||||
|
||||
"""
|
||||
|
||||
generateTightUnmarshalBody(out)
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.afterUnmarshall(wireFormat);
|
||||
"""
|
||||
|
||||
out << """
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Write the booleans that this object uses to a BooleanStream
|
||||
*/
|
||||
int ${className}::marshal1(ProtocolFormat& wireFormat, Object& o, BooleanStream& bs) {
|
||||
${jclass.simpleName}& info = (${jclass.simpleName}&) o;
|
||||
"""
|
||||
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.beforeMarshall(wireFormat);
|
||||
"""
|
||||
|
||||
out << """
|
||||
int rc = base.marshal1(wireFormat, info, bs);
|
||||
"""
|
||||
|
||||
def baseSize = generateMarshal1Body(out)
|
||||
|
||||
out << """
|
||||
return rc + ${baseSize};
|
||||
}
|
||||
|
||||
/*
|
||||
* Write a object instance to data output stream
|
||||
*/
|
||||
void ${className}::marshal2(ProtocolFormat& wireFormat, Object& o, BinaryWriter& dataOut, BooleanStream& bs) {
|
||||
base.marshal2(wireFormat, o, dataOut, bs);
|
||||
"""
|
||||
|
||||
if( !properties.isEmpty() || marshallerAware ) out << """
|
||||
${jclass.simpleName}& info = (${jclass.simpleName}&) o;
|
||||
"""
|
||||
|
||||
generateMarshal2Body(out)
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.afterMarshall(wireFormat);
|
||||
"""
|
||||
|
||||
out << """
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
|
||||
void generateFactory(PrintWriter out) {
|
||||
out << """/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Marshalling code for Open Wire Format
|
||||
//
|
||||
//
|
||||
// NOTE!: This file is autogenerated - do not modify!
|
||||
// if you need to make a change, please see the Groovy scripts in the
|
||||
// activemq-openwire module
|
||||
//
|
||||
|
||||
#include "marshal/${className}.hpp"
|
||||
|
||||
"""
|
||||
|
||||
for (jclass in concreteClasses) {
|
||||
out << """#include "marshal/${jclass.simpleName}Marshaller.hpp"
|
||||
"""
|
||||
}
|
||||
|
||||
out << """
|
||||
|
||||
using namespace apache::activemq::client::marshal;
|
||||
|
||||
|
||||
void MarshallerFactory::configure(ProtocolFormat& format)
|
||||
{
|
||||
"""
|
||||
|
||||
for (jclass in concreteClasses) {
|
||||
out << """
|
||||
format.addMarshaller(new ${jclass.simpleName}Marshaller());"""
|
||||
}
|
||||
|
||||
out << """
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
|
@ -1,172 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.apache.activemq.openwire.tool.OpenWireCppMarshallingHeadersScript
|
||||
|
||||
/**
|
||||
* Generates the C++ marshalling headers for the Open Wire Format
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
class GenerateCppMarshallingHeaders extends OpenWireCppMarshallingHeadersScript {
|
||||
|
||||
void generateFile(PrintWriter out) {
|
||||
out << """/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef ${className}_hpp_
|
||||
#define ${className}_hpp_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "command/IDataStructure.hpp"
|
||||
|
||||
/* we could cut this down - for now include all possible headers */
|
||||
#include "command/BrokerId.hpp"
|
||||
#include "command/ConnectionId.hpp"
|
||||
#include "command/ConsumerId.hpp"
|
||||
#include "command/ProducerId.hpp"
|
||||
#include "command/SessionId.hpp"
|
||||
|
||||
#include "io/BinaryReader.hpp"
|
||||
#include "io/BinaryWriter.hpp"
|
||||
|
||||
#include "command/${baseClass}.hpp"
|
||||
#include "util/ifr/p.hpp"
|
||||
|
||||
#include "protocol/ProtocolFormat.hpp"
|
||||
|
||||
namespace apache
|
||||
{
|
||||
namespace activemq
|
||||
{
|
||||
namespace client
|
||||
{
|
||||
namespace marshal
|
||||
{
|
||||
using namespace ifr ;
|
||||
using namespace apache::activemq::client::command;
|
||||
using namespace apache::activemq::client::io;
|
||||
using namespace apache::activemq::client::protocol;
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
class ${className} : public ${baseClass}
|
||||
{
|
||||
public:
|
||||
${className}() ;
|
||||
virtual ~${className}() ;
|
||||
|
||||
virtual IDataStructure* createCommand() ;
|
||||
virtual char getDataStructureType() ;
|
||||
|
||||
virtual void unmarshal(ProtocolFormat& wireFormat, Object o, BinaryReader& dataIn, BooleanStream& bs) ;
|
||||
virtual int marshal1(ProtocolFormat& wireFormat, Object& o, BooleanStream& bs) ;
|
||||
virtual void marshal2(ProtocolFormat& wireFormat, Object& o, BinaryWriter& dataOut, BooleanStream& bs) ;
|
||||
} ;
|
||||
|
||||
/* namespace */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /*${className}_hpp_*/
|
||||
"""
|
||||
}
|
||||
|
||||
|
||||
void generateFactory(PrintWriter out) {
|
||||
out << """//*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Marshalling code for Open Wire Format
|
||||
//
|
||||
//
|
||||
// NOTE!: This file is autogenerated - do not modify!
|
||||
// if you need to make a change, please see the Groovy scripts in the
|
||||
// activemq-openwire module
|
||||
//
|
||||
|
||||
#ifndef MarshallerFactory_hpp_
|
||||
#define MarshallerFactory_hpp_
|
||||
|
||||
|
||||
namespace apache
|
||||
{
|
||||
namespace activemq
|
||||
{
|
||||
namespace client
|
||||
{
|
||||
namespace marshal
|
||||
{
|
||||
using namespace ifr ;
|
||||
using namespace std ;
|
||||
using namespace apache::activemq::client;
|
||||
using namespace apache::activemq::client::command;
|
||||
using namespace apache::activemq::client::io;
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
class MarshallerFactory
|
||||
{
|
||||
public:
|
||||
MarshallerFactory() ;
|
||||
virtual ~MarshallerFactory() ;
|
||||
|
||||
virtual void configure(ProtocolFormat& format) ;
|
||||
} ;
|
||||
|
||||
/* namespace */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /*MarshallerFactory_hpp_*/
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
|
@ -1,298 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.apache.activemq.openwire.tool.OpenWireJavaMarshallingScript
|
||||
|
||||
/**
|
||||
* Generates the Java marshalling code for the Open Wire Format
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
class GenerateJavaMarshalling extends OpenWireJavaMarshallingScript {
|
||||
|
||||
void generateFile(PrintWriter out) {
|
||||
out << """/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.activemq.openwire.v${openwireVersion};
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.activemq.openwire.*;
|
||||
import org.apache.activemq.command.*;
|
||||
|
||||
"""
|
||||
for (pkg in jclass.importedPackages) {
|
||||
for (clazz in pkg.classes) {
|
||||
out << "import "+clazz.qualifiedName+";"
|
||||
}
|
||||
}
|
||||
out << """
|
||||
|
||||
/**
|
||||
* Marshalling code for Open Wire Format for ${className}
|
||||
*
|
||||
*
|
||||
* NOTE!: This file is auto generated - do not modify!
|
||||
* if you need to make a change, please see the modify the groovy scripts in the
|
||||
* under src/gram/script and then use maven openwire:generate to regenerate
|
||||
* this file.
|
||||
*
|
||||
* @version \$Revision\$
|
||||
*/
|
||||
public ${abstractClassText}class ${className} extends ${baseClass} {
|
||||
"""
|
||||
|
||||
if( !abstractClass ) out << """
|
||||
/**
|
||||
* Return the type of Data Structure we marshal
|
||||
* @return short representation of the type data structure
|
||||
*/
|
||||
public byte getDataStructureType() {
|
||||
return ${jclass.simpleName}.DATA_STRUCTURE_TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a new object instance
|
||||
*/
|
||||
public DataStructure createObject() {
|
||||
return new ${jclass.simpleName}();
|
||||
}
|
||||
"""
|
||||
|
||||
out << """
|
||||
/**
|
||||
* Un-marshal an object instance from the data input stream
|
||||
*
|
||||
* @param o the object to un-marshal
|
||||
* @param dataIn the data input stream to build the object from
|
||||
* @throws IOException
|
||||
*/
|
||||
public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInputStream dataIn, BooleanStream bs) throws IOException {
|
||||
super.tightUnmarshal(wireFormat, o, dataIn, bs);
|
||||
"""
|
||||
|
||||
if( !properties.isEmpty() ) out << """
|
||||
${jclass.simpleName} info = (${jclass.simpleName})o;
|
||||
"""
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.beforeUnmarshall(wireFormat);
|
||||
|
||||
"""
|
||||
|
||||
generateTightUnmarshalBody(out)
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.afterUnmarshall(wireFormat);
|
||||
"""
|
||||
|
||||
out << """
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write the booleans that this object uses to a BooleanStream
|
||||
*/
|
||||
public int tightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) throws IOException {
|
||||
"""
|
||||
|
||||
|
||||
if( !properties.isEmpty() ) out << """
|
||||
${jclass.simpleName} info = (${jclass.simpleName})o;
|
||||
"""
|
||||
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.beforeMarshall(wireFormat);
|
||||
"""
|
||||
|
||||
out << """
|
||||
int rc = super.tightMarshal1(wireFormat, o, bs);
|
||||
"""
|
||||
|
||||
def baseSize = generateTightMarshal1Body(out)
|
||||
|
||||
out << """
|
||||
return rc + ${baseSize};
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a object instance to data output stream
|
||||
*
|
||||
* @param o the instance to be marshaled
|
||||
* @param dataOut the output stream
|
||||
* @throws IOException thrown if an error occurs
|
||||
*/
|
||||
public void tightMarshal2(OpenWireFormat wireFormat, Object o, DataOutputStream dataOut, BooleanStream bs) throws IOException {
|
||||
super.tightMarshal2(wireFormat, o, dataOut, bs);
|
||||
"""
|
||||
|
||||
if( !properties.isEmpty() ) out << """
|
||||
${jclass.simpleName} info = (${jclass.simpleName})o;
|
||||
"""
|
||||
|
||||
generateTightMarshal2Body(out)
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.afterMarshall(wireFormat);
|
||||
"""
|
||||
|
||||
out << """
|
||||
}
|
||||
"""
|
||||
|
||||
out << """
|
||||
/**
|
||||
* Un-marshal an object instance from the data input stream
|
||||
*
|
||||
* @param o the object to un-marshal
|
||||
* @param dataIn the data input stream to build the object from
|
||||
* @throws IOException
|
||||
*/
|
||||
public void looseUnmarshal(OpenWireFormat wireFormat, Object o, DataInputStream dataIn) throws IOException {
|
||||
super.looseUnmarshal(wireFormat, o, dataIn);
|
||||
"""
|
||||
|
||||
if( !properties.isEmpty() ) out << """
|
||||
${jclass.simpleName} info = (${jclass.simpleName})o;
|
||||
"""
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.beforeUnmarshall(wireFormat);
|
||||
|
||||
"""
|
||||
|
||||
generateLooseUnmarshalBody(out)
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.afterUnmarshall(wireFormat);
|
||||
"""
|
||||
|
||||
out << """
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Write the booleans that this object uses to a BooleanStream
|
||||
*/
|
||||
public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutputStream dataOut) throws IOException {
|
||||
"""
|
||||
|
||||
if( !properties.isEmpty() ) out << """
|
||||
${jclass.simpleName} info = (${jclass.simpleName})o;
|
||||
"""
|
||||
|
||||
|
||||
if( marshallerAware ) out << """
|
||||
info.beforeMarshall(wireFormat);
|
||||
"""
|
||||
|
||||
out << """
|
||||
super.looseMarshal(wireFormat, o, dataOut);
|
||||
"""
|
||||
|
||||
generateLooseMarshalBody(out)
|
||||
|
||||
out << """
|
||||
}
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
|
||||
void generateFactory(PrintWriter out) {
|
||||
out << """/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.activemq.openwire.v${openwireVersion};
|
||||
|
||||
import org.apache.activemq.openwire.DataStreamMarshaller;
|
||||
import org.apache.activemq.openwire.OpenWireFormat;
|
||||
|
||||
/**
|
||||
* MarshallerFactory for Open Wire Format.
|
||||
*
|
||||
*
|
||||
* NOTE!: This file is auto generated - do not modify!
|
||||
* if you need to make a change, please see the modify the groovy scripts in the
|
||||
* under src/gram/script and then use maven openwire:generate to regenerate
|
||||
* this file.
|
||||
*
|
||||
* @version \$Revision\$
|
||||
*/
|
||||
public class MarshallerFactory {
|
||||
|
||||
/**
|
||||
* Creates a Map of command type -> Marshallers
|
||||
*/
|
||||
static final private DataStreamMarshaller marshaller[] = new DataStreamMarshaller[256];
|
||||
static {
|
||||
"""
|
||||
|
||||
for (jclass in concreteClasses) {
|
||||
out << """
|
||||
add(new ${jclass.simpleName}Marshaller());"""
|
||||
}
|
||||
|
||||
out << """
|
||||
|
||||
}
|
||||
|
||||
static private void add(DataStreamMarshaller dsm) {
|
||||
marshaller[dsm.getDataStructureType()] = dsm;
|
||||
}
|
||||
|
||||
static public DataStreamMarshaller[] createMarshallerMap(OpenWireFormat wireFormat) {
|
||||
return marshaller;
|
||||
}
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
|
@ -1,224 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import org.apache.activemq.openwire.tool.OpenWireScript
|
||||
import org.apache.activemq.openwire.tool.TestDataGenerator
|
||||
import org.apache.tools.ant.Project;
|
||||
import org.apache.tools.ant.taskdefs.FixCRLF;
|
||||
|
||||
/**
|
||||
* Generates the Java test code for the Open Wire Format
|
||||
*
|
||||
* @version $Revision: $
|
||||
*/
|
||||
class GenerateJavaTests extends OpenWireScript {
|
||||
|
||||
Object run() {
|
||||
|
||||
def openwireVersion = getProperty("version");
|
||||
|
||||
def destDir = new File("src/test/java/org/apache/activemq/openwire/v${openwireVersion}")
|
||||
println "Generating Java test code to directory ${destDir}"
|
||||
|
||||
def openwireClasses = classes.findAll {
|
||||
it.getAnnotation("openwire:marshaller")!=null
|
||||
}
|
||||
|
||||
def concreteClasses = new ArrayList()
|
||||
def buffer = new StringBuffer()
|
||||
int counter = 0
|
||||
Map map = [:]
|
||||
|
||||
destDir.mkdirs()
|
||||
for (jclass in openwireClasses) {
|
||||
|
||||
println "Processing ${jclass.simpleName}"
|
||||
def abstractText = "abstract "
|
||||
def classIsAbstract = isAbstract(jclass);
|
||||
def isBaseAbstract = isAbstract(jclass.superclass);
|
||||
if( !classIsAbstract ) {
|
||||
concreteClasses.add(jclass)
|
||||
abstractText = ""
|
||||
}
|
||||
|
||||
def properties = jclass.declaredProperties.findAll { isValidProperty(it) }
|
||||
|
||||
def testClassName = jclass.simpleName + "Test"
|
||||
if (classIsAbstract)
|
||||
testClassName += "Support"
|
||||
|
||||
def file = new File(destDir, testClassName + ".java")
|
||||
|
||||
buffer << """
|
||||
${jclass.simpleName}Test.class
|
||||
"""
|
||||
|
||||
file.withWriter { out |
|
||||
out << """/**
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.activemq.openwire.v${openwireVersion};
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.activemq.openwire.*;
|
||||
import org.apache.activemq.command.*;
|
||||
"""
|
||||
for (pkg in jclass.importedPackages) {
|
||||
for (clazz in pkg.classes) {
|
||||
out << "import "+clazz.qualifiedName+";"
|
||||
}
|
||||
}
|
||||
|
||||
def baseClass = "DataFileGeneratorTestSupport"
|
||||
if (!jclass.superclass.simpleName.equals("JNDIBaseStorable") && !jclass.superclass.simpleName.equals("DataStructureSupport") && !jclass.superclass.simpleName.equals("Object") ) {
|
||||
baseClass = jclass.superclass.simpleName + "Test";
|
||||
if (isBaseAbstract)
|
||||
baseClass += "Support"
|
||||
}
|
||||
|
||||
def marshallerAware = isMarshallAware(jclass);
|
||||
|
||||
out << """
|
||||
|
||||
/**
|
||||
* Test case for the OpenWire marshalling for ${jclass.simpleName}
|
||||
*
|
||||
*
|
||||
* NOTE!: This file is auto generated - do not modify!
|
||||
* if you need to make a change, please see the modify the groovy scripts in the
|
||||
* under src/gram/script and then use maven openwire:generate to regenerate
|
||||
* this file.
|
||||
*
|
||||
* @version \$Revision: \$
|
||||
*/
|
||||
public ${abstractText}class $testClassName extends $baseClass {
|
||||
"""
|
||||
if (!classIsAbstract)
|
||||
out << """
|
||||
|
||||
public static ${jclass.simpleName}Test SINGLETON = new ${jclass.simpleName}Test();
|
||||
|
||||
public Object createObject() throws Exception {
|
||||
${jclass.simpleName} info = new ${jclass.simpleName}();
|
||||
populateObject(info);
|
||||
return info;
|
||||
}
|
||||
"""
|
||||
out << """
|
||||
|
||||
protected void populateObject(Object object) throws Exception {
|
||||
super.populateObject(object);
|
||||
${jclass.simpleName} info = (${jclass.simpleName}) object;
|
||||
"""
|
||||
|
||||
def generator = new TestDataGenerator();
|
||||
|
||||
for (property in properties) {
|
||||
def annotation = property.getter.getAnnotation("openwire:property");
|
||||
def size = annotation.getValue("size");
|
||||
def testSize = stringValue(annotation, "testSize");
|
||||
def type = property.type.simpleName
|
||||
def cached = isCachedProperty(property);
|
||||
def propertyName = property.simpleName;
|
||||
if (testSize == "-1") continue
|
||||
|
||||
out << " "
|
||||
switch (type) {
|
||||
case "boolean":
|
||||
out << "info.${property.setter.simpleName}(${generator.createBool()});"; break;
|
||||
case "byte":
|
||||
out << "info.${property.setter.simpleName}(${generator.createByte()});"; break;
|
||||
case "char":
|
||||
out << "info.${property.setter.simpleName}(${generator.createChar()});"; break;
|
||||
case "short":
|
||||
out << "info.${property.setter.simpleName}(${generator.createShort()});"; break;
|
||||
case "int":
|
||||
out << "info.${property.setter.simpleName}(${generator.createInt()});"; break;
|
||||
case "long":
|
||||
out << "info.${property.setter.simpleName}(${generator.createLong()});"; break;
|
||||
case "byte[]":
|
||||
out << """info.${property.setter.simpleName}(${generator.createByteArray(propertyName)});"""; break;
|
||||
case "String":
|
||||
out << """info.${property.setter.simpleName}("${generator.createString(propertyName)}");"""; break;
|
||||
case "ByteSequence":
|
||||
out << """
|
||||
{
|
||||
byte data[] = ${generator.createByteArray(propertyName)};
|
||||
info.${property.setter.simpleName}(new org.apache.activeio.packet.ByteSequence(data,0,data.length));
|
||||
}
|
||||
""";
|
||||
break;
|
||||
case "Throwable":
|
||||
out << """info.${property.setter.simpleName}(createThrowable("${generator.createString(propertyName)}"));"""; break;
|
||||
default:
|
||||
if( property.type.arrayType ) {
|
||||
def arrayType = property.type.arrayComponentType.simpleName;
|
||||
if (size == null)
|
||||
size = 2
|
||||
if (arrayType == jclass.simpleName)
|
||||
size = 0
|
||||
|
||||
out << """
|
||||
{
|
||||
${arrayType} value[] = new ${arrayType}[${size}];
|
||||
for( int i=0; i < ${size}; i++ ) {
|
||||
value[i] = create${arrayType}("${generator.createString(propertyName)}");
|
||||
}
|
||||
info.${property.setter.simpleName}(value);
|
||||
}"""
|
||||
}
|
||||
else {
|
||||
out << """info.${property.setter.simpleName}(create${type}("${generator.createString(propertyName)}"));"""
|
||||
}
|
||||
}
|
||||
out.newLine()
|
||||
}
|
||||
out << """
|
||||
}
|
||||
}
|
||||
"""
|
||||
}
|
||||
// Use the FixCRLF Ant Task to make sure the file has consistent newlines
|
||||
// so that SVN does not complain on checkin.
|
||||
Project project = new Project();
|
||||
project.init();
|
||||
FixCRLF fixCRLF = new FixCRLF();
|
||||
fixCRLF.setProject(project);
|
||||
fixCRLF.setSrcdir(file.getParentFile());
|
||||
fixCRLF.setIncludes(file.getName());
|
||||
fixCRLF.execute();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue