001: /*
002: * @(#)init.java 1.5 05/06/14
003: *
004: * Copyright (c) 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
005: *
006: * See the file "LICENSE.txt" for information on usage and redistribution
007: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
008: */
009: package pnuts.lib;
010:
011: import pnuts.lang.Context;
012: import pnuts.lang.Package;
013: import pnuts.ext.ModuleBase;
014: import org.pnuts.lib.*;
015:
016: /**
017: * Initialization of the pnuts.lib module.
018: */
019: public class init extends ModuleBase {
020:
021: static String[] files = { "pnuts/lib/console", "pnuts/lib/package",
022: "pnuts/lib/array", "pnuts/lib/i18n", "pnuts/lib/system",
023: "pnuts/lib/collection", "org/pnuts/lib/calendar",
024: "org/pnuts/lib/modifiers" };
025:
026: static String[][] functions = {
027: // pnuts/lib/console
028: { "getWriter", "getErrorWriter", "error", },
029: // pnuts/lib/package
030: { "createPackage", "$" },
031: // pnuts/lib/array
032: { "rsort", "collect", },
033: // pnuts/lib/i18n
034: { "formatMessage", "getResourceBundle",
035: "getLocalizedResource" },
036: // pnuts/lib/system
037: { "setVerbose", "addShutdownHook", "removeShutdownHook" },
038: // pnuts/lib/collection
039: { "vector", "hashTable" },
040: // pnuts/lib/calendar
041: { "getYear", "getMonth", "getWeekOfYear", "getDayOfYear",
042: "getDayOfMonth", "getDayOfWeek", "getHour",
043: "getMinute", "getSecond", "getMillisecond",
044: "getMaxDayOfYear", "getMaxDayOfMonth", "addYear",
045: "addMonth", "addWeek", "addDay", "addHour",
046: "addMinute", "addSecond", "addMillisecond",
047: "diffYear", "diffMonth", "diffWeek", "diffDay",
048: "diffHour", "diffMinute", "diffSecond",
049: "diffMillisecond" },
050: { "isPublic", "isProtected", "isPrivate", "isAbstract",
051: "isInterface", "isStatic" } };
052:
053: static String[] javaFunctions = { "print", "println", "exit",
054: "arraycopy", "string", "hex", "include", "includeFile",
055: "format", "isFunction", "isGenerator", "iterable",
056: "isArray", "random", "memcache", "LRUcache",
057: "applyFunction", "call", "mapFunction", "project",
058: "rootScope", "filter", "reduce", "size", "count", "list",
059: "set", "map", "reverse", "push", "pop", "shift", "unshift",
060: "contains", "mapget", "mapput", "isEmpty", "getFile",
061: "basename", "dirname", "getURL", "getURI", "write",
062: "flush", "sort", "compile", "parse", "unparse", "run",
063: "date", "setFormatLocale", "getResource", "isCompiled",
064: "makeProxy", "subclass", "javaAdapter", "beanclass",
065: "currentTimeMillis", "printAll", "getTimeZone",
066: "setTimeZone", "getMaxDayOfMonth", "getMaxDayOfYear",
067: "getLocale", "setLocale", "formatDate", "formatTime",
068: "formatDateTime", "isJava2", "classGenerator",
069: "setFinalizer", "getPackage", "findPackage",
070: "removePackage", "aggregateMode", "constant", "join",
071: "generator", "identical", "binarySearch", "schedule",
072: "range", "formatNumber", "formatCurrency", "formatPercent",
073: "toLowerCase", "toUpperCase", "getClassPath",
074: "setClassPath", "addClassPath" };
075:
076: protected String getPrefix() {
077: return "org";
078: }
079:
080: public Object execute(Context context) {
081: context.clearPackages();
082: for (int i = 0; i < files.length; i++) {
083: autoload(functions[i], files[i], context);
084: }
085:
086: for (int i = 0; i < javaFunctions.length; i++) {
087: autoloadFunction(javaFunctions[i], context);
088: }
089: Package pkg = getPackage(context);
090: String FINALLY = "finally".intern();
091: pkg.set(FINALLY, new _finally(), context);
092: pkg.export(FINALLY);
093:
094: String INTERFACE = "interface".intern();
095: pkg.set(INTERFACE, new _interface(), context);
096: pkg.export(INTERFACE);
097:
098: return null;
099: }
100: }
|