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