Source Code Cross Referenced for CompiledScope.java in  » Web-Framework » anvil » anvil » script » compiler » 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.script.compiler 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: CompiledScope.java,v 1.7 2002/09/16 08:05:04 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.script.compiler;
011:
012:        import anvil.core.Any;
013:        import anvil.core.runtime.AnyFunction;
014:        import anvil.core.runtime.AnyType;
015:        import anvil.doc.Doc;
016:        import anvil.script.Context;
017:        import anvil.script.Type;
018:        import anvil.script.Scope;
019:        import anvil.script.ClassType;
020:        import anvil.script.Function;
021:        import anvil.script.CompilableFunction;
022:        import anvil.script.InterfaceType;
023:        import anvil.script.MethodType;
024:        import anvil.script.ConstantVariableType;
025:        import anvil.script.MemberVariableType;
026:        import anvil.script.StaticVariableType;
027:        import anvil.java.util.Hashlist;
028:        import anvil.java.util.BindingEnumeration;
029:        import java.lang.reflect.Field;
030:        import java.lang.reflect.Method;
031:        import java.lang.reflect.Constructor;
032:        import java.util.Enumeration;
033:
034:        /**
035:         * class Compiled
036:         *
037:         * @author: Jani Lehtimäki
038:         */
039:        public abstract class CompiledScope extends Compiled implements  Scope {
040:
041:            protected Hashlist _types = new Hashlist();
042:            protected Class _class = null;
043:            protected String _descriptor = null;
044:
045:            public CompiledScope(Scope parent, Class clazz, String name,
046:                    Doc document) {
047:                super (parent, name, document);
048:                if (clazz == null) {
049:                    clazz = this .getClass();
050:                }
051:                _class = clazz;
052:                _descriptor = clazz.getName().replace('.', '/');
053:            }
054:
055:            protected void initializeMembers(ClassLoader classloader) {
056:                try {
057:                    Method[] methods = _class.getDeclaredMethods();
058:                    Constructor[] constructors = _class.getConstructors();
059:                    Class[] classes = _class.getDeclaredClasses();
060:                    Object[] members = (Object[]) getstatic(_class, "_members");
061:                    int n = members.length;
062:                    for (int i = 0; i < n; i += 4) {
063:                        if (members[i] == null) {
064:                            break;
065:                        }
066:
067:                        int type = ((Integer) members[i]).intValue();
068:                        String name = (String) members[i + 1];
069:                        Doc doc = (Doc) members[i + 2];
070:                        Object data = members[i + 3];
071:
072:                        switch (type) {
073:                        case Type.MODULE: {
074:                            onScript(name, doc);
075:                        }
076:                            break;
077:
078:                        case NAMESPACE: {
079:                            Class innercls = findNamespace(classes, name);
080:                            onNamespace(classloader, innercls, name, doc);
081:                        }
082:                            break;
083:
084:                        case CLASS: {
085:                            Class innercls = findClass(classes, name);
086:                            onClass(classloader, innercls, name, doc);
087:                        }
088:                            break;
089:
090:                        case INTERFACE: {
091:                            Class innercls = findInterface(classes, name);
092:                            onInterface(classloader, innercls, name, doc);
093:                        }
094:                            break;
095:
096:                        case FUNCTION: {
097:                            Object[] parameters = (Object[]) data;
098:                            Method method = findMethod(methods, "f_" + name);
099:                            onFunction(method, name, parameters, doc);
100:                        }
101:                            break;
102:
103:                        case METHOD: {
104:                            Method method = findMethod(methods, "m_" + name);
105:                            Object[] parameters = (Object[]) data;
106:                            onMethod(method, name, parameters, doc);
107:                        }
108:                            break;
109:
110:                        case INTERFACE_METHOD: {
111:                            Method method = findMethod(methods, "m_" + name);
112:                            Object[] parameters = (Object[]) data;
113:                            onInterfaceMethod(method, name, parameters, doc);
114:                        }
115:                            break;
116:
117:                        case CONSTRUCTOR: {
118:                            Method method = findMethod(methods, "m_" + name);
119:                            Object[] parameters = (Object[]) data;
120:                            Constructor constructor = null;
121:                            int lastlength = -1;
122:                            for (int j = 0; j < constructors.length; j++) {
123:                                Class[] types = constructors[j]
124:                                        .getParameterTypes();
125:                                if (types.length > lastlength) {
126:                                    constructor = constructors[j];
127:                                    lastlength = types.length;
128:                                }
129:                            }
130:                            onConstructor(method, constructor, name,
131:                                    parameters, doc);
132:                        }
133:                            break;
134:
135:                        case CONSTANT_VARIABLE: {
136:                            Field field = _class.getDeclaredField("c_" + name);
137:                            onConstantVariable(field, name, doc);
138:                        }
139:                            break;
140:
141:                        case STATIC_VARIABLE: {
142:                            Field field = _class.getDeclaredField("s_" + name);
143:                            onStaticVariable(field, name, doc);
144:                        }
145:                            break;
146:
147:                        case MEMBER_VARIABLE: {
148:                            Field field = _class.getDeclaredField("f_" + name);
149:                            onMemberVariable(field, name, doc);
150:                        }
151:                            break;
152:
153:                        default: {
154:                            anvil.Log.log().error(
155:                                    "Invalid member code " + type + " for '"
156:                                            + name + "' at initialization of "
157:                                            + _class.getName());
158:                        }
159:                            break;
160:
161:                        }
162:                    }
163:
164:                } catch (Throwable t) {
165:                    anvil.Log.log()
166:                            .error(
167:                                    "Initialization of " + _class.getName()
168:                                            + " failed", t);
169:                }
170:
171:            }
172:
173:            protected void onScript(String name, Doc doc) {
174:            }
175:
176:            protected Scope onNamespace(ClassLoader classloader, Class cls,
177:                    String name, Doc doc) {
178:                Scope namespace = new CompiledNamespace(classloader, this , cls,
179:                        name, doc);
180:                declare(namespace);
181:                return namespace;
182:            }
183:
184:            protected ClassType onClass(ClassLoader classloader, Class cls,
185:                    String name, Doc doc) {
186:                ClassType clazz = new CompiledClassType(classloader, this , cls,
187:                        name, doc);
188:                declare(clazz);
189:                return clazz;
190:            }
191:
192:            protected InterfaceType onInterface(ClassLoader classloader,
193:                    Class cls, String name, Doc doc) {
194:                InterfaceType intrface = new CompiledInterfaceType(classloader,
195:                        this , cls, name, doc);
196:                declare(intrface);
197:                return intrface;
198:            }
199:
200:            protected CompilableFunction onFunction(Method method, String name,
201:                    Object[] parameters, Doc doc) {
202:                CompilableFunction function = new FunctionBase(this , method,
203:                        name, parameters, doc);
204:                putstatic(_class, "f_" + name, function);
205:                putstatic(_class, "F_" + name, new AnyFunction(function));
206:                declare(function);
207:                return function;
208:            }
209:
210:            protected MethodType onMethod(Method method, String name,
211:                    Object[] parameters, Doc doc) {
212:                MethodType function = new MethodBase(this , method, name,
213:                        parameters, doc);
214:                putstatic(_class, "m_" + name, function);
215:                putstatic(_class, "M_" + name, new AnyFunction(function));
216:                declare(function);
217:                return function;
218:            }
219:
220:            protected MethodType onInterfaceMethod(Method method, String name,
221:                    Object[] parameters, Doc doc) {
222:                MethodType function = new InterfaceMethodBase(this , method,
223:                        name, parameters, doc);
224:                putstatic(_class, "m_" + name, function);
225:                putstatic(_class, "M_" + name, new AnyFunction(function));
226:                declare(function);
227:                return function;
228:            }
229:
230:            protected MethodType onConstructor(Method method,
231:                    Constructor constructor, String name, Object[] parameters,
232:                    Doc doc) {
233:                MethodType function = new ConstructorBase(this , constructor,
234:                        method, name, parameters, doc);
235:                putfield(_class, null, "m_" + name, function);
236:                putfield(_class, null, "M_" + name, new AnyFunction(function));
237:                declare(function);
238:                return function;
239:            }
240:
241:            protected ConstantVariableType onConstantVariable(Field field,
242:                    String name, Doc doc) {
243:                ConstantVariableType constant = new ConstantVariable(this ,
244:                        name, field, doc);
245:                _types.put(name, constant);
246:                return constant;
247:            }
248:
249:            protected StaticVariableType onStaticVariable(Field field,
250:                    String name, Doc doc) {
251:                StaticVariableType variable = new StaticVariable(this , name,
252:                        field, doc);
253:                _types.put(name, variable);
254:                return variable;
255:            }
256:
257:            protected MemberVariableType onMemberVariable(Field field,
258:                    String name, Doc doc) {
259:                MemberVariableType variable = new MemberVariable(this , name,
260:                        field, doc);
261:                _types.put(name, variable);
262:                return variable;
263:            }
264:
265:            public Type lookupDeclaration(String name) {
266:                return (Type) _types.get(name);
267:            }
268:
269:            public final Enumeration getDeclarations() {
270:                return _types.elements();
271:            }
272:
273:            protected final void declare(Type type) {
274:                _types.put(type.getName(), type);
275:            }
276:
277:            protected final void declare(String name, Type type) {
278:                _types.put(name, type);
279:            }
280:
281:            public int getTypeRef(anvil.codec.ConstantPool pool) {
282:                return pool.addClass(_descriptor);
283:            }
284:
285:            public String getDescriptor() {
286:                return _descriptor;
287:            }
288:
289:            public CompiledModule getModule() {
290:                Type type = this ;
291:                while (type != null) {
292:                    Type parent = type.getParent();
293:                    if (parent == null) {
294:                        return (CompiledModule) type;
295:                    }
296:                    type = parent;
297:                }
298:                return null;
299:            }
300:
301:            public String buildQualifiedName() {
302:                StringBuffer buffer = new StringBuffer(24);
303:                Scope scope = this ;
304:                out: while (true) {
305:                    switch (scope.getType()) {
306:                    case CLASS:
307:                    case NAMESPACE:
308:                        if (buffer.length() > 0) {
309:                            buffer.insert(0, '.');
310:                        }
311:                        buffer.insert(0, scope.getName());
312:                        scope = scope.getParent();
313:                        break;
314:                    default:
315:                        break out;
316:                    }
317:                }
318:                return buffer.toString();
319:            }
320:
321:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.