## org.extex.unit.dynamic Class NativeDef

java.lang.Object
org.extex.interpreter.type.AbstractCode
org.extex.interpreter.type.AbstractAssignment
org.extex.unit.dynamic.NativeDef

All Implemented Interfaces:
java.io.Serializable, Configurable, LogEnabled, Code

public class NativeDefextends AbstractAssignmentimplements 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="org.extex.interpreter.primitives.dynamic.NativeDef">
</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: 7371$
Author:
Gerd Neugebauer
Serialized Form

Nested Class Summary
protected static 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(CodeToken token)
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 log)
Setter for the logger.
protected  java.util.logging.Logger getLogger()
Getter for logger.

Methods inherited from class org.extex.interpreter.type.AbstractAssignment
execute

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

### serialVersionUID

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

Constant Field Values
Constructor Detail

### NativeDef

public NativeDef(CodeToken token)
Creates a new object.

Parameters:
token - the initial token for the primitive
Method Detail

### assign

public void assign(Flags prefix,
Context context,
TokenSource source,
Typesetter typesetter)
throws ConfigurationException,
HelpingException,
TypesetterException
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:
ConfigurationException - in case of an configuration error
HelpingException - in case of an error
TypesetterException - in case of an error in the typesetter
AbstractAssignment.assign(org.extex.interpreter.Flags, org.extex.interpreter.context.Context, org.extex.interpreter.TokenSource, org.extex.typesetter.Typesetter)

### configure

public void configure(Configuration config)
throws ConfigurationException
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
Configurable.configure(org.extex.framework.configuration.Configuration)

### enableLogging

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

Specified by:
enableLogging in interface LogEnabled
Parameters:
log - the logger to use
LogEnabled.enableLogging(java.util.logging.Logger)
protected java.util.logging.Logger getLogger()