gnu.xquery.lang
Class XQuery

java.lang.Object
  extended by gnu.expr.Language
      extended by gnu.xquery.lang.XQuery
Direct Known Subclasses:
XSLT

public class XQuery
extends Language

The XQuery language.


Field Summary
static java.lang.String DEFAULT_ELEMENT_PREFIX
          Pseudo-namespace "prefix" for the default element namespace.
static java.lang.String DEFAULT_FUNCTION_PREFIX
          Pseudo-namespace "prefix" for the default function namespace.
static Namespace[] defaultFunctionNamespacePath
           
static Environment extensionsEnvEnv
          Environment of pre-defined non-standard Qexo/Kawa functions.
static QuoteExp falseExp
           
static ConstantFunction0 falseFunction
           
static XQuery instance
           
static java.lang.String KAWA_FUNCTION_NAMESPACE
           
static Namespace kawaFunctionNamespace
           
static java.lang.String LOCAL_NAMESPACE
           
static int PARSE_WITH_FOCUS
          Special parser flag used by evalToFocusProc.
static java.lang.String QEXO_FUNCTION_NAMESPACE
           
static Namespace qexoFunctionNamespace
           
static java.lang.String SCHEMA_INSTANCE_NAMESPACE
           
static java.lang.String SCHEMA_NAMESPACE
           
static QuoteExp trueExp
           
static ConstantFunction0 trueFunction
           
static int VARIADIC_FUNCTION_NAMESPACE
           
static java.lang.String XHTML_NAMESPACE
           
static Environment xqEnvironment
           
static java.lang.String XQUERY_FUNCTION_NAMESPACE
           
static Namespace xqueryFunctionNamespace
           
 
Fields inherited from class gnu.expr.Language
current, env_counter, environ, FUNCTION_NAMESPACE, NAMESPACE_PREFIX_NAMESPACE, PARSE_IMMEDIATE, PARSE_ONE_LINE, PARSE_PROLOG, requirePedantic, userEnv, VALUE_NAMESPACE
 
Constructor Summary
XQuery()
           
 
Method Summary
 java.lang.Object applyWithFocus(Procedure proc, java.lang.Object values)
          Call a procedure with each item in a sequence as the context item.
 void applyWithFocus(Procedure proc, java.lang.Object values, Consumer out)
          Call a procedure with each item in a sequence as the context item.
 java.lang.Object applyWithFocus(Procedure proc, java.lang.Object item, int position, int size)
          Call a procedure with a given focus (context).
 void applyWithFocus(Procedure proc, java.lang.Object item, int position, int size, Consumer out)
          Call a procedure with a given focus (context).
 void applyWithFocus$X(Procedure proc, java.lang.Object values, CallContext ctx)
          Call a procedure with each item in a sequence as the context item.
static char asChar(java.lang.Object x)
           
static Numeric asNumber(java.lang.Object arg)
           
protected  void define_method(java.lang.String name, java.lang.String cname, java.lang.String mname)
           
 void define(java.lang.String name, java.lang.Object value)
          Enter a value into the current environment.
 void eval_with_focus$X(java.lang.String expr, java.lang.Object values, CallContext ctx)
          Evaluate an expression with a given focus (context).
 void eval_with_focus$X(java.lang.String expr, java.lang.Object item, int position, int size, CallContext ctx)
          Evaluate an expression with a given focus (context).
 Procedure evalToFocusProc(java.io.Reader in, SourceMessages messages)
          Parse an XQuery expression from a Reader that is the body of a procedure.
 Procedure evalToFocusProc(java.lang.String expr)
          Parse an XQuery expression that is the body of a procedure.
 void evalWithFocus(java.io.Reader in, SourceMessages messages, java.lang.Object values, Consumer out)
          Evaluate an expression with each item in a sequence as the context item.
 void evalWithFocus(java.io.Reader in, SourceMessages messages, java.lang.Object item, int position, int size, Consumer out)
          Evaluate an expression with a given focus (context).
 java.lang.Object evalWithFocus(java.lang.String expr, java.lang.Object values)
          Evaluate an expression with each item in a sequence as the context item.
 java.lang.Object evalWithFocus(java.lang.String expr, java.lang.Object item, int position, int size)
          Evaluate an expression with a given focus (context).
 Compilation getCompilation(Lexer lexer, SourceMessages messages)
           
static java.lang.Object getExternal(Symbol name, java.lang.Object type)
           
static XQuery getInstance()
           
 Lexer getLexer(InPort inp, SourceMessages messages)
           
 java.lang.String getName()
           
 int getNamespaceOf(Declaration decl)
          Return the namespace (e.g value or function) of a Declaration.
 Consumer getOutputConsumer(java.io.Writer out)
           
 Procedure getPrompter()
           
static Type getStandardType(java.lang.String name)
           
 Symbol getSymbol(java.lang.String name)
           
 Type getTypeFor(java.lang.Class clas)
           
 Type getTypeFor(java.lang.String name)
           
 boolean hasNamespace(Declaration decl, int namespace)
          True if a Declaration is in the specified namespace.
 boolean hasSeparateFunctionNamespace()
          True if functions are in a separate anme space from variable.
 boolean isTrue(java.lang.Object value)
          Test if a value is considered "true" in this language.
static java.lang.String makeClassName(java.lang.String source)
           
static java.lang.String mangle(java.lang.String name)
           
static int namespaceForFunctions(int argCount)
           
 boolean parse(Compilation tr, int options)
           
static void registerEnvironment()
          The compiler insert calls to this method for applications and applets.
 void resolve(Compilation comp)
          Perform any need post-processing after we've read all the modules to be compiled.
 
Methods inherited from class gnu.expr.Language
asType, booleanObject, coerceFromObject, coerceToObject, coerceToObject, declFromField, defAliasStFld, defineFunction, defineFunction, defProcStFld, defProcStFld, detect, detect, detect, emitCoerceToBoolean, emitPushBoolean, eval, eval, eval, eval, eval, eval, eval, eval, eval, getDefaultLanguage, getEnvironment, getEnvPropertyFor, getEnvPropertyFor, getFormat, getInstance, getInstance, getInstanceFromFilenameExtension, getLangEnvironment, getLangTypeFor, getLanguages, getNewEnvironment, getTypeFor, getTypeFor, getTypeFor, loadClass, lookup, lookupBuiltin, noValue, parse, parse, parse, registerLanguage, runAsApplication, setDefaultLanguage, setDefaults, string2Type
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

XQUERY_FUNCTION_NAMESPACE

public static final java.lang.String XQUERY_FUNCTION_NAMESPACE
See Also:
Constant Field Values

KAWA_FUNCTION_NAMESPACE

public static final java.lang.String KAWA_FUNCTION_NAMESPACE
See Also:
Constant Field Values

QEXO_FUNCTION_NAMESPACE

public static final java.lang.String QEXO_FUNCTION_NAMESPACE
See Also:
Constant Field Values

LOCAL_NAMESPACE

public static final java.lang.String LOCAL_NAMESPACE
See Also:
Constant Field Values

SCHEMA_NAMESPACE

public static final java.lang.String SCHEMA_NAMESPACE
See Also:
Constant Field Values

SCHEMA_INSTANCE_NAMESPACE

public static final java.lang.String SCHEMA_INSTANCE_NAMESPACE
See Also:
Constant Field Values

XHTML_NAMESPACE

public static final java.lang.String XHTML_NAMESPACE
See Also:
Constant Field Values

xqueryFunctionNamespace

public static final Namespace xqueryFunctionNamespace

kawaFunctionNamespace

public static final Namespace kawaFunctionNamespace

qexoFunctionNamespace

public static final Namespace qexoFunctionNamespace

defaultFunctionNamespacePath

public static final Namespace[] defaultFunctionNamespacePath

DEFAULT_ELEMENT_PREFIX

public static final java.lang.String DEFAULT_ELEMENT_PREFIX
Pseudo-namespace "prefix" for the default element namespace.


DEFAULT_FUNCTION_PREFIX

public static final java.lang.String DEFAULT_FUNCTION_PREFIX
Pseudo-namespace "prefix" for the default function namespace.

See Also:
Constant Field Values

PARSE_WITH_FOCUS

public static final int PARSE_WITH_FOCUS
Special parser flag used by evalToFocusProc.

See Also:
Constant Field Values

VARIADIC_FUNCTION_NAMESPACE

public static final int VARIADIC_FUNCTION_NAMESPACE
See Also:
Constant Field Values

extensionsEnvEnv

public static Environment extensionsEnvEnv
Environment of pre-defined non-standard Qexo/Kawa functions.


xqEnvironment

public static final Environment xqEnvironment

instance

public static final XQuery instance

falseExp

public static QuoteExp falseExp

trueExp

public static QuoteExp trueExp

falseFunction

public static final ConstantFunction0 falseFunction

trueFunction

public static final ConstantFunction0 trueFunction
Constructor Detail

XQuery

public XQuery()
Method Detail

hasSeparateFunctionNamespace

public boolean hasSeparateFunctionNamespace()
Description copied from class: Language
True if functions are in a separate anme space from variable. Is true for e.g. Common Lisp, Emacs Lisp; false for Scheme.

Overrides:
hasSeparateFunctionNamespace in class Language

asNumber

public static Numeric asNumber(java.lang.Object arg)

asChar

public static char asChar(java.lang.Object x)

isTrue

public boolean isTrue(java.lang.Object value)
Description copied from class: Language
Test if a value is considered "true" in this language.

Overrides:
isTrue in class Language

getLexer

public Lexer getLexer(InPort inp,
                      SourceMessages messages)
Specified by:
getLexer in class Language

getCompilation

public Compilation getCompilation(Lexer lexer,
                                  SourceMessages messages)
Overrides:
getCompilation in class Language

parse

public boolean parse(Compilation tr,
                     int options)
              throws java.io.IOException,
                     SyntaxException
Specified by:
parse in class Language
Throws:
java.io.IOException
SyntaxException

resolve

public void resolve(Compilation comp)
Description copied from class: Language
Perform any need post-processing after we've read all the modules to be compiled. Using a separate pass allows compiling mutually recursive modules.

Overrides:
resolve in class Language

namespaceForFunctions

public static int namespaceForFunctions(int argCount)

getNamespaceOf

public int getNamespaceOf(Declaration decl)
Description copied from class: Language
Return the namespace (e.g value or function) of a Declaration. Return a bitmask of all the namespaces "covered" by the Declaration. Note this isn't a namespace in the XML sense; if a Declaration has a specific namespace URI, then that is part of its symbol. This namespace bitmap is a separate dimension, for the use of languages that have separate namespaces for different kinds of declarations, such as variables and functions.

Overrides:
getNamespaceOf in class Language

hasNamespace

public boolean hasNamespace(Declaration decl,
                            int namespace)
Description copied from class: Language
True if a Declaration is in the specified namespace.

Overrides:
hasNamespace in class Language
namespace - normally a bitmask as returned by getNamespaceOf.

getSymbol

public Symbol getSymbol(java.lang.String name)
Overrides:
getSymbol in class Language

define

public void define(java.lang.String name,
                   java.lang.Object value)
Description copied from class: Language
Enter a value into the current environment.

Overrides:
define in class Language

define_method

protected void define_method(java.lang.String name,
                             java.lang.String cname,
                             java.lang.String mname)

getName

public java.lang.String getName()
Overrides:
getName in class Language

applyWithFocus

public void applyWithFocus(Procedure proc,
                           java.lang.Object item,
                           int position,
                           int size,
                           Consumer out)
                    throws java.lang.Throwable
Call a procedure with a given focus (context).

Parameters:
proc - a 3-operand Procedure as returned by evalToFocusProc
item - the context item, passed as the first argument to proc
position - the context position, passed as the second argument
size - the context size, passed as the second argument
out - where to send the result of proc
Throws:
java.lang.Throwable

applyWithFocus

public java.lang.Object applyWithFocus(Procedure proc,
                                       java.lang.Object item,
                                       int position,
                                       int size)
                                throws java.lang.Throwable
Call a procedure with a given focus (context).

Parameters:
proc - a 3-operand Procedure as returned by evalToFocusProc
item - the context item, passed as the first argument to proc
position - the context position, passed as the second argument
size - the context size, passed as the second argument
Returns:
the result of applying proc
Throws:
java.lang.Throwable

applyWithFocus

public void applyWithFocus(Procedure proc,
                           java.lang.Object values,
                           Consumer out)
                    throws java.lang.Throwable
Call a procedure with each item in a sequence as the context item.

Parameters:
proc - a 3-operand Procedure as returned by evalToFocusProc
values - a sequence. The proc is called once for each item, with the item as the first argument, a 1-based index as the second argument, and the sequence size as the third argument.
out - where to send the result of proc
Throws:
java.lang.Throwable

applyWithFocus

public java.lang.Object applyWithFocus(Procedure proc,
                                       java.lang.Object values)
                                throws java.lang.Throwable
Call a procedure with each item in a sequence as the context item.

Parameters:
proc - a 3-operand Procedure as returned by evalToFocusProc
values - a sequence. The proc is called once for each item, with the item as the first argument, a 1-based index as the second argument, and the sequence size as the third argument.
Returns:
the result of applying proc
Throws:
java.lang.Throwable

applyWithFocus$X

public void applyWithFocus$X(Procedure proc,
                             java.lang.Object values,
                             CallContext ctx)
                      throws java.lang.Throwable
Call a procedure with each item in a sequence as the context item.

Parameters:
proc - a 3-operand Procedure as returned by evalToFocusProc
values - a sequence. The proc is called once for each item, with the item as the first argument, a 1-based index as the second argument, and the sequence size as the third argument.
ctx - the CallContext. The $X in the method name tells Kawa that this argument is implicit when invoked from XQuery.
Throws:
java.lang.Throwable

evalToFocusProc

public Procedure evalToFocusProc(java.lang.String expr)
                          throws java.lang.Throwable
Parse an XQuery expression that is the body of a procedure. Helper method used by evalWithFocus methods.

Parameters:
expr - an XQuery expression (query) to evaluate
Returns:
a 3-operand Procedure whose arguments become the context item, position, and size.
Throws:
java.lang.Throwable

evalToFocusProc

public Procedure evalToFocusProc(java.io.Reader in,
                                 SourceMessages messages)
                          throws java.lang.Throwable
Parse an XQuery expression from a Reader that is the body of a procedure. Helper method used by evalWithFocus methods.

Parameters:
in - where we read the expression from
messages - where to write syntax errors
Returns:
a 3-operand Procedure whose arguments become the context item, position, and size.
Throws:
java.lang.Throwable

evalWithFocus

public void evalWithFocus(java.io.Reader in,
                          SourceMessages messages,
                          java.lang.Object values,
                          Consumer out)
                   throws java.lang.Throwable
Evaluate an expression with each item in a sequence as the context item.

Parameters:
in - where we read the expression from
messages - where to write syntax errors
values - becomes the context sequence while evaluating expr.
out - where to send the result of the expression
Throws:
java.lang.Throwable

evalWithFocus

public java.lang.Object evalWithFocus(java.lang.String expr,
                                      java.lang.Object values)
                               throws java.lang.Throwable
Evaluate an expression with each item in a sequence as the context item.

Parameters:
expr - an XQuery expression (query) to evaluate
values - becomes the context sequence while evaluating the expression
Returns:
the result of evaluating the expression
Throws:
java.lang.Throwable

evalWithFocus

public java.lang.Object evalWithFocus(java.lang.String expr,
                                      java.lang.Object item,
                                      int position,
                                      int size)
                               throws java.lang.Throwable
Evaluate an expression with a given focus (context).

Parameters:
expr - an XQuery expression (query) to evaluate
item - becomes the context item while evaluating expr.
position - becomes the context position
size - becomes the context size
Returns:
the result of evaluating expr
Throws:
java.lang.Throwable

evalWithFocus

public void evalWithFocus(java.io.Reader in,
                          SourceMessages messages,
                          java.lang.Object item,
                          int position,
                          int size,
                          Consumer out)
                   throws java.lang.Throwable
Evaluate an expression with a given focus (context).

Parameters:
in - where we read the expression from
messages - where to write syntax errors
item - becomes the context item while evaluating the expression
position - becomes the context position
size - becomes the context size
out - where to send the result of the expression
Throws:
java.lang.Throwable

eval_with_focus$X

public void eval_with_focus$X(java.lang.String expr,
                              java.lang.Object values,
                              CallContext ctx)
                       throws java.lang.Throwable
Evaluate an expression with a given focus (context). Similar to evalWithFocus(String, Object, Consumer). The "$X" in the method name tells the Kawa compiler that the CallContext argument is implicit, so it can be invoked from XQuery code thus: XQuery:eval-with-focus($xquery, "expr", $sequence)

Throws:
java.lang.Throwable

eval_with_focus$X

public void eval_with_focus$X(java.lang.String expr,
                              java.lang.Object item,
                              int position,
                              int size,
                              CallContext ctx)
                       throws java.lang.Throwable
Evaluate an expression with a given focus (context). Similar to evalWithFocus(String, Object, int, int, Consumer). The "$X" in the method name tells the Kawa compiler that the CallContext argument is implicit, so it can be invoked from XQuery code thus: XQuery:eval-with-focus($xquery, "expr", $item, $pos, $size)

Throws:
java.lang.Throwable

getInstance

public static XQuery getInstance()

registerEnvironment

public static void registerEnvironment()
The compiler insert calls to this method for applications and applets.


getOutputConsumer

public Consumer getOutputConsumer(java.io.Writer out)
Overrides:
getOutputConsumer in class Language

getStandardType

public static Type getStandardType(java.lang.String name)

getTypeFor

public Type getTypeFor(java.lang.String name)
Overrides:
getTypeFor in class Language

getTypeFor

public Type getTypeFor(java.lang.Class clas)
Overrides:
getTypeFor in class Language

getPrompter

public Procedure getPrompter()
Overrides:
getPrompter in class Language

mangle

public static java.lang.String mangle(java.lang.String name)

makeClassName

public static java.lang.String makeClassName(java.lang.String source)

getExternal

public static java.lang.Object getExternal(Symbol name,
                                           java.lang.Object type)