Fixes recursion bug in disambiguate_in().
[ohcount] / test / src_dir / as1.as
1 /* SVN FILE: $Id: FakeObject.as 42 2008-03-26 03:18:02Z xpointsh $ */
2 /**
3  * Description
4  *
5  * Fake
6  * Copyright 2008, Sean Chatman and Garrett Woodworth
7  *
8  * Licensed under The MIT License
9  * Redistributions of files must retain the above copyright notice.
10  *
11  * @filesource
12  * @copyright           Copyright 2008, Sean Chatman and Garrett Woodworth
13  * @link                        http://code.google.com/p/fake-as3/
14  * @package                     fake
15  * @subpackage          com.fake
16  * @since                       2008-03-06
17  * @version                     $Revision: 42 $
18  * @modifiedby          $LastChangedBy: xpointsh $
19  * @lastmodified        $Date: 2008-03-25 20:18:02 -0700 (Tue, 25 Mar 2008) $
20  * @license                     http://www.opensource.org/licenses/mit-license.php The MIT License
21  */
22 package com.fake
23 {
24         import flash.utils.*;
25
26         /**
27          * FakeObject is the root object for all classes
28          * in Fake. It contains a reference to the class name
29          * and class object. These are obtained by using the
30          * reflection classes in flash.utils.
31          */
32         public dynamic class FakeObject extends Proxy
33         {
34                 /**
35                 * The name of the top level subclass
36                 */
37                 [Transient] public var className:String;
38                 /**
39                 * A reference to the top level subclass
40                 */
41                 [Transient] public var ClassRef:Class;
42
43                 private var __item:Array;
44
45                 public function FakeObject()
46                 {
47                         getClassInfo();
48                         __item = new Array();
49                 }
50
51                 /**
52                  * This method is called by the constructor. Populates the className and ClassRef using
53                  * getQualifiedClassName and getDefinitionByName
54                  */
55                 private function getClassInfo():void
56                 {
57                         var qcName:Array = getQualifiedClassName(this).split("::");
58                         className = qcName[1];
59
60                         var classPath:String = getQualifiedClassName(this).replace( "::", "." );
61                         ClassRef = getDefinitionByName(classPath) as Class;
62                 }
63
64                 /**
65                  * Override the callProperty of the flash_proxy
66                  * @param method
67                  * @param args
68                  * @return
69                  *
70                  */
71                 override flash_proxy function callProperty(method: *, ...args):*
72                 {
73                         try
74                         {
75                                 return ClassRef.prototype[method].apply(method, args);
76                         }
77                         catch (e:Error)
78                         {
79                                 return overload(method, args);
80                         }
81                 }
82
83                 /**
84                  * To be overriden by subclasses. Allows calling any method on any object that extends FakeOject
85                  * @param method
86                  * @param args
87                  *
88                  */
89                 protected function overload(method:*, args:Array):void
90                 {
91                 }
92
93                 /**
94                  * get a property on the object
95                  * @param name
96                  * @return
97                  *
98                  */
99                 override flash_proxy function getProperty(name:*):*
100                 {
101                 return overloadGetProperty(name);
102             }
103
104             protected function overloadGetProperty(name:*):*
105             {
106                 return __item[name];
107             }
108
109             /**
110              * Set a property on the object
111              * @param name
112              * @param value
113              *
114              */
115             override flash_proxy function setProperty(name:*, value:*):void
116             {
117                 overloadSetProperty(name, value)
118             }
119
120             protected function overloadSetProperty(name:*, value:*):void
121             {
122                 __item[name] = value;
123             }
124
125                 /**
126              * Check if the property exits
127              * @param name
128              * @param value
129              *
130              */
131             override flash_proxy function hasProperty(name:*):Boolean
132             {
133                 if (__item[name])
134                 {
135                         return true;
136                 }
137                 return false;
138             }
139         }
140 }