if (bMissing)
{
e = createValidationException(e);
ValidationException x = new ValidationException("err.validation.requiredAttribute",
new Object[]{new StringId(attribute.getCaption()), new StringId(m_metaclass.getCaption())});
x.setClassName(m_metaclass.getName());
x.setOIDHolder(this);
e.addException(attribute.getName(), x);
}
}
if (attribute.getMaxLength() > 0)
{
int nLength = 0;
if (value instanceof String)
{
nLength = ((String)value).length();
}
else if (value instanceof Binary)
{
nLength = ((Binary)value).getData().length;
}
if (nLength > attribute.getMaxLength())
{
e = createValidationException(e);
ValidationException x = new ValidationException("err.validation.maxDataLength",
new Object[]{Primitive.createInteger(attribute.getMaxLength()),
new StringId(attribute.getCaption()), new StringId(m_metaclass.getCaption())});
x.setClassName(m_metaclass.getName());
x.setOIDHolder(this);
e.addException(attribute.getName(), x);
}
}
if (bFull)
{
if (attribute.isConstrained() &&
attribute.getEnumeration() != type &&
value != null && e == null)
{
if (((InstanceList)attribute.getEnumeration().invoke("read",
new Object[]{null, (type.isPrimitive()) ?
Pair.attribute(Metaclass.ENUMERATION_VALUE).eq(value) :
new Pair(Symbol.AT).eq(value), null, Primitive.createInteger(-1),
Primitive.ZERO_INTEGER, Boolean.FALSE})).isEmpty())
{
e = createValidationException(e);
ValidationException x = new ValidationException("err.validation.enumerationValue",
new Object[]{new StringId(attribute.getEnumeration().getCaption()),
new StringId(attribute.getCaption()), new StringId(m_metaclass.getCaption())});
x.setClassName(m_metaclass.getName());
x.setOIDHolder(this);
e.addException(attribute.getName(), x);
}
}
if (attribute.getValidationFunction() != null && e == null)
{
Object result = m_context.getMachine().invoke(attribute.getValidationFunction(), this, value, null);
if (result != null)
{
ValidationException x = null;
if (result instanceof Boolean)
{
if (!((Boolean)result).booleanValue())
{
x = new ValidationException("err.validation.valueRange",
new Object[]{new StringId(attribute.getCaption()), new StringId(m_metaclass.getCaption())});
}
}
else if (result instanceof String)
{
x = new ValidationException((String)result);