condor.classad
Class RecordExpr

Object
  extended bycondor.classad.Expr
      extended bycondor.classad.RecordExpr

public class RecordExpr
extends Expr

A "record" expression (also known as a "classad"). An internal (non-leaf) node of an expression tree representing a classified ad (a.k.a. property list, record, table, map, etc.) A record is logically a mapping from case-independent strings (AttrNames) to expressions (Exprs). It keeps track of the original strings (with case preserved) and the order in which they were added so that the "original" record can be printed.

Version:
2.1
Author:
Marvin Solomon
See Also:
Expr

Nested Class Summary
 
Nested classes inherited from class condor.classad.Expr
Expr.Env
 
Field Summary
 
Fields inherited from class condor.classad.Expr
ABSOLUTE_TIME, AND, ATTRIBUTE, BIT_COMPLEMENT, BITAND, BITOR, BITXOR, BOOLEAN, CALL, COND, dblevel, DIFFERENT, DIV, EQUAL, ERROR, GREATER, GREATER_EQ, INTEGER, LEFT_SHIFT, LESS, LESS_EQ, LIST, MAXPREC, MINUS, MOD, NOT, NOT_EQUAL, OP, opName, opNameXML, OR, PLUS, REAL, RECORD, RELATIVE_TIME, RIGHT_SHIFT, SAME, SELECTION, STRING, SUBSCRIPT, TIMES, type, UMINUS, UNDEFINED, UPLUS, URIGHT_SHIFT
 
Constructor Summary
RecordExpr()
          Default constructor: a record with no fields.
RecordExpr(int n)
          Creates a RecordExpr with a specified capacity.
 
Method Summary
 Iterator attributes()
          Enumerate the attribute names.
protected  Expr eval1(Expr.Env env)
          Evaluate this Expr.
 RecordExpr insertAttribute(AttrName key, Expr expr)
          Add an attribute (replacing previous value if any).
 RecordExpr insertAttribute(String name, Expr expr)
          Add an attribute (replacing previous value if any).
 Expr lookup(AttrName name)
          Find the attribute with the given name.
 Expr lookup(AttrName name, Expr.Env env)
          Find the attribute with the given name in this RecordExpr or one of its ancestors.
 Expr lookup(String name)
          Find the attribute with the given name in this RecordExpr.
 int prec()
          The precedence of the operator in this expression node.
 Expr removeAttribute(AttrName attr)
          Delete an attribute.
 int size()
          Count how many attributes.
 StringBuffer toString(StringBuffer sb)
          Convert this Expr to a string, appending the result to the end of "sb".
 void transmit(DataOutput out)
          Serialize this RecordExpr in the format currently expected by Condor.
protected  String typeName()
          The type of the expression.
 
Methods inherited from class condor.classad.Expr
db, db, eval, eval, intValue, isConstant, isTrue, realValue, selectExpr, stringValue, subExpr, toString
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RecordExpr

public RecordExpr()
Default constructor: a record with no fields.


RecordExpr

public RecordExpr(int n)
Creates a RecordExpr with a specified capacity.

Parameters:
n - the estimated number of attributes to be inserted into this RecordExpr (for efficiency only).
Method Detail

typeName

protected String typeName()
The type of the expression.

Overrides:
typeName in class Expr
Returns:
the string ``classad''.

lookup

public Expr lookup(String name)
Find the attribute with the given name in this RecordExpr.

Parameters:
name - the attribute name to look for.
Returns:
the definition of "name", or null if there is none.

lookup

public Expr lookup(AttrName name,
                   Expr.Env env)
Find the attribute with the given name in this RecordExpr or one of its ancestors. The parameter "env" contains the list of RecordExprs containing this RecordExpression, innermost first. On a successful search, "env" is updated to contain RecordExprs that (properly) contain the resulting Expr. If "name" is not found, "env" is reset to the empty environment.

Parameters:
name - the attribute nae to look for.
env - the environment to search and update if this RecordExpr does not directly defined "name".
Returns:
the definition of "name", or null if there is none.

lookup

public Expr lookup(AttrName name)
Find the attribute with the given name.

Parameters:
name - the attribute name to look for.
Returns:
the value of the attribute (null if not present).

insertAttribute

public RecordExpr insertAttribute(String name,
                                  Expr expr)
Add an attribute (replacing previous value if any).

Parameters:
name - the name of the attribute to be added.
expr - the value of the attribute.
Returns:
this RecordExpr.
Throws:
IllegalArgumentException - if name or expr is null.

insertAttribute

public RecordExpr insertAttribute(AttrName key,
                                  Expr expr)
Add an attribute (replacing previous value if any).

Parameters:
key - the name of the attribute to be added.
expr - the value of the attribute.
Returns:
this RecordExpr.
Throws:
IllegalArgumentException - if name or expr is null or name is a reserved word.

removeAttribute

public Expr removeAttribute(AttrName attr)
Delete an attribute. The attribute attr is removed from this RecordExpr.

Parameters:
attr - the attribute to be removed.
Returns:
the value of the attribute if any. Returns null if no matching attribute was in the ad.

size

public int size()
Count how many attributes.

Returns:
the number of distinct attributes in this ClassAd.

attributes

public Iterator attributes()
Enumerate the attribute names.

Returns:
an iterator of objects of type AttrName, representing the the attribute names.

eval1

protected Expr eval1(Expr.Env env)
Evaluate this Expr. This is the internal method used to implement Expr.eval(). A Record evaluates to itself.

Specified by:
eval1 in class Expr
Parameters:
env - ignored.
Returns:
this RecordExpr.

toString

public StringBuffer toString(StringBuffer sb)
Convert this Expr to a string, appending the result to the end of "sb". The representation is the "canonical native format": '[' [ name '=' expr [ ';' name '=' expr ]* ] ']' with no extra spaces. Each "name" is represented as by AttrRef.toString().

Specified by:
toString in class Expr
Parameters:
sb - a place to put the result.
Returns:
sb.
See Also:
ClassAdWriter

transmit

public void transmit(DataOutput out)
              throws IOException
Serialize this RecordExpr in the format currently expected by Condor. The integer n is serialized by the writeInt method of the output stream and the n+2 strings are serialized by the writeUTF method. Normally, The output stream will be an instance of condor.cedar.CedarOutputStream, which means that n is written as 8 bytes, most significant byte first, and the strings are null-terminated and encoded using Java UTF-8 (which just transmits the low 8 bits of each character provided the string contains only ASCII characters).

To reconstitute a classad from this format, use a ClassAdReader and a ClassAdParser.

Parameters:
out - the stream to which the serialzed data should be written.
Throws:
InvalidObjectException - if this add does not have MyType and TargetType attributes.
IOException - if an I/O error occurs.
See Also:
ClassAdParser.parse(), ClassAdReader

prec

public int prec()
The precedence of the operator in this expression node. Used to print expressions without superfluous parentheses.

Specified by:
prec in class Expr
Returns:
the precendence of this node.
See Also:
ClassAdWriter.MINIMAL_PARENTHESES