Little class to carry in info such as template name, line and column for information error reporting from the uberspector implementations *
Ejemplo n.º 1
0
		/// <summary>
		/// Property  getter
		/// </summary>
		public IVelPropertyGet GetPropertyGet(Object obj, String identifier, Info i)
		{
			AbstractExecutor executor;

			Type claz = obj.GetType();

			/*
			*  first try for a getFoo() type of property
			*  (also getfoo() )
			*/

			executor = new PropertyExecutor(rlog, introspector, claz, identifier);

			/*
			*  if that didn't work, look for get("foo")
			*/

			if (!executor.IsAlive)
			{
				executor = new GetExecutor(rlog, introspector, claz, identifier);
			}

			/*
			*  finally, look for boolean isFoo()
			*/

			if (!executor.IsAlive)
			{
				executor = new BooleanPropertyExecutor(rlog, introspector, claz, identifier);
			}

			return new VelGetterImpl(executor);
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Property getter.
		/// </summary>
		public IVelPropertyGet GetPropertyGet(Object obj, String identifier, Info i)
		{
			AbstractExecutor executor;

			Type type = obj.GetType();

			// First try for a getFoo() type of property (also getfoo())
			executor = new PropertyExecutor(runtimeLogger, introspector, type, identifier);

			// If that didn't work, look for get("foo")
			if (!executor.IsAlive)
			{
				executor = new GetExecutor(runtimeLogger, introspector, type, identifier);
			}

			// If that didn't work, look for boolean isFoo()
			if (!executor.IsAlive)
			{
				executor = new BooleanPropertyExecutor(runtimeLogger, introspector, type, identifier);
			}

			// If that didn't work, look for an enumeration
			if (!executor.IsAlive && (obj is Type) && (obj as Type).IsEnum)
			{
				executor = new EnumValueExecutor(runtimeLogger, introspector, obj as Type, identifier);
			}

			return new VelGetterImpl(executor);
		}
Ejemplo n.º 3
0
		/// <summary>
		/// simple init - don't do anything that is context specific.
		/// just get what we need from the AST, which is static.
		/// </summary>
		public override Object Init(IInternalContextAdapter context, Object data)
		{
			base.Init(context, data);

			identifier = FirstToken.Image;

			uberInfo = new Info(context.CurrentTemplateName, Line, Column);
			return data;
		}
Ejemplo n.º 4
0
		/// <summary>
		/// Method
		/// </summary>
		public IVelMethod GetMethod(Object obj, String methodName, Object[] args, Info i)
		{
			if (obj == null)
				return null;

			MethodInfo m = introspector.GetMethod(obj.GetType(), methodName, args);

			return (m != null) ? new VelMethodImpl(m) : null;
		}
Ejemplo n.º 5
0
		/// <summary> Property setter
		/// </summary>
		public IVelPropertySet GetPropertySet(Object obj, String identifier, Object arg, Info i)
		{
			Type claz = obj.GetType();

			IVelMethod vm = null;

			try
			{
				/*
				*  first, we introspect for the set<identifier> setter method
				*/

				Object[] parameters = new Object[] {arg};

				try
				{
					vm = GetMethod(obj, "set" + identifier, parameters, i);

					if (vm == null)
					{
						throw new MethodAccessException();
					}
				}
				catch(MethodAccessException)
				{
					StringBuilder sb = new StringBuilder("set");
					sb.Append(identifier);

					if (Char.IsLower(sb[3]))
					{
						sb[3] = Char.ToUpper(sb[3]);
					}
					else
					{
						sb[3] = Char.ToLower(sb[3]);
					}

					vm = GetMethod(obj, sb.ToString(), parameters, i);

					if (vm == null)
						throw;
				}
			}
			catch(MethodAccessException)
			{
				// right now, we only support the IDictionary interface
				if (typeof(IDictionary).IsAssignableFrom(claz))
				{
					Object[] parameters = new Object[] {new Object(), new Object()};

					vm = GetMethod(obj, "Add", parameters, i);

					if (vm != null)
						return new VelSetterImpl(vm, identifier);
				}
			}

			return (vm != null) ? new VelSetterImpl(vm) : null;
		}
Ejemplo n.º 6
0
        /// <summary>
        /// Property setter.
        /// </summary>
        public IVelPropertySet GetPropertySet(Object obj, String identifier, Object arg, Info i)
        {
            Type type = obj.GetType();

            IVelMethod method = null;

            try
            {
                /*
                 *  first, we introspect for the set<identifier> setter method
                 */

                Object[] parameters = new Object[] { arg };

                try
                {
                    method = GetMethod(obj, string.Format("set{0}", identifier), parameters, i);

                    if (method == null)
                    {
                        throw new MethodAccessException();
                    }
                }
                catch (MethodAccessException)
                {
                    StringBuilder sb = new StringBuilder("set");
                    sb.Append(identifier);

                    if (Char.IsLower(sb[3]))
                    {
                        sb[3] = Char.ToUpper(sb[3]);
                    }
                    else
                    {
                        sb[3] = Char.ToLower(sb[3]);
                    }

                    method = GetMethod(obj, sb.ToString(), parameters, i);

                    if (method == null)
                    {
                        throw;
                    }
                }
            }
            catch (MethodAccessException)
            {
                // right now, we only support the IDictionary interface
                if (typeof(IDictionary).IsAssignableFrom(type))
                {
                    Object[] parameters = new Object[] { new Object(), new Object() };

                    method = GetMethod(obj, "Add", parameters, i);

                    if (method != null)
                    {
                        return(new VelSetterImpl(method, identifier));
                    }
                }
            }

            return((method != null) ? new VelSetterImpl(method) : null);
        }
        /// <summary> Property setter
        /// </summary>
        public VelPropertySet getPropertySet(Object obj, String identifier, Object arg, Info i)
        {
            Type claz = obj.GetType();

            VelPropertySet vs = null;
            VelMethod      vm = null;

            try
            {
                /*
                 *  first, we introspect for the set<identifier> setter method
                 */

                Object[] params_Renamed = new Object[] { arg };

                try
                {
                    vm = getMethod(obj, "set" + identifier, params_Renamed, i);

                    if (vm == null)
                    {
                        throw new MethodAccessException();
                    }
                }
                catch (MethodAccessException nsme2)
                {
                    StringBuilder sb = new StringBuilder("set");
                    sb.Append(identifier);

                    if (Char.IsLower(sb[3]))
                    {
                        sb[3] = Char.ToUpper(sb[3]);
                    }
                    else
                    {
                        sb[3] = Char.ToLower(sb[3]);
                    }

                    vm = getMethod(obj, sb.ToString(), params_Renamed, i);

                    if (vm == null)
                    {
                        throw new MethodAccessException();
                    }
                }
            }
            catch (MethodAccessException nsme)
            {
                /*
                 *  right now, we only support the Map interface
                 */

                if (typeof(IDictionary).IsAssignableFrom(claz))
                {
                    Object[] params_Renamed = new Object[] { new Object(), new Object() };

                    vm = getMethod(obj, "put", params_Renamed, i);

                    if (vm != null)
                    {
                        return(new VelSetterImpl(this, vm, identifier));
                    }
                }
            }

            return((vm != null) ? new VelSetterImpl(this, vm) : null);
        }