~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to sope-appserver/WOXML/WOXMLSaxModelHandler.m

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "WOXMLSaxModelHandler.h"
 
23
#include "WOXMLMappingEntity.h"
 
24
#include "WOXMLMappingModel.h"
 
25
#include "WOXMLMappingProperty.h"
 
26
#include "common.h"
 
27
 
 
28
@implementation WOXMLSaxModelHandler
 
29
 
 
30
- (void)dealloc {
 
31
  RELEASE(self->currentModel);
 
32
  RELEASE(self->currentProperty);
 
33
  RELEASE(self->currentEntity);
 
34
  [super dealloc];
 
35
}
 
36
 
 
37
- (WOXMLMappingModel *)model {
 
38
  return AUTORELEASE(RETAIN(self->currentModel));
 
39
}
 
40
 
 
41
/* tag handler */
 
42
 
 
43
- (void)startModel:(id<SaxAttributes>)_attrs {
 
44
  if ((self->currentProperty != nil) || (self->currentEntity != nil)) {
 
45
    NSLog(@"cannot nest 'model' tags inside property or entity tags !");
 
46
    return;
 
47
  }
 
48
 
 
49
  RELEASE(self->currentModel); self->currentModel = nil;
 
50
  self->currentModel = [[WOXMLMappingModel alloc] init];
 
51
}
 
52
- (void)endModel {
 
53
  if ((self->currentProperty != nil) || (self->currentEntity != nil))
 
54
    return;
 
55
}
 
56
 
 
57
- (void)startEntity:(id<SaxAttributes>)_attrs {
 
58
  NSString *s;
 
59
  
 
60
  if (self->currentProperty) {
 
61
    NSLog(@"cannot nest 'entity' tags inside property tags !");
 
62
    return;
 
63
  }
 
64
  if (self->currentEntity) {
 
65
    NSLog(@"cannot nest 'entity' tags inside entity tags !");
 
66
    return;
 
67
  }
 
68
  if (self->currentModel == nil) {
 
69
    NSLog(@"missing 'model' parent element for 'entity' tag !");
 
70
    return;
 
71
  }
 
72
  
 
73
  self->currentEntity = [[WOXMLMappingEntity alloc] init];
 
74
  
 
75
  if ((s = [_attrs valueForRawName:@"name"]))
 
76
    [self->currentEntity setName:s];
 
77
  if ((s = [_attrs valueForRawName:@"xmlTag"]))
 
78
    [self->currentEntity setXmlTag:s];
 
79
  if ((s = [_attrs valueForRawName:@"unmappedTagsKey"]))
 
80
    [self->currentEntity setUnmappedTagsKey:s];
 
81
  if ((s = [_attrs valueForRawName:@"contentsKey"]))
 
82
    [self->currentEntity setContentsKey:s];
 
83
  
 
84
  if ((s = [_attrs valueForRawName:@"ignoreUnmappedTags"])) {
 
85
    [self->currentEntity setIgnoreUnmappedTags:
 
86
         [[s uppercaseString] isEqualToString:@"YES"]];
 
87
  }
 
88
}
 
89
- (void)endEntity {
 
90
  if ((self->currentProperty != nil) || (self->currentModel == nil))
 
91
    return;
 
92
  
 
93
  if (self->currentEntity) {
 
94
    if ([self->currentEntity isValid])
 
95
      [self->currentModel addEntity:self->currentEntity];
 
96
    RELEASE(self->currentEntity); self->currentEntity = nil;
 
97
  }
 
98
}
 
99
 
 
100
- (void)startProperty:(id<SaxAttributes>)_attrs {
 
101
  NSString *s;
 
102
  
 
103
  if (self->currentProperty) {
 
104
    NSLog(@"cannot nest 'property' tags inside property tags !");
 
105
    return;
 
106
  }
 
107
  if ((self->currentEntity == nil) || (self->currentModel == nil)) {
 
108
    NSLog(@"missing 'entity' parent element for 'property' tag !");
 
109
    return;
 
110
  }
 
111
 
 
112
  self->currentProperty = [[WOXMLMappingProperty alloc] init];
 
113
 
 
114
  if ((s = [_attrs valueForRawName:@"name"]))
 
115
    [self->currentProperty setName:s];
 
116
  if ((s = [_attrs valueForRawName:@"xmlTag"]))
 
117
    [self->currentProperty setXmlTag:s];
 
118
  if ((s = [_attrs valueForRawName:@"codeBasedOn"]))
 
119
    [self->currentProperty setCodeBasedOn:s];
 
120
  if ((s = [_attrs valueForRawName:@"outputTags"]))
 
121
    [self->currentProperty setOutputTags:s];
 
122
  
 
123
  if ((s = [_attrs valueForRawName:@"attribute"])) {
 
124
    [self->currentProperty setAttribute:
 
125
         [[s uppercaseString] isEqualToString:@"YES"]];
 
126
  }
 
127
  if ((s = [_attrs valueForRawName:@"forceList"])) {
 
128
    [self->currentProperty setForceList:
 
129
         [[s uppercaseString] isEqualToString:@"YES"]];
 
130
  }
 
131
  if ((s = [_attrs valueForRawName:@"reportEmptyValues"])) {
 
132
    [self->currentProperty setReportEmptyValues:
 
133
         [[s uppercaseString] isEqualToString:@"YES"]];
 
134
  }
 
135
}
 
136
- (void)endProperty {
 
137
  if ((self->currentEntity == nil) || (self->currentModel == nil))
 
138
    return;
 
139
 
 
140
  if (self->currentProperty) {
 
141
    if ([self->currentProperty isValid])
 
142
      [self->currentEntity addProperty:self->currentProperty];
 
143
 
 
144
    RELEASE(self->currentProperty); self->currentProperty = nil;
 
145
  }
 
146
}
 
147
 
 
148
/* SAX */
 
149
 
 
150
- (void)startDocument {
 
151
  RELEASE(self->currentModel);    self->currentModel    = nil;
 
152
  RELEASE(self->currentEntity);   self->currentEntity   = nil;
 
153
  RELEASE(self->currentProperty); self->currentProperty = nil;
 
154
}
 
155
- (void)endDocument {
 
156
}
 
157
 
 
158
- (void)startElement:(NSString *)_localName
 
159
  namespace:(NSString *)_ns
 
160
  rawName:(NSString *)_rawName
 
161
  attributes:(id<SaxAttributes>)_attrs
 
162
{
 
163
  if ([_rawName isEqualToString:@"model"])
 
164
    [self startModel:_attrs];
 
165
  else if ([_rawName isEqualToString:@"entity"])
 
166
    [self startEntity:_attrs];
 
167
  else if ([_rawName isEqualToString:@"property"])
 
168
    [self startProperty:_attrs];
 
169
}
 
170
- (void)endElement:(NSString *)_localName
 
171
  namespace:(NSString *)_ns
 
172
  rawName:(NSString *)_rawName
 
173
{
 
174
  if ([_rawName isEqualToString:@"model"])
 
175
    [self endModel];
 
176
  else if ([_rawName isEqualToString:@"entity"])
 
177
    [self endEntity];
 
178
  else if ([_rawName isEqualToString:@"property"])
 
179
    [self endProperty];
 
180
}
 
181
 
 
182
@end /* WOXMLSaxModelHandler */