|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.extex.interpreter.type.AbstractCode
org.extex.interpreter.type.AbstractAssignment
org.extex.unit.dynamic.java.JavaDef
public class JavaDef
This primitive provides a binding of a macro or active character to Java
code. This code implements the primitive \javadef.
The primitive \javadef attaches 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.
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 〈tokens〉 is any specification of a list of tokens like
a constant list enclosed in braces or a tokens register. The value of these
tokens are taken and interpreted as the name of a Java class. This class is
loaded if needed and instantiated. The instance is bound as code to the
〈control sequence〉.
The following example illustrates the use of this primitive:
The Primitive \javadef
Syntax
The general form of this primitive is
〈javadef〉
→ \javadef 〈control sequence〉 〈tokens〉
\javadef\abc{org.extex.interpreter.primitive.Relax}
The primitive \javadef 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. This is shown in the following example:
\global\javadef\abc{org.extex.interpreter.primitive.Relax}
The primitive \javadef also respects the count register \globaldefs to enable general global assignment.
Since the primitive is classified as assignment the value of \afterassignment is applied.
Now we come to the Java side of the definition. The class given as
〈tokens〉 must implement the interface Code. The easiest way to achieve this is by
declaring a class derived from
AbstractCode.
package my.package;
import org.extex.interpreter.type.AbstractCode;
import org.extex.interpreter.contect.Context;
import org.extex.interpreter.Flags;
import org.extex.interpreter.TokenSource;
import org.extex.typesetter.Typesetter;
import de.dante.util.GeneralException;
class MyPrimitive extends AbstractCode {
public MyPrimitive(final String name) {
super(name);
// initialization code – if required
}
public boolean execute(final Flags prefix,
final Context context,
final TokenSource source,
final Typesetter typesetter
) {
// implement the execution behavior here
return true;
}
}
There is more to say about primitives like how to write expandable primitives or ifs. Those details can be found in section Primitives.
| Field Summary | |
|---|---|
protected static long |
serialVersionUID
The constant serialVersionUID contains the id for serialization. |
| Constructor Summary | |
|---|---|
JavaDef()
Creates a new object. |
|
JavaDef(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 |
define(Flags prefix,
Context context,
TokenSource source,
Typesetter typesetter)
Perform a define operation |
| 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 |
|---|
protected static final long serialVersionUID
| Constructor Detail |
|---|
public JavaDef()
public JavaDef(CodeToken token)
token - the initial token for the primitive| Method Detail |
|---|
public void assign(Flags prefix,
Context context,
TokenSource source,
Typesetter typesetter)
throws HelpingException,
TypesetterException
execute().
This method is preferable to execute() since the
execute() method provided in this class takes care of
\afterassignment and \globaldefs as well.
assign in class AbstractAssignmentprefix - the prefix controlling the executioncontext - the interpreter contextsource - the token sourcetypesetter - the typesetter
HelpingException - in case of an error
TypesetterException - in case of an error in the typesetterAbstractAssignment.assign(
org.extex.interpreter.Flags, org.extex.interpreter.context.Context,
org.extex.interpreter.TokenSource, org.extex.typesetter.Typesetter)
public void define(Flags prefix,
Context context,
TokenSource source,
Typesetter typesetter)
throws HelpingException,
TypesetterException
define in interface Definerprefix - the flagscontext - the interpreter contextsource - the source for new tokenstypesetter - the typesetter
HelpingException - in case of an error
TypesetterException - in case of an error in the typesetterDefiner.define(org.extex.interpreter.Flags,
org.extex.interpreter.context.Context,
org.extex.interpreter.TokenSource, org.extex.typesetter.Typesetter)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||