/// <summary> {@inheritDoc} /// /// </summary> /// <seealso cref="org.apache.velocity.util.introspection.Uberspect.getPropertySet(java.lang.Object, java.lang.String,"> /// java.lang.Object, org.apache.velocity.util.introspection.Info) /// </seealso> //@Override public override IVelPropertySet GetPropertySet(object obj, string identifier, object arg, Info i) { IVelPropertySet setter = leftUberspect.GetPropertySet(obj, identifier, arg, i); return(setter != null ? setter : rightUberspect.GetPropertySet(obj, identifier, arg, i)); }
/// <summary> Sets the value of a complex reference (something like $foo.bar) /// Currently used by ASTSetReference() /// /// </summary> /// <seealso cref="ASTSetDirective"> /// /// </seealso> /// <param name="context">context object containing this reference /// </param> /// <param name="value">Object to set as value /// </param> /// <returns> true if successful, false otherwise /// </returns> /// <throws> MethodInvocationException </throws> public virtual bool SetValue(IInternalContextAdapter context, object value) { if (GetNumChildren() == 0) { context.Put(rootString, value); return(true); } /* * The rootOfIntrospection is the object we will * retrieve from the Context. This is the base * object we will apply reflection to. */ object result = GetVariableValue(context, rootString); if (result == null) { string msg = "reference set is not a valid reference at " + Log.FormatFileString(uberInfo); log.Error(msg); return(false); } /* * How many child nodes do we have? */ for (int i = 0; i < numChildren - 1; i++) { result = GetChild(i).Execute(result, context); if (result == null) { if (strictRef) { string name = GetChild(i + 1).FirstToken.Image; throw new MethodInvocationException("Attempted to access '" + name + "' on a null value", null, name, uberInfo.TemplateName, GetChild(i + 1).Line, GetChild(i + 1).Column); } string msg = "reference set is not a valid reference at " + Log.FormatFileString(uberInfo); log.Error(msg); return(false); } } /* * We support two ways of setting the value in a #set($ref.foo = $value ) : * 1) ref.setFoo( value ) * 2) ref,put("foo", value ) to parallel the get() map introspection */ try { IVelPropertySet vs = rsvc.Uberspect.GetPropertySet(result, identifier, value, uberInfo); if (vs == null) { if (strictRef) { throw new MethodInvocationException("Object '" + result.GetType().FullName + "' does not contain property '" + identifier + "'", null, identifier, uberInfo.TemplateName, uberInfo.Line, uberInfo.Column); } else { return(false); } } vs.Invoke(result, value); } catch (TargetInvocationException ite) { /* * this is possible */ throw new MethodInvocationException("ASTReference : Invocation of method '" + identifier + "' in " + result.GetType() + " threw exception " + ite.GetBaseException().ToString(), ite.GetBaseException(), identifier, TemplateName, this.Line, this.Column); } /** * pass through application level runtime exceptions */ catch (System.SystemException e) { throw e; } catch (System.Exception e) { /* * maybe a security exception? */ string msg = "ASTReference setValue() : exception : " + e + " template at " + Log.FormatFileString(uberInfo); log.Error(msg, e); throw new VelocityException(msg, e); } return(true); }