
Classes | |
| class | AttributeDefault |
| interface | Default |
| class | Factory |
| class | QualiferValidation |
| class | RelationshipDefault |
| class | ValidationObjectValue |
Public Member Functions | |
| void | _addPartialClass (Class< ERXPartial > partialClass) |
| Class | _enforcedKVCNumberClassForKey (String key) |
| void | awakeObjectFromInsertion (EOEnterpriseObject eo, EOEditingContext ec) |
| EOEnterpriseObject | createInstanceWithEditingContext (EOEditingContext ec, EOGlobalID gid) |
| String | displayNameForKey (String key) |
| EOEntity | entity () |
| ERXEntityClassDescription (EOEntity entity) | |
| String | inverseForRelationshipKey (String relationshipKey) |
| String | localizedKey (String key) |
| void | modelFileDidChange (NSNotification n) |
| NSArray< Class< ERXPartial > > | partialClasses () |
| void | readDefaultValues () |
| void | setDefaultAttributeValue (EOAttribute attr, String defaultValue) |
| void | setDefaultRelationshipValue (EORelationship rel, String defaultValue) |
| void | setDefaultValuesInObject (EOEnterpriseObject eo, EOEditingContext ec) |
| void | validateObjectForDelete (EOEnterpriseObject obj) throws NSValidation.ValidationException |
| void | validateObjectForInsert (EOEnterpriseObject obj) throws NSValidation.ValidationException |
| void | validateObjectForSave (EOEnterpriseObject obj) throws NSValidation.ValidationException |
| void | validateObjectForUpdate (EOEnterpriseObject obj) throws NSValidation.ValidationException |
| void | validateObjectWithUserInfo (EOEnterpriseObject object, Object value, String validationTypeString, String property) |
| Object | validateValueForKey (Object obj, String s) throws NSValidation.ValidationException |
Static Public Member Functions | |
| static Factory | factory () |
| static void | registerDescription () |
Static Public Attributes | |
| static final Logger | defaultLog = Logger.getLogger("er.default.ERXEntityClassDescription") |
| static final Logger | log = Logger.getLogger(ERXEntityClassDescription.class) |
| static final String | ValidateEntityClassAvailability = "ERXEntityClassDescription.validateEntityClassAvailability" |
| static final Logger | validationLog = Logger.getLogger("er.validation.ERXEntityClassDescription") |
Protected Member Functions | |
| void | checkEntity () |
| boolean | validateObjectValueDictWithInfo (ValidationObjectValue values, NSDictionary info, String cacheKey) |
Protected Attributes | |
| NSMutableDictionary | _initialDefaultValues |
| NSDictionary | _validationInfo |
| NSMutableDictionary | _validationQualiferCache |
| String | defaultKey = "default" |
Private Member Functions | |
| void | invokeValidityMethodWithType (int type, EOEnterpriseObject eo) throws NSValidation.ValidationException |
| Method[] | validityMethods () |
Static Private Member Functions | |
| static Method | methodInSharedGSVEngineInstanceWithName (String name) |
| static Object | sharedGSVEngineInstance () |
| static boolean | useValidity () |
Private Attributes | |
| NSMutableArray< Class < ERXPartial > > | _partialClasses = new NSMutableArray<Class<ERXPartial>>() |
Static Private Attributes | |
| static Factory | _factory |
| static Object | sharedGSVEngineInstance |
| static Boolean | useValidity |
| static int | VALIDITY_DELETE = 1 |
| static int | VALIDITY_INSERT = 2 |
| static int | VALIDITY_SAVE = 0 |
| static int | VALIDITY_UPDATE = 3 |
| static Method[] | validityMethods = null |
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.ERXValidation user info entry on your entity. This is an example:
"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";
This code is mainly a quick-and-dirty rewrite from PRValidation by Proteon. 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";
}
If you wish to provide your own class description subclass see the documentation associated with the Factory inner class.
| ERXEntityClassDescription | ( | EOEntity | entity | ) |
Public constructor
| entity | that this class description corresponds to |
| void _addPartialClass | ( | Class< ERXPartial > | partialClass | ) |
Associates a partial entity class with this entity.
| partialClass | the partial class to associate |
| Class _enforcedKVCNumberClassForKey | ( | String | key | ) |
| void awakeObjectFromInsertion | ( | EOEnterpriseObject | eo, | |
| EOEditingContext | ec | |||
| ) |
| void checkEntity | ( | ) | [protected] |
| EOEnterpriseObject createInstanceWithEditingContext | ( | EOEditingContext | ec, | |
| EOGlobalID | gid | |||
| ) |
Calculates a display name for a key using localization of entityname.key if found otherwise an improved method.
| key | to be converted |
| EOEntity entity | ( | ) |
Overridden to perform a check if the entity is still in a model group. This can happen if you remove the entity, clone it to change things and re-add it afterwards.
| static Factory factory | ( | ) | [static] |
getter for the factory
| void invokeValidityMethodWithType | ( | int | type, | |
| EOEnterpriseObject | eo | |||
| ) | throws NSValidation.ValidationException [private] |
| static Method methodInSharedGSVEngineInstanceWithName | ( | String | name | ) | [static, private] |
| void modelFileDidChange | ( | NSNotification | n | ) |
| NSArray<Class<ERXPartial> > partialClasses | ( | ) |
Returns the list of partial entity classes for this entity.
| void readDefaultValues | ( | ) |
| static void registerDescription | ( | ) | [static] |
This method is called by the principal class of the framework when the framework's NSBundle is loaded. This method registers an observer, either a Factory object, which is an inner class of this class or a custom Factory subclass specified in the property: er.extensions.ERXClassDescription.factoryClass. This observer listens for notifications when a model is loaded or a class description is needed and responds by creating and registering custom class descriptions.
| void setDefaultAttributeValue | ( | EOAttribute | attr, | |
| String | defaultValue | |||
| ) |
| void setDefaultRelationshipValue | ( | EORelationship | rel, | |
| String | defaultValue | |||
| ) |
| void setDefaultValuesInObject | ( | EOEnterpriseObject | eo, | |
| EOEditingContext | ec | |||
| ) |
| static Object sharedGSVEngineInstance | ( | ) | [static, private] |
| static boolean useValidity | ( | ) | [static, private] |
| void validateObjectForDelete | ( | EOEnterpriseObject | obj | ) | throws NSValidation.ValidationException |
This method is called when an object is about to be deleted. If any validation exceptions occur they are converted to an ERXValidationException and that is thrown.
| obj | enterprise object to be deleted |
| validation | exception |
| void validateObjectForInsert | ( | EOEnterpriseObject | obj | ) | throws NSValidation.ValidationException |
This method is called when an object is about to be inserted. If any validation exceptions occur they are converted to an ERXValidationException and that is thrown.
| obj | enterprise object to be deleted |
| validation | exception |
| void validateObjectForSave | ( | EOEnterpriseObject | obj | ) | throws NSValidation.ValidationException |
This method is called when an object is about to be saved. Adds support for extra validation keys to be set in an array in the entity's userInfo under the keypath ERXValidation.additionalValidationKeys. If any validation exceptions occur they are converted to an ERXValidationException and that is thrown.
| obj | enterprise object to be saved |
| validation | exception |
| void validateObjectForUpdate | ( | EOEnterpriseObject | obj | ) | throws NSValidation.ValidationException |
This method is called when an object is about to be updated. If any validation exceptions occur they are converted to an ERXValidationException and that is thrown.
| obj | enterprise object to be deleted |
| validation | exception |
| boolean validateObjectValueDictWithInfo | ( | ValidationObjectValue | values, | |
| NSDictionary | info, | |||
| String | cacheKey | |||
| ) | [protected] |
| void validateObjectWithUserInfo | ( | EOEnterpriseObject | object, | |
| Object | value, | |||
| String | validationTypeString, | |||
| String | property | |||
| ) |
| Object validateValueForKey | ( | Object | obj, | |
| String | s | |||
| ) | throws NSValidation.ValidationException |
This method is called to validate a value for a particular key. Typical validation exceptions that might occur are non-null constraints or string is greater in length than is allowed. If a validation exception does occur they are converted to an ERXValidationException and that is thrown.
| obj | value to be validated | |
| s | property key to validate the value against. |
| validation | exception |
| Method [] validityMethods | ( | ) | [private] |
NSMutableDictionary _initialDefaultValues [protected] |
Holds default values
NSMutableArray<Class<ERXPartial> > _partialClasses = new NSMutableArray<Class<ERXPartial>>() [private] |
NSDictionary _validationInfo [protected] |
Holds validation info from the entities user info dictionary
NSMutableDictionary _validationQualiferCache [protected] |
Holds validation qualifiers
String defaultKey = "default" [protected] |
final Logger defaultLog = Logger.getLogger("er.default.ERXEntityClassDescription") [static] |
default logging support
Object sharedGSVEngineInstance [static, private] |
the shared validity engine instance as Object to eliminate compile errors if validity is not linked and should not be used
Boolean useValidity [static, private] |
Boolean that gets initialized on first use to indicate if validity should be used or not, remember that the call System.getProperty acts synchronized so this saves some time in multithreaded apps.
final String ValidateEntityClassAvailability = "ERXEntityClassDescription.validateEntityClassAvailability" [static] |
final Logger validationLog = Logger.getLogger("er.validation.ERXEntityClassDescription") [static] |
validation logging support
int VALIDITY_DELETE = 1 [static, private] |
index of validity delete method
int VALIDITY_INSERT = 2 [static, private] |
index of validity insert method
int VALIDITY_SAVE = 0 [static, private] |
index of validity save method
int VALIDITY_UPDATE = 3 [static, private] |
index of validity update method
Method [] validityMethods = null [static, private] |
holds validity Methods
1.5.8