edg.workload.common.jrequestad
Class Ad

java.lang.Object
  extended byedg.workload.common.jrequestad.Ad
Direct Known Subclasses:
JobAd, JobState

public class Ad
extends java.lang.Object

This class is used to user-friendly represent and manipulate a condor classad it provides several utilities such us string and file constructor and manipulation of native classes (String, int, boolean) instead of classad Expression


Field Summary
protected  condor.classad.RecordExpr jobAd
          The internal Ad representation
static int TYPE_AD
          Attribute Ad type value
static int TYPE_BOOL
          Attribute Boolean type value
static int TYPE_EXPRESSION
          Attribute Expression type value
static int TYPE_INTEGER
          Attribute Integer type value
static int TYPE_REAL
          Attribute Real/Double type value
static int TYPE_STRING
          Attribute String type value
static int TYPE_UNKNOWN
          unknown Attribute value
 
Constructor Summary
Ad()
          Default Constructor
Ad(condor.classad.RecordExpr ad)
           
Ad(java.lang.String ad)
          Instantiates a JobAd object from the given Ad-string
 
Method Summary
 void addAttribute(java.lang.String attrName, Ad attrValue)
          ADD ATTRIBUTE METHODS /** Allow adding a value to an already set attribute of the JobAd instance (i.e. it transforms it in a list attribute). if used on a non-set attribute the corresponding setAttribute method is automatically called.
 void addAttribute(java.lang.String attrName, boolean attrValue)
          Allow adding a value to an already set attribute of the JobAd instance (i.e. it transforms it in a list attribute). if used on a non-set attribute the corresponding setAttribute method is automatically called.
 void addAttribute(java.lang.String attrName, double attrValue)
          Allow adding a value to an already set attribute of the JobAd instance (i.e. it transforms it in a list attribute). if used on a non-set attribute the corresponding setAttribute method is automatically called.
 void addAttribute(java.lang.String attrName, int attrValue)
          Allow adding a value to an already set attribute of the JobAd instance (i.e. it transforms it in a list attribute). if used on a non-set attribute the corresponding setAttribute method is automatically called.
 void addAttribute(java.lang.String attrName, java.lang.String attrValue)
          Allow adding a value to an already set attribute of the JobAd instance (i.e. it transforms it in a list attribute). if used on a non-set attribute the corresponding setAttribute method is automatically called.
protected  condor.classad.ListExpr appendValue(condor.classad.Expr attrValue, condor.classad.ListExpr list)
          Append a value to a list and return the corresponding Expression List
 java.util.Iterator attributes()
          Enumerate the attribute names.
 void clear()
          Reset the JobAd Instance.
 void delAttribute(java.lang.String attrName)
          Remove the specified attribute from the Ad instance
 void fromFile(java.lang.String path)
          Retrieve the JobAd from the specified file path
 void fromRecord(condor.classad.RecordExpr re)
           
 void fromString(java.lang.String jdl)
          Update the JobAd object with the given ClassAd-jdl String
 Ad getAd(java.lang.String attrName)
          Retrieve an atribute of Ad type
 java.util.Vector getAdValue(java.lang.String attrName)
           
 java.util.Vector getBooleanValue(java.lang.String attrName)
          Retreive the value of the specified attribute
protected  java.lang.Object getConstant(java.lang.String attrName, condor.classad.Expr value, int exprType)
           
 java.util.Vector getDoubleValue(java.lang.String attrName)
          Retreive the value of the specified attribute
 java.util.Vector getIntValue(java.lang.String attrName)
          Retreive the value of the specified attribute
 java.util.Vector getStringValue(java.lang.String attrName)
          Retreive the value of the specified attribute
 int getType(java.lang.String attrName)
          GET METHODS /** Retrieve the type of the specified attribute, if present
protected  java.util.Vector getValue(java.lang.String attrName, condor.classad.Expr value, int exprType)
          get the value(s) from an Expression and return it/them as a Vector of Expr
 boolean hasAttribute(java.lang.String attrName)
          Check If the specified attribute has already been set
 boolean isSet()
          Check whether the JobAd has been initialised (true) or not (false)
 condor.classad.Expr lookup(java.lang.String attrName)
          Find the attribute with the given name.
 void setAttribute(java.lang.String attrName, Ad attrValue)
          Insert an attribute of Ad type
 void setAttribute(java.lang.String attrName, boolean attrValue)
          Insert an attribute of boolean type
 void setAttribute(java.lang.String attrName, double attrValue)
          Insert an attribute of double type
 void setAttribute(java.lang.String attrName, condor.classad.Expr attrValue)
          Insert an attribute of Expr type
 void setAttribute(java.lang.String attrName, int attrValue)
          SET METHODS /** Insert an attribute of integer type
 void setAttribute(java.lang.String attrName, java.lang.String attrValue)
          Insert an attribute of String type
 int size()
          Return the number of attributes that have been inserted so far
 java.lang.String toString()
          Convert the JobAd Instance into a sinlge-line String representation This method is equivalent as toString (false , false )
 java.lang.String toString(boolean multiLines, boolean multiLists)
          Convert the JobAd Instance into its String representation, one line per attribute, multi line for listed attribute active
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_UNKNOWN

public static final int TYPE_UNKNOWN
unknown Attribute value

See Also:
getType(java.lang.String), Constant Field Values

TYPE_INTEGER

public static final int TYPE_INTEGER
Attribute Integer type value

See Also:
getType(java.lang.String), Constant Field Values

TYPE_BOOL

public static final int TYPE_BOOL
Attribute Boolean type value

See Also:
getType(java.lang.String), Constant Field Values

TYPE_STRING

public static final int TYPE_STRING
Attribute String type value

See Also:
getType(java.lang.String), Constant Field Values

TYPE_REAL

public static final int TYPE_REAL
Attribute Real/Double type value

See Also:
getType(java.lang.String), Constant Field Values

TYPE_AD

public static final int TYPE_AD
Attribute Ad type value

See Also:
getType(java.lang.String), Constant Field Values

TYPE_EXPRESSION

public static final int TYPE_EXPRESSION
Attribute Expression type value

See Also:
getType(java.lang.String), Constant Field Values

jobAd

protected condor.classad.RecordExpr jobAd
The internal Ad representation

Constructor Detail

Ad

public Ad()
Default Constructor


Ad

public Ad(java.lang.String ad)
   throws java.text.ParseException,
          JobAdException
Instantiates a JobAd object from the given Ad-string

Throws:
java.text.ParseException - The Classad has JDL syntax error. Unable to build a valid Ad
JobAdException - One or more attributes contain syntax error(s)

Ad

public Ad(condor.classad.RecordExpr ad)
   throws JobAdException
Method Detail

setAttribute

public void setAttribute(java.lang.String attrName,
                         int attrValue)
                  throws javax.naming.directory.InvalidAttributeValueException
SET METHODS /** Insert an attribute of integer type

Throws:
javax.naming.directory.InvalidAttributeValueException

setAttribute

public void setAttribute(java.lang.String attrName,
                         boolean attrValue)
                  throws javax.naming.directory.InvalidAttributeValueException
Insert an attribute of boolean type

Throws:
javax.naming.directory.InvalidAttributeValueException

setAttribute

public void setAttribute(java.lang.String attrName,
                         double attrValue)
                  throws javax.naming.directory.InvalidAttributeValueException
Insert an attribute of double type

Throws:
javax.naming.directory.InvalidAttributeValueException

setAttribute

public void setAttribute(java.lang.String attrName,
                         java.lang.String attrValue)
                  throws javax.naming.directory.InvalidAttributeValueException
Insert an attribute of String type

Throws:
javax.naming.directory.InvalidAttributeValueException

setAttribute

public void setAttribute(java.lang.String attrName,
                         Ad attrValue)
                  throws javax.naming.directory.InvalidAttributeValueException
Insert an attribute of Ad type

Throws:
javax.naming.directory.InvalidAttributeValueException

setAttribute

public void setAttribute(java.lang.String attrName,
                         condor.classad.Expr attrValue)
                  throws javax.naming.directory.InvalidAttributeValueException,
                         java.lang.IllegalArgumentException
Insert an attribute of Expr type

Throws:
javax.naming.directory.InvalidAttributeValueException
java.lang.IllegalArgumentException

addAttribute

public void addAttribute(java.lang.String attrName,
                         Ad attrValue)
                  throws java.lang.IllegalArgumentException,
                         javax.naming.directory.InvalidAttributeValueException
ADD ATTRIBUTE METHODS /** Allow adding a value to an already set attribute of the JobAd instance (i.e. it transforms it in a list attribute). if used on a non-set attribute the corresponding setAttribute method is automatically called.

Parameters:
attrName - a String representing the attribute name
attrValue - - The value of the attribute to be added
Throws:
IllegalArgumentException- - The specified value is not allowed for the attribute
javax.naming.directory.InvalidAttributeValueException - - A value has not the right type for an attribute
java.lang.IllegalArgumentException

addAttribute

public void addAttribute(java.lang.String attrName,
                         int attrValue)
                  throws java.lang.IllegalArgumentException,
                         javax.naming.directory.InvalidAttributeValueException
Allow adding a value to an already set attribute of the JobAd instance (i.e. it transforms it in a list attribute). if used on a non-set attribute the corresponding setAttribute method is automatically called.

Parameters:
attrName - a String representing the attribute name
attrValue - - The value of the attribute to be added
Throws:
IllegalArgumentException- - The specified value is not allowed for the attribute
javax.naming.directory.InvalidAttributeValueException - - A value has not the right type for an attribute
java.lang.IllegalArgumentException

addAttribute

public void addAttribute(java.lang.String attrName,
                         double attrValue)
                  throws java.lang.IllegalArgumentException,
                         javax.naming.directory.InvalidAttributeValueException
Allow adding a value to an already set attribute of the JobAd instance (i.e. it transforms it in a list attribute). if used on a non-set attribute the corresponding setAttribute method is automatically called.

Parameters:
attrName - a String representing the attribute name
attrValue - - The value of the attribute to be added
Throws:
IllegalArgumentException- - The specified value is not allowed for the attribute
javax.naming.directory.InvalidAttributeValueException - - the has not the right format for the attribute
java.lang.IllegalArgumentException

addAttribute

public void addAttribute(java.lang.String attrName,
                         boolean attrValue)
                  throws java.lang.IllegalArgumentException,
                         javax.naming.directory.InvalidAttributeValueException
Allow adding a value to an already set attribute of the JobAd instance (i.e. it transforms it in a list attribute). if used on a non-set attribute the corresponding setAttribute method is automatically called.

Parameters:
attrName - a String representing the attribute name
attrValue - - The value of the attribute to be added
Throws:
IllegalArgumentException- - The specified value is not allowed for the attribute
javax.naming.directory.InvalidAttributeValueException - - the value has not the right format for the attribute
java.lang.IllegalArgumentException

addAttribute

public void addAttribute(java.lang.String attrName,
                         java.lang.String attrValue)
                  throws java.lang.IllegalArgumentException,
                         javax.naming.directory.InvalidAttributeValueException
Allow adding a value to an already set attribute of the JobAd instance (i.e. it transforms it in a list attribute). if used on a non-set attribute the corresponding setAttribute method is automatically called.

Parameters:
attrName - a String representing the attribute name
attrValue - - The value of the attribute to be added
Throws:
java.lang.IllegalArgumentException - The specified type is not allowed for the attribute value
javax.naming.directory.InvalidAttributeValueException - The value has not the right format for the attribute

getType

public int getType(java.lang.String attrName)
            throws java.lang.NoSuchFieldException
GET METHODS /** Retrieve the type of the specified attribute, if present

Parameters:
attrName - the name of the attribute to look for
Returns:
one of the following value: TYPE_UNKNOWN, TYPE_INTEGER , TYPE_BOOL, TYPE_STRING, TYPE_DOUBLE, TYPE_EXPRESSION, TYPE_AD
Throws:
java.lang.NoSuchFieldException - - Unable to find the attribute inside the Ad

getIntValue

public java.util.Vector getIntValue(java.lang.String attrName)
                             throws java.lang.NoSuchFieldException,
                                    java.lang.IllegalArgumentException
Retreive the value of the specified attribute

Parameters:
attrName - The name of the attribute name to be retrieved
Returns:
a Vector cantaining the values listed in the specified attribute , (1-size Vector if the attribute has a single value)
Throws:
java.lang.IllegalArgumentException - - The type of retrieved value is not allowed for the specified attribute name
java.lang.NoSuchFieldException - - The requested attribute has not been set yet

getDoubleValue

public java.util.Vector getDoubleValue(java.lang.String attrName)
                                throws java.lang.NoSuchFieldException,
                                       java.lang.IllegalArgumentException
Retreive the value of the specified attribute

Parameters:
attrName - The name of the attribute to be retrieved
Returns:
a Vector cantaining the values listed in the specified attribute , (1-size Vector if the attribute has a single value)
Throws:
java.lang.NoSuchFieldException
java.lang.IllegalArgumentException

getBooleanValue

public java.util.Vector getBooleanValue(java.lang.String attrName)
                                 throws java.lang.NoSuchFieldException,
                                        java.lang.IllegalArgumentException
Retreive the value of the specified attribute

Parameters:
attrName - The name of the attribute to be retrieved
Returns:
a Vector cantaining the values listed in the specified attribute , (1-size Vector if the attribute has a single value)
Throws:
java.lang.IllegalArgumentException - - The type of retrieved value is not allowed for the specified attribute name
java.lang.NoSuchFieldException - - The requested attribute has not been set yet

getStringValue

public java.util.Vector getStringValue(java.lang.String attrName)
                                throws java.lang.NoSuchFieldException,
                                       java.lang.IllegalArgumentException
Retreive the value of the specified attribute

Parameters:
attrName - The name of the attribute to be retrieved
Returns:
a Vector cantaining the values listed in the specified attribute , (1-size Vector if the attribute has a single value)
Throws:
java.lang.IllegalArgumentException - - The type of retrieved value is not allowed for the specified attribute name
java.lang.NoSuchFieldException - - The requested attribute has not been set yet

getAdValue

public java.util.Vector getAdValue(java.lang.String attrName)
                            throws java.lang.NoSuchFieldException,
                                   java.lang.IllegalArgumentException
Throws:
java.lang.NoSuchFieldException
java.lang.IllegalArgumentException

getAd

public Ad getAd(java.lang.String attrName)
         throws java.lang.NoSuchFieldException,
                java.lang.IllegalArgumentException
Retrieve an atribute of Ad type

Parameters:
attrName - the name of the attribute to be retrieved
Throws:
java.lang.NoSuchFieldException
java.lang.IllegalArgumentException

getConstant

protected java.lang.Object getConstant(java.lang.String attrName,
                                       condor.classad.Expr value,
                                       int exprType)
                                throws java.lang.IllegalArgumentException,
                                       java.lang.NoSuchFieldException
Throws:
java.lang.IllegalArgumentException
java.lang.NoSuchFieldException

getValue

protected java.util.Vector getValue(java.lang.String attrName,
                                    condor.classad.Expr value,
                                    int exprType)
                             throws java.lang.NoSuchFieldException,
                                    java.lang.IllegalArgumentException
get the value(s) from an Expression and return it/them as a Vector of Expr

Throws:
java.lang.NoSuchFieldException
java.lang.IllegalArgumentException

lookup

public condor.classad.Expr lookup(java.lang.String attrName)
Find the attribute with the given name.

Returns:
the value of the attribute (null if not present)

attributes

public java.util.Iterator attributes()
Enumerate the attribute names.

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

hasAttribute

public boolean hasAttribute(java.lang.String attrName)
Check If the specified attribute has already been set

Parameters:
attrName - The name of the attibute to be looked for
Returns:
true if the attribute has been found, false otherwise

isSet

public boolean isSet()
Check whether the JobAd has been initialised (true) or not (false)


size

public int size()
Return the number of attributes that have been inserted so far

Returns:
the size of the JobAd

clear

public void clear()
Reset the JobAd Instance. All the previous existing attributes will be deleted


delAttribute

public void delAttribute(java.lang.String attrName)
                  throws java.lang.NoSuchFieldException
Remove the specified attribute from the Ad instance

Parameters:
attrName - the attribute to be retrieved
Throws:
java.lang.NoSuchFieldException - The attribute is not present

appendValue

protected condor.classad.ListExpr appendValue(condor.classad.Expr attrValue,
                                              condor.classad.ListExpr list)
Append a value to a list and return the corresponding Expression List


fromFile

public void fromFile(java.lang.String path)
              throws java.lang.Exception
Retrieve the JobAd from the specified file path

Parameters:
path - the path of the file from where the jobAd is supposed to be read
Throws:
java.text.ParseException - - The string doesn't seem to be a valid classad
JobAdException - - One or more attributes contain syntax error(s)
java.io.FileNotFoundException - the specified path does not exist
java.lang.Exception

toString

public java.lang.String toString()
Convert the JobAd Instance into a sinlge-line String representation This method is equivalent as toString (false , false )

See Also:
toString(boolean multiLines , boolean multiLists)

toString

public java.lang.String toString(boolean multiLines,
                                 boolean multiLists)
Convert the JobAd Instance into its String representation, one line per attribute, multi line for listed attribute active

Parameters:
multiLines - one-attribute per line representation enablng
multiLists - list attributes splitted into multi line representation enablng
See Also:
toString()

fromRecord

public void fromRecord(condor.classad.RecordExpr re)
                throws JobAdException
Throws:
JobAdException

fromString

public void fromString(java.lang.String jdl)
                throws java.text.ParseException,
                       JobAdException
Update the JobAd object with the given ClassAd-jdl String

Parameters:
jdl - A String representig the description of the job
Throws:
java.text.ParseException - The string doesn't seem to be a valid classad
JobAdException - One or more attributes contain syntax error(s)