|
Project Wonder 5.0 | |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.webobjects.eocontrol.EOClassDescription
com.webobjects.eoaccess.EOEntityClassDescription
er.extensions.eof.ERXEntityClassDescription
public class ERXEntityClassDescription
The main purpose of the ERXClassDescription class is
to throw ERXValidationException
s instead of the
usual NSValidation.ValidationException
objects. See the
ERXValidationException and ERXValidationFactory class
for more information about localized and templatized
validation exceptions. This class is configured to
register itself as the class description by calling
the method registerDescription
. This method
is called when the principal class of this framework is
loaded. This happens really early so you shouldn't have
to worry about this at all.
Additionally, this class allows for model driven validations in a "poor-mans-Validity-way":
add a ERXValidation
user info entry on your entity.
This is an example:
This code is mainly a quick-and-dirty rewrite from PRValidation by Proteon.
"ERXValidation" = {
// these keys are evaluated on validateForSave, they don't correspond to properties
additionalValidationKeys = ("validateEmailPassword");
// This dictionary holds the keys to use for validating properties
validateForKey =
{
// these keys are evaluated on validateForSave, they don't correspond to properties
email =
(
{
// this is the message code into ValidationStrings.plist
// User.email.wrongLength = "The mail does not have the right size (5 to 50)";
message = "wrongLength";
// skip this rule if the value is null
ignoreIfNull = true;
// if there is a qualifier key, then a dictionary containing "object" and "value" is evaluated
// and an exception is thrown if the evaluation returns false
qualifier = "(value.length >= 5) AND (value.length < 50)";
},
{
// again, this is the message code into ValidationStrings.plist
message = "sampleTest";
// Given this key, an object of the corresponding EOQualifierEvaluation subclass is created
// and given this dictionary on creation. This object needs to be re-entrant.
className = "SampleTest";
// an example is:
// public class SampleTest implements EOQualifierEvaluation {
// int minLength, maxLength;
// public SampleTest(Object param) {
// NSDictionary dict = (NSDictionary)param;
// minLength = ERXValueUtilities.intValue(dict.objectForKey("minLength"));
// maxLength = ERXValueUtilities.intValue(dict.objectForKey("maxLength"));
// }
// public boolean evaluateObject(Object o) {
// ERXEntityClassDescription.ValidationObjectValue val
// = (ERXEntityClassDescription.ValidationObjectValue)o;
// EOEnterpriseObject eo = val.object();
// String value = (String)val.value();
// return value.length() >= minLength && value.length() <= maxLength;
// }
// }
minLength = "5";
maxLength = "10";
}
);
// This key does not correspond to any property, it get's evaluated in D2WApps where you have a
// multi-step page and need to do validation before validateForSave
"validateEmailPassword" =
(
{
message = "stupidTestWithEmailAndPassword";
// means to get D2W to highlight the fields involved instead of only displaying the message
// For this to work, your corresponding localized String should be
// User.email,password.stupidTestWithEmailAndPassword = "Stupid test failed";
keyPaths = "email,password";
qualifier = "(object.email.length >= object.password.length)";
}
);
};
// These get checked when the object gets saved, additionally to "additionalValidations"
// The structure of "validateForInsert", "validateForUpdate" and "validateForDelete" is the same.
validateForSave =
(
{
message = "cantBeBoth";
keyPaths = "isEditor,isAdmin";
qualifier = "(object.isEditor = 'Y' and object.isAdmin = 'Y')";
}
);
}
Additionally, this class adds a concept of "Default" values that get pushed into the object at creation time.
Simply add a "ERXDefaultValues" key into the entity's userInfo dictionary that contains key-value-pairs for every default you want to set. Alternately, you can set a "default" key on each of the relationship or attrbute's userInfo
Example:
"ERXDefaultValues" = {
// Example for simple values.
isAdmin = N;
isEditor = Y;
// Example for a related object (->Languages(pk,displayName)). You need to enter the primary key value.
language = "de";
// Example for an NSArray of related objects
recommendingUser = "@threadStorage.actor";
// Example for an NSArray
articlesToRevisit = "@threadStorage.actor.articles";
// Example for a NSTimestamp. All static methods from ERXTimestampUtilities are supported.
created = "@now";
updatePassword = "@tomorrow";
}
Nested Class Summary | |
---|---|
static class |
ERXEntityClassDescription.AttributeDefault
|
static interface |
ERXEntityClassDescription.Default
|
static class |
ERXEntityClassDescription.Factory
This factory inner class is registered as the observer for three notifications: modelWasAdded, classDescriptionNeededForEntity and classDescriptionNeededForClass. |
static class |
ERXEntityClassDescription.QualiferValidation
|
static class |
ERXEntityClassDescription.RelationshipDefault
|
static class |
ERXEntityClassDescription.ValidationObjectValue
|
Nested classes/interfaces inherited from class com.webobjects.eocontrol.EOClassDescription |
---|
com.webobjects.eocontrol.EOClassDescription.ClassDelegate |
Field Summary | |
---|---|
protected com.webobjects.foundation.NSMutableDictionary |
_initialDefaultValues
Holds default values |
protected com.webobjects.foundation.NSDictionary |
_validationInfo
Holds validation info from the entities user info dictionary |
protected com.webobjects.foundation.NSMutableDictionary |
_validationQualiferCache
Holds validation qualifiers |
protected java.lang.String |
defaultKey
default handling |
static org.apache.log4j.Logger |
defaultLog
default logging support |
static org.apache.log4j.Logger |
log
logging support |
static java.lang.String |
ValidateEntityClassAvailability
|
static org.apache.log4j.Logger |
validationLog
validation logging support |
Fields inherited from class com.webobjects.eoaccess.EOEntityClassDescription |
---|
_entity |
Fields inherited from class com.webobjects.eocontrol.EOClassDescription |
---|
_CLASS, ClassDescriptionNeededForClassNotification, ClassDescriptionNeededForEntityNameNotification, DeleteRuleCascade, DeleteRuleDeny, DeleteRuleNoAction, DeleteRuleNullify |
Constructor Summary | |
---|---|
ERXEntityClassDescription(com.webobjects.eoaccess.EOEntity entity)
Public constructor |
Method Summary | |
---|---|
void |
_addPartialClass(java.lang.Class<ERXPartial> partialClass)
Associates a partial entity class with this entity. |
java.lang.Class |
_enforcedKVCNumberClassForKey(java.lang.String key)
|
void |
awakeObjectFromInsertion(com.webobjects.eocontrol.EOEnterpriseObject eo,
com.webobjects.eocontrol.EOEditingContext ec)
|
protected void |
checkEntity()
|
com.webobjects.eocontrol.EOEnterpriseObject |
createInstanceWithEditingContext(com.webobjects.eocontrol.EOEditingContext ec,
com.webobjects.eocontrol.EOGlobalID gid)
|
java.lang.String |
displayNameForKey(java.lang.String key)
Calculates a display name for a key using localization of entityname.key if found otherwise an improved method. |
com.webobjects.eoaccess.EOEntity |
entity()
Overridden to perform a check if the entity is still in a model group. |
static ERXEntityClassDescription.Factory |
factory()
getter for the factory |
java.lang.String |
inverseForRelationshipKey(java.lang.String relationshipKey)
|
java.lang.String |
localizedKey(java.lang.String key)
|
void |
modelFileDidChange(com.webobjects.foundation.NSNotification n)
|
com.webobjects.foundation.NSArray<java.lang.Class<ERXPartial>> |
partialClasses()
Returns the list of partial entity classes for this entity. |
void |
readDefaultValues()
|
static void |
registerDescription()
This method is called by the principal class of the framework when the framework's NSBundle is loaded. |
void |
setDefaultAttributeValue(com.webobjects.eoaccess.EOAttribute attr,
java.lang.String defaultValue)
|
void |
setDefaultRelationshipValue(com.webobjects.eoaccess.EORelationship rel,
java.lang.String defaultValue)
|
void |
setDefaultValuesInObject(com.webobjects.eocontrol.EOEnterpriseObject eo,
com.webobjects.eocontrol.EOEditingContext ec)
|
void |
validateObjectForDelete(com.webobjects.eocontrol.EOEnterpriseObject obj)
This method is called when an object is about to be deleted. |
void |
validateObjectForInsert(com.webobjects.eocontrol.EOEnterpriseObject obj)
This method is called when an object is about to be inserted. |
void |
validateObjectForSave(com.webobjects.eocontrol.EOEnterpriseObject obj)
This method is called when an object is about to be saved. |
void |
validateObjectForUpdate(com.webobjects.eocontrol.EOEnterpriseObject obj)
This method is called when an object is about to be updated. |
protected boolean |
validateObjectValueDictWithInfo(ERXEntityClassDescription.ValidationObjectValue values,
com.webobjects.foundation.NSDictionary info,
java.lang.String cacheKey)
|
void |
validateObjectWithUserInfo(com.webobjects.eocontrol.EOEnterpriseObject object,
java.lang.Object value,
java.lang.String validationTypeString,
java.lang.String property)
|
java.lang.Object |
validateValueForKey(java.lang.Object obj,
java.lang.String s)
This method is called to validate a value for a particular key. |
Methods inherited from class com.webobjects.eoaccess.EOEntityClassDescription |
---|
_awakeFromRegistration, _concreteSubClassDescriptionForDeferredFault, _globalIDWithEntityName, _newDictionaryForProperties, allAttributeKeys, allPropertyKeys, allToManyRelationshipKeys, allToOneRelationshipKeys, attributeKeys, classDescriptionForDestinationKey, classForAttributeKey, clientAttributeKeys, clientToManyRelationshipKeys, clientToOneRelationshipKeys, defaultFormatterForKey, deleteRuleForRelationshipKey, entityName, fetchSpecificationNamed, ownsDestinationObjectsForRelationshipKey, readResolve, superClassDescription, toManyRelationshipKeys, toOneRelationshipKeys, validateObjectForSave |
Methods inherited from class com.webobjects.eocontrol.EOClassDescription |
---|
_decimalFormatter, _integerFormatter, _timestampFormatter, awakeObjectFromFetch, classDelegate, classDescriptionForClass, classDescriptionForEntityName, classDescriptionForKeyPath, defaultFormatterForKeyPath, finalize, invalidateClassDescriptionCache, propagateDeleteForObject, registerClassDescription, setClassDelegate, toString, userPresentableDescriptionForObject |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final org.apache.log4j.Logger log
public static final org.apache.log4j.Logger validationLog
public static final org.apache.log4j.Logger defaultLog
protected com.webobjects.foundation.NSDictionary _validationInfo
protected com.webobjects.foundation.NSMutableDictionary _validationQualiferCache
protected com.webobjects.foundation.NSMutableDictionary _initialDefaultValues
public static final java.lang.String ValidateEntityClassAvailability
protected java.lang.String defaultKey
Constructor Detail |
---|
public ERXEntityClassDescription(com.webobjects.eoaccess.EOEntity entity)
entity
- that this class description corresponds toMethod Detail |
---|
public static ERXEntityClassDescription.Factory factory()
public static void registerDescription()
public void modelFileDidChange(com.webobjects.foundation.NSNotification n)
public void validateObjectForDelete(com.webobjects.eocontrol.EOEnterpriseObject obj) throws com.webobjects.foundation.NSValidation.ValidationException
ERXValidationException
and that is
thrown.
validateObjectForDelete
in class com.webobjects.eoaccess.EOEntityClassDescription
obj
- enterprise object to be deleted
validation
- exception
com.webobjects.foundation.NSValidation.ValidationException
public com.webobjects.eoaccess.EOEntity entity()
entity
in class com.webobjects.eoaccess.EOEntityClassDescription
protected void checkEntity()
public com.webobjects.eocontrol.EOEnterpriseObject createInstanceWithEditingContext(com.webobjects.eocontrol.EOEditingContext ec, com.webobjects.eocontrol.EOGlobalID gid)
createInstanceWithEditingContext
in class com.webobjects.eoaccess.EOEntityClassDescription
public void validateObjectForUpdate(com.webobjects.eocontrol.EOEnterpriseObject obj) throws com.webobjects.foundation.NSValidation.ValidationException
ERXValidationException
and that is
thrown.
obj
- enterprise object to be deleted
validation
- exception
com.webobjects.foundation.NSValidation.ValidationException
public void validateObjectForInsert(com.webobjects.eocontrol.EOEnterpriseObject obj) throws com.webobjects.foundation.NSValidation.ValidationException
ERXValidationException
and that is
thrown.
obj
- enterprise object to be deleted
validation
- exception
com.webobjects.foundation.NSValidation.ValidationException
public java.lang.Object validateValueForKey(java.lang.Object obj, java.lang.String s) throws com.webobjects.foundation.NSValidation.ValidationException
ERXValidationException
and that is
thrown.
validateValueForKey
in class com.webobjects.eoaccess.EOEntityClassDescription
obj
- value to be validateds
- property key to validate the value
against.
validation
- exception
com.webobjects.foundation.NSValidation.ValidationException
public void validateObjectForSave(com.webobjects.eocontrol.EOEnterpriseObject obj) throws com.webobjects.foundation.NSValidation.ValidationException
ERXValidation.additionalValidationKeys
. If any validation
exceptions occur they are converted to an
ERXValidationException
and that is
thrown.
validateObjectForSave
in class com.webobjects.eocontrol.EOClassDescription
obj
- enterprise object to be saved
validation
- exception
com.webobjects.foundation.NSValidation.ValidationException
protected boolean validateObjectValueDictWithInfo(ERXEntityClassDescription.ValidationObjectValue values, com.webobjects.foundation.NSDictionary info, java.lang.String cacheKey)
public void validateObjectWithUserInfo(com.webobjects.eocontrol.EOEnterpriseObject object, java.lang.Object value, java.lang.String validationTypeString, java.lang.String property)
public java.lang.String displayNameForKey(java.lang.String key)
displayNameForKey
in class com.webobjects.eocontrol.EOClassDescription
key
- to be converted
public void readDefaultValues()
public void setDefaultAttributeValue(com.webobjects.eoaccess.EOAttribute attr, java.lang.String defaultValue)
public void setDefaultRelationshipValue(com.webobjects.eoaccess.EORelationship rel, java.lang.String defaultValue)
public void setDefaultValuesInObject(com.webobjects.eocontrol.EOEnterpriseObject eo, com.webobjects.eocontrol.EOEditingContext ec)
public void awakeObjectFromInsertion(com.webobjects.eocontrol.EOEnterpriseObject eo, com.webobjects.eocontrol.EOEditingContext ec)
awakeObjectFromInsertion
in class com.webobjects.eoaccess.EOEntityClassDescription
public java.lang.String localizedKey(java.lang.String key)
public java.lang.String inverseForRelationshipKey(java.lang.String relationshipKey)
inverseForRelationshipKey
in class com.webobjects.eoaccess.EOEntityClassDescription
public java.lang.Class _enforcedKVCNumberClassForKey(java.lang.String key)
_enforcedKVCNumberClassForKey
in class com.webobjects.eoaccess.EOEntityClassDescription
public void _addPartialClass(java.lang.Class<ERXPartial> partialClass)
partialClass
- the partial class to associateer.extensions.partials
public com.webobjects.foundation.NSArray<java.lang.Class<ERXPartial>> partialClasses()
er.extensions.partials
|
Last updated: Tue, Feb 21, 2017 05:45 PM CET | |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |