You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by di...@apache.org on 2008/11/16 23:35:38 UTC
svn commit: r718128 [2/6] - in /incubator/etch/branches/etch-python: ./
binding-csharp/compiler/src/main/java/etch/bindings/csharp/compiler/
binding-csharp/compiler/src/main/resources/etch/bindings/csharp/compiler/
binding-csharp/runtime/ binding-cshar...
Modified: incubator/etch/branches/etch-python/binding-csharp/runtime/src/main/csharp/Etch/Util/URL.cs
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/binding-csharp/runtime/src/main/csharp/Etch/Util/URL.cs?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/binding-csharp/runtime/src/main/csharp/Etch/Util/URL.cs (original)
+++ incubator/etch/branches/etch-python/binding-csharp/runtime/src/main/csharp/Etch/Util/URL.cs Sun Nov 16 14:35:35 2008
@@ -27,15 +27,15 @@
{
#region MEMBER VARIABLES
- private String _scheme;
- private String _user;
- private String _password;
- private String _host;
- private int _port;
- private String _uri;
- private List<String> _params;
- private Dictionary<String, Object> _terms;
- private String _fragment;
+ private string scheme;
+ private string user;
+ private string password;
+ private string host;
+ private int? port;
+ private string uri;
+ private List<string> parms;
+ private Dictionary<string, object> terms;
+ private string fragment;
#endregion
@@ -45,7 +45,7 @@
/// Constructs a url from a string.
/// </summary>
/// <param name="urlString"></param>
- public URL( String urlString )
+ public URL( string urlString )
{
Parse( urlString );
}
@@ -56,15 +56,15 @@
/// <param name="other"></param>
public URL( URL other )
{
- _scheme = other.Scheme;
- _user = other.User;
- _password = other.Password;
- _host = other.Host;
- _port = other.Port;
- _uri = other.Uri;
- _params = CopyParams( other._params );
- _terms = CopyTerms( other._terms );
- _fragment = other._fragment;
+ scheme = other.scheme;
+ user = other.user;
+ password = other.password;
+ host = other.host;
+ port = other.port;
+ uri = other.uri;
+ parms = CopyList( other.parms );
+ terms = CopyTerms( other.terms );
+ fragment = other.fragment;
}
/// <summary>
@@ -77,11 +77,11 @@
#endregion
- private void Parse( String s )
+ private void Parse( string s )
{
// s is scheme:[//[user[:password]@]host[:port]/]uri[;params][?terms][#fragment]
- String[] x = StringUtil.LeftSplit( s, ':' );
+ string[] x = StringUtil.LeftSplit( s, ':' );
if ( x == null )
throw new ArgumentNullException( "missing scheme" );
@@ -135,13 +135,13 @@
s = "";
}
}
- _uri = Unescape( s );
+ Uri = Unescape( s );
}
- private void ParseHost( String s )
+ private void ParseHost( string s )
{
// s is [user[:password]@]host[:port]
- String[] x = StringUtil.LeftSplit( s, '@' );
+ string[] x = StringUtil.LeftSplit( s, '@' );
if ( x != null )
{
ParseUserPassword( x[ 0 ] );
@@ -153,37 +153,39 @@
}
}
- private void ParseUserPassword( String s )
+ private void ParseUserPassword( string s )
{
// s is user[:password]
- String[] x = StringUtil.LeftSplit( s, ':' );
+ string[] x = StringUtil.LeftSplit( s, ':' );
if ( x != null )
{
- _user = Unescape( x[ 0 ] );
- _password = Unescape( x[ 1 ] );
+ User = Unescape( x[ 0 ] );
+ Password = Unescape( x[ 1 ] );
}
else
{
- _user = Unescape( s );
+ User = Unescape( s );
}
}
- private void ParseHostPort( String s )
+ private void ParseHostPort( string s )
{
// s is host[:port]
- String[] x = StringUtil.LeftSplit( s, ':' );
+ string[] x = StringUtil.LeftSplit( s, ':' );
if ( x != null )
{
- _host = Unescape( x[ 0 ] );
- _port = Convert.ToInt32( Unescape( x[ 1 ] ) );
+ Host = Unescape( x[ 0 ] );
+ string p = Unescape(x[1]);
+ CheckNotInteger("port", p);
+ Port = int.Parse(p);
}
else
{
- _host = Unescape( s );
+ Host = Unescape( s );
}
}
- private void ParseParams( String s )
+ private void ParseParams( string s )
{
// s is param[;param]*
if ( s.Length == 0 )
@@ -191,7 +193,7 @@
EnsureParams();
- String[] x;
+ string[] x;
while ( ( x = StringUtil.LeftSplit( s, ';' ) ) != null )
{
AddParam( Unescape( x[ 0 ] ) );
@@ -200,14 +202,14 @@
AddParam( Unescape( s ) );
}
- private void ParseTerms( String s )
+ private void ParseTerms( string s )
{
// s is term[&term]*
if ( s.Length == 0 )
return;
- String[] x;
+ string[] x;
while ( ( x = StringUtil.LeftSplit( s, '&' ) ) != null )
{
ParseTerm( x[ 0 ] );
@@ -216,7 +218,7 @@
ParseTerm( s );
}
- private void ParseTerm( String s )
+ private void ParseTerm( string s )
{
// s is name[=value]
@@ -225,7 +227,7 @@
EnsureTerms();
- String[] x = StringUtil.LeftSplit( s, '=' );
+ string[] x = StringUtil.LeftSplit( s, '=' );
if ( x != null )
AddTerm( Unescape( x[ 0 ] ), Unescape( x[ 1 ] ) );
else
@@ -238,16 +240,16 @@
/// Gets and Sets the scheme.
/// Return the scheme which may be null but not blank.
/// </summary>
- public String Scheme
+ public string Scheme
{
get
{
- return _scheme;
+ return scheme;
}
set
{
CheckNotBlank( "scheme", value );
- _scheme = value;
+ scheme = value;
}
}
@@ -256,25 +258,25 @@
/// </summary>
/// <param name="testScheme">a scheme to test against.</param>
/// <returns>true if the schemes match, false otherwise.</returns>
- public bool IsScheme( String testScheme )
+ public bool IsScheme( string testScheme )
{
- return testScheme.Equals( _scheme, StringComparison.CurrentCultureIgnoreCase );
+ return testScheme.Equals( scheme, StringComparison.CurrentCultureIgnoreCase );
}
#endregion
#region USER
- public String User
+ public string User
{
get
{
- return _user;
+ return user;
}
set
{
CheckNotBlank( "user", value );
- _user = value;
+ user = value;
}
}
@@ -282,16 +284,16 @@
#region PASSWORD
- public String Password
+ public string Password
{
get
{
- return _password;
+ return password;
}
set
{
- CheckNotBlank( "password", value );
- _password = value;
+ //CheckNotBlank( "password", value );
+ password = value;
}
}
@@ -299,16 +301,16 @@
#region HOST
- public String Host
+ public string Host
{
get
{
- return _host;
+ return host;
}
set
{
CheckNotBlank( "host", value );
- _host = value;
+ host = value;
}
}
@@ -316,33 +318,38 @@
#region PORT
- public int Port
+ public int? Port
{
get
{
- return _port;
+ return port;
}
set
{
- if ( value < 0 || value > 65535 )
+ if ( value != null && value < 0 || value > 65535 )
throw new ArgumentOutOfRangeException( "port < 0 || port > 65535 " );
- _port = value;
+ port = value;
}
}
+ public bool HasPort()
+ {
+ return port != null;
+ }
+
#endregion
#region URI
- public String Uri
+ public string Uri
{
get
{
- return _uri;
+ return uri;
}
set
{
- _uri = value;
+ uri = value;
}
}
@@ -356,7 +363,7 @@
/// <returns>true if there is atleast one param</returns>
public bool HasParams()
{
- return ( ( _params!=null ) && ( _params.Count > 0 ) );
+ return ( ( parms!=null ) && ( parms.Count > 0 ) );
}
/// <summary>
@@ -367,16 +374,16 @@
/// <param name="prefix">the prefix of the param to fetch (e.g., "transport=").</param>
/// <returns>the param which starts with the specified prefix.</returns>
///
- public String GetParam( String prefix )
+ public string GetParam( string prefix )
{
- if ( _params == null )
+ CheckNotNull( prefix, "prefix == null");
+
+ if (parms == null)
return null;
- foreach ( String s in _params )
- {
- if ( s.StartsWith( prefix ) )
- return s;
- }
+ foreach (string p in parms)
+ if (p.StartsWith(prefix))
+ return p;
return null;
}
@@ -388,12 +395,12 @@
/// of the form "transport=tcp". But they can be anything you like, really.
/// The iterator might be empty.</returns>
///
- public IEnumerator<String> GetParams()
+ public string[] GetParams()
{
- if ( _params == null )
- return new EmptyIterator<String>();
+ if ( parms == null )
+ return new string[] {};
- return _params.GetEnumerator();
+ return parms.ToArray();
}
/// <summary>
@@ -402,10 +409,11 @@
/// </summary>
/// <param name="param">a param (e.g., "transport=tcp" or "01831864574898475").</param>
///
- public void AddParam( String param )
+ public void AddParam( string param )
{
+ CheckNotNull(param, "param == null");
EnsureParams();
- _params.Add( param );
+ parms.Add( param );
}
/// <summary>
@@ -417,17 +425,19 @@
/// <param name="prefix">the prefix of the param to remove (e.g., "transport=").</param>
/// <returns>the param removed.</returns>
///
- public String RemoveParam( String prefix )
+ public string RemoveParam( string prefix )
{
- if ( _params == null )
+ CheckNotNull(prefix, "prefix == null");
+
+ if ( parms == null )
return null;
- foreach ( String s in _params )
+ foreach ( string p in GetParams() )
{
- if ( s.StartsWith( prefix ) )
+ if ( p.StartsWith( prefix ) )
{
- _params.Remove( s );
- return s;
+ parms.Remove( p );
+ return p;
}
}
return null;
@@ -438,14 +448,14 @@
/// </summary>
public void ClearParams()
{
- if ( _params != null )
- _params.Clear();
+ if ( parms != null )
+ parms.Clear();
}
public void EnsureParams()
{
- if ( _params == null )
- _params = new List<string>();
+ if ( parms == null )
+ parms = new List<string>();
}
#endregion
@@ -457,9 +467,9 @@
/// </summary>
/// <returns>true if there is at least one query term. Query terms
/// are of the form name=value</returns>
- public Boolean HasTerms()
+ public bool HasTerms()
{
- return _terms!=null && _terms.Count>0;
+ return terms != null && terms.Count > 0;
}
/// <summary>
@@ -468,11 +478,14 @@
/// <param name="name"></param>
/// <returns>true if there is at least one query term with the specified
/// name</returns>
- public Boolean HasTerm( String name )
+ public bool HasTerm( string name )
{
- if ( _terms == null )
+ CheckName(name);
+
+ if ( terms == null )
return false;
- return _terms.ContainsKey( name );
+
+ return terms.ContainsKey( name );
}
@@ -482,17 +495,22 @@
/// <param name="name"></param>
/// <param name="value"></param>
/// <returns>if there is a query term with the specified value.</returns>
- public Boolean HasTerm( String name, String value )
+ public bool HasTerm( string name, string value )
{
- if ( _terms == null )
+ CheckName(name);
+
+ if ( terms == null )
return false;
- Object obj = _terms[ name ];
- if ( obj == null )
+ if (value == null)
+ return HasTerm(name);
+
+ object obj;
+ if (!terms.TryGetValue(name, out obj))
return false;
- if ( obj is List<String> )
- return ( ( List<String> ) obj ).Contains( value );
+ if ( obj is List<string> )
+ return ( ( List<string> ) obj ).Contains( value );
return obj.Equals( value );
}
@@ -503,9 +521,9 @@
/// <param name="name"></param>
/// <param name="value"></param>
/// <returns>if there is a query term with the specified value.</returns>
- public Boolean HasTerm( String name, int? value )
+ public bool HasTerm( string name, int? value )
{
- return HasTerm( name, value.ToString() );
+ return HasTerm( name, ToString(value) );
}
/// <summary>
@@ -514,9 +532,20 @@
/// <param name="name"></param>
/// <param name="value"></param>
/// <returns>if there is a query term with the specified value.</returns>
- public Boolean HasTerm( String name, double? value )
+ public bool HasTerm(string name, double? value)
{
- return HasTerm( name, value.ToString() );
+ return HasTerm(name, ToString(value));
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="name"></param>
+ /// <param name="value"></param>
+ /// <returns>if there is a query term with the specified value.</returns>
+ public bool HasTerm(string name, bool? value)
+ {
+ return HasTerm(name, ToString(value));
}
/// <summary>
@@ -524,17 +553,19 @@
/// </summary>
/// <param name="name"></param>
/// <returns>true if the query term specified by name has multiple values.</returns>
- public Boolean HasMultipleValues(String name)
+ public bool HasMultipleValues(string name)
{
- if ( _terms == null )
+ CheckName(name);
+
+ if ( terms == null )
return false;
- Object obj = _terms[ name ];
- if ( obj == null )
+ object obj;
+ if (!terms.TryGetValue(name, out obj))
return false;
- if ( obj is List<String> )
- return ( ( List<String> ) obj ).Count > 1;
+ if ( obj is List<string> )
+ return ( ( List<string> ) obj ).Count > 1;
return false;
}
@@ -544,33 +575,33 @@
/// </summary>
/// <param name="name"></param>
/// <returns>the value of the specified term, or null if not found.</returns>
- public String GetTerm( String name )
+ public string GetTerm(string name)
{
- Object obj = null;
- if ( _terms == null )
+ CheckName(name);
+
+ if (terms == null)
return null;
- try
- {
- obj = _terms[name];
- }
- catch (Exception)
- {
-
- }
- if ( obj == null )
+
+ object obj;
+ if (!terms.TryGetValue(name, out obj))
return null;
- if ( obj is List<String> )
+ if (obj is List<string>)
{
- IEnumerator<String> i = ( ( List<String> ) obj ).GetEnumerator();
- i.MoveNext();
- String s = i.Current;
+ IEnumerator<string> i = ((List<string>)obj).GetEnumerator();
+
+ if (!i.MoveNext())
+ return null;
+
+ string v = i.Current;
- if ( i.MoveNext() )
- throw new Exception( "term has multiple values" );
- return s;
+ if (i.MoveNext())
+ throw new Exception(string.Format("term {0} has multiple values", name));
+
+ return v;
}
- return ( String ) obj;
+
+ return (string)obj;
}
/// <summary>
@@ -579,76 +610,102 @@
/// <param name="name"></param>
/// <param name="defaultValue"></param>
/// <returns>the value of the specified term, or defaultValue if not found.</returns>
- public String GetTerm( String name, String defaultValue )
+ public string GetTerm( string name, string defaultValue )
{
- String value = GetTerm( name );
+ string value = GetTerm( name );
if ( value == null )
return defaultValue;
return value;
}
/// <summary>
- /// Gets the boolean value of the specified query term.
+ /// Gets the integer value of the specified query term.
/// </summary>
/// <param name="name"></param>
- /// <returns>the boolean value, or null if not found.</returns>
- /// <see cref="GetTerm(String)"/>
- public bool? GetBooleanTerm( String name )
+ /// <returns>the integer value, or null if not found.</returns>
+ ///
+ public int? GetIntegerTerm(string name)
{
- String s = GetTerm( name );
- if ( s == null )
+ string s = GetTerm(name);
+ if (s == null)
return null;
-
- // modeling java behavior
- return s.Equals( "true", StringComparison.CurrentCultureIgnoreCase )? true : false;
+ return int.Parse(s);
}
- public Boolean GetBooleanTerm( String name, Boolean defaultValue )
+ /// <summary>
+ /// Gets the integer value of the specified query term.
+ /// </summary>
+ /// <param name="name"></param>
+ /// <param name="defaultValue">the value to return if the term is not found.</param>
+ /// <returns>the integer value, or defaultValue if not found.</returns>
+ /// <see cref="GetTerm( string )"/>
+ ///
+ public int GetIntegerTerm(string name, int defaultValue)
{
- String s = GetTerm( name );
- if ( s == null )
+ int? v = GetIntegerTerm(name);
+ if (v == null)
return defaultValue;
-
- return ( s.Equals( "true", StringComparison.CurrentCultureIgnoreCase ) )? true : false;
+ return v.Value;
}
/// <summary>
- /// Gets the integer value of the specified query term.
+ /// Gets the double value of the specified query term.
/// </summary>
/// <param name="name"></param>
- /// <returns>the integer value, or null if not found.</returns>
+ /// <returns>the double value, or null if not found.</returns>
///
- public int? GetIntegerTerm( String name )
+ public double? GetDoubleTerm(string name)
{
- String s = GetTerm( name );
- if ( s == null )
+ string s = GetTerm(name);
+ if (s == null)
return null;
- return Convert.ToInt32( s );
+ return double.Parse(s);
}
/// <summary>
- /// Gets the integer value of the specified query term.
+ /// Gets the double value of the specified query term.
/// </summary>
/// <param name="name"></param>
/// <param name="defaultValue">the value to return if the term is not found.</param>
- /// <returns>the integer value, or defaultValue if not found.</returns>
- /// <see cref="GetTerm( String )"/>
+ /// <returns>the double value, or defaultValue if not found.</returns>
+ /// <see cref="GetTerm( string )"/>
///
- public int? GetIntegerTerm( String name, int defaultValue )
+ public double GetDoubleTerm(string name, double defaultValue)
{
- int? i = GetIntegerTerm( name );
- if ( i == null )
+ double? v = GetDoubleTerm(name);
+ if (v == null)
return defaultValue;
- return i;
+ return v.Value;
}
- public double? GetDoubleTerm( String name )
+ /// <summary>
+ /// Gets the boolean value of the specified query term.
+ /// </summary>
+ /// <param name="name"></param>
+ /// <returns>the boolean value, or null if not found.</returns>
+ /// <see cref="GetTerm(string)"/>
+ public bool? GetBooleanTerm(string name)
{
- String s = GetTerm( name );
- if ( s == null )
+ string s = GetTerm(name);
+ if (s == null)
return null;
+ return s.Equals("true", StringComparison.CurrentCultureIgnoreCase);
+ }
- return Convert.ToDouble( s );
+ /// <summary>
+ /// Gets the bool value of the specified query term.
+ /// </summary>
+ /// <param name="name"></param>
+ /// <param name="defaultValue">the value to return if the term is not found.</param>
+ /// <returns>the bool value, or defaultValue if not found.</returns>
+ /// <see cref="GetTerm( string )"/>
+ ///
+ public bool GetBooleanTerm(string name, bool defaultValue)
+ {
+ bool? v = GetBooleanTerm(name);
+ if (v == null)
+ return defaultValue;
+ return v.Value;
}
/// <summary>
@@ -656,30 +713,33 @@
/// </summary>
/// <param name="name"></param>
/// <returns>an iterator over the string values of the query term. May be empty.</returns>
- public IEnumerator<String> GetTerms( String name )
+ public string[] GetTerms( string name )
{
- if ( _terms == null )
- return null;
- Object obj = _terms[ name ];
- if ( obj == null )
- return new EmptyIterator<String>();
+ CheckName(name);
+
+ if ( terms == null )
+ return new string[] {};
- if ( obj is List<String> )
- return ( ( List<String> ) obj ).GetEnumerator();
+ object obj;
+ if (!terms.TryGetValue(name, out obj))
+ return new string[] { };
- return new SingleIterator<String>( ( String ) obj );
+ if ( obj is List<string> )
+ return ( ( List<string> ) obj ).ToArray();
+
+ return new string[] { (string)obj };
}
/// <summary>
/// Gets the names of the query terms.
/// </summary>
/// <returns>an iterator over the string names.</returns>
- public IEnumerator<String> GetTermNames()
+ public string[] GetTermNames()
{
- if ( _terms == null )
- return new EmptyIterator<String>();
+ if ( terms == null )
+ return new string[] { };
- return _terms.Keys.GetEnumerator();
+ return ToArray(terms.Keys);
}
/// <summary>
@@ -688,36 +748,50 @@
/// </summary>
/// <param name="name"></param>
/// <param name="value"></param>
- public void AddTerm( String name, String value )
+ public void AddTerm(string name, string value)
{
+ CheckName(name);
+
+ if (value == null)
+ return;
+
EnsureTerms();
- Object obj;
- try
- {
- obj = _terms[ name ];
- }
- catch ( KeyNotFoundException )
- {
- obj = null;
- }
+ object obj;
- if ( obj == null )
+ if (!terms.TryGetValue(name, out obj))
{
- _terms.Add( name, value );
+ terms.Add( name, value );
return;
}
- if ( obj is List<String> )
+ if ( obj is List<string> )
{
- ( ( List<String> ) obj ).Add( value );
+ List<string> values = (List<string>)obj;
+ if (!values.Contains(value))
+ values.Add(value);
return;
}
- List<String> values = new List<string>();
- values.Add( ( String ) obj );
- values.Add( value );
- _terms[ name ] = values;
+ // obj is not a list but we need one, so replace obj in terms with a
+ // list, then add value to the list.
+
+ List<string> nvalues = new List<string>();
+ terms[name] = nvalues;
+ nvalues.Add( ( string ) obj );
+
+ nvalues.Add( value );
+ }
+
+ /// <summary>
+ /// Adds the specified query term to the set of query terms. Duplicate
+ /// name/value pairs are suppressed.
+ /// </summary>
+ /// <param name="name"></param>
+ /// <param name="value"></param>
+ public void AddTerm( string name, int? value )
+ {
+ AddTerm(name, ToString(value));
}
/// <summary>
@@ -726,9 +800,9 @@
/// </summary>
/// <param name="name"></param>
/// <param name="value"></param>
- public void AddTerm( String name, int? value )
+ public void AddTerm(string name, double? value)
{
- AddTerm( name, value.ToString() );
+ AddTerm(name, ToString(value));
}
/// <summary>
@@ -737,9 +811,9 @@
/// </summary>
/// <param name="name"></param>
/// <param name="value"></param>
- public void AddTerm( String name, double? value )
+ public void AddTerm(string name, bool? value)
{
- AddTerm( name, value.ToString() );
+ AddTerm(name, ToString(value));
}
/// <summary>
@@ -747,9 +821,14 @@
/// </summary>
/// <param name="name"></param>
/// <returns>true if something was removed, false otherwise.</returns>
- public Boolean RemoveTerm( String name )
+ public bool RemoveTerm( string name )
{
- return _terms.Remove( name );
+ CheckName(name);
+
+ if (terms == null)
+ return false;
+
+ return terms.Remove(name);
}
/// <summary>
@@ -759,30 +838,51 @@
/// <param name="value"></param>
/// <returns>true if the name/value pair was found and removed.</returns>
///
- public Boolean RemoveTerm( String name, String value )
+ public bool RemoveTerm( string name, string value )
{
- if ( _terms == null )
+ CheckName(name);
+
+ if ( terms == null )
return false;
- Object obj = _terms[ name ];
- if ( obj == null )
+ if (value == null)
+ return RemoveTerm(name);
+
+ object obj;
+ if (!terms.TryGetValue(name, out obj))
return false;
- if ( obj is List<String> )
+ if ( obj is List<string> )
{
- List<String> x = ( List<String> ) obj;
- Boolean ok = x.Remove( value );
- if ( x.Count == 1 )
- {
- IEnumerator<String> it = x.GetEnumerator();
- it.MoveNext();
- _terms[ name ] = it.Current;
- }
-
+ List<string> x = ( List<string> ) obj;
+ bool ok = x.Remove( value );
+ if (x.Count == 0)
+ terms.Remove(name);
return ok;
}
- _terms.Remove( name );
- return true;
+
+ if (obj.Equals(value))
+ {
+ terms.Remove(name);
+ return true;
+ }
+
+ return false;
+ }
+
+ public Boolean RemoveTerm(string name, int? value)
+ {
+ return RemoveTerm(name, ToString(value));
+ }
+
+ public Boolean RemoveTerm(string name, double? value)
+ {
+ return RemoveTerm(name, ToString(value));
+ }
+
+ public Boolean RemoveTerm(string name, bool? value)
+ {
+ return RemoveTerm(name, ToString(value));
}
/// <summary>
@@ -790,14 +890,14 @@
/// </summary>
public void ClearTerms()
{
- if ( _terms != null )
- _terms.Clear();
+ if ( terms != null )
+ terms.Clear();
}
private void EnsureTerms()
{
- if ( _terms == null )
- _terms = new Dictionary<String, Object>();
+ if ( terms == null )
+ terms = new Dictionary<string, object>();
}
@@ -805,16 +905,16 @@
#region FRAGMENT
- public String Fragment
+ public string Fragment
{
get
{
- return _fragment;
+ return fragment;
}
set
{
CheckNotBlank( "fragment", value );
- _fragment = value;
+ fragment = value;
}
}
@@ -826,33 +926,33 @@
{
StringBuilder sb = new StringBuilder();
- Escape( sb, _scheme );
+ Escape( sb, scheme );
sb.Append( ':' );
- if ( _host != null )
+ if ( host != null )
{
sb.Append( "//" );
- if ( _user != null )
+ if ( user != null )
{
- Escape( sb, _user );
- if ( _password != null )
+ Escape( sb, user );
+ if ( password != null )
{
sb.Append( ':' );
- Escape( sb, _password );
+ Escape( sb, password );
}
sb.Append( '@' );
}
- Escape( sb, _host );
- if ( _port != 0 )
+ Escape( sb, host );
+ if ( port != null )
{
sb.Append( ':' );
- sb.Append( _port );
+ sb.Append( port );
}
sb.Append( '/' );
}
- if ( _uri != null )
- Escape( sb, _uri );
+ if ( uri != null )
+ Escape( sb, uri );
if ( HasParams() )
ParamsToString( sb );
@@ -860,35 +960,36 @@
if ( HasTerms() )
TermsToString( sb );
- if ( _fragment != null )
+ if ( fragment != null )
{
sb.Append( '#' );
- Escape( sb, _fragment );
+ Escape( sb, fragment );
}
+
return sb.ToString();
}
public override int GetHashCode()
{
int code = 23547853;
- code ^= hc( _scheme );
- code ^= hc( _user );
- code ^= hc( _password );
- code ^= hc( _host );
- code ^= hc( _port );
- code ^= hc( _uri );
- code ^= hc( _params );
- code ^= hc( _terms );
- code ^= hc( _fragment );
+ code ^= hc( scheme );
+ code ^= hc( user );
+ code ^= hc( password );
+ code ^= hc( host );
+ code ^= hc( port );
+ code ^= hc( uri );
+ code ^= hc( parms );
+ code ^= hc( terms );
+ code ^= hc( fragment );
return code;
}
- private int hc( Dictionary<String,Object> m )
+ private int hc( Dictionary<string,object> m )
{
return m != null ? m.GetHashCode() : 793;
}
- private int hc( List<String> s )
+ private int hc( List<string> s )
{
return s != null ? s.GetHashCode() : 161;
}
@@ -898,7 +999,7 @@
return i != null ? i.GetHashCode() : 59;
}
- private int hc( String s )
+ private int hc( string s )
{
return s != null ? s.GetHashCode() : 91;
}
@@ -909,77 +1010,59 @@
if ( obj == this )
return true;
- if ( !( obj is URL ) )
+ if (obj == null)
+ return false;
+
+ if (obj.GetType() != typeof(URL))
return false;
URL other = ( URL ) obj;
- if ( !_scheme.Equals( other.Scheme, StringComparison.CurrentCultureIgnoreCase ) )
+ if ( !StringUtil.EqIgnoreCase(scheme, other.scheme) )
return false;
- if ( !_user.Equals( other.User ) )
+ if (!StringUtil.Eq(user, other.user))
return false;
- if ( !_password.Equals( other.Password ) )
+ if (!StringUtil.Eq(password, other.password))
return false;
- if ( !_host.Equals( other.Host ) )
+ if (!StringUtil.Eq(host, other.host))
return false;
- if ( _port != other.Port )
+ if (!Eq(port, other.port))
return false;
- if (!_uri.Equals(other._uri))
+ if (!StringUtil.Eq(uri, other.uri))
return false;
- if ( !CompareParams( _params, other._params ) )
+ if ( !Eq( parms, other.parms ) )
return false;
- if ( !CompareTerms( _terms, other._terms ) )
+ if ( !Eq( terms, other.terms ) )
return false;
- if ( !_fragment.Equals( other.Fragment ) )
+ if (!StringUtil.Eq(fragment, other.fragment))
return false;
return true;
}
- private bool CompareParams( List<String> a, List<String> b )
- {
- if ( a == b )
- return true;
-
- int na = a != null ? a.Count : 0;
- int nb = b != null ? b.Count : 0;
-
-
-
- if (na == 0 || nb == 0)
- return na == 0 && nb == 0;
-
- return a.Equals( b );
- }
-
- private bool CompareTerms( Dictionary<String, Object> a, Dictionary<String, Object> b )
+ private static bool Eq(object a, object b)
{
- if ( a == b )
+ if (ReferenceEquals(a, b))
return true;
- int na = a != null ? a.Count : 0;
- int nb = b != null ? b.Count : 0;
-
- if ( na == 0 || nb == 0 )
- return na == 0 && nb == 0;
+ if (a == null || b == null)
+ return false;
- return a.Equals( b );
+ return a.Equals(b);
}
private void ParamsToString( StringBuilder sb )
{
- IEnumerator<String> it = GetParams();
- while ( it.MoveNext() )
+ foreach (string param in GetParams())
{
- String param = it.Current;
sb.Append( ';' );
Escape( sb, param );
}
@@ -988,18 +1071,14 @@
private void TermsToString( StringBuilder sb )
{
char sep = '?';
- IEnumerator<String> it = GetTermNames();
- while ( it.MoveNext() )
+ foreach (string name in GetTermNames())
{
- String name = it.Current;
- IEnumerator<String> jt = GetTerms( name );
- while ( jt.MoveNext() )
+ foreach (string value in GetTerms(name))
{
- String value = jt.Current;
- sb.Append( sep );
- Escape( sb, name );
- sb.Append( '=' );
- Escape( sb, value );
+ sb.Append(sep);
+ Escape(sb, name);
+ sb.Append('=');
+ Escape(sb, value);
sep = '&';
}
}
@@ -1011,19 +1090,25 @@
public void Dump()
{
Console.WriteLine( "---------------" );
- Console.WriteLine( "scheme = "+_scheme );
- Console.WriteLine( "user = "+_user );
- Console.WriteLine( "password = "+_password );
- Console.WriteLine( "host = "+_host );
- Console.WriteLine( "port = "+_port );
- Console.WriteLine( "uri = "+_uri );
- Console.WriteLine( "params = "+_params );
- Console.WriteLine( "terms = "+_terms );
- Console.WriteLine( "fragment = "+_fragment );
- }
+ Console.WriteLine( "scheme = "+scheme );
+ Console.WriteLine( "user = "+user );
+ Console.WriteLine( "password = "+password );
+ Console.WriteLine( "host = "+host );
+ Console.WriteLine( "port = "+port );
+ Console.WriteLine( "uri = "+uri );
+ Console.WriteLine( "params = "+parms );
+ Console.WriteLine( "terms = "+terms );
+ Console.WriteLine( "fragment = "+fragment );
+ }
- private void Escape( StringBuilder sb, String s )
+ private static void Escape( StringBuilder sb, string s )
{
+ if (s == null)
+ {
+ sb.Append("null");
+ return;
+ }
+
CharIterator i = new CharIterator( s );
while ( i.MoveNext() )
{
@@ -1045,7 +1130,7 @@
}
}
- private static Boolean IsEscaped( char c )
+ private static bool IsEscaped( char c )
{
if ( c >= '0' && c <= '9' )
return false;
@@ -1092,7 +1177,7 @@
return true;
}
- private String Unescape( String s )
+ private static string Unescape( string s )
{
StringBuilder sb = new StringBuilder();
CharIterator i = new CharIterator( s );
@@ -1119,44 +1204,74 @@
return sb.ToString();
}
- private static void CheckNotBlank( String name, String value )
+ private static void CheckName(string name)
{
- if ( value != null && value.Length == 0 )
- throw new ArgumentException( name + " is blank" );
+ if (name == null || name.Length == 0)
+ throw new ArgumentException("name null or empty");
}
- private static String ValueToString( double value )
+ private static string ToString(object value)
{
- return Convert.ToString( value );
+ return value != null ? value.ToString() : null;
}
- private static String ValueToString( int value )
+ private static string[] ToArray(Dictionary<string, object>.KeyCollection keyCollection)
{
- return Convert.ToString( value );
+ string[] a = new string[keyCollection.Count];
+ keyCollection.CopyTo(a, 0);
+ return a;
}
- private static List<String> CopyParams( List<String> paramss )
+ private void CheckNotNull(string value, string msg)
{
- if ( paramss == null )
+ if (value == null)
+ throw new NullReferenceException(msg);
+ }
+
+ private static void CheckNotBlank( string name, string value )
+ {
+ if ( value != null && value.Length == 0 )
+ throw new ArgumentException( name + " is blank" );
+ }
+
+ private static void CheckNotInteger(string name, string value)
+ {
+ CheckNotBlank(name, value);
+ try
+ {
+ int.Parse(value);
+ }
+ catch (FormatException)
+ {
+ throw new ArgumentException(name + " is not integer");
+ }
+ }
+
+ private static List<string> CopyList( List<string> parms )
+ {
+ // just goes one level deep.
+
+ if (parms == null)
return null;
- return new List<String>( paramss );
+
+ return new List<string>(parms);
}
- private static Dictionary<String, Object> CopyTerms( Dictionary<String, Object> terms )
+ private static Dictionary<string, object> CopyTerms( Dictionary<string, object> terms )
{
if ( terms == null )
return null;
- Dictionary<String, Object> map = new Dictionary<string, object>( terms );
- IEnumerator<KeyValuePair<String, Object>> i = map.GetEnumerator();
- while ( i.MoveNext() )
+ Dictionary<string, object> nterms = new Dictionary<string, object>();
+ foreach (KeyValuePair<string, object> me in terms)
{
- KeyValuePair<String, Object> me = i.Current;
- Object obj = me.Value;
- if ( obj is List<String> )
- map[ me.Key ] = new List<String>( ( List<String> ) obj );
+ string name = me.Key;
+ object value = me.Value;
+ if (value is List<string>)
+ value = CopyList((List<string>) value);
+ nterms.Add(name, value);
}
- return map;
+ return nterms;
}
#endregion
Modified: incubator/etch/branches/etch-python/binding-csharp/runtime/src/test/csharp/Etch/Transport/Fmt/Binary/TestBinaryTaggedDataInOut.cs
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/binding-csharp/runtime/src/test/csharp/Etch/Transport/Fmt/Binary/TestBinaryTaggedDataInOut.cs?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/binding-csharp/runtime/src/test/csharp/Etch/Transport/Fmt/Binary/TestBinaryTaggedDataInOut.cs (original)
+++ incubator/etch/branches/etch-python/binding-csharp/runtime/src/test/csharp/Etch/Transport/Fmt/Binary/TestBinaryTaggedDataInOut.cs Sun Nov 16 14:35:35 2008
@@ -13,6 +13,7 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
+
using System;
using System.Collections.Generic;
using System.Text;
@@ -151,11 +152,11 @@
public void Test_byte()
{
// 2 dimensional
- Test( new sbyte[][] { new sbyte[] { SByte.MinValue, -1, 0, 1, SByte.MaxValue }, new sbyte[] { 23 } },
+ TestX( new sbyte[][] { new sbyte[] { SByte.MinValue, -1, 0, 1, SByte.MaxValue }, new sbyte[] { 23 } },
Validator_byte.Get( 2 ) );
// 3 dimensional
- Test(
+ TestX(
new sbyte[][][]
{
new sbyte[][] { new sbyte[] { SByte.MinValue, -1, 0, 1, SByte.MaxValue }, new sbyte[] { 23 } },
@@ -169,12 +170,12 @@
public void Test_short()
{
// 2 dimensional
- Test( new short[][] { new short[] { short.MinValue, SByte.MinValue, -1, 0, 1,
+ TestX( new short[][] { new short[] { short.MinValue, SByte.MinValue, -1, 0, 1,
SByte.MaxValue, short.MaxValue }, new short[] { 23 } },
Validator_short.Get( 2 ) );
// 3 dimensional
- Test(
+ TestX(
new short[][][]
{
new short[][] { new short[] { short.MinValue, SByte.MinValue, -1, 0, 1,
@@ -193,12 +194,12 @@
{
// 2 Dimensional
- Test( new int[][] { new int[] { int.MinValue, short.MinValue, SByte.MinValue,
+ TestX( new int[][] { new int[] { int.MinValue, short.MinValue, SByte.MinValue,
-1, 0, 1, sbyte.MaxValue, short.MaxValue, int.MaxValue}, new int[] { 23 } },
Validator_int.Get( 2 ) );
// 3 dimensional
- Test(
+ TestX(
new int[][][]
{
new int[][] { new int[] { int.MinValue, short.MinValue, SByte.MinValue,
@@ -215,13 +216,13 @@
public void Test_long()
{
// 2 dimensional
- Test( new long[][] { new long[] { long.MinValue, int.MinValue, short.MinValue,
+ TestX( new long[][] { new long[] { long.MinValue, int.MinValue, short.MinValue,
SByte.MinValue, -1, 0, 1, sbyte.MaxValue, short.MaxValue,
int.MaxValue, long.MaxValue}, new long[] { 23 } },
Validator_long.Get( 2 ) );
// 3 dimensional
- Test(
+ TestX(
new long[][][]
{
new long[][] { new long[] { long.MinValue, int.MinValue, short.MinValue,
@@ -241,14 +242,14 @@
public void Test_float()
{
// 2 dimensional
- Test( new float[][] { new float[] { -1, 0, 1, float.MinValue, float.Epsilon,
+ TestX( new float[][] { new float[] { -1, 0, 1, float.MinValue, float.Epsilon,
float.MaxValue, float.NaN, float.NegativeInfinity,
float.PositiveInfinity, -0.0f, 1.1f,
3.141592653589793238462643383279f }, new float[] { 23 } },
Validator_float.Get( 2 ) );
// 3 dimensional
- Test(
+ TestX(
new float[][][]
{
new float[][] { new float[] { -1, 0, 1, float.MinValue, float.Epsilon,
@@ -273,14 +274,14 @@
public void Test_double()
{
// 2 dimensional
- Test( new double[][] { new double[]{ -1, 0, 1, double.MinValue, double.Epsilon,
+ TestX( new double[][] { new double[]{ -1, 0, 1, double.MinValue, double.Epsilon,
double.MaxValue, double.NaN, double.NegativeInfinity,
double.PositiveInfinity, -0.0f, 1.1f,
3.141592653589793238462643383279 }, new double[]{ 23 } },
Validator_double.Get( 2 ) );
// 3 dimensional
- Test(
+ TestX(
new double[][][]
{
new double[][] { new double[]{ -1, 0, 1, double.MinValue, double.Epsilon,
@@ -306,11 +307,11 @@
{
// 2 dimensional
- Test( new String[][] { new String[] { "", "a", "ab", "abc" }, new String[] { "23" } },
+ TestX( new String[][] { new String[] { "", "a", "ab", "abc" }, new String[] { "23" } },
Validator_string.Get( 2 ) );
// 3 dimensional
- Test(
+ TestX(
new String[][][]
{
new String[][] { new String[] { "", "a", "ab", "abc" }, new String[] { "23" } },
@@ -334,21 +335,45 @@
Field _mf__messageId = DefaultValueFactory._mf__messageId;
add.PutValidator( _mf__messageId, Validator_long.Get( 0 ) );
- long msgid = 0x0123456789abcdefL;
+ long msgid = 0x0102030405060708L;
Message msg = new Message( add, vf );
msg.Add( x, 1 );
msg.Add( y, 2 );
msg.Add( _mf__messageId, msgid );
- /*byte[] buf = */ Msg2bytes( msg );
+ testmsg2bytes(msg, null, new sbyte[] { 3, -122, 39, -23, -73, -100, 3, -122, 21, 10, 44, -77, 1, -122, 99, 6, -76, 104, -121, 1, 2, 3, 4, 5, 6, 7, 8, -122, 21, 10, 44, -76, 2, -127 });
+ testmsg2bytes(msg, false, new sbyte[] { 3, -122, 39, -23, -73, -100, 3, -122, 21, 10, 44, -77, 1, -122, 99, 6, -76, 104, -121, 1, 2, 3, 4, 5, 6, 7, 8, -122, 21, 10, 44, -76, 2, -127 });
+ testmsg2bytes(msg, true, new sbyte[] { 3, -109, 3, 97, 100, 100, 3, -109, 1, 120, 1, -109, 10, 95, 109, 101, 115, 115, 97, 103, 101, 73, 100, -121, 1, 2, 3, 4, 5, 6, 7, 8, -109, 1, 121, 2, -127 });
msg = new Message( add, vf );
msg.Add( x, 1000000000 );
msg.Add( y, 2000000000 );
msg.Add( _mf__messageId, msgid );
+ testmsg2bytes(msg, null, new sbyte[] { 3, -122, 39, -23, -73, -100, 3, -122, 21, 10, 44, -77, -122, 59, -102, -54, 0, -122, 99, 6, -76, 104, -121, 1, 2, 3, 4, 5, 6, 7, 8, -122, 21, 10, 44, -76, -122, 119, 53, -108, 0, -127 });
+ testmsg2bytes(msg, false, new sbyte[] { 3, -122, 39, -23, -73, -100, 3, -122, 21, 10, 44, -77, -122, 59, -102, -54, 0, -122, 99, 6, -76, 104, -121, 1, 2, 3, 4, 5, 6, 7, 8, -122, 21, 10, 44, -76, -122, 119, 53, -108, 0, -127 });
+ testmsg2bytes(msg, true, new sbyte[] { 3, -109, 3, 97, 100, 100, 3, -109, 1, 120, -122, 59, -102, -54, 0, -109, 10, 95, 109, 101, 115, 115, 97, 103, 101, 73, 100, -121, 1, 2, 3, 4, 5, 6, 7, 8, -109, 1, 121, -122, 119, 53, -108, 0, -127 });
+ }
+
+ private void testmsg2bytes( Message msg, bool? stringTypeAndField,
+ sbyte[] sexpected )
+ {
+ byte[] expected = ToSByteArray(sexpected);
+ byte[] actual = Msg2bytes( msg, stringTypeAndField );
+ try
+ {
+ AssertArrayEquals(expected, actual);
+ }
+ catch ( Exception )
+ {
+ Dump( expected );
+ Dump( actual );
+ throw;
+ }
+ }
- /*buf = */Msg2bytes( msg );
-
+ private byte[] ToSByteArray(sbyte[] a)
+ {
+ return (byte[])(Array)a;
}
[Test]
@@ -397,25 +422,25 @@
//_buf = new sbyte[] { 1, -9, -100, -73, -23, 39, -9, 104, -76, 6, 99, -13, -17, -51, -85, -119, 103, 69, 35, 1, -9, -76, 44, 10, 21, -9, 0, -108, 53, 119, -9, -77, 44, 10, 21, -9, 0, -54, -102, 59, -22 };
// _buf = new sbyte[] { 3, -9, 39, -23, -73, -100, -9, 99, 6, -76, 104, -13, 1, 35, 69, 103, -119, -85, -51, -17, -9, 21, 10, 44, -76, -9, 119, 53, -108, 0, -9, 21, 10, 44, -77, -9, 59, -102, -54, 0, -22 };
_buf = new sbyte[]
- {
- 3, // version
- -122, // INT (type)
- 39, -23, -73, -100, // add
- 3, // length
- -122, // INT (key)
- 99, 6, -76, 104,
- -121, // LONG (value)
- 1, 35, 69, 103, -119, -85, -51, -17,
- -122, // INT (key)
- 21, 10, 44, -76, // y
- -122, // INT (value)
- 119, 53, -108, 0,
- -122, // INT (key)
- 21, 10, 44, -77, // x
- -122, // INT (value)
- 59, -102, -54, 0,
- -127 // NONE
- };
+ {
+ 3, // version
+ -122, // INT (type)
+ 39, -23, -73, -100, // add
+ 3, // length
+ -122, // INT (key)
+ 99, 6, -76, 104,
+ -121, // LONG (value)
+ 1, 35, 69, 103, -119, -85, -51, -17,
+ -122, // INT (key)
+ 21, 10, 44, -76, // y
+ -122, // INT (value)
+ 119, 53, -108, 0,
+ -122, // INT (key)
+ 21, 10, 44, -77, // x
+ -122, // INT (value)
+ 59, -102, -54, 0,
+ -127 // NONE
+ };
buf = new byte[_buf.Length];
Buffer.BlockCopy(_buf, 0, buf, 0, _buf.Length);
@@ -500,7 +525,6 @@
TestPerf( "test_sum_perf", i, m, msg, n );
}
- /** @throws Exception */
[Test]
public void testValueToBytes()
{
@@ -630,28 +654,58 @@
assertValueToBytes(new DateTime[] { new DateTime(2008, 1, 2, 3, 4, 5, 6, DateTimeKind.Utc), new DateTime(2008, 2, 3, 4, 5, 6, 7, DateTimeKind.Utc) },
new sbyte[] { 3, 1, 1, 2, -111, -107, -122, 43, 57, 107, -52, 1, 2, -107, -122, 43, 57, 107, -52, 1, -122, 102, 0, 26, 64, -121, 0, 0, 1, 23, 56, 116, -88, -114, -127, -107, -122, 43, 57, 107, -52, 1, -122, 102, 0, 26, 64, -121, 0, 0, 1, 23, -35, 120, 5, 87, -127, -127, -127 });
- }
-
- private void assertValueToBytes( Object value, sbyte[] expectedBytes )
- {
- XType t = new XType(1, "a");
- Field f = new Field(2, "b");
- t.PutValidator(f, Validator_object.Get(0));
-
- Message msg = new Message(t, vf);
- msg.Add(f, value);
-
- BinaryTaggedDataOutput btdo = new BinaryTaggedDataOutput( vf, "none:" );
- FlexBuffer buf = new FlexBuffer();
- btdo.WriteMessage(msg, buf);
-
- buf.SetIndex( 0 );
- byte[] b = buf.GetAvailBytes();
- sbyte[] b1 = new sbyte[b.Length];
- Buffer.BlockCopy(b,0,b1,0,b.Length);
- Dump( b );
- AssertArrayEquals( expectedBytes, b1 );
- }
+ }
+
+ [Test]
+ public void badtype()
+ {
+ Message msg = Bytes2msg(new sbyte[] { 3, 1, 0, -127 });
+ Assert.AreEqual(1, msg.GetXType.Id);
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentException))]
+ public void badmsglen1()
+ {
+ Message msg = Bytes2msg(new sbyte[] { 3, 1, -1, -127 });
+ Console.WriteLine("msg = " + msg);
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentException))]
+ public void badmsglen2()
+ {
+ Message msg = Bytes2msg(new sbyte[] { 3, 1, 99, -127 });
+ Console.WriteLine("msg = " + msg);
+ }
+
+ [Test]
+ public void badfield()
+ {
+ Message msg = Bytes2msg(new sbyte[] { 3, 1, 1, 2, 2, -127 }, Validator.Level.MISSING_OK);
+ Console.WriteLine("msg = " + msg);
+ }
+
+ private void assertValueToBytes( Object value, sbyte[] expectedBytes )
+ {
+ XType t = new XType(1, "a");
+ Field f = new Field(2, "b");
+ t.PutValidator(f, Validator_object.Get(0));
+
+ Message msg = new Message(t, vf);
+ msg.Add(f, value);
+
+ BinaryTaggedDataOutput btdo = new BinaryTaggedDataOutput( vf, "none:" );
+ FlexBuffer buf = new FlexBuffer();
+ btdo.WriteMessage(msg, buf);
+
+ buf.SetIndex( 0 );
+ byte[] b = buf.GetAvailBytes();
+ sbyte[] b1 = new sbyte[b.Length];
+ Buffer.BlockCopy(b,0,b1,0,b.Length);
+ Dump( b );
+ AssertArrayEquals( expectedBytes, b1 );
+ }
private static void TestPerf( String name, int iter, Messagizer m, Message msg, int n )
{
@@ -748,20 +802,40 @@
}
#endregion MyPacketSource
- private byte[] Msg2bytes( Message msg )
+ private byte[] Msg2bytes(Message msg, bool? stringTypeAndField)
{
FlexBuffer buf = new FlexBuffer();
- BinaryTaggedDataOutput btdo = new BinaryTaggedDataOutput(vf, "none:");
- btdo.WriteMessage( msg,buf );
+
+ URL u = new URL("none:");
+ if (stringTypeAndField != null)
+ u.AddTerm(BinaryTaggedDataOutput.STRING_TYPE_AND_FIELD, stringTypeAndField.ToString());
+
+ BinaryTaggedDataOutput btdo = new BinaryTaggedDataOutput(vf, u.ToString());
+ btdo.WriteMessage( msg, buf );
buf.SetIndex( 0 );
return buf.GetAvailBytes();
}
- private Message Bytes2msg( byte[] buf )
- {
- BinaryTaggedDataInput btdi = new BinaryTaggedDataInput(vf, "tcp:");
+ private Message Bytes2msg(byte[] buf, Validator.Level level)
+ {
+ BinaryTaggedDataInput btdi = new BinaryTaggedDataInput(vf, "none:");
return btdi.ReadMessage(new FlexBuffer(buf));
- }
+ }
+
+ private Message Bytes2msg(byte[] buf)
+ {
+ return Bytes2msg(buf, Validator.Level.FULL);
+ }
+
+ private Message Bytes2msg(sbyte[] buf, Validator.Level level)
+ {
+ return Bytes2msg((byte[])(Array)buf, level);
+ }
+
+ private Message Bytes2msg(sbyte[] buf)
+ {
+ return Bytes2msg(buf, Validator.Level.FULL);
+ }
private void TestX( Object x, Validator v )
{
@@ -775,13 +849,14 @@
TestX( getValue, v.ElementValidator() );
}
}
- Object y = Test( x, v );
- // y = DefaultValueFactory.ArrayValue2Native( y, x.GetType()/*, cnvrtr*/ );
- AreEqual( x, y );
+
+ Test(x, v, null);
+ Test(x, v, false);
+ Test(x, v, true);
}
- private Object Test( Object x, Validator v )
+ private void Test(Object x, Validator v, bool? stringTypeAndField)
{
//Console.WriteLine( "-----------------------------------------" );
@@ -792,14 +867,16 @@
msg.Add( mf_x, x );
//Console.WriteLine( "msg = "+msg );
- byte[] bufx = Msg2bytes( msg );
+ byte[] bufx = Msg2bytes(msg, stringTypeAndField);
+ Dump(bufx);
Message msg2 = Bytes2msg( bufx );
//Console.WriteLine( "msg2 = "+msg2 );
msg2.CheckType( mt_foo );
Assert.AreEqual( 1, msg2.Count );
- msg.ContainsKey( mf_x );
- return msg2.Get( mf_x );
+ Assert.IsTrue(msg.ContainsKey( mf_x ));
+ Object y = msg2.Get(mf_x);
+ AreEqual(x, y);
}
public void Dump(byte[] buf)
@@ -910,8 +987,6 @@
{
private readonly static TypeMap types = new TypeMap();
-
-
private readonly static Class2TypeMap class2type =
new Class2TypeMap();
@@ -920,10 +995,8 @@
DefaultValueFactory.Init( types, class2type );
}
- /**
- * Constructs the ValueFactoryFake.
- */
- public MyValueFactory() : base ("none:",types,class2type)
+ public MyValueFactory()
+ : base ("none:", types, class2type)
{
// nothing to do.
}
Modified: incubator/etch/branches/etch-python/binding-csharp/runtime/src/test/csharp/Etch/Util/TestURL.cs
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/binding-csharp/runtime/src/test/csharp/Etch/Util/TestURL.cs?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/binding-csharp/runtime/src/test/csharp/Etch/Util/TestURL.cs (original)
+++ incubator/etch/branches/etch-python/binding-csharp/runtime/src/test/csharp/Etch/Util/TestURL.cs Sun Nov 16 14:35:35 2008
@@ -186,20 +186,8 @@
string testUrl = "tcp://user:password@127.0.0.1:4001/myUri";
URL url = new URL( testUrl );
Assert.IsFalse( url.HasParams() );
- Assert.IsNull( url.GetParam( "PARAM1=" ) );
-
- // get empty iterator
- IEnumerator<String> it = url.GetParams();
- Assert.IsFalse( it.MoveNext() );
- try
- {
- String s = it.Current;
- Assert.Fail();
- }
- catch ( Exception )
- {
- Assert.IsTrue( true );
- }
+ Assert.AreEqual(0, url.GetParams().Length);
+ Assert.IsNull(url.GetParam("PARAM1="));
testUrl = "tcp://user:password@127.0.0.1:4001/cuae;PARAM1=1;PARAM2=2";
url = new URL( testUrl );
@@ -208,39 +196,41 @@
Assert.AreEqual( "PARAM2=2", url.GetParam( "PARAM2" ) );
// get iterator over params
- it = url.GetParams();
- Assert.IsTrue( it.MoveNext() );
- Assert.AreEqual( "PARAM1=1", it.Current );
- Assert.IsTrue( it.MoveNext() );
- Assert.AreEqual( "PARAM2=2", it.Current );
- Assert.IsFalse( it.MoveNext() );
+ string[] p = url.GetParams();
+ Assert.AreEqual(2, p.Length);
+ Assert.IsTrue(Find("PARAM1=1", p));
+ Assert.IsTrue(Find("PARAM2=2", p));
// add a new param
url.AddParam( "0123456789" );
Assert.AreEqual( "0123456789", url.GetParam( "0123" ) );
- it = url.GetParams();
- Assert.IsTrue( it.MoveNext() );
- Assert.IsTrue( it.MoveNext() );
- Assert.IsTrue( it.MoveNext() );
- Assert.AreEqual( "0123456789", it.Current );
- Assert.IsFalse( it.MoveNext() );
- //Assert.AreEqual( "tcp://user:password@127.0.0.1:4001/cuae;PARAM1=1;PARAM2=2;0123456789", url.ToString() );
+ p = url.GetParams();
+ Assert.AreEqual(3, p.Length);
+ Assert.IsTrue(Find("PARAM1=1", p));
+ Assert.IsTrue(Find("PARAM2=2", p));
+ Assert.IsTrue(Find("0123456789", p));
// remove a param
Assert.AreEqual( "PARAM1=1", url.RemoveParam( "PARAM1" ) );
- Assert.IsNull( url.GetParam( "PARAM1=" ) );
- it = url.GetParams();
- Assert.IsTrue( it.MoveNext() );
- Assert.IsTrue( it.MoveNext() );
- Assert.AreEqual( "0123456789", it.Current );
- Assert.IsFalse( it.MoveNext() );
- //Assert.AreEqual( "tcp://user:password@127.0.0.1:4001/cuae;PARAM2=2;0123456789", url.ToString() );
+ Assert.IsNull(url.GetParam("PARAM1="));
+ p = url.GetParams();
+ Assert.AreEqual(2, p.Length);
+ Assert.IsTrue(Find("PARAM2=2", p));
+ Assert.IsTrue(Find("0123456789", p));
// clear all params
url.ClearParams();
Assert.IsFalse( url.HasParams() );
}
+ private bool Find(string s, string[] a)
+ {
+ foreach (string x in a)
+ if (x.Equals(s))
+ return true;
+ return false;
+ }
+
[Test]
public void TestQueryTerms()
{
@@ -250,18 +240,35 @@
testUrl = "tcp://user:password@127.0.0.1:4001/cuae?term1=500";
url = new URL( testUrl );
+
Assert.IsTrue( url.HasTerms() );
Assert.IsTrue( url.HasTerm( "term1" ) );
Assert.IsTrue( url.HasTerm( "term1", "500" ) );
- Assert.IsTrue( url.HasTerm( "term1", 500 ) );
- Assert.IsFalse( url.HasTerm( "term1", "1000" ) );
- Assert.IsFalse( url.HasMultipleValues( "term1" ) );
- Assert.AreEqual( "500", url.GetTerm( "term1" ) );
- Assert.AreEqual( 500, url.GetIntegerTerm( "term1" ) );
+ Assert.IsTrue(url.HasTerm("term1", 500));
+ Assert.IsFalse(url.HasTerm("term1", "1000"));
+ Assert.IsFalse(url.HasTerm("term1", 1000));
+ Assert.IsFalse(url.HasMultipleValues("term1"));
+ Assert.AreEqual("500", url.GetTerm("term1"));
+ Assert.AreEqual(500, url.GetIntegerTerm("term1"));
+ Assert.AreEqual("500", url.GetTerm("term1", "x"));
+ Assert.AreEqual(500, url.GetIntegerTerm("term1", 2));
+
+ Assert.IsFalse(url.HasTerm("term2"));
+ Assert.IsFalse(url.HasTerm("term2", "500"));
+ Assert.IsFalse(url.HasTerm("term2", 500));
+ Assert.IsNull(url.GetTerm("term2"));
+ Assert.IsNull(url.GetIntegerTerm("term2"));
+ Assert.AreEqual("x", url.GetTerm("term2", "x"));
+ Assert.AreEqual(2, url.GetIntegerTerm("term2", 2));
// multiple values of the same term
- url.AddTerm( "term1", 500.500 );
- Assert.IsTrue( url.HasMultipleValues( "term1" ) );
+ url.AddTerm( "term1", 500.5 );
+ Assert.IsTrue(url.HasMultipleValues("term1"));
+ Assert.IsTrue(url.HasTerm("term1"));
+ Assert.IsTrue(url.HasTerm("term1", "500"));
+ Assert.IsTrue(url.HasTerm("term1", 500));
+ Assert.IsTrue(url.HasTerm("term1", "500.5"));
+ Assert.IsTrue(url.HasTerm("term1", 500.5));
try
{
url.GetTerm( "term1" );
@@ -269,14 +276,12 @@
}
catch ( Exception )
{
- Assert.IsTrue( true );
+ // ignore exception
}
- IEnumerator<String> it = url.GetTerms( "term1" );
- Assert.IsTrue( it.MoveNext() );
- Assert.AreEqual( "500", it.Current );
- Assert.IsTrue( it.MoveNext() );
- Assert.AreEqual( "500.5", it.Current );
- Assert.IsFalse( it.MoveNext() );
+ string[] t = url.GetTerms( "term1" );
+ Assert.AreEqual(2, t.Length);
+ Assert.AreEqual( "500", t[0] );
+ Assert.AreEqual( "500.5", t[1] );
// add another term => multiple terms
url.AddTerm( "term2", "value" );
@@ -285,21 +290,19 @@
Assert.IsTrue( url.HasTerm( "term2", "value" ) );
Assert.AreEqual( "value", url.GetTerm( "term2" ) );
- it = url.GetTermNames();
- Assert.IsTrue( it.MoveNext() );
- Assert.AreEqual( "term1", it.Current );
- Assert.IsTrue( it.MoveNext() );
- Assert.AreEqual( "term2", it.Current );
- Assert.IsFalse( it.MoveNext() );
+ t = url.GetTermNames();
+ Assert.AreEqual(2, t.Length);
+ Assert.AreEqual( "term1", t[0] );
+ Assert.AreEqual( "term2", t[1] );
// Console.WriteLine( url.ToString() );
// remove term
Assert.IsFalse( url.RemoveTerm( "term3" ) );
Assert.IsTrue( url.RemoveTerm( "term2" ) );
Assert.IsFalse( url.HasTerm( "term2" ) );
- it = url.GetTermNames();
- Assert.IsTrue( it.MoveNext() );
- Assert.IsFalse( it.MoveNext() );
+ t = url.GetTermNames();
+ Assert.AreEqual(1, t.Length);
+ Assert.AreEqual("term1", t[0]);
// remove one value from a list of values for a term
Assert.IsTrue( url.RemoveTerm( "term1", "500.5" ) );
@@ -309,6 +312,7 @@
// clear terms
url.ClearTerms();
Assert.IsFalse( url.HasTerms() );
+ Assert.AreEqual(0, url.GetTermNames().Length);
Assert.AreEqual( "tcp://user:password@127.0.0.1:4001/cuae", url.ToString() );
}
Modified: incubator/etch/branches/etch-python/binding-java/compiler/src/main/java/etch/bindings/java/compiler/Compiler.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/binding-java/compiler/src/main/java/etch/bindings/java/compiler/Compiler.java?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/binding-java/compiler/src/main/java/etch/bindings/java/compiler/Compiler.java (original)
+++ incubator/etch/branches/etch-python/binding-java/compiler/src/main/java/etch/bindings/java/compiler/Compiler.java Sun Nov 16 14:35:35 2008
@@ -17,7 +17,6 @@
package etch.bindings.java.compiler;
-import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringReader;
@@ -40,6 +39,7 @@
import etch.compiler.CmdLineOptions;
import etch.compiler.EtchGrammarConstants;
import etch.compiler.LogHandler;
+import etch.compiler.Output;
import etch.compiler.ParseException;
import etch.compiler.Token;
import etch.compiler.Version;
@@ -169,7 +169,7 @@
return;
if (lh != null)
- lh.logMessage( level == 2 ? LogHandler.LEVEL_WARNING : LogHandler.LEVEL_ERROR, null, msg );
+ lh.report( level == 2 ? LogHandler.LEVEL_WARNING : LogHandler.LEVEL_ERROR, null, msg );
else
System.out.printf( "Velocity msg (%d): %s\n", level, msg );
}
@@ -180,7 +180,7 @@
return;
if (lh != null)
- lh.logMessage( level == 2 ? LogHandler.LEVEL_WARNING : LogHandler.LEVEL_ERROR, null, msg );
+ 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 );
}
@@ -225,15 +225,17 @@
}
@Override
- public void generate( Module module, CmdLineOptions options, LogHandler _lh )
+ public void generate( Module module, CmdLineOptions options )
throws Exception
{
- this.lh = _lh;
+ // java always wants to not flatten packages:
+ options.noFlattenPackages = true;
+
+ lh = options.lh;
- boolean ignoreGlobal = options.ignoreGlobal;
- boolean ignoreLocal = options.ignoreLocal;
- String userWords = options.userWordsList;
- File dir = options.outputDir;
+ 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.
@@ -246,56 +248,54 @@
mapWords( userWords, words );
// check for collisions with the reserved word list.
- ReservedWordChecker checker = new ReservedWordChecker( words, false,_lh );
+ ReservedWordChecker checker = new ReservedWordChecker( words, false, lh );
module.treewalk( checker );
if (!checker.ok())
{
- _lh.logMessage( LogHandler.LEVEL_ERROR, null, "Encountered errors during java generation.\n" );
+ 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.
- if (dir != null && module.name().name.length() > 0)
- {
- String path = module.name().name.replace( '.', '/' );
- dir = new File( dir, path );
- }
- else
+ Output dir = options.output;
+ Output templateDir = options.templateOutput;
+
+ String m = module.name().name;
+ if (m.length() > 0)
{
- dir = new File( "." );
+ dir = dir.newPackage( m );
+ templateDir = templateDir.newPackage( m );
}
-
- dir.mkdirs();
-
+
// generate code for each service.
for (Service intf : module)
{
+ // TODO flush gIntf
gIntf = intf;
- generate( intf, what, dir );
+ try
+ {
+ generate( intf, what, dir, templateDir );
+ }
+ finally
+ {
+ // TODO flush gIntf
+ gIntf = null;
+ }
}
- gIntf = null;
}
+ // TODO flush gIntf
+ @Deprecated
private Service gIntf;
- private void generate( final Service intf, Set<String> what, File dir )
- throws Exception
+ private void generate( final Service intf, Set<String> what, Output dir,
+ Output templateDir ) throws Exception
{
what = populateWhat( what );
- if (what == null)
- {
- // lh.logMessage( lh.LEVEL_ERROR, null,
- // "User has selected invalid option\n" );
- // return;
- throw new Exception(
- "User has selected invalid option. Valid Options are"
- + " all,both,server,client,impl,main,helper,none\n" );
- }
-
if (what.isEmpty())
{
// lh.logMessage( lh.LEVEL_ERROR, null, "User has selected NONE\n" );
@@ -304,182 +304,187 @@
final MessageDirection msgDir = getMessageDirection( what );
- // Generate the value factory file
- doFile( dir, getVfName( intf ) + fnSuffix, true, true, new Gen()
+ if (what.contains( WHAT_INTF ))
{
- public void run( PrintWriter pw ) throws Exception
- {
- generateVf( pw, intf );
- }
- }, lh );
-
- // Generate the interface, remote, and stub files
-
-// boolean hasBaseClass = intf.hasMessageDirection( MessageDirection.BOTH );
-
- generate( intf, dir, msgDir, MessageDirection.BOTH, false, true );
+ // 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 readme file.
+
+ generateReadme( intf, dir, msgDir );
+ }
- generate( intf, dir, msgDir, MessageDirection.SERVER, true, true );
+ // Generate main template file.
- generate( intf, dir, msgDir, MessageDirection.CLIENT, true, true );
+ if (what.contains( WHAT_MAIN ))
+ generateMain( intf, templateDir, msgDir );
- boolean force = what.contains( WHAT_FORCE );
-// System.out.println( "force = "+force );
+ // Generate impl template file.
- // Always generate helper file.
+ if (what.contains( WHAT_IMPL ))
+ generateImpl( intf, templateDir, msgDir );
+ }
- doFile( dir, getHelperName( intf ) + fnSuffix, true, true, new Gen()
+ private void generateReadme( final Service intf, Output dir,
+ final MessageDirection msgDir ) throws Exception
+ {
+ doFile( dir, "readme-etch-java-files.txt", lh, new Gen()
{
public void run( PrintWriter pw ) throws Exception
{
- generateHelper( pw, intf, msgDir );
+ generateReadme( pw, intf, msgDir );
}
- }, lh );
-
- // Always generate readme file.
+ } );
+ }
- doFile( dir, "readme-etch-java-files.txt", true, true, new Gen()
+ 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
{
- generateReadme( pw, intf, msgDir );
+ generateVf( pw, intf );
}
- }, lh );
-
- // Always Generate the base file
- generateBase( intf, dir, msgDir, true );
-
- // Generate main file.
-
- if (what.contains( WHAT_MAIN ))
- generateMain( intf, dir, msgDir, force );
-
- // Generate base and impl files.
+ } );
+ }
- if (what.contains( WHAT_IMPL ))
- generateImpl( intf, dir, msgDir, force );
+ 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, File dir,
- MessageDirection msgDir, boolean force ) throws Exception
+ 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, true, force,
- new Gen()
+ if (msgDir == MessageDirection.BOTH
+ || msgDir == MessageDirection.CLIENT)
+ doFile( dir, getMainName( intf, MessageDirection.CLIENT ) + fnSuffix, lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
{
- public void run( PrintWriter pw ) throws Exception
- {
- generateMain (pw, intf, MessageDirection.CLIENT, false );
- }
- }, lh
- );
-
- if (msgDir == MessageDirection.BOTH || msgDir == MessageDirection.SERVER)
- doFile( dir, getMainName( intf, MessageDirection.SERVER ) + fnSuffix, true, force,
- new Gen()
+ 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
{
- public void run( PrintWriter pw ) throws Exception
- {
- generateMain (pw, intf, MessageDirection.SERVER, false );
- }
- }, lh
- );
+ generateMain( pw, intf, MessageDirection.SERVER, false );
+ }
+ } );
}
- private void generateBase( final Service intf, File dir,
- MessageDirection msgDir, boolean force ) throws Exception
+ 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, true, force,
- new Gen()
+ doFile( dir, getBaseName( intf, MessageDirection.CLIENT ) + fnSuffix, lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
{
- public void run( PrintWriter pw ) throws Exception
- {
- generateBase (pw, intf, MessageDirection.CLIENT, false );
- }
- }, lh
- );
+ generateBase (pw, intf, MessageDirection.CLIENT, false );
+ }
+ } );
if (msgDir == MessageDirection.BOTH || msgDir == MessageDirection.SERVER)
- doFile( dir, getBaseName( intf, MessageDirection.SERVER ) + fnSuffix, true, force,
- new Gen()
+ doFile( dir, getBaseName( intf, MessageDirection.SERVER ) + fnSuffix, lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
{
- public void run( PrintWriter pw ) throws Exception
- {
- generateBase (pw, intf, MessageDirection.SERVER, false );
- }
- }, lh
- );
+ generateBase (pw, intf, MessageDirection.SERVER, false );
+ }
+ } );
}
- private void generateImpl( final Service intf, File dir,
- MessageDirection msgDir, boolean force ) throws Exception
+ 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, true, force,
- new Gen()
+ if (msgDir == MessageDirection.BOTH
+ || msgDir == MessageDirection.CLIENT)
+ doFile( dir, getImplName( intf, MessageDirection.CLIENT ) + fnSuffix, lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
{
- public void run( PrintWriter pw ) throws Exception
- {
- generateImpl (pw, intf, MessageDirection.CLIENT, false );
- }
- }, lh
- );
-
- if (msgDir == MessageDirection.BOTH || msgDir == MessageDirection.SERVER)
- doFile( dir, getImplName( intf, MessageDirection.SERVER ) + fnSuffix, true, force,
- new Gen()
+ 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
{
- public void run( PrintWriter pw ) throws Exception
- {
- generateImpl (pw, intf, MessageDirection.SERVER, false );
- }
- }, lh
- );
+ generateImpl( pw, intf, MessageDirection.SERVER, false );
+ }
+ } );
}
- private void generate( final Service intf, File dir,
+ private void generateIntfRemoteStub( final Service intf, Output dir,
final MessageDirection what, final MessageDirection mc,
- final boolean hasBaseClass, boolean makeFile ) throws Exception
+ final boolean hasBaseClass ) throws Exception
{
-
// Generate interface file
- doFile( dir, getIntfName( intf, mc ) + fnSuffix, makeFile, true, new Gen()
+ doFile( dir, getIntfName( intf, mc ) + fnSuffix, lh, new Gen()
{
public void run( PrintWriter pw ) throws Exception
{
generateIntf( pw, intf, mc, hasBaseClass );
}
- }, lh );
+ } );
// Generate remote file
if (mc == MessageDirection.BOTH || what == MessageDirection.BOTH
- || mc != what)
- doFile( dir, getRemoteName( intf, mc ) + fnSuffix, makeFile,
- true, new Gen()
+ || mc != what)
+ doFile( dir, getRemoteName( intf, mc ) + fnSuffix, lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
{
- public void run( PrintWriter pw ) throws Exception
- {
- generateRemote( pw, intf, mc, hasBaseClass );
- }
- }, lh
- );
+ generateRemote( pw, intf, mc, hasBaseClass );
+ }
+ } );
// Generate stub file
if (mc == MessageDirection.BOTH || what == MessageDirection.BOTH
- || mc == what)
- doFile( dir, getStubName( intf, mc ) + fnSuffix, makeFile,
- true, new Gen()
+ || mc == what)
+ doFile( dir, getStubName( intf, mc ) + fnSuffix, lh, new Gen()
+ {
+ public void run( PrintWriter pw ) throws Exception
{
- public void run( PrintWriter pw ) throws Exception
- {
- generateStub( pw, intf, mc, hasBaseClass );
- }
- }, lh
- );
+ generateStub( pw, intf, mc, hasBaseClass );
+ }
+ } );
}
/**
@@ -528,7 +533,10 @@
}
/**
- * Generate the call to message implementation of the interface.
+ * 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
@@ -552,7 +560,10 @@
}
/**
- * Generate the message to call implementation.
+ * 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
@@ -575,7 +586,8 @@
}
/**
- * Generate the transport helper.
+ * Generate the transport plumbing helper.
+ *
* @param pw
* @param intf
* @param mc
@@ -615,7 +627,7 @@
}
/**
- * Generate the message to call implementation.
+ * Generate the template main program.
*
* @param pw
* @param intf
@@ -638,7 +650,9 @@
}
/**
- * Generates the base class to be used by the impl class
+ * 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
@@ -661,7 +675,10 @@
}
/**
- * Generate the sample implementation.
+ * 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
@@ -693,6 +710,18 @@
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 );
@@ -707,23 +736,12 @@
{
return intf.name() + "Helper";
}
-
- private String getMainName( Service intf, MessageDirection mc )
- {
- if (mc == MessageDirection.SERVER)
- return "Main" + intf.name() + "Listener";
- return "Main" + getIntfName(intf, mc);
- }
+
private String getBaseName( Service intf, MessageDirection mc )
{
return "Base" + getIntfName( intf, mc );
}
- private String getImplName( Service intf, MessageDirection mc )
- {
- return "Impl" + getIntfName( intf, mc );
- }
-
@Override
public String asyncReceiverPoolName( Message msg )
{
@@ -1038,8 +1056,6 @@
Named<?> n = type.getNamed( gIntf );
- // Allow subclassing for builtins if they want it
-
if (n.isBuiltin())
{
Builtin b = (Builtin) n;
@@ -1109,5 +1125,5 @@
addBuiltin( service, newName( "Map" ), "java.util.Map<?, ?>", true );
addBuiltin( service, newName( "Set" ), "java.util.Set<?>", true );
addBuiltin( service, newName( "Datetime" ), "java.util.Date", false );
- }
+ }
}
Modified: incubator/etch/branches/etch-python/binding-java/compiler/src/main/resources/etch/bindings/java/compiler/remote.vm
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/binding-java/compiler/src/main/resources/etch/bindings/java/compiler/remote.vm?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/binding-java/compiler/src/main/resources/etch/bindings/java/compiler/remote.vm (original)
+++ incubator/etch/branches/etch-python/binding-java/compiler/src/main/resources/etch/bindings/java/compiler/remote.vm Sun Nov 16 14:35:35 2008
@@ -308,7 +308,7 @@
catch ( Exception e )
{
#foreach($t in $n.thrown().iterator())
- if (e.getClass() == ${t.getNamed().fqname()}.class)
+ if (e instanceof ${t.getNamed().fqname()})
throw ($t.getNamed().fqname()) e;
#end
if (e instanceof RuntimeException) throw (RuntimeException) e;
Modified: incubator/etch/branches/etch-python/binding-java/compiler/src/main/resources/etch/bindings/java/compiler/vf.vm
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/binding-java/compiler/src/main/resources/etch/bindings/java/compiler/vf.vm?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/binding-java/compiler/src/main/resources/etch/bindings/java/compiler/vf.vm (original)
+++ incubator/etch/branches/etch-python/binding-java/compiler/src/main/resources/etch/bindings/java/compiler/vf.vm Sun Nov 16 14:35:35 2008
@@ -174,11 +174,19 @@
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;
}
} );
Modified: incubator/etch/branches/etch-python/binding-java/runtime/src/main/java/etch/bindings/java/support/DefaultValueFactory.java
URL: http://svn.apache.org/viewvc/incubator/etch/branches/etch-python/binding-java/runtime/src/main/java/etch/bindings/java/support/DefaultValueFactory.java?rev=718128&r1=718127&r2=718128&view=diff
==============================================================================
--- incubator/etch/branches/etch-python/binding-java/runtime/src/main/java/etch/bindings/java/support/DefaultValueFactory.java (original)
+++ incubator/etch/branches/etch-python/binding-java/runtime/src/main/java/etch/bindings/java/support/DefaultValueFactory.java Sun Nov 16 14:35:35 2008
@@ -423,7 +423,7 @@
public void unlockDynamicTypes()
{
- // TODO dynamicTypes.unlock();
+ // TODO implement dynamicTypes.unlock();
throw new UnsupportedOperationException( "unlockDynamicTypes not implemented" );
}
}