This is an automated email from the ASF dual-hosted git repository. dfoulks pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/activemq-nms-openwire-generator.git
commit 3b257ca54bba89e1d4bdda8bbb66ca80e185b09c Author: Timothy A. Bish <[email protected]> AuthorDate: Wed Jul 29 19:11:11 2009 +0000 Commands Generator, produces CSharp Openwire Command classes with mostly all the same functionality as the older hand hacked ones, plus all the correct Openwire Protocol values for v1-v5 --- .../nms/openwire/tool/AmqCSharpGeneratorTask.java | 2 +- .../tool/commands/CommandClassGenerator.java | 116 +++++++++++++++------ .../tool/commands/CommandCodeGenerator.java | 61 +++++------ .../commands/CommandCodeGeneratorsFactory.java | 66 +++--------- .../openwire/tool/commands/CommandGenerator.java | 9 +- .../tool/commands/ConnectionIdGenerator.java | 46 ++++++++ .../tool/commands/ConnectionInfoGenerator.java | 26 +++++ .../tool/commands/ConsumerIdGenerator.java | 62 +++++++++++ .../tool/commands/ConsumerInfoGenerator.java | 26 +++++ .../tool/commands/DestinationInfoGenerator.java | 66 ++++++++++++ .../openwire/tool/commands/MessageGenerator.java | 54 ++++++++++ .../tool/commands/ProducerIdGenerator.java | 62 +++++++++++ .../tool/commands/ProducerInfoGenerator.java | 26 +++++ .../tool/commands/RemoveInfoGenerator.java | 39 +++++++ .../openwire/tool/commands/SessionIdGenerator.java | 75 +++++++++++++ .../tool/commands/SessionInfoGenerator.java | 42 ++++++++ .../tool/commands/TransactionInfoGenerator.java | 63 +++++++++++ 17 files changed, 725 insertions(+), 116 deletions(-) diff --git a/src/main/java/org/apache/activemq/nms/openwire/tool/AmqCSharpGeneratorTask.java b/src/main/java/org/apache/activemq/nms/openwire/tool/AmqCSharpGeneratorTask.java index cf04a10..d3b84f5 100644 --- a/src/main/java/org/apache/activemq/nms/openwire/tool/AmqCSharpGeneratorTask.java +++ b/src/main/java/org/apache/activemq/nms/openwire/tool/AmqCSharpGeneratorTask.java @@ -29,7 +29,7 @@ import org.codehaus.jam.JamServiceParams; public class AmqCSharpGeneratorTask extends Task { - int maxVersion = 3; + int maxVersion = 5; File source = new File("."); File target = new File("."); diff --git a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/CommandClassGenerator.java b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/CommandClassGenerator.java index f86b677..40386eb 100644 --- a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/CommandClassGenerator.java +++ b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/CommandClassGenerator.java @@ -38,7 +38,6 @@ public class CommandClassGenerator extends CommandCodeGenerator { out.println(""); out.println("namespace Apache.NMS.ActiveMQ.Commands"); out.println("{"); - out.println(""); out.println(" /*"); out.println(" *"); out.println(" * Command code for OpenWire format for "+getClassName() ); @@ -57,6 +56,10 @@ public class CommandClassGenerator extends CommandCodeGenerator { generateProperties( out ); out.println(""); + + generateConstructors(out); + + out.println(""); out.println(" ///"); out.println(" /// <summery>"); out.println(" /// Get the unique identifier that this object and its own"); @@ -68,16 +71,20 @@ public class CommandClassGenerator extends CommandCodeGenerator { out.println(" return ID_" + getClassName().toUpperCase() + ";"); out.println(" }"); out.println(""); -// out.println(" ///"); -// out.println(" /// <summery>"); -// out.println(" /// Clone this object and return a new instance that the caller now owns."); -// out.println(" /// </summery>"); -// out.println(" ///"); -// out.println(" public override Object Clone()"); -// out.println(" {"); -// generateCloneBody( out ); -// out.println(" }"); -// out.println(""); + + if( isCloneable() ) { + out.println(" ///"); + out.println(" /// <summery>"); + out.println(" /// Clone this object and return a new instance that the caller now owns."); + out.println(" /// </summery>"); + out.println(" ///"); + out.println(" public override Object Clone()"); + out.println(" {"); + generateCloneBody( out ); + out.println(" }"); + out.println(""); + } + out.println(" ///"); out.println(" /// <summery>"); out.println(" /// Returns a string containing the information for this DataStructure"); @@ -93,7 +100,30 @@ public class CommandClassGenerator extends CommandCodeGenerator { generateAdditonalMembers( out ); generatePropertyAccessors( out ); - if( isGenIsClass() ) { + if( isComparable() ) { + + out.println(" public override int GetHashCode()"); + out.println(" {"); + generateHashCodeBody(out); + out.println(" }"); + out.println(""); + out.println(" public override bool Equals(object that)"); + out.println(" {"); + out.println(" if(that is "+getClassName()+")"); + out.println(" {"); + out.println(" return Equals(("+getClassName()+") that);"); + out.println(" }"); + out.println(" return false;"); + out.println(" }"); + out.println(""); + out.println(" public virtual bool Equals("+getClassName()+" that)"); + out.println(" {"); + generateEqualsBody(out); + out.println(" }"); + + } + + if( getBaseClassName().equals( "BaseCommand" ) ) { out.println(" ///"); out.println(" /// <summery>"); out.println(" /// Return an answer of true to the is"+getClassName()+"() query."); @@ -117,7 +147,7 @@ public class CommandClassGenerator extends CommandCodeGenerator { out.println(" /// the proper processXXX method in the visitor." ); out.println(" /// </summery>"); out.println(" ///"); - out.println(" public override Response visit( ICommandVisitor visitor )" ); + out.println(" public override Response visit(ICommandVisitor visitor)" ); out.println(" {"); generateVisitBody(out); out.println(" }"); @@ -135,14 +165,26 @@ public class CommandClassGenerator extends CommandCodeGenerator { out.print( getBaseClassName() ); + for( String name : getAdditionalBases() ) { + out.print( ", "+name ); + } + if( isMarshalAware() ) { out.print( ", MarshallAware" ); } + if( isCloneable() ) { + out.print( ", ICloneable" ); + } + out.println(); out.println(" {"); } + protected void generateConstructors( PrintWriter out ) { + // The default constructor is fine for basic Commands. + } + protected void generateProperties( PrintWriter out ) { for( JProperty property : getProperties() ) { @@ -178,24 +220,7 @@ public class CommandClassGenerator extends CommandCodeGenerator { out.println(" // this method is an override."); out.println(" " + getClassName() + " o = (" + getClassName() + ") base.Clone();"); out.println(""); - - for( JProperty property : getProperties() ) { - - String type = toCSharpType(property.getType()); - String name = decapitalize(property.getSimpleName()); - - if( property.getType().isArrayType() ) { - - } else if( !property.getType().isPrimitiveType() ) { - - out.println(" if(o." + name + " != null)"); - out.println(" {"); - out.println(" o." + name + " = (" + type + ") o." + name + ".Clone();"); - out.println(" }"); - out.println(""); - } - - } + out.println(" return o;"); } protected void generateAdditonalMembers( PrintWriter out ) { @@ -218,4 +243,33 @@ public class CommandClassGenerator extends CommandCodeGenerator { } } + protected void generateHashCodeBody( PrintWriter out ) { + out.println(" int answer = 0;"); + out.println(""); + + for( JProperty property : getProperties() ) { + String accessorName = property.getSimpleName(); + + out.println(" answer = (answer * 37) + HashCode("+accessorName+");"); + } + + out.println(""); + out.println(" return answer;"); + } + + protected void generateEqualsBody( PrintWriter out ) { + + for( JProperty property : getProperties() ) { + String accessorName = property.getSimpleName(); + + out.println(" if(!Equals(this."+accessorName+", that."+accessorName+"))"); + out.println(" {"); + out.println(" return false;"); + out.println(" }"); + } + + out.println(""); + out.println(" return true;"); + } + } diff --git a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/CommandCodeGenerator.java b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/CommandCodeGenerator.java index cbacec2..7faaf0e 100644 --- a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/CommandCodeGenerator.java +++ b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/CommandCodeGenerator.java @@ -18,6 +18,8 @@ package org.apache.activemq.nms.openwire.tool.commands; import java.io.PrintWriter; import java.util.List; +import java.util.Set; +import java.util.TreeSet; import org.codehaus.jam.JClass; import org.codehaus.jam.JProperty; @@ -26,11 +28,13 @@ public abstract class CommandCodeGenerator { private JClass jClass; private List<JProperty> properties; + private Set<String> additionalBases = new TreeSet<String>(); private boolean marshalAware = false; private String className; private String baseClassName; private String openWireOpCode; - private boolean genIsClass = false; + private boolean cloneable; + private boolean comparable; public abstract void generate( PrintWriter out ); @@ -54,14 +58,6 @@ public abstract class CommandCodeGenerator { out.println(""); } - public boolean isGenIsClass() { - return genIsClass; - } - - public void setGenIsClass(boolean genIsClass) { - this.genIsClass = genIsClass; - } - public JClass getJClass() { return jClass; } @@ -78,6 +74,14 @@ public abstract class CommandCodeGenerator { this.properties = properties; } + public boolean isComparable() { + return comparable; + } + + public void setComparable(boolean comparable) { + this.comparable = comparable; + } + public boolean isMarshalAware() { return marshalAware; } @@ -86,6 +90,14 @@ public abstract class CommandCodeGenerator { this.marshalAware = marshalAware; } + public boolean isCloneable() { + return cloneable; + } + + public void setCloneable(boolean cloneable) { + this.cloneable = cloneable; + } + public String getClassName() { return className; } @@ -110,26 +122,17 @@ public abstract class CommandCodeGenerator { this.openWireOpCode = openWireOpCode; } -// protected String toFileName( JClass type ) { -// String name = type.getSimpleName(); -// -// if( name.equals( "String" ) ) { -// return null; -// } else if( type.isArrayType() ) { -// JClass arrayClass = type.getArrayComponentType(); -// return toHeaderFileName( arrayClass ); -// } else if( name.equals( "Throwable" ) || name.equals( "Exception" ) ) { -// return "BrokerError"; -// } else if( name.equals("BaseDataStructure" ) ){ -// return "DataStructure"; -// } else if( name.equals("ByteSequence") ) { -// return "std::vector<unsigned char>"; -// } else if( !type.isPrimitiveType() ) { -// return name; -// } else { -// return null; -// } -// } + public void addAdditionalBase( String name ) { + this.additionalBases.add(name); + } + + public Set<String> getAdditionalBases() { + return additionalBases; + } + + public void setAdditionalBases(Set<String> additionalBases) { + this.additionalBases = additionalBases; + } protected String toCSharpType(JClass type) { String name = type.getSimpleName(); diff --git a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/CommandCodeGeneratorsFactory.java b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/CommandCodeGeneratorsFactory.java index 95ae4ce..fd3e45c 100644 --- a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/CommandCodeGeneratorsFactory.java +++ b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/CommandCodeGeneratorsFactory.java @@ -16,9 +16,6 @@ */ package org.apache.activemq.nms.openwire.tool.commands; -import java.util.HashSet; -import java.util.Set; - /** * Provides methods to get a Source file and Header file Code generator given a Class * name. @@ -27,35 +24,6 @@ import java.util.Set; */ public class CommandCodeGeneratorsFactory { - private Set<String> commandsWithShortcuts; - - /* - * Here we store all Commands that need to have a isXXX method generated - * such as isMessage. We then check in the <code>checkNeedsShortcut</code> - * method and if the Command being generated is in this list we create a - * method call to override the virtual method in the base Command interface. - */ - { - commandsWithShortcuts = new HashSet<String>(); - commandsWithShortcuts.add( "Response" ); - commandsWithShortcuts.add( "RemoveInfo" ); - commandsWithShortcuts.add( "MessageDispatch" ); - commandsWithShortcuts.add( "BrokerInfo" ); - commandsWithShortcuts.add( "KeepAliveInfo" ); - commandsWithShortcuts.add( "WireFormatInfo" ); - commandsWithShortcuts.add( "Message" ); - commandsWithShortcuts.add( "MessageAck" ); - commandsWithShortcuts.add( "ProducerAck" ); - commandsWithShortcuts.add( "ProducerInfo" ); - commandsWithShortcuts.add( "MessageDispatchNotification" ); - commandsWithShortcuts.add( "ShutdownInfo" ); - commandsWithShortcuts.add( "TransactionInfo" ); - commandsWithShortcuts.add( "ConnectionInfo" ); - commandsWithShortcuts.add( "ConsumerInfo" ); - commandsWithShortcuts.add( "RemoveSubscriptionInfo" ); - - } - /** * Given a class name return an instance of a CSharp Class File Generator * that can generate the file for the Class. @@ -66,25 +34,23 @@ public class CommandCodeGeneratorsFactory { */ public CommandCodeGenerator getCodeGenerator( String className ) { - CommandCodeGenerator generator = null; -// if( className.equals("Message") ) { -// generator = new MessageHeaderGenerator(); -// } else if( className.equals("ConnectionId") ) { -// generator = new ConnectionIdHeaderGenerator(); -// } else if( className.equals("ConsumerId") ) { -// generator = new ConsumerIdHeaderGenerator(); -// } else if( className.equals("ProducerId") ) { -// generator = new ProducerIdHeaderGenerator(); -// } else if( className.equals("SessionId") ) { -// generator = new SessionIdHeaderGenerator(); -// } else if( className.equals("SessionInfo") ) { -// generator = new SessionInfoHeaderGenerator(); -// } else { - generator = new CommandClassGenerator(); -// } + Class<?> generatorClass = null; + + try { + generatorClass = Class.forName( "org.apache.activemq.nms.openwire.tool.commands." + className + "Generator" ); + } catch (ClassNotFoundException e) { + return new CommandClassGenerator(); + } - if( this.commandsWithShortcuts.contains( className ) ) { - generator.setGenIsClass( true ); + CommandCodeGenerator generator; + try { + generator = (CommandCodeGenerator) generatorClass.newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + return null; + } catch (IllegalAccessException e) { + e.printStackTrace(); + return null; } return generator; diff --git a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/CommandGenerator.java b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/CommandGenerator.java index efe5a67..ef4eca1 100644 --- a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/CommandGenerator.java +++ b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/CommandGenerator.java @@ -56,7 +56,7 @@ public class CommandGenerator extends MultiSourceGenerator { try { // Using the current JClass state in the MultiSourceGenerator we can - // now generate the Header and Source for the CSharp commands. + // now generate the Source for the CSharp commands. generateClassFile(); } catch (Exception e) { e.printStackTrace(); @@ -64,7 +64,6 @@ public class CommandGenerator extends MultiSourceGenerator { } public Object run() { - filePostFix = ".cs"; if (destDir == null) { destDir = new File( targetDir+"/Commands"); @@ -75,7 +74,7 @@ public class CommandGenerator extends MultiSourceGenerator { protected void generateClassFile() throws Exception { - File headerFile = new File(destDir, className + filePostFix); + File headerFile = new File(destDir, className + ".cs"); CommandCodeGenerator generator = generatorsFactory.getCodeGenerator( className ); @@ -85,6 +84,7 @@ public class CommandGenerator extends MultiSourceGenerator { generator.setClassName( getClassName() ); generator.setBaseClassName( getBaseClass() ); generator.setOpenWireOpCode( getOpenWireOpCode(getJclass()) ); + generator.setComparable( className.endsWith("Id") ); PrintWriter out = null; try { @@ -99,8 +99,7 @@ public class CommandGenerator extends MultiSourceGenerator { } // Use the FixCRLF Ant Task to make sure the file has consistent - // newlines - // so that SVN does not complain on checkin. + // newlines so that SVN does not complain on checkin. Project project = new Project(); project.init(); FixCRLF fixCRLF = new FixCRLF(); diff --git a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ConnectionIdGenerator.java b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ConnectionIdGenerator.java new file mode 100644 index 0000000..e8b1111 --- /dev/null +++ b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ConnectionIdGenerator.java @@ -0,0 +1,46 @@ +/** + * 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.nms.openwire.tool.commands; + +import java.io.PrintWriter; + +public class ConnectionIdGenerator extends CommandClassGenerator { + + protected void generateConstructors( PrintWriter out ) { + out.println(" public "+getClassName()+"()"); + out.println(" {"); + out.println(" }"); + out.println(""); + out.println(" public "+getClassName()+"( SessionId sessionId )"); + out.println(" {"); + out.println(" this.value = sessionId.ConnectionId;"); + out.println(" }"); + out.println(""); + out.println(" public "+getClassName()+"( ProducerId producerId )"); + out.println(" {"); + out.println(" this.value = producerId.ConnectionId;"); + out.println(" }"); + out.println(""); + out.println(" public "+getClassName()+"( ConsumerId consumerId )"); + out.println(" {"); + out.println(" this.value = consumerId.ConnectionId;"); + out.println(" }"); + out.println(""); + + super.generateConstructors(out); + } +} diff --git a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ConnectionInfoGenerator.java b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ConnectionInfoGenerator.java new file mode 100644 index 0000000..77c647e --- /dev/null +++ b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ConnectionInfoGenerator.java @@ -0,0 +1,26 @@ +/** + * 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.nms.openwire.tool.commands; + +import java.io.PrintWriter; + +public class ConnectionInfoGenerator extends CommandClassGenerator { + + protected void generateVisitBody( PrintWriter out ) { + out.println(" return visitor.processAddConnection( this );"); + } +} diff --git a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ConsumerIdGenerator.java b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ConsumerIdGenerator.java new file mode 100644 index 0000000..396a85c --- /dev/null +++ b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ConsumerIdGenerator.java @@ -0,0 +1,62 @@ +/** + * 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.nms.openwire.tool.commands; + +import java.io.PrintWriter; + +public class ConsumerIdGenerator extends CommandClassGenerator { + + protected void generateConstructors( PrintWriter out ) { + + out.println(" public "+getClassName()+"() {"); + out.println(" }"); + out.println(""); + out.println(" public "+getClassName()+"( SessionId sessionId, long consumerId ) {"); + out.println(" this.connectionId = sessionId.ConnectionId;"); + out.println(" this.sessionId = sessionId.Value;"); + out.println(" this.value = consumerId;"); + out.println(" }"); + out.println(""); + + super.generateConstructors(out); + } + + protected void generateProperties( PrintWriter out ) { + + out.println(" private SessionId parentId = null;"); + out.println(""); + + super.generateProperties(out); + } + + protected void generateAdditonalMembers( PrintWriter out ) { + out.println(" public SessionId ParentId"); + out.println(" {"); + out.println(" get"); + out.println(" {"); + out.println(" if( this.parentId == null ) {"); + out.println(" this.parentId = new SessionId( this );"); + out.println(" }"); + out.println(" return this.parentId;"); + out.println(" }"); + out.println(" }"); + out.println(""); + + super.generateAdditonalMembers( out ); + } + +} diff --git a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ConsumerInfoGenerator.java b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ConsumerInfoGenerator.java new file mode 100644 index 0000000..5eaf17b --- /dev/null +++ b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ConsumerInfoGenerator.java @@ -0,0 +1,26 @@ +/** + * 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.nms.openwire.tool.commands; + +import java.io.PrintWriter; + +public class ConsumerInfoGenerator extends CommandClassGenerator { + + protected void generateVisitBody( PrintWriter out ) { + out.println(" return visitor.processAddConsumer( this );"); + } +} diff --git a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/DestinationInfoGenerator.java b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/DestinationInfoGenerator.java new file mode 100644 index 0000000..7875203 --- /dev/null +++ b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/DestinationInfoGenerator.java @@ -0,0 +1,66 @@ +/** + * 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.nms.openwire.tool.commands; + +import java.io.PrintWriter; + +public class DestinationInfoGenerator extends CommandClassGenerator { + + protected void generateVisitBody( PrintWriter out ) { + + out.println(" if(IsAddOperation)"); + out.println(" {"); + out.println(" return visitor.processAddDestination(this);"); + out.println(" }"); + out.println(" else if(IsRemoveOperation)"); + out.println(" {"); + out.println(" return visitor.processRemoveDestination(this);"); + out.println(" }"); + out.println(" throw new IOException(\"Unknown operation type: \" + OperationType);"); + + } + + protected void generateProperties( PrintWriter out ) { + + out.println(" public const byte ADD_OPERATION_TYPE = 0;"); + out.println(" public const byte REMOVE_OPERATION_TYPE = 1;"); + + super.generateProperties(out); + } + + protected void generateAdditonalMembers( PrintWriter out ) { + + out.println(" public bool IsAddOperation"); + out.println(" {"); + out.println(" get"); + out.println(" {"); + out.println(" return OperationType == ADD_OPERATION_TYPE;"); + out.println(" }"); + out.println(" }"); + out.println(""); + out.println(" public bool IsRemoveOperation"); + out.println(" {"); + out.println(" get"); + out.println(" {"); + out.println(" return OperationType == REMOVE_OPERATION_TYPE;"); + out.println(" }"); + out.println(" }"); + + super.generateAdditonalMembers(out); + } + +} diff --git a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/MessageGenerator.java b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/MessageGenerator.java new file mode 100644 index 0000000..b92fa62 --- /dev/null +++ b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/MessageGenerator.java @@ -0,0 +1,54 @@ +/** + * 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.nms.openwire.tool.commands; + +import java.io.PrintWriter; + +public class MessageGenerator extends CommandClassGenerator { + + public MessageGenerator() { + super.setMarshalAware(true); + super.setCloneable(true); + super.addAdditionalBase("MessageReference"); + } + + protected void generateProperties( PrintWriter out ) { + + super.generateProperties(out); + } + + protected void generateAdditonalMembers( PrintWriter out ) { + + super.generateAdditonalMembers( out ); + } + + protected void generateCloneBody( PrintWriter out ) { + + out.println(" // Since we are a derived class use the base's Clone()"); + out.println(" // to perform the shallow copy. Since it is shallow it"); + out.println(" // will include our derived class. Since we are derived,"); + out.println(" // this method is an override."); + out.println(" " + getClassName() + " o = (" + getClassName() + ") base.Clone();"); + out.println(""); + out.println(" if( this.messageId != null )"); + out.println(" {"); + out.println(" o.MessageId = (MessageId) this.messageId.Clone();"); + out.println(" }"); + out.println(""); + out.println(" return o;"); + } +} diff --git a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ProducerIdGenerator.java b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ProducerIdGenerator.java new file mode 100644 index 0000000..c42817a --- /dev/null +++ b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ProducerIdGenerator.java @@ -0,0 +1,62 @@ +/** + * 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.nms.openwire.tool.commands; + +import java.io.PrintWriter; + +public class ProducerIdGenerator extends CommandClassGenerator { + + protected void generateConstructors( PrintWriter out ) { + + out.println(" public "+getClassName()+"() {"); + out.println(" }"); + out.println(""); + out.println(" public "+getClassName()+"( SessionId sessionId, long consumerId ) {"); + out.println(" this.connectionId = sessionId.ConnectionId;"); + out.println(" this.sessionId = sessionId.Value;"); + out.println(" this.value = consumerId;"); + out.println(" }"); + out.println(""); + + super.generateConstructors(out); + } + + protected void generateProperties( PrintWriter out ) { + + out.println(" private SessionId parentId;"); + out.println(""); + + super.generateProperties(out); + } + + protected void generateAdditonalMembers( PrintWriter out ) { + out.println(" public SessionId ParentId"); + out.println(" {"); + out.println(" get"); + out.println(" {"); + out.println(" if( this.parentId == null ) {"); + out.println(" this.parentId = new SessionId( this );"); + out.println(" }"); + out.println(" return this.parentId;"); + out.println(" }"); + out.println(" }"); + out.println(""); + + super.generateAdditonalMembers( out ); + } + +} diff --git a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ProducerInfoGenerator.java b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ProducerInfoGenerator.java new file mode 100644 index 0000000..70d7f2c --- /dev/null +++ b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/ProducerInfoGenerator.java @@ -0,0 +1,26 @@ +/** + * 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.nms.openwire.tool.commands; + +import java.io.PrintWriter; + +public class ProducerInfoGenerator extends CommandClassGenerator { + + protected void generateVisitBody( PrintWriter out ) { + out.println(" return visitor.processAddProducer( this );"); + } +} diff --git a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/RemoveInfoGenerator.java b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/RemoveInfoGenerator.java new file mode 100644 index 0000000..038dd71 --- /dev/null +++ b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/RemoveInfoGenerator.java @@ -0,0 +1,39 @@ +/** + * 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.nms.openwire.tool.commands; + +import java.io.PrintWriter; + +public class RemoveInfoGenerator extends CommandClassGenerator { + + protected void generateVisitBody( PrintWriter out ) { + + out.println(" switch(objectId.GetDataStructureType())"); + out.println(" {"); + out.println(" case ConnectionId.ID_CONNECTIONID:"); + out.println(" return visitor.processRemoveConnection((ConnectionId) objectId);"); + out.println(" case SessionId.ID_SESSIONID:"); + out.println(" return visitor.processRemoveSession((SessionId) objectId);"); + out.println(" case ConsumerId.ID_CONSUMERID:"); + out.println(" return visitor.processRemoveConsumer((ConsumerId) objectId);"); + out.println(" case ProducerId.ID_PRODUCERID:"); + out.println(" return visitor.processRemoveProducer((ProducerId) objectId);"); + out.println(" default:"); + out.println(" throw new IOException(\"Unknown remove command type: \" + objectId.GetDataStructureType());"); + out.println(" }"); + } +} diff --git a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/SessionIdGenerator.java b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/SessionIdGenerator.java new file mode 100644 index 0000000..2e86d45 --- /dev/null +++ b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/SessionIdGenerator.java @@ -0,0 +1,75 @@ +/** + * 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.nms.openwire.tool.commands; + +import java.io.PrintWriter; + +public class SessionIdGenerator extends CommandClassGenerator { + + protected void generateConstructors( PrintWriter out ) { + + out.println(" public "+getClassName()+"()"); + out.println(" {"); + out.println(" }"); + out.println(""); + out.println(" public "+getClassName()+"( ConnectionId connectionId, long sessionId )"); + out.println(" {"); + out.println(" this.ConnectionId = connectionId.Value;"); + out.println(" this.value = sessionId;"); + out.println(" }"); + out.println(""); + out.println(" public "+getClassName()+"( ProducerId producerId )"); + out.println(" {"); + out.println(" this.ConnectionId = producerId.ConnectionId;"); + out.println(" this.value = producerId.SessionId;"); + out.println(" }"); + out.println(""); + out.println(" public "+getClassName()+"( ConsumerId consumerId )"); + out.println(" {"); + out.println(" this.ConnectionId = consumerId.ConnectionId;"); + out.println(" this.value = consumerId.SessionId;"); + out.println(" }"); + out.println(""); + + super.generateConstructors(out); + } + + protected void generateProperties( PrintWriter out ) { + + out.println(" private ConnectionId parentId;"); + out.println(""); + + super.generateProperties(out); + } + + protected void generateAdditonalMembers( PrintWriter out ) { + out.println(" public ConnectionId getParentId"); + out.println(" {"); + out.println(" get"); + out.println(" {"); + out.println(" if( this.parentId == null ) {"); + out.println(" this.parentId = new ConnectionId( this );"); + out.println(" }"); + out.println(" return this.parentId;"); + out.println(" }"); + out.println(" }"); + out.println(""); + + super.generateAdditonalMembers( out ); + } + +} diff --git a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/SessionInfoGenerator.java b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/SessionInfoGenerator.java new file mode 100644 index 0000000..672949e --- /dev/null +++ b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/SessionInfoGenerator.java @@ -0,0 +1,42 @@ +/** + * 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.nms.openwire.tool.commands; + +import java.io.PrintWriter; + +public class SessionInfoGenerator extends CommandClassGenerator { + + protected void generateVisitBody( PrintWriter out ) { + out.println(" return visitor.processAddSession( this );"); + } + + protected void generateConstructors( PrintWriter out ) { + + out.println(" public "+getClassName()+"()"); + out.println(" {"); + out.println(" }"); + out.println(""); + out.println(" public "+getClassName()+"(ConnectionInfo connectionInfo, long sessionId)"); + out.println(" {"); + out.println(" this.sessionId = new SessionId(connectionInfo.ConnectionId, sessionId);"); + out.println(" }"); + out.println(""); + + super.generateConstructors(out); + } + +} diff --git a/src/main/java/org/apache/activemq/nms/openwire/tool/commands/TransactionInfoGenerator.java b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/TransactionInfoGenerator.java new file mode 100644 index 0000000..025a68c --- /dev/null +++ b/src/main/java/org/apache/activemq/nms/openwire/tool/commands/TransactionInfoGenerator.java @@ -0,0 +1,63 @@ +/** + * 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.nms.openwire.tool.commands; + +import java.io.PrintWriter; + +public class TransactionInfoGenerator extends CommandClassGenerator { + + protected void generateVisitBody( PrintWriter out ) { + + out.println(" switch(type)"); + out.println(" {"); + out.println(" case TransactionInfo.BEGIN:"); + out.println(" return visitor.processBeginTransaction(this);"); + out.println(" case TransactionInfo.END:"); + out.println(" return visitor.processEndTransaction(this);"); + out.println(" case TransactionInfo.PREPARE:"); + out.println(" return visitor.processPrepareTransaction(this);"); + out.println(" case TransactionInfo.COMMIT_ONE_PHASE:"); + out.println(" return visitor.processCommitTransactionOnePhase(this);"); + out.println(" case TransactionInfo.COMMIT_TWO_PHASE:"); + out.println(" return visitor.processCommitTransactionTwoPhase(this);"); + out.println(" case TransactionInfo.ROLLBACK:"); + out.println(" return visitor.processRollbackTransaction(this);"); + out.println(" case TransactionInfo.RECOVER:"); + out.println(" return visitor.processRecoverTransactions(this);"); + out.println(" case TransactionInfo.FORGET:"); + out.println(" return visitor.processForgetTransaction(this);"); + out.println(" default:"); + out.println(" throw new IOException(\"Transaction info type unknown: \" + type);"); + out.println(" }"); + } + + protected void generateProperties( PrintWriter out ) { + + out.println(" public const byte BEGIN = 0;"); + out.println(" public const byte PREPARE = 1;"); + out.println(" public const byte COMMIT_ONE_PHASE = 2;"); + out.println(" public const byte COMMIT_TWO_PHASE = 3;"); + out.println(" public const byte ROLLBACK = 4;"); + out.println(" public const byte RECOVER = 5;"); + out.println(" public const byte FORGET = 6;"); + out.println(" public const byte END = 7;"); + out.println(""); + + super.generateProperties(out); + } + +}
