// so we determine the persistent type of the base expression
ClassDescriptor classDesc = findClassDescriptorFor(baseType);
if (classDesc == null)
{
throw new JDOUserException("Access to type "+baseType.getName()+" is not allowed because the type is not persistent");
}
FieldAccess fieldAccess = new FieldAccess(nameExpr.getBaseExpression(), nameExpr.getName());
// it may be either a field, reference or collection descriptor -
// this depends on whether the name expression is a base expression
// to another name expression (not a method invocation or other expression)
ObjectReferenceDescriptor refDesc = classDesc.getObjectReferenceDescriptorByName(nameExpr.getName());
if (refDesc != null)
{
fieldAccess.setFieldDescriptor(refDesc);
}
else if (nameExpr.hasParent() && (nameExpr.getParent() instanceof NameExpression))
{
// if we are the base expression of another name expression, then it must be a reference
throw new JDOUserException("Cannot find reference "+nameExpr.getName()+" in type "+baseType.getName()+" because it is not defined, not persistent or not a reference");
}
else
{
// it can be a field or collection
CollectionDescriptor collDesc = classDesc.getCollectionDescriptorByName(nameExpr.getName());
if (collDesc != null)
{
fieldAccess.setFieldDescriptor(collDesc);
}
else
{
FieldDescriptor fieldDesc = classDesc.getFieldDescriptorByName(nameExpr.getName());
if (fieldDesc == null)
{
throw new JDOUserException("Cannot find feature "+nameExpr.getName()+" in type "+baseType.getName()+" because it is not defined or not persistent");
}
fieldAccess.setFieldDescriptor(fieldDesc);
}
}
newExpr = fieldAccess;