/** * This file is auto generated from JavaDoc. Do not modify it manually. */ import type { String } from "../../types/java/lang/String"; import type { Object } from "../../types/java/lang/Object"; import type { TypedArgument } from "../../types/senselogic/sitevision/api/script/factory/TypedArgument"; import type { List } from "../../types/java/util/List"; import type { Enum } from "../../types/java/lang/Enum"; import type { Set } from "../../types/java/util/Set"; import type { Map } from "../../types/java/util/Map"; import type { ListWrapper } from "../ListWrapper"; import type { ArraysInstance } from "../ArraysInstance"; import type { CollectionsInstance } from "../CollectionsInstance"; import type { MathInstance } from "../MathInstance"; /** * Instance creation utility that can be used in limited scripting languages (such as Velocity). * *

* This interface contains 5 categories of methods: *

*
    *
  1. * Methods for creating an object instance via a constructor (or an Enum instance via an enum name), e.g. see:
    * {@link InstanceCreatorUtil#getDefaultInstance(String)}
    * {@link InstanceCreatorUtil#getArgumentInstance(String, TypedArgument)}
    * {@link InstanceCreatorUtil#getArgumentsInstance(String, java.util.List)}
    * {@link InstanceCreatorUtil#getEnumInstance(String, String)}
    *   *
  2. *
  3. * Methods needed to properly describe constructor arguments for the first category above, e.g see:
    * {@link InstanceCreatorUtil#getObjectArgument(Object)}
    * {@link InstanceCreatorUtil#getNullArgument(String)}
    * {@link InstanceCreatorUtil#getCustomArgument(String, Object)}
    * {@link InstanceCreatorUtil#getIntArgument(int)}
    * ...
    *   *
  4. *
  5. * Methods that creates wrappers for certain non-instantiable classes (enables instance-level invocation on their static methods), e.g. see:
    * {@link InstanceCreatorUtil#getArraysInstance()}
    * {@link InstanceCreatorUtil#getCollectionsInstance()}
    * {@link InstanceCreatorUtil#getMathInstance()}
    *   *
  6. *
  7. * Convenience methods for creating common object instances or helpers, e.g. see:
    * {@link InstanceCreatorUtil#getList()}
    * {@link InstanceCreatorUtil#getMap()}
    * {@link InstanceCreatorUtil#getLinkedMap()}
    * {@link InstanceCreatorUtil#getSet()}
    * {@link InstanceCreatorUtil#getListWrapper()}
    *   *
  8. *
  9. * Methods to create Java arrays, e.g see:
    * {@link InstanceCreatorUtil#getBooleanArray(int)}
    * {@link InstanceCreatorUtil#getByteArray(int)}
    * {@link InstanceCreatorUtil#getCharArray(int)}
    * {@link InstanceCreatorUtil#getDoubleArray(int)}
    * {@link InstanceCreatorUtil#getFloatArray(int)}
    * {@link InstanceCreatorUtil#getIntArray(int)}
    * {@link InstanceCreatorUtil#getLongArray(int)}
    * {@link InstanceCreatorUtil#getObjectArray(int)}
    * {@link InstanceCreatorUtil#getShortArray(int)}
    * {@link InstanceCreatorUtil#getStringArray(int)}
    *
  10. *
* *

* An instance of the Sitevision class implementing this interface can be obtained via * {@link senselogic.sitevision.api.Utils#getInstanceCreatorUtil()}. * See {@link senselogic.sitevision.api.Utils} for how to obtain an instance of the Utils interface. *

* @author Magnus Lövgren * @since Sitevision 3.1 */ export interface InstanceCreatorUtil { /** * Creates and returns an instance of a specified Java class using the default constructor. * *

* 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. *

* @param aQualifiedClassName a fully qualified name of the class (i.e. including packages) * @return an instance of the class, or null if an instance can not be created * @see InstanceCreatorUtil#getArgumentInstance(String, TypedArgument) * @see InstanceCreatorUtil#getArgumentsInstance(String, java.util.List) */ getDefaultInstance(aQualifiedClassName: String | string): unknown; /** * Creates and returns an instance of a specified Java class using a single argument constructor. * *

* 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. *

* @param aQualifiedClassName a fully qualified name of the class (i.e. including packages) * @param aConstructorArgument a typed argument that describes the value and the type of the constructor argument * @return an instance of the class, or null if an instance can not be created * @see InstanceCreatorUtil#getDefaultInstance(String) * @see InstanceCreatorUtil#getArgumentsInstance(String, java.util.List) */ getArgumentInstance( aQualifiedClassName: String | string, aConstructorArgument: TypedArgument ): unknown; /** * Creates and returns an instance of a specified Java class using a multiple argument constructor. * *

* 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. *

* @param aQualifiedClassName a fully qualified name of the class (i.e. including packages) * @param aConstructorArguments a list of typed arguments that describes the values and types of the constructor arguments * @return an instance of the class, or null if an instance can not be created * @see InstanceCreatorUtil#getDefaultInstance(String) * @see InstanceCreatorUtil#getArgumentInstance(String, TypedArgument) */ getArgumentsInstance( aQualifiedClassName: String | string, aConstructorArguments: List | unknown[] ): unknown; /** * Gets a typed argument for a byte primitive. * @param aByte a byte value * @return a typed argument for the byte primitive. */ getByteArgument(aByte: unknown): TypedArgument; /** * Gets a typed argument for a short primitive. * @param aShort a short value * @return a typed argument for the short primitive. */ getShortArgument(aShort: number): TypedArgument; /** * Gets a typed argument for a int primitive. * @param anInt an int value * @return a typed argument for the int primitive. */ getIntArgument(anInt: number): TypedArgument; /** * Gets a typed argument for a long primitive. * @param aLong a long value * @return a typed argument for the long primitive. */ getLongArgument(aLong: number): TypedArgument; /** * Gets a typed argument for a float primitive. * @param aFloat a float value * @return a typed argument for the float primitive. */ getFloatArgument(aFloat: number): TypedArgument; /** * Gets a typed argument for a double primitive. * @param aDouble a double value * @return a typed argument for the double primitive. */ getDoubleArgument(aDouble: number): TypedArgument; /** * Gets a typed argument for a char primitive. * @param aChar a char value * @return a typed argument for the char primitive. */ getCharArgument(aChar: string): TypedArgument; /** * Gets a typed argument for a boolean primitive. * @param aBoolean a boolean value * @return a typed argument for the boolean primitive. */ getBooleanArgument(aBoolean: boolean): TypedArgument; /** * Gets a typed argument for an 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 * {@link #getCustomArgument(String, Object)} instead. *

* @param aValue an object, not null * @return a typed argument for aValue object, null if aValue is null. The class value of TypedArgument will be set via aValue.getClass(). * @see InstanceCreatorUtil#getNullArgument(String) * @see InstanceCreatorUtil#getCustomArgument(String, Object) */ getObjectArgument(aValue: unknown): TypedArgument; /** * Gets a typed argument for a null value for a specified class/interface. * *

* Note! This method must be used if you should pass a null value to a constructor! *

* @param aQualifiedClassName a fully qualified name of the class (i.e. including packages) * @return a null argument that uses a specified class/interface as type, or null if an aQualifiedClassName is invalid) */ getNullArgument(aQualifiedClassName: String | string): TypedArgument; /** * Gets a typed argument that specifies a certain class/interface for an object. * *

* 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))
   *  
* @param aQualifiedClassName a fully qualified name of the class (i.e. including packages) * @param aValue an object * @return a typed argument that uses a specified class/interface as type, or null if an aQualifiedClassName is invalid * @see InstanceCreatorUtil#getObjectArgument(Object) * @see InstanceCreatorUtil#getNullArgument(String) */ getCustomArgument( aQualifiedClassName: String | string, aValue: unknown ): TypedArgument; /** * Gets a typed argument for an Enum value for a specified enum class. * @param aQualifiedEnumClassName a fully qualified name of the enum class (i.e. including packages) * @param anEnum an Enum instance or a String with the name of the Enum * @return a typed argument that uses a specified enum as type, or null if an aQualifiedEnumClassName or anEnum is invalid * @see #getEnumInstance(String, String) */ getEnumArgument( aQualifiedEnumClassName: String | string, anEnum: unknown ): TypedArgument; /** * Gets an enum instance for a specified enum class. * *

* Example of how to create the {@link senselogic.sitevision.api.webresource.doctype.DocType#HTML5} instance * of {@link senselogic.sitevision.api.webresource.doctype.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 {@link senselogic.sitevision.api.search.index.IndexUtil.IndexType#USER_IDENTITY} instance * of {@link senselogic.sitevision.api.search.index.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'))
   *  
* @param aQualifiedEnumClassName a fully qualified name of the enum class (i.e. including packages) * @param anEnumName the name of the enum value * @return an Enum instance, or null if an aQualifiedEnumClassName or anEnumName is invalid */ getEnumInstance( aQualifiedEnumClassName: String | string, anEnumName: String | string ): Enum; /** * Convenience method to get an ArrayList instance. * @return a java.util.ArrayList instance * @see #getListWrapper() */ getList(): List; /** * Convenience method to get a HashSet instance. * @return a java.util.HashSet instance */ getSet(): Set; /** * Convenience method to get a HashMap instance. * @return a java.util.HashMap instance */ getMap(): Map; /** * Convenience method to get a LinkedHashMap instance. * @return a java.util.LinkedHashMap instance * @since Sitevision 4.5.4.1 */ getLinkedMap(): Map; /** * Gets a 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. *

* @return a ListWrapper instance * @since Sitevision 3.5 */ getListWrapper(): ListWrapper; /** * Gets a 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. *

* @return a wrapper instance for java.util.Arrays */ getArraysInstance(): ArraysInstance; /** * Gets a 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. *

* @return a wrapper instance for java.util.Collections */ getCollectionsInstance(): CollectionsInstance; /** * Gets a 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. *

* @return a wrapper instance for java.lang.Math */ getMathInstance(): MathInstance; /** * Creates a boolean array with a given size. * @param aSize the array size * @return a boolean array with aSize length, or empty array if aSize is zero or negative * @see ArraysInstance * @since Sitevision 4.5.5 */ getBooleanArray(aSize: number): boolean; /** * Creates a byte array with a given size. * @param aSize the array size * @return a byte array with aSize length, or empty array if aSize is zero or negative * @see ArraysInstance * @since Sitevision 4.5.5 */ getByteArray(aSize: number): unknown; /** * Creates a char array with a given size. * @param aSize the array size * @return a char array with aSize length, or empty array if aSize is zero or negative * @see ArraysInstance * @since Sitevision 4.5.5 */ getCharArray(aSize: number): string; /** * Creates a double array with a given size. * @param aSize the array size * @return a double array with aSize length, or empty array if aSize is zero or negative * @see ArraysInstance * @since Sitevision 4.5.5 */ getDoubleArray(aSize: number): number; /** * Creates a float array with a given size. * @param aSize the array size * @return a float array with aSize length, or empty array if aSize is zero or negative * @see ArraysInstance * @since Sitevision 4.5.5 */ getFloatArray(aSize: number): number; /** * Creates a int array with a given size. * @param aSize the array size * @return a int array with aSize length, or empty array if aSize is zero or negative * @see ArraysInstance * @since Sitevision 4.5.5 */ getIntArray(aSize: number): number; /** * Creates a long array with a given size. * @param aSize the array size * @return a long array with aSize length, or empty array if aSize is zero or negative * @see ArraysInstance * @since Sitevision 4.5.5 */ getLongArray(aSize: number): number; /** * Creates a short array with a given size. * @param aSize the array size * @return a short array with aSize length, or empty array if aSize is zero or negative * @see ArraysInstance * @since Sitevision 4.5.5 */ getShortArray(aSize: number): number; /** * Creates a String array with a given size. * @param aSize the array size * @return a String array with aSize length, or empty array if aSize is zero or negative * @see ArraysInstance * @since Sitevision 4.5.5 */ getStringArray(aSize: number): string; /** * Creates a Object array with a given size. * @param aSize the array size * @return a Object array with aSize length, or empty array if aSize is zero or negative * @see ArraysInstance * @since Sitevision 4.5.5 */ getObjectArray(aSize: number): unknown; } declare namespace InstanceCreatorUtil {} declare var instanceCreatorUtil: InstanceCreatorUtil; export default instanceCreatorUtil;