//Separate the field and lookup portions
StringTokenizer tok = new StringTokenizer(attrib, ":");
if (tok.countTokens() != 2)
{
throw new PersistenceException("Format error (need field:lookup) in indirect default-data value: "
+ attrib);
}
String fieldStr = tok.nextToken();
String lookupStr = tok.nextToken();
//Extract the schema, table, field names
tok = new StringTokenizer(fieldStr, ".");
if (tok.countTokens() != 3)
{
throw new PersistenceException(
"Format error (need $schema.table.field) in indirect default-data value: " + attrib);
}
String schema = tok.nextToken();
String table = tok.nextToken();
String field = tok.nextToken();
//Extract the value from the table
Persistent p = create(schema + "." + table);
tok = new StringTokenizer(lookupStr, "|");
String f = null;
String v = null;
StringTokenizer t = null;
for (int i = 0; i < tok.countTokens(); i++)
{
t = new StringTokenizer(tok.nextToken(), "=");
f = t.nextToken();
v = t.nextToken();
p.setField(f, v);
}
if (p.find())
{
retValue = p.getFieldString(field);
}
else
{
throw new PersistenceException("Could not lookup indirect default-data value: " + retValue);
}
}
return retValue;
}