protected override object getValueBody(OgnlContext context, object source) // throws OgnlException { IDictionary answer; if (className == null) { try { answer = (IDictionary)DEFAULT_MAP_CLASS.GetConstructor(new Type[0]).Invoke(new object[0]); } catch (Exception ex) { /* This should never happen */ throw new OgnlException("Default IDictionary class '" + DEFAULT_MAP_CLASS.Name + "' instantiation error", ex); } } else { try { answer = (IDictionary)OgnlRuntime.classForName(context, className).GetConstructor(new Type[0]).Invoke(new object[0]); } catch (Exception ex) { throw new OgnlException("IDictionary implementor '" + className + "' not found", ex); } } for (int i = 0; i < jjtGetNumChildren(); ++i) { ASTKeyValue kv = (ASTKeyValue)children[i]; Node k = kv.getKey(), v = kv.getValue(); answer.Add(k.getValue(context, source), (v == null) ? null : v.getValue(context, source)); } return(answer); }
public override bool isNodeConstant(OgnlContext context) // throws OgnlException { bool result = false; Exception reason = null; try { Type c = OgnlRuntime.classForName(context, className); /* * Check for virtual static field "class"; this cannot interfere with * normal static fields because it is a reserved word. It is considered * constant. */ if (fieldName.Equals("class")) { result = true; } else { FieldInfo f = c.GetField(fieldName); if (f == null) { // try to load Property PropertyInfo p = c.GetProperty(fieldName); if (p == null) { throw new MissingFieldException("Field or Property " + fieldName + " of class " + className + " is not found."); } else if (!p.GetAccessors() [0].IsStatic) { throw new MissingFieldException("Property " + fieldName + " of class " + className + " is not static."); } // Property can't be constant. else { return(false); } } else if (!f.IsStatic) { throw new OgnlException("Field " + fieldName + " of class " + className + " is not static"); } result = f.IsLiteral; } } catch (TypeLoadException e) { reason = e; } catch (MissingFieldException e) { reason = e; } catch (SecurityException e) { reason = e; } if (reason != null) { throw new OgnlException("Could not get static field " + fieldName + " from class " + className, reason); } return(result); }
protected override object getValueBody(OgnlContext context, object source) // throws OgnlException { object result, root = context.getRoot(); int count = jjtGetNumChildren(); object[] args = OgnlRuntime.getObjectArrayPool().create(count); try { for (int i = 0; i < count; ++i) { args[i] = children[i].getValue(context, root); } if (isArray) { if (args.Length == 1) { try { Type componentClass = OgnlRuntime.classForName(context, className); IList sourceList = null; int size; if (args[0] is IList) { sourceList = (IList)args[0]; size = sourceList.Count; } else { size = (int)OgnlOps.longValue(args[0]); } result = Array.CreateInstance(componentClass, size); if (sourceList != null) { TypeConverter converter = context.getTypeConverter(); for (int i = 0, icount = sourceList.Count; i < icount; i++) { object o = sourceList [i]; if ((o == null) || componentClass.IsInstanceOfType(o)) { ((Array)result).SetValue(o, i); } else { ((Array)result).SetValue(converter.convertValue(context, null, null, null, o, componentClass), i); } } } } catch (TypeLoadException ex) { throw new OgnlException("array component class '" + className + "' not found", ex); } } else { throw new OgnlException("only expect array size or fixed initializer list"); } } else { result = OgnlRuntime.callConstructor(context, className, args); } return(result); } finally { OgnlRuntime.getObjectArrayPool().recycle(args); } }