Author: jgomes
Date: Wed May 28 11:00:02 2008
New Revision: 661031

URL: http://svn.apache.org/viewvc?rev=661031&view=rev
Log:
Add common utility functions that all providers can use.
Updated Visual Studio project defines to be the same as the NAnt defines.

Added:
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/   (with 
props)
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/Atomic.cs
    
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/AtomicBoolean.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/Convert.cs
    
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/CountDownLatch.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/DateUtils.cs
    activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs
Modified:
    activemq/activemq-dotnet/Apache.NMS/trunk/   (props changed)
    activemq/activemq-dotnet/Apache.NMS/trunk/nant-common.xml
    activemq/activemq-dotnet/Apache.NMS/trunk/vs2005-nms-test.csproj
    activemq/activemq-dotnet/Apache.NMS/trunk/vs2005-nms.csproj

Propchange: activemq/activemq-dotnet/Apache.NMS/trunk/
------------------------------------------------------------------------------
    bugtraq:label = Issue #:

Propchange: activemq/activemq-dotnet/Apache.NMS/trunk/
------------------------------------------------------------------------------
--- bugtraq:message (added)
+++ bugtraq:message Wed May 28 11:00:02 2008
@@ -0,0 +1 @@
+Fixes [AMQNET-%BUGID%]. (See 
https://issues.apache.org/activemq/browse/AMQNET-%BUGID%)

Propchange: activemq/activemq-dotnet/Apache.NMS/trunk/
------------------------------------------------------------------------------
    bugtraq:url = https://issues.apache.org/activemq/browse/AMQNET-%BUGID%

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/nant-common.xml
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/nant-common.xml?rev=661031&r1=661030&r2=661031&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/nant-common.xml (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/nant-common.xml Wed May 28 
11:00:02 2008
@@ -237,7 +237,7 @@
   <target name="set-net-3.5-framework-configuration">
     <property name="current.build.framework" value="net-3.5" />
     <property name="current.build.framework.name" value=".NET 3.5"/>
-    <property name="current.build.defines" value="${build.defines}NET,NET_3_5" 
dynamic="true" />
+    <property name="current.build.defines" 
value="${build.defines}NET,NET_2_0,NET_3_5" dynamic="true" />
     <property name="current.build.framework.sign" value="true"/>
     <property name="link.sdkdoc.version" value="SDK_v6_0a" />
     <property name="link.sdkdoc.web" value="true" />

Propchange: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/
------------------------------------------------------------------------------
    bugtraq:label = Issue #:

Added: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/Atomic.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/Atomic.cs?rev=661031&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/Atomic.cs 
(added)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/Atomic.cs 
Wed May 28 11:00:02 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_2_0
+       public class Atomic<T> where T : IComparable
+       {
+               private T atomicValue;
+
+               public T Value
+               {
+                       get
+                       {
+                               lock(this)
+                               {
+                                       return atomicValue;
+                               }
+                       }
+                       set
+                       {
+                               lock(this)
+                               {
+                                       atomicValue = value;
+                               }
+                       }
+               }
+
+               public Atomic(T defaultValue)
+               {
+                       atomicValue = defaultValue;
+               }
+
+               public bool CompareAndSet(T expected, T newValue)
+               {
+                       lock(this)
+                       {
+                               if(0 == atomicValue.CompareTo(expected))
+                               {
+                                       atomicValue = newValue;
+                                       return true;
+                               }
+
+                               return false;
+                       }
+               }
+       }
+#endif
+}

Added: 
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/AtomicBoolean.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/AtomicBoolean.cs?rev=661031&view=auto
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/AtomicBoolean.cs 
(added)
+++ 
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/AtomicBoolean.cs 
Wed May 28 11:00:02 2008
@@ -0,0 +1,76 @@
+/*
+ * 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_2_0
+
+       public class AtomicBoolean : Atomic<bool>
+       {
+               public AtomicBoolean(bool defaultValue)
+                               : base(defaultValue)
+               {
+               }
+       }
+
+#else
+
+       public class AtomicBoolean
+       {
+               private bool atomicValue;
+
+               public bool Value
+               {
+                       get
+                       {
+                               lock(this)
+                               {
+                                       return atomicValue;
+                               }
+                       }
+                       set
+                       {
+                               lock(this)
+                               {
+                                       atomicValue = value;
+                               }
+                       }
+               }
+
+               public AtomicBoolean(bool defaultValue)
+               {
+                       atomicValue = defaultValue;
+               }
+
+               public bool CompareAndSet(bool expected, bool newValue)
+               {
+                       lock(this)
+                       {
+                               if(atomicValue == expected)
+                               {
+                                       atomicValue = newValue;
+                                       return true;
+                               }
+
+                               return false;
+                       }
+               }
+       }
+#endif
+}

Added: activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/Convert.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/Convert.cs?rev=661031&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/Convert.cs 
(added)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/Convert.cs 
Wed May 28 11:00:02 2008
@@ -0,0 +1,47 @@
+/*
+ * 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;
+
+namespace Apache.NMS.Util
+{
+       class NMSConvert
+       {
+               public static AcknowledgementMode ToAcknowledgementMode(string 
ackText)
+               {
+                       if(String.Compare(ackText, "AutoAcknowledge", true) == 
0)
+                       {
+                               return AcknowledgementMode.AutoAcknowledge;
+                       }
+                       else if(String.Compare(ackText, "ClientAcknowledge", 
true) == 0)
+                       {
+                               return AcknowledgementMode.ClientAcknowledge;
+                       }
+                       else if(String.Compare(ackText, "DupsOkAcknowledge", 
true) == 0)
+                       {
+                               return AcknowledgementMode.DupsOkAcknowledge;
+                       }
+                       else if(String.Compare(ackText, "Transactional", true) 
== 0)
+                       {
+                               return AcknowledgementMode.Transactional;
+                       }
+                       else
+                       {
+                               return AcknowledgementMode.AutoAcknowledge;
+                       }
+               }
+       }
+}

Added: 
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/CountDownLatch.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/CountDownLatch.cs?rev=661031&view=auto
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/CountDownLatch.cs
 (added)
+++ 
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/CountDownLatch.cs
 Wed May 28 11:00:02 2008
@@ -0,0 +1,68 @@
+/*
+ * 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.Threading;
+
+namespace Apache.NMS.Util
+{
+       public class CountDownLatch
+       {
+               private readonly ManualResetEvent mutex = new 
ManualResetEvent(false);
+               private int remaining;
+
+               public CountDownLatch(int i)
+               {
+                       remaining = i;
+               }
+
+               public void countDown()
+               {
+                       lock(mutex)
+                       {
+                               if(remaining > 0)
+                               {
+                                       remaining--;
+                                       if(0 == remaining)
+                                       {
+                                               mutex.Set();
+                                       }
+                               }
+                       }
+               }
+
+               public int Remaining
+               {
+                       get
+                       {
+                               lock(mutex)
+                               {
+                                       return remaining;
+                               }
+                       }
+               }
+
+               public bool await(int timeout)
+               {
+                       return mutex.WaitOne(timeout, false);
+               }
+
+               public WaitHandle AsyncWaitHandle
+               {
+                       get { return mutex; }
+               }
+       }
+}

Added: 
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/DateUtils.cs
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/DateUtils.cs?rev=661031&view=auto
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/DateUtils.cs 
(added)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/DateUtils.cs 
Wed May 28 11:00:02 2008
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+using System;
+
+namespace Apache.NMS.Util
+{
+       public class DateUtils
+       {
+               /// <summary>
+               /// The start of the Windows epoch
+               /// </summary>
+               public static readonly DateTime windowsEpoch = new 
DateTime(1601, 1, 1, 0, 0, 0, 0);
+               /// <summary>
+               /// The start of the Java epoch
+               /// </summary>
+               public static readonly DateTime javaEpoch = new DateTime(1970, 
1, 1, 0, 0, 0, 0);
+               
+               /// <summary>
+               /// The difference between the Windows epoch and the Java epoch
+               /// in milliseconds.
+               /// </summary>
+               public static readonly long epochDiff; /* = 1164447360000L; */
+
+               static DateUtils()
+               {
+                       epochDiff = (javaEpoch.ToFileTimeUtc() - 
windowsEpoch.ToFileTimeUtc())
+                                                       / 
TimeSpan.TicksPerMillisecond;
+               }
+
+               public static long ToJavaTime(DateTime dateTime)
+               {
+                       return (dateTime.ToFileTime() / 
TimeSpan.TicksPerMillisecond) - epochDiff;
+               }
+
+               public static DateTime ToDateTime(long javaTime)
+               {
+                       return DateTime.FromFileTime((javaTime + epochDiff) * 
TimeSpan.TicksPerMillisecond);
+               }
+
+               public static long ToJavaTimeUtc(DateTime dateTime)
+               {
+                       return (dateTime.ToFileTimeUtc() / 
TimeSpan.TicksPerMillisecond) - epochDiff;
+               }
+
+               public static DateTime ToDateTimeUtc(long javaTime)
+               {
+                       return DateTime.FromFileTimeUtc((javaTime + epochDiff) 
* TimeSpan.TicksPerMillisecond);
+               }
+       }
+}

Added: 
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=661031&view=auto
==============================================================================
--- 
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs 
(added)
+++ 
activemq/activemq-dotnet/Apache.NMS/trunk/src/main/csharp/Util/URISupport.cs 
Wed May 28 11:00:02 2008
@@ -0,0 +1,102 @@
+/*
+ * 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.Collections.Specialized;
+using System.Globalization;
+using System.Text;
+using System.Reflection;
+
+namespace Apache.NMS.Util
+{
+       /// <summary>
+       /// 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&amp;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>
+               public static StringDictionary ParseQuery(string query)
+               {
+                       StringDictionary map = new StringDictionary();
+
+                       // strip the initial "?"
+                       if(query.StartsWith("?"))
+                       {
+                               query = query.Substring(1);
+                       }
+
+                       // split the query into parameters
+                       string[] parameters = query.Split('&');
+                       foreach(string pair in parameters)
+                       {
+                               if(pair.Length > 0)
+                               {
+                                       string[] nameValue = pair.Split('=');
+
+                                       if(nameValue.Length != 2)
+                                       {
+                                               throw new 
NMS.NMSException("Invalid URI parameter: " + query);
+                                       }
+
+                                       map[nameValue[0]] = nameValue[1];
+                               }
+                       }
+
+                       return map;
+               }
+
+               /// <summary>
+               /// Sets the public properties of a target object using a 
string map.
+               /// This method uses .Net reflection to identify public 
properties of
+               /// the target object matching the keys from the passed map.
+               /// </summary>
+               /// <param name="target">The object whose properties will be 
set.</param>
+               /// <param name="map">Map of key/value pairs.</param>
+               /// <param name="prefix">Key value prefix.  This is prepended 
to the property name
+               /// before searching for a matching key value.</param>
+               public static void SetProperties(object target, 
StringDictionary map, string prefix)
+               {
+                       Type type = target.GetType();
+
+                       foreach(string key in map.Keys)
+                       {
+                               if(key.ToLower().StartsWith(prefix.ToLower()))
+                               {
+                                       string bareKey = 
key.Substring(prefix.Length);
+                                       PropertyInfo prop = 
type.GetProperty(bareKey,
+                                                                               
                                        BindingFlags.FlattenHierarchy
+                                                                               
                                        | BindingFlags.Public
+                                                                               
                                        | BindingFlags.Instance
+                                                                               
                                        | BindingFlags.IgnoreCase);
+
+                                       if(null == prop)
+                                       {
+                                               throw new 
NMS.NMSException(string.Format("no such property: {0} on class: {1}", bareKey, 
target.GetType().Name));
+                                       }
+
+                                       prop.SetValue(target, 
Convert.ChangeType(map[key], prop.PropertyType, CultureInfo.InvariantCulture), 
null);
+                               }
+                       }
+               }
+       }
+}
+

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/vs2005-nms-test.csproj
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/vs2005-nms-test.csproj?rev=661031&r1=661030&r2=661031&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/vs2005-nms-test.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/vs2005-nms-test.csproj Wed May 28 
11:00:02 2008
@@ -17,14 +17,14 @@
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
     <OutputPath>build\net-2.0\debug\</OutputPath>
-    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DefineConstants>TRACE;DEBUG;NET,NET_2_0</DefineConstants>
     <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 
'Release|AnyCPU' ">
     <DebugSymbols>false</DebugSymbols>
     <Optimize>true</Optimize>
     <OutputPath>build\net-2.0\release\</OutputPath>
-    <DefineConstants>TRACE</DefineConstants>
+    <DefineConstants>TRACE;NET,NET_2_0</DefineConstants>
     <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
   </PropertyGroup>
   <ItemGroup>

Modified: activemq/activemq-dotnet/Apache.NMS/trunk/vs2005-nms.csproj
URL: 
http://svn.apache.org/viewvc/activemq/activemq-dotnet/Apache.NMS/trunk/vs2005-nms.csproj?rev=661031&r1=661030&r2=661031&view=diff
==============================================================================
--- activemq/activemq-dotnet/Apache.NMS/trunk/vs2005-nms.csproj (original)
+++ activemq/activemq-dotnet/Apache.NMS/trunk/vs2005-nms.csproj Wed May 28 
11:00:02 2008
@@ -19,14 +19,14 @@
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
     <OutputPath>build\net-2.0\debug\</OutputPath>
-    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DefineConstants>TRACE;DEBUG;NET,NET_2_0</DefineConstants>
     <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 
'Release|AnyCPU' ">
     <DebugSymbols>false</DebugSymbols>
     <Optimize>true</Optimize>
     <OutputPath>build\net-2.0\release\</OutputPath>
-    <DefineConstants>TRACE</DefineConstants>
+    <DefineConstants>TRACE;NET,NET_2_0</DefineConstants>
     <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
   </PropertyGroup>
   <ItemGroup>
@@ -62,6 +62,12 @@
     <Compile Include="src\main\csharp\NMSConnectionFactory.cs" />
     <Compile Include="src\main\csharp\NMSSecurityException.cs" />
     <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\Convert.cs" />
+    <Compile Include="src\main\csharp\Util\CountDownLatch.cs" />
+    <Compile Include="src\main\csharp\Util\DateUtils.cs" />
+    <Compile Include="src\main\csharp\Util\URISupport.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="activemq-dotnet.snk" />


Reply via email to