2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "WOXMLMappingEntity.h"
23 #include "WOXMLMappingProperty.h"
26 @implementation WOXMLMappingEntity
30 RELEASE(self->xmlTag);
31 RELEASE(self->unmappedTagsKey);
32 RELEASE(self->contentsKey);
33 RELEASE(self->properties);
40 if ([self->name length] == 0)
42 if ([self->xmlTag length] == 0)
49 - (void)setName:(NSString *)_name {
50 ASSIGN(self->name, _name);
56 - (void)setXmlTag:(NSString *)_xmlTag {
57 ASSIGN(self->xmlTag, _xmlTag);
59 - (NSString *)xmlTag {
63 - (void)setUnmappedTagsKey:(NSString *)_unmappedTagsKey {
64 ASSIGN(self->unmappedTagsKey, _unmappedTagsKey);
66 - (NSString *)unmappedTagsKey {
67 return self->unmappedTagsKey;
70 - (void)setContentsKey:(NSString *)_contentsKey {
71 ASSIGN(self->contentsKey, _contentsKey);
73 - (NSString *)contentsKey {
74 return self->contentsKey;
77 - (void)setIgnoreUnmappedTags:(BOOL)_flag {
78 self->ignoreUnmappedTags = _flag;
80 - (BOOL)ignoreUnmappedTags {
81 return self->ignoreUnmappedTags;
86 - (void)addProperty:(WOXMLMappingProperty *)_property {
87 NSAssert1([_property isValid], @"tried to add invalid property %@", _property);
89 if (self->properties == nil)
90 self->properties = [[NSMutableArray alloc] init];
91 if (self->tagToProperty == nil)
92 self->tagToProperty = [[NSMutableDictionary alloc] init];
94 if ([self->tagToProperty objectForKey:[_property xmlTag]]) {
95 NSLog(@"WARNING: already defined propery for tag %@", [_property xmlTag]);
99 [self->properties addObject:_property];
100 [self->tagToProperty setObject:_property forKey:[_property xmlTag]];
103 - (WOXMLMappingProperty *)propertyForXmlTag:(NSString *)_xmlTag {
104 return [self->tagToProperty objectForKey:_xmlTag];
107 - (NSArray *)properties {
108 return self->properties;
111 /* XML representation */
113 - (NSString *)xmlStringValue {
118 s = [NSMutableString stringWithCapacity:4096];
119 [s appendString:@"<entity"];
120 [s appendString:@" name='"];
121 [s appendString:[self name]];
122 [s appendString:@"' xmlTag='"];
123 [s appendString:[self xmlTag]];
124 [s appendString:@"'"];
125 [s appendString:@">\n"];
127 e = [[self properties] objectEnumerator];
128 while ((prop = [e nextObject]))
129 [s appendString:[prop xmlStringValue]];
131 [s appendString:@"</entity>\n"];
137 - (NSString *)description {
140 s = [NSMutableString stringWithCapacity:100];
141 [s appendFormat:@"<%@ 0x%08X:", NSStringFromClass([self class]), self];
144 [s appendFormat:@" name=%@", [self name]];
146 [s appendFormat:@" tag=%@", [self xmlTag]];
147 if ([self unmappedTagsKey])
148 [s appendFormat:@" unmapped=%@", [self unmappedTagsKey]];
149 if ([self contentsKey])
150 [s appendFormat:@" content=%@", [self contentsKey]];
152 if (self->ignoreUnmappedTags)
153 [s appendString:@" ignore-unmapped"];
155 [s appendString:@">"];
159 @end /* WOXMLMappingEntity */