Oolite 1.91.0.7646-241128-10e222e
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 157 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 115 of file OOPListSchemaVerifier.m.

376 :(id)rootPList
377 named:(NSString *)name
378 failedForProperty:(id)subPList
379 withError:(NSError *)error
380 expectedType:(NSDictionary *)localSchema
381{
382 BOOL result;
383
384 if ([_delegate respondsToSelector:@selector(verifier:withPropertyList:named:failedForProperty:withError:expectedType:)])
385 {
386 @try
387 {
388 result = [_delegate verifier:self
389 withPropertyList:rootPList
390 named:name
391 failedForProperty:subPList
392 withError:error
393 expectedType:localSchema];
394 }
395 @catch (NSException *exception)
396 {
397 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);
398 result = NO;
399 }
400 }
401 else
402 {
403 OOLog(@"plistVerifier.failed", @"Verification of property list \"%@\" failed at %@: %@", name, [error plistKeyPathDescription], [error localizedFailureReason]);
404 result = NO;
405 }
406 return result;
407}
#define OOLog(class, format,...)
Definition OOLogging.h:88

◆ 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 115 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 {
335 @try
336 {
337 result = [_delegate verifier:self
338 withPropertyList:rootPList
339 named:name
340 testProperty:subPList
341 atPath:KeyPathToArray(keyPath)
342 againstType:typeKey
343 error:&error];
344 }
345 @catch (NSException *exception)
346 {
347 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);
348 result = NO;
349 error = nil;
350 }
351
352 if (outError != NULL)
353 {
354 if (!result || error != nil)
355 {
356 // Note: Generates an error if delegate returned NO (meaning stop) or if delegate produced an error but did not request a stop.
357 *outError = ErrorWithProperty(kPListDelegatedTypeError, &keyPath, NSUnderlyingErrorKey, error, @"Value at %@ does not match delegated type \"%@\".", KeyPathToString(keyPath), typeKey);
358 }
359 else *outError = nil;
360 }
361 }
362 else
363 {
364 if (!_badDelegateWarning)
365 {
366 OOLog(@"plistVerifier.badDelegate", @"%@", @"Property list schema verifier: delegate does not handle delegated types.");
367 _badDelegateWarning = YES;
368 }
369 result = YES;
370 }
371
372 return result;
373}
@ kPListDelegatedTypeError
static NSString * KeyPathToString(BackLinkChain keyPath)
static NSError * ErrorWithProperty(OOPListSchemaVerifierErrorCode errorCode, BackLinkChain *keyPath, NSString *propKey, id propValue, NSString *format,...)
return nil

◆ resolveSchemaType:atPath:error:

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

Extends class OOPListSchemaVerifier.

Definition at line 115 of file OOPListSchemaVerifier.m.

496 :(id)specifier
497 atPath:(BackLinkChain)keyPath
498 error:(NSError **)outError
499{
500 id typeVal = nil;
501 NSString *complaint = nil;
502
503 assert(outError != NULL);
504
505 if (![specifier isKindOfClass:[NSString class]] && ![specifier isKindOfClass:[NSDictionary class]]) goto BAD_TYPE;
506
507 for (;;)
508 {
509 if ([specifier isKindOfClass:[NSString class]]) specifier = [NSDictionary dictionaryWithObject:specifier forKey:@"type"];
510 typeVal = [(NSDictionary *)specifier objectForKey:@"type"];
511
512 if ([typeVal isKindOfClass:[NSString class]])
513 {
514 if ([typeVal hasPrefix:@"$"])
515 {
516 // Macro reference; look it up in $definitions
517 specifier = [_definitions objectForKey:typeVal];
518 if (specifier == nil)
519 {
520 *outError = ErrorWithProperty(kPListErrorSchemaUndefiniedMacroReference, &keyPath, kUndefinedMacroErrorKey, typeVal, @"Bad schema: reference to undefined macro \"%@\".", StringForErrorReport(typeVal));
521 return nil;
522 }
523 }
524 else
525 {
526 // Non-macro string
527 return specifier;
528 }
529 }
530 else if ([typeVal isKindOfClass:[NSDictionary class]])
531 {
532 specifier = typeVal;
533 }
534 else
535 {
536 goto BAD_TYPE;
537 }
538 }
539
540BAD_TYPE:
541 // Error: bad type
542 if (typeVal == nil) complaint = @"no type specified";
543 else complaint = @"not string or dictionary";
544
545 *outError = Error(kPListErrorSchemaBadTypeSpecifier, &keyPath, @"Bad schema: invalid type specifier for path %@ (%@).", KeyPathToString(keyPath), complaint);
546 return nil;
547}
@ kPListErrorSchemaBadTypeSpecifier
@ kPListErrorSchemaUndefiniedMacroReference
NSString *const kUndefinedMacroErrorKey
static NSString * StringForErrorReport(NSString *string)
static NSError * Error(OOPListSchemaVerifierErrorCode errorCode, BackLinkChain *keyPath, NSString *format,...)

◆ 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 115 of file OOPListSchemaVerifier.m.

410 :(id)rootPList
411 named:(NSString *)name
412 subProperty:(id)subProperty
413 againstSchemaType:(id)subSchema
414 atPath:(BackLinkChain)keyPath
415 tentative:(BOOL)tentative
416 error:(NSError **)outError
417 stop:(BOOL *)outStop
418{
420 NSError *error = nil;
421 NSDictionary *resolvedSpecifier = nil;
422 NSAutoreleasePool *pool = nil;
423
424 assert(outStop != NULL);
425
426 pool = [[NSAutoreleasePool alloc] init];
427
429
430 @try
431 {
433
434 resolvedSpecifier = [self resolveSchemaType:subSchema atPath:keyPath error:&error];
435 if (resolvedSpecifier != nil) type = StringToSchemaType([resolvedSpecifier objectForKey:@"type"], &error);
436
437 #define VERIFY_CASE(T) case kType##T: error = Verify_##T(self, subProperty, resolvedSpecifier, rootPList, name, keyPath, tentative, outStop); break;
438
439 switch (type)
440 {
441 VERIFY_CASE(String);
442 VERIFY_CASE(Array);
443 VERIFY_CASE(Dictionary);
444 VERIFY_CASE(Integer);
445 VERIFY_CASE(PositiveInteger);
446 VERIFY_CASE(Float);
447 VERIFY_CASE(PositiveFloat);
448 VERIFY_CASE(OneOf);
449 VERIFY_CASE(Enumeration);
450 VERIFY_CASE(Boolean);
451 VERIFY_CASE(FuzzyBoolean);
452 VERIFY_CASE(Vector);
453 VERIFY_CASE(Quaternion);
454 VERIFY_CASE(DelegatedType);
455
456 case kTypeUnknown:
457 // resolveSchemaType:... or StringToSchemaType() should have provided an error.
458 *outStop = YES;
459 }
460 }
461 @catch (NSException *exception)
462 {
463 error = Error(kPListErrorInternal, (BackLinkChain *)&keyPath, @"Uncaught exception %@: %@ in plist verifier for \"%@\" at %@.", [exception name], [exception reason], name, KeyPathToString(keyPath));
464 }
465
467
468 if (error != nil)
469 {
470 if (!tentative && !IsFailureAlreadyReportedError(error))
471 {
472 *outStop = ![self delegateVerifierWithPropertyList:rootPList
473 named:name
474 failedForProperty:subProperty
475 withError:error
476 expectedType:subSchema];
477 }
478 else if (tentative) *outStop = YES;
479 }
480
481 if (outError != NULL && error != nil)
482 {
483 *outError = [error retain];
484 [pool release];
485 [error autorelease];
486 }
487 else
488 {
489 [pool release];
490 }
491
492 return error == nil;
493}
@ kPListErrorInternal
static SchemaType StringToSchemaType(NSString *string, NSError **outError)
#define DebugDumpPopIndent()
#define DebugDumpIndent()
#define VERIFY_CASE(T)
#define DebugDumpPushIndent()
static BOOL IsFailureAlreadyReportedError(NSError *error)

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