com.opensymphony.xwork2.conversion.impl.InstantiatingNullHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of xwork Show documentation
Show all versions of xwork Show documentation
XWork is an command-pattern framework that is used to power WebWork
as well as other applications. XWork provides an Inversion of Control
container, a powerful expression language, data type conversion,
validation, and pluggable configuration.
The newest version!
/*
* Copyright (c) 2002-2006 by OpenSymphony
* All rights reserved.
*/
package com.opensymphony.xwork2.conversion.impl;
import com.opensymphony.xwork2.ObjectFactory;
import com.opensymphony.xwork2.conversion.NullHandler;
import com.opensymphony.xwork2.conversion.ObjectTypeDeterminer;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import com.opensymphony.xwork2.util.reflection.ReflectionContextState;
import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
import java.beans.PropertyDescriptor;
import java.util.*;
/**
*
*
* Provided that the key {@link ReflectionContextState#CREATE_NULL_OBJECTS} is in the action context with a value of true (this key is set
* only during the execution of the {@link com.opensymphony.xwork2.interceptor.ParametersInterceptor}), OGNL expressions
* that have caused a NullPointerException will be temporarily stopped for evaluation while the system automatically
* tries to solve the null references by automatically creating the object.
*
* The following rules are used when handling null references:
*
*
*
* - If the property is declared exactly as a {@link Collection} or {@link List}, then an ArrayList shall be
* returned and assigned to the null references.
*
* - If the property is declared as a {@link Map}, then a HashMap will be returned and assigned to the null
* references.
*
* - If the null property is a simple bean with a no-arg constructor, it will simply be created using the {@link
* ObjectFactory#buildBean(java.lang.Class, java.util.Map)} method.
*
*
*
*
*
*
*
* For example, if a form element has a text field named person.name and the expression person evaluates
* to null, then this class will be invoked. Because the person expression evaluates to a Person class, a
* new Person is created and assigned to the null reference. Finally, the name is set on that object and the overall
* effect is that the system automatically created a Person object for you, set it by calling setUsers() and then
* finally called getUsers().setName() as you would typically expect.
*
*