condor.classad
Class ClassAd

Object
  extended bycondor.classad.ClassAd

public class ClassAd
extends Object

A library of handy methods for manipulating classad expressions. The class contains only static methods for performing various operations on classified advertisements. See Expr and its various subclasses, especially RecordExpr for the actual objects that are manipulated.

Version:
2.2
Author:
Marvin Solomon
See Also:
Expr, RecordExpr

Method Summary
static RecordExpr bind(RecordExpr ad1, RecordExpr ad2)
          Wrap a pair of ads in an environment defining "self" and "other".
static Constant constant(double x)
          Create a constant expression from a real value.
static Constant constant(int i)
          Create a constant expression from an integer value.
static Constant constant(String s)
          Create a constant expression from a String value.
static Expr eval(RecordExpr ad, String attr)
          Evaluate a selection from a ClassAd.
static Expr eval(RecordExpr ad, String[] attrs)
          Evaluate a selection from a ClassAd.
static Expr eval(String name, Expr expr, RecordExpr ad)
          Evaluate an expression in the context of a ClassAd.
static Expr eval(String attr, RecordExpr ad1, RecordExpr ad2)
          Evaluate an attribute of a ClassAd in an environment consisting of a pair of ads.
static boolean loadJavaLibrary(String className)
          Loads a "library" of externally defined Java functions.
static int[] match(Expr expr1, Expr expr2)
          Match two ClassAds.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

bind

public static RecordExpr bind(RecordExpr ad1,
                              RecordExpr ad2)
Wrap a pair of ads in an environment defining "self" and "other". The result is the classad
     env = [
          Ad1 = [ other = Ad2.self; self = ad1 ]
          Ad2 = [ other = Ad1.self; self = ad2 ]
     ]
 
Inside ad1, self refers to ad1 and other refers to ad2, and in inside ad2, self refers to ad2 and other refers to ad1.

Parameters:
ad1 - the first ClassAd
ad2 - the second ClassAd
Returns:
a RecordExpr env such that env.Ad1.self is ad1, and env.Ad2.self is ad2.

eval

public static Expr eval(RecordExpr ad,
                        String[] attrs)
Evaluate a selection from a ClassAd.

Parameters:
ad - a ClassAd from which to select.
attrs - a sequence attr1, attr2, ..., attrn of attribute names.
Returns:
the result of evaluating ad.attr1.attr2...attrn.

eval

public static Expr eval(RecordExpr ad,
                        String attr)
Evaluate a selection from a ClassAd.

Parameters:
ad - a ClassAd from which to select.
attr - an attribute name.
Returns:
the result of evaluating ad.attr.

eval

public static Expr eval(String name,
                        Expr expr,
                        RecordExpr ad)
Evaluate an expression in the context of a ClassAd. The expr is evaluated as if it were a the value of an attribute named name in ad.

Note: the RecordExpr ad is modified and then returned to its original state, so this method is not thread-safe.

Parameters:
name - the name of the attribute.
expr - the expression to evaluate.
ad - the context for evaluation.
Returns:
the result of evaluating expr in the context of ad.

eval

public static Expr eval(String attr,
                        RecordExpr ad1,
                        RecordExpr ad2)
Evaluate an attribute of a ClassAd in an environment consisting of a pair of ads. The result is ad1.attr evaluated in the environment produced by bind(ad1, ad2).

Parameters:
attr - the name of the attribute used to initiate the evaluation
ad1 - the ClassAd used to initiate the evaluation
ad2 - the other ClassAd
Returns:
the result of the evaluation
See Also:
bind(RecordExpr,RecordExpr)

match

public static int[] match(Expr expr1,
                          Expr expr2)
Match two ClassAds. The expressions expr1.requirements and expr2.requirments both evaluate to true in the environment produced by bind(expr1, expr2), then the result is the list { rank1, rank2 }, where ranki is the result of evaluating expri in bind(expr1, expr2). If either of the requirements attributes is missing or evaluates to a value other than true, or if either of the rank attributes is missing or evaluates to something other than an Integer, the result is null.

Parameters:
expr1 - the first expression.
expr2 - the second expression.
Returns:
the result of the match, either a pair of integers or null.
See Also:
bind(RecordExpr,RecordExpr)

loadJavaLibrary

public static boolean loadJavaLibrary(String className)
Loads a "library" of externally defined Java functions. For the purposes of this method, a "library" is simply a Java class. Only static methods of the class with certain signatures are considered.

Note: Methods not obeying these restrictions will be silently ignored

The methods must be static and return an expression (more precisely, condor.classad.Expr) and have an optional Env parameter followed by either one parameter of type Expr[] or any number of parameters (including zero) all of which are of type Expr. In the former case, the method defines a "varargs" function: It will be called with an array of Expr values representing the (evaluated) actual parameters. In the latter case, a call with the wrong number of arguments will evaluate to ERROR without invoking the method at all. Otherwise, the actual parameters are evaluated and passed to the arguments of the method and the value returned from the method is the value of the call.

If a method has an initial Env parameter, evaluation of the actual parameters is inhibited. The arguments are passed as is to the the Expr or Expr[] formal parameters, and the Env parameter is set to an environment (stack of enclosing Record expressions) that the method can use to evaluate the expressions.

Parameters:
className - the fully qualified name of the class (e.g. condor.classad.Builtin)
Returns:
false if the load fails.
See Also:
Env

constant

public static Constant constant(int i)
Create a constant expression from an integer value.

Parameters:
i - the value.
Returns:
the resulting Constant object.

constant

public static Constant constant(double x)
Create a constant expression from a real value.

Parameters:
x - the value.
Returns:
the resulting Constant object.

constant

public static Constant constant(String s)
Create a constant expression from a String value.

Parameters:
s - the value.
Returns:
the resulting Constant object.