summaryrefslogtreecommitdiffstats
path: root/tags/cpp-sdo-1.0.incubating-M3/runtime/core/src/commonj/sdo/ChangeSummaryBuilder.h
blob: 59e158aeedb0892ad7d2e46da40177262aff1e1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 *   
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

/* $Rev$ $Date$ */


#ifndef _CHANGESUMMARYBUILDER_H_
#define _CHANGESUMMARYBUILDER_H_

#include "commonj/sdo/disable_warn.h"

#include "commonj/sdo/SAX2Parser.h"
#include "commonj/sdo/DataFactory.h"
#include "commonj/sdo/DataObject.h"
#include "commonj/sdo/SAX2Namespaces.h"
#include "commonj/sdo/PropertySetting.h"
#include "commonj/sdo/ChangeSummaryImpl.h"


#include <stack>

namespace commonj
{
    namespace sdo
    {

/**
 * createDelete is a class holding a creation or deletion in 
 * a change summary builder.
 * When rebuilding a change summary from the serialized version
 * creates and deletes are stored in these until they can be 
 * converted into a change summary.
 */


        class createDelete
        {
        public:
            createDelete();
            createDelete(SDOXMLString intype);
            virtual ~createDelete();
            SDOXMLString type;
            SDOXMLString value;
            int indexshift;
        };

/**
 * changeAttribute is a class holding a changed attribute in a 
 * change summary builder.
 * When rebuilding a change summary from the serialized version
 * changes are stored in these until they can be 
 * converted into a change summary.
 */

        class changeAttribute
        {
        public:
            changeAttribute();
            changeAttribute(SDOXMLString inname,
                            SDOXMLString invalue);
            virtual ~changeAttribute();
            SDOXMLString name;
            SDOXMLString value;
        };

/**
 * changeElement is a class holding a changed element in a change summary builder.
 * When rebuilding a change summary from the serialized version
 * changes are stored in these until they can be 
 * converted into a change summary.
 */
        class changeElement
        {
        public:
            changeElement();
            changeElement(SDOXMLString inname, 
                        SDOXMLString inpath, bool isRef, bool isDel);
            changeElement(SDOXMLString inname,
                        SDOXMLString inpath,
                          SDOXMLString invalue, bool isRef, bool isDel);
            virtual ~changeElement();
            SDOXMLString name;
            SDOXMLString value;
            SDOXMLString path;
            bool isReference;
            bool isDeletion;
            int index;
        };

/**
 * change is a class holding a change in a change summary builder.
 * When rebuilding a change summary from the serialized version
 * changes are stored in these until they can be 
 * converted into a change summary.
 * Changes consist of changeAttributes and changeElements
 */


        class change
        {
        public:
            change();
            change(SDOXMLString inname, SDOXMLString ref);
            void addAttribute(changeAttribute ca);
            void addElement(changeElement ce);
            std::list<changeAttribute> attributes;
            std::list<changeElement> elements;
            SDOXMLString name;
            SDOXMLString reference;
        };
        
/**
 * deletionAttribute is a class holding a deletion attribute in a change summary builder.
 * When rebuilding a change summary from the serialized version
 * deletions are stored in these until they can be 
 * converted into a change summary.
 * Changes consist of deletionAttributes and deletionElements
 */
        class deletionAttribute
        {
        public:
            deletionAttribute();
            deletionAttribute(SDOXMLString inname,
                            SDOXMLString invalue);
            virtual ~deletionAttribute();
            SDOXMLString name;
            SDOXMLString value;
        };

/**
 * deletionElement is a class holding a deletion element in a change summary builder.
 * When rebuilding a change summary from the serialized version
 * deletions are stored in these until they can be 
 * converted into a change summary.
 * Changes consist of deletionAttributes and deletionElements
 */
        class deletionElement
        {
        public:
            deletionElement();
            deletionElement(SDOXMLString inname);
            deletionElement(SDOXMLString inname,
                            SDOXMLString inpath, int inindex);
            virtual ~deletionElement();
            SDOXMLString name;
            SDOXMLString value;
            bool isDeletion;
            int index;
        };


/**
 * deletions is a class holding a deletion in a change summary builder.
 * When rebuilding a change summary from the serialized version
 * deletions are stored in these until they can be 
 * converted into a change summary.
 * Changes consist of deletionAttributes and deletionElements
 */

        class deletion
        {
        public:
            deletion();
            deletion(SDOXMLString inname, SDOXMLString ref);
            void addAttribute(deletionAttribute ca);
            void addElement(deletionElement ce);
            void insertElement(deletionElement ce);
            SDOXMLString name;
            SDOXMLString reference;
            DataObjectPtr dob; /* the recreated one*/
            std::list<deletionAttribute> attributes;
            std::list<deletionElement> elements;
            bool completedprocessing;
        };

    /** deletionListElement is an item in a list of deletions in a change summary builder.
     *
     * All the deletions are stored whilst rebuilding a change
     * summary, then applied. These list elements hold them.
     */

        class deletionListElement
        {
        public:
            deletionListElement();
            deletionListElement(deletion in_del, int in_index, SDOXMLString in_prev);
            SDOXMLString previous;
            deletion del;
            int index;
        };

/**
 * The ChangeSummaryBuilder recreates a change summary from the
 * XML representations of the changes, creations and deletions.
 * It does this by populating a list of changes as though they had
 * been applied to the current data graph.
 */

        class ChangeSummaryBuilder
        {

            
        public:
            
            enum CsState
            {
             baseState,
             dealingWithCreateDelete,
             dealingWithChange,
             dealingWithChangeElement,
             dealingWithDeletion,
             dealingWithDeletionElement
            };


            ChangeSummaryBuilder(
                DataFactoryPtr df,
                DataObjectPtr& rootDO);
            
            virtual ~ChangeSummaryBuilder();

    
            virtual void processStart(
                const SDOXMLString& localname,
                const SDOXMLString& prefix,
                const SDOXMLString& URI,
                const SAX2Namespaces& namespaces,
                const SAX2Attributes& attributes);

            virtual void processChars(
                const SDOXMLString& chars);

            virtual void processEnd(
                const SDOXMLString& localname,
                const SDOXMLString& prefix,
                const SDOXMLString& URI);

            virtual void buildChangeSummary(
                 DataObjectPtr changeSummaryDO);

            virtual void populateDeletion(ChangeSummaryImpl* csi, DataObjectPtr dob,
                                            int index);

            virtual void handleDeletion(
                              ChangeSummaryImpl* csi, 
                              int currentIndex, 
                              DataObjectPtr cont,
                              SDOXMLString path,
                              SDOXMLString prop);

            virtual void handleDeletion(ChangeSummaryImpl* csi,
                int index,
                SDOXMLString path);

            void shiftIndices(int index, int delta);
            
            SDOXMLString shiftedIndex(int index);


        private:
            DataFactoryPtr dataFactory;
            DataObjectPtr&  rootDataObject;
            
            CsState currentState;

            std::vector<deletionListElement> deletionList;
            std::vector<SDOXMLString> currentLocation;
            std::vector<createDelete> createDeletes;

            std::vector<change> changes;
            change currentChange;
            SDOXMLString previousChange;
            SDOXMLString currentLocalName;
            int changeIndex;

            std::vector<deletion> deletions;
            deletion currentDeletion;
            SDOXMLString previousDeletion;
            int deletionIndex;
            int deletionLevel;


        };
    } // End - namespace sdo
} // End - namespace commonj

#endif //_CHANGESUMMARYBUILDER_H_