You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by jg...@apache.org on 2008/10/24 20:18:18 UTC
svn commit: r707700 - in /activemq/activemq-dotnet/Apache.NMS/trunk:
src/main/csharp/Util/AtomicReference.cs src/main/csharp/Util/URISupport.cs
vs2008-nms.csproj
Author: jgomes
Date: Fri Oct 24 11:18:18 2008
New Revision: 707700
URL: http://svn.apache.org/viewvc?rev=707700&view=rev
Log:
Integrating patch submission from Allan Schrum.
Fixes [AMQNET-26]. (See https://issues.apache.org/activemq/browse/AMQNET-26)
Added:
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/AtomicReference.cs
Modified:
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs
activemq/activemq-dotnet/Apache.NMS/trunk/vs2008-nms.csproj
Added: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/AtomicReference.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/AtomicReference.cs?rev=707700&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/AtomicReference.cs (added)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/AtomicReference.cs Fri Oct 24 11:18:18 2008
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+using System;
+using System.Text;
+
+namespace Apache.NMS.Util
+{
+#if !NET_1_1
+ public class AtomicReference<T>
+ {
+ private T atomicValue;
+
+ public T Value
+ {
+ get
+ {
+ lock(this)
+ {
+ return atomicValue;
+ }
+ }
+ set
+ {
+ lock(this)
+ {
+ atomicValue = value;
+ }
+ }
+ }
+
+ public AtomicReference()
+ {
+ }
+
+ public AtomicReference(T defaultValue)
+ {
+ atomicValue = defaultValue;
+ }
+
+ public T GetAndSet(T value)
+ {
+ lock(this)
+ {
+ T ret = atomicValue;
+ atomicValue = value;
+ return ret;
+ }
+ }
+ }
+#endif
+}
Modified: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs?rev=707700&r1=707699&r2=707700&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs Fri Oct 24 11:18:18 2008
@@ -15,24 +15,27 @@
* limitations under the License.
*/
using System;
+using System.Collections;
using System.Collections.Specialized;
using System.Globalization;
using System.Reflection;
+using System.Text;
+using System.Web;
namespace Apache.NMS.Util
{
/// <summary>
- /// Class to provide support for URI query parameters which uses .Net reflection
+ /// Class to provide support for Uri query parameters which uses .Net reflection
/// to identify and set properties.
/// </summary>
public class URISupport
{
/// <summary>
- /// Parse a URI query string of the form ?x=y&z=0
+ /// Parse a Uri query string of the form ?x=y&z=0
/// into a map of name/value pairs.
/// </summary>
/// <param name="query">The query string to parse. This string should not contain
- /// URI escape characters.</param>
+ /// Uri escape characters.</param>
public static StringDictionary ParseQuery(string query)
{
StringDictionary map = new StringDictionary();
@@ -53,7 +56,7 @@
if(nameValue.Length != 2)
{
- throw new NMS.NMSException("Invalid URI parameter: " + query);
+ throw new NMS.NMSException("Invalid Uri parameter: " + query);
}
map[nameValue[0]] = nameValue[1];
@@ -63,6 +66,11 @@
return map;
}
+ public static StringDictionary ParseParameters(Uri uri)
+ {
+ return uri.Query == null ? emptyMap() : ParseQuery(stripPrefix(uri.Query, "?"));
+ }
+
/// <summary>
/// Sets the public properties of a target object using a string map.
/// This method uses .Net reflection to identify public properties of
@@ -96,6 +104,324 @@
}
}
}
+
+ private static String UrlDecode(String s)
+ {
+#if !NETCF
+ return HttpUtility.HtmlDecode(s);
+#else
+ return Uri.UnescapeDataString(s);
+#endif
+ }
+
+ private static String UrlEncode(String s)
+ {
+#if !NETCF
+ return HttpUtility.HtmlEncode(s);
+#else
+ return Uri.EscapeUriString(s);
+#endif
+ }
+
+ public static String createQueryString(StringDictionary options)
+ {
+ if(options.Count > 0)
+ {
+ StringBuilder rc = new StringBuilder();
+ bool first = true;
+ foreach(String key in options.Keys)
+ {
+ string value = options[key];
+
+ if(first)
+ {
+ first = false;
+ }
+ else
+ {
+ rc.Append("&");
+ }
+ rc.Append(UrlEncode(key));
+ rc.Append("=");
+ rc.Append(UrlEncode(value));
+ }
+ return rc.ToString();
+ }
+ else
+ {
+ return "";
+ }
+ }
+
+ public class CompositeData
+ {
+ private String host;
+ private String scheme;
+ private String path;
+ private Uri[] components;
+ private StringDictionary parameters;
+ private String fragment;
+
+ public Uri[] Components
+ {
+ get { return components; }
+ set { components = value; }
+ }
+
+ public String Fragment
+ {
+ get { return fragment; }
+ set { fragment = value; }
+ }
+
+ public StringDictionary Parameters
+ {
+ get { return parameters; }
+ set { parameters = value; }
+ }
+
+ public String Scheme
+ {
+ get { return scheme; }
+ set { scheme = value; }
+ }
+
+ public String Path
+ {
+ get { return path; }
+ set { path = value; }
+ }
+
+ public String Host
+ {
+ get { return host; }
+ set { host = value; }
+ }
+
+ public Uri toUri()
+ {
+ StringBuilder sb = new StringBuilder();
+ if(scheme != null)
+ {
+ sb.Append(scheme);
+ sb.Append(':');
+ }
+
+ if(host != null && host.Length != 0)
+ {
+ sb.Append(host);
+ }
+ else
+ {
+ sb.Append('(');
+ for(int i = 0; i < components.Length; i++)
+ {
+ if(i != 0)
+ {
+ sb.Append(',');
+ }
+ sb.Append(components[i].ToString());
+ }
+ sb.Append(')');
+ }
+
+ if(path != null)
+ {
+ sb.Append('/');
+ sb.Append(path);
+ }
+
+ if(parameters.Count != 0)
+ {
+ sb.Append("?");
+ sb.Append(createQueryString(parameters));
+ }
+
+ if(fragment != null)
+ {
+ sb.Append("#");
+ sb.Append(fragment);
+ }
+
+ return new Uri(sb.ToString());
+ }
+ }
+
+ public static String stripPrefix(String value, String prefix)
+ {
+ if(value.StartsWith(prefix))
+ {
+ return value.Substring(prefix.Length);
+ }
+
+ return value;
+ }
+
+ public static CompositeData parseComposite(Uri uri)
+ {
+
+ CompositeData rc = new CompositeData();
+ rc.Scheme = uri.Scheme;
+ String ssp = stripPrefix(uri.AbsoluteUri.Trim(), rc.Scheme).Trim();
+ ssp = stripPrefix(ssp, ":").Trim();
+ ssp = stripPrefix(ssp, "//").Trim();
+
+ parseComposite(uri, rc, ssp);
+
+ rc.Fragment = uri.Fragment;
+ return rc;
+ }
+
+ /// <summary>
+ /// </summary>
+ /// <param name="uri"></param>
+ /// <param name="rc"></param>
+ /// <param name="ssp"></param>
+ /// <param name="p"></param>
+ private static void parseComposite(Uri uri, CompositeData rc, String ssp)
+ {
+ String componentString;
+ String parms;
+
+ if(!checkParenthesis(ssp))
+ {
+ throw new ApplicationException(uri.ToString() + ": Not a matching number of '(' and ')' parenthesis");
+ }
+
+ int p;
+ int intialParen = ssp.IndexOf("(");
+ if(intialParen >= 0)
+ {
+ rc.Host = ssp.Substring(0, intialParen);
+ p = rc.Host.IndexOf("/");
+ if(p >= 0)
+ {
+ rc.Path = rc.Host.Substring(p);
+ rc.Host = rc.Host.Substring(0, p);
+ }
+ p = ssp.LastIndexOf(")");
+ componentString = ssp.Substring(intialParen + 1, p - 1);
+ parms = ssp.Substring(p + 1).Trim();
+
+ }
+ else
+ {
+ p = ssp.IndexOf("?");
+ if(p >= 0)
+ {
+ componentString = ssp.Substring(0, p);
+ parms = ssp.Substring(p);
+ }
+ else
+ {
+ componentString = ssp;
+ parms = "";
+ }
+ }
+
+ String[] components = splitComponents(componentString);
+ rc.Components = new Uri[components.Length];
+ for(int i = 0; i < components.Length; i++)
+ {
+ rc.Components[i] = new Uri(components[i].Trim());
+ }
+
+ p = parms.IndexOf("?");
+ if(p >= 0)
+ {
+ if(p > 0)
+ {
+ rc.Path = stripPrefix(parms.Substring(0, p), "/");
+ }
+ rc.Parameters = ParseQuery(parms.Substring(p + 1));
+ }
+ else
+ {
+ if(parms.Length > 0)
+ {
+ rc.Path = stripPrefix(parms, "/");
+ }
+ rc.Parameters = emptyMap();
+ }
+ }
+
+ private static StringDictionary emptyMap()
+ {
+ return new StringDictionary();
+ }
+
+ /// <summary>
+ /// </summary>
+ /// <param name="componentString"></param>
+ private static String[] splitComponents(String str)
+ {
+ ArrayList l = new ArrayList();
+
+ int last = 0;
+ int depth = 0;
+ char[] chars = str.ToCharArray();
+ for(int i = 0; i < chars.Length; i++)
+ {
+ switch(chars[i])
+ {
+ case '(':
+ depth++;
+ break;
+ case ')':
+ depth--;
+ break;
+ case ',':
+ if(depth == 0)
+ {
+ String s = str.Substring(last, i);
+ l.Add(s);
+ last = i + 1;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ String ending = str.Substring(last);
+ if(ending.Length != 0)
+ {
+ l.Add(ending);
+ }
+
+ String[] rc = new String[l.Count];
+ l.CopyTo(rc);
+
+ return rc;
+ }
+
+ public static bool checkParenthesis(String str)
+ {
+ bool result = true;
+ if(str != null)
+ {
+ int open = 0;
+ int closed = 0;
+
+ int i = 0;
+ while((i = str.IndexOf('(', i)) >= 0)
+ {
+ i++;
+ open++;
+ }
+
+ i = 0;
+ while((i = str.IndexOf(')', i)) >= 0)
+ {
+ i++;
+ closed++;
+ }
+
+ result = (open == closed);
+ }
+
+ return result;
+ }
}
}
Modified: activemq/activemq-dotnet/Apache.NMS/trunk/vs2008-nms.csproj
URL: http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/vs2008-nms.csproj?rev=707700&r1=707699&r2=707700&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/vs2008-nms.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/vs2008-nms.csproj Fri Oct 24 11:18:18 2008
@@ -42,6 +42,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
+ <Reference Include="System.Web" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
@@ -74,6 +75,7 @@
<Compile Include="src\main\csharp\Tracer.cs" />
<Compile Include="src\main\csharp\Util\Atomic.cs" />
<Compile Include="src\main\csharp\Util\AtomicBoolean.cs" />
+ <Compile Include="src\main\csharp\Util\AtomicReference.cs" />
<Compile Include="src\main\csharp\Util\Convert.cs" />
<Compile Include="src\main\csharp\Util\CountDownLatch.cs" />
<Compile Include="src\main\csharp\Util\DateUtils.cs" />