Last active
August 29, 2015 13:59
-
-
Save cameroncf/10487348 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| component | |
| output="false" | |
| { | |
| public SingletonFactory function init() | |
| output = 'false' | |
| { return this; } | |
| public any function getObject(required String objectName) | |
| output = 'false' | |
| { | |
| // it exists, return it | |
| // return object | |
| lock | |
| timeout = '10' | |
| throwontimeout = 'No' | |
| name = 'SingletonFactory' | |
| type = 'READONLY' | |
| { | |
| if (structKeyExists(application,'SingletonFactory') and | |
| structKeyExists(application.SingletonFactory,arguments.objectName)) | |
| { | |
| return application.SingletonFactory[arguments.objectName]; | |
| } | |
| } | |
| // create if needed | |
| lock | |
| timeout = '10' | |
| throwontimeout = 'No' | |
| name = 'SingletonFactory' | |
| type = 'EXCLUSIVE' | |
| { | |
| if (not structKeyExists(application,'SingletonFactory') or | |
| not structKeyExists(application.SingletonFactory,arguments.objectName)) | |
| { | |
| if (not structKeyExists(application,'SingletonFactory')) | |
| { application.SingletonFactory = structNew(); } | |
| if (not structKeyExists(application.SingletonFactory,arguments.objectName)) | |
| { application.SingletonFactory[arguments.objectName] = createObject("component",arguments.objectName).init(); } | |
| } // end create | |
| return application.SingletonFactory[arguments.objectName]; | |
| } // end lock | |
| } // end getObject() | |
| public void function clearObject(String objectName) | |
| output = 'false' | |
| { | |
| lock | |
| timeout = '10' | |
| throwontimeout = 'No' | |
| name = 'SingletonFactory' | |
| type = 'EXCLUSIVE' | |
| { | |
| if (structKeyExists(arguments,'objectName') and len(trim(arguments.objectName))) | |
| { | |
| structDelete(application.SingletonFactory,'arguments.objectName'); | |
| } else { | |
| structDelete(application,'SingletonFactory'); | |
| } | |
| } | |
| }// end clearObject() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment