Copyright© 2008-2026 Sitevision AB, all rights reserved.
@Requireable(value="InstanceCreatorUtil") public interface InstanceCreatorUtil
This interface contains 5 categories of methods:
getDefaultInstance(String)getArgumentInstance(String, TypedArgument)getArgumentsInstance(String, java.util.List)getEnumInstance(String, String)getObjectArgument(Object)getNullArgument(String)getCustomArgument(String, Object)getIntArgument(int)getArraysInstance()getCollectionsInstance()getMathInstance()getList()getMap()getLinkedMap()getSet()getListWrapper()getBooleanArray(int)getByteArray(int)getCharArray(int)getDoubleArray(int)getFloatArray(int) getIntArray(int)getLongArray(int)getObjectArray(int) getShortArray(int) getStringArray(int)
An instance of the Sitevision class implementing this interface can be obtained via
Utils.getInstanceCreatorUtil().
See Utils for how to obtain an instance of the Utils interface.
| Modifier and Type | Method and Description |
|---|---|
Object |
getArgumentInstance(String aQualifiedClassName,
TypedArgument aConstructorArgument)
Creates and returns an instance of a specified Java class using a single argument constructor.
|
Object |
getArgumentsInstance(String aQualifiedClassName,
List<TypedArgument> aConstructorArguments)
Creates and returns an instance of a specified Java class using a multiple argument constructor.
|
ArraysInstance |
getArraysInstance()
Gets a
java.util.Arrays wrapper instance. |
TypedArgument |
getBooleanArgument(boolean aBoolean)
Gets a typed argument for a
boolean primitive. |
boolean[] |
getBooleanArray(int aSize)
Creates a boolean array with a given size.
|
TypedArgument |
getByteArgument(byte aByte)
Gets a typed argument for a
byte primitive. |
byte[] |
getByteArray(int aSize)
Creates a byte array with a given size.
|
TypedArgument |
getCharArgument(char aChar)
Gets a typed argument for a
char primitive. |
char[] |
getCharArray(int aSize)
Creates a char array with a given size.
|
CollectionsInstance |
getCollectionsInstance()
Gets a
java.util.Collections wrapper instance. |
TypedArgument |
getCustomArgument(String aQualifiedClassName,
Object aValue)
Gets a typed argument that specifies a certain class/interface for an object.
|
Object |
getDefaultInstance(String aQualifiedClassName)
Creates and returns an instance of a specified Java class using the default constructor.
|
TypedArgument |
getDoubleArgument(double aDouble)
Gets a typed argument for a
double primitive. |
double[] |
getDoubleArray(int aSize)
Creates a double array with a given size.
|
TypedArgument |
getEnumArgument(String aQualifiedEnumClassName,
Object anEnum)
Gets a typed argument for an
Enum value for a specified enum class. |
Enum |
getEnumInstance(String aQualifiedEnumClassName,
String anEnumName)
Gets an enum instance for a specified enum class.
|
TypedArgument |
getFloatArgument(float aFloat)
Gets a typed argument for a
float primitive. |
float[] |
getFloatArray(int aSize)
Creates a float array with a given size.
|
TypedArgument |
getIntArgument(int anInt)
Gets a typed argument for a
int primitive. |
int[] |
getIntArray(int aSize)
Creates a int array with a given size.
|
Map |
getLinkedMap()
Convenience method to get a
LinkedHashMap instance. |
List |
getList()
Convenience method to get an
ArrayList instance. |
ListWrapper |
getListWrapper()
Gets a
ListWrapper instance. |
TypedArgument |
getLongArgument(long aLong)
Gets a typed argument for a
long primitive. |
long[] |
getLongArray(int aSize)
Creates a long array with a given size.
|
Map |
getMap()
Convenience method to get a
HashMap instance. |
MathInstance |
getMathInstance()
Gets a
java.lang.Math wrapper instance. |
TypedArgument |
getNullArgument(String aQualifiedClassName)
Gets a typed argument for a
null value for a specified class/interface. |
TypedArgument |
getObjectArgument(Object aValue)
Gets a typed argument for an
Object. |
Object[] |
getObjectArray(int aSize)
Creates a Object array with a given size.
|
Set |
getSet()
Convenience method to get a
HashSet instance. |
TypedArgument |
getShortArgument(short aShort)
Gets a typed argument for a
short primitive. |
short[] |
getShortArray(int aSize)
Creates a short array with a given size.
|
String[] |
getStringArray(int aSize)
Creates a String array with a given size.
|
Object getDefaultInstance(String aQualifiedClassName)
Example of how to create a Date instance in Velocity:
#set ($instanceCreatorUtil = $sitevisionUtils.instanceCreatorUtil)
#set ($now = $instanceCreatorUtil.getDefaultInstance('java.util.Date'))
Note! This method will not create any objects of any classes that has a fully qualified class name
that starts with senselogic.sitevision and resides outside the api package.
aQualifiedClassName - a fully qualified name of the class (i.e. including packages)null if an instance can not be createdgetArgumentInstance(String, TypedArgument),
getArgumentsInstance(String, java.util.List)Object getArgumentInstance(String aQualifiedClassName, TypedArgument aConstructorArgument)
Example of how to create an StringBuilder instance with the initial capacity 500 in Velocity
(i.e. invoke the StringBuilder(int) constructor):
#set ($instanceCreatorUtil = $sitevisionUtils.instanceCreatorUtil)
#set ($capacityIntArgument = $instanceCreatorUtil.getIntArgument(500))
#set ($buffer = $instanceCreatorUtil.getArgumentInstance('java.lang.StringBuilder', $capacityIntArgument))
Note! This method will not create any objects of any classes that has a fully qualified class name that starts with
senselogic.sitevision and resides outside the api package.
aQualifiedClassName - a fully qualified name of the class (i.e. including packages)aConstructorArgument - a typed argument that describes the value and the type of the constructor argumentnull if an instance can not be createdgetDefaultInstance(String),
getArgumentsInstance(String, java.util.List)Object getArgumentsInstance(String aQualifiedClassName, List<TypedArgument> aConstructorArguments)
Example of how to create an Locale instance with language "en" and country "US" in Velocity
(i.e. invoke the Locale(String,String) constructor):
#set ($instanceCreatorUtil = $sitevisionUtils.instanceCreatorUtil)
## Set up arguments
#set ($args = $instanceCreatorUtil.listWrapper) ## Use ListWrapper to prohibit output when invoking the "add" method...
$args.add($instanceCreatorUtil.getObjectArgument('en')) ## Add first argument (language)
$args.add($instanceCreatorUtil.getObjectArgument('US')) ## Add second argument (country)
## Create instance with arguments
#set ($americanLocale = $instanceCreatorUtil.getArgumentsInstance('java.util.Locale', $args.unwrap())) ## unwrap() to get actual List
Note! This method will not create any objects of any classes that has a fully qualified class name that
starts with senselogic.sitevision and resides outside the api package.
aQualifiedClassName - a fully qualified name of the class (i.e. including packages)aConstructorArguments - a list of typed arguments that describes the values and types of the constructor argumentsnull if an instance can not be createdgetDefaultInstance(String),
getArgumentInstance(String, TypedArgument)TypedArgument getByteArgument(byte aByte)
byte primitive.aByte - a byte valuebyte primitive.TypedArgument getShortArgument(short aShort)
short primitive.aShort - a short valueshort primitive.TypedArgument getIntArgument(int anInt)
int primitive.anInt - an int valueint primitive.TypedArgument getLongArgument(long aLong)
long primitive.aLong - a long valuelong primitive.TypedArgument getFloatArgument(float aFloat)
float primitive.aFloat - a float valuefloat primitive.TypedArgument getDoubleArgument(double aDouble)
double primitive.aDouble - a double valuedouble primitive.TypedArgument getCharArgument(char aChar)
char primitive.aChar - a char valuechar primitive.TypedArgument getBooleanArgument(boolean aBoolean)
boolean primitive.aBoolean - a boolean valueboolean primitive.TypedArgument getObjectArgument(Object aValue)
Object.
Note! This method can only be used if the class of your actual
instance exactly match the type required by the constructor you are trying to invoke! If types mismatch, you must use
getCustomArgument(String, Object) instead.
aValue - an object, not nullaValue object, null if aValue is null.
The class value of TypedArgument will be set via aValue.getClass().getNullArgument(String),
getCustomArgument(String, Object)TypedArgument getNullArgument(String aQualifiedClassName)
null value for a specified class/interface.
Note! This method must be used if you should pass a null value to a constructor!
aQualifiedClassName - a fully qualified name of the class (i.e. including packages)null if an aQualifiedClassName is invalid)TypedArgument getCustomArgument(String aQualifiedClassName, Object aValue)
Note! This method must be used if the class of your actual instance doesn't exactly match the type required by the constructor you are trying to invoke! Typical cases for when to use this method are:
Example of how to create a ArrayList instance in Velocity via the ArrayList(Collection) constructor:
#set ($myList = ...) ## $myList.class is NOT Collection, it's ArrayList, Vector or another Collection implementation...
#set ($instanceCreatorUtil = $sitevisionUtils.instanceCreatorUtil)
#set ($aCollectionsTypeArgument = $instanceCreatorUtil.getCustomArgument('java.util.Collection', $myList))
#set ($anArrayList = $instanceCreatorUtil.getArgumentInstance('java.util.ArrayList', $aCollectionsTypeArgument))
aQualifiedClassName - a fully qualified name of the class (i.e. including packages)aValue - an objectnull if an aQualifiedClassName is invalidgetObjectArgument(Object),
getNullArgument(String)TypedArgument getEnumArgument(String aQualifiedEnumClassName, Object anEnum)
Enum value for a specified enum class.aQualifiedEnumClassName - a fully qualified name of the enum class (i.e. including packages)anEnum - an Enum instance or a String with the name of the Enumnull if an aQualifiedEnumClassName
or anEnum is invalidgetEnumInstance(String, String)Enum getEnumInstance(String aQualifiedEnumClassName, String anEnumName)
Example of how to create the DocType.HTML5 instance
of DocType in Velocity:
#set ($instanceCreatorUtil = $sitevisionUtils.instanceCreatorUtil)
#set ($html5Enum = $instanceCreatorUtil.getEnumInstance('senselogic.sitevision.api.webresource.doctype.DocType', 'HTML5'))
Example of how to create the SECONDS instance of java.util.concurrent.TimeUnit in Velocity:
#set ($instanceCreatorUtil = $sitevisionUtils.instanceCreatorUtil)
#set ($secondsEnum = $instanceCreatorUtil.getEnumInstance('java.util.concurrent.TimeUnit', 'SECONDS'))
Example of how to create the IndexUtil.IndexType.USER_IDENTITY instance
of IndexUtil.IndexType (note that IndexType is an "inner"
enum of IndexUtil) in Velocity:
#set ($instanceCreatorUtil = $sitevisionUtils.instanceCreatorUtil)
## Note that '$' is used to separate outer class from inner enum
#set ($enumClassName = 'senselogic.sitevision.api.search.index.IndexUtil$IndexType')
#set ($userIdentityType = $instanceCreatorUtil.getEnumInstance($enumClassName, 'USER_IDENTITY'))
aQualifiedEnumClassName - a fully qualified name of the enum class (i.e. including packages)anEnumName - the name of the enum valuenull if an aQualifiedEnumClassName or anEnumName is invalidList getList()
ArrayList instance.java.util.ArrayList instancegetListWrapper()Set getSet()
HashSet instance.java.util.HashSet instanceMap getMap()
HashMap instance.java.util.HashMap instanceMap getLinkedMap()
LinkedHashMap instance.java.util.LinkedHashMap instanceListWrapper getListWrapper()
ListWrapper instance.
The java.util.List interface specifies that the add method should return a boolean.
This is a problem if your scripting language (e.g. Velocity) requires you to suppress the returned value so it won't end up
in the resulting output. A ListWrapper instance enables such suppressing.
ArraysInstance getArraysInstance()
java.util.Arrays wrapper instance.
The Arrays class contains static methods only and can't be instantiated. This is a problem if your
scripting language (e.g. Velocity) doesn't support static class access (i.e. need an instance/object to invoke methods).
An ArraysInstance instance enables Arrays method invocations.
java.util.ArraysCollectionsInstance getCollectionsInstance()
java.util.Collections wrapper instance.
The Collections class contains static methods only and can't be instantiated. This is a problem if your
scripting language (e.g. Velocity) doesn't support static class access (i.e. need an instance/object to invoke methods).
A CollectionsInstance instance enables Collections method invocations.
java.util.CollectionsMathInstance getMathInstance()
java.lang.Math wrapper instance.
The Math class contains static methods only and can't be instantiated. This is a problem if your
scripting language (e.g. Velocity) doesn't support static class access (i.e. need an instance/object to invoke methods).
A MathInstance instance enables Math method invocations.
java.lang.Mathboolean[] getBooleanArray(int aSize)
aSize - the array sizeArraysInstancebyte[] getByteArray(int aSize)
aSize - the array sizeArraysInstancechar[] getCharArray(int aSize)
aSize - the array sizeArraysInstancedouble[] getDoubleArray(int aSize)
aSize - the array sizeArraysInstancefloat[] getFloatArray(int aSize)
aSize - the array sizeArraysInstanceint[] getIntArray(int aSize)
aSize - the array sizeArraysInstancelong[] getLongArray(int aSize)
aSize - the array sizeArraysInstanceshort[] getShortArray(int aSize)
aSize - the array sizeArraysInstanceString[] getStringArray(int aSize)
aSize - the array sizeArraysInstanceObject[] getObjectArray(int aSize)
aSize - the array sizeArraysInstanceSitevision - Content Management Made Easy
Sitevision is an advanced Java enterprise portal product that implements Java Content Repository (JSR 283).
Copyright© 2008-2026 Sitevision AB, all rights reserved.