Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18183/Spring/Spring.Core/Util
Modified Files:
MethodInvoker.cs StringUtils.cs TypeAliasResolver.cs
Log Message:
Added centralised Type resolution mechanism, runtime type converter, Xml Config handler, multiple documentation updates.
Index: StringUtils.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Util/StringUtils.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** StringUtils.cs 16 Jul 2004 13:59:03 -0000 1.6
--- StringUtils.cs 26 Jul 2004 07:47:57 -0000 1.7
***************
*** 1,27 ****
/*
! * Copyright 2002-2004 the original author or authors.
! *
! * Licensed 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;
using System.Text;
namespace Spring.Util
{
/// <summary>
! /// Miscellaneous string utility methods. Mainly for internal use
! /// within the framework.
/// </summary>
/// <author>Rod Johnson</author>
--- 1,36 ----
+ #region Licence
+
/*
! * Copyright 2002-2004 the original author or authors.
! *
! * Licensed 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.
! */
!
! #endregion
!
! #region Imports
!
using System;
using System.Collections;
using System.Text;
+ #endregion
+
namespace Spring.Util
{
/// <summary>
! /// Miscellaneous <see cref="System.String"/> utility methods.
! /// Mainly for internal use within the framework.
/// </summary>
/// <author>Rod Johnson</author>
***************
*** 34,44 ****
public abstract class StringUtils
{
! /// <summary> Count the occurrences of the substring in string s.</summary>
! /// <param name="s">string to search in. Return 0 if this is null.</param>
! /// <param name="sub">string to search for. Return 0 if this is null.</param>
! /// <returns>number of times <paramref>sub</paramref> occurs in string <paramref>s</paramref></returns>
! public static int CountOccurrencesOf(string s, string sub)
{
! if (s == null || sub == null || "".Equals(sub) || sub.Length > s.Length)
{
return 0;
--- 43,64 ----
public abstract class StringUtils
{
! /// <summary>
! /// Count the occurrences of the substring in
! /// <see cref="System.String"/> <paramref name="s"/>.
! /// </summary>
! /// <param name="s">
! /// The <see cref="System.String"/> to search in. Return 0 if this is null.
! /// </param>
! /// <param name="sub">
! /// The <see cref="System.String"/> to search for. Return 0 if this is null.
! /// </param>
! /// <returns>
! /// The number of times <paramref name="sub"/> occurs in string <paramref name="s"/>.
! /// </returns>
! public static int CountOccurrencesOf (string s, string sub)
{
! if (s == null
! || !StringUtils.HasText (sub)
! || sub.Length > s.Length)
{
return 0;
***************
*** 48,52 ****
return 1;
}
-
int count = 0, pos = 0, idx = 0;
while ((idx = s.IndexOf(sub, pos)) != -1)
--- 68,71 ----
***************
*** 58,120 ****
}
! /// <summary> Delete all occurrences of the given substring.</summary>
! /// <param name="inString">string to delete from</param>
! /// <param name="pattern">the pattern to delete all occurrences of</param>
! /// <returns>modified string</returns>
! public static string Delete(string inString, string pattern)
{
! if (inString == null || pattern == null || "".Equals(pattern))
{
return inString;
}
! return inString.Replace(pattern, "");
}
! /// <summary> Delete any character in a given string.</summary>
! /// <param name="inString">string to delete from</param>
! /// <param name="chars">characters to delete. E.g. az\n will delete "a"s, "z"s and new lines.</param>
! public static string DeleteAny(string inString, string chars)
{
! if (inString == null || chars == null || "".Equals(chars) || inString.IndexOfAny(chars.ToCharArray()) == -1)
{
return inString;
}
!
! StringBuilder sb = new StringBuilder();
! for (int i = 0; i < inString.Length; i++)
{
! char c = inString[i];
! if (chars.IndexOf(c) == -1)
{
! sb.Append(c);
}
}
! return sb.ToString();
}
! /// <summary> Tokenize the given String into a String array</summary>
/// <remarks>
! /// <p>If <paramref>s</paramref> is null, mehod returns empty string array.</p>
! /// <p>If <paramref>delimiters</paramref> is null or empty string,
! /// mehod returns a string array with one element: <paramref>s</paramref> itself</p>
/// </remarks>
! /// <param name="s">the string to tokenize</param>
! /// <param name="delimiters">the delimiter characters, assembled as String</param>
! /// <param name="trimTokens">trim the tokens via String.Trim</param>
! /// <param name="ignoreEmptyTokens">omit empty tokens from the result array</param>
! /// <returns> an array of the tokens</returns>
! public static string[] Split(string s, string delimiters, bool trimTokens, bool ignoreEmptyTokens)
{
if (s == null)
{
! return new string[0];
}
! if (delimiters == null || "".Equals(delimiters))
{
! return new string[] {s};
}
!
! string[] tmp = s.Split(delimiters.ToCharArray());
!
// short circuit if String.Split default behavior is ok
if (!trimTokens && !ignoreEmptyTokens)
--- 77,166 ----
}
! /// <summary>
! /// Delete all occurrences of the given substring.</summary>
! /// <param name="inString">
! /// The <see cref="System.String"/> to delete from.
! /// </param>
! /// <param name="pattern">
! /// The pattern to delete all occurrences of.
! /// </param>
! /// <returns>The modified <see cref="System.String"/>.</returns>
! public static string Delete (string inString, string pattern)
{
! if (inString == null
! || !StringUtils.HasText (pattern))
{
return inString;
}
! return inString.Replace (pattern, "");
}
! /// <summary>
! /// Delete any character in a given <see cref="System.String"/>.
! /// </summary>
! /// <param name="inString">
! /// The <see cref="System.String"/> to delete from.
! /// </param>
! /// <param name="chars">The characters to delete.</param>
! /// <example>
! /// az\n as the characters to delete will delete "a"s, "z"s and new lines.
! /// </example>
! public static string DeleteAny (string inString, string chars)
{
! if (inString == null
! || !StringUtils.HasText (chars)
! || inString.IndexOfAny (chars.ToCharArray ()) == -1)
{
return inString;
}
! StringBuilder sb = new StringBuilder ();
! for (int i = 0; i < inString.Length; ++i)
{
! char c = inString [i];
! if (chars.IndexOf (c) == -1)
{
! sb.Append (c);
}
}
! return sb.ToString ();
}
! /// <summary>
! /// Tokenize the given <see cref="System.String"/> into a
! /// <see cref="System.String"/> array.
! /// </summary>
/// <remarks>
! /// <p>
! /// If <paramref name="s"/> is null, mehod returns an empty
! /// <see cref="System.String"/> array.
! /// </p>
! /// <p>
! /// If <paramref name="delimiters"/> is null or empty <see cref="System.String"/>,
! /// mehod returns a <see cref="System.String"/> array with one
! /// element: <paramref name="s"/> itself.
! /// </p>
/// </remarks>
! /// <param name="s">The <see cref="System.String"/> to tokenize.</param>
! /// <param name="delimiters">
! /// The delimiter characters, assembled as a <see cref="System.String"/>.
! /// </param>
! /// <param name="trimTokens">
! /// Trim the tokens via <see cref="System.String.Trim"/>.
! /// </param>
! /// <param name="ignoreEmptyTokens">
! /// Omit empty tokens from the result array.</param>
! /// <returns>An array of the tokens.</returns>
! public static string [] Split (
! string s, string delimiters, bool trimTokens, bool ignoreEmptyTokens)
{
if (s == null)
{
! return new string [0];
}
! if (!StringUtils.HasText (delimiters))
{
! return new string [] {s};
}
! string[] tmp = s.Split (delimiters.ToCharArray ());
// short circuit if String.Split default behavior is ok
if (!trimTokens && !ignoreEmptyTokens)
***************
*** 124,169 ****
else
{
! ArrayList tokens = new ArrayList(tmp.Length);
! for (int i = 0; i < tmp.Length; i++)
{
! string token = (trimTokens ? tmp[i].Trim() : tmp[i]);
if (!(ignoreEmptyTokens && token.Length == 0))
{
! tokens.Add(token);
}
}
!
! return (string[]) tokens.ToArray(typeof(string));
}
}
/// <summary>
! /// Append the given String to the given String array, returning a new array
! /// consisting of the input array contents plus the given String.
/// </summary>
! /// <param name="arr">the array to append to</param>
! /// <param name="s">the string to append</param>
! /// <returns> the new array </returns>
! public static string[] AddStringToArray(string[] arr, string s)
{
! string[] newArr = new string[arr.Length + 1];
! Array.Copy(arr, 0, newArr, 0, arr.Length);
! newArr[arr.Length] = s;
return newArr;
}
! /// <summary> Convert a CSV list into an array of Strings.</summary>
/// <param name="s">CSV list
/// </param>
/// <returns> an array of Strings, or the empty array if s is null
/// </returns>
public static string[] CommaDelimitedListToStringArray(string s)
{
return DelimitedListToStringArray(s, ",");
}
!
/// <summary> Take a String which is a delimited list and convert it to a String array.</summary>
/// <param name="s">String
/// </param>
/// <param name="delim">delim (this will not be returned)
/// </param>
/// <returns> an array of the tokens in the list
/// </returns>
public static string[] DelimitedListToStringArray(string s, string delim)
{
if (s == null)
{
return new string[0];
}
if (delim == null)
{
return new string[]{s};
}
! return s.Split(delim[0]);
}
/// <summary>
! /// Convenience method to return a ICollection as a delimited (e.g. CSV)
! /// string. E.g. useful for ToString() implementations.
/// </summary>
! /// <param name="c">ICollection to display</param>
! /// <param name="delim">delimiter to use (probably a ",")</param>
! /// <returns>the delimited string representation</returns>
! public static string CollectionToDelimitedString(ICollection c, string delim)
{
if (c == null)
--- 170,228 ----
else
{
! ArrayList tokens = new ArrayList (tmp.Length);
! for (int i = 0; i < tmp.Length; ++i)
{
! string token = (trimTokens ? tmp [i].Trim () : tmp [i]);
if (!(ignoreEmptyTokens && token.Length == 0))
{
! tokens.Add (token);
}
}
! return (string []) tokens.ToArray (typeof (string));
}
}
/// <summary>
! /// Append the given <see cref="System.String"/> to the given
! /// <see cref="System.String"/> array, returning a new array
! /// consisting of the input array contents plus the given
! /// <see cref="System.String"/>.
/// </summary>
! /// <param name="arr">The array to append to.</param>
! /// <param name="s">
! /// The <see cref="System.String"/> to append (may be null).
! /// </param>
! /// <returns>The new array.</returns>
! public static string [] AddStringToArray (string [] arr, string s)
{
! if (s == null)
! {
! return arr;
! }
! string [] newArr = new string [arr.Length + 1];
! Array.Copy (arr, 0, newArr, 0, arr.Length);
! newArr [arr.Length] = s;
return newArr;
}
! /// <summary>
/// Convert a CSV list into an array of <see cref="System.String"/>s.
/// </summary>
/// <param name="s">A CSV list.</param>
/// <returns>
/// An array of <see cref="System.String"/>s, or the empty array
/// if <paramref name="s"/> is null.
/// </returns>
public static string [] CommaDelimitedListToStringArray (string s)
{
return DelimitedListToStringArray (s, ",");
}
!
/// <summary>
/// Take a <see cref="System.String"/> which is a delimited list
/// and convert it to a <see cref="System.String"/> array.
/// </summary>
/// <param name="s">
/// The <see cref="System.String"/> to be parsed.
/// </param>
/// <param name="delim">
/// The delimeter (this will not be returned).
/// </param>
/// <returns>
/// An array of the tokens in the list.
/// </returns>
public static string[] DelimitedListToStringArray (
string s, string delim)
{
if (s == null)
{
return new string [0];
}
if (delim == null)
{
return new string [] {s};
}
! return s.Split (delim [0]);
}
/// <summary>
! /// Convenience method to return an
! /// <see cref="System.Collections.ICollection"/> as a delimited
! /// (e.g. CSV) <see cref="System.String"/>.
/// </summary>
! /// <param name="c">
! /// The <see cref="System.Collections.ICollection"/> to parse.
! /// </param>
! /// <param name="delim">
! /// The delimiter to use (probably a ',').
! /// </param>
! /// <returns>The delimited string representation.</returns>
! public static string CollectionToDelimitedString (
! ICollection c, string delim)
{
if (c == null)
***************
*** 171,218 ****
return "null";
}
!
! StringBuilder sb = new StringBuilder();
int i = 0;
! foreach(object obj in c)
{
if (i++ > 0)
{
! sb.Append(delim);
}
! sb.Append(obj);
}
! return sb.ToString();
}
/// <summary>
! /// Convenience method to return a ICollection as a CSV String.
! /// E.g. useful for ToString() implementations.
/// </summary>
! /// <param name="c">ICollection to display</param>
! /// <returns>the delimited string representation</returns>
! public static string CollectionToCommaDelimitedString(ICollection c)
{
! return CollectionToDelimitedString(c, ",");
}
! /// <summary> Convenience method to return a String array as a CSV String.
! /// E.g. useful for toString() implementations.
/// </summary>
! /// <param name="arr">array to display. Elements may be of any type (toString
/// will be called on each element).
/// </param>
! public static string ArrayToCommaDelimitedString(System.Object[] arr)
{
! return ArrayToDelimitedString(arr, ",");
}
! /// <summary> Convenience method to return a String array as a delimited (e.g. CSV)
! /// String. E.g. useful for toString() implementations.
/// </summary>
! /// <param name="arr">array to display. Elements may be of any type (toString
/// will be called on each element).
/// </param>
! /// <param name="delim">delimiter to use (probably a ,)
/// </param>
! public static string ArrayToDelimitedString(System.Object[] arr, string delim)
{
if (arr == null)
--- 230,287 ----
return "null";
}
! StringBuilder sb = new StringBuilder ();
int i = 0;
! foreach (object obj in c)
{
if (i++ > 0)
{
! sb.Append (delim);
}
! sb.Append (obj);
}
! return sb.ToString ();
}
/// <summary>
! /// Convenience method to return an
! /// <see cref="System.Collections.ICollection"/> as a CSV
! /// <see cref="System.String"/>.
/// </summary>
! /// <param name="c">
! /// The <see cref="System.Collections.ICollection"/> to display.
! /// </param>
! /// <returns>The delimited string representation.</returns>
! public static string CollectionToCommaDelimitedString (
! ICollection c)
{
! return CollectionToDelimitedString (c, ",");
}
! /// <summary>
! /// Convenience method to return a <see cref="System.String"/>
! /// array as a CSV <see cref="System.String"/>.
/// </summary>
! /// <param name="arr">
! /// The array to parse. Elements may be of any type (ToString
/// will be called on each element).
/// </param>
! public static string ArrayToCommaDelimitedString (object [] arr)
{
! return ArrayToDelimitedString (arr, ",");
}
!
! /// <summary>
! /// Convenience method to return a <see cref="System.String"/>
! /// array as a delimited (e.g. CSV) <see cref="System.String"/>.
/// </summary>
! /// <param name="arr">
! /// The array to parse. Elements may be of any type (ToString
/// will be called on each element).
/// </param>
! /// <param name="delim">
! /// The delimiter to use (probably a ',').
/// </param>
! public static string ArrayToDelimitedString (
! object [] arr, string delim)
{
if (arr == null)
***************
*** 222,239 ****
else
{
! System.Text.StringBuilder sb = new System.Text.StringBuilder();
! for (int i = 0; i < arr.Length; i++)
! {
! if (i > 0)
! sb.Append(delim);
! sb.Append(arr[i]);
! }
! return sb.ToString();
}
}
/// <summary>Checks if a string has length.</summary>
! /// <param name="str">the string to check, may be null</param>
! /// <returns> <c>true</c> if the string has length and is not null</returns>
/// <example>
/// <code>
--- 291,303 ----
else
{
! return StringUtils.CollectionToDelimitedString (arr, delim);
}
}
/// <summary>Checks if a string has length.</summary>
! /// <param name="str">The string to check, may be null.</param>
! /// <returns>
! /// True if the string has length and is not null.
! /// </returns>
/// <example>
/// <code>
***************
*** 244,258 ****
/// </code>
/// </example>
! public static bool HasLength(string str)
{
return (str != null && str.Length > 0);
}
! /// <summary> Checks if a String has text. More specifically, returns <c>true</c>
! /// if the string not <c>null</c>, it's <c>length is > 0</c>, and
! /// it has at least one non-whitespace character.
/// </summary>
! /// <param name="str">the string to check, may be null</param>
! /// <returns> <c>true</c> if the String is not null, length > 0, and not whitespace only</returns>
/// <example>
/// <code>
--- 308,331 ----
/// </code>
/// </example>
! public static bool HasLength (string str)
{
return (str != null && str.Length > 0);
}
! /// <summary>
! /// Checks if a <see cref="System.String"/> has text.
/// </summary>
! /// <remarks>
! /// <p>
! /// More specifically, returns <c>true</c> if the string is not
! /// <c>null</c>, it's <c>length is > 0</c>, and it has at least
! /// one non-whitespace character.
! /// </p>
! /// </remarks>
! /// <param name="str">The string to check, may be null</param>
! /// <returns>
! /// True if the <paramref name="str"/> is not null, length > 0,
! /// and not whitespace only.
! /// </returns>
/// <example>
/// <code>
***************
*** 264,268 ****
/// </code>
/// </example>
! public static bool HasText(string str)
{
if (str == null)
--- 337,341 ----
/// </code>
/// </example>
! public static bool HasText (string str)
{
if (str == null)
***************
*** 272,294 ****
else
{
! return HasLength(str.Trim());
}
}
! /// <summary> Unqualifies a string qualified by a '.' dot character.
! /// For example, "this.name.is.qualified", returns "qualified".
/// </summary>
! /// <param name="qualifiedName">the qualified name</param>
! public static string Unqualify(string qualifiedName)
{
! return Unqualify(qualifiedName, '.');
}
! /// <summary> Unqualifies a string qualified by a separator character. For example,
! /// "this:name:is:qualified" returns "qualified" if using a ':' separator.
/// </summary>
! /// <param name="qualifiedName">the qualified name</param>
! /// <param name="separator">the separator character</param>
! public static string Unqualify(string qualifiedName, char separator)
{
if (qualifiedName == null)
--- 345,376 ----
else
{
! return HasLength (str.Trim ());
}
}
! /// <summary>
! /// Unqualifies a string qualified by a '.' dot character.
/// </summary>
! /// <param name="qualifiedName">The qualified name.</param>
! /// <returns>The unqualified string.</returns>
! /// <example>
! /// "this.name.is.qualified", returns "qualified".
! /// </example>
! public static string Unqualify (string qualifiedName)
{
! return Unqualify (qualifiedName, '.');
}
! /// <summary>
! /// Unqualifies a string qualified by a separator character.
/// </summary>
! /// <param name="qualifiedName">The qualified name.</param>
! /// <param name="separator">The separator character.</param>
! /// <example>
! /// "this:name:is:qualified" returns "qualified" if using a
! /// ':' separator.
! /// </example>
! public static string Unqualify (
! string qualifiedName, char separator)
{
if (qualifiedName == null)
***************
*** 296,309 ****
return null;
}
!
! return qualifiedName.Substring(qualifiedName.LastIndexOf(separator) + 1);
}
! /// <summary> Uncapitalizes a string, changing the first letter to
/// lower case. No other letters are changed.
/// </summary>
! /// <param name="str">the string to uncapitalize, may be null</param>
! /// <returns> the uncapitalized string, <c>null</c> if input string is null</returns>
! public static string Uncapitalize(string str)
{
int strLen;
--- 378,395 ----
return null;
}
! return qualifiedName.Substring (
! qualifiedName.LastIndexOf (separator) + 1);
}
! /// <summary>
! /// Uncapitalizes a string, changing the first letter to
/// lower case. No other letters are changed.
/// </summary>
! /// <param name="str">
! /// The string to uncapitalize, may be null.</param>
! /// <returns>
! /// The uncapitalized string, <c>null</c> if input string is null.
! /// </returns>
! public static string Uncapitalize (string str)
{
int strLen;
***************
*** 312,320 ****
return str;
}
!
! StringBuilder sb = new StringBuilder(strLen);
! sb.Append(Char.ToLower(str[0]));
! sb.Append(str.Substring(1));
! return sb.ToString();
}
}
--- 398,405 ----
return str;
}
! StringBuilder sb = new StringBuilder (strLen);
! sb.Append (Char.ToLower (str[0]));
! sb.Append (str.Substring (1));
! return sb.ToString ();
}
}
Index: MethodInvoker.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Util/MethodInvoker.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MethodInvoker.cs 23 Jul 2004 10:14:53 -0000 1.1
--- MethodInvoker.cs 26 Jul 2004 07:47:57 -0000 1.2
***************
*** 146,150 ****
string typeName = staticMethod.Substring(0, lastDotIndex);
string methodName = staticMethod.Substring(lastDotIndex + 1);
! TargetType = ObjectUtils.LocateType(typeName);
TargetMethod = methodName;
}
--- 146,150 ----
string typeName = staticMethod.Substring(0, lastDotIndex);
string methodName = staticMethod.Substring(lastDotIndex + 1);
! TargetType = ObjectUtils.ResolveType(typeName);
TargetMethod = methodName;
}
Index: TypeAliasResolver.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Util/TypeAliasResolver.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** TypeAliasResolver.cs 23 Jul 2004 10:14:53 -0000 1.1
--- TypeAliasResolver.cs 26 Jul 2004 07:47:57 -0000 1.2
***************
*** 45,48 ****
--- 45,49 ----
/// </p>
/// </remarks>
+ /// <version>$Id$</version>
public sealed class TypeAliasResolver {
***************
*** 182,186 ****
if (type != null)
{
! if (TypeAliasResolver.Aliases.ContainsKey (type))
{
return TypeAliasResolver.Aliases [type] as string;
--- 183,187 ----
if (type != null)
{
! if (TypeAliasResolver.Aliases.ContainsKey (type.ToLower ()))
{
return TypeAliasResolver.Aliases [type] as string;
|