Oolite
Loading...
Searching...
No Matches
OOPListSchemaVerifier(OOPrivate) Category Reference

Instance Methods

(BOOL) - delegateVerifierWithPropertyList:named:testProperty:atPath:againstType:error:
(BOOL) - delegateVerifierWithPropertyList:named:failedForProperty:withError:expectedType:
(BOOL) - verifyPList:named:subProperty:againstSchemaType:atPath:tentative:error:stop:
(NSDictionary *) - resolveSchemaType:atPath:error:

Detailed Description

Definition at line 174 of file OOPListSchemaVerifier.m.

Method Documentation

◆ delegateVerifierWithPropertyList:named:failedForProperty:withError:expectedType:

- (BOOL) delegateVerifierWithPropertyList: (id) rootPList
named: (NSString*) name
failedForProperty: (id) subPList
withError: (NSError*) error
expectedType: (NSDictionary*) localSchema 

Extends class OOPListSchemaVerifier.

Definition at line 367 of file OOPListSchemaVerifier.m.

367 :(id)rootPList
368 named:(NSString*)name
369 failedForProperty:(id)subPList
370 withError:(NSError*)error
371 expectedType:(NSDictionary*)localSchema
372{
373 BOOL result;
374
375 if ([_delegate respondsToSelector:@selector(verifier:withPropertyList:named:failedForProperty:withError:expectedType:)]) {
376 @try {
377 result = [_delegate verifier:self
378 withPropertyList:rootPList
379 named:name
380 failedForProperty:subPList
381 withError:error
382 expectedType:localSchema];
383 }
384 @catch (NSException* exception) {
385 OOLog(@"plistVerifier.delegateException", @"Property list schema verifier: delegate threw exception (%@) in -verifier:withPropertyList:named:failedForProperty:atPath:expectedType: at %@ in %@ -- stopping.", [exception name], [error plistKeyPathDescription], name);
386 result = NO;
387 }
388 } else {
389 OOLog(@"plistVerifier.failed", @"Verification of property list \"%@\" failed at %@: %@", name, [error plistKeyPathDescription], [error localizedFailureReason]);
390 result = NO;
391 }
392 return result;
393}
#define OOLog(class, format,...)
Definition OOLogging.h:84

References OOLog.

◆ delegateVerifierWithPropertyList:named:testProperty:atPath:againstType:error:

- (BOOL) delegateVerifierWithPropertyList: (id) rootPList
named: (NSString*) name
testProperty: (id) subPList
atPath: (BackLinkChain) keyPath
againstType: (NSString*) typeKey
error: (NSError**) outError 

Extends class OOPListSchemaVerifier.

Definition at line 323 of file OOPListSchemaVerifier.m.

323 :(id)rootPList
324 named:(NSString*)name
325 testProperty:(id)subPList
326 atPath:(BackLinkChain)keyPath
327 againstType:(NSString*)typeKey
328 error:(NSError**)outError
329{
330 BOOL result;
331 NSError* error = nil;
332
333 if ([_delegate respondsToSelector:@selector(verifier:withPropertyList:named:testProperty:atPath:againstType:error:)]) {
334 @try {
335 result = [_delegate verifier:self
336 withPropertyList:rootPList
337 named:name
338 testProperty:subPList
339 atPath:KeyPathToArray(keyPath)
340 againstType:typeKey
341 error:&error];
342 }
343 @catch (NSException* exception) {
344 OOLog(@"plistVerifier.delegateException", @"Property list schema verifier: delegate threw exception (%@) in -verifier:withPropertyList:named:testProperty:atPath:againstType: for type \"%@\" at %@ in %@ -- treating as failure.", [exception name], typeKey, KeyPathToString(keyPath), name);
345 result = NO;
346 error = nil;
347 }
348
349 if (outError != NULL) {
350 if (!result || error != nil) {
351 // Note: Generates an error if delegate returned NO (meaning stop) or if delegate produced an error but did not request a stop.
352 *outError = ErrorWithProperty(kPListDelegatedTypeError, &keyPath, NSUnderlyingErrorKey, error, @"Value at %@ does not match delegated type \"%@\".", KeyPathToString(keyPath), typeKey);
353 } else
354 *outError = nil;
355 }
356 } else {
357 if (!_badDelegateWarning) {
358 OOLog(@"plistVerifier.badDelegate", @"%@", @"Property list schema verifier: delegate does not handle delegated types.");
359 _badDelegateWarning = YES;
360 }
361 result = YES;
362 }
363
364 return result;
365}
@ kPListDelegatedTypeError
static NSString * KeyPathToString(BackLinkChain keyPath)
struct BackLinkChain BackLinkChain
static NSError * ErrorWithProperty(OOPListSchemaVerifierErrorCode errorCode, BackLinkChain *keyPath, NSString *propKey, id propValue, NSString *format,...)
return nil

References ErrorWithProperty(), KeyPathToString(), kPListDelegatedTypeError, nil, and OOLog.

Here is the call graph for this function:

◆ resolveSchemaType:atPath:error:

- (NSDictionary *) resolveSchemaType: (id) specifier
atPath: (BackLinkChain) keyPath
error: (NSError**) outError 

Extends class OOPListSchemaVerifier.

Definition at line 476 of file OOPListSchemaVerifier.m.

476 :(id)specifier
477 atPath:(BackLinkChain)keyPath
478 error:(NSError**)outError
479{
480 id typeVal = nil;
481 NSString* complaint = nil;
482
483 assert(outError != NULL);
484
485 if (![specifier isKindOfClass:[NSString class]] && ![specifier isKindOfClass:[NSDictionary class]])
486 goto BAD_TYPE;
487
488 for (;;) {
489 if ([specifier isKindOfClass:[NSString class]])
490 specifier = [NSDictionary dictionaryWithObject:specifier forKey:@"type"];
491 typeVal = [(NSDictionary*)specifier objectForKey:@"type"];
492
493 if ([typeVal isKindOfClass:[NSString class]]) {
494 if ([typeVal hasPrefix:@"$"]) {
495 // Macro reference; look it up in $definitions
496 specifier = [_definitions objectForKey:typeVal];
497 if (specifier == nil) {
498 *outError = ErrorWithProperty(kPListErrorSchemaUndefiniedMacroReference, &keyPath, kUndefinedMacroErrorKey, typeVal, @"Bad schema: reference to undefined macro \"%@\".", StringForErrorReport(typeVal));
499 return nil;
500 }
501 } else {
502 // Non-macro string
503 return specifier;
504 }
505 } else if ([typeVal isKindOfClass:[NSDictionary class]]) {
506 specifier = typeVal;
507 } else {
508 goto BAD_TYPE;
509 }
510 }
511
512BAD_TYPE:
513 // Error: bad type
514 if (typeVal == nil)
515 complaint = @"no type specified";
516 else
517 complaint = @"not string or dictionary";
518
519 *outError = Error(kPListErrorSchemaBadTypeSpecifier, &keyPath, @"Bad schema: invalid type specifier for path %@ (%@).", KeyPathToString(keyPath), complaint);
520 return nil;
521}
@ kPListErrorSchemaBadTypeSpecifier
@ kPListErrorSchemaUndefiniedMacroReference
NSString *const kUndefinedMacroErrorKey
static NSString * StringForErrorReport(NSString *string)
static NSError * Error(OOPListSchemaVerifierErrorCode errorCode, BackLinkChain *keyPath, NSString *format,...)

References Error(), ErrorWithProperty(), KeyPathToString(), kPListErrorSchemaBadTypeSpecifier, kPListErrorSchemaUndefiniedMacroReference, kUndefinedMacroErrorKey, nil, and StringForErrorReport().

Here is the call graph for this function:

◆ verifyPList:named:subProperty:againstSchemaType:atPath:tentative:error:stop:

- (BOOL) verifyPList: (id) rootPList
named: (NSString*) name
subProperty: (id) subProperty
againstSchemaType: (id) subSchema
atPath: (BackLinkChain) keyPath
tentative: (BOOL) tentative
error: (NSError**) outError
stop: (BOOL*) outStop 

Extends class OOPListSchemaVerifier.

Definition at line 395 of file OOPListSchemaVerifier.m.

395 :(id)rootPList
396 named:(NSString*)name
397 subProperty:(id)subProperty
398 againstSchemaType:(id)subSchema
399 atPath:(BackLinkChain)keyPath
400 tentative:(BOOL)tentative
401 error:(NSError**)outError
402 stop:(BOOL*)outStop
403{
405 NSError* error = nil;
406 NSDictionary* resolvedSpecifier = nil;
407 NSAutoreleasePool* pool = nil;
408
409 assert(outStop != NULL);
410
411 pool = [[NSAutoreleasePool alloc] init];
412
414
415 @try {
417
418 resolvedSpecifier = [self resolveSchemaType:subSchema atPath:keyPath error:&error];
419 if (resolvedSpecifier != nil)
420 type = StringToSchemaType([resolvedSpecifier objectForKey:@"type"], &error);
421
422#define VERIFY_CASE(T) \
423 case kType##T: \
424 error = Verify_##T(self, subProperty, resolvedSpecifier, rootPList, name, keyPath, tentative, outStop); \
425 break;
426
427 switch (type) {
428 VERIFY_CASE(String);
429 VERIFY_CASE(Array);
430 VERIFY_CASE(Dictionary);
431 VERIFY_CASE(Integer);
432 VERIFY_CASE(PositiveInteger);
433 VERIFY_CASE(Float);
434 VERIFY_CASE(PositiveFloat);
435 VERIFY_CASE(OneOf);
436 VERIFY_CASE(Enumeration);
437 VERIFY_CASE(Boolean);
438 VERIFY_CASE(FuzzyBoolean);
441 VERIFY_CASE(DelegatedType);
442
443 case kTypeUnknown:
444 // resolveSchemaType:... or StringToSchemaType() should have provided an error.
445 *outStop = YES;
446 }
447 }
448 @catch (NSException* exception) {
449 error = Error(kPListErrorInternal, (BackLinkChain*)&keyPath, @"Uncaught exception %@: %@ in plist verifier for \"%@\" at %@.", [exception name], [exception reason], name, KeyPathToString(keyPath));
450 }
451
453
454 if (error != nil) {
455 if (!tentative && !IsFailureAlreadyReportedError(error)) {
456 *outStop = ![self delegateVerifierWithPropertyList:rootPList
457 named:name
458 failedForProperty:subProperty
459 withError:error
460 expectedType:subSchema];
461 } else if (tentative)
462 *outStop = YES;
463 }
464
465 if (outError != NULL && error != nil) {
466 *outError = [error retain];
467 [pool release];
468 [error autorelease];
469 } else {
470 [pool release];
471 }
472
473 return error == nil;
474}
@ kPListErrorInternal
static SchemaType StringToSchemaType(NSString *string, NSError **outError)
#define DebugDumpPopIndent()
#define DebugDumpIndent()
#define VERIFY_CASE(T)
#define DebugDumpPushIndent()
static BOOL IsFailureAlreadyReportedError(NSError *error)
struct Quaternion Quaternion
struct Vector Vector

References DebugDumpIndent, DebugDumpPopIndent, DebugDumpPushIndent, OOPListSchemaVerifier::delegateVerifierWithPropertyList:named:failedForProperty:withError:expectedType:, Error(), IsFailureAlreadyReportedError(), KeyPathToString(), kPListErrorInternal, kTypeUnknown, nil, OOPListSchemaVerifier::resolveSchemaType:atPath:error:, StringToSchemaType(), and VERIFY_CASE.

Here is the call graph for this function:

The documentation for this category was generated from the following file: