ColdBox Platform Version 2.6.4

coldbox.system.plugins
Class BeanFactory

WEB-INF.cftags.component
        extended by coldbox.system.FrameworkSupertype
            extended by coldbox.system.Plugin
                extended by coldbox.system.plugins.BeanFactory

public class BeanFactory
extends Plugin

I am the ColdBox BeanFactory plugin that takes care of autowiring and dependency injection


Constructor Summary
init(any controller)
          constructor
 
Method Summary
 void addModelMapping([string alias], string path)
          Add a new model mapping
 void appendExternalLocations(string locations)
          Try to append a new model external location
 void autowire(any target, [boolean useSetterInjection='true'], [boolean annotationCheck='false'], [string onDICompleteUDF='onDIComplete'], [string stopRecursion=''])
          Autowire an object using the ColdBox DSL
 BeanFactory configure()
          Configure the bean factory for operation from the configuration file
 boolean containsModel(string name, [boolean resolveAlias='false'])
          Checks if the factory has a model object definition found
 Any create(string bean)
          Create a named bean, simple as that
private any getColdboxDSL(any definition)
          Get dependencies using the coldbox dependency DSL
private struct getConstructorArguments(any model='')
          The constructor argument collection for a model object
private BaseDictionary getDICacheDictionary()
          Get DICacheDictionary
private any getDSLDependency(any definition)
          get a dsl dependency
private any getEntityServiceDSL(any definition)
          Get a virtual entity service object
 string getExternalLocations()
          Get all the registered external locations
private any getIOCDependency(any definition)
          Get an IOC dependency
private any getJavaLoaderDSL(any definition)
          Get JavaLoader Dependency
private any getLogBoxDSL(any definition)
          Get dependencies using the logbox dependency DSL
 any getModel(string name, [boolean useSetterInjection], [string onDICompleteUDF], [string stopRecursion])
          Create or retrieve model objects by convention
private any getModelDSL(any definition)
          Get dependencies using the model dependency DSL
 struct getModelMappings()
          Get the model mappings structure
private struct getNewMDEntry()
          Get a new metadata entry structure
private any getOCMDependency(any definition)
          Get OCM dependencies
private any getWebserviceDSL(any Definition)
          Get webservice dependencies
private void injectBean(any targetBean, string beanName, any beanObject, string scope)
          Inject a bean with dependencies via setters or property injections
 string locateModel(string name, [boolean resolveAlias='false'])
          Get the location instantiation path for a model object
private array parseMetadata(any metadata, array dependencies, [boolean useSetterInjection='true'], [string stopRecursion=''])
          I get a components dependencies via searching for 'setters'
 Any populateBean(any target, [string scope=''], [boolean trustedSetter='false'], [string include=''], [string exclude=''])
          Populate a named or instantiated bean (java/cfc) from the request collection items
 any populateFromJSON(any target, string JSONString, [string scope=''], [boolean trustedSetter='false'], [string include=''], [string exclude=''])
          Populate a named or instantiated bean from a json string
 Any populateFromQuery(any target, query qry, [Numeric RowNumber='1'], [string scope=''], [boolean trustedSetter='false'], [string include=''], [string exclude=''])
          Populate a named or instantiated bean from query
 any populateFromStruct(any target, struct memento, [string scope], [boolean trustedSetter='false'], [string include=''], [string exclude=''])
          Populate a named or instantiated bean from a structure
 Any populateModel(any model, [string scope=''], [boolean trustedSetter='false'], [string include=''], [string exclude=''])
          Populate a named or instantiated model (java/cfc) from the request collection items
private void processAfterCompleteDI(any targetObject, [string onDICompleteUDF='onDIComplete'])
          see if we have a method to call after DI, and if so, call it
 void removeExternalLocations(string locations)
          Try to remove all the external locations passed in
 string resolveModelAlias(string name)
          Resolve the real name of any incoming argument model name or alias
private void setDICacheDictionary(BaseDictionary DICacheDictionary)
          Set DICacheDictionary
private boolean stopClassRecursion(string classname, string stopRecursion)
          Should we stop recursion or not due to class name found
 
Methods inherited from class coldbox.system.Plugin
getPluginDescription, getPluginName, getPluginVersion, getRequestCollection, getRequestContext, getpluginAuthor, getpluginAuthorURL, getpluginPath, setPluginDescription, setPluginName, setPluginVersion, setpluginAuthor, setpluginAuthorURL
 
Methods inherited from class coldbox.system.FrameworkSupertype
$abort, $dump, $htmlhead, $include, $rethrow, $throw, addAsset, announceInterception, getColdboxOCM, getController, getDatasource, getDebugMode, getHash, getInstance, getInterceptor, getMailSettings, getModuleSettings, getMyPlugin, getPlugin, getResource, getSetting, getSettingStructure, getSettingsBean, getfwLocale, includeUDF, locateDirectoryPath, locateFilePath, persistVariables, relocate, renderExternalView, renderView, runEvent, setDebugMode, setNextEvent, setNextRoute, setSetting, setfwLocale, settingExists
 
Methods inherited from class WEB-INF.cftags.component
 

Constructor Detail

init

public init(any controller)
constructor

Parameters:
controller - coldbox.system.web.Controller
Method Detail

addModelMapping

public void addModelMapping([string alias], string path)
Add a new model mapping. Ex: addModelMapping('myBean','security.test.FormBean'). The alias can be a single item or a comma delimmitted list

Parameters:
alias - The model alias to use, this can also be a list of aliases. Ex: SecurityService,Security
path - The model path (From the model conventions downward). Do not add full path, this is a convenience

appendExternalLocations

public void appendExternalLocations(string locations)
Try to append a new model external location

Parameters:
locations - Locations to add to the lookup, will be added in passed order. Comma delimited allowed.

autowire

public void autowire(any target, [boolean useSetterInjection='true'], [boolean annotationCheck='false'], [string onDICompleteUDF='onDIComplete'], [string stopRecursion=''])
Autowire an object using the ColdBox DSL

Parameters:
target - The object to autowire
useSetterInjection - Whether to use setter injection alongside the annotations property injection. cfproperty injection takes precedence.
annotationCheck - This value determines if we check if the target contains an autowire annotation in the cfcomponent tag: autowire=true|false, it will only autowire if that metadata attribute is set to true. The default is false, which will autowire automatically.
onDICompleteUDF - After Dependencies are injected, this method will look for this UDF and call it if it exists. The default value is onDIComplete
stopRecursion - The stop recursion class. Ex: transfer.com.TransferDecorator. By default all ColdBox base classes are included.

configure

public BeanFactory configure()
Configure the bean factory for operation from the configuration file.


containsModel

public boolean containsModel(string name, [boolean resolveAlias='false'])
Checks if the factory has a model object definition found

Parameters:
name - The name of the model to check
resolveAlias - Resolve model aliases

create

public Any create(string bean)
Create a named bean, simple as that. If the bean has an init() method, it will be called.

Parameters:
bean - The type of bean to create and return. Uses full cfc path mapping.Ex: coldbox.beans.ExceptionBean

getColdboxDSL

private any getColdboxDSL(any definition)
Get dependencies using the coldbox dependency DSL

Parameters:
definition - The dependency definition structure

getConstructorArguments

private struct getConstructorArguments(any model='')
The constructor argument collection for a model object

Parameters:
model - The model object

getDICacheDictionary

private BaseDictionary getDICacheDictionary()
Get DICacheDictionary


getDSLDependency

private any getDSLDependency(any definition)
get a dsl dependency

Parameters:
definition - The dependency definition structure

getEntityServiceDSL

private any getEntityServiceDSL(any definition)
Get a virtual entity service object

Parameters:
definition - The dependency definition structure

getExternalLocations

public string getExternalLocations()
Get all the registered external locations


getIOCDependency

private any getIOCDependency(any definition)
Get an IOC dependency

Parameters:
definition - The dependency definition structure

getJavaLoaderDSL

private any getJavaLoaderDSL(any definition)
Get JavaLoader Dependency

Parameters:
definition - The dependency definition structure

getLogBoxDSL

private any getLogBoxDSL(any definition)
Get dependencies using the logbox dependency DSL

Parameters:
definition - The dependency definition structure

getModel

public any getModel(string name, [boolean useSetterInjection], [string onDICompleteUDF], [string stopRecursion])
Create or retrieve model objects by convention

Overrides:
getModel in class FrameworkSupertype
Parameters:
name - The name of the model to retrieve
useSetterInjection - Whether to use setter injection alongside the annotations property injection. cfproperty injection takes precedence.
onDICompleteUDF - After Dependencies are injected, this method will look for this UDF and call it if it exists. The default value is onDIComplete
stopRecursion - A comma-delimmited list of stoprecursion classpaths.

getModelDSL

private any getModelDSL(any definition)
Get dependencies using the model dependency DSL

Parameters:
definition - The dependency definition structure

getModelMappings

public struct getModelMappings()
Get the model mappings structure


getNewMDEntry

private struct getNewMDEntry()
Get a new metadata entry structure


getOCMDependency

private any getOCMDependency(any definition)
Get OCM dependencies

Parameters:
definition - The dependency definition structure

getWebserviceDSL

private any getWebserviceDSL(any Definition)
Get webservice dependencies

Parameters:
Definition - The dependency definition structure

injectBean

private void injectBean(any targetBean, string beanName, any beanObject, string scope)
Inject a bean with dependencies via setters or property injections

Parameters:
targetBean - The bean that will be injected with dependencies
beanName - The name of the property to inject
beanObject - The bean object to inject.
scope - The scope to inject a property into.

locateModel

public string locateModel(string name, [boolean resolveAlias='false'])
Get the location instantiation path for a model object. If the model location is not found, this method returns an empty string.

Parameters:
name - The model to locate
resolveAlias - Resolve model aliases

parseMetadata

private array parseMetadata(any metadata, array dependencies, [boolean useSetterInjection='true'], [string stopRecursion=''])
I get a components dependencies via searching for 'setters'

Parameters:
metadata - The recursive metadata
dependencies - The dependencies
useSetterInjection - Whether to use setter injection alongside the annotations property injection. cfproperty injection takes precedence.
stopRecursion - The stop recursion class

populateBean

public Any populateBean(any target, [string scope=''], [boolean trustedSetter='false'], [string include=''], [string exclude=''])
Populate a named or instantiated bean (java/cfc) from the request collection items

Parameters:
target - This can be an instantiated bean object or a bean instantitation path as a string. This method follows the bean contract (set{property_name}). Example: setUsername(), setfname()
scope - Use scope injection instead of setters population. Ex: scope=variables.instance.
trustedSetter - If set to true, the setter method will be called even if it does not exist in the bean
include - A list of keys to include in the population
exclude - A list of keys to exclude in the population

populateFromJSON

public any populateFromJSON(any target, string JSONString, [string scope=''], [boolean trustedSetter='false'], [string include=''], [string exclude=''])
Populate a named or instantiated bean from a json string

Parameters:
target - This can be an instantiated bean object or a bean instantitation path as a string. If you pass an instantiation path and the bean has an 'init' method. It will be executed. This method follows the bean contract (set{property_name}). Example: setUsername(), setfname()
JSONString - The JSON string to populate the object with. It has to be valid JSON and also a structure with name-key value pairs.
scope - Use scope injection instead of setters population. Ex: scope=variables.instance.
trustedSetter - If set to true, the setter method will be called even if it does not exist in the bean
include - A list of keys to include in the population
exclude - A list of keys to exclude in the population

populateFromQuery

public Any populateFromQuery(any target, query qry, [Numeric RowNumber='1'], [string scope=''], [boolean trustedSetter='false'], [string include=''], [string exclude=''])
Populate a named or instantiated bean from query

Parameters:
target - This can be an instantiated bean object or a bean instantitation path as a string. If you pass an instantiation path and the bean has an 'init' method. It will be executed. This method follows the bean contract (set{property_name}). Example: setUsername(), setfname()
qry - The query to popluate the bean object with
RowNumber - The query row number to use for population
scope - Use scope injection instead of setters population. Ex: scope=variables.instance.
trustedSetter - If set to true, the setter method will be called even if it does not exist in the bean
include - A list of keys to include in the population
exclude - A list of keys to exclude in the population

populateFromStruct

public any populateFromStruct(any target, struct memento, [string scope], [boolean trustedSetter='false'], [string include=''], [string exclude=''])
Populate a named or instantiated bean from a structure

Parameters:
target - This can be an instantiated bean object or a bean instantitation path as a string. If you pass an instantiation path and the bean has an 'init' method. It will be executed. This method follows the bean contract (set{property_name}). Example: setUsername(), setfname()
memento - The structure to populate the object with.
scope - Use scope injection instead of setters population.
trustedSetter - If set to true, the setter method will be called even if it does not exist in the bean
include - A list of keys to include in the population
exclude - A list of keys to exclude in the population

populateModel

public Any populateModel(any model, [string scope=''], [boolean trustedSetter='false'], [string include=''], [string exclude=''])
Populate a named or instantiated model (java/cfc) from the request collection items

Overrides:
populateModel in class FrameworkSupertype
Parameters:
model - The name of the model to get and populate or the acutal model object. If you already have an instance of a model, then use the populateBean() method
scope - Use scope injection instead of setters population. Ex: scope=variables.instance.
trustedSetter - If set to true, the setter method will be called even if it does not exist in the bean
include - A list of keys to include in the population
exclude - A list of keys to exclude in the population

processAfterCompleteDI

private void processAfterCompleteDI(any targetObject, [string onDICompleteUDF='onDIComplete'])
see if we have a method to call after DI, and if so, call it

Parameters:
targetObject - the target object to call on
onDICompleteUDF - After Dependencies are injected, this method will look for this UDF and call it if it exists.

removeExternalLocations

public void removeExternalLocations(string locations)
Try to remove all the external locations passed in

Parameters:
locations - Locations to remove from the lookup. Comma delimited allowed.

resolveModelAlias

public string resolveModelAlias(string name)
Resolve the real name of any incoming argument model name or alias

Parameters:
name - The model alias or name to resolve

setDICacheDictionary

private void setDICacheDictionary(BaseDictionary DICacheDictionary)
Set DICacheDictionary

Parameters:
DICacheDictionary

stopClassRecursion

private boolean stopClassRecursion(string classname, string stopRecursion)
Should we stop recursion or not due to class name found

Parameters:
classname - The class name to check
stopRecursion - The comma delimmitted list of stop recurssion classes

ColdBox Platform Version 2.6.4