You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by gr...@apache.org on 2010/11/29 15:29:24 UTC
svn commit: r1040122 [1/4] - in /incubator/etch/trunk: ./ binding-go/
binding-go/compiler/ binding-go/compiler/src/ binding-go/compiler/src/main/
binding-go/compiler/src/main/java/ binding-go/compiler/src/main/java/org/
binding-go/compiler/src/main/jav...
Author: grandyho
Date: Mon Nov 29 14:29:21 2010
New Revision: 1040122
URL: http://svn.apache.org/viewvc?rev=1040122&view=rev
Log:
ETCH-120
alpha version of a Google Go Binding
Added:
incubator/etch/trunk/binding-go/
incubator/etch/trunk/binding-go/README.txt
incubator/etch/trunk/binding-go/build.xml
incubator/etch/trunk/binding-go/compiler/
incubator/etch/trunk/binding-go/compiler/build.xml
incubator/etch/trunk/binding-go/compiler/src/
incubator/etch/trunk/binding-go/compiler/src/main/
incubator/etch/trunk/binding-go/compiler/src/main/java/
incubator/etch/trunk/binding-go/compiler/src/main/java/org/
incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/
incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/
incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/
incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/go/
incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/go/compiler/
incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/go/compiler/Compiler.java
incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/go/compiler/CompilerVersion.java
incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/go/compiler/CompilerVersion.java.tmpl
incubator/etch/trunk/binding-go/compiler/src/main/resources/
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/base.vm
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/etch_wireshark.vm
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/helper.vm
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/impl.vm
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/intf.vm
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/javaKeywords.kwd
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/main.vm
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/makefile.vm
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/readme.vm
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/remote.vm
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/stub.vm
incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/vf.vm
incubator/etch/trunk/binding-go/runtime/
incubator/etch/trunk/binding-go/runtime/Makefile
incubator/etch/trunk/binding-go/runtime/src/
incubator/etch/trunk/binding-go/runtime/src/main/
incubator/etch/trunk/binding-go/runtime/src/main/go/
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/BinaryTaggedData.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/BinaryTaggedDataInput.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/BinaryTaggedDataOutput.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/ComboValidator.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/DefaultDeliveryService.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/DefaultValueFactory.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/DeliveryService.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Direction.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/EtchStub.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Field.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Flexbuffer.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/IdName.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/IdNameMap.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/ImportExportHelper.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Logger.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Mailbox.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Makefile
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Message.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Messagizer.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Packetizer.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/PlainMailBox.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/PlainMailBoxManager.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/SessionTransport.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/StructValue.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/TaggedDataInput.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/TaggedDataOutput.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/TcpConnection.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/TcpListener.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Type.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/TypeMap.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Util.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/Validator.go
incubator/etch/trunk/binding-go/runtime/src/main/go/etch/ValueFactory.go
incubator/etch/trunk/binding-go/runtime/src/test/
incubator/etch/trunk/binding-go/runtime/src/test/go/
incubator/etch/trunk/binding-go/runtime/src/test/go/Arrayvalue_test.go
incubator/etch/trunk/binding-go/runtime/src/test/go/BinaryTaggedDataInput_test.go
incubator/etch/trunk/binding-go/runtime/src/test/go/BinaryTaggedDataOutput_test.go
incubator/etch/trunk/binding-go/runtime/src/test/go/DefaultDeliveryService_test.go
incubator/etch/trunk/binding-go/runtime/src/test/go/DefaultValueFactory_test.go
incubator/etch/trunk/binding-go/runtime/src/test/go/EtchStub_test.go
incubator/etch/trunk/binding-go/runtime/src/test/go/Flexbuffer_test.go
incubator/etch/trunk/binding-go/runtime/src/test/go/Integration_test.go
incubator/etch/trunk/binding-go/runtime/src/test/go/Makefile
incubator/etch/trunk/binding-go/runtime/src/test/go/Packetizer_test.go
incubator/etch/trunk/binding-go/runtime/src/test/go/PlainMailBoxManager_test.go
incubator/etch/trunk/binding-go/runtime/src/test/go/PlainMailBox_test.go
incubator/etch/trunk/binding-go/runtime/src/test/go/StructValue_test.go
incubator/etch/trunk/binding-go/runtime/src/test/go/Type_test.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/
incubator/etch/trunk/binding-go/runtime/src/test/go/example/HelloWorld.etch
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/.gitignore
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/BaseHelloWorldClient.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/BaseHelloWorldServer.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/HelloWorld.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/HelloWorldClient.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/HelloWorldHelper.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/HelloWorldServer.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/ImplHelloWorldClient.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/ImplHelloWorldServer.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/MainHelloWorldClient.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/MainHelloWorldListener.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/Makefile
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/RemoteHelloWorld.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/RemoteHelloWorldClient.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/RemoteHelloWorldServer.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/StubHelloWorld.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/StubHelloWorldClient.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/StubHelloWorldServer.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/ValueFactoryHelloWorld.go
incubator/etch/trunk/binding-go/runtime/src/test/go/example/generated/helloworld_wireshark.ewh
incubator/etch/trunk/binding-go/runtime/src/test/go/testmain.go
Modified:
incubator/etch/trunk/build-support/etch.common.xml
incubator/etch/trunk/build.dependencies
incubator/etch/trunk/build.xml
Added: incubator/etch/trunk/binding-go/README.txt
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/README.txt?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/README.txt (added)
+++ incubator/etch/trunk/binding-go/README.txt Mon Nov 29 14:29:21 2010
@@ -0,0 +1,111 @@
+Google GO Binding for Apache Etch
+*********************************
+
+This is an alpha implementation of a Go binding (runtime + compiler) for Apache Etch.
+You can use most basic features of Etch:
+- non-blocking oneway calls
+- blocking twoway calls
+- server directed calls
+- client directed calls
+- user defined struct types
+- arrays
+
+-----------------------------------------------------------------------------------
+Building the Binding
+-----------------------------------------------------------------------------------
+
+There are two parts:
+- RUNTIME: libraries to execute Go Source using Etch
+- COMPILER: code generator for e.g. stubs and proxies from an Etch IDL
+
+COMPILER BUILD:
+***************
+
+If you build Etch using ant, you can enable the Go Binding COMPILER build by setting
+ include.experimental=true
+in build.dependencies in the top level directory.
+See BUILD.txt on the top-level of the Etch SVN trunk for more details on the ant-based build
+of Apache Etch.
+
+RUNTIME BUILD:
+**************
+
+To build the Go binding RUNTIME for Linux (X86) just do:
+
+> cd binding-go/runtime/
+> make
+
+This will build all required files to binding-go/runtime/src/main/go/etch/etch.8 and
+will execute the go binding testsuite.
+
+-----------------------------------------------------------------------------------
+Generating Go Source from Etch IDLs
+-----------------------------------------------------------------------------------
+
+If you have built the compiler, you can generate Go Code from an Etch IDL with:
+
+> etch -b go -d . -w INTF,MAIN,IMPL,BOTH SomeFile.etch
+
+This will generate all neccessary files and a Makefile for Linux (x86)
+Build your generated source code with
+
+> make ETCHLIBPATH=/some/path/binding-go/runtime/etch
+
+ETCHLIBPATH must contain the Go Etch runtime (etch.8)
+
+-----------------------------------------------------------------------------------
+Example
+-----------------------------------------------------------------------------------
+
+The Binding comes with an example IDL based on Etch's HelloWorld Example. It illustrates
+bidirectional calls (client -> server and server->client), oneway calls, twoway calls,
+user defined types, arrays of primitives and arrays of structs.
+
+Check the IDL with
+
+> cd binding-go/runtime/src/test/go/example/
+> less HelloWorld.etch
+
+For your convenience the generated sources are already contained in the "generated" folder
+and some method implementations have been made already (check Impl*.go and Main*.go)
+
+If you have already built the Etch Go RUNTIME (see above), then proceed by
+building the example source (on Linux x86) by executing:
+
+> cd binding-go/runtime/src/test/go/example/generated
+> make ETCHLIBPATH=../../../../main/go/etch
+
+Execute the example server:
+
+> cd binding-go/runtime/src/test/go/example/generated
+> ./HelloWorldServer
+
+Execute the example client:
+
+> cd binding-go/runtime/src/test/go/example/generated
+> ./HelloWorldClient
+
+-----------------------------------------------------------------------------------
+Unsupported Features
+-----------------------------------------------------------------------------------
+
+This binding is alpha and supports not all features of Etch, some things are
+known not to work or unstable.
+
+If you like the binding and need one of those features or want to get involved otherwise,
+feel free to post to etch-dev@incubator.apache.org, send patches or create Jira issues
+at https://issues.apache.org/jira/browse/ETCH
+
+We are very happy about your help!
+
+Currently unsupported features:
+- exceptions
+- mixins
+- constants & enums
+- multi-dimensional arrays
+- builtin types: set, list, map, datetime
+- object parameter type (experimental)
+- security (Auth)
+- filters
+
+
Added: incubator/etch/trunk/binding-go/build.xml
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/build.xml?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/build.xml (added)
+++ incubator/etch/trunk/binding-go/build.xml Mon Nov 29 14:29:21 2010
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="utf-8" ?>
+ <!--
+ * 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. *
+ -->
+<project name="etch-go-binding" basedir="." default="help">
+ <description>Etch-to-Go Binding</description>
+ <property name="Etch.basedir" location="${basedir}/.." />
+ <import file="${Etch.basedir}/build-support/etch.common.xml" />
+
+ <!-- standard, supported targets -->
+ <target name="Debug" depends="debug" />
+ <target name="Release" depends="release" />
+ <target name="Clean" depends="clean" />
+ <target name="debug" depends="init-debug,component-all,post-debug" />
+ <target name="release" depends="init-release,component-all,post-release" />
+ <target name="clean" depends="init-clean,component-all,post-clean" />
+ <target name="maven-install" depends="init-maven,release" />
+
+ <target name="init-maven" >
+ <property name="DO.maven.install" value="true" />
+ </target>
+
+ <target name="validate-dependencies" >
+ <mkdir dir="${Etch.logDirectory}" />
+ </target>
+
+ <target name="init-debug" depends="validate-dependencies" >
+ <property name="Etch.build.target" value="Debug" />
+ <property name="Etch.javac.debug" value="on" />
+ <property name="Etch.javac.optimize" value="off" />
+ </target>
+
+ <target name="post-debug" >
+ </target>
+
+ <target name="init-release" depends="validate-dependencies">
+ <!-- For now, keep debug-symbols and no-optimize, even for release builds -->
+ <property name="Etch.build.target" value="Release" />
+ <property name="Etch.javac.debug" value="on" />
+ <property name="Etch.javac.optimize" value="off" />
+ <!--
+ <property name="Etch.javac.debug" value="off" />
+ <property name="Etch.javac.optimize" value="on" />
+ -->
+ </target>
+
+ <target name="post-release" >
+ </target>
+
+ <target name="init-clean" depends="validate-dependencies">
+ <property name="Etch.build.target" value="Clean" />
+ </target>
+
+ <target name="post-clean" >
+ <echo message="Executing clean" />
+ </target>
+
+ <target name="component-all" >
+ <build_component dir="compiler" />
+ </target>
+
+</project>
Added: incubator/etch/trunk/binding-go/compiler/build.xml
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/compiler/build.xml?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/compiler/build.xml (added)
+++ incubator/etch/trunk/binding-go/compiler/build.xml Mon Nov 29 14:29:21 2010
@@ -0,0 +1,227 @@
+<?xml version="1.0" encoding="utf-8" ?>
+ <!--
+ * 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. *
+ -->
+<project name="etch-go-compiler" basedir="." default="help">
+ <description>Etch-to-Go compiler implementation</description>
+ <property name="Etch.basedir" location="${basedir}/../.." />
+ <import file="${Etch.basedir}/build-support/etch.includes.xml" />
+
+ <!-- Static properties of the sub-project -->
+ <property name="proj" location="${Etch.basedir}/binding-go/compiler" />
+ <property name="target" location="${proj}/target" />
+ <property name="src" location="${proj}/src" />
+ <property name="generatedSrc" location="${target}/generated-sources" />
+ <property name="classesDirectory" location="${target}/classes" />
+ <property name="resourcesDirectory" location="${target}/resources" />
+ <property name="testResultsDirectory" location="${target}/test-results" />
+
+ <!-- MACRO: init-target -->
+ <macrodef name="init-target" >
+ <sequential>
+ <delete dir="${classesDirectory}" failonerror="false" quiet="true" />
+ <delete dir="${resourcesDirectory}" failonerror="false" quiet="true" />
+ <mkdir dir="${classesDirectory}" />
+ <mkdir dir="${classesDirectory}/main" />
+ <mkdir dir="${classesDirectory}/test" />
+ <mkdir dir="${resourcesDirectory}" />
+ </sequential>
+ </macrodef>
+
+ <!-- MACRO: compile-sources -->
+ <macrodef name="compile-sources" >
+ <sequential>
+ <!-- compile compiler plugin -->
+ <javac debug="${Etch.javac.debug}"
+ target="1.5"
+ optimize="${Etch.javac.optimize}"
+ destdir="${classesDirectory}/main" >
+ <src path="${src}/main/java" />
+ <exclude name="**/.svn/**" />
+ <classpath refid="Etch.dependencies.jar.paths" />
+ <classpath>
+ <pathelement location="${Etch.HOME}/lib/${etch-compiler.jar}" />
+ </classpath>
+ </javac>
+
+ <!-- compiler plugin resources -->
+ <copy todir="${classesDirectory}/main" >
+ <fileset dir="${src}/main/resources">
+ <include name="**/*.kwd" />
+ <include name="**/*.vm" />
+ </fileset>
+ </copy>
+
+ <!--
+ <javac debug="${Etch.javac.debug}"
+ target="1.5"
+ optimize="${Etch.javac.optimize}"
+ destdir="${classesDirectory}/test" >
+ <src path="${src}/test/java" />
+ <exclude name="**/.svn/**" />
+ <classpath refid="Etch.dependencies.jar.paths" />
+ <classpath>
+ <pathelement location="${classesDirectory}/main" />
+ <pathelement location="${Etch.HOME}/lib/${etch-compiler.jar}" />
+ </classpath>
+ </javac>
+ -->
+
+ </sequential>
+ </macrodef>
+
+ <!-- MACRO: bundle-jars -->
+ <macrodef name="bundle-jars" >
+ <attribute name="dist" default="${Etch.dist}" />
+ <sequential>
+ <mkdir dir="@{dist}/lib" />
+
+ <!-- CREATE jars -->
+
+ <!-- Package up etch-go-compiler jar -->
+ <jar jarfile="@{dist}/lib/${etch-go-compiler.jar}" >
+ <manifest>
+ <attribute name="Copyright" value="${Etch.copyrightNotice}" />
+ <attribute name="Version" value="${Etch.version}" />
+ <attribute name="LongVersion" value="${Etch.longversion}" />
+ <attribute name="Build-Tag" value="${Etch.buildTag}" />
+ <attribute name="SVN-Revision" value="${Etch.runtime.revisionNumber}" />
+ </manifest>
+ <metainf dir="${Etch.basedir}" >
+ <include name="NOTICE.txt" />
+ <include name="LICENSE.txt" />
+ </metainf>
+ <fileset dir="${classesDirectory}/main">
+ <include name="org/apache/etch/bindings/**" />
+ <!-- <include name="resources/**" /> -->
+ </fileset>
+ </jar>
+
+ <!-- CREATE source archives -->
+
+ <!-- package up etch-go-compiler src -->
+ <zip destfile="@{dist}/lib/${etch-go-compiler-src.zip}" >
+ <fileset dir="${src}/main/java" >
+ <include name="org/apache/etch/bindings/**/*.java" />
+ </fileset>
+ <fileset dir="${src}/main/resources" >
+ <include name="**/*" />
+ </fileset>
+ </zip>
+
+ </sequential>
+ </macrodef>
+
+ <!-- INIT TARGET -->
+ <!-- Modify this target to define project specific properties that can only be set at runtime -->
+ <target name="do-init">
+ <delete dir="${target}" failonerror="false" quiet="true" />
+
+ <mkdir dir="${target}" />
+ <mkdir dir="${generatedSrc}" />
+ <mkdir dir="${classesDirectory}" />
+ <mkdir dir="${resourcesDirectory}" />
+ <mkdir dir="${testResultsDirectory}" />
+ </target>
+
+ <!-- CLEAN TARGET -->
+ <target name="do-clean">
+ <delete dir="${target}" />
+ </target>
+
+ <!-- BUILD TARGET -->
+
+ <target name="generate-sources" >
+ <!-- Generate version info -->
+ <update-tokens filename="${src}/main/java/org/apache/etch/bindings/go/compiler/CompilerVersion.java" />
+ </target>
+
+ <target name="compile-for-dist" >
+ <!-- Initialize target directories -->
+ <init-target />
+
+ <!-- Compile Source -->
+ <compile-sources />
+
+ <!-- Bundle Jars -->
+ <bundle-jars dist="${Etch.dist}" />
+ </target>
+
+ <target name="compile-for-clover" if="Clover.enabled" >
+
+ <echo message="Rebuilding with clover" />
+
+ <!-- initialize-clover -->
+ <initialize-clover suffix="etchgocompiler" >
+ <fileset dir="${src}/main/java">
+ <include name="**/*.java" />
+ </fileset>
+ <!--
+ <testsources dir="${src}/test/java">
+ <include name="**/*.java" />
+ </testsources>
+ -->
+ </initialize-clover>
+
+ <!-- Initialize target directories -->
+ <init-target />
+
+ <!-- Compile Source -->
+ <compile-sources />
+
+ <!-- Bundle Jars -->
+ <bundle-jars dist="${Etch.clover-dist}" />
+
+ </target>
+
+ <target name="do-build" depends="generate-sources,compile-for-dist,compile-for-clover" />
+
+ <!-- TEST TARGET -->
+ <target name="do-test">
+
+ <!-- Run Unit Tests -->
+ <!--
+ <junit printsummary="yes" haltonfailure="no" dir="${classesDirectory}"
+ errorProperty="build.tests.fail" failureProperty="build.tests.fail">
+ <classpath>
+ <pathelement location="${classesDirectory}/main" />
+ <pathelement location="${classesDirectory}/test" />
+ <pathelement location="${Etch.dependency.junit.jar}" />
+ <pathelement location="${Etch.HOME}/lib/${etch-compiler.jar}" />
+ <pathelement location="${Etch.dependency.clover.jar}"/>
+ </classpath>
+ <formatter type="xml"/>
+ <batchtest fork="true" todir="${testResultsDirectory}">
+ <fileset dir="${src}/test/java">
+ <include name="**/*.java" />
+ </fileset>
+ </batchtest>
+ </junit>
+ -->
+ </target>
+
+ <!-- POSTBUILD TARGET -->
+ <target name="do-postbuild">
+ </target>
+
+ <target name="do-publish" if="build.tests.fail">
+ <!-- Set flag file if any tests failed -->
+ <touch file="${Etch.runtime.tests.fail}"/>
+ </target>
+
+</project>
Added: incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/go/compiler/Compiler.java
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/go/compiler/Compiler.java?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/go/compiler/Compiler.java (added)
+++ incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/go/compiler/Compiler.java Mon Nov 29 14:29:21 2010
@@ -0,0 +1,1178 @@
+/* $Id: Compiler.java 999964 2010-09-22 14:16:17Z grandyho $
+ *
+ * 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.etch.bindings.go.compiler;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.etch.compiler.Backend;
+import org.apache.etch.compiler.CmdLineOptions;
+import org.apache.etch.compiler.EtchGrammarConstants;
+import org.apache.etch.compiler.LogHandler;
+import org.apache.etch.compiler.Output;
+import org.apache.etch.compiler.ParseException;
+import org.apache.etch.compiler.Token;
+import org.apache.etch.compiler.Version;
+import org.apache.etch.compiler.Backend.Gen;
+import org.apache.etch.compiler.ast.Builtin;
+import org.apache.etch.compiler.ast.Except;
+import org.apache.etch.compiler.ast.Item;
+import org.apache.etch.compiler.ast.Message;
+import org.apache.etch.compiler.ast.MessageDirection;
+import org.apache.etch.compiler.ast.Module;
+import org.apache.etch.compiler.ast.MsgDirHelper;
+import org.apache.etch.compiler.ast.Name;
+import org.apache.etch.compiler.ast.Named;
+import org.apache.etch.compiler.ast.ParamList;
+import org.apache.etch.compiler.ast.Parameter;
+import org.apache.etch.compiler.ast.ReservedWordChecker;
+import org.apache.etch.compiler.ast.Service;
+import org.apache.etch.compiler.ast.Struct;
+import org.apache.etch.compiler.ast.Thrown;
+import org.apache.etch.compiler.ast.TypeRef;
+import org.apache.etch.compiler.opt.ToString;
+import org.apache.etch.compiler.opt.ToString.FieldItem;
+import org.apache.etch.compiler.opt.ToString.FmtItem;
+import org.apache.etch.compiler.opt.ToString.StringItem;
+import org.apache.etch.util.Assertion;
+import org.apache.etch.util.Hash;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.RuntimeServices;
+import org.apache.velocity.runtime.log.LogChute;
+
+
+/**
+ * Compiler is a helper class not only for Backend, but also for the templates.
+ * They call methods here to perform "hard" tasks.
+ */
+public class Compiler extends Backend
+{
+
+ private final static String tmplPath1 = "org/apache/etch/bindings/go/compiler/";
+
+ private final static String tmplPath2 = "resources/org/apache/etch/bindings/go/compiler/";
+
+ private final static String fnSuffix = ".go";
+
+ private final static String VERSION = Version.VERSION + " / "
+ + CompilerVersion.VERSION;
+
+ /**
+ * Constructs the Compiler. This is a helper class not only for Backend, but
+ * also for the templates. They call methods here to perform "hard" tasks.
+ *
+ * @throws Exception
+ */
+ public Compiler() throws Exception
+ {
+ initVelocity();
+
+ String[] path = { tmplPath1, tmplPath2 };
+ vf_vm = getTemplate( path, "vf.vm" );
+ intf_vm = getTemplate( path, "intf.vm" );
+ remote_vm = getTemplate( path, "remote.vm" );
+ stub_vm = getTemplate( path, "stub.vm" );
+ helper_vm = getTemplate( path, "helper.vm" );
+ makefile_vm = getTemplate( path, "makefile.vm" );
+ main_vm = getTemplate( path, "main.vm" );
+ base_vm = getTemplate( path, "base.vm" );
+ impl_vm = getTemplate( path, "impl.vm" );
+
+ local_kwd = getPath( path, "javaKeywords.kwd" );
+ etch_wireshark_vm = getTemplate(path, "etch_wireshark.vm");
+ }
+
+ private final Template vf_vm;
+
+ private final Template intf_vm;
+
+ private final Template remote_vm;
+
+ private final Template stub_vm;
+
+ private final Template helper_vm;
+
+ private final Template makefile_vm;
+
+ private final Template main_vm;
+
+ private final Template base_vm;
+
+ private final Template impl_vm;
+
+ private final String local_kwd;
+
+ private LogHandler lh;
+
+ /**
+ * Initializes use of velocity engine and sets up
+ * resource loaders.
+ * @throws Exception
+ */
+ private void initVelocity()
+ throws Exception
+ {
+ Velocity.setProperty( Velocity.RUNTIME_LOG_LOGSYSTEM, new MyLogger() );
+
+ Velocity.setProperty( Velocity.RESOURCE_LOADER, "file, class" );
+
+ Velocity.setProperty( "file.resource.loader.description", "Velocity File Resource Loader" );
+ Velocity.setProperty( "file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader" );
+ Velocity.setProperty( "file.resource.loader.path", "." );
+
+ Velocity.setProperty( "class.resource.loader.description", "Velocity Classpath Resource Loader" );
+ Velocity.setProperty( "class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader" );
+
+ Velocity.init();
+ }
+
+ private static class MyLogger implements LogChute
+ {
+ private final LogHandler lh = null;
+
+ public void init( RuntimeServices rts ) throws Exception
+ {
+ // ignore.
+ }
+
+ public boolean isLevelEnabled( int level )
+ {
+ return level >= 2;
+ }
+
+ public void log( int level, String msg )
+ {
+ if (level < 2)
+ return;
+
+ if (lh != null)
+ lh.report( level == 2 ? LogHandler.LEVEL_WARNING : LogHandler.LEVEL_ERROR, null, msg );
+ else
+ System.out.printf( "Velocity msg (%d): %s\n", level, msg );
+ }
+
+ public void log( int level, String msg, Throwable e )
+ {
+ if (level < 2)
+ return;
+
+ if (lh != null)
+ lh.report( level == 2 ? LogHandler.LEVEL_WARNING : LogHandler.LEVEL_ERROR, null, msg );
+ else
+ System.out.printf( "Velocity msg (%d): %s: %s\n", level, msg, e );
+ }
+ }
+
+ /**
+ * @param path
+ * @param fn
+ * @return the velocity template
+ * @throws Exception
+ */
+ private Template getTemplate( String[] path, String fn )
+ throws Exception
+ {
+ ResourceNotFoundException rnfe = null;
+
+ for (String p: path)
+ {
+ if (p == null)
+ continue;
+
+// System.out.println( "trying to load template "+(p+fn) );
+ try
+ {
+ if (Velocity.resourceExists( p+fn ))
+ return Velocity.getTemplate( p+fn );
+ }
+ catch ( ResourceNotFoundException e )
+ {
+ rnfe = e;
+ }
+ catch ( Exception e )
+ {
+ System.out.println( "ignoring "+e);
+ }
+ }
+
+ if (rnfe != null)
+ throw rnfe;
+
+ throw new ResourceNotFoundException("could not find resource: "+fn);
+ }
+
+ @Override
+ public void generate( Module module, CmdLineOptions options )
+ throws Exception
+ {
+ // java always wants to not flatten packages:
+ options.noFlattenPackages = true;
+
+ lh = options.lh;
+
+ boolean ignoreGlobal = options.ignoreGlobalWordsList;
+ boolean ignoreLocal = options.ignoreLocalWordsList;
+ String userWords = options.userWordsList != null ? options.userWordsList.getPath() : null;
+ Set<String> what = options.what;
+
+ // Load the reserved words lists if any have been provided.
+ Map<String, String> words = new HashMap<String, String>();
+ if (!ignoreGlobal)
+ mapWords( global_kwd, words );
+ if (!ignoreLocal)
+ mapWords( local_kwd, words );
+ if (userWords != null)
+ mapWords( userWords, words );
+
+ // check for collisions with the reserved word list.
+ ReservedWordChecker checker = new ReservedWordChecker( words, false, lh );
+ module.treewalk( checker );
+ if (!checker.ok())
+ {
+ lh.report( LogHandler.LEVEL_ERROR, null, "Encountered errors during java generation." );
+ return;
+ }
+
+ // ok, we're ready to generate code. make sure the
+ // output directories exist.
+
+ Output dir = options.output;
+ Output templateDir = options.templateOutput;
+
+
+ // generate code for each service.
+
+ for (Service intf : module)
+ {
+ generate( intf, what, dir, templateDir );
+ }
+ }
+
+ private void generate( final Service intf, Set<String> what, Output dir,
+ Output templateDir ) throws Exception
+ {
+ what = populateWhat( what );
+
+ if (what.isEmpty())
+ {
+ // lh.logMessage( lh.LEVEL_ERROR, null, "User has selected NONE\n" );
+ return;
+ }
+
+ final MessageDirection msgDir = getMessageDirection( what );
+
+ if (what.contains( WHAT_INTF ))
+ {
+ // Generate the value factory file.
+
+ generateVf( intf, dir );
+
+ // Generate the interface, remote, and stub files.
+
+ generateIntfRemoteStub( intf, dir, msgDir, MessageDirection.BOTH, false );
+
+ generateIntfRemoteStub( intf, dir, msgDir, MessageDirection.SERVER, true );
+
+ generateIntfRemoteStub( intf, dir, msgDir, MessageDirection.CLIENT, true );
+
+ // Generate helper file.
+
+ generateHelper( intf, dir, msgDir );
+
+ // Generate base file.
+
+ generateBase( intf, dir, msgDir );
+
+ // Generate makefile file.
+
+ generateMakefile( intf, dir, msgDir );
+
+ generateKeywordList(intf, dir, msgDir, MessageDirection.BOTH, true);
+ }
+
+ // Generate main template file.
+
+ if (what.contains( WHAT_MAIN ))
+ generateMain( intf, templateDir, msgDir );
+
+ // Generate impl template file.
+
+ if (what.contains( WHAT_IMPL ))
+ generateImpl( intf, templateDir, msgDir );
+ }
+
+ private void generateMakefile( final Service intf, Output dir,
+ final MessageDirection msgDir ) throws Exception
+ {
+ doFile( dir, "Makefile", lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
+ {
+ generateMakefile( pw, intf, msgDir );
+ }
+ } );
+ }
+
+
+
+ private final Template etch_wireshark_vm;
+
+ private void generateKeywordList(final Service intf, Output dir,
+ final MessageDirection what, final MessageDirection mc,
+ final boolean hasBaseClass) throws Exception {
+ doFile(dir, getKeywordFilename(intf), lh,
+ new Gen() {
+ public void run(PrintWriter pw) throws Exception {
+ generateKeywords(pw, intf, mc, hasBaseClass);
+ }
+ });
+ }
+
+ void generateKeywords(PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass) throws Exception {
+ VelocityContext context = new VelocityContext();
+ context.put("now", new Date());
+ context.put("version", VERSION);
+ context.put("helper", this);
+ context.put("intf", intf);
+ context.put("mc", mc);
+ context.put("suffix", MsgDirHelper.getSuffix(mc).toLowerCase());
+ context.put("hasBaseClass", hasBaseClass);
+ etch_wireshark_vm.merge(context, pw);
+ }
+
+
+ public String getKeywordForWireshark(String fieldname) {
+ int hash = Hash.hash(fieldname);
+ return String.format("0x%08x", hash) + "," + fieldname;
+ }
+
+ public String getKeywordFilename(Service intf) {
+ return intf.name().name().toLowerCase() + "_wireshark.ewh";
+ }
+
+
+ private void generateVf( final Service intf, Output dir )
+ throws Exception
+ {
+ doFile( dir, getVfName( intf ) + fnSuffix, lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
+ {
+ generateVf( pw, intf );
+ }
+ } );
+ }
+
+ private void generateHelper( final Service intf, Output dir,
+ final MessageDirection msgDir ) throws Exception
+ {
+ doFile( dir, getHelperName( intf ) + fnSuffix, lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
+ {
+ generateHelper( pw, intf, msgDir );
+ }
+ } );
+ }
+
+ private void generateMain( final Service intf, Output dir,
+ MessageDirection msgDir ) throws Exception
+ {
+ if (msgDir == MessageDirection.BOTH
+ || msgDir == MessageDirection.CLIENT)
+ doFile( dir, getMainName( intf, MessageDirection.CLIENT ) + fnSuffix, lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
+ {
+ generateMain( pw, intf, MessageDirection.CLIENT, false );
+ }
+ } );
+
+ if (msgDir == MessageDirection.BOTH
+ || msgDir == MessageDirection.SERVER)
+ doFile( dir, getMainName( intf, MessageDirection.SERVER ) + fnSuffix, lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
+ {
+ generateMain( pw, intf, MessageDirection.SERVER, false );
+ }
+ } );
+ }
+
+ private void generateBase( final Service intf, Output dir,
+ MessageDirection msgDir ) throws Exception
+ {
+ if (msgDir == MessageDirection.BOTH || msgDir == MessageDirection.CLIENT)
+ doFile( dir, getBaseName( intf, MessageDirection.CLIENT ) + fnSuffix, lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
+ {
+ generateBase (pw, intf, MessageDirection.CLIENT, false );
+ }
+ } );
+
+ if (msgDir == MessageDirection.BOTH || msgDir == MessageDirection.SERVER)
+ doFile( dir, getBaseName( intf, MessageDirection.SERVER ) + fnSuffix, lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
+ {
+ generateBase (pw, intf, MessageDirection.SERVER, false );
+ }
+ } );
+ }
+
+ private void generateImpl( final Service intf, Output dir,
+ MessageDirection msgDir ) throws Exception
+ {
+ if (msgDir == MessageDirection.BOTH
+ || msgDir == MessageDirection.CLIENT)
+ doFile( dir, getImplName( intf, MessageDirection.CLIENT ) + fnSuffix, lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
+ {
+ generateImpl( pw, intf, MessageDirection.CLIENT, false );
+ }
+ } );
+
+ if (msgDir == MessageDirection.BOTH
+ || msgDir == MessageDirection.SERVER)
+ doFile( dir, getImplName( intf, MessageDirection.SERVER ) + fnSuffix, lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
+ {
+ generateImpl( pw, intf, MessageDirection.SERVER, false );
+ }
+ } );
+ }
+
+ private void generateIntfRemoteStub( final Service intf, Output dir,
+ final MessageDirection what, final MessageDirection mc,
+ final boolean hasBaseClass ) throws Exception
+ {
+ // Generate interface file
+
+ doFile( dir, getIntfName( intf, mc ) + fnSuffix, lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
+ {
+ generateIntf( pw, intf, mc, hasBaseClass );
+ }
+ } );
+
+ // Generate remote file
+
+ if (mc == MessageDirection.BOTH || what == MessageDirection.BOTH
+ || mc != what)
+ doFile( dir, getRemoteName( intf, mc ) + fnSuffix, lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
+ {
+ generateRemote( pw, intf, mc, hasBaseClass );
+ }
+ } );
+
+ // Generate stub file
+
+ if (mc == MessageDirection.BOTH || what == MessageDirection.BOTH
+ || mc == what)
+ doFile( dir, getStubName( intf, mc ) + fnSuffix, lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
+ {
+ generateStub( pw, intf, mc, hasBaseClass );
+ }
+ } );
+ }
+
+ /**
+ * Generate the value factory for the service.
+ *
+ * @param pw
+ * @param intf
+ * @throws Exception
+ */
+ void generateVf( PrintWriter pw, Service intf ) throws Exception
+ {
+ // params keeps track of the total set of parameters
+ // named (for enums, structs, exceptions, and messages).
+ Set<String> params = new HashSet<String>();
+
+ VelocityContext context = new VelocityContext();
+ context.put( "now", new Date() );
+ context.put( "version", VERSION );
+ context.put( "helper", this );
+ context.put( "intf", intf );
+ context.put( "params", params );
+ vf_vm.merge( context, pw );
+ }
+
+ /**
+ * Generate the interface for the service.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @param hasBaseClass
+ * @throws Exception
+ */
+ void generateIntf( PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass ) throws Exception
+ {
+ VelocityContext context = new VelocityContext();
+ context.put( "now", new Date() );
+ context.put( "version", VERSION );
+ context.put( "helper", this );
+ context.put( "intf", intf );
+ context.put( "mc", mc );
+ context.put( "suffix", MsgDirHelper.getSuffix( mc ) );
+ context.put( "hasBaseClass", hasBaseClass );
+ intf_vm.merge( context, pw );
+ }
+
+ /**
+ * Generate the call to message implementation of the interface. This class
+ * turns calls on its methods into messages which are sent to the remote
+ * stub. For two-way calls, it then waits for a response message, returning
+ * the result therein to the caller.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @param hasBaseClass
+ * @throws Exception
+ */
+ void generateRemote( PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass ) throws Exception
+ {
+ VelocityContext context = new VelocityContext();
+ context.put( "now", new Date() );
+ context.put( "version", VERSION );
+ context.put( "helper", this );
+ context.put( "intf", intf );
+ context.put( "mc", mc );
+ context.put( "suffix", MsgDirHelper.getSuffix( mc ) );
+ context.put( "hasBaseClass", hasBaseClass );
+ context.put( "methodList", new ArrayList<String>());
+ remote_vm.merge( context, pw );
+ }
+
+ /**
+ * Generate the message to call implementation. This class accepts a message
+ * and turns it back into a call on the user's implementation. For two-way
+ * messages, the return value from the user's implementation method is turned
+ * into the appropriate response message and sent.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @param hasBaseClass
+ * @throws Exception
+ */
+ void generateStub( PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass ) throws Exception
+ {
+ VelocityContext context = new VelocityContext();
+ context.put( "now", new Date() );
+ context.put( "version", VERSION );
+ context.put( "helper", this );
+ context.put( "intf", intf );
+ context.put( "mc", mc );
+ context.put( "suffix", MsgDirHelper.getSuffix( mc ) );
+ context.put( "hasBaseClass", hasBaseClass );
+ stub_vm.merge( context, pw );
+ }
+
+ /**
+ * Generate the transport plumbing helper.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @throws Exception
+ */
+ void generateHelper( PrintWriter pw, Service intf, MessageDirection mc )
+ throws Exception
+ {
+ VelocityContext context = new VelocityContext();
+ context.put( "now", new Date() );
+ context.put( "version", VERSION );
+ context.put( "helper", this );
+ context.put( "intf", intf );
+ context.put( "mc", mc );
+
+ helper_vm.merge( context, pw );
+ }
+
+ /**
+ * Generate the Makefile.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @throws Exception
+ */
+ void generateMakefile( PrintWriter pw, Service intf, MessageDirection mc ) throws Exception
+ {
+ VelocityContext context = new VelocityContext();
+ context.put( "now", new Date() );
+ context.put( "version", VERSION );
+ context.put( "helper", this );
+ context.put( "intf", intf );
+ context.put( "mc", mc );
+
+ makefile_vm.merge( context, pw );
+ }
+
+ /**
+ * Generate the template main program.
+ *
+ * @param pw
+ * @param intf
+ * @param mc
+ * @param hasBaseClass
+ * @throws Exception
+ */
+ void generateMain( PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass ) throws Exception
+ {
+ VelocityContext context = new VelocityContext();
+ context.put( "now", new Date() );
+ context.put( "version", VERSION );
+ context.put( "helper", this );
+ context.put( "intf", intf );
+ context.put( "mc", mc );
+ context.put( "suffix", MsgDirHelper.getSuffix( mc ) );
+ context.put( "hasBaseClass", hasBaseClass );
+ main_vm.merge( context, pw );
+ }
+
+ /**
+ * Generates the base implementation of the interfaces, with each
+ * method throwing an exception to the tune that it isn't implemented.
+ * User's impl will extend this base implementation.
+ * @param pw
+ * @param intf
+ * @param mc
+ * @param hasBaseClass
+ * @throws Exception
+ */
+ void generateBase( PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass ) throws Exception
+ {
+ VelocityContext context = new VelocityContext();
+ context.put( "now", new Date() );
+ context.put( "version", VERSION );
+ context.put( "helper", this );
+ context.put( "intf", intf );
+ context.put( "mc", mc );
+ context.put( "suffix", MsgDirHelper.getSuffix( mc ) );
+ context.put( "hasBaseClass", hasBaseClass );
+ context.put( "methodList", new ArrayList<String>());
+ base_vm.merge( context, pw );
+ }
+
+ /**
+ * Generate the template user implemention class which extends the base
+ * implementation generated above. This class will only have the appropriate
+ * constructor and reference to the appropriate remote, and a comment inviting
+ * the user to override methods.
+ * @param pw
+ * @param intf
+ * @param mc
+ * @param hasBaseClass
+ * @throws Exception
+ */
+ void generateImpl( PrintWriter pw, Service intf, MessageDirection mc,
+ boolean hasBaseClass ) throws Exception
+ {
+ VelocityContext context = new VelocityContext();
+ context.put( "now", new Date() );
+ context.put( "version", VERSION );
+ context.put( "helper", this );
+ context.put( "intf", intf );
+ context.put( "mc", mc );
+ context.put( "suffix", MsgDirHelper.getSuffix( mc ) );
+ context.put( "hasBaseClass", hasBaseClass );
+ impl_vm.merge( context, pw );
+ }
+
+ private String getVfName( Service intf )
+ {
+ return "ValueFactory" + getIntfName( intf, MessageDirection.BOTH );
+ }
+
+ private String getIntfName( Service intf, MessageDirection mc )
+ {
+ String suffix = MsgDirHelper.getSuffix( mc );
+ return intf.name() + suffix;
+ }
+
+ private String getMainName( Service intf, MessageDirection mc )
+ {
+ if (mc == MessageDirection.SERVER)
+ return "Main" + intf.name() + "Listener";
+ return "Main" + getIntfName( intf, mc );
+ }
+
+ private String getImplName( Service intf, MessageDirection mc )
+ {
+ return "Impl" + getIntfName( intf, mc );
+ }
+
+ private String getRemoteName( Service intf, MessageDirection mc )
+ {
+ return "Remote" + getIntfName( intf, mc );
+ }
+
+ private String getStubName( Service intf, MessageDirection mc )
+ {
+ return "Stub" + getIntfName( intf, mc );
+ }
+
+ private String getHelperName( Service intf )
+ {
+ return intf.name() + "Helper";
+ }
+
+ private String getBaseName( Service intf, MessageDirection mc )
+ {
+ return "Base" + getIntfName( intf, mc );
+ }
+
+ @Override
+ public String asyncReceiverPoolName( Message msg )
+ {
+ return msg.getAsyncReceiver().toString().toLowerCase();
+ }
+
+ @Override
+ public String getTypeValue( TypeRef type, Token value )
+ {
+ // System.out.println( "getTypeValue called with: "+type+": "+value );
+ Token t = type.type();
+ switch (t.kind)
+ {
+ case EtchGrammarConstants.LONG:
+ return "int64(" + value.image + ")";
+ case EtchGrammarConstants.FLOAT:
+ return "float(" + value.image + ")";
+ case EtchGrammarConstants.DOUBLE:
+ return "float64(" + value.image + ")";
+ case EtchGrammarConstants.STRING:
+ return protectString( value.image );
+ default:
+ return value.image;
+ }
+ }
+
+ private String protectString( String s )
+ {
+ // System.out.println( "protectString called with: "+s );
+
+ StringBuffer sb = new StringBuffer();
+ sb.append( "\"" );
+ for (char c : s.toCharArray())
+ {
+ if (c == '\t')
+ {
+ sb.append( "\\t" );
+ continue;
+ }
+ if (c == '\r')
+ {
+ sb.append( "\\r" );
+ continue;
+ }
+ if (c == '\n')
+ {
+ sb.append( "\\n" );
+ continue;
+ }
+ if (c == '\"')
+ {
+ sb.append( "\\\"" );
+ continue;
+ }
+ if (c == '\\')
+ {
+ sb.append( "\\\\" );
+ continue;
+ }
+ if (c >= 32 && c < 127)
+ {
+ sb.append( c );
+ continue;
+ }
+ sb.append( String.format( "\\u%04x", (int) c ) );
+ }
+ sb.append( "\"" );
+ return sb.toString();
+ }
+
+ /**
+ * @param type
+ * @return type name appropriate for use as a structure element or exception
+ * parameter or function parameter or result.
+ */
+ @Override
+ public String getTypeName( TypeRef type )
+ {
+ if(type.dim() > 1)
+ throw new IllegalArgumentException("Sorry, Multidimensional Arrays are not supported in the Go binding");
+
+ if (type.dim() > 0)
+ return dim2spec( type.dim() ) + getNativeTypeName( type ) ;
+ return getRefTypeName( type );
+ }
+
+ /**
+ * @param type the etch type
+ * @return the fundamental native type for java. so etch int -> java int,
+ * while etch string -> java String.
+ */
+ @Override
+ public String getNativeTypeName( TypeRef type )
+ {
+ Token t = type.type();
+ switch (t.kind)
+ {
+ case EtchGrammarConstants.VOID:
+ return "";
+ case EtchGrammarConstants.BOOLEAN:
+ return "bool";
+ case EtchGrammarConstants.BYTE:
+ return "int8";
+ case EtchGrammarConstants.SHORT:
+ return "int16";
+ case EtchGrammarConstants.INT:
+ return "int32";
+ case EtchGrammarConstants.LONG:
+ return "int64";
+ case EtchGrammarConstants.FLOAT:
+ return "float";
+ case EtchGrammarConstants.DOUBLE:
+ return "float64";
+ case EtchGrammarConstants.STRING:
+ return "string";
+ case EtchGrammarConstants.OBJECT:
+ return "*interface{}";
+ default:
+ {
+ // we have to use a fully qualified name here.
+ // find the actual type...
+ Named<?> n = type.intf().get( t.image );
+ if (n == null)
+ throw new IllegalArgumentException( String.format(
+ "undefined or ambiguous name at line %d: %s",
+ t.beginLine, t.image ) );
+ return "*" + capitalize(n.name().toString());
+ }
+ }
+ }
+
+ /**
+ * @param type the etch type
+ * @return the fundamental native reference type for java. so etch int ->
+ * java Integer, while etch string -> java String.
+ */
+ private String getRefTypeName( TypeRef type )
+ {
+ Token t = type.type();
+ switch (t.kind)
+ {
+ case EtchGrammarConstants.VOID:
+ return "";
+ case EtchGrammarConstants.BOOLEAN:
+ return "bool";
+ case EtchGrammarConstants.BYTE:
+ return "int8";
+ case EtchGrammarConstants.SHORT:
+ return "int16";
+ case EtchGrammarConstants.INT:
+ return "int32";
+ case EtchGrammarConstants.LONG:
+ return "int64";
+ case EtchGrammarConstants.FLOAT:
+ return "float";
+ case EtchGrammarConstants.DOUBLE:
+ return "float64";
+ case EtchGrammarConstants.STRING:
+ return "string";
+ case EtchGrammarConstants.OBJECT:
+ return "*interface{}";
+ default:
+ {
+ // we have to use a fully qualified name here.
+ // find the actual type...
+ Named<?> n = type.intf().get( t.image );
+ if (n == null)
+ throw new IllegalArgumentException( String.format(
+ "undefined or ambiguous name at line %d: %s",
+ t.beginLine, t.image ) );
+ return "*" + capitalize(n.name( ).toString());
+ }
+ }
+ }
+
+ private String dim2spec( int i )
+ {
+
+ String s = "";
+ while (i-- > 0)
+ s += "[]";
+ return s;
+ }
+
+ @Override
+ public String formatString( ParamList<Service> n, boolean isExcept )
+ throws ParseException, IOException
+ {
+ ToString ts = (ToString) n.getOpt( "ToString" );
+ List<FmtItem> list;
+ if (ts != null)
+ {
+ list = ts.getFormat();
+ n.checkFormatList( ts.lineno(), list );
+ }
+ else if (isExcept)
+ list = n.mkFormatList( true, ((Except)n).hasExtends() );
+ else
+ list = n.mkFormatList( false, ((Struct)n).hasExtends() );
+
+ if (list.size() == 1)
+ {
+ return list.get( 0 ).value();
+ }
+
+ StringBuffer sb = new StringBuffer();
+ sb.append( "String.format( " );
+ sb.append( "\"" );
+ for (FmtItem i : list)
+ {
+ if (i instanceof FieldItem)
+ {
+ sb.append( "%s" );
+ }
+ else
+ {
+ escape( sb, ((StringItem) i).value() );
+ }
+ }
+ sb.append( "\"" );
+ for (FmtItem i : list)
+ {
+ if (i instanceof FieldItem)
+ {
+ sb.append( ", " );
+ sb.append( ((FieldItem) i).value() );
+ }
+ }
+ sb.append( " )" );
+ return sb.toString();
+ }
+
+ private void escape( StringBuffer sb, String s ) throws IOException
+ {
+ StringReader rdr = new StringReader( s );
+ int c;
+ while ((c = rdr.read()) >= 0)
+ {
+ if (c == '"')
+ sb.append( "\\\"" );
+ else if (c == '\\')
+ sb.append( "\\\\" );
+ else if (c == '\t')
+ sb.append( "\\t" );
+ else if (c == '\r')
+ sb.append( "\\r" );
+ else if (c == '\n')
+ sb.append( "\\n" );
+ else
+ sb.append( (char) c );
+ }
+ }
+
+ @Override
+ public String mfvname( String vname )
+ {
+ return "_mf_" + vname;
+ }
+
+ @Override
+ public String mtvname( String vname )
+ {
+ return "_mt_" + vname;
+ }
+
+ @Override
+ public String getLang()
+ {
+ return "go";
+ }
+
+ @Override
+ public String enum_efqname( String fqname, String moduleName,
+ String serviceName, String enumName )
+ {
+ return fqname;
+ }
+
+ @Override
+ public String except_efqname( String fqname, String moduleName,
+ String serviceName, String exceptName )
+ {
+
+ return fqname;
+ }
+
+ @Override
+ public String struct_efqname( String fqname, String moduleName,
+ String serviceName, String enumName )
+ {
+
+ return fqname;
+ }
+
+ @Override
+ public String qualifyParameterName( Token name )
+ {
+ return name.image;
+ }
+
+ @Override
+ public String qualifyConstantName( Service intf, Token name )
+ {
+ return intf.fqname() + '.' + name.image;
+ }
+
+ @Override
+ public String qualifyEnumName( Service intf, Token name )
+ {
+ return intf.fqname() + '.' + name.image;
+ }
+
+ @Override
+ public String getValidator( Named<?> named )
+ {
+ if (named instanceof Parameter)
+ {
+ Parameter param = (Parameter) named;
+ TypeRef type = param.type();
+
+ if (type.isBuiltin())
+ return String.format( "Validator_%s.get( %d )",
+ type.type(), type.dim() );
+
+ Named<?> n = type.getNamed( type.intf() );
+
+ if (n.isBuiltin())
+ {
+ Builtin b = (Builtin) n;
+ String cn = b.className();
+
+ int i = cn.indexOf( '<' );
+ if (i >= 0)
+ cn = cn.substring( 0, i );
+
+ return String.format( "Validator_custom.get( %s.class, %d, %s )",
+ cn, type.dim(), b.allowSubclass() );
+ }
+
+ // Allow subclassing for etch defined structs and externs.
+
+ if (n.isStruct() || n.isExcept())
+ return String.format( "Validator_custom.get( %s.class, %d, true )",
+ n.efqname( this ), type.dim() );
+
+ // Don't allow subclassing for externs or etch defined enums.
+
+ if (!(n.isExtern() || n.isEnumx()))
+ Assertion.check( n.isExtern() || n.isEnumx(),
+ "n.isExtern() || n.isEnumx(): "+n );
+
+ return String.format( "Validator_custom.get( %s.class, %d, false )",
+ n.efqname( this ), type.dim() );
+ }
+
+ if (named instanceof Thrown)
+ {
+ Thrown thrown = (Thrown) named;
+ Except e = (Except) thrown.getNamed();
+ return String.format( "Validator_custom.get( %s.class, 0, true )", e.efqname( this ) );
+ }
+
+ if (named instanceof Item)
+ return "Validator_boolean.get( 0 )";
+
+ return "null";
+ }
+
+ /**
+ * @param name
+ * @return the appropriate name for a getter method.
+ */
+ public String getGetterName( Name name )
+ {
+ String s = name.name;
+ return "get"+s.substring( 0, 1 ).toUpperCase()+s.substring( 1 );
+ }
+
+ /**
+ * @param name
+ * @return the appropriate name for a setter method.
+ */
+ public String getSetterName( Name name )
+ {
+ String s = name.name;
+ return "set"+s.substring( 0, 1 ).toUpperCase()+s.substring( 1 );
+ }
+
+ @Override
+ public void addDefaults( Service service ) throws ParseException
+ {
+ addBuiltin( service, newName( "List" ), "java.util.List<?>", true );
+ addBuiltin( service, newName( "Map" ), "java.util.Map<?, ?>", true );
+ addBuiltin( service, newName( "Set" ), "java.util.Set<?>", true );
+ addBuiltin( service, newName( "Datetime" ), "java.util.Date", false );
+ }
+
+ public String getPackageName(Service service) {
+ return service.parent().name().toString().replaceAll("\\.","_");
+ }
+ public String capitalize(String what) {
+ if(what == null || what.length() == 0)
+ return "";
+ String r = what.substring(0,1);
+ return r.toUpperCase() + what.substring(1);
+ }
+}
Added: incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/go/compiler/CompilerVersion.java
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/go/compiler/CompilerVersion.java?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/go/compiler/CompilerVersion.java (added)
+++ incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/go/compiler/CompilerVersion.java Mon Nov 29 14:29:21 2010
@@ -0,0 +1,33 @@
+/* $Id: CompilerVersion.java.tmpl 767991 2009-04-23 17:36:27Z sccomer $
+ *
+ * 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.etch.bindings.go.compiler;
+
+/**
+ * The version info of this Etch backend (compiler).
+ */
+public interface CompilerVersion
+{
+ // This file is edited by the production build system to replace the value
+ // of VERSION below with whatever it wants the version string to actually be.
+
+ /** The version of this Etch backend (compiler) */
+ public String VERSION = "go 1.2.0-incubating (LOCAL-0)";
+}
Added: incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/go/compiler/CompilerVersion.java.tmpl
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/go/compiler/CompilerVersion.java.tmpl?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/go/compiler/CompilerVersion.java.tmpl (added)
+++ incubator/etch/trunk/binding-go/compiler/src/main/java/org/apache/etch/bindings/go/compiler/CompilerVersion.java.tmpl Mon Nov 29 14:29:21 2010
@@ -0,0 +1,33 @@
+/* $Id: CompilerVersion.java.tmpl 767991 2009-04-23 17:36:27Z sccomer $
+ *
+ * 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.etch.bindings.go.compiler;
+
+/**
+ * The version info of this Etch backend (compiler).
+ */
+public interface CompilerVersion
+{
+ // This file is edited by the production build system to replace the value
+ // of VERSION below with whatever it wants the version string to actually be.
+
+ /** The version of this Etch backend (compiler) */
+ public String VERSION = "go @EtchLongVersion@ (@EtchBuildTag@)";
+}
Added: incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/base.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/base.vm?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/base.vm (added)
+++ incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/base.vm Mon Nov 29 14:29:21 2010
@@ -0,0 +1,74 @@
+## 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.
+// This file automatically generated by:
+// $version
+// $now
+// This file is automatically created and should not be edited!
+// Re-implement these methods by overriding them in Impl$intf.name()$suffix.
+#set($i = $intf.name())
+#set($intfname = "$i$suffix")
+#set($clname = "Base$intfname")
+#if ($helper.isServer($mc))
+#set($peer = "client")
+#else
+#set($peer = "server")
+#end
+
+package $helper.getPackageName($intf)
+
+type ${intfname}_base struct {
+#if ($helper.isServer($mc))
+ TheClient *Remote${i}Client
+#end
+}
+
+func (base *${intfname}_base) SessionQuery(obj interface{}) interface{} {
+ return nil
+}
+
+func (base *${intfname}_base) SessionControl(ctrl interface{}, value interface{}) interface{} {
+ return nil
+}
+
+func (base *${intfname}_base) SessionNotify(obj interface{}) {
+
+}
+
+#foreach ($mthd in $intf.iterator())
+#if ($mthd.isMsgDir($mc) || $mthd.isMsgDirBoth())
+#if (!$mthd.isHidden())
+#if(!$methodList.contains($mthd.name().name()))
+#set ( $addMethodListStatus = $methodList.add($mthd.name().name()) )
+
+#set ( $methodName="func (base *${intfname}_base) $mthd.name() (" )
+#set( $sep = "" )
+#foreach( $param in $mthd.iterator() )
+#set ( $methodName = $methodName + "$param.name() $sep$helper.getTypeName( $param.type() )")
+#set( $sep = ", " )
+#end
+#set ( $methodName = $methodName + ") $helper.getTypeName( $mthd.type() )" )
+$methodName {
+#if ($mthd.type() != "")
+ panic("not implemented")
+#end
+}
+#end
+#end
+#end
+#end
+
+
Added: incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/etch_wireshark.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/etch_wireshark.vm?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/etch_wireshark.vm (added)
+++ incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/etch_wireshark.vm Mon Nov 29 14:29:21 2010
@@ -0,0 +1,64 @@
+##
+## 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.
+##
+
+#foreach($n in $intf.iterator())
+#if($n.isMessage())
+#if(!$n.isHidden())
+#set ( $str="$intf.fqname().$n.name()" )
+$helper.getKeywordForWireshark($str)
+#if(! $n.isOneway())
+#set ( $str="$intf.fqname()._result_$n.name()" )
+$helper.getKeywordForWireshark($str)
+#end
+#end
+#end
+#end
+#foreach($n in $intf.iterator() )
+#if ($n.isStruct() || $n.isEnumx() || $n.isExcept())
+$helper.getKeywordForWireshark($n.fqname().toString())
+#end
+#end
+#set ($tmp = $helper.resetHistory())
+#foreach($n in $intf.iterator())
+#if(!$n.isHidden())
+#if(!$n.isBuiltin())
+#foreach($p in $n.iterator())
+#if(!$helper.historyContains($p.name().toString()))
+$helper.getKeywordForWireshark($p.name().toString())
+#set ($tmp = $helper.addStringToHistory($p.name().toString()))
+#end
+#end
+#end
+#end
+#end
+$helper.getKeywordForWireshark("_Etch_RuntimeException")
+$helper.getKeywordForWireshark("_Etch_AuthException")
+$helper.getKeywordForWireshark("_exception")
+$helper.getKeywordForWireshark("_Etch_List")
+$helper.getKeywordForWireshark("_Etch_Map")
+$helper.getKeywordForWireshark("_Etch_Set")
+$helper.getKeywordForWireshark("_Etch_Datetime")
+$helper.getKeywordForWireshark("msg")
+$helper.getKeywordForWireshark("_messageId")
+$helper.getKeywordForWireshark("_inReplyTo")
+$helper.getKeywordForWireshark("result")
+$helper.getKeywordForWireshark("keys")
+$helper.getKeywordForWireshark("values")
+$helper.getKeywordForWireshark("dateTime")
+$helper.getKeywordForWireshark("keysAndValues")
Added: incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/helper.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/helper.vm?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/helper.vm (added)
+++ incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/helper.vm Mon Nov 29 14:29:21 2010
@@ -0,0 +1,126 @@
+## 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.
+// This file automatically generated by:
+// $version
+// $now
+// This file is automatically created and should not be edited!
+
+#set($i = $intf.name())
+package $helper.getPackageName($intf)
+
+import "etch"
+
+#if($helper.isServer($mc) || $helper.isBoth($mc))
+
+type ${i}ServerFactory struct {
+ session etch.Session
+ transport etch.Transport
+}
+
+func New${i}ServerFactory(transport etch.Transport) *${i}ServerFactory {
+ val := &${i}ServerFactory{nil, transport}
+ return val
+}
+
+func NewListener(addr string) etch.Transport{
+ tl := etch.NewTcpListener(addr)
+ dsl := etch.NewDefaultSessionListener(tl)
+ tl.SetSession(dsl)
+ sf := New${i}ServerFactory(dsl)
+ dsl.SetSession(sf)
+ return sf
+}
+
+func (dsf *${i}ServerFactory) NewServer(connection *etch.TcpConnection) {
+ ptzr := etch.NewPacketizer(connection, 10*1024)
+ connection.SetSession(ptzr)
+ dvf := NewValueFactory${i}()
+ msgzr := etch.NewMessagizer(dvf, ptzr)
+ ptzr.SetSession(msgzr)
+ mbm := etch.NewPlainMailboxManager(nil, msgzr)
+ msgzr.SetSession(mbm)
+ dsvc := etch.NewDefaultDeliveryService(mbm, nil)
+ mbm.SetSession(dsvc)
+ impl := new(Impl${i}Server)
+
+ stub := etch.NewEtchStub(dsvc, impl)
+ dsvc.SetSession(stub)
+
+ impl.TheClient = NewRemoteHelloWorldClient(dsvc, dvf)
+ SetStubHelpers_Stub${i}Server(dvf)
+
+ dsvc.TransportControl(etch.START, 4000)
+}
+
+
+func (dsf *${i}ServerFactory) SessionQuery(obj interface{}) interface{} {
+ return nil
+}
+
+func (dsf *${i}ServerFactory) SessionControl(ctrl interface{}, value interface{}) interface{} {
+ return nil
+}
+
+func (dsf *${i}ServerFactory) SessionNotify(obj interface{}) {
+
+}
+
+func (dsf *${i}ServerFactory) GetSession() etch.Session {
+ return nil
+}
+
+func (dsf *${i}ServerFactory) SetSession(sess etch.Session) {
+
+}
+
+func (dsf *${i}ServerFactory) TransportQuery(obj interface{}) interface{} {
+ return nil
+}
+
+func (dsf *${i}ServerFactory) TransportControl(ctrl interface{}, value interface{}) {
+ dsf.transport.TransportControl(ctrl, value)
+}
+
+func (dsf *${i}ServerFactory) TransportNotify(value interface{}) {
+
+}
+#end
+#if($helper.isClient($mc) || $helper.isBoth($mc))
+
+func NewRemoteServer(addr string) *Remote${i}Server{
+ tcpClientConn := etch.NewTcpConnection(addr, false, nil, nil)
+ cdsvc, vf := buildStack(tcpClientConn)
+ return NewRemote${i}Server(cdsvc, vf)
+}
+
+func buildStack(conn *etch.TcpConnection) (etch.DeliveryService, etch.ValueFactory) {
+ ptzr := etch.NewPacketizer(conn, 10*1024)
+ conn.SetSession(ptzr)
+ dvf := NewValueFactory${i}()
+ msgzr := etch.NewMessagizer(dvf, ptzr)
+ ptzr.SetSession(msgzr)
+ mbm := etch.NewPlainMailboxManager(nil, msgzr)
+ msgzr.SetSession(mbm)
+ dsvc := etch.NewDefaultDeliveryService(mbm, nil)
+ mbm.SetSession(dsvc)
+ stub := etch.NewEtchStub(dsvc, new(Impl${i}Client))
+ dsvc.SetSession(stub)
+
+ SetStubHelpers_Stub${i}Client(dvf)
+ return dsvc, dvf
+}
+#end
\ No newline at end of file
Added: incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/impl.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/impl.vm?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/impl.vm (added)
+++ incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/impl.vm Mon Nov 29 14:29:21 2010
@@ -0,0 +1,46 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied. See the License for the
+## specific language governing permissions and limitations
+## under the License.
+// This file automatically generated by:
+// $version
+// $now
+// This file is automatically created for your convenience and will not be
+// overwritten once it exists! Please edit this file as necessary to implement
+// your service logic.
+#set($i = $intf.name())
+#set($intfname = "$i$suffix")
+#set($baseclname = "Base$intfname")
+#set($clname = "Impl$intfname")
+#if ($helper.isServer($mc))
+#set($peer = "client")
+#set($peerclass = "Remote${i}Client")
+#else
+#set($peer = "server")
+#set($peerclass = "Remote${i}Server")
+#end
+
+package $helper.getPackageName($intf)
+
+type ${clname} struct {
+ ${intfname}_base
+}
+
+
+//ADD YOUR IMPLEMENTATIONS FOR SERVER/CLIENT SIDE METHODS HERE AS
+// func (f *${clname}) your_method(p param1, ...) {
+// //your code goes here
+// }
+//default implementation for methods can be found in ${intfname}_base.go
\ No newline at end of file
Added: incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/intf.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/intf.vm?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/intf.vm (added)
+++ incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/intf.vm Mon Nov 29 14:29:21 2010
@@ -0,0 +1,79 @@
+## 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.
+// This file automatically generated by:
+// $version
+// $now
+// This file is automatically created and should not be edited!
+
+package $helper.getPackageName($intf)
+
+#if ($hasBaseClass)
+type $intf.name()$suffix interface {
+ $intf.name()
+#else
+type $intf.name()$suffix interface {
+#end
+#foreach( $n in $intf.iterator() )
+#if ($n.isMixin())
+ $n.fqname()$suffix
+#end
+#end
+#if (!$intf.hasMessageDirection($mc))
+ // no $mc direction items defined.
+#end
+#foreach( $n in $intf.iterator() )
+#if ($n.isMessage())
+#if ($n.isMsgDir($mc))
+#if (!$n.isHidden())
+#set ($methodName = "$n.name() (")
+#set( $sep = "" )
+#foreach( $p in $n.iterator() )
+#set ($methodName = $methodName + "$sep $p.name() $helper.getTypeName( $p.type() )")
+#set( $sep = ", " )
+#end
+#set ($methodName = $methodName + " ) $helper.getTypeName( $n.type() )")
+ $methodName
+#end
+#end
+#elseif ($n.isConstant())
+//constants not yet supported
+#elseif ($n.isEnumx())
+//enums not yet supported
+#elseif ($n.isExtern())
+## ignore extern
+#elseif ($n.isMixin())
+## ignore mixin
+#elseif ($n.isBuiltin())
+## nothing to do.
+#end
+#end
+}
+
+#foreach( $n in $intf.iterator() )
+#if ($n.isStruct() || $n.isExcept())
+#if (!$hasBaseClass)
+type $helper.capitalize($n.name().toString()) struct {
+#if( $n.hasExtends() )
+ $n.getExtends().name()
+#end
+#foreach( $i in $n.iterator() )
+ $helper.capitalize($i.name().toString()) $helper.getTypeName( $i.type() )
+#end
+}
+#end
+#end
+#end
\ No newline at end of file
Added: incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/javaKeywords.kwd
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/javaKeywords.kwd?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/javaKeywords.kwd (added)
+++ incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/javaKeywords.kwd Mon Nov 29 14:29:21 2010
@@ -0,0 +1,77 @@
+# $Id: javaKeywords.kwd 777138 2009-05-21 14:44:35Z sccomer $
+#
+# 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.
+
+# * not used
+# ** added in 1.2
+# *** added in 1.4
+# **** added in 5.0
+
+true
+false
+null
+abstract
+continue
+for
+new
+switch
+assert # ***
+default
+goto # *
+package
+synchronized
+boolean
+do
+if
+private
+this
+break
+double
+implements
+protected
+throw
+byte
+else
+import
+public
+throws
+case
+enum # ****
+instanceof
+return
+transient
+catch
+extends
+int
+short
+try
+char
+final
+interface
+static
+void
+class
+finally
+long
+strictfp # **
+volatile
+const # *
+float
+native
+super
+while
Added: incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/main.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/main.vm?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/main.vm (added)
+++ incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/main.vm Mon Nov 29 14:29:21 2010
@@ -0,0 +1,62 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied. See the License for the
+## specific language governing permissions and limitations
+## under the License.
+// This file automatically generated by:
+// $version
+// $now
+// This file is automatically created for your convenience and will not be
+// overwritten once it exists! Please edit this file as necessary to implement
+// your service logic.
+package main
+
+#set($i = $intf.name())
+#set($intfname = "$i$suffix")
+#set($baseclname = "Base$intfname")
+#set($clname = "Impl$intfname")
+#if ($helper.isServer($mc))
+#set($peer = "client")
+#set($peerclass = "Remote${i}Client")
+#else
+#set($peer = "server")
+#set($peerclass = "Remote${i}Server")
+#end
+
+import "etch"
+import "$helper.getPackageName($intf)"
+import "fmt"
+import "bufio"
+import "os"
+
+func main() {
+#if ($helper.isServer($mc))
+ listener := ${helper.getPackageName($intf)}.NewListener("127.0.0.1:4001")
+ listener.TransportControl(etch.START_AND_WAIT_UP, 4000)
+ fmt.Printf("Press a key to exit\n")
+ reader := bufio.NewReader(os.Stdin)
+ reader.ReadBytes('\n');
+ listener.TransportControl(etch.STOP_AND_WAIT_DOWN, 4000)
+#else
+ remote := ${helper.getPackageName($intf)}.NewRemoteServer("127.0.0.1:4001")
+ remote.TransportControl(etch.START_AND_WAIT_UP, 4000)
+
+ //add your calls to the server here
+
+ fmt.Printf("Press Enter to exit\n")
+ reader := bufio.NewReader(os.Stdin)
+ reader.ReadBytes('\n');
+ remote.TransportControl(etch.STOP_AND_WAIT_DOWN, 4000)
+#end
+}
Added: incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/makefile.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/makefile.vm?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/makefile.vm (added)
+++ incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/makefile.vm Mon Nov 29 14:29:21 2010
@@ -0,0 +1,46 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied. See the License for the
+## specific language governing permissions and limitations
+## under the License.
+#set($i = $intf.name())
+FILES= \
+ Base${i}Client.go\
+ Base${i}Server.go\
+ ${i}Client.go\
+ ${i}.go\
+ ${i}Helper.go\
+ ${i}Server.go\
+ Impl${i}Client.go\
+ Impl${i}Server.go\
+ Remote${i}Client.go\
+ Remote${i}.go\
+ Remote${i}Server.go\
+ Stub${i}Client.go\
+ Stub${i}.go\
+ Stub${i}Server.go\
+ ValueFactory${i}.go\
+
+all: server
+ 8g -o ${i}client.8 -I ${ETCHLIBPATH} -I . Main${i}Client.go
+ 8l -L ${ETCHLIBPATH} -L . -o ${i}Client ${i}client.8
+
+server:
+ifndef ETCHLIBPATH
+ @echo Please call \"make ETCHLIBPATH=/some/path\",where /some/path contains etch.8
+ false
+endif
+ 8g -o ${helper.getPackageName($intf)}.8 -I ${ETCHLIBPATH} -I . ${FILES}
+ 8g -o ${i}server.8 -I ${ETCHLIBPATH} -I . Main${i}Listener.go
+ 8l -L ${ETCHLIBPATH} -L . -o ${i}Server ${i}server.8
Added: incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/readme.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/readme.vm?rev=1040122&view=auto
==============================================================================
--- incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/readme.vm (added)
+++ incubator/etch/trunk/binding-go/compiler/src/main/resources/org/apache/etch/bindings/go/compiler/readme.vm Mon Nov 29 14:29:21 2010
@@ -0,0 +1,17 @@
+## 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.
+Google Go Binding for Etch