Class NativeLoad

  extended by org.extex.interpreter.type.AbstractCode
      extended by org.extex.unit.dynamic.NativeLoad
All Implemented Interfaces:, Configurable, LogEnabled, Code

public class NativeLoad
extends AbstractCode
implements Configurable, LogEnabled

This primitive initiates the loading of native code and implements the primitive \nativeload.

The Primitive \nativeload

The primitive \nativeload loads some native language code. As parameter the type of the native extension and a specification of the loader to be used are given.

With this method it is possible to load larger extensions of ExTeX in one junk. There is no need to declare each single macro with \def. It is even possible to define extension macros in other programming languages than the TeX language.


The general form of this primitive is
      → \nativeload ⟨type⟩ ⟨tokens⟩ 

The ⟨type⟩ is any specification of a list of tokens like a constant list enclosed in braces or a token register. The value of these tokens are taken and resolved via the configuration.

The ⟨tokens⟩ is any specification of a list of tokens like a constant list enclosed in braces or a tokens register. For the Java loader the value of these tokens are taken and interpreted as the name of a Java class. This class is loaded if needed, instantiated, and its method init() is invoked. The instantiation requires the empty constructor to be visible.


The following example illustrates the use of this primitive:


For the loading of the Java class it is necessary that this Java class implements the interface Loadable.

 package my.package;
 import org.extex.interpreter.context.Context;
 import org.extex.typesetter.Typesetter;
 import org.extex.util.exception.GeneralException;
 class MyModule implements Loadable {
     public MyModule() {
         // initialization code – if required
     public void init(final Context context, final Typesetter
 typesetter )
         throws GeneralException {
             // implement the initialization code here


The supported types are determined in the configuration of the unit which defines the primitive. Here a mapping is specified assigning a binding class for each supported type. Thus it is possible to configure in the support for several extension types. Currently a binding for Java is provided. In the future other languages can be added easily.

 <define name="nativeload"
   <load name="java"

The body of the define tag for the primitive may contain an arbitrary number of load sections. Each load has the attribute name and class. The attribute name determines the type. This corresponds to the type given in the first argument of the primitive invocation.

The class attribute names the class which provides the binding to the target programming language.

$Revision: 7371 $
Gerd Neugebauer
See Also:
Serialized Form

Field Summary
protected static long serialVersionUID
          The constant serialVersionUID contains the id for serialization.
Constructor Summary
NativeLoad(CodeToken token)
          Creates a new object.
Method Summary
 void configure(Configuration config)
          Configure an object according to a given Configuration.
 void enableLogging(java.util.logging.Logger log)
          Setter for the logger.
 void execute(Flags prefix, Context context, TokenSource source, Typesetter typesetter)
          This method takes the first token and executes it.
protected  java.util.logging.Logger getLogger()
          Getter for logger.
Methods inherited from class org.extex.interpreter.type.AbstractCode
getLocalizer, getName, getToken, isIf, isOuter, readResolve, toString, toText, toText
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

Field Detail


protected static final long serialVersionUID
The constant serialVersionUID contains the id for serialization.

See Also:
Constant Field Values
Constructor Detail


public NativeLoad(CodeToken token)
Creates a new object.

token - the initial token for the primitive
Method Detail


public void configure(Configuration config)
               throws ConfigurationException
Configure an object according to a given Configuration.

Specified by:
configure in interface Configurable
config - the configuration object to consider
ConfigurationException - in case that something went wrong
See Also:


public void enableLogging(java.util.logging.Logger log)
Setter for the logger.

Specified by:
enableLogging in interface LogEnabled
log - the logger to use
See Also:


public void execute(Flags prefix,
                    Context context,
                    TokenSource source,
                    Typesetter typesetter)
             throws HelpingException,
This method takes the first token and executes it. The result is placed on the stack. This operation might have side effects. To execute a token it might be necessary to consume further tokens.

Specified by:
execute in interface Code
execute in class AbstractCode
prefix - the prefix controlling the execution
context - the interpreter context
source - the token source
typesetter - the typesetter
HelpingException - in case of an error
TypesetterException - in case of an error in the typesetter
See Also:
AbstractCode.execute(org.extex.interpreter.Flags, org.extex.interpreter.context.Context, org.extex.interpreter.TokenSource, org.extex.typesetter.Typesetter)


protected java.util.logging.Logger getLogger()
Getter for logger.

the logger