{
try
{
if (myConfig == null)
{
throw new PersistenceException("Configuration may not be null here");
}
/* top-level items should be a "persistent" element */
if (! myConfig.getName().equals("persistent"))
{
throw new PersistenceException("Configuration must be from 'persistent' element, not '"
+ myConfig.getName() + "'. Check config file format.");
}
setName(myConfig.getAttribute("name"));
id = myConfig.getAttribute("id", "");
authMgrBypassAllowed = myConfig.getAttributeAsBoolean("am-bypass-allowed", false);
helperClassName = myConfig.getAttribute("helper", null);
implClassName = myConfig.getAttribute("class", null);
pageSize = myConfig.getAttributeAsInteger("page-size", 0);
name = SuperString.notNull(myConfig.getAttribute("name"));
if (name.equals(""))
{
throw new PersistenceException("persistent element must have a name attribute");
}
tableName = SuperString.notNull(myConfig.getAttribute("table"));
if (tableName.equals(""))
{
throw new PersistenceException("persistent '" + name + "' must have a table attribute");
}
objectDescription = myConfig.getAttribute("descrip", getName());
//added by Santanu Dutt for Securable persistent Objects
if (myConfig.getAttributeAsBoolean("securable", false))
{
setSecurable(true);
}
if (myConfig.getAttributeAsBoolean("row-securable", false))
{
setSecurable(true);
rowSecurable = true;
}
int fieldCount = 0;
Configuration[] children = myConfig.getChildren();
Configuration oneChild = null;
for (int i = 0; i < children.length; i++)
{
oneChild = children[i];
if (oneChild.getName().equals("field"))
{
fieldCount++;
configureField(oneChild);
}
else if (oneChild.getName().equals("detail"))
{
/* Configure a detail relation from this persistent to another */
DefaultRelation r = new DefaultRelation(Relation.DETAIL, oneChild.getAttribute("name"), getName(),
oneChild.getAttribute("persistent"));
String fromString = oneChild.getAttribute("fromFields");
String toString = oneChild.getAttribute("toFields");
StringTokenizer stk = new StringTokenizer(fromString, ",");
while (stk.hasMoreTokens())
{
r.addFromField(stk.nextToken().trim());
}
stk = new StringTokenizer(toString, ",");
while (stk.hasMoreTokens())
{
r.addToField(stk.nextToken().trim());
}
relations.put(oneChild.getAttribute("name"), r);
}
else if (oneChild.getName().equals("relation"))
{
DefaultRelation r = new DefaultRelation(Relation.OTHER, oneChild.getAttribute("name"), getName(),
oneChild.getAttribute("persistent"));
String fromString = oneChild.getAttribute("fromFields");
String toString = oneChild.getAttribute("toFields");
StringTokenizer stk = new StringTokenizer(fromString, ",");
while (stk.hasMoreTokens())
{
r.addFromField(stk.nextToken().trim());
}
stk = new StringTokenizer(toString, ",");
while (stk.hasMoreTokens())
{
r.addToField(stk.nextToken().trim());
}
relations.put(oneChild.getAttribute("name"), r);
}
else if (oneChild.getName().equals("default-data"))
{
/* Do nothing - we don't deal with default-data here, it's only read */
/* at the time the table is created */
}
else if (oneChild.getName().equals("index"))
{
/* records fields to be indexed. */
String indexName = oneChild.getAttribute("name");
boolean isUnique = new Boolean(oneChild.getAttribute("is-unique")).booleanValue();
boolean createWithTable = new Boolean(oneChild.getAttribute("create-with-table")).booleanValue();
Configuration[] indexedFields = oneChild.getChildren();
String fieldNames = "";
for (int j = 0; j < indexedFields.length; j++)
{
String columnName = indexedFields[j].getAttribute("name");
fieldNames += columnName;
if (j + 1 != indexedFields.length)
{
fieldNames += ",";
}
}
Index index = addIndex(indexName, fieldNames, isUnique);
indicies.add(index);
index.setCreateWithTable(createWithTable);
}
else
{
log.warn("Unknown child of 'persistent' element '" + name + "', '" + oneChild.getName()
+ "' was ignored");
}
}
if (fieldCount == 0)
{
throw new ConfigurationException("No fields in persistent '" + name + "' for schema '"
+ getSchemaName() + "', id '" + id
+ "', and persistent does not use 'use-factory' option.");
}
if (isSecurable())
{
String amHint = myConfig.getAttribute("am", defaultAmHint);
try
{
authMgr = (AuthorizationManager) getService(AuthorizationManager.ROLE, amHint);
}
catch (Exception e)
{
log.error("Could not get service " + AuthorizationManager.ROLE + "/" + amHint);
throw new PersistenceException(e);
}
}
}
catch (ConfigurationException ce)
{
throw new PersistenceException(ce);
}
}