2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo 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 OGo 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 OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "WOXMLMappingEntity.h"
24 #include "WOXMLMappingProperty.h"
27 @implementation WOXMLMappingEntity
31 RELEASE(self->xmlTag);
32 RELEASE(self->unmappedTagsKey);
33 RELEASE(self->contentsKey);
34 RELEASE(self->properties);
41 if ([self->name length] == 0)
43 if ([self->xmlTag length] == 0)
50 - (void)setName:(NSString *)_name {
51 ASSIGN(self->name, _name);
57 - (void)setXmlTag:(NSString *)_xmlTag {
58 ASSIGN(self->xmlTag, _xmlTag);
60 - (NSString *)xmlTag {
64 - (void)setUnmappedTagsKey:(NSString *)_unmappedTagsKey {
65 ASSIGN(self->unmappedTagsKey, _unmappedTagsKey);
67 - (NSString *)unmappedTagsKey {
68 return self->unmappedTagsKey;
71 - (void)setContentsKey:(NSString *)_contentsKey {
72 ASSIGN(self->contentsKey, _contentsKey);
74 - (NSString *)contentsKey {
75 return self->contentsKey;
78 - (void)setIgnoreUnmappedTags:(BOOL)_flag {
79 self->ignoreUnmappedTags = _flag;
81 - (BOOL)ignoreUnmappedTags {
82 return self->ignoreUnmappedTags;
87 - (void)addProperty:(WOXMLMappingProperty *)_property {
88 NSAssert1([_property isValid], @"tried to add invalid property %@", _property);
90 if (self->properties == nil)
91 self->properties = [[NSMutableArray alloc] init];
92 if (self->tagToProperty == nil)
93 self->tagToProperty = [[NSMutableDictionary alloc] init];
95 if ([self->tagToProperty objectForKey:[_property xmlTag]]) {
96 NSLog(@"WARNING: already defined propery for tag %@", [_property xmlTag]);
100 [self->properties addObject:_property];
101 [self->tagToProperty setObject:_property forKey:[_property xmlTag]];
104 - (WOXMLMappingProperty *)propertyForXmlTag:(NSString *)_xmlTag {
105 return [self->tagToProperty objectForKey:_xmlTag];
108 - (NSArray *)properties {
109 return self->properties;
112 /* XML representation */
114 - (NSString *)xmlStringValue {
119 s = [NSMutableString stringWithCapacity:4096];
120 [s appendString:@"<entity"];
121 [s appendString:@" name='"];
122 [s appendString:[self name]];
123 [s appendString:@"' xmlTag='"];
124 [s appendString:[self xmlTag]];
125 [s appendString:@"'"];
126 [s appendString:@">\n"];
128 e = [[self properties] objectEnumerator];
129 while ((prop = [e nextObject]))
130 [s appendString:[prop xmlStringValue]];
132 [s appendString:@"</entity>\n"];
138 - (NSString *)description {
141 s = [NSMutableString stringWithCapacity:100];
142 [s appendFormat:@"<%@ 0x%08X:", NSStringFromClass([self class]), self];
145 [s appendFormat:@" name=%@", [self name]];
147 [s appendFormat:@" tag=%@", [self xmlTag]];
148 if ([self unmappedTagsKey])
149 [s appendFormat:@" unmapped=%@", [self unmappedTagsKey]];
150 if ([self contentsKey])
151 [s appendFormat:@" content=%@", [self contentsKey]];
153 if (self->ignoreUnmappedTags)
154 [s appendString:@" ignore-unmapped"];
156 [s appendString:@">"];
160 @end /* WOXMLMappingEntity */