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 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 

Definition at line 115 of file OOPListSchemaVerifier.m.

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

Definition at line 115 of file OOPListSchemaVerifier.m.

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

Definition at line 115 of file OOPListSchemaVerifier.m.

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

Definition at line 115 of file OOPListSchemaVerifier.m.

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