1
/* $Id: GVAttributeSchema.m,v 1.1 2008/02/11 12:34:07 glenlow Exp $ $Revision: 1.1 $ */
2
/* vim:set shiftwidth=4 ts=8: */
4
/**********************************************************
5
* This software is part of the graphviz package *
6
* http://www.graphviz.org/ *
8
* Copyright (c) 1994-2008 AT&T Corp. *
9
* and is licensed under the *
10
* Common Public License, Version 1.0 *
13
* Information and Software Systems Research *
14
* AT&T Research, Florham Park NJ *
15
**********************************************************/
17
#import "GVAttributeSchema.h"
19
static NSXMLDocument *_attributes = nil;
20
static NSTextFieldCell *_stringCell = nil;
21
static NSComboBoxCell *_enumCell = nil;
23
@implementation GVAttributeSchema
27
_attributes = [[NSXMLDocument alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"attributes" ofType:@"xml"]] options:0 error:nil];
29
NSFont* smallFont = [NSFont labelFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]];
31
_stringCell = [[NSTextFieldCell alloc] init];
32
[_stringCell setControlSize:NSSmallControlSize];
33
[_stringCell setDrawsBackground:NO];
34
[_stringCell setEditable:YES];
35
[_stringCell setEnabled:YES];
36
[_stringCell setFont:smallFont];
38
_enumCell = [[NSComboBoxCell alloc] init];
39
[_enumCell setBezeled:NO];
40
[_enumCell setButtonBordered:NO];
41
[_enumCell setCompletes:YES];
42
[_enumCell setControlSize:NSSmallControlSize];
43
[_enumCell setDrawsBackground:NO];
44
[_enumCell setEditable:YES];
45
[_enumCell setEnabled:YES];
46
[_enumCell setFont:smallFont];
47
[_enumCell setHasVerticalScroller:NO];
50
+ (NSArray*)attributeSchemasWithComponent:(NSString *)component
52
NSMutableArray* attributeSchemas = [NSMutableArray array];
53
for (NSXMLElement* element in [_attributes nodesForXPath:[NSString stringWithFormat:@"/xsd:schema/xsd:complexType[@name='%@']/xsd:attribute", component] error:nil])
54
[attributeSchemas addObject:[[[GVAttributeSchema alloc] initWithXMLElement:element] autorelease]];
55
return attributeSchemas;
58
- (id)initWithXMLElement:(NSXMLElement *)element
60
if (self = [super init])
61
_element = [element retain];
67
return [[_element attributeForName:@"ref"] stringValue];
72
NSCell *typeCell = _stringCell;
74
/* determine which cell to return */
75
NSString *type = [[[_attributes nodesForXPath:[NSString stringWithFormat:@"/xsd:schema/xsd:attribute[@name='%@']/@type[1]", [self name]] error:nil] lastObject] stringValue];
77
if (![type hasPrefix:@"xsd:"]) {
78
NSXMLElement *simpleType = [[_attributes nodesForXPath:[NSString stringWithFormat:@"/xsd:schema/xsd:simpleType[@name='%@'][1]", type] error:nil] lastObject];
79
NSArray *enumerations = [simpleType nodesForXPath:@"xsd:restriction/xsd:enumeration" error:nil];
80
if ([enumerations count]) {
81
[_enumCell removeAllItems];
82
for (NSXMLElement *enumeration in enumerations)
83
[_enumCell addItemWithObjectValue: [[enumeration attributeForName: @"value"] stringValue]];
89
/* determine the default value */
90
NSString* defaultValue = [[_element attributeForName:@"default"] stringValue];
91
if ([typeCell respondsToSelector:@selector(setPlaceholderString:)])
92
[typeCell performSelector:@selector(setPlaceholderString:) withObject:defaultValue];
96
- (NSString*)documentation
98
return [[[_attributes nodesForXPath:[NSString stringWithFormat:@"/xsd:schema/xsd:attribute[@name='%@']/xsd:annotation/xsd:documentation[1]", [self name]] error:nil] lastObject] XMLString];