001: /*
002: * $Id: AnyStackTraceElement.java,v 1.2 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 anvil.core.Any;
013: import anvil.core.AnyAbstractClass;
014: import anvil.script.Context;
015: import anvil.script.Module;
016: import anvil.script.Function;
017: import anvil.script.StackFrame;
018:
019: /// @class StackTraceElelement
020: /// Represents a single stack frame.
021:
022: /**
023: * class AnyStackTraceElelement
024: *
025: * @author: Jani Lehtimäki
026: */
027: public class AnyStackTraceElement extends AnyAbstractClass {
028:
029: public static final anvil.core.RuntimePermission CAN_USE = new anvil.core.RuntimePermission(
030: "anvil.runtime.StackTraceElement", false);
031:
032: private Module _module;
033: private Any _instance;
034: private Function _function;
035: private int _line;
036:
037: public AnyStackTraceElement(Module module, Any instance,
038: Function function, int line) {
039: _module = module;
040: _instance = instance;
041: _function = function;
042: _line = line;
043: }
044:
045: public AnyStackTraceElement(StackFrame frame) {
046: _module = frame.getModule();
047: _instance = frame.getSelf();
048: _function = frame.getFunction();
049: _line = frame.getLine();
050: }
051:
052: public final anvil.script.ClassType classOf() {
053: return __class__;
054: }
055:
056: public Object toObject() {
057: return null;
058: }
059:
060: public String toString() {
061: StringBuffer buffer = new StringBuffer(50);
062: buffer.append(_function);
063: buffer.append(' ');
064: buffer.append('[');
065: buffer.append(_module.getPathinfo());
066: if (_line > 0) {
067: buffer.append(": ");
068: buffer.append(_line);
069: }
070: buffer.append("] ");
071: return buffer.toString();
072: }
073:
074: /// @method getPathinfo
075: /// Returns the path of the source file containing the execution point
076: /// represented by this stack trace element.
077: /// @synopsis string getPathinfo()
078: public Any m_getPathinfo() {
079: return Any.create(_module.getPathinfo());
080: }
081:
082: /// @method getClassName
083: /// Returns the fully qualified name of the class containing
084: /// the execution point represented by this stack trace element.
085: /// @synopsis string getClassName()
086: public Any m_getClassName() {
087: if (_instance != null) {
088: return Any.create(_instance.classOf().getQualifiedName());
089: } else {
090: return UNDEFINED;
091: }
092: }
093:
094: /// @method getLine
095: /// Returns the line number of the source line containing
096: /// the execution point represented by this stack trace element.
097: /// @synopsis int getLine()
098: public Any m_getLine() {
099: return Any.create(_line);
100: }
101:
102: /// @method getModule
103: /// Returns the module instance containing
104: /// the execution point represented by this stack trace element.
105: /// @synopsis Scope getModule()
106: /// @throws AccessDenied If security policy denies access to
107: /// path represented by this stack trace element
108: public Any m_getModule(Context context) {
109: context.checkImport(_module.getPathinfo());
110: return new AnyScope(_module);
111: }
112:
113: /// @method getInstance
114: /// Returns the instance of class containing
115: /// the execution point represented by this stack trace element.
116: /// @synopsis object getInstance()
117: /// @return Instance, or undefined if the execution were not
118: /// in method.
119: /// @throws AccessDenied If security policy denies access to
120: /// path represented by this stack trace element
121: public Any m_getInstance(Context context) {
122: context.checkImport(_module.getPathinfo());
123: if (_instance != null) {
124: return _instance;
125: } else {
126: return UNDEFINED;
127: }
128: }
129:
130: /// @method getFunctionName
131: /// Returns the name of the function containing
132: /// the execution point represented by this stack trace element.
133: /// @synopsis string getFunctionName()
134: public Any m_getFunctionName() {
135: return Any.create(_function.getName());
136: }
137:
138: /// @method getFunction
139: /// Returns a handle to function (or method) containing
140: /// the execution point represented by this stack trace element.
141: /// Instance, if any, is inserted to handle as well.
142: /// @synopsis Function getFunction()
143: /// @throws AccessDenied If security policy denies access to
144: /// path represented by this stack trace element
145: public Any m_getFunction(Context context) {
146: context.checkImport(_module.getPathinfo());
147: if (_function != null) {
148: return new AnyFunction(_instance, _function);
149: } else {
150: return UNDEFINED;
151: }
152: }
153:
154: public static final anvil.script.compiler.NativeClass __class__ = new anvil.script.compiler.NativeClass(
155: "StackTraceElement",
156: AnyStackTraceElement.class,
157: //DOC{{
158: ""
159: + " @class StackTraceElelement\n"
160: + " Represents a single stack frame.\n"
161: + " @method getPathinfo\n"
162: + " Returns the path of the source file containing the execution point \n"
163: + " represented by this stack trace element.\n"
164: + " @synopsis string getPathinfo()\n"
165: + " @method getClassName\n"
166: + " Returns the fully qualified name of the class containing \n"
167: + " the execution point represented by this stack trace element.\n"
168: + " @synopsis string getClassName()\n"
169: + " @method getLine\n"
170: + " Returns the line number of the source line containing \n"
171: + " the execution point represented by this stack trace element.\n"
172: + " @synopsis int getLine()\n"
173: + " @method getModule\n"
174: + " Returns the module instance containing \n"
175: + " the execution point represented by this stack trace element.\n"
176: + " @synopsis Scope getModule()\n"
177: + " @throws AccessDenied If security policy denies access to \n"
178: + " path represented by this stack trace element\n"
179: + " @method getInstance\n"
180: + " Returns the instance of class containing \n"
181: + " the execution point represented by this stack trace element.\n"
182: + " @synopsis object getInstance()\n"
183: + " @return Instance, or undefined if the execution were not\n"
184: + " in method.\n"
185: + " @throws AccessDenied If security policy denies access to \n"
186: + " path represented by this stack trace element\n"
187: + " @method getFunctionName\n"
188: + " Returns the name of the function containing \n"
189: + " the execution point represented by this stack trace element.\n"
190: + " @synopsis string getFunctionName()\n"
191: + " @method getFunction\n"
192: + " Returns a handle to function (or method) containing \n"
193: + " the execution point represented by this stack trace element.\n"
194: + " Instance, if any, is inserted to handle as well.\n"
195: + " @synopsis Function getFunction()\n"
196: + " @throws AccessDenied If security policy denies access to \n"
197: + " path represented by this stack trace element\n"
198: //}}DOC
199: );
200: static {
201: RuntimeModule.class.getName();
202: }
203:
204: }
|