CreateObject
Creates a new object representation according to the {@code type} and {@code className} arguments.
Available types are:
class/component - Creates a new instance of a BoxLang class (Default if not used)
java - Creates a new instance of a Java class
webservice - Creates a SOAP web service client from a WSDL URL
{anything} - Passes the request to the {@code BoxEvent.ON_CREATEOBJECT_REQUEST} event for further processing
If the type requested is not supported, then it passes to an interception call to the {@code BoxEvent.ON_CREATEOBJECT_REQUEST} event, so any listeners can contribute to the object creation request (if any). If there are no listeners, an exception is thrown.
You can also target an explicit class from a loaded BoxLang module by using the {@code @moduleName} suffix. Example: {@code createObject( 'class', 'class.name.path@module' )}
The properties is an optional argument that can be used to pass to the object creation process according to the type.
class/component - The properties are not used
java - The properties can be a single or an array of absolute path(s) to a directory containing Jars/Classes, or absolute path(s) to specific Jars/Classes to classload
webservice - The properties are not used
{anything} - The properties can be any object that the listener can use to create the object
IMPORTANT: For class/component types, this does NOT create an instance of the class. For that you will need to call the {@code init()} method on the returned object. For webservice type, a fully configured SoapClient is returned ready for method invocation.
Method Signature
CreateObject(type=[string], className=[string], properties=[any], externalOnly=[boolean], classloader=[any])Arguments
type
string
false
The type of object to create: java, class (component), webservice, or any other type
class
className
string
false
For java/class types: a fully qualified class name. For webservice type: the WSDL URL.
properties
any
false
Depending on the type, this can be used to pass additional properties to the object creation process
externalOnly
boolean
false
classloader
any
false
Optional class loader to use when loading Java classes. Only applicable for type="java".
Examples
Create a BX / Component Instance
createObject Component
Create a SOAP WebService Instance
createObject WebService
Create a java class with specified bundle and version
createObject filesystem
Additional Examples
Related
Last updated
Was this helpful?
