org.springframework.expression.spel.ast
Class ConstructorReference

java.lang.Object
  extended by org.springframework.expression.spel.ast.SpelNodeImpl
      extended by org.springframework.expression.spel.ast.ConstructorReference
All Implemented Interfaces:
SpelNode

public class ConstructorReference
extends SpelNodeImpl

Represents the invocation of a constructor. Either a constructor on a regular type or construction of an array. When an array is constructed, an initializer can be specified.

Examples:
new String('hello world')
new int[]{1,2,3,4}
new int[3] new int[3]{1,2,3}

Since:
3.0
Author:
Andy Clement, Juergen Hoeller

Field Summary
private  ConstructorExecutor cachedExecutor
          The cached executor that may be reused on subsequent evaluations.
private  SpelNodeImpl[] dimensions
           
private  boolean isArrayConstructor
           
 
Fields inherited from class org.springframework.expression.spel.ast.SpelNodeImpl
children, pos
 
Constructor Summary
ConstructorReference(int pos, SpelNodeImpl... arguments)
          Create a constructor reference.
ConstructorReference(int pos, SpelNodeImpl[] dimensions, SpelNodeImpl... arguments)
          Create a constructor reference.
 
Method Summary
private  TypedValue createArray(ExpressionState state)
          Create an array and return it.
private  TypedValue createNewInstance(ExpressionState state)
          Create a new ordinary object and return it.
private  ConstructorExecutor findExecutorForConstructor(java.lang.String typename, java.util.List<TypeDescriptor> argumentTypes, ExpressionState state)
          Go through the list of registered constructor resolvers and see if any can find a constructor that takes the specified set of arguments.
 TypedValue getValueInternal(ExpressionState state)
          Implements getValue() - delegating to the code for building an array or a simple type.
private  boolean hasInitializer()
           
private  void populateBooleanArray(ExpressionState state, java.lang.Object newArray, TypeConverter typeConverter, InlineList initializer)
           
private  void populateByteArray(ExpressionState state, java.lang.Object newArray, TypeConverter typeConverter, InlineList initializer)
           
private  void populateCharArray(ExpressionState state, java.lang.Object newArray, TypeConverter typeConverter, InlineList initializer)
           
private  void populateDoubleArray(ExpressionState state, java.lang.Object newArray, TypeConverter typeConverter, InlineList initializer)
           
private  void populateFloatArray(ExpressionState state, java.lang.Object newArray, TypeConverter typeConverter, InlineList initializer)
           
private  void populateIntArray(ExpressionState state, java.lang.Object newArray, TypeConverter typeConverter, InlineList initializer)
           
private  void populateLongArray(ExpressionState state, java.lang.Object newArray, TypeConverter typeConverter, InlineList initializer)
           
private  void populateReferenceTypeArray(ExpressionState state, java.lang.Object newArray, TypeConverter typeConverter, InlineList initializer, java.lang.Class<?> componentType)
           
private  void populateShortArray(ExpressionState state, java.lang.Object newArray, TypeConverter typeConverter, InlineList initializer)
           
 java.lang.String toStringAST()
           
 
Methods inherited from class org.springframework.expression.spel.ast.SpelNodeImpl
getChild, getChildCount, getEndPosition, getObjectClass, getPreviousChild, getStartPosition, getTypedValue, getValue, getValue, isWritable, nextChildIs, setValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isArrayConstructor

private boolean isArrayConstructor

dimensions

private SpelNodeImpl[] dimensions

cachedExecutor

private volatile ConstructorExecutor cachedExecutor
The cached executor that may be reused on subsequent evaluations.

Constructor Detail

ConstructorReference

public ConstructorReference(int pos,
                            SpelNodeImpl... arguments)
Create a constructor reference. The first argument is the type, the rest are the parameters to the constructor call


ConstructorReference

public ConstructorReference(int pos,
                            SpelNodeImpl[] dimensions,
                            SpelNodeImpl... arguments)
Create a constructor reference. The first argument is the type, the rest are the parameters to the constructor call

Method Detail

getValueInternal

public TypedValue getValueInternal(ExpressionState state)
                            throws EvaluationException
Implements getValue() - delegating to the code for building an array or a simple type.

Specified by:
getValueInternal in class SpelNodeImpl
Throws:
EvaluationException

createNewInstance

private TypedValue createNewInstance(ExpressionState state)
                              throws EvaluationException
Create a new ordinary object and return it.

Parameters:
state - the expression state within which this expression is being evaluated
Returns:
the new object
Throws:
EvaluationException - if there is a problem creating the object

findExecutorForConstructor

private ConstructorExecutor findExecutorForConstructor(java.lang.String typename,
                                                       java.util.List<TypeDescriptor> argumentTypes,
                                                       ExpressionState state)
                                                throws SpelEvaluationException
Go through the list of registered constructor resolvers and see if any can find a constructor that takes the specified set of arguments.

Parameters:
typename - the type trying to be constructed
argumentTypes - the types of the arguments supplied that the constructor must take
state - the current state of the expression
Returns:
a reusable ConstructorExecutor that can be invoked to run the constructor or null
Throws:
SpelEvaluationException - if there is a problem locating the constructor

toStringAST

public java.lang.String toStringAST()
Specified by:
toStringAST in interface SpelNode
Specified by:
toStringAST in class SpelNodeImpl
Returns:
the string form of this AST node

createArray

private TypedValue createArray(ExpressionState state)
                        throws EvaluationException
Create an array and return it.

Parameters:
state - the expression state within which this expression is being evaluated
Returns:
the new array
Throws:
EvaluationException - if there is a problem creating the array

populateReferenceTypeArray

private void populateReferenceTypeArray(ExpressionState state,
                                        java.lang.Object newArray,
                                        TypeConverter typeConverter,
                                        InlineList initializer,
                                        java.lang.Class<?> componentType)

populateByteArray

private void populateByteArray(ExpressionState state,
                               java.lang.Object newArray,
                               TypeConverter typeConverter,
                               InlineList initializer)

populateFloatArray

private void populateFloatArray(ExpressionState state,
                                java.lang.Object newArray,
                                TypeConverter typeConverter,
                                InlineList initializer)

populateDoubleArray

private void populateDoubleArray(ExpressionState state,
                                 java.lang.Object newArray,
                                 TypeConverter typeConverter,
                                 InlineList initializer)

populateShortArray

private void populateShortArray(ExpressionState state,
                                java.lang.Object newArray,
                                TypeConverter typeConverter,
                                InlineList initializer)

populateLongArray

private void populateLongArray(ExpressionState state,
                               java.lang.Object newArray,
                               TypeConverter typeConverter,
                               InlineList initializer)

populateCharArray

private void populateCharArray(ExpressionState state,
                               java.lang.Object newArray,
                               TypeConverter typeConverter,
                               InlineList initializer)

populateBooleanArray

private void populateBooleanArray(ExpressionState state,
                                  java.lang.Object newArray,
                                  TypeConverter typeConverter,
                                  InlineList initializer)

populateIntArray

private void populateIntArray(ExpressionState state,
                              java.lang.Object newArray,
                              TypeConverter typeConverter,
                              InlineList initializer)

hasInitializer

private boolean hasInitializer()