(file) Return to SCMOInternalXmlEncoder.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 thilo.boehm 1.2 //%LICENSE////////////////////////////////////////////////////////////////
  2                 //
  3                 // Licensed to The Open Group (TOG) under one or more contributor license
  4                 // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5                 // this work for additional information regarding copyright ownership.
  6                 // Each contributor licenses this file to you under the OpenPegasus Open
  7                 // Source License; you may not use this file except in compliance with the
  8                 // License.
  9                 //
 10                 // Permission is hereby granted, free of charge, to any person obtaining a
 11                 // copy of this software and associated documentation files (the "Software"),
 12                 // to deal in the Software without restriction, including without limitation
 13                 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14                 // and/or sell copies of the Software, and to permit persons to whom the
 15                 // Software is furnished to do so, subject to the following conditions:
 16                 //
 17                 // The above copyright notice and this permission notice shall be included
 18                 // in all copies or substantial portions of the Software.
 19                 //
 20                 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21                 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 thilo.boehm 1.2 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23                 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24                 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25                 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26                 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27                 //
 28                 //////////////////////////////////////////////////////////////////////////
 29                 //
 30 marek       1.5 // This code implements part of PEP#348 - The CMPI infrastructure using SCMO
 31                 // (Single Chunk Memory Objects).
 32                 // The design document can be found on the OpenPegasus website openpegasus.org
 33                 // at https://collaboration.opengroup.org/pegasus/pp/documents/21210/PEP_348.pdf
 34                 //
 35 thilo.boehm 1.2 //%/////////////////////////////////////////////////////////////////////////////
 36                 
 37                 #include "SCMOInternalXmlEncoder.h"
 38                 #include <Pegasus/Common/SCMOXmlWriter.h>
 39                 
 40                 PEGASUS_NAMESPACE_BEGIN
 41                 
 42                 void SCMOInternalXmlEncoder::_putXMLInstance(
 43                     CIMBuffer& out,
 44 anusha.kandepu 1.4     const SCMOInstance& ci,
 45                        const CIMPropertyList& propertyList )
 46 thilo.boehm    1.2 {
 47                    
 48                        if (ci.isUninitialized())
 49                        {
 50                            out.putUint32(0);
 51                            out.putUint32(0);
 52                            out.putString(String());
 53                            out.putNamespaceName(CIMNamespaceName());
 54                        }
 55                        else
 56                        {
 57                            Buffer buf(4096);
 58                    
 59                            // Serialize instance as XML.
 60 anusha.kandepu 1.4         if (propertyList.isNull()) 
 61                            { 
 62                                Array<Uint32> emptyNodes; 
 63                                SCMOXmlWriter::appendInstanceElement(
 64                                    buf,
 65                                    ci,
 66                                    false,
 67                                    emptyNodes);
 68                            }   
 69                            else
 70                            {
 71                                Array<propertyFilterNodesArray_t> propFilterNodesArrays;
 72                                // This searches for an already created array of nodes, 
 73                                // if not found, creates it inside propFilterNodesArrays
 74                                const Array<Uint32> & nodes= 
 75                                    SCMOXmlWriter::getFilteredNodesArray( 
 76                                        propFilterNodesArrays, 
 77                                        ci,
 78                                        propertyList); 
 79                                SCMOXmlWriter::appendInstanceElement(
 80                                    buf,
 81 anusha.kandepu 1.4                 ci,
 82                                    true,
 83                                    nodes);
 84                            }
 85 thilo.boehm    1.2         buf.append('\0');
 86                    
 87                            out.putUint32(buf.size());
 88                            out.putBytes(buf.getData(), buf.size());
 89                            buf.clear();
 90                    
 91                            if (0 == ci.getClassName())
 92                            {
 93                                out.putUint32(0);
 94                                out.putString(String());
 95                                out.putNamespaceName(CIMNamespaceName());
 96                            }
 97                            else
 98                            {
 99                                // Serialize object path as XML.
100                                SCMOXmlWriter::appendValueReferenceElement(buf, ci, true);
101                                buf.append('\0');
102                    
103                                out.putUint32(buf.size());
104                                out.putBytes(buf.getData(), buf.size());
105                    
106 thilo.boehm    1.2             // Write hostname and namespace in UTF-16 format
107                                Uint32 len=0;
108                                const char* hn = ci.getHostName_l(len);
109                                out.putUTF8AsString(hn, len);
110                                const char * ns = ci.getNameSpace_l(len);
111                                out.putUTF8AsString(ns, len);
112                            }
113                        }
114                    }
115                    
116                    void SCMOInternalXmlEncoder::_putXMLNamedInstance(
117                        CIMBuffer& out,
118 anusha.kandepu 1.4     const Array<SCMOInstance> & ci, 
119                        const CIMPropertyList& propertyList)
120 thilo.boehm    1.2 {
121 anusha.kandepu 1.4     Array<propertyFilterNodesArray_t> propFilterNodesArrays;
122                        Array<Uint32> emptyNodes;
123                        for (Uint32 i = 0, n = ci.size(); i < n; i++)
124 thilo.boehm    1.2     {
125 anusha.kandepu 1.4         if (ci[i].isUninitialized())
126 thilo.boehm    1.2         {
127                                out.putUint32(0);
128 anusha.kandepu 1.4             out.putUint32(0);
129 thilo.boehm    1.2             out.putString(String());
130                                out.putNamespaceName(CIMNamespaceName());
131                            }
132                            else
133                            {
134 anusha.kandepu 1.4             Buffer buf(4096);
135                                // Serialize instance as XML.
136                                if (propertyList.isNull()) 
137                                { 
138                                    SCMOXmlWriter::appendInstanceElement( 
139                                        buf, 
140                                        ci[i], 
141                                        false, 
142                                        emptyNodes); 
143                                } 
144                                else 
145                                { 
146                                    // This searches for an already created array of nodes, 
147                                    // if not found, creates it inside propFilterNodesArrays 
148                                    const Array<Uint32> & nodes = 
149                                        SCMOXmlWriter::getFilteredNodesArray( 
150                                            propFilterNodesArrays, 
151                                            ci[i], 
152                                            propertyList);
153                                    SCMOXmlWriter::appendInstanceElement( 
154                                        buf, 
155 anusha.kandepu 1.4                     ci[i], 
156                                        true, 
157                                        nodes); 
158                                } 
159 thilo.boehm    1.2             buf.append('\0');
160                                out.putUint32(buf.size());
161                                out.putBytes(buf.getData(), buf.size());
162 anusha.kandepu 1.4             buf.clear();
163 thilo.boehm    1.2 
164 anusha.kandepu 1.4             if (0 == ci[i].getClassName())
165                                {
166                                    out.putUint32(0);
167                                    out.putString(String());
168                                    out.putNamespaceName(CIMNamespaceName());
169                                }
170                                else
171                                {
172                                    // Serialize object path as XML.
173                                    SCMOXmlWriter::appendInstanceNameElement(buf, ci[i]);
174                                    buf.append('\0');
175                    
176                                    out.putUint32(buf.size());
177                                    out.putBytes(buf.getData(), buf.size());
178                    
179                                    // Write hostname and namespace in UTF-16 format
180                                    Uint32 len=0;
181                                    const char* hn = ci[i].getHostName_l(len);
182                                    out.putUTF8AsString(hn, len);
183                                    const char * ns = ci[i].getNameSpace_l(len);
184                                    out.putUTF8AsString(ns, len);
185 anusha.kandepu 1.4             }
186 thilo.boehm    1.2         }
187                        }
188                    }
189                    
190                    void SCMOInternalXmlEncoder::_putXMLObject(
191                        CIMBuffer& out,
192 anusha.kandepu 1.4     const Array<SCMOInstance> & co,
193                        const CIMPropertyList& propertyList)
194 thilo.boehm    1.2 {
195 anusha.kandepu 1.4     Array<propertyFilterNodesArray_t> propFilterNodesArrays;
196                        Array<Uint32> emptyNodes;
197                        for (Uint32 i = 0, n = co.size(); i < n; i++)
198 thilo.boehm    1.2     {
199 anusha.kandepu 1.4         if (co[i].isUninitialized())
200 thilo.boehm    1.2         {
201                                out.putUint32(0);
202 anusha.kandepu 1.4             out.putUint32(0);
203 thilo.boehm    1.2             out.putString(String());
204                                out.putNamespaceName(CIMNamespaceName());
205                            }
206                            else
207                            {
208 anusha.kandepu 1.4             Buffer buf(4096);
209                    
210                                // Serialize instance as XML.
211                                if (propertyList.isNull())
212                                {
213                                    SCMOXmlWriter::appendObjectElement(
214                                        buf,
215                                        co[i],
216                                        false,
217                                        emptyNodes);
218                                }
219                                else
220                                {
221                                    // This searches for an already created array of nodes,
222                                    // if not found, creates it inside propFilterNodesArrays
223                                    const Array<Uint32> & nodes =
224                                        SCMOXmlWriter::getFilteredNodesArray(
225                                            propFilterNodesArrays,
226                                            co[i],
227                                            propertyList);
228                                    SCMOXmlWriter::appendObjectElement(
229 anusha.kandepu 1.4                     buf,
230                                        co[i],
231                                        true,
232                                        nodes);
233                                }
234                    
235 thilo.boehm    1.2             buf.append('\0');
236                                out.putUint32(buf.size());
237                                out.putBytes(buf.getData(), buf.size());
238 anusha.kandepu 1.4             buf.clear();
239 thilo.boehm    1.2 
240 anusha.kandepu 1.4             if (0 == co[i].getClassName())
241                                {
242                                    out.putUint32(0);
243                                    out.putString(String());
244                                    out.putNamespaceName(CIMNamespaceName());
245                                }
246                                else
247                                {
248                                    // Serialize object path as XML.
249                                    _appendValueReferenceElement(buf, co[i]);
250                                    buf.append('\0');
251                    
252                                    out.putUint32(buf.size());
253                                    out.putBytes(buf.getData(), buf.size());
254                    
255                                    // Write hostname and namespace in UTF-16 format
256                                    Uint32 len=0;
257                                    const char* hn = co[i].getHostName_l(len);
258                                    out.putUTF8AsString(hn, len);
259                                    const char * ns = co[i].getNameSpace_l(len);
260                                    out.putUTF8AsString(ns, len);
261 anusha.kandepu 1.4             }
262 thilo.boehm    1.2         }
263                        }
264                    }
265                    
266 thilo.boehm    1.3 void SCMOInternalXmlEncoder::_appendValueReferenceElement(
267                        Buffer& out,
268                        const SCMOInstance& ref)
269                    {
270                        out << STRLIT("<VALUE.REFERENCE>\n");
271                    
272                        SCMOXmlWriter::appendInstanceNameElement(out, ref);
273                    
274                        out << STRLIT("</VALUE.REFERENCE>\n");
275                    }
276                    
277 thilo.boehm    1.2 PEGASUS_NAMESPACE_END

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2