001: /*
002: * BlendExtension.java --
003: *
004: * This extension encapsulates the java::* commands.
005: *
006: * Copyright (c) 1997-1998 by Sun Microsystems, Inc.
007: *
008: * See the file "license.terms" for information on usage and redistribution
009: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
010: *
011: * RCS: @(#) $Id: BlendExtension.java,v 1.26 2007/06/07 20:52:15 mdejong Exp $
012: */
013:
014: package tcl.lang;
015:
016: public class BlendExtension extends Extension {
017:
018: /*
019: *----------------------------------------------------------------------
020: *
021: * init --
022: *
023: * Initialize the java pacakge.
024: *
025: * Results:
026: * None.
027: *
028: * Side effects:
029: * Creates the java namespace and java::* commands.
030: *
031: *----------------------------------------------------------------------
032: */
033:
034: public void init(Interp interp) // Interpreter to intialize.
035: throws TclException {
036: if (interp.getCommand("java::new") != null) {
037: throw new TclRuntimeError(
038: "BlendExtension.init() invoked twice in same interp");
039: }
040:
041: // Create the commands in the Java package
042:
043: loadOnDemand(interp, "java::bind", "tcl.lang.JavaBindCmd");
044: loadOnDemand(interp, "java::call", "tcl.lang.JavaCallCmd");
045: loadOnDemand(interp, "java::cast", "tcl.lang.JavaCastCmd");
046: loadOnDemand(interp, "java::defineclass",
047: "tcl.lang.JavaDefineClassCmd");
048: loadOnDemand(interp, "java::event", "tcl.lang.JavaEventCmd");
049: loadOnDemand(interp, "java::field", "tcl.lang.JavaFieldCmd");
050: loadOnDemand(interp, "java::for", "tcl.lang.JavaForCmd");
051: loadOnDemand(interp, "java::getinterp",
052: "tcl.lang.JavaGetInterpCmd");
053: loadOnDemand(interp, "java::import", "tcl.lang.JavaImportCmd");
054: loadOnDemand(interp, "java::info", "tcl.lang.JavaInfoCmd");
055: loadOnDemand(interp, "java::instanceof",
056: "tcl.lang.JavaInstanceofCmd");
057: loadOnDemand(interp, "java::isnull", "tcl.lang.JavaIsNullCmd");
058: loadOnDemand(interp, "java::load", "tcl.lang.JavaLoadCmd");
059: loadOnDemand(interp, "java::new", "tcl.lang.JavaNewCmd");
060: loadOnDemand(interp, "java::null", "tcl.lang.JavaNullCmd");
061: loadOnDemand(interp, "java::prop", "tcl.lang.JavaPropCmd");
062: loadOnDemand(interp, "java::throw", "tcl.lang.JavaThrowCmd");
063: loadOnDemand(interp, "java::try", "tcl.lang.JavaTryCmd");
064:
065: // Set up namespace exporting of these java commands.
066: // FIXME : double check that this works with one demand loaded clases.
067:
068: interp
069: .eval("namespace eval ::java {namespace export bind call cast defineclass event field getinterp import info instanceof isnull load new null prop throw try}");
070:
071: // load unsupported command(s)
072: loadOnDemand(interp, "unsupported::jdetachcall",
073: "tcl.lang.UnsupportedJDetachCallCmd");
074:
075: // Part of the java package is defined in Tcl code. We source
076: // in that code now.
077:
078: interp.evalResource("/tcl/lang/library/java/javalock.tcl");
079:
080: // Set up the tcljava array which will store info about
081: // The system that scripts may want to access to.
082:
083: // Set tcljava(tcljava) to jacl or tclblend
084:
085: TclObject plat = interp.getVar("tcl_platform", "platform",
086: TCL.GLOBAL_ONLY);
087:
088: if (plat.toString().equals("java")) {
089: interp.setVar("tcljava", "tcljava", TclString
090: .newInstance("jacl"), TCL.GLOBAL_ONLY);
091: } else {
092: interp.setVar("tcljava", "tcljava", TclString
093: .newInstance("tclblend"), TCL.GLOBAL_ONLY);
094: }
095:
096: // set tcljava(java.version) to the JVM version number
097:
098: interp.setVar("tcljava", "java.version", TclString
099: .newInstance(System.getProperty("java.version")),
100: TCL.GLOBAL_ONLY);
101:
102: // set tcljava(java.home) to the root of the JVM install
103:
104: interp.setVar("tcljava", "java.home", TclString
105: .newInstance(System.getProperty("java.home")),
106: TCL.GLOBAL_ONLY);
107:
108: // set tcljava(java.vendor) to the info from the JVM provider
109:
110: interp.setVar("tcljava", "java.vendor", TclString
111: .newInstance(System.getProperty("java.vendor")),
112: TCL.GLOBAL_ONLY);
113:
114: // set tcljava(java.vendor.url) to the info from the JVM provider
115:
116: interp.setVar("tcljava", "java.vendor.url", TclString
117: .newInstance(System.getProperty("java.vendor.url")),
118: TCL.GLOBAL_ONLY);
119:
120: // set tcljava(java.vendor.url.bug) to the info from the JVM provider
121:
122: interp.setVar("tcljava", "java.vendor.url.bug",
123: TclString.newInstance(System
124: .getProperty("java.vendor.url.bug")),
125: TCL.GLOBAL_ONLY);
126:
127: // Provide the Tcl/Java package with the version info.
128: // The version is also set in:
129: // src/jacl/tcl/lang/Interp.java
130: // src/pkgIndex.tcl
131: // win/makefile.vc
132: // unix/configure.in
133:
134: interp.eval("package provide java 1.4.1");
135:
136: }
137:
138: } // end BlendExtension
|