Oolite
Loading...
Searching...
No Matches
OOPListSchemaVerifier Class Reference

#include <OOPListSchemaVerifier.h>

Inheritance diagram for OOPListSchemaVerifier:
Collaboration diagram for OOPListSchemaVerifier:

Instance Methods

(id) - initWithSchema:
(void) - setDelegate:
(id) - delegate
(BOOL) - verifyPropertyList:named:
(void) - dealloc [implementation]
(BOOL) - delegateVerifierWithPropertyList:named:testProperty:atPath:againstType:error: [implementation]
(BOOL) - delegateVerifierWithPropertyList:named:failedForProperty:withError:expectedType: [implementation]
(BOOL) - verifyPList:named:subProperty:againstSchemaType:atPath:tentative:error:stop: [implementation]
(NSDictionary *) - resolveSchemaType:atPath:error: [implementation]

Class Methods

(instancetype) + verifierWithSchema:
(NSString *) + descriptionForKeyPath:

Private Attributes

NSDictionary * _schema
NSDictionary * _definitions
id _delegate
uint32_t _badDelegateWarning: 1

Detailed Description

Definition at line 38 of file OOPListSchemaVerifier.h.

Method Documentation

◆ dealloc

- (void) dealloc
implementation

Definition at line 253 of file OOPListSchemaVerifier.m.

254{
255 [_schema release];
256 [_definitions release];
257
258 [super dealloc];
259}

References dealloc.

Referenced by dealloc.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ delegate

- (id) delegate

Definition at line 269 of file OOPListSchemaVerifier.m.

270{
271 return _delegate;
272}

References _delegate, and delegate.

Referenced by delegate, and setDelegate:.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ delegateVerifierWithPropertyList:named:failedForProperty:withError:expectedType:

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

Provided by category OOPListSchemaVerifier(OOPrivate).

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

Referenced by Verify_Dictionary(), and OOPListSchemaVerifier(OOPrivate)::verifyPList:named:subProperty:againstSchemaType:atPath:tentative:error:stop:.

Here is the caller graph for this function:

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

Provided by category OOPListSchemaVerifier(OOPrivate).

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.");
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

Referenced by Verify_DelegatedType().

Here is the caller graph for this function:

◆ descriptionForKeyPath:

+ (NSString *) descriptionForKeyPath: (NSArray*) keyPath

Definition at line 291 of file OOPListSchemaVerifier.m.

291 :(NSArray*)keyPath
292{
293 NSMutableString* result = nil;
294 id component = nil;
295 BOOL first = YES;
296
297 result = [NSMutableString string];
298
299 foreach (component, keyPath) {
300 if ([component isKindOfClass:[NSNumber class]]) {
301 [result appendFormat:@"[%@]", component];
302 } else if ([component isKindOfClass:[NSString class]]) {
303 if (!first)
304 [result appendString:@"."];
305 [result appendString:component];
306 } else
307 return nil;
308 first = NO;
309 }
310
311 if (first) {
312 // Empty path
313 return @"root";
314 }
315
316 return result;
317}

References nil.

Referenced by KeyPathToString(), NSError(OOPListSchemaVerifierConveniences)::plistKeyPathDescription, and OOCheckShipDataPListVerifierStage(OOPrivate)::verifier:withPropertyList:named:testProperty:atPath:againstType:error:.

Here is the caller graph for this function:

◆ initWithSchema:

- (id) initWithSchema: (NSDictionary*) schema

Definition at line 234 of file OOPListSchemaVerifier.m.

234 :(NSDictionary*)schema
235{
236 self = [super init];
237 if (self != nil) {
238 _schema = [schema retain];
239 _definitions = [[_schema oo_dictionaryForKey:@"$w0"] retain];
240 sDebugDump = [[NSUserDefaults standardUserDefaults] boolForKey:@"plist-schema-verifier-dump-structure"];
241 if (sDebugDump)
242 OOLogSetDisplayMessagesInClass(@"verifyOXP.verbose.plistDebugDump", YES);
243
244 if (_schema == nil) {
245 [self release];
246 self = nil;
247 }
248 }
249
250 return self;
251}
void OOLogSetDisplayMessagesInClass(NSString *inClass, BOOL inFlag)
Definition OOLogging.m:172
static BOOL sDebugDump

References _definitions, _schema, nil, OOLogSetDisplayMessagesInClass(), and sDebugDump.

Here is the call graph for this function:

◆ resolveSchemaType:atPath:error:

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

Provided by category OOPListSchemaVerifier(OOPrivate).

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}
NSString *const kUndefinedMacroErrorKey
@ kPListErrorSchemaBadTypeSpecifier
@ kPListErrorSchemaUndefiniedMacroReference
static NSString * StringForErrorReport(NSString *string)
static NSError * Error(OOPListSchemaVerifierErrorCode errorCode, BackLinkChain *keyPath, NSString *format,...)

Referenced by OOPListSchemaVerifier(OOPrivate)::verifyPList:named:subProperty:againstSchemaType:atPath:tentative:error:stop:.

Here is the caller graph for this function:

◆ setDelegate:

- (void) setDelegate: (id) delegate

Definition at line 261 of file OOPListSchemaVerifier.m.

261 :(id)delegate
262{
263 if (_delegate != delegate) {
266 }
267}

References _badDelegateWarning, _delegate, and delegate.

Referenced by OOCheckShipDataPListVerifierStage::run.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ verifierWithSchema:

+ (id) verifierWithSchema: (NSDictionary*) schema

Definition at line 229 of file OOPListSchemaVerifier.m.

229 :(NSDictionary*)schema
230{
231 return [[[self alloc] initWithSchema:schema] autorelease];
232}

Referenced by OOCheckShipDataPListVerifierStage::run.

Here is the caller 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 
implementation

Provided by category OOPListSchemaVerifier(OOPrivate).

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

Referenced by verifyPropertyList:named:.

Here is the caller graph for this function:

◆ verifyPropertyList:named:

- (BOOL) verifyPropertyList: (id) plist
named: (NSString*) name 

Definition at line 274 of file OOPListSchemaVerifier.m.

274 :(id)plist named:(NSString*)name
275{
276 BOOL OK;
277 BOOL stop = NO;
278
279 OK = [self verifyPList:plist
280 named:name
281 subProperty:plist
282 againstSchemaType:_schema
283 atPath:BackLinkRoot()
284 tentative:NO
285 error:NULL
286 stop:&stop];
287
288 return OK;
289}

References verifyPList:named:subProperty:againstSchemaType:atPath:tentative:error:stop:.

Here is the call graph for this function:

Member Data Documentation

◆ _badDelegateWarning

- (uint32_t) _badDelegateWarning
private

Definition at line 44 of file OOPListSchemaVerifier.h.

Referenced by setDelegate:.

◆ _definitions

- (NSDictionary*) _definitions
private

Definition at line 41 of file OOPListSchemaVerifier.h.

Referenced by initWithSchema:.

◆ _delegate

- (id) _delegate
private

Definition at line 43 of file OOPListSchemaVerifier.h.

Referenced by delegate, and setDelegate:.

◆ _schema

- (NSDictionary*) _schema
private

Definition at line 40 of file OOPListSchemaVerifier.h.

Referenced by initWithSchema:.


The documentation for this class was generated from the following files: