incubator-etch-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dix...@apache.org
Subject svn commit: r752721 [2/2] - in /incubator/etch/trunk/binding-python/compiler/src/main: java/org/apache/etch/bindings/python/compiler/ resources/org/apache/etch/bindings/python/compiler/
Date Thu, 12 Mar 2009 00:27:18 GMT
Modified: incubator/etch/trunk/binding-python/compiler/src/main/resources/org/apache/etch/bindings/python/compiler/vf.vm
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-python/compiler/src/main/resources/org/apache/etch/bindings/python/compiler/vf.vm?rev=752721&r1=752720&r2=752721&view=diff
==============================================================================
--- incubator/etch/trunk/binding-python/compiler/src/main/resources/org/apache/etch/bindings/python/compiler/vf.vm
(original)
+++ incubator/etch/trunk/binding-python/compiler/src/main/resources/org/apache/etch/bindings/python/compiler/vf.vm
Thu Mar 12 00:27:18 2009
@@ -16,78 +16,202 @@
 //   $now
 // This file is automatically created and should not be edited!
 
-using System;
-using System.Collections.Generic;
-using Etch.Msg;
-using Etch.Support;
+package $intf.parent().name();
+
+import org.apache.etch.bindings.java.msg.AsyncMode;
+import org.apache.etch.bindings.java.msg.Direction;
+import org.apache.etch.bindings.java.msg.Field;
+import org.apache.etch.bindings.java.msg.ImportExportHelper;
+import org.apache.etch.bindings.java.msg.StructValue;
+import org.apache.etch.bindings.java.msg.Type;
+import org.apache.etch.bindings.java.msg.TypeMap;
+import org.apache.etch.bindings.java.msg.ValueFactory;
+import org.apache.etch.bindings.java.support.Class2TypeMap;
+import org.apache.etch.bindings.java.support.DefaultValueFactory;
+
 #foreach( $n in $intf.iterator() )
 #if ($n.isExtern())
 #if ($n.hasImport( $helper ))
-using $n.getImport( $helper );
+import $n.getImport( $helper );
 #end
 #if ($n.hasSerializerImport( $helper ))
-using $n.getSerializerImport( $helper );
+import $n.getSerializerImport( $helper );
 #end
 #end
 #end
-#set( $i = $intf.name() )
-#set( $vf = "ValueFactory$i" )
-
-namespace $intf.parent().name()
-{
 
-///<summary>ValueFactory for $i.</summary>
-public class ${vf} : DefaultValueFactory
+#set( $vf = "ValueFactory$intf.name()" )
+/**
+ * ValueFactory for $intf.name().
+ */
+@SuppressWarnings("unused")
+public final class ${vf} extends DefaultValueFactory
 {
-	private readonly static TypeMap types = new TypeMap();
-    
-	private readonly static Class2TypeMap class2type = new Class2TypeMap();
-	 
-	///<summary>Constructs ${vf}.</summary>
-	public ${vf}(string uri) : base(uri, types, class2type)
+	/**
+	 * Constructs ${vf}.
+	 * @param uri the uri used to configure the session.
+	 */
+	public ${vf}( String uri )
 	{
+		super( uri, types, class2type );
 #foreach ( $n in $intf.iterator() )
 #if ($n.isMixin())
 #set( $m = $n.getModule() )
 #set( $s = $m.iterator().next() )
-		addMixin( new ${m.name()}.ValueFactory${s.name()}(uri) );
+		addMixin( new ${m.name()}.ValueFactory${s.name()}( uri ) );
+#end
 #end
-#end		
 	}
 	
-	private static void InitTypes()
+	private final static TypeMap types = new TypeMap();
+	
+	private final static Class2TypeMap class2type = new Class2TypeMap();
+
+	static
+	{
+		DefaultValueFactory.init( types, class2type );
+		initTypes();
+		initResults();
+		initFields();
+		initParams();
+	}
+#foreach ( $n in $intf.iterator() )
+#if ($n.isEnumx() || $n.isStruct() || $n.isExtern() || $n.isExcept() || $n.isMessage())
+
+	/** Type for $n.fqname() */
+	public static Type ${n.vname( $helper )};
+#end
+#end
+
+	private static void initTypes()
 	{
 #foreach ( $n in $intf.iterator() )
 #if ($n.isEnumx() || $n.isStruct() || $n.isExtern() || $n.isExcept() || $n.isMessage())
-		$n.vname( $helper ) =  types.Get( "$n.fqname()" );
+		${n.vname( $helper )} = types.get( "$n.fqname()" );
 #end
 #end
 	}
-	
-	private static void InitResults() 
+
+	private static void initResults()
 	{
 #foreach ( $n in $intf.iterator() )
 #if ($n.isMessage())
-		${n.vname( $helper )}.SetDirection( Direction.$n.getMessageDirection() );
+		${n.vname( $helper )}.setDirection( Direction.$n.msgDir() );
 #if (!$n.isHidden())
 #if ($n.isQueuedAsyncReceiver())
-		${n.vname( $helper )}.SetAsyncMode( AsyncMode.QUEUED );
+		${n.vname( $helper )}.setAsyncMode( AsyncMode.QUEUED );
 #elseif ($n.isFreeAsyncReceiver())
-		${n.vname( $helper )}.SetAsyncMode( AsyncMode.FREE );
+		${n.vname( $helper )}.setAsyncMode( AsyncMode.FREE );
 #else
-		${n.vname( $helper )}.SetAsyncMode( AsyncMode.NONE );
+		${n.vname( $helper )}.setAsyncMode( AsyncMode.NONE );
 #end
 #if (!$n.isOneway())
-#set($r = $n.getResultMessage())
-		${n.vname( $helper )}.SetResult( $r.vname( $helper ) );
-		${r.vname( $helper )}.Timeout = $n.getTimeout();
+#set( $r = $n.getResultMessage() )
+		${n.vname( $helper )}.setResult( $r.vname( $helper ) );
+		${r.vname( $helper )}.setTimeout( $n.getTimeout() );
+#end
 #end
 #end
 #end
-#end	
 	}
-	
-	private static void InitFields()
+## ----------------------------- import / export -----------------------------
+#foreach ( $n in $intf.iterator() )
+#if ($n.isStruct() || $n.isExcept())
+#set( $tname = $n.efqname( $helper ) )
+
+	static
+	{
+		class2type.put( ${tname}.class, ${n.vname( $helper )} );
+		${n.vname( $helper )}.setComponentType( ${tname}.class );
+#if ($n.hasExtends())
+		${n.vname( $helper )}.setSuperType( $n.getExtends().vname( $helper ) );
+#end
+		${n.vname( $helper )}.setImportExportHelper( new ImportExportHelper()
+		{
+			public final StructValue exportValue( ValueFactory vf, Object value )
+			{
+				StructValue struct = new StructValue( ${n.vname( $helper )}, vf );
+				$tname v = ($tname) value;
+#foreach( $p in $n.getAllParameters() )
+				struct.put( $p.vname( $helper ), v.$p.name() );
+#end
+				return struct;
+			}
+
+			public final Object importValue( StructValue struct )
+			{
+				$tname v = new ${tname}();
+#foreach ($p in $n.getAllParameters())
+				v.$p.name() = ($helper.getTypeName( $p.type() )) struct.get( $p.vname( $helper ) );
+#end
+				return v;
+			}
+		} );
+	}
+#elseif ($n.isExtern())
+#set( $tname = $n.efqname( $helper ) )
+#elseif ($n.isEnumx())
+#set( $tname = $n.efqname( $helper ) )
+
+	static
+	{
+		class2type.put( ${tname}.class, ${n.vname( $helper )} );
+		${n.vname( $helper )}.setComponentType( ${tname}.class );
+		${n.vname( $helper )}.setImportExportHelper( new ImportExportHelper()
+		{
+			public final StructValue exportValue( ValueFactory vf, Object value )
+			{
+				StructValue struct = new StructValue( ${n.vname( $helper )}, vf );
+				${tname} v = (${tname}) value;
+				switch (v)
+				{
+#foreach ($p in $n.iterator())
+					case $p.name(): struct.put( $p.vname( $helper ), true ); break;
+#end
+				}
+				return struct;
+			}
+
+			public final Object importValue( StructValue struct )
+			{
+				// if empty, it likely means that a null value was sent
+				// or an unknown key (from a different rev of the service).
+				if (struct.isEmpty())
+					return null;
+				
+				// there should only be a single key, so take the first one
+				Field key = struct.keySet().iterator().next();
+#foreach ($p in $n.iterator())
+				if (key == $p.vname( $helper )) return ${tname}.$p.name();
+#end
+
+				// a known key was sent, but it did not match any defined
+				// key for this type.
+				return null;
+			}
+		} );
+	}
+#end
+#end
+## ----------------------------- fields -----------------------------
+#set( $x = $params.clear() )
+## standard params from DefaultValueFactory
+#set( $x = $params.add( "msg" ) )
+#set( $x = $params.add( "result" ) )
+#foreach( $n in $intf.iterator() )
+#if ($n.isEnumx() || $n.isStruct() || $n.isExcept() || $n.isMessage())
+#foreach( $param in $n.iterator() )
+#if (!$params.contains($param.name().name()))
+#set( $x = $params.add($param.name().name()) )
+
+	/** Field for $param.name().name() */
+	public static Field $param.vname( $helper );
+#end
+#end
+#end
+#end
+
+	private static void initFields()
 	{
 #set( $x = $params.clear() )
 ## standard params from DefaultValueFactory
@@ -103,175 +227,76 @@
 #end
 #end
 #end
+
 #foreach ( $n in $intf.iterator() )
 #if ($n.isMessage())
 #if (!$n.isHidden())
 #if (!$n.isOneway())
 #set( $r = $n.getResultMessage() )
-		${r.vname( $helper )}.ResponseField = _mf_result;
+		${r.vname( $helper )}.setResponseField( _mf_result );
+#end
 #end
 #end
 #end
-#end	
 	}
 	
-	private static void InitParams()
+	static
+	{
+		// initialize the extern serializers:
+#foreach( $n in $intf.iterator() )
+#if ($n.isExtern())
+		${n.sname( $helper )}.init( ${n.vname( $helper )}, class2type );
+#end
+#end
+	}
+
+#set( $ctr = 0 )
+	private static void initParams()
 	{
 #foreach( $n in $intf.iterator() )
 #if ($n.isEnumx() || $n.isStruct() || $n.isExcept() || $n.isMessage())
+#if ($ctr > 0 && $ctr % 100 == 0)
+
+		initParams${ctr}();
+	}
+	
+	private static void initParams${ctr}()
+	{
+#end
+#set( $ctr = $ctr + 1 )
+
+		// params for $n.name()
 #if ($n.isStruct() || $n.isExcept())
 #foreach( $param in $n.getAllParameters() )
-		${n.vname( $helper )}.PutValidator( $param.vname( $helper ), $helper.getValidator( $param
) );
+		${n.vname( $helper )}.putValidator( $param.vname( $helper ), org.apache.etch.bindings.java.support.$helper.getValidator(
$param ) );
 #end
 #else
-		// params for $n.name()
 #foreach( $param in $n.iterator() )
-		${n.vname( $helper )}.PutValidator( $param.vname( $helper ), $helper.getValidator( $param
) );
+		${n.vname( $helper )}.putValidator( $param.vname( $helper ), org.apache.etch.bindings.java.support.$helper.getValidator(
$param ) );
 #end
 #end
 #if ($n.isMessage())
-		${n.vname( $helper )}.PutValidator( _mf__messageId, Validator_long.Get( 0 ) );
+		${n.vname( $helper )}.putValidator( _mf__messageId, org.apache.etch.bindings.java.support.Validator_long.get(
0 ) );
 #if ($n.isHidden())
 #set( $param = $n.getResultParam() )
 #set( $reqMsg = $n.getRequestMessage() )
 #foreach( $t in $reqMsg.thrown().iterator() )
-		${n.vname( $helper )}.PutValidator( $param.vname( $helper ), $helper.getValidator( $t )
); // thrown $t.name()
+		${n.vname( $helper )}.putValidator( $param.vname( $helper ), org.apache.etch.bindings.java.support.$helper.getValidator(
$t ) ); // thrown $t.name()
 #end
-		${n.vname( $helper )}.PutValidator( $param.vname( $helper ), Validator_RuntimeException.Get()
); // thrown RuntimeException
-		${n.vname( $helper )}.PutValidator( _mf__inReplyTo, Validator_long.Get( 0 ) );
+		${n.vname( $helper )}.putValidator( $param.vname( $helper ), org.apache.etch.bindings.java.support.Validator_RuntimeException.get()
); // thrown RuntimeException
+		${n.vname( $helper )}.putValidator( _mf__inReplyTo, org.apache.etch.bindings.java.support.Validator_long.get(
0 ) );
 #end
 #end
 #end
 #end
 	}
 	
-	
-	static ${vf}()
+	static
 	{
-		DefaultValueFactory.Init( types, class2type );
-		InitTypes();		
-		InitResults();
-		InitFields();
-		InitParams();
-
-## --- import/export ----
-
-#foreach ( $n in $intf.iterator() )
-#if ($n.isStruct() || $n.isExcept())
-#set( $tname = $n.efqname( $helper ) )
-
-		class2type.Add( typeof( ${tname} ), ${n.vname( $helper )} );
-		${n.vname( $helper )}.SetComponentType( typeof( ${tname} ) );
-		#if ($n.hasExtends())
-			${n.vname( $helper )}.SetSuperType( $n.getExtends().vname( $helper ) );
-		#end
-		${n.vname( $helper )}.SetImportExportHelper
-			( 
-				new ImportExportHelper(
-					delegate( ValueFactory vf, Object value ) 
-					{
-						StructValue sv = new StructValue( ${n.vname( $helper )}, vf );
-						$tname v = ($tname) value;
-#foreach( $p in $n.getAllParameters()  )
-						sv.Add( $p.vname( $helper ), v.$p.name() );
-#end
-						return sv;
-					}, 
-					delegate( StructValue sv ) 
-					{
-						$tname v = new ${tname}();
-						#foreach ($p in $n.getAllParameters())
-						v.$p.name() = ($helper.getTypeName( $p.type() )) sv.Get( $p.vname( $helper ) );
-						#end
-						return v;
-						
-					} 
-				)
-			);
-
-#elseif ($n.isExtern())
-#set( $tname = $n.efqname( $helper ) )
-#elseif ($n.isEnumx())
-#set( $tname = $n.efqname( $helper ) )
-
-		class2type.Add( typeof( ${tname} ), ${n.vname( $helper )} );
-		${n.vname( $helper )}.SetComponentType( typeof( ${tname} ) );
-		${n.vname( $helper )}.SetImportExportHelper
-			( 
-				new ImportExportHelper( 
-					
-					delegate( ValueFactory vf, Object value ) 
-					{
-						StructValue sv = new StructValue( ${n.vname( $helper )}, vf );
-						${tname} v = (${tname}) value;
-						switch (v)
-						{
-#foreach ($p in $n.iterator())
-							case ${tname}.$p.name(): sv.Add( $p.vname( $helper ), true ); break;
-#end
-						}
-						return sv;
-					}, 
-					delegate( StructValue sv ) 
-					{
-						// there should only be a single key, so take the first one
-						Field key = null;
-						IEnumerator<Field> myEnum = sv.Keys.GetEnumerator();
-						if (myEnum.MoveNext())
-							key = myEnum.Current;
-				
-#foreach ($p in $n.iterator())
-						if (key == $p.vname( $helper )) return ${tname}.$p.name();
-#end
-						return null;
-					} 
-				)
-			);
-
-#end
-#end
-
-		// initialize the extern serializers:
-#foreach( $n in $intf.iterator() )
-#if ($n.isExtern())
-		${n.sname( $helper )}.Init( ${n.vname( $helper )}, class2type );
-#end
-#end
-
-		// done updating types and fields, lock them.
-		types.Lock();
-		foreach(XType t in types.Values())
-			t.Lock();
-		class2type.Lock();
-
-
-	
-	} // end of static constructor
-
-	
-	
-#foreach ( $n in $intf.iterator() )
-#if ($n.isEnumx() || $n.isStruct() || $n.isExtern() || $n.isExcept() || $n.isMessage())
-	/// Type for $n.fqname() 
-	public static XType $n.vname( $helper );
-#end
-#end
-## ---------------------------------------------------------------------------
-	
-		
-#set( $x = $params.clear() )
-## standard params from DefaultValueFactory
-#set( $x = $params.add( "msg" ) )
-#set( $x = $params.add( "result" ) )
-#foreach( $n in $intf.iterator() )
-#if ($n.isEnumx() || $n.isStruct() || $n.isExcept() || $n.isMessage())
-#foreach( $param in $n.iterator() )
-#if (!$params.contains($param.name().name()))
-#set( $x = $params.add($param.name().name()) )
-	public static Field $param.vname( $helper );
-#end
-#end
-#end
-#end
+		// done updating types, and class2type: lock them.
+		types.lock();
+		for (Type t: types.values())
+			t.lock();
+		class2type.lock();
 	}
-}
\ No newline at end of file
+}



Mime
View raw message