Source Code Cross Referenced for AnyScope.java in  » Web-Framework » anvil » anvil » core » runtime » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » anvil » anvil.core.runtime 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:/*
002: * $Id: AnyScope.java,v 1.4 2002/09/16 08:05:03 jkl Exp $
003: *
004: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
005: *
006: * Use is subject to license terms, as defined in
007: * Anvil Sofware License, Version 1.1. See LICENSE 
008: * file, or http://njet.org/license-1.1.txt
009: */
010:package anvil.core.runtime;
011:
012:import java.io.IOException;
013:import java.io.Writer;
014:import java.util.Enumeration;
015:import anvil.java.util.BindingEnumeration;
016:import anvil.core.Any;
017:import anvil.core.AnyAbstractClass;
018:import anvil.core.Register;
019:import anvil.core.Serializer;
020:import anvil.core.Unserializer;
021:import anvil.core.UnserializationException;
022:import anvil.script.Context;
023:import anvil.script.Type;
024:import anvil.script.CompilableFunction;
025:import anvil.script.Function;
026:import anvil.script.FunctionDispatcher;
027:import anvil.script.Scope;
028:import anvil.script.Module;
029:import anvil.script.VariableType;
030:
031:/// @class Scope
032:/// Scope is a wrapper for modules and namespaces.
033:/// It provides the contained entities with
034:/// attributes or references.
035:
036:/**
037: * class AnyScope
038: *
039: * @author: Jani Lehtimäki
040: */
041:public class AnyScope extends AnyAbstractClass
042:{
043:
044:  public static final anvil.script.compiler.NativeClass __class__ = 
045:    new anvil.script.compiler.NativeClass("Scope", AnyScope.class,
046:    //DOC{{
047:    ""+
048:      " @class Scope\n" +
049:      " Scope is a wrapper for modules and namespaces.\n" +
050:      " It provides the contained entities with\n" +
051:      " attributes or references.\n" 
052:    //}}DOC
053:  );
054:  static {
055:    RuntimeModule.class.getName();
056:  }
057:  
058:  
059:  private Scope _scope;
060:
061:  
062:  public AnyScope(Scope scope)
063:  {
064:    _scope = scope; 
065:  }
066:
067:
068:  public final anvil.script.ClassType classOf() 
069:  {
070:    return __class__;
071:  }
072:
073:
074:  public final Type type() 
075:  {
076:    return _scope;
077:  }
078:
079:  
080:  public String toString()
081:  {
082:    return _scope.toString();
083:  }
084:  
085:    
086:  public Writer toAnvil(Writer writer) throws IOException
087:  {
088:    writer.write(_scope.getName());
089:    return writer;
090:  }
091:
092:  
093:  public Object toObject()
094:  {
095:    return _scope;
096:  }
097:
098:  private VariableType getVariable(String name)
099:  {
100:    Type type = _scope.lookupDeclaration(name);
101:    if (type instanceof  VariableType) {
102:      return (VariableType)type;
103:    }
104:    return null;
105:  }
106:
107:
108:  public Any getAttribute(Context context, String attribute)
109:  {
110:    VariableType var = getVariable(attribute);
111:    if (var != null) {
112:      return var.getValue();
113:    }
114:    return UNDEFINED;
115:  }
116:  
117:  
118:  public Any setAttribute(Context context, String attribute, Any value)
119:  {
120:    VariableType var = getVariable(attribute);
121:    if (var != null) {
122:      var.setValue(value);
123:    }
124:    return value;
125:  }
126:    
127:  
128:  public Any checkAttribute(Context context, String attribute)
129:  {
130:    VariableType var = getVariable(attribute);
131:    if (var != null) {
132:      return var.getValue();
133:    }
134:    return UNDEFINED;  
135:  }
136:  
137:
138:  public boolean deleteAttribute(Context context, String attribute)
139:  {
140:    return false;
141:  }
142:
143:
144:  public Any getReference(Context context, Any index)
145:  {
146:    return getAttribute(context, index.toString());
147:  }
148:  
149:  
150:  public Any setReference(Context context, Any index, Any value)
151:  {
152:    return setAttribute(context, index.toString(), value);
153:  }
154:  
155: 
156:  public Any setReference(Context context, Any value)
157:  {
158:    return this ;
159:  }
160:
161:
162:  public Any checkReference(Context context, Any index)
163:  {
164:    return checkAttribute(context, index.toString());
165:  }
166:  
167:
168:  public boolean deleteReference(Context context, Any index)
169:  {
170:    return false;
171:  }
172:
173:  
174:  public BindingEnumeration enumeration()
175:  {
176:    return new VariableFilter(_scope.getDeclarations());
177:  }
178:
179:
180:  public static final class VariableFilter implements  BindingEnumeration
181:  {
182:    private Enumeration _enum;
183:    private boolean _hasNext;
184:    private VariableType _nextElement;
185:    
186:    public VariableFilter(Enumeration enum)
187:    { 
188:      _enum = enum;
189:      forward();
190:    }
191:    
192:    private void forward()
193:    {
194:      Enumeration enum = _enum;
195:      while(enum.hasMoreElements()) {
196:        Object elem = enum.nextElement();
197:        if (elem instanceof  VariableType) {
198:          _hasNext = true;
199:          _nextElement = (VariableType)elem;
200:          return;
201:        }
202:      }
203:      _hasNext = false;
204:    }
205:    
206:    public boolean hasMoreElements()
207:    {
208:      return _hasNext;
209:    }
210:
211:    public Object nextKey()
212:    {
213:      return _nextElement.getName();
214:    }
215:
216:    public Object nextElement()
217:    {
218:      Any value = _nextElement.getValue();
219:      forward();
220:      return value;
221:    }
222:  
223:  }
224:
225:
226:  public final void serialize(Serializer serializer) throws IOException 
227:  {
228:    if (serializer.register(this )) {
229:      return;
230:    }
231:    serializer.write('M');
232:    AnyType.serializeType(serializer, _scope);
233:  }
234:
235:
236:  public static final Any unserialize(Unserializer unserializer) throws UnserializationException
237:  {
238:    Type type = AnyType.unserializeType(unserializer);
239:    if (type instanceof  Scope) {
240:      AnyScope scope = new AnyScope((Scope)type);
241:      unserializer.register(scope);
242:      return scope;
243:    }
244:    throw new UnserializationException();
245:  }
246:
247:
248:  public boolean has(String methodName)
249:  {
250:    Type type = _scope.lookupDeclaration(methodName);
251:    return ((type != null) && (type.getType() == Type.FUNCTION));
252:  }
253:
254:
255:  protected FunctionDispatcher getDispatcherFor(Context context, String name)
256:  {
257:    Type type = _scope.lookupDeclaration(name);
258:    if ((type != null) && (type.getType() == Type.FUNCTION)) {
259:      return ((CompilableFunction)type).getDispatcher(context);
260:    } else {
261:      throw context.NoSuchMethod(_scope.getName() + '.' + name);
262:    }    
263:  }
264:
265:  protected FunctionDispatcher getDispatcherFor(Context context, int index)
266:  {
267:    String name = Register.getNameOf(index);
268:    Type type = _scope.lookupDeclaration(name);
269:    if ((type != null) && (type.getType() == Type.FUNCTION)) {
270:      return ((CompilableFunction)type).getDispatcher(context);
271:    } else {
272:      throw context.NoSuchMethod(_scope.getName() + '.' + name);
273:    }    
274:  }
275:
276:
277:  public Any invoke(Context context, int methodIndex, Any[] parameters)
278:  {
279:    return getDispatcherFor(context, methodIndex).execute(context, null, parameters);
280:  }
281:
282:  public Any invoke(Context context, int methodIndex)
283:  {
284:    return getDispatcherFor(context, methodIndex).execute(context, null);
285:  }
286:
287:  public Any invoke(Context context, int methodIndex, Any param1)
288:  {
289:    return getDispatcherFor(context, methodIndex).execute(context, null, param1);
290:  }
291:
292:  public Any invoke(Context context, int methodIndex, Any param1, Any param2)
293:  {
294:    return getDispatcherFor(context, methodIndex).execute(context, null, param1, param2);
295:  }
296:
297:  public Any invoke(Context context, int methodIndex, Any param1, Any param2, Any param3)
298:  {
299:    return getDispatcherFor(context, methodIndex).execute(context, null, param1, param2, param3);
300:  }
301:
302:  public Any invoke(Context context, int methodIndex, Any param1, Any param2, Any param3, Any param4)
303:  {
304:    return getDispatcherFor(context, methodIndex).execute(context, null, param1, param2, param3, param4);
305:  }
306:
307:
308:  public Any invoke(Context context, String methodName, Any[] parameters)
309:  {
310:    return getDispatcherFor(context, methodName).execute(context, null, parameters);
311:  }
312:  
313:  public Any invoke(Context context, String methodName)
314:  {
315:    return getDispatcherFor(context, methodName).execute(context, null);
316:  }
317:
318:  public Any invoke(Context context, String methodName, Any param1)
319:  {
320:    return getDispatcherFor(context, methodName).execute(context, null, param1);
321:  }
322:
323:  public Any invoke(Context context, String methodName, Any param1, Any param2)
324:  {
325:    return getDispatcherFor(context, methodName).execute(context, null, param1, param2);
326:  }
327:
328:  public Any invoke(Context context, String methodName, Any param1, Any param2, Any param3)
329:  {
330:    return getDispatcherFor(context, methodName).execute(context, null, param1, param2, param3);
331:  }
332:
333:  public Any invoke(Context context, String methodName, Any param1, Any param2, Any param3, Any param4)
334:  {
335:    return getDispatcherFor(context, methodName).execute(context, null, param1, param2, param3, param4);
336:  }
337:
338:
339:  
340:
341:}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.