]> err.no Git - sope/blob - sope-appserver/WOXML/WOXMLMappingEntity.m
PCH support
[sope] / sope-appserver / WOXML / WOXMLMappingEntity.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include "WOXMLMappingEntity.h"
23 #include "WOXMLMappingProperty.h"
24 #include "common.h"
25
26 @implementation WOXMLMappingEntity
27
28 - (void)dealloc {
29   RELEASE(self->name);
30   RELEASE(self->xmlTag);
31   RELEASE(self->unmappedTagsKey);
32   RELEASE(self->contentsKey);
33   RELEASE(self->properties);
34   [super dealloc];
35 }
36
37 /* validity */
38
39 - (BOOL)isValid {
40   if ([self->name length] == 0)
41     return NO;
42   if ([self->xmlTag length] == 0)
43     return NO;
44   return YES;
45 }
46
47 /* attributes */
48
49 - (void)setName:(NSString *)_name {
50   ASSIGN(self->name, _name);
51 }
52 - (NSString *)name {
53   return self->name;
54 }
55
56 - (void)setXmlTag:(NSString *)_xmlTag {
57   ASSIGN(self->xmlTag, _xmlTag);
58 }
59 - (NSString *)xmlTag {
60   return self->xmlTag;
61 }
62
63 - (void)setUnmappedTagsKey:(NSString *)_unmappedTagsKey {
64   ASSIGN(self->unmappedTagsKey, _unmappedTagsKey);
65 }
66 - (NSString *)unmappedTagsKey {
67   return self->unmappedTagsKey;
68 }
69
70 - (void)setContentsKey:(NSString *)_contentsKey {
71   ASSIGN(self->contentsKey, _contentsKey);
72 }
73 - (NSString *)contentsKey {
74   return self->contentsKey;
75 }
76
77 - (void)setIgnoreUnmappedTags:(BOOL)_flag {
78   self->ignoreUnmappedTags = _flag;
79 }
80 - (BOOL)ignoreUnmappedTags {
81   return self->ignoreUnmappedTags;
82 }
83
84 /* properties */
85
86 - (void)addProperty:(WOXMLMappingProperty *)_property {
87   NSAssert1([_property isValid], @"tried to add invalid property %@", _property);
88   
89   if (self->properties == nil)
90     self->properties = [[NSMutableArray alloc] init];
91   if (self->tagToProperty == nil)
92     self->tagToProperty = [[NSMutableDictionary alloc] init];
93   
94   if ([self->tagToProperty objectForKey:[_property xmlTag]]) {
95     NSLog(@"WARNING: already defined propery for tag %@", [_property xmlTag]);
96     return;
97   }
98
99   [self->properties    addObject:_property];
100   [self->tagToProperty setObject:_property forKey:[_property xmlTag]];
101 }
102
103 - (WOXMLMappingProperty *)propertyForXmlTag:(NSString *)_xmlTag {
104   return [self->tagToProperty objectForKey:_xmlTag];
105 }
106
107 - (NSArray *)properties {
108   return self->properties;
109 }
110
111 /* XML representation */
112
113 - (NSString *)xmlStringValue {
114   NSMutableString *s;
115   NSEnumerator *e;
116   id prop;
117
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"];
126   
127   e = [[self properties] objectEnumerator];
128   while ((prop = [e nextObject]))
129     [s appendString:[prop xmlStringValue]];
130   
131   [s appendString:@"</entity>\n"];
132   return s;
133 }
134
135 /* description */
136
137 - (NSString *)description {
138   NSMutableString *s;
139
140   s = [NSMutableString stringWithCapacity:100];
141   [s appendFormat:@"<%@ 0x%08X:", NSStringFromClass([self class]), self];
142
143   if ([self name])
144     [s appendFormat:@" name=%@", [self name]];
145   if ([self xmlTag])
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]];
151   
152   if (self->ignoreUnmappedTags)
153     [s appendString:@" ignore-unmapped"];
154   
155   [s appendString:@">"];
156   return s;
157 }
158
159 @end /* WOXMLMappingEntity */