de.dante.extex.interpreter.primitives.dynamic
Class NativeDef

java.lang.Object
  extended byde.dante.extex.interpreter.type.AbstractCode
      extended byde.dante.extex.interpreter.type.AbstractAssignment
          extended byde.dante.extex.interpreter.primitives.dynamic.NativeDef
All Implemented Interfaces:
Code, Configurable, Localizable, LogEnabled, java.io.Serializable

public class NativeDef
extends AbstractAssignment
implements Configurable, LogEnabled

This primitive provides a binding of a macro or active character to code in some programming language. This code implements the primitive \nativedef.

The Primitive \nativedef

The primitive \nativedef assigns a definition to a macro or active character. This is done in a similar way as \def works. The difference is that the definition has to be provided in form of a Java class which glues in native code.

Syntax

The general form of this primitive is
   ⟨nativedef⟩
       → \nativedef ⟨type⟩ ⟨control sequence⟩ ⟨name⟩  

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. This appropriate class is loaded if needed and instantiated. The instance is bound as code to the ⟨control sequence⟩.

The ⟨control sequence⟩ is any macro or active character. If this token is missing or of the wrong type then an error is raised.

The ⟨name⟩ 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 passed to the binding class to specify the target. For instance the Java binding requires this to be name of the Java class implementing the functionality.

The primitive \nativedef is local to the enclosing group as is \def. And similar to \def the modifier \global can be used to make the definition in all groups instead of the current group only.

The primitive \nativedef also respects the count register \globaldefs to enable general global assignment.

Since the primitive is classified as assignment the value of \afterassignment is applied.

Examples

    \nativedef{java}\x{my.primitive.MyPrimitive}  

This example shows how the control sequence \x is bound to the Java class my.primitive.MyPrimitive. This definition is local to the current group.

    \global\nativedef{java}\x{my.primitive.MyPrimitive}  

This example shows how the control sequence \x is bound to the Java class my.primitive.MyPrimitive. This definition is performed globally.

Configuration

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="nativedef"
          class="de.dante.extex.interpreter.primitives.dynamic.NativeDef">
    <load name="java"
          class="de.dante.extex.interpreter.primitives.dynamic.java.JavaDef"/>
  </define>
 

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.

Version:
$Revision: 1.12 $
Author:
Gerd Neugebauer
See Also:
Serialized Form

Nested Class Summary
protected  class NativeDef.Factory
          This inner class provides access to the functionality of an abstract factory.
 
Field Summary
protected static long serialVersionUID
          The constant serialVersionUID contains the id for serialization.
 
Constructor Summary
NativeDef(java.lang.String codeName)
          Creates a new object.
 
Method Summary
 void assign(Flags prefix, Context context, TokenSource source, Typesetter typesetter)
          The method assign is the core of the functionality of execute().
 void configure(Configuration config)
          Configure an object according to a given Configuration.
 void enableLogging(java.util.logging.Logger theLogger)
          Setter for the logger.
protected  java.util.logging.Logger getLogger()
          Getter for logger.
 
Methods inherited from class de.dante.extex.interpreter.type.AbstractAssignment
execute
 
Methods inherited from class de.dante.extex.interpreter.type.AbstractCode
enableLocalization, getLocalizer, getName, isIf, isOuter, printable, printableControlSequence, readResolve, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

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

See Also:
Constant Field Values
Constructor Detail

NativeDef

public NativeDef(java.lang.String codeName)
Creates a new object.

Parameters:
codeName - the name of the primitive
Method Detail

assign

public void assign(Flags prefix,
                   Context context,
                   TokenSource source,
                   Typesetter typesetter)
            throws InterpreterException
Description copied from class: AbstractAssignment
The method assign is the core of the functionality of execute(). This method is preferable to execute() since the execute() method provided in this class takes care of \afterassignment and \globaldefs as well.

Specified by:
assign in class AbstractAssignment
Parameters:
prefix - the prefix controlling the execution
context - the interpreter context
source - the token source
typesetter - the typesetter
Throws:
InterpreterException - in case of an error
See Also:
AbstractAssignment.assign( de.dante.extex.interpreter.Flags, de.dante.extex.interpreter.context.Context, de.dante.extex.interpreter.TokenSource, de.dante.extex.typesetter.Typesetter)

configure

public void configure(Configuration config)
               throws ConfigurationException
Description copied from interface: Configurable
Configure an object according to a given Configuration.

Specified by:
configure in interface Configurable
Parameters:
config - the configuration object to consider
Throws:
ConfigurationException - in case that something went wrong
See Also:
Configurable.configure( de.dante.util.framework.configuration.Configuration)

enableLogging

public void enableLogging(java.util.logging.Logger theLogger)
Description copied from interface: LogEnabled
Setter for the logger.

Specified by:
enableLogging in interface LogEnabled
Parameters:
theLogger - the logger to use
See Also:
LogEnabled.enableLogging( java.util.logging.Logger)

getLogger

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

Returns:
the logger