You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2006/07/05 23:59:39 UTC
svn commit: r419354 [1/2] - in
/incubator/activemq/trunk/activemq-openwire-generator: ./ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/activemq/
src/main/java/org/apache/activemq/openwire/ src/main/...
Author: chirino
Date: Wed Jul 5 14:59:37 2006
New Revision: 419354
URL: http://svn.apache.org/viewvc?rev=419354&view=rev
Log:
Created a activemq-openwire-generator module which will hold the openwire code generation scripts. This will be used in conjunction
with the m2 gram plugin to generate openwire marshallers under maven 2.
Added:
incubator/activemq/trunk/activemq-openwire-generator/
incubator/activemq/trunk/activemq-openwire-generator/pom.xml
incubator/activemq/trunk/activemq-openwire-generator/src/
incubator/activemq/trunk/activemq-openwire-generator/src/main/
incubator/activemq/trunk/activemq-openwire-generator/src/main/java/
incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/
incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/
incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/
incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/
incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/
incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCSharpClassesScript.java
incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCSharpMarshallingScript.java
incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java
incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java
incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java
incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppMarshallingClassesScript.java
incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppMarshallingHeadersScript.java
incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireJavaMarshallingScript.java
incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireScript.java (with props)
incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/TestDataGenerator.java
incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/
incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCMarshalling.groovy (with props)
incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCSharpClasses.groovy (with props)
incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCSharpMarshalling.groovy (with props)
incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppClasses.groovy (with props)
incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppHeaders.groovy (with props)
incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppMarshallingClasses.groovy (with props)
incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateCppMarshallingHeaders.groovy (with props)
incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateJavaMarshalling.groovy (with props)
incubator/activemq/trunk/activemq-openwire-generator/src/main/resources/GenerateJavaTests.groovy (with props)
Added: incubator/activemq/trunk/activemq-openwire-generator/pom.xml
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/pom.xml?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/pom.xml (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/pom.xml Wed Jul 5 14:59:37 2006
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://maven.apache.org/POM/4.0.0">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>incubator-activemq</groupId>
+ <artifactId>activemq-parent</artifactId>
+ <version>4.1-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>activemq-openwire-generator</artifactId>
+ <name>Openwire Generator</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>groovy</groupId>
+ <artifactId>gram</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>groovy</groupId>
+ <artifactId>groovy-all</artifactId>
+ <version>1.0-jsr-03</version>
+ </dependency>
+ <dependency>
+ <groupId>groovy</groupId>
+ <artifactId>groovy-all</artifactId>
+ <version>1.0-jsr-03</version>
+ </dependency>
+ <dependency>
+ <groupId>annogen</groupId>
+ <artifactId>annogen</artifactId>
+ <version>0.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>1.6.2</version>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>default-tools.jar</id>
+ <activation>
+ <property>
+ <name>java.vendor</name>
+ <value>Sun Microsystems Inc.</value>
+ </property>
+ </activation>
+ <dependencies>
+ <dependency>
+ <groupId>com.sun</groupId>
+ <artifactId>tools</artifactId>
+ <version>1.4.2</version>
+ <scope>system</scope>
+ <systemPath>${java.home}/../lib/tools.jar</systemPath>
+ </dependency>
+ </dependencies>
+ </profile>
+ </profiles>
+
+</project>
Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCSharpClassesScript.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCSharpClassesScript.java?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCSharpClassesScript.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCSharpClassesScript.java Wed Jul 5 14:59:37 2006
@@ -0,0 +1,89 @@
+/**
+ *
+ * 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.
+ */
+package org.apache.activemq.openwire.tool;
+
+import java.io.File;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.Iterator;
+
+import org.codehaus.jam.JProperty;
+
+/**
+ *
+ * @version $Revision: 383749 $
+ */
+public abstract class OpenWireCSharpClassesScript extends OpenWireClassesScript {
+
+ public Object run() {
+ filePostFix = ".cs";
+ if (destDir == null) {
+ destDir = new File("../activemq-dotnet/src/main/csharp/ActiveMQ/Commands");
+ }
+
+ return super.run();
+ }
+
+ public String makeHashCodeBody() throws Exception {
+ if (simpleName.endsWith("Id")) {
+ StringWriter buffer = new StringWriter();
+ PrintWriter out = new PrintWriter(buffer);
+ out.println(" int answer = 0;");
+ Iterator iter = getProperties().iterator();
+ while (iter.hasNext()) {
+ JProperty property = (JProperty) iter.next();
+ out.println(" answer = (answer * 37) + HashCode(" + property.getSimpleName() + ");");
+ }
+ out.println(" return answer;");
+ return buffer.toString();
+ }
+ return null;
+ }
+
+ public String makeEqualsBody() throws Exception {
+ if (simpleName.endsWith("Id")) {
+ StringWriter buffer = new StringWriter();
+ PrintWriter out = new PrintWriter(buffer);
+
+ Iterator iter = getProperties().iterator();
+ while (iter.hasNext()) {
+ JProperty property = (JProperty) iter.next();
+ String name = property.getSimpleName();
+ out.println(" if (! Equals(this." + name + ", that." + name + ")) return false;");
+ }
+ out.println(" return true;");
+ return buffer.toString();
+ }
+ return null;
+ }
+
+ public String makeToStringBody() throws Exception {
+ StringWriter buffer = new StringWriter();
+ PrintWriter out = new PrintWriter(buffer);
+ out.println(" return GetType().Name + \"[\"");
+ Iterator iter = getProperties().iterator();
+ while (iter.hasNext()) {
+ JProperty property = (JProperty) iter.next();
+ String name = property.getSimpleName();
+ out.println(" + \" " + name + "=\" + " + name);
+ }
+ out.println(" + \" ]\";");
+ return buffer.toString();
+ }
+
+
+}
Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCSharpMarshallingScript.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCSharpMarshallingScript.java?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCSharpMarshallingScript.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCSharpMarshallingScript.java Wed Jul 5 14:59:37 2006
@@ -0,0 +1,393 @@
+/**
+ *
+ * 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.
+ */
+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: 384390 $
+ */
+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);");
+ }
+ }
+ }
+ }
+
+}
Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireClassesScript.java Wed Jul 5 14:59:37 2006
@@ -0,0 +1,233 @@
+/**
+ *
+ * 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.
+ */
+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: 386442 $
+ */
+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]);
+ }
+ }
+
+ public String getBaseClass() {
+ return baseClass;
+ }
+
+ public void setBaseClass(String baseClass) {
+ this.baseClass = baseClass;
+ }
+
+ public String getClassName() {
+ return className;
+ }
+
+ public void setClassName(String className) {
+ this.className = className;
+ }
+
+ public File getDestDir() {
+ return destDir;
+ }
+
+ public void setDestDir(File destDir) {
+ this.destDir = destDir;
+ }
+
+ public File getDestFile() {
+ return destFile;
+ }
+
+ public void setDestFile(File destFile) {
+ this.destFile = destFile;
+ }
+
+ public JClass getJclass() {
+ return jclass;
+ }
+
+ public void setJclass(JClass jclass) {
+ this.jclass = jclass;
+ }
+
+ public Set getManuallyMaintainedClasses() {
+ return manuallyMaintainedClasses;
+ }
+
+ public void setManuallyMaintainedClasses(Set manuallyMaintainedClasses) {
+ this.manuallyMaintainedClasses = manuallyMaintainedClasses;
+ }
+
+ public String getSimpleName() {
+ return simpleName;
+ }
+
+ public void setSimpleName(String simpleName) {
+ this.simpleName = simpleName;
+ }
+
+ public JClass getSuperclass() {
+ return superclass;
+ }
+
+ public void setSuperclass(JClass superclass) {
+ this.superclass = superclass;
+ }
+
+}
Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppClassesScript.java Wed Jul 5 14:59:37 2006
@@ -0,0 +1,209 @@
+/*
+ *
+ * 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.
+ */
+package org.apache.activemq.openwire.tool;
+
+import org.codehaus.jam.JClass;
+
+import java.io.File;
+
+/**
+ *
+ * @version $Revision: 409828 $
+ */
+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 "" ;
+ }
+}
Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppHeadersScript.java Wed Jul 5 14:59:37 2006
@@ -0,0 +1,30 @@
+/**
+ *
+ * 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.
+ */
+package org.apache.activemq.openwire.tool;
+
+
+/**
+ *
+ * @version $Revision: 379734 $
+ */
+public abstract class OpenWireCppHeadersScript extends OpenWireCppClassesScript {
+
+ protected String getFilePostFix() {
+ return ".hpp";
+ }
+
+}
Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppMarshallingClassesScript.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppMarshallingClassesScript.java?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppMarshallingClassesScript.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppMarshallingClassesScript.java Wed Jul 5 14:59:37 2006
@@ -0,0 +1,241 @@
+/**
+ *
+ * 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.
+ */
+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: 381410 $
+ */
+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);");
+ }
+ }
+ }
+ }
+}
Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppMarshallingHeadersScript.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppMarshallingHeadersScript.java?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppMarshallingHeadersScript.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireCppMarshallingHeadersScript.java Wed Jul 5 14:59:37 2006
@@ -0,0 +1,38 @@
+/**
+ *
+ * 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.
+ */
+package org.apache.activemq.openwire.tool;
+
+import java.io.File;
+
+/**
+ *
+ * @version $Revision: 381410 $
+ */
+public abstract class OpenWireCppMarshallingHeadersScript extends OpenWireJavaMarshallingScript {
+
+ public Object run() {
+ filePostFix = getFilePostFix();
+ if (destDir == null) {
+ destDir = new File("../openwire-cpp/src/marshal");
+ }
+ return super.run();
+ }
+
+ protected String getFilePostFix() {
+ return ".hpp";
+ }
+}
Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireJavaMarshallingScript.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireJavaMarshallingScript.java?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireJavaMarshallingScript.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireJavaMarshallingScript.java Wed Jul 5 14:59:37 2006
@@ -0,0 +1,529 @@
+/**
+ *
+ * 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.
+ */
+package org.apache.activemq.openwire.tool;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.codehaus.jam.JAnnotation;
+import org.codehaus.jam.JAnnotationValue;
+import org.codehaus.jam.JClass;
+import org.codehaus.jam.JProperty;
+
+/**
+ *
+ * @version $Revision: 384826 $
+ */
+public abstract class OpenWireJavaMarshallingScript extends OpenWireClassesScript {
+
+ protected List concreteClasses = new ArrayList();
+ protected File factoryFile;
+ protected String factoryFileName = "MarshallerFactory";
+ protected String indent = " ";
+
+ public Object run() {
+ if (destDir == null) {
+ destDir = new File("src/main/java/org/apache/activemq/openwire/v" + getOpenwireVersion());
+ }
+ Object answer = super.run();
+ processFactory();
+ return answer;
+ }
+
+ protected void processFactory() {
+ if (factoryFile == null) {
+ factoryFile = new File(destDir, factoryFileName + filePostFix);
+ }
+ PrintWriter out = null;
+ try {
+ out = new PrintWriter(new FileWriter(factoryFile));
+ generateFactory(out);
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ finally {
+ if (out != null) {
+ out.close();
+ }
+ }
+ }
+
+ protected abstract void generateFactory(PrintWriter out);
+
+ protected void processClass(JClass jclass) {
+ super.processClass(jclass);
+
+ if (!jclass.isAbstract()) {
+ concreteClasses.add(jclass);
+ }
+ }
+
+ protected String getClassName(JClass jclass) {
+ return super.getClassName(jclass) + "Marshaller";
+ }
+
+ protected String getBaseClassName(JClass jclass) {
+ String answer = "BaseDataStreamMarshaller";
+ JClass superclass = jclass.getSuperclass();
+ if (superclass != null) {
+ String superName = superclass.getSimpleName();
+ if (!superName.equals("Object") && !superName.equals("JNDIBaseStorable") && !superName.equals("DataStructureSupport")) {
+ answer = superName + "Marshaller";
+ }
+ }
+ return answer;
+ }
+
+ protected void initialiseManuallyMaintainedClasses() {
+ }
+
+ protected void generateTightUnmarshalBody(PrintWriter out) {
+ List properties = getProperties();
+ for (Iterator iter = properties.iterator(); iter.hasNext();) {
+ JProperty property = (JProperty) iter.next();
+ JAnnotation annotation = property.getAnnotation("openwire:property");
+ JAnnotationValue size = annotation.getValue("size");
+ JClass propertyType = property.getType();
+ String propertyTypeName = propertyType.getSimpleName();
+
+ if (propertyType.isArrayType() && !propertyTypeName.equals("byte[]")) {
+ generateTightUnmarshalBodyForArrayProperty(out, property, size);
+ }
+ else {
+ generateTightUnmarshalBodyForProperty(out, property, size);
+ }
+ }
+ }
+
+ protected void generateTightUnmarshalBodyForProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
+ String setter = property.getSetter().getSimpleName();
+ String type = property.getType().getSimpleName();
+
+ if (type.equals("boolean")) {
+ out.println(" info." + setter + "(bs.readBoolean());");
+ }
+ else if (type.equals("byte")) {
+ out.println(" info." + setter + "(dataIn.readByte());");
+ }
+ else if (type.equals("char")) {
+ out.println(" info." + setter + "(dataIn.readChar());");
+ }
+ else if (type.equals("short")) {
+ out.println(" info." + setter + "(dataIn.readShort());");
+ }
+ else if (type.equals("int")) {
+ out.println(" info." + setter + "(dataIn.readInt());");
+ }
+ else if (type.equals("long")) {
+ out.println(" info." + setter + "(tightUnmarshalLong(wireFormat, dataIn, bs));");
+ }
+ else if (type.equals("String")) {
+ out.println(" info." + setter + "(tightUnmarshalString(dataIn, bs));");
+ }
+ else if (type.equals("byte[]")) {
+ if (size != null) {
+ out.println(" info." + setter + "(tightUnmarshalConstByteArray(dataIn, bs, "+ size.asInt() +"));");
+ }
+ else {
+ out.println(" info." + setter + "(tightUnmarshalByteArray(dataIn, bs));");
+ }
+ }
+ else if (type.equals("ByteSequence")) {
+ out.println(" info." + setter + "(tightUnmarshalByteSequence(dataIn, bs));");
+ }
+ else if (isThrowable(property.getType())) {
+ out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") tightUnmarsalThrowable(wireFormat, dataIn, bs));");
+ }
+ else if (isCachedProperty(property)) {
+ out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") tightUnmarsalCachedObject(wireFormat, dataIn, bs));");
+ }
+ else {
+ out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") tightUnmarsalNestedObject(wireFormat, dataIn, bs));");
+ }
+ }
+
+ protected void generateTightUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
+ JClass propertyType = property.getType();
+ String arrayType = propertyType.getArrayComponentType().getQualifiedName();
+ String setter = property.getSetter().getSimpleName();
+ out.println();
+ if (size != null) {
+ out.println(" {");
+ out.println(" " + arrayType + " value[] = new " + arrayType + "[" + size.asInt() + "];");
+ out.println(" " + "for( int i=0; i < " + size.asInt() + "; i++ ) {");
+ out.println(" value[i] = (" + arrayType + ") tightUnmarsalNestedObject(wireFormat,dataIn, bs);");
+ out.println(" }");
+ out.println(" info." + setter + "(value);");
+ out.println(" }");
+ }
+ else {
+ out.println(" if (bs.readBoolean()) {");
+ out.println(" short size = dataIn.readShort();");
+ out.println(" " + arrayType + " value[] = new " + arrayType + "[size];");
+ out.println(" for( int i=0; i < size; i++ ) {");
+ out.println(" value[i] = (" + arrayType + ") tightUnmarsalNestedObject(wireFormat,dataIn, bs);");
+ out.println(" }");
+ out.println(" info." + setter + "(value);");
+ out.println(" }");
+ out.println(" else {");
+ out.println(" info." + setter + "(null);");
+ out.println(" }");
+ }
+ }
+
+ protected int generateTightMarshal1Body(PrintWriter out) {
+ List properties = getProperties();
+ int baseSize = 0;
+ for (Iterator iter = properties.iterator(); iter.hasNext();) {
+ JProperty property = (JProperty) iter.next();
+ JAnnotation annotation = property.getAnnotation("openwire:property");
+ JAnnotationValue size = annotation.getValue("size");
+ JClass propertyType = property.getType();
+ String type = propertyType.getSimpleName();
+ String getter = "info." + property.getGetter().getSimpleName() + "()";
+
+ if (type.equals("boolean")) {
+ out.println(" bs.writeBoolean(" + getter + ");");
+ }
+ else if (type.equals("byte")) {
+ baseSize += 1;
+ }
+ else if (type.equals("char")) {
+ baseSize += 2;
+ }
+ else if (type.equals("short")) {
+ baseSize += 2;
+ }
+ else if (type.equals("int")) {
+ baseSize += 4;
+ }
+ else if (type.equals("long")) {
+ out.println(" rc+=tightMarshalLong1(wireFormat, " + getter + ", bs);");
+ }
+ else if (type.equals("String")) {
+ out.println(" rc += tightMarshalString1(" + getter + ", bs);");
+ }
+ else if (type.equals("byte[]")) {
+ if (size == null) {
+ out.println(" rc += tightMarshalByteArray1(" + getter + ", bs);");
+ }
+ else {
+ out.println(" rc += tightMarshalConstByteArray1(" + getter + ", bs, "+size.asInt()+");");
+ }
+ }
+ else if (type.equals("ByteSequence")) {
+ out.println(" rc += tightMarshalByteSequence1(" + getter + ", bs);");
+ }
+ else if (propertyType.isArrayType()) {
+ if (size != null) {
+ out.println(" rc += tightMarshalObjectArrayConstSize1(wireFormat, " + getter + ", bs, " + size.asInt() + ");");
+ }
+ else {
+ out.println(" rc += tightMarshalObjectArray1(wireFormat, " + getter + ", bs);");
+ }
+ }
+ else if (isThrowable(propertyType)) {
+ out.println(" rc += tightMarshalThrowable1(wireFormat, " + getter + ", bs);");
+ }
+ else {
+ if (isCachedProperty(property)) {
+ out.println(" rc += tightMarshalCachedObject1(wireFormat, (DataStructure)" + getter + ", bs);");
+ }
+ else {
+ out.println(" rc += tightMarshalNestedObject1(wireFormat, (DataStructure)" + getter + ", bs);");
+ }
+ }
+ }
+ return baseSize;
+ }
+
+ protected void generateTightMarshal2Body(PrintWriter out) {
+ List properties = getProperties();
+ for (Iterator iter = properties.iterator(); iter.hasNext();) {
+ JProperty property = (JProperty) iter.next();
+ JAnnotation annotation = property.getAnnotation("openwire:property");
+ JAnnotationValue size = annotation.getValue("size");
+ JClass propertyType = property.getType();
+ String type = propertyType.getSimpleName();
+ String getter = "info." + property.getGetter().getSimpleName() + "()";
+
+ if (type.equals("boolean")) {
+ out.println(" bs.readBoolean();");
+ }
+ else if (type.equals("byte")) {
+ out.println(" dataOut.writeByte(" + getter + ");");
+ }
+ else if (type.equals("char")) {
+ out.println(" dataOut.writeChar(" + getter + ");");
+ }
+ else if (type.equals("short")) {
+ out.println(" dataOut.writeShort(" + getter + ");");
+ }
+ else if (type.equals("int")) {
+ out.println(" dataOut.writeInt(" + getter + ");");
+ }
+ else if (type.equals("long")) {
+ out.println(" tightMarshalLong2(wireFormat, " + getter + ", dataOut, bs);");
+ }
+ else if (type.equals("String")) {
+ out.println(" tightMarshalString2(" + getter + ", dataOut, bs);");
+ }
+ else if (type.equals("byte[]")) {
+ String mandatory = getMandatoryFlag(annotation);
+ if (size != null) {
+ out.println(" tightMarshalConstByteArray2(" + getter + ", dataOut, bs, " + size.asInt() + ");");
+ }
+ else {
+ out.println(" tightMarshalByteArray2(" + getter + ", dataOut, bs);");
+ }
+ }
+ else if (type.equals("ByteSequence")) {
+ out.println(" tightMarshalByteSequence2(" + getter + ", dataOut, bs);");
+ }
+ else if (propertyType.isArrayType()) {
+ if (size != null) {
+ out.println(" tightMarshalObjectArrayConstSize2(wireFormat, " + getter + ", dataOut, bs, " + size.asInt() + ");");
+ }
+ else {
+ out.println(" tightMarshalObjectArray2(wireFormat, " + getter + ", dataOut, bs);");
+ }
+ }
+ else if (isThrowable(propertyType)) {
+ out.println(" tightMarshalThrowable2(wireFormat, " + getter + ", dataOut, bs);");
+ }
+ else {
+ if (isCachedProperty(property)) {
+ out.println(" tightMarshalCachedObject2(wireFormat, (DataStructure)" + getter + ", dataOut, bs);");
+ }
+ else {
+ out.println(" tightMarshalNestedObject2(wireFormat, (DataStructure)" + getter + ", dataOut, bs);");
+ }
+ }
+ }
+ }
+
+
+ protected void generateLooseMarshalBody(PrintWriter out) {
+ List properties = getProperties();
+ for (Iterator iter = properties.iterator(); iter.hasNext();) {
+ JProperty property = (JProperty) iter.next();
+ JAnnotation annotation = property.getAnnotation("openwire:property");
+ JAnnotationValue size = annotation.getValue("size");
+ JClass propertyType = property.getType();
+ String type = propertyType.getSimpleName();
+ String getter = "info." + property.getGetter().getSimpleName() + "()";
+
+ if (type.equals("boolean")) {
+ out.println(" dataOut.writeBoolean("+ getter + ");");
+ }
+ else if (type.equals("byte")) {
+ out.println(" dataOut.writeByte(" + getter + ");");
+ }
+ else if (type.equals("char")) {
+ out.println(" dataOut.writeChar(" + getter + ");");
+ }
+ else if (type.equals("short")) {
+ out.println(" dataOut.writeShort(" + getter + ");");
+ }
+ else if (type.equals("int")) {
+ out.println(" dataOut.writeInt(" + getter + ");");
+ }
+ else if (type.equals("long")) {
+ out.println(" looseMarshalLong(wireFormat, " + getter + ", dataOut);");
+ }
+ else if (type.equals("String")) {
+ out.println(" looseMarshalString(" + getter + ", dataOut);");
+ }
+ else if (type.equals("byte[]")) {
+ if (size != null) {
+ out.println(" looseMarshalConstByteArray(wireFormat, " + getter + ", dataOut, " + size.asInt() + ");");
+ }
+ else {
+ out.println(" looseMarshalByteArray(wireFormat, " + getter + ", dataOut);");
+ }
+ }
+ else if (type.equals("ByteSequence")) {
+ out.println(" looseMarshalByteSequence(wireFormat, " + getter + ", dataOut);");
+ }
+ else if (propertyType.isArrayType()) {
+ if (size != null) {
+ out.println(" looseMarshalObjectArrayConstSize(wireFormat, " + getter + ", dataOut, " + size.asInt() + ");");
+ }
+ else {
+ out.println(" looseMarshalObjectArray(wireFormat, " + getter + ", dataOut);");
+ }
+ }
+ else if (isThrowable(propertyType)) {
+ out.println(" looseMarshalThrowable(wireFormat, " + getter + ", dataOut);");
+ }
+ else {
+ if (isCachedProperty(property)) {
+ out.println(" looseMarshalCachedObject(wireFormat, (DataStructure)" + getter + ", dataOut);");
+ }
+ else {
+ out.println(" looseMarshalNestedObject(wireFormat, (DataStructure)" + getter + ", dataOut);");
+ }
+ }
+ }
+ }
+
+
+ protected void generateLooseUnmarshalBody(PrintWriter out) {
+ List properties = getProperties();
+ for (Iterator iter = properties.iterator(); iter.hasNext();) {
+ JProperty property = (JProperty) iter.next();
+ JAnnotation annotation = property.getAnnotation("openwire:property");
+ JAnnotationValue size = annotation.getValue("size");
+ JClass propertyType = property.getType();
+ String propertyTypeName = propertyType.getSimpleName();
+
+ if (propertyType.isArrayType() && !propertyTypeName.equals("byte[]")) {
+ generateLooseUnmarshalBodyForArrayProperty(out, property, size);
+ }
+ else {
+ generateLooseUnmarshalBodyForProperty(out, property, size);
+ }
+ }
+ }
+
+ protected void generateLooseUnmarshalBodyForProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
+ String setter = property.getSetter().getSimpleName();
+ String type = property.getType().getSimpleName();
+
+ if (type.equals("boolean")) {
+ out.println(" info." + setter + "(dataIn.readBoolean());");
+ }
+ else if (type.equals("byte")) {
+ out.println(" info." + setter + "(dataIn.readByte());");
+ }
+ else if (type.equals("char")) {
+ out.println(" info." + setter + "(dataIn.readChar());");
+ }
+ else if (type.equals("short")) {
+ out.println(" info." + setter + "(dataIn.readShort());");
+ }
+ else if (type.equals("int")) {
+ out.println(" info." + setter + "(dataIn.readInt());");
+ }
+ else if (type.equals("long")) {
+ out.println(" info." + setter + "(looseUnmarshalLong(wireFormat, dataIn));");
+ }
+ else if (type.equals("String")) {
+ out.println(" info." + setter + "(looseUnmarshalString(dataIn));");
+ }
+ else if (type.equals("byte[]")) {
+ if (size != null) {
+ out.println(" info." + setter + "(looseUnmarshalConstByteArray(dataIn, " + size.asInt() + "));");
+ }
+ else {
+ out.println(" info." + setter + "(looseUnmarshalByteArray(dataIn));");
+ }
+ }
+ else if (type.equals("ByteSequence")) {
+ out.println(" info." + setter + "(looseUnmarshalByteSequence(dataIn));");
+ }
+ else if (isThrowable(property.getType())) {
+ out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") looseUnmarsalThrowable(wireFormat, dataIn));");
+ }
+ else if (isCachedProperty(property)) {
+ out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") looseUnmarsalCachedObject(wireFormat, dataIn));");
+ }
+ else {
+ out.println(" info." + setter + "((" + property.getType().getQualifiedName() + ") looseUnmarsalNestedObject(wireFormat, dataIn));");
+ }
+ }
+
+ protected void generateLooseUnmarshalBodyForArrayProperty(PrintWriter out, JProperty property, JAnnotationValue size) {
+ JClass propertyType = property.getType();
+ String arrayType = propertyType.getArrayComponentType().getQualifiedName();
+ String setter = property.getSetter().getSimpleName();
+ out.println();
+ if (size != null) {
+ out.println(" {");
+ out.println(" " + arrayType + " value[] = new " + arrayType + "[" + size.asInt() + "];");
+ out.println(" " + "for( int i=0; i < " + size.asInt() + "; i++ ) {");
+ out.println(" value[i] = (" + arrayType + ") looseUnmarsalNestedObject(wireFormat,dataIn);");
+ out.println(" }");
+ out.println(" info." + setter + "(value);");
+ out.println(" }");
+ }
+ else {
+ out.println(" if (dataIn.readBoolean()) {");
+ out.println(" short size = dataIn.readShort();");
+ out.println(" " + arrayType + " value[] = new " + arrayType + "[size];");
+ out.println(" for( int i=0; i < size; i++ ) {");
+ out.println(" value[i] = (" + arrayType + ") looseUnmarsalNestedObject(wireFormat,dataIn);");
+ out.println(" }");
+ out.println(" info." + setter + "(value);");
+ out.println(" }");
+ out.println(" else {");
+ out.println(" info." + setter + "(null);");
+ out.println(" }");
+ }
+ }
+
+ /**
+ * Returns whether or not the given annotation has a mandatory flag on it or not
+ */
+ protected String getMandatoryFlag(JAnnotation annotation) {
+ JAnnotationValue value = annotation.getValue("mandatory");
+ if (value != null) {
+ String text = value.asString();
+ if (text != null && text.equalsIgnoreCase("true")) {
+ return "true";
+ }
+ }
+ return "false";
+ }
+
+ public List getConcreteClasses() {
+ return concreteClasses;
+ }
+
+ public void setConcreteClasses(List concreteClasses) {
+ this.concreteClasses = concreteClasses;
+ }
+
+ public File getFactoryFile() {
+ return factoryFile;
+ }
+
+ public void setFactoryFile(File factoryFile) {
+ this.factoryFile = factoryFile;
+ }
+
+ public String getFactoryFileName() {
+ return factoryFileName;
+ }
+
+ public void setFactoryFileName(String factoryFileName) {
+ this.factoryFileName = factoryFileName;
+ }
+
+ public String getIndent() {
+ return indent;
+ }
+
+ public void setIndent(String indent) {
+ this.indent = indent;
+ }
+}
Added: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireScript.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireScript.java?rev=419354&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireScript.java (added)
+++ incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireScript.java Wed Jul 5 14:59:37 2006
@@ -0,0 +1,133 @@
+/**
+ *
+ * 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.
+ */
+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 = (String) getProperty("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");
+ }
+}
\ No newline at end of file
Propchange: incubator/activemq/trunk/activemq-openwire-generator/src/main/java/org/apache/activemq/openwire/tool/OpenWireScript.java
------------------------------------------------------------------------------
svn:executable = *