I was wondering if someone can see why I can't seem to get my singleton
from the following function?

 

<cffunction 

                        access="private" 

                        name="getInstance" 

                        output="false" 

                        returntype="Object" 

                        displayname="Get Instance" 

                        hint="Returns an instance of the object, gets it
from the persistent scope if the class is a singleton.">

 

                        <cfscript>

                        var mySingletonPath = "";

                        // Check if this object is a singleton

                        if ( isSingleton() )

                        {

                                    mySingletonPath =
getSingletonScope() & ".hash" & getClassPathAsHash() & ".hash" & hash(
getMetaData( this ).name );

                                    // Check if the singleton is
instantiated

                                    if ( NOT isDefined( mySingletonPath
) )

                                    {

                                                setInstanceVariable(
variableName = "initialized", value = true );

                                                setClassVariable(
variableName = "hash" & hash( getMetaData( this ).name ), value = this,
scope = getSingletonScope() );

                                    }

                                    // Return the Singleton

                                    //getClassVariable( variableName =
"hash" & hash( getMetaData( this ).name ), scope = getSingletonScope()
).dumpInstance();abort();

                                    return getClassVariable(
variableName = "hash" & hash( getMetaData( this ).name ), scope =
getSingletonScope() ); 

                        }

                        setInstanceVariable( variableName =
"initialized", value = true );

                        // Return a new instance of this object

                        return this;

                        </cfscript>

 

     </cffunction>

 

Let's say if I set a variable in the object with a value of "1",
instantiate the object, change the value to "2" save the object and
instantiate it again, and then call dumpInstance() I expect the value to
be "1" not "2".

 

When I uncomment the following line it outputs the expected result, i.e.
an instance variable with the value "1"

//getClassVariable( variableName = "hash" & hash( getMetaData( this
).name ), scope = getSingletonScope() ).dumpInstance();abort();

 

But when I later dump it from the file that instantiates the object it
outputs "2"

FormProcess = new ( "com.pacificMomentum.data.FormProcess" ).init();

FormProcess.dumpInstance();abort();

 

PS.

dumpInstance() is one of my own methods which dumps instance variables
BTW.

The init() method in the object returns getInstance() BTW i.e.

return getInstance();

 

________________________________

Taco Fleur - E-commerce Development Manager

Shelco Searches & Services

An Authorised ASIC Information Broker

www.shelco.com.au

Ph: + 61 7 3236 2605

 

 



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:212918
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to