Results 1 to 4 of 4

Thread: How to get id by Object instance

  1. #1

    Default How to get id by Object instance

    <object id="objectId" class="com.xxx.xxx.AbcObject" />

    Now I have got the instance of the object abcObject.

    how can I get the id-"objectId" of it in xml config file?

    Thanks

  2. #2

    Default

    var clazz:Class=Class(getDefinitionByName(getQualified ClassName(object)));
    var objectNames:Array=this._applicationContext.getObje ctNamesForType(clazz);
    for(var j:int=0;j<objectNames.length;j++) {
    var objectName:String = objectNames[j];
    if(object==this._applicationContext.getObject(obje ctName)){
    //do with objectName;
    }
    }

  3. #3
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    406

    Default why?

    Hey Nathan,

    please keep in mind that the code you've posted will only work on objects that have been marked as singletons. Non-singleton objects will yield a new instance everytime you call _applicationContext.getObject().

    If you want to keep track of those you will have to create your own mechanism that keeps track of what object belongs to which object id.

    I guess something like this could work:

    Code:
    var objectName:String = 'SomeObjectId';
    var objectIdRegistry:Dictionary = new Dictionary(true);
    var object:Object = _applicationContext.getObject(objectName);
    objectIdRegistry[object] = objectName;
    than somewhere else in your code if you want to know the object id that the object originated from:
    Code:
    var objectName:String = objectIdRegistry[object] as String;
    That way you can keep track of both singletons and prototyped objects.

    Hope that helps a little,

    cheers,

    Roland

  4. #4

    Default

    Thank you very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •