mirror of https://github.com/apache/activemq.git
The openwire generation scripts have moved to the activemq-openwire-generator module
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@426386 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7f883f6fe2
commit
8c9a6ebb53
|
@ -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$
|
||||
*/
|
||||
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,394 +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 org.codehaus.jam.JAnnotation;
|
||||
import org.codehaus.jam.JAnnotationValue;
|
||||
import org.codehaus.jam.JClass;
|
||||
import org.codehaus.jam.JProperty;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
public abstract class OpenWireCSharpMarshallingScript extends OpenWireJavaMarshallingScript {
|
||||
|
||||
public Object run() {
|
||||
filePostFix = ".cs";
|
||||
if (destDir == null) {
|
||||
destDir = new File("../activemq-dotnet/src/main/csharp/ActiveMQ/OpenWire/V"+getOpenwireVersion());
|
||||
}
|
||||
|
||||
return super.run();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
// This section is for the tight wire format encoding generator
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
protected void generateTightUnmarshalBodyForProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
|
||||
|
||||
String propertyName = property.getSimpleName();
|
||||
String type = property.getType().getSimpleName();
|
||||
|
||||
if (type.equals("boolean")) {
|
||||
out.println(" info." + propertyName + " = bs.ReadBoolean();");
|
||||
}
|
||||
else if (type.equals("byte")) {
|
||||
out.println(" info." + propertyName + " = dataIn.ReadByte();");
|
||||
}
|
||||
else if (type.equals("char")) {
|
||||
out.println(" info." + propertyName + " = dataIn.ReadChar();");
|
||||
}
|
||||
else if (type.equals("short")) {
|
||||
out.println(" info." + propertyName + " = dataIn.ReadInt16();");
|
||||
}
|
||||
else if (type.equals("int")) {
|
||||
out.println(" info." + propertyName + " = dataIn.ReadInt32();");
|
||||
}
|
||||
else if (type.equals("long")) {
|
||||
out.println(" info." + propertyName + " = TightUnmarshalLong(wireFormat, dataIn, bs);");
|
||||
}
|
||||
else if (type.equals("String")) {
|
||||
out.println(" info." + propertyName + " = TightUnmarshalString(dataIn, bs);");
|
||||
}
|
||||
else if (type.equals("byte[]") || type.equals("ByteSequence")) {
|
||||
if (size != null) {
|
||||
out.println(" info." + propertyName + " = ReadBytes(dataIn, " + size.asInt() + ");");
|
||||
}
|
||||
else {
|
||||
out.println(" info." + propertyName + " = ReadBytes(dataIn, bs.ReadBoolean());");
|
||||
}
|
||||
}
|
||||
else if (isThrowable(property.getType())) {
|
||||
out.println(" info." + propertyName + " = TightUnmarshalBrokerError(wireFormat, dataIn, bs);");
|
||||
}
|
||||
else if (isCachedProperty(property)) {
|
||||
out.println(" info." + propertyName + " = (" + type + ") TightUnmarshalCachedObject(wireFormat, dataIn, bs);");
|
||||
}
|
||||
else {
|
||||
out.println(" info." + propertyName + " = (" + type + ") TightUnmarshalNestedObject(wireFormat, dataIn, bs);");
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateTightUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
|
||||
JClass propertyType = property.getType();
|
||||
String arrayType = propertyType.getArrayComponentType().getSimpleName();
|
||||
String propertyName = property.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 + ") TightUnmarshalNestedObject(wireFormat,dataIn, bs);");
|
||||
out.println(" }");
|
||||
out.println(" info." + propertyName + " = value;");
|
||||
out.println(" }");
|
||||
}
|
||||
else {
|
||||
out.println(" if (bs.ReadBoolean()) {");
|
||||
out.println(" short size = dataIn.ReadInt16();");
|
||||
out.println(" " + arrayType + "[] value = new " + arrayType + "[size];");
|
||||
out.println(" for( int i=0; i < size; i++ ) {");
|
||||
out.println(" value[i] = (" + arrayType + ") TightUnmarshalNestedObject(wireFormat,dataIn, bs);");
|
||||
out.println(" }");
|
||||
out.println(" info." + propertyName + " = value;");
|
||||
out.println(" }");
|
||||
out.println(" else {");
|
||||
out.println(" info." + propertyName + " = 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.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.print("");
|
||||
out.println(" rc += TightMarshalString1(" + getter + ", bs);");
|
||||
}
|
||||
else if (type.equals("byte[]") || type.equals("ByteSequence")) {
|
||||
if (size == null) {
|
||||
out.println(" bs.WriteBoolean(" + getter + "!=null);");
|
||||
out.println(" rc += " + getter + "==null ? 0 : " + getter + ".Length+4;");
|
||||
}
|
||||
else {
|
||||
baseSize += size.asInt();
|
||||
}
|
||||
}
|
||||
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 += TightMarshalBrokerError1(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.getSimpleName();
|
||||
|
||||
if (type.equals("boolean")) {
|
||||
out.println(" bs.ReadBoolean();");
|
||||
}
|
||||
else if (type.equals("byte")) {
|
||||
out.println(" dataOut.Write(" + getter + ");");
|
||||
}
|
||||
else if (type.equals("char")) {
|
||||
out.println(" dataOut.Write(" + getter + ");");
|
||||
}
|
||||
else if (type.equals("short")) {
|
||||
out.println(" dataOut.Write(" + getter + ");");
|
||||
}
|
||||
else if (type.equals("int")) {
|
||||
out.println(" dataOut.Write(" + 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[]") || type.equals("ByteSequence")) {
|
||||
if (size != null) {
|
||||
out.println(" dataOut.Write(" + getter + ", 0, " + size.asInt() + ");");
|
||||
}
|
||||
else {
|
||||
out.println(" if(bs.ReadBoolean()) {");
|
||||
out.println(" dataOut.Write(" + getter + ".Length);");
|
||||
out.println(" dataOut.Write(" + getter + ");");
|
||||
out.println(" }");
|
||||
}
|
||||
}
|
||||
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(" TightMarshalBrokerError2(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);");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
// This section is for the loose wire format encoding generator
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
protected void generateLooseUnmarshalBodyForProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
|
||||
|
||||
String propertyName = property.getSimpleName();
|
||||
String type = property.getType().getSimpleName();
|
||||
|
||||
if (type.equals("boolean")) {
|
||||
out.println(" info." + propertyName + " = dataIn.ReadBoolean();");
|
||||
}
|
||||
else if (type.equals("byte")) {
|
||||
out.println(" info." + propertyName + " = dataIn.ReadByte();");
|
||||
}
|
||||
else if (type.equals("char")) {
|
||||
out.println(" info." + propertyName + " = dataIn.ReadChar();");
|
||||
}
|
||||
else if (type.equals("short")) {
|
||||
out.println(" info." + propertyName + " = dataIn.ReadInt16();");
|
||||
}
|
||||
else if (type.equals("int")) {
|
||||
out.println(" info." + propertyName + " = dataIn.ReadInt32();");
|
||||
}
|
||||
else if (type.equals("long")) {
|
||||
out.println(" info." + propertyName + " = LooseUnmarshalLong(wireFormat, dataIn);");
|
||||
}
|
||||
else if (type.equals("String")) {
|
||||
out.println(" info." + propertyName + " = LooseUnmarshalString(dataIn);");
|
||||
}
|
||||
else if (type.equals("byte[]") || type.equals("ByteSequence")) {
|
||||
if (size != null) {
|
||||
out.println(" info." + propertyName + " = ReadBytes(dataIn, " + size.asInt() + ");");
|
||||
}
|
||||
else {
|
||||
out.println(" info." + propertyName + " = ReadBytes(dataIn, dataIn.ReadBoolean());");
|
||||
}
|
||||
}
|
||||
else if (isThrowable(property.getType())) {
|
||||
out.println(" info." + propertyName + " = LooseUnmarshalBrokerError(wireFormat, dataIn);");
|
||||
}
|
||||
else if (isCachedProperty(property)) {
|
||||
out.println(" info." + propertyName + " = (" + type + ") LooseUnmarshalCachedObject(wireFormat, dataIn);");
|
||||
}
|
||||
else {
|
||||
out.println(" info." + propertyName + " = (" + type + ") LooseUnmarshalNestedObject(wireFormat, dataIn);");
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateLooseUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
|
||||
JClass propertyType = property.getType();
|
||||
String arrayType = propertyType.getArrayComponentType().getSimpleName();
|
||||
String propertyName = property.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 + ") LooseUnmarshalNestedObject(wireFormat,dataIn);");
|
||||
out.println(" }");
|
||||
out.println(" info." + propertyName + " = value;");
|
||||
out.println(" }");
|
||||
}
|
||||
else {
|
||||
out.println(" if (dataIn.ReadBoolean()) {");
|
||||
out.println(" short size = dataIn.ReadInt16();");
|
||||
out.println(" " + arrayType + "[] value = new " + arrayType + "[size];");
|
||||
out.println(" for( int i=0; i < size; i++ ) {");
|
||||
out.println(" value[i] = (" + arrayType + ") LooseUnmarshalNestedObject(wireFormat,dataIn);");
|
||||
out.println(" }");
|
||||
out.println(" info." + propertyName + " = value;");
|
||||
out.println(" }");
|
||||
out.println(" else {");
|
||||
out.println(" info." + propertyName + " = null;");
|
||||
out.println(" }");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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.getSimpleName();
|
||||
|
||||
if (type.equals("boolean")) {
|
||||
out.println(" dataOut.Write(" + getter + ");");
|
||||
}
|
||||
else if (type.equals("byte")) {
|
||||
out.println(" dataOut.Write(" + getter + ");");
|
||||
}
|
||||
else if (type.equals("char")) {
|
||||
out.println(" dataOut.Write(" + getter + ");");
|
||||
}
|
||||
else if (type.equals("short")) {
|
||||
out.println(" dataOut.Write(" + getter + ");");
|
||||
}
|
||||
else if (type.equals("int")) {
|
||||
out.println(" dataOut.Write(" + 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[]") || type.equals("ByteSequence")) {
|
||||
if (size != null) {
|
||||
out.println(" dataOut.Write(" + getter + ", 0, " + size.asInt() + ");");
|
||||
}
|
||||
else {
|
||||
out.println(" dataOut.Write(" + getter + "!=null);");
|
||||
out.println(" if(" + getter + "!=null) {");
|
||||
out.println(" dataOut.Write(" + getter + ".Length);");
|
||||
out.println(" dataOut.Write(" + getter + ");");
|
||||
out.println(" }");
|
||||
}
|
||||
}
|
||||
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(" LooseMarshalBrokerError(wireFormat, " + getter + ", dataOut);");
|
||||
}
|
||||
else {
|
||||
if (isCachedProperty(property)) {
|
||||
out.println(" LooseMarshalCachedObject(wireFormat, (DataStructure)" + getter + ", dataOut);");
|
||||
}
|
||||
else {
|
||||
out.println(" LooseMarshalNestedObject(wireFormat, (DataStructure)" + getter + ", dataOut);");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,170 +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.HashSet;
|
||||
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$
|
||||
*/
|
||||
public abstract class OpenWireClassesScript extends OpenWireScript {
|
||||
protected Set manuallyMaintainedClasses = new HashSet();
|
||||
protected File destDir;
|
||||
protected File destFile;
|
||||
|
||||
protected JClass jclass;
|
||||
protected JClass superclass;
|
||||
protected String simpleName;
|
||||
protected String className;
|
||||
protected String baseClass;
|
||||
protected StringBuffer buffer;
|
||||
|
||||
public OpenWireClassesScript() {
|
||||
initialiseManuallyMaintainedClasses();
|
||||
}
|
||||
|
||||
public Object run() {
|
||||
if (destDir == null) {
|
||||
throw new IllegalArgumentException("No destDir defined!");
|
||||
}
|
||||
System.out.println(getClass().getName() + " generating files in: " + destDir);
|
||||
destDir.mkdirs();
|
||||
buffer = new StringBuffer();
|
||||
|
||||
JamClassIterator iter = getClasses();
|
||||
while (iter.hasNext()) {
|
||||
jclass = iter.nextClass();
|
||||
if (isValidClass(jclass)) {
|
||||
processClass(jclass);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.getAnnotation("openwire:marshaller") == null) {
|
||||
return false;
|
||||
}
|
||||
return !manuallyMaintainedClasses.contains(jclass.getSimpleName());
|
||||
}
|
||||
|
||||
protected void processClass(JClass jclass) {
|
||||
simpleName = jclass.getSimpleName();
|
||||
superclass = jclass.getSuperclass();
|
||||
|
||||
System.out.println(getClass().getName() + " processing class: " + simpleName);
|
||||
|
||||
className = getClassName(jclass);
|
||||
|
||||
destFile = new File(destDir, className + filePostFix);
|
||||
|
||||
baseClass = getBaseClassName(jclass);
|
||||
|
||||
PrintWriter out = null;
|
||||
try {
|
||||
out = new PrintWriter(new FileWriter(destFile));
|
||||
generateFile(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();
|
||||
}
|
||||
|
||||
protected abstract void generateFile(PrintWriter out);
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,210 +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 org.codehaus.jam.JClass;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
public abstract class OpenWireCppClassesScript extends OpenWireClassesScript {
|
||||
|
||||
public Object run() {
|
||||
filePostFix = getFilePostFix();
|
||||
if (destDir == null) {
|
||||
destDir = new File("../openwire-cpp/src/main/cpp/activemq/command");
|
||||
}
|
||||
return super.run();
|
||||
}
|
||||
|
||||
protected String getFilePostFix() {
|
||||
return ".cpp";
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the Java type to a C++ type name
|
||||
*/
|
||||
public String toCppType(JClass type) {
|
||||
String name = type.getSimpleName();
|
||||
if (name.equals("String")) {
|
||||
return "p<string>";
|
||||
}
|
||||
else if (type.isArrayType()) {
|
||||
if( name.equals("byte[]") )
|
||||
name = "char[]" ;
|
||||
else if( name.equals("DataStructure[]") )
|
||||
name = "IDataStructure[]" ;
|
||||
|
||||
return "array<" + name.substring(0, name.length()-2) + ">";
|
||||
}
|
||||
else if (name.equals("Throwable") || name.equals("Exception")) {
|
||||
return "p<BrokerError>";
|
||||
}
|
||||
else if (name.equals("ByteSequence")) {
|
||||
return "array<char>";
|
||||
}
|
||||
else if (name.equals("boolean")) {
|
||||
return "bool";
|
||||
}
|
||||
else if (name.equals("long")) {
|
||||
return "long long";
|
||||
}
|
||||
else if (name.equals("byte")) {
|
||||
return "char";
|
||||
}
|
||||
else if( name.equals("Command") || name.equals("DataStructure") ) {
|
||||
return "p<I" + name + ">" ;
|
||||
}
|
||||
else if( !type.isPrimitiveType() ) {
|
||||
return "p<" + name + ">" ;
|
||||
}
|
||||
else {
|
||||
return name ;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the Java type to a C++ default value
|
||||
*/
|
||||
public String toCppDefaultValue(JClass type) {
|
||||
String name = type.getSimpleName();
|
||||
|
||||
if ( name.equals("boolean") ) {
|
||||
return "false";
|
||||
}
|
||||
else if (!type.isPrimitiveType()) {
|
||||
return "NULL";
|
||||
}
|
||||
else {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the Java type to the name of the C++ marshal method
|
||||
* to be used
|
||||
*/
|
||||
public String toMarshalMethodName(JClass type) {
|
||||
String name = type.getSimpleName();
|
||||
if (name.equals("String")) {
|
||||
return "marshalString";
|
||||
}
|
||||
else if (type.isArrayType()) {
|
||||
if ( type.getArrayComponentType().isPrimitiveType() && name.equals("byte[]") )
|
||||
return "marshalByteArray" ;
|
||||
else
|
||||
return "marshalObjectArray" ;
|
||||
}
|
||||
else if ( name.equals("ByteSequence") ) {
|
||||
return "marshalByteArray";
|
||||
}
|
||||
else if (name.equals("short") ) {
|
||||
return "marshalShort";
|
||||
}
|
||||
else if (name.equals("int") ) {
|
||||
return "marshalInt";
|
||||
}
|
||||
else if (name.equals("long") ) {
|
||||
return "marshalLong";
|
||||
}
|
||||
else if (name.equals("byte")) {
|
||||
return "marshalByte";
|
||||
}
|
||||
else if (name.equals("double")) {
|
||||
return "marshalDouble";
|
||||
}
|
||||
else if (name.equals("float")) {
|
||||
return "marshalFloat";
|
||||
}
|
||||
else if (name.equals("boolean")) {
|
||||
return "marshalBoolean";
|
||||
}
|
||||
else if( !type.isPrimitiveType() ) {
|
||||
return "marshalObject" ;
|
||||
}
|
||||
else {
|
||||
return name ;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the Java type to the name of the C++ unmarshal method
|
||||
* to be used
|
||||
*/
|
||||
public String toUnmarshalMethodName(JClass type) {
|
||||
String name = type.getSimpleName();
|
||||
if (name.equals("String")) {
|
||||
return "unmarshalString";
|
||||
}
|
||||
else if (type.isArrayType()) {
|
||||
if ( type.getArrayComponentType().isPrimitiveType() && name.equals("byte[]") )
|
||||
return "unmarshalByteArray" ;
|
||||
else
|
||||
return "unmarshalObjectArray" ;
|
||||
}
|
||||
else if ( name.equals("ByteSequence") ) {
|
||||
return "unmarshalByteArray";
|
||||
}
|
||||
else if (name.equals("short") ) {
|
||||
return "unmarshalShort";
|
||||
}
|
||||
else if (name.equals("int") ) {
|
||||
return "unmarshalInt";
|
||||
}
|
||||
else if (name.equals("long") ) {
|
||||
return "unmarshalLong";
|
||||
}
|
||||
else if (name.equals("byte")) {
|
||||
return "unmarshalByte";
|
||||
}
|
||||
else if (name.equals("double")) {
|
||||
return "unmarshalDouble";
|
||||
}
|
||||
else if (name.equals("float")) {
|
||||
return "unmarshalFloat";
|
||||
}
|
||||
else if (name.equals("boolean")) {
|
||||
return "unmarshalBoolean";
|
||||
}
|
||||
else if( !type.isPrimitiveType() ) {
|
||||
return "unmarshalObject" ;
|
||||
}
|
||||
else {
|
||||
return name ;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the Java type to a C++ pointer cast
|
||||
*/
|
||||
public String toUnmarshalCast(JClass type) {
|
||||
String name = toCppType(type) ;
|
||||
|
||||
if( name.startsWith("p<") )
|
||||
return "p_cast<" + name.substring(2) ;
|
||||
else if( name.startsWith("array<") &&
|
||||
(type.isArrayType() && !type.getArrayComponentType().isPrimitiveType()) &&
|
||||
!type.getSimpleName().equals("ByteSequence") )
|
||||
return "array_cast<" + name.substring(6) ;
|
||||
else
|
||||
return "" ;
|
||||
}
|
||||
}
|
|
@ -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$
|
||||
*/
|
||||
public abstract class OpenWireCppHeadersScript extends OpenWireCppClassesScript {
|
||||
|
||||
protected String getFilePostFix() {
|
||||
return ".hpp";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,242 +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 org.codehaus.jam.JAnnotation;
|
||||
import org.codehaus.jam.JAnnotationValue;
|
||||
import org.codehaus.jam.JClass;
|
||||
import org.codehaus.jam.JProperty;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @version $Revision$
|
||||
*/
|
||||
public abstract class OpenWireCppMarshallingClassesScript extends OpenWireCppMarshallingHeadersScript {
|
||||
|
||||
protected String getFilePostFix() {
|
||||
return ".cpp";
|
||||
}
|
||||
|
||||
protected void generateUnmarshalBodyForProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
|
||||
out.print(" ");
|
||||
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 + "( DataStreamMarshaller.readByte(dataIn) );");
|
||||
}
|
||||
else if (type.equals("char")) {
|
||||
out.println("info." + setter + "( DataStreamMarshaller.readChar(dataIn) );");
|
||||
}
|
||||
else if (type.equals("short")) {
|
||||
out.println("info." + setter + "( DataStreamMarshaller.readShort(dataIn) );");
|
||||
}
|
||||
else if (type.equals("int")) {
|
||||
out.println("info." + setter + "( DataStreamMarshaller.readInt(dataIn) );");
|
||||
}
|
||||
else if (type.equals("long")) {
|
||||
out.println("info." + setter + "( UnmarshalLong(wireFormat, dataIn, bs) );");
|
||||
}
|
||||
else if (type.equals("String")) {
|
||||
out.println("info." + setter + "( readString(dataIn, bs) );");
|
||||
}
|
||||
else if (type.equals("byte[]") || type.equals("ByteSequence")) {
|
||||
if (size != null) {
|
||||
out.println("info." + setter + "( readBytes(dataIn, " + size.asInt() + ") );");
|
||||
}
|
||||
else {
|
||||
out.println("info." + setter + "( readBytes(dataIn, bs.readBoolean()) );");
|
||||
}
|
||||
}
|
||||
else if (isThrowable(property.getType())) {
|
||||
out.println("info." + setter + "( unmarshalBrokerError(wireFormat, dataIn, bs) );");
|
||||
}
|
||||
else if (isCachedProperty(property)) {
|
||||
out.println("info." + setter + "( (" + type + ") unmarshalCachedObject(wireFormat, dataIn, bs) );");
|
||||
}
|
||||
else {
|
||||
out.println("info." + setter + "( (" + type + ") unmarshalNestedObject(wireFormat, dataIn, bs) );");
|
||||
}
|
||||
}
|
||||
|
||||
protected void generateUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
|
||||
JClass propertyType = property.getType();
|
||||
String arrayType = propertyType.getArrayComponentType().getSimpleName();
|
||||
String setter = property.getGetter().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 + ") unmarshalNestedObject(wireFormat,dataIn, bs);");
|
||||
out.println(" }");
|
||||
out.println(" info." + setter + "( value );");
|
||||
out.println(" }");
|
||||
}
|
||||
else {
|
||||
out.println(" if (bs.readBoolean()) {");
|
||||
out.println(" short size = DataStreamMarshaller.readShort(dataIn);");
|
||||
out.println(" " + arrayType + "[] value = new " + arrayType + "[size];");
|
||||
out.println(" for( int i=0; i < size; i++ ) {");
|
||||
out.println(" value[i] = (" + arrayType + ") unmarshalNestedObject(wireFormat,dataIn, bs);");
|
||||
out.println(" }");
|
||||
out.println(" info." + setter + "( value );");
|
||||
out.println(" }");
|
||||
out.println(" else {");
|
||||
out.println(" info." + setter + "( null );");
|
||||
out.println(" }");
|
||||
}
|
||||
}
|
||||
|
||||
protected int generateMarshal1Body(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() + "()";
|
||||
|
||||
out.print(indent);
|
||||
if (type.equals("boolean")) {
|
||||
out.println("bs.writeBoolean(" + getter + ");");
|
||||
}
|
||||
else if (type.equals("byte")) {
|
||||
baseSize += 1;
|
||||
}
|
||||
else if (type.equals("char")) {
|
||||
baseSize += 1;
|
||||
}
|
||||
else if (type.equals("short")) {
|
||||
baseSize += 1;
|
||||
}
|
||||
else if (type.equals("int")) {
|
||||
baseSize += 1;
|
||||
}
|
||||
else if (type.equals("long")) {
|
||||
out.println("rc += marshal1Long(wireFormat, " + getter + ", bs);");
|
||||
}
|
||||
else if (type.equals("String")) {
|
||||
out.println("rc += writeString(" + getter + ", bs);");
|
||||
}
|
||||
else if (type.equals("byte[]") || type.equals("ByteSequence")) {
|
||||
if (size == null) {
|
||||
out.println("bs.writeBoolean(" + getter + "!=null);");
|
||||
out.println(" rc += " + getter + "==null ? 0 : " + getter + ".Length+4;");
|
||||
}
|
||||
else {
|
||||
baseSize += size.asInt();
|
||||
}
|
||||
}
|
||||
else if (propertyType.isArrayType()) {
|
||||
if (size != null) {
|
||||
out.println("rc += marshalObjectArrayConstSize(wireFormat, " + getter + ", bs, " + size.asInt() + ");");
|
||||
}
|
||||
else {
|
||||
out.println("rc += marshalObjectArray(wireFormat, " + getter + ", bs);");
|
||||
}
|
||||
}
|
||||
else if (isThrowable(propertyType)) {
|
||||
out.println("rc += marshalBrokerError(wireFormat, " + getter + ", bs);");
|
||||
}
|
||||
else {
|
||||
if (isCachedProperty(property)) {
|
||||
out.println("rc += marshal1CachedObject(wireFormat, " + getter + ", bs);");
|
||||
}
|
||||
else {
|
||||
out.println("rc += marshal1NestedObject(wireFormat, " + getter + ", bs);");
|
||||
}
|
||||
}
|
||||
}
|
||||
return baseSize;
|
||||
}
|
||||
|
||||
protected void generateMarshal2Body(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() + "()";
|
||||
|
||||
out.print(indent);
|
||||
if (type.equals("boolean")) {
|
||||
out.println("bs.readBoolean();");
|
||||
}
|
||||
else if (type.equals("byte")) {
|
||||
out.println("DataStreamMarshaller.writeByte(" + getter + ", dataOut);");
|
||||
}
|
||||
else if (type.equals("char")) {
|
||||
out.println("DataStreamMarshaller.writeChar(" + getter + ", dataOut);");
|
||||
}
|
||||
else if (type.equals("short")) {
|
||||
out.println("DataStreamMarshaller.writeShort(" + getter + ", dataOut);");
|
||||
}
|
||||
else if (type.equals("int")) {
|
||||
out.println("DataStreamMarshaller.writeInt(" + getter + ", dataOut);");
|
||||
}
|
||||
else if (type.equals("long")) {
|
||||
out.println("marshal2Long(wireFormat, " + getter + ", dataOut, bs);");
|
||||
}
|
||||
else if (type.equals("String")) {
|
||||
out.println("writeString(" + getter + ", dataOut, bs);");
|
||||
}
|
||||
else if (type.equals("byte[]") || type.equals("ByteSequence")) {
|
||||
if (size != null) {
|
||||
out.println("dataOut.write(" + getter + ", 0, " + size.asInt() + ");");
|
||||
}
|
||||
else {
|
||||
out.println("if(bs.readBoolean()) {");
|
||||
out.println(" DataStreamMarshaller.writeInt(" + getter + ".Length, dataOut);");
|
||||
out.println(" dataOut.write(" + getter + ");");
|
||||
out.println(" }");
|
||||
}
|
||||
}
|
||||
else if (propertyType.isArrayType()) {
|
||||
if (size != null) {
|
||||
out.println("marshalObjectArrayConstSize(wireFormat, " + getter + ", dataOut, bs, " + size.asInt() + ");");
|
||||
}
|
||||
else {
|
||||
out.println("marshalObjectArray(wireFormat, " + getter + ", dataOut, bs);");
|
||||
}
|
||||
}
|
||||
else if (isThrowable(propertyType)) {
|
||||
out.println("marshalBrokerError(wireFormat, " + getter + ", dataOut, bs);");
|
||||
}
|
||||
else {
|
||||
if (isCachedProperty(property)) {
|
||||
out.println("marshal2CachedObject(wireFormat, " + getter + ", dataOut, bs);");
|
||||
}
|
||||
else {
|
||||
out.println("marshal2NestedObject(wireFormat, " + getter + ", dataOut, bs);");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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$
|
||||
*/
|
||||
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";
|
||||
}
|
||||
}
|
|
@ -1,498 +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$
|
||||
*/
|
||||
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";
|
||||
}
|
||||
}
|
|
@ -1,134 +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 org.codehaus.gram.GramSupport;
|
||||
import org.codehaus.jam.JAnnotationValue;
|
||||
import org.codehaus.jam.JClass;
|
||||
import org.codehaus.jam.JField;
|
||||
import org.codehaus.jam.JMethod;
|
||||
import org.codehaus.jam.JProperty;
|
||||
import org.codehaus.jam.JamClassIterator;
|
||||
import org.codehaus.jam.JamService;
|
||||
|
||||
/**
|
||||
* @version $Revision$
|
||||
*/
|
||||
public abstract class OpenWireScript extends GramSupport {
|
||||
|
||||
private String openwireVersion;
|
||||
protected String filePostFix = ".java";
|
||||
|
||||
public boolean isValidProperty(JProperty it) {
|
||||
JMethod getter = it.getGetter();
|
||||
return getter != null && it.getSetter() != null && getter.isStatic() == false && getter.getAnnotation("openwire:property") != null;
|
||||
}
|
||||
|
||||
public boolean isCachedProperty(JProperty it) {
|
||||
JMethod getter = it.getGetter();
|
||||
if (!isValidProperty(it))
|
||||
return false;
|
||||
JAnnotationValue value = getter.getAnnotation("openwire:property").getValue("cache");
|
||||
return value != null && value.asBoolean();
|
||||
}
|
||||
|
||||
public boolean isAbstract(JClass j) {
|
||||
JField[] fields = j.getFields();
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
JField field = fields[i];
|
||||
if (field.isStatic() && field.isPublic() && field.isFinal() && field.getSimpleName().equals("DATA_STRUCTURE_TYPE")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isThrowable(JClass j) {
|
||||
if (j.getQualifiedName().equals(Throwable.class.getName())) {
|
||||
return true;
|
||||
}
|
||||
return j.getSuperclass() != null && isThrowable(j.getSuperclass());
|
||||
}
|
||||
|
||||
public boolean isMarshallAware(JClass j) {
|
||||
if (filePostFix.endsWith("java")) {
|
||||
JClass[] interfaces = j.getInterfaces();
|
||||
for (int i = 0; i < interfaces.length; i++) {
|
||||
if (interfaces[i].getQualifiedName().equals("org.apache.activemq.command.MarshallAware")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
String simpleName = j.getSimpleName();
|
||||
return simpleName.equals("ActiveMQMessage") || simpleName.equals("WireFormatInfo");
|
||||
}
|
||||
/*
|
||||
* else { // is it a message type String simpleName = j.getSimpleName();
|
||||
* JClass superclass = j.getSuperclass(); return
|
||||
* simpleName.equals("ActiveMQMessage") || (superclass != null &&
|
||||
* superclass.getSimpleName().equals("ActiveMQMessage")); }
|
||||
*/
|
||||
}
|
||||
|
||||
public JamService getJam() {
|
||||
return (JamService) getBinding().getVariable("jam");
|
||||
}
|
||||
|
||||
public JamClassIterator getClasses() {
|
||||
return getJam().getClasses();
|
||||
}
|
||||
|
||||
public String getOpenwireVersion() {
|
||||
if (openwireVersion == null) {
|
||||
openwireVersion = System.getProperty("openwire.version");
|
||||
}
|
||||
return openwireVersion;
|
||||
}
|
||||
|
||||
public void setOpenwireVersion(String openwireVersion) {
|
||||
this.openwireVersion = openwireVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the Java type to a C# type name
|
||||
*/
|
||||
public String toCSharpType(JClass type) {
|
||||
String name = type.getSimpleName();
|
||||
if (name.equals("String")) {
|
||||
return "string";
|
||||
}
|
||||
else if (name.equals("Throwable") || name.equals("Exception")) {
|
||||
return "BrokerError";
|
||||
}
|
||||
else if (name.equals("ByteSequence")) {
|
||||
return "byte[]";
|
||||
}
|
||||
else if (name.equals("boolean")) {
|
||||
return "bool";
|
||||
}
|
||||
else {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public String getOpenWireOpCode(JClass aClass) {
|
||||
return annotationValue(aClass, "openwire:marshaller", "code", "0");
|
||||
}
|
||||
}
|
|
@ -1,67 +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;
|
||||
|
||||
/**
|
||||
* A simple helper class to help auto-generate test data when code generating test cases
|
||||
*
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
public class TestDataGenerator {
|
||||
private int stringCounter;
|
||||
|
||||
private boolean boolCounter;
|
||||
private byte byteCounter;
|
||||
private char charCounter = 'a';
|
||||
private short shortCounter;
|
||||
private int intCounter;
|
||||
private long longCounter;
|
||||
|
||||
public String createByte() {
|
||||
return "(byte) " + (++byteCounter);
|
||||
}
|
||||
|
||||
public String createChar() {
|
||||
return "'" + (charCounter++) + "'";
|
||||
}
|
||||
|
||||
public String createShort() {
|
||||
return "(short) " + (++shortCounter);
|
||||
}
|
||||
|
||||
public int createInt() {
|
||||
return ++intCounter;
|
||||
}
|
||||
|
||||
public long createLong() {
|
||||
return ++longCounter;
|
||||
}
|
||||
|
||||
public String createString(String property) {
|
||||
return property + ":" + (++stringCounter);
|
||||
}
|
||||
|
||||
public boolean createBool() {
|
||||
boolCounter = !boolCounter;
|
||||
return boolCounter;
|
||||
}
|
||||
|
||||
public String createByteArray(String property) {
|
||||
return "\"" + createString(property) + "\".getBytes()";
|
||||
}
|
||||
}
|
|
@ -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 = System.getProperty("openwire.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,126 +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,153 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2005-2006 The Apache Software Foundation
|
||||
*
|
||||
* Licensed 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 << """/*
|
||||
* Copyright 2006 The Apache Software Foundation or its licensors, as
|
||||
* applicable.
|
||||
*
|
||||
* Licensed 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 = System.getProperty("openwire.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