KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > es > ESGlobal


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.es;
30
31 /**
32  * Implementation class representing the global object.
33  */

34 abstract public class ESGlobal extends ESObject implements ESCallable {
35   private Global resin;
36
37   /**
38    * Null constructor
39    */

40   protected ESGlobal(Global resin)
41   {
42     super("Global", resin);
43     //snapPrototype = true;
44

45     this.resin = resin;
46   }
47
48   /**
49    * Returns the string representation of the type.
50    */

51   public ESBase typeof() throws ESException
52   {
53     return ESString.create("function");
54   }
55
56   /**
57    * returns the string representation
58    */

59   public ESString toStr() throws ESException
60   {
61     return ESString.create("[global]");
62   }
63
64   /**
65    * returns a primitive
66    */

67   public ESBase toPrimitive(int hint) throws ESException
68   {
69     return toStr();
70   }
71
72   public void setProperty(String JavaDoc name, ESBase value)
73     throws Throwable JavaDoc
74   {
75     setProperty(ESId.intern(name), value);
76   }
77
78   public Object JavaDoc toJavaObject()
79     throws ESException
80   {
81     Object JavaDoc o = prototype.toJavaObject();
82     return (o == null) ? this : o;
83   }
84
85   /**
86    * Execute the static function
87    */

88   ESBase execute()
89     throws Throwable JavaDoc
90   {
91     Global resin = (Global) prototype;
92
93     try {
94       Call call = resin.getCall();
95       call.caller = call;
96       call.setArg(0, this);
97       call.top = 1;
98
99       call.scopeLength = 1;
100       call.scope[0] = this;
101       call.global = this;
102
103       ESBase value = null;
104
105       try {
106         value = call(0, call, 0);
107       } finally {
108         resin.freeCall(call);
109       }
110
111       return value;
112     } catch (ESException e) {
113       throw e;
114     } catch (Throwable JavaDoc e) {
115       throw new ESWrapperException(e);
116     }
117   }
118
119
120   public void export(ESObject dest)
121     throws Throwable JavaDoc
122   {
123
124   }
125
126   /**
127    * Wraps the java object in an ES wrapper
128    */

129   public ESBase wrap(Object JavaDoc obj)
130     throws Throwable JavaDoc
131   {
132     return resin.wrap(obj);
133   }
134
135   public abstract ESBase call(int n, Call call, int length)
136     throws Throwable JavaDoc;
137 }
138
Popular Tags