[Adapdev-commits] Adapdev/src/Adapdev.NVelocity/Tool DataInfo.cs,1.2,1.3 IToolInfo.cs,1.2,1.3 ToolLo
Status: Beta
Brought to you by:
intesar66
From: Sean M. <int...@us...> - 2005-11-16 05:45:33
|
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.NVelocity/Tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22005/src/Adapdev.NVelocity/Tool Added Files: DataInfo.cs IToolInfo.cs ToolLoader.cs Log Message: --- NEW FILE: ToolLoader.cs --- namespace NVelocity.Tool { using System; /// <summary> /// <p>A view tool that allows template designers to load /// an arbitrary object into the context. Any object /// with a public constructor without parameters can be used /// as a view tool.</p> /// <p>THIS CLASS IS HERE AS A PROOF OF CONCEPT ONLY. IT IS NOT /// INTENDED FOR USE IN PRODUCTION ENVIRONMENTS. USE AT YOUR OWN RISK.</p> /// </summary> /// <author><a href="mailto:si...@te...">Gabe Sidler</a></author> /// <author><a href="mailto:ge...@ap...">Geir Magnusson Jr.</a></author> public class ToolLoader { public ToolLoader() { } /// <summary> /// Creates and returns an object of the specified classname. /// The object must have a valid default constructor. /// </summary> /// <param name="clazz">the fully qualified class name of the object</param> /// <returns>an instance of the specified class or null if the class /// could not be instantiated.</returns> public virtual Object Load(String clazz) { try { Type type = Type.GetType(clazz); Object o = Activator.CreateInstance(type); return o; } catch (Exception) { return null; } } } } --- NEW FILE: IToolInfo.cs --- namespace NVelocity.Tool { using System; /// <summary> Interface to simplify and abstract tool handling. /// * /// Implementations of this class should hold both the context /// key for the tool and sufficient information to return /// an instance of the tool. /// * /// </summary> /// <author> <a href="mailto:na...@es...">Nathan Bubna</a> /// * /// </author> /// <version> $Id: IToolInfo.cs,v 1.3 2005/11/16 05:45:24 intesar66 Exp $ /// /// </version> public interface IToolInfo { String Key { get; } String Classname { get; } /// <returns>the context key for the tool /// /// </returns> /// <returns>the fully qualified classname for the tool /// /// </returns> /// <summary> Returns an instance of the tool. /// * /// Instances returned may be new on each call, pooled, or /// the be same instance every time depending on the /// implementation. The object passed to this method may /// be used to initialize or create the tool that is returned, /// or it may be null if no such data is required. /// * /// </summary> /// <param name="initData">an object that may be used to initialize the instance /// </param> /// <returns>an instance of the tool /// /// </returns> Object getInstance(Object initData); } } --- NEW FILE: DataInfo.cs --- namespace NVelocity.Tool { using System; /// <summary> ToolInfo implementation to handle "primitive" data types. /// It currently supports String, Number, and Boolean data. /// * /// </summary> /// <author> <a href="mailto:na...@es...">Nathan Bubna</a> /// * /// </author> /// <version> $Id: DataInfo.cs,v 1.3 2005/11/16 05:45:24 intesar66 Exp $ /// /// </version> public class DataInfo : IToolInfo { public virtual String Key { get { return key; } } public virtual String Classname { get { return data.GetType().FullName; } } public static String TYPE_STRING = "string"; public static String TYPE_NUMBER = "number"; public static String TYPE_BOOLEAN = "boolean"; private String key; private Object data; /// <summary> Parses the value string into a recognized type. If /// the type specified is not supported, the data will /// be held and returned as a string. /// * /// </summary> /// <param name="key">the context key for the data /// </param> /// <param name="type">the data type /// </param> /// <param name="value">the data /// /// </param> public DataInfo(String key, String type, String value_Renamed) { this.key = key; if (type.ToUpper().Equals(TYPE_BOOLEAN.ToUpper())) { this.data = Boolean.Parse(value_Renamed); } else if (type.ToUpper().Equals(TYPE_NUMBER.ToUpper())) { if (value_Renamed.IndexOf((Char) '.') >= 0) { //UPGRADE_TODO: Format of parameters of constructor 'java.lang.Double.Double' are different in the equivalent in .NET. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1092"' this.data = Double.Parse(value_Renamed); } else { this.data = Int32.Parse(value_Renamed); } } else { this.data = value_Renamed; } } /// <summary> Returns the data. Always returns the same /// object since the data is a constant. Initialization /// data is ignored. /// </summary> public virtual Object getInstance(Object initData) { return data; } } } |