private void cleanUpContext(Map<String, Object> context) { ReflectionContextState.clear(context); context.remove(XWorkConverter.CONVERSION_PROPERTY_FULLNAME); context.remove(REPORT_ERRORS_ON_NO_PROP); }
public static boolean isCreatingNullObjects(Map<String, Object> context) { //TODO return getBooleanProperty(ReflectionContextState.CREATE_NULL_OBJECTS, context); }
public static void updateCurrentPropertyPath(Map<String, Object> context, Object name) { String currentPath=getCurrentPropertyPath(context); if (name!=null) { if (currentPath!=null) { StringBuilder sb = new StringBuilder(currentPath); sb.append("."); sb.append(name.toString()); currentPath = sb.toString(); } else { currentPath = name.toString(); } context.put(CURRENT_PROPERTY_PATH, currentPath); } }
if (!ReflectionContextState.isGettingByKeyProperty(context) && !key.equals(KEY_PROPERTY_FOR_CREATION)) { return super.getProperty(context, target, key); } else { ReflectionContextState.setGettingByKeyProperty(context,false); Class lastBeanClass = ReflectionContextState.getLastBeanClassAccessed(context); String lastPropertyClass = ReflectionContextState.getLastBeanPropertyAccessed(context); ReflectionContextState.updateCurrentPropertyPath(context, key); return super.getProperty(context, target, key); if (ReflectionContextState.isCreatingNullObjects(context)) { Map collMap = getSetMap(context, c, keyProperty, collClass); if (key.toString().equals(KEY_PROPERTY_FOR_CREATION)) { Object value = collMap.get(realKey); if (value == null && ReflectionContextState.isCreatingNullObjects(context) && objectTypeDeterminer .shouldCreateIfNew(lastBeanClass,lastPropertyClass,c,keyProperty,false)) {
@Override public String doIntercept(ActionInvocation invocation) throws Exception { Object action = invocation.getAction(); if (!(action instanceof NoParameters)) { ActionContext ac = invocation.getInvocationContext(); final Map<String, Object> parameters = retrieveParameters(ac); if (LOG.isDebugEnabled()) { LOG.debug("Setting params " + getParameterLogMap(parameters)); } if (parameters != null) { Map<String, Object> contextMap = ac.getContextMap(); try { ReflectionContextState.setCreatingNullObjects(contextMap, true); ReflectionContextState.setDenyMethodExecution(contextMap, true); ReflectionContextState.setReportingConversionErrors(contextMap, true); ValueStack stack = ac.getValueStack(); setParameters(action, stack, parameters); } finally { ReflectionContextState.setCreatingNullObjects(contextMap, false); ReflectionContextState.setDenyMethodExecution(contextMap, false); ReflectionContextState.setReportingConversionErrors(contextMap, false); } } } return invocation.invoke(); }
private Map getSetMap(Map context, Collection collection, String property, Class valueClass) throws OgnlException { if (LOG.isDebugEnabled()) { LOG.debug("getting set Map"); } String path = ReflectionContextState.getCurrentPropertyPath(context); Map map = ReflectionContextState.getSetMap(context, path); if (map == null) { if (LOG.isDebugEnabled()) { LOG.debug("creating set Map"); } map = new HashMap(); map.put(null, new SurrugateList(collection)); for (Object currTest : collection) { Object currKey = _accessor.getProperty(context, currTest, property); if (currKey != null) { map.put(currKey, currTest); } } ReflectionContextState.setSetMap(context, map, path); } return map; }
throws OgnlException { if (ReflectionContextState.isGettingByKeyProperty(context) || name.equals(XWorkCollectionPropertyAccessor.KEY_PROPERTY_FOR_CREATION)) { return _sAcc.getProperty(context, target, name); return super.getProperty(context, target, name); ReflectionContextState.updateCurrentPropertyPath(context, name); && ReflectionContextState.isCreatingNullObjects(context) && objectTypeDeterminer.shouldCreateIfNew(lastClass,lastProperty,target,null,true)) {
public static void setReportingConversionErrors(Map<String, Object> context, boolean reportingErrors) { setBooleanValue(XWorkConverter.REPORT_CONVERSION_ERRORS, context, reportingErrors); }
public void testNullIsNotReturnedWhenCreateNullObjectsIsSpecified() { ValueStack vs = ActionContext.getContext().getValueStack(); vs.push(new MapHolder(Collections.emptyMap())); ReflectionContextState.setCreatingNullObjects(vs.getContext(), true); Object value = vs.findValue("map['key']"); assertNotNull(value); assertSame(Object.class, value.getClass()); }
boolean c = ReflectionContextState.isCreatingNullObjects(context);
ReflectionContextState.setCreatingNullObjects(context, true); ReflectionContextState.setDenyMethodExecution(context, true); ReflectionContextState.setReportingConversionErrors(context, true);
public static void setCreatingNullObjects(Map<String, Object> context, boolean creatingNullObjects) { setBooleanValue(ReflectionContextState.CREATE_NULL_OBJECTS, context, creatingNullObjects); }
public void testNullIsReturnedWhenCreateNullObjectsIsSpecifiedAsFalse() { ValueStack vs = ActionContext.getContext().getValueStack(); vs.push(new MapHolder(Collections.emptyMap())); ReflectionContextState.setCreatingNullObjects(vs.getContext(), false); assertNull(vs.findValue("map['key']")); }
Map<String, Object> contextMap = ac.getContextMap(); try { ReflectionContextState.setCreatingNullObjects(contextMap, true); ReflectionContextState.setReportingConversionErrors(contextMap, true); final ValueStack stack = ac.getValueStack(); ReflectionContextState.setCreatingNullObjects(context, true); ReflectionContextState.setDenyMethodExecution(context, true); ReflectionContextState.setReportingConversionErrors(context, true); addParametersToContext(ac, parameters); } finally { ReflectionContextState.setCreatingNullObjects(contextMap, false); ReflectionContextState.setReportingConversionErrors(contextMap, false);
public static boolean isDenyMethodExecution(Map<String, Object> context) { return getBooleanProperty(ReflectionContextState.DENY_METHOD_EXECUTION, context); }
public static void setDenyMethodExecution(Map<String, Object> context, boolean denyMethodExecution) { setBooleanValue(ReflectionContextState.DENY_METHOD_EXECUTION, context, denyMethodExecution); }
/** * @see com.opensymphony.xwork2.util.ValueStack#findValue(java.lang.String) */ public Object findValue(String expr, boolean throwExceptionOnFailure) { try { setupExceptionOnFailure(throwExceptionOnFailure); return tryFindValueWhenExpressionIsNotNull(expr); } catch (OgnlException e) { return handleOgnlException(expr, throwExceptionOnFailure, e); } catch (Exception e) { return handleOtherException(expr, throwExceptionOnFailure, e); } finally { ReflectionContextState.clear(context); } }
ReflectionContextState.setCreatingNullObjects(context, true); ReflectionContextState.setDenyMethodExecution(context, true); ReflectionContextState.setReportingConversionErrors(context, true);
public static boolean isReportingConversionErrors(Map<String, Object> context) { return getBooleanProperty(XWorkConverter.REPORT_CONVERSION_ERRORS, context); }
public static void setGettingByKeyProperty(Map<String, Object> context, boolean gettingByKeyProperty) { setBooleanValue(GETTING_BY_KEY_PROPERTY, context, gettingByKeyProperty); }