root/ossieparser/trunk/PRFSimpleProperty.cpp @ 10

Revision 10, 10.4 KB (checked in by balister, 9 years ago)

Initial import

Line 
1#include "PRFSimpleProperty.h"
2
3PRFSimpleProperty::PRFSimpleProperty()
4{
5        this->id = NULL;
6        this->name = NULL;
7        this->mode = NULL;
8        this->action = NULL;
9        this->dataType = NULL;
10        this->type = NULL;
11        this->value = NULL;
12}
13
14PRFSimpleProperty::PRFSimpleProperty( DOMElement* _elem )
15{
16        this->root = _elem;
17       
18        this->id = NULL;
19        this->name = NULL;
20        this->mode = NULL;
21        this->action = NULL;
22        this->dataType = new CF::DataType();
23        this->type = NULL;
24        this->value = NULL; 
25
26        this->parseElement();
27}
28
29PRFSimpleProperty::~PRFSimpleProperty()
30{
31        root->release();
32        simpleKinds.clear();
33
34        delete this->id;
35        this->id = NULL;
36
37        delete this->name;
38        this->name = NULL;
39
40        delete this->mode;
41        this->mode = NULL;
42
43        delete this->action;
44        this->action = NULL;
45
46        delete this->type;
47        this->type = NULL;
48
49        delete this->value;
50        this->value = NULL;
51}
52
53PRFSimpleProperty::PRFSimpleProperty( const PRFSimpleProperty&  _prfSimpleProp )
54{
55        this->root = _prfSimpleProp.root;
56
57        this->id = new char[ strlen( _prfSimpleProp.id ) + 1 ];
58        strcpy( this->id, _prfSimpleProp.id );
59
60        this->type = new char[ strlen( _prfSimpleProp.type ) + 1 ];
61        strcpy( this->type, _prfSimpleProp.type );
62
63        this->name = new char[ strlen( _prfSimpleProp.name ) + 1 ];
64        strcpy( this->name, _prfSimpleProp.name );
65
66        this->mode = new char[ strlen( _prfSimpleProp.mode ) + 1 ];
67        strcpy( this->mode, _prfSimpleProp.mode );
68
69        this->value = new char[ strlen( _prfSimpleProp.value ) + 1 ];
70        strcpy( this->value, _prfSimpleProp.value );
71
72        this->action = new char[ strlen( _prfSimpleProp.action ) + 1 ];
73        strcpy( this->action, _prfSimpleProp.action );
74
75        CF::DataType* dataType = new CF::DataType;
76        *dataType = *(_prfSimpleProp.dataType);
77
78        for(int i=0; i<(_prfSimpleProp.simpleKinds.size()); i++)
79                this->simpleKinds.push_back(_prfSimpleProp.simpleKinds[i]);
80}
81
82void PRFSimpleProperty::parseElement()
83{
84        const XMLCh* _tmp = root->getAttribute(XMLString::transcode("id"));
85        id = XMLString::transcode(_tmp);
86       
87        dataType->id = CORBA::string_dup( id );
88
89    const XMLCh* _tmp1 = root->getAttribute(XMLString::transcode("type"));
90        type = XMLString::transcode(_tmp1);
91
92        const XMLCh* _tmp2 = root->getAttribute(XMLString::transcode("name"));
93        name = XMLString::transcode(_tmp2);
94
95        const XMLCh* _tmp3 = root->getAttribute(XMLString::transcode("mode"));
96        mode = XMLString::transcode(_tmp3);
97 
98    setValue( parseValue(root) );
99
100    parseKind(root);   
101
102    parseAction(root);   
103}
104
105char* PRFSimpleProperty::parseValue(DOMElement* _elem) 
106{
107        DOMNodeList* nodeList = _elem->getElementsByTagName( XMLString::transcode( "value" ) );
108
109        if(nodeList->getLength() != 0) 
110    { 
111                DOMElement* tmpElement = (DOMElement*) nodeList->item(0); 
112                return getTextNode(tmpElement); 
113    }
114
115    return NULL;
116}
117
118void PRFSimpleProperty::setValue(char* _val) /* throws NumberFormatException */
119{
120          if( isLong() )
121                  //dataType->value <<= ORB_WRAP::anyType( "long", _val );
122                  ORB_WRAP::anyType( "long", _val, dataType->value );
123          else if( isUlong() ) 
124                  //dataType->value <<= ORB_WRAP::anyType( "ulong", _val );
125                  ORB_WRAP::anyType( "ulong", _val, dataType->value );
126          else if( isDouble() ) 
127                  //dataType->value <<= ORB_WRAP::anyType( "double", _val );
128                  ORB_WRAP::anyType( "double", _val, dataType->value );
129          else if( isShort() )  {
130                  //dataType->value <<= ORB_WRAP::anyType( "short", _val );
131                  ORB_WRAP::anyType( "short", _val, dataType->value );
132                        CORBA::Short len = -1;
133
134                        dataType->value >>= len;
135          }
136          else if( isString() ) 
137                  //dataType->value <<= ORB_WRAP::anyType( "string", _val );
138                  ORB_WRAP::anyType( "string", _val, dataType->value );
139          else if( isBoolean() ) 
140          { 
141//              if(_val == "false" || _val == "0") 
142//                      dataType->value = ORB_WRAP::anyType( "bool", "false" );
143//              else if(_val == "true" || _val == "1")   
144//                      dataType->value = ORB_WRAP::anyType( "bool", "true" );
145//              else 
146//                      throw new NumberFormatException("[PRFSimpleProperty:setValue]");
147                // add support to ORB_WRAP for type bool
148          } 
149          else if( isChar() ) 
150          { 
151                  if( strlen( _val ) > 1)
152                  {
153                          throw;// new NumberFormatException("[PRFSimpleProperty:setValue]"); 
154                  }
155                 
156                  char _v = (( strlen( _val ) == 0) ? ' ' : _val[0]);
157                  ORB_WRAP::anyType( "string", _val, dataType->value );
158                  //dataType->value <<= ORB_WRAP::anyType( "string", &_v ); 
159          } 
160          else 
161          {
162                  //String msg = "[PRFSimpleProperty:setValue] type not supported yet";
163                  throw ;//new NumberFormatException(msg); 
164          } 
165         
166          this->value = new char[ strlen( _val ) + 1 ];
167          strcpy( this->value, _val );
168}
169
170
171void PRFSimpleProperty::parseKind( DOMElement* _elem )
172{
173        DOMNodeList* nodeList = _elem->getElementsByTagName( XMLString::transcode( "kind" ) );
174 
175    simpleKinds.push_back("configure");
176 
177    if( nodeList->getLength() != 0 ) 
178    { 
179                simpleKinds.pop_back();
180
181                const XMLCh* _tmp;
182
183                for(int i = 0; i < nodeList->getLength(); i++) 
184                { 
185                        DOMElement* tmpElement = (DOMElement*) nodeList->item(i);
186       
187                        _tmp = tmpElement->getAttribute(XMLString::transcode("kindtype"));
188                        simpleKinds.push_back( XMLString::transcode(_tmp) );
189                }
190        }     
191}
192
193void PRFSimpleProperty::parseAction(DOMElement* _elem)
194{
195        DOMNodeList* nodeList = _elem->getElementsByTagName( XMLString::transcode( "action" ) );
196
197    if( nodeList->getLength() != 0 ) 
198    { 
199                DOMElement* tmpElement = (DOMElement*) nodeList->item(0); 
200               
201                const XMLCh* _tmp = tmpElement->getAttribute(XMLString::transcode("type"));
202                action = XMLString::transcode(_tmp);
203    }
204}
205
206bool PRFSimpleProperty::isAllocation() 
207
208    for(int i = 0; i < simpleKinds.size(); i++) 
209    { 
210                if( strcmp( simpleKinds[i], "allocation" ) == 0 )
211                        return true;
212    } 
213
214    return false;
215}
216
217bool PRFSimpleProperty::isConfigure() 
218
219    for(int i = 0; i < simpleKinds.size(); i++) 
220    { 
221                if( strcmp( simpleKinds[i], "configure" ) == 0 )
222                        return true;
223    } 
224
225    return false;
226}
227
228bool PRFSimpleProperty::isTest() 
229
230    for(int i = 0; i < simpleKinds.size(); i++) 
231    { 
232                if( strcmp( simpleKinds[i], "test" ) == 0 )
233                        return true;
234    } 
235
236    return false;
237}
238
239bool PRFSimpleProperty::isExecParam() 
240
241    for(int i = 0; i < simpleKinds.size(); i++) 
242    { 
243                if( strcmp( simpleKinds[i], "execparam" ) == 0 )
244                        return true;
245    } 
246
247    return false;
248}
249
250bool PRFSimpleProperty::isFactoryParam() 
251
252    for(int i = 0; i < simpleKinds.size(); i++) 
253    { 
254                if( strcmp( simpleKinds[i], "factoryparam" ) == 0 )
255                        return true;
256    } 
257
258    return false;
259}
260
261char* PRFSimpleProperty::getTextNode(DOMElement* _elem) 
262
263        DOMNodeList* nodeList = _elem->getChildNodes(); 
264   
265        if( nodeList->getLength() == 0 ) 
266                return "NotSpecified";
267    else 
268                return XMLString::transcode(nodeList->item(0)->getNodeValue());
269}
270
271char* PRFSimpleProperty::toString() 
272
273    char* str = new char[ MAX_PRF_BUF ];
274 
275    str = strcpy( str, "\n     ID=" );
276        str = strcat( str, getID() );
277    str = strcat( str, "\n     Type=" );
278        str = strcat( str, getType() );
279
280    if( name != NULL || name != "") 
281    {
282                str = strcat( str, "\n     Name=" );
283                str = strcat( str, getName() );
284    } 
285
286    str = strcat( str, "\n     Mode=" );
287        str = strcat( str, getMode() );
288    str = strcat( str, "\n     Value=" );
289        str = strcat( str, getValue() );
290 
291    for(int i=0; i<simpleKinds.size(); i++)
292    {
293                str = strcat( str, "\n     Kind=" );
294                str = strcat( str, simpleKinds[i] );
295    } 
296
297    str = strcat( str, "\n     Action=" );
298        str = strcat( str, getAction() );
299
300    return str; 
301}
302
303char* PRFSimpleProperty::getID()                                const { return id; } 
304
305char* PRFSimpleProperty::getType()                              const { return type; } 
306
307char* PRFSimpleProperty::getName()                              const { return name; } 
308
309char* PRFSimpleProperty::getMode()                              const { return mode; }
310
311char* PRFSimpleProperty::getValue()                             const { return value; } 
312
313char* PRFSimpleProperty::getAction()                    const { return action; } 
314
315CF::DataType* PRFSimpleProperty::getDataType()  const { return dataType; } 
316
317std::vector<char*> PRFSimpleProperty::getKinds()const { return simpleKinds; }
318
319bool PRFSimpleProperty::isBoolean()                             { return (type == NULL ? false : strcmp( type, "boolean" ) == 0); }
320
321bool PRFSimpleProperty::isChar()                                { return (type == NULL ? false : strcmp( type, "char" ) == 0); }
322
323bool PRFSimpleProperty::isDouble()                              { return (type == NULL ? false : strcmp( type, "double" ) == 0); }
324
325bool PRFSimpleProperty::isFloat()                               { return (type == NULL ? false : strcmp( type, "float" ) == 0); }
326
327bool PRFSimpleProperty::isShort()                               { return (type == NULL ? false : strcmp( type, "short" ) == 0); }
328
329bool PRFSimpleProperty::isLong()                                { return (type == NULL ? false : strcmp( type, "long" ) == 0); }
330
331bool PRFSimpleProperty::isObjref()                              { return (type == NULL ? false : strcmp( type, "objref" ) == 0); }
332
333bool PRFSimpleProperty::isOctet()                               { return (type == NULL ? false : strcmp( type, "octet" ) == 0); }
334
335bool PRFSimpleProperty::isString()                              { return (type == NULL ? false : strcmp( type, "string" ) == 0); }
336
337bool PRFSimpleProperty::isUlong()                               { return (type == NULL ? false : strcmp( type, "ulong" ) == 0); }
338
339bool PRFSimpleProperty::isUshort()                              { return (type == NULL ? false : strcmp( type, "ushort" ) == 0); }
340
341bool PRFSimpleProperty::isReadOnly()                    { return (type == NULL ? false : strcmp( type, "readonly" ) == 0); }
342
343bool PRFSimpleProperty::isReadWrite()                   { return (type == NULL ? false : strcmp( type, "readwrite" ) == 0); }
344
345bool PRFSimpleProperty::isWriteOnly()                   { return (type == NULL ? false : strcmp( type, "writeonly" ) == 0); }
346
347bool PRFSimpleProperty::isEqual()                               { return (action == NULL ? false : strcmp( action, "eq" ) == 0); }
348
349bool PRFSimpleProperty::isNotEqual()                    { return (action == NULL ? false : strcmp( action, "ne" ) == 0); }
350
351bool PRFSimpleProperty::isGreaterThan()                 { return (action == NULL ? false : strcmp( action, "gt" ) == 0); }
352
353bool PRFSimpleProperty::isLessThan()                    { return (action == NULL ? false : strcmp( action, "lt" ) == 0); }
354
355bool PRFSimpleProperty::isGreaterThanOrEqual()  { return (action == NULL ? false : strcmp( action, "ge" ) == 0); }
356
357bool PRFSimpleProperty::isLessThanOrEqual()             { return (action == NULL ? false : strcmp( action, "le" ) == 0); }
358
359bool PRFSimpleProperty::isExternal()                    { return (action == NULL ? false : strcmp( action, "external" ) == 0); }
360
Note: See TracBrowser for help on using the browser.