1
import Parser.XML.Tree;
5
* <p>class Result - Standard Return Type for an action, which covers the result of an action. It offers the ability to
6
* render the Result either as XML or as a mapping. Further it contains a set of messages, which presents errors,
7
* warning and status of an action (if needed).
8
* Only one OWLItem or OWLContainer can be linked to one result, new set statements will override the previous ones.
15
* <p>Rendering type for this resul</p>
17
public constant XML = 1;
21
* <p>Rendering type</p>
23
public constant RENDER_SINGLE = 0;
26
* <p>Rendering type</p>
28
public constant RENDER_DEEP = 1;
31
* <p>Rendering type</p>
33
public constant RENDER_UP = 2;
38
* <p>conatains one of RENDER_SINGLE(default), RENDER_DEEP or RENDER_UP</p>
40
private int render_flag = 0;
43
* <p>counter for the message container</p>
45
private int messagecounter = 0;
48
* <p>internal flag for the result type,ITEM or CLUSTER or CONTAINER </p>
50
private int result_type = 0;
52
* <p>Result has a single item</p>
54
private constant ITEM = 1;
57
* <p>Result is a cluster (more than on OWLContainer)</p>
59
private constant CLUSTER = 2;
62
* <p>Result is an OWLContainer</p>
64
private constant CONTAINER = 3;
66
* <p>Container for the messages</p>
68
private array messages = ({ }) ;
71
* <p>Container for a set of owlitems</p>
73
private Visconte.Onto.OWLContainer owl_container ;
76
* <p>The single OWLItem</p>
78
private Visconte.Onto.Item.OWLItem owl_item ;
81
* <p>array storing more than one OWLContainer</p>
83
private array(array) cluster = ({ }); ;
90
public void create() {
95
* <p>Returns an XML Representation of the Result</p>
96
* Checks the result type and and returns a rendered XML-String
98
* @param void|list_flags - mapping with attribute-value that can be added to the <list> tag
99
* @return string - the rendered XML
101
public string get_XML_Result(void|mapping list_flags)
107
xc= XMLConversion(list_flags);
113
xml_result = xc->convert_Item(owl_item, render_flag);
117
xml_result = xc->convert_Cluster(cluster);
121
xml_result = xc->convert_Container(owl_container);
124
xml_result="<list></list>";
133
* <p>Returns a mapping with given tag and attribute name and the id as keys</p>
136
* @param attribute - the attribute to look for
137
* @param tag - the tag to look for (e.g. individual etc.)
138
* @return mapping with ids -> attributes
140
public mapping get_id_mapping(string attribute, string tag)
142
mapping(string:string) id_mapping=([]);
143
Node root = Parser.XML.Tree.parse_input(get_XML_Result());
144
array childs = root->get_descendants(0);
145
foreach(childs,Node n)
147
mapping attr = n->get_attributes();
149
if(n->get_tag_name()==tag && has_index(attr, "id") && has_index(attr, attribute))
151
id_mapping+=([ attr["id"] : attr[attribute] ]);
158
* <p>Returns an Array with mappings that have all tags and attribute as name:value set</p>
160
* @return array - containing the result mappings
162
public array get_result_mapping()
165
Node root = Parser.XML.Tree.parse_input(get_XML_Result());
166
array childs = root->get_descendants(0);
167
foreach(childs,Node n)
169
mapping attr = n->get_attributes();
170
attr+=([ "tag_name" : n->get_tag_name() ]);
179
* <p>Check if this Result has an error</p>
182
* @param error_num - checks for special Error number, see File MessageCodes
183
* @return true or false
185
public int has_error(int|void error_num)
188
foreach(messages, Visconte.Request.Message m)
192
if(error_num && m->errorcode==error_num)
209
* <p>Returns the messages either as XML or as array</p>
212
* @param content_type - if set to 1 XML will be rendered else the array will be
214
* @return mixed (array or string)
216
public mixed get_Messages(int content_type)
219
if(content_type==XML)
221
Node root_node = Node(Parser.XML.Tree.XML_ROOT,"root", ([ ]), "");
222
mapping(string:string) attr = ([ ]);;
225
foreach(messages,Visconte.Request.Message msg)
227
attr+=([ "type" : (string)msg->type , "about" : msg->about , "messagecode" : (string)msg->errorcode ]);
229
Node msg_node = Node(Parser.XML.Tree.XML_ELEMENT,"message", attr,"");
230
Node backtrace_node = Node(Parser.XML.Tree.XML_ELEMENT,"backtrace", ([ ]),"");
231
Node msg_text = Node(Parser.XML.Tree.XML_TEXT,"", ([ ]),msg->msg);
232
Node backtrace_text = Node(Parser.XML.Tree.XML_TEXT,"", ([ ]),msg->backtrace);
233
msg_node->add_child(msg_text);
234
msg_node->add_child(backtrace_node);
235
backtrace_node->add_child(backtrace_text);
237
root_node->add_child(msg_node);
240
return root_node->render_xml();
249
* <p>Dumps the messages to the console</p>
251
public void dump_messages()
253
foreach(messages, Visconte.Request.Message m)
255
write(m->to_string());
259
* <p>Add a message to the Result</p>
262
* @param msg - a Message-object
264
public void add_Message(Visconte.Request.Message msg)
266
if(msg && objectp(msg))
274
* <p>Add a OWLContainer to the cluster</p>
277
* @param meta - mapping with attribute-value shape, will be added to the XML-
280
public void add_cluster(mapping meta, Visconte.Onto.OWLContainer container)
284
cluster+=({ ({meta, container}) });
290
* <p>Set an Visconte.Onto.OWLContainer to the Result. This overwrites any
291
* existing Visconte.Onto.OWLContainer or/and Visconte.Onto.Item.OWLItem</p>
293
* @param container - the Visconte.Onto.OWLContainer
295
public void set_OWLContainer(Visconte.Onto.OWLContainer container)
299
//if a Visconte.Onto.OWLContainer is added, null an existing Visconte.Onto.Item.OWLItem
300
this_program::owl_container=container;
301
result_type=CONTAINER;
308
* <p>Set an Visconte.Onto.Item.OWLItem to the Result. This overwrites any
309
* existing Visconte.Onto.OWLContainer or/and Visconte.Onto.Item.OWLItem</p>
312
* @param item - The OWLitem
314
public void set_OWLItem(Visconte.Onto.Item.OWLItem item, int|void render_flag)
318
//if a OWLItem is added, null an existing Visconte.Onto.OWLContainer
319
this_program::owl_item=item;
322
this_program::render_flag=render_flag;
324
this_program::render_flag=RENDER_SINGLE;
335
* class XMLConversion - class to translate OWLItems to the visconte exchange format
344
import Visconte.Onto.Item;
345
import Parser.XML.Tree;
349
* <p>the Model Tag</p>
351
public constant MODEL_NODE = "model";
353
* <p>The List Tag</p>
355
public constant LIST = "list";
357
* <p>The DatatypeProperty tag</p>
359
public constant DATA_TYPE_NODE = "property";
361
* <p>The ObjectProperty Tag </p>
363
public constant OBJECT_PROPERTY_NODE = "association";
365
* <p>The individual tag</p>
367
public constant INDIVIDUAL_NODE = "individual";
369
* <p>The cluser tag</p>
371
public constant CLUSTER_NODE = "cluster";
373
* <p>Tag for any attribute (property or associaion) of an individual</p>
375
public constant INDIVIDUAL_PROPERTY = "attribute";
378
* <p>Attributes for the list tag</p>
380
public mapping(string:string) list_flag =([]);
383
* <p>Set an Visconte.Onto.OWLContainer to the Result. This overwrites any
384
* existing Visconte.Onto.OWLContainer or/and OWLItem</p>
386
* @param container - the Visconte.Onto.OWLContainer
388
public string create(void|mapping list_flag)
391
this_program::list_flag=list_flag;
394
* <p>Renders a cluster as XML</p>
396
* @param clusters - the array containing the OWLContainer
398
public string convert_Cluster(array clusters)
400
Node xml_cluster_root = Node(XML_ROOT,"root",([]),"");
401
foreach(clusters, array cluster)
403
Node cluster_node = Node(XML_ELEMENT,CLUSTER_NODE,cluster[0],"");
404
xml_cluster_root->add_child(cluster_node);
405
Visconte.Onto.OWLContainer container = cluster[1];
406
while(container->has_items())
407
cluster_node->add_child(create_Item_Node(container->next(), 0) );
409
return xml_cluster_root->render_xml();
414
* <p>Render a OWLContainer as XML</p>
416
* @param container - the Visconte.Onto.OWLContainer
418
public string convert_Container(Visconte.Onto.OWLContainer container)
420
container->reset_iterator();
421
list_flag->size = (string)container->size_of();
422
Node xml_container = Node(XML_ELEMENT,LIST,list_flag,"");
423
while(container->has_items())
425
Visconte.Onto.Item.OWLItem x =container->next();
426
xml_container->add_child(create_Item_Node(x,0));
428
return xml_container->render_xml();
432
* <p>Render a OWLItem as XML</p>
434
* @param item - the OWLItem
435
* @param render_flag - the flags: RENDER_SINGLE(default), RENDER_DEEP or RENDER_UP
437
public string convert_Item(Visconte.Onto.Item.OWLItem item, int render_flag)
439
return create_Item_Node(item,render_flag)->render_xml();
444
* <p>Creates a Node for an OWLItem/p>
445
* @param item - the OWLItem
446
* @param render_flag - the flags: RENDER_SINGLE(default), RENDER_DEEP or RENDER_UP
448
private Node create_Item_Node(Visconte.Onto.Item.OWLItem item, int render_flag)
450
switch(item->ITEMTYPE)
452
case Visconte.Onto.Item.OWLItem.CLASS:
454
return create_Class_Node(item, render_flag);
457
case Visconte.Onto.Item.OWLItem.OBJECT_PROPERTY:
458
return create_Object_Property_Node(item);
461
case Visconte.Onto.Item.OWLItem.DATATYPE_PROPERTY:
462
return create_Datatype_Property_Node(item);
465
case Visconte.Onto.Item.OWLItem.INDIVIDUAL:
466
return create_Individual_Node(item);
470
return Node(XML_ELEMENT,MODEL_NODE,([]),"");
477
* <p>this method creates an Class Node in visconte format</p>
479
* @param item - the OWLClass
480
* @param render_flag - the flags: RENDER_SINGLE(default), RENDER_DEEP or RENDER_UP
482
private Node create_Class_Node(Visconte.Onto.Item.OWLItem item, int render_flag)
484
mapping(string:string) attr = ([ ]);;
486
attr+=(["id": ID(item->get_Id(),1)->uref]);
487
attr+=(["label" : item->get_Label()]);
488
attr+=(["weight" : (string) item->get_weight(5)]);
489
attr+=(["drops" : (string) item->get_weight()]);
490
attr+=(["lastModified" : (string) item->get_date_of_change() ]);
491
if(item->is_document_term())
492
attr+=(["isDocumentTerm" : "true"]);
494
attr+=(["isDocumentTerm" : "false"]);
497
model_node = Node(XML_ELEMENT,MODEL_NODE,attr,"");
499
Visconte.Onto.OWLContainer container = item->get_domain_properties();
501
while(container->has_items())
503
model_node->add_child(create_Item_Node(container->next(),render_flag));
505
if(render_flag==Visconte.Request.Result.RENDER_DEEP)
507
container = item->get_childs();
508
while(container->has_items())
510
model_node->add_child(create_Item_Node(container->next(),render_flag));
513
if(render_flag==Visconte.Request.Result.RENDER_UP)
516
if(item->has_parent())
518
item = item->get_parent();
520
Node parent = create_Item_Node(item,render_flag);
521
parent->add_child(model_node);
532
* <p>this method creates an ObjectProperty Node in visconte format</p>
534
* @param item - the OWLObjectProperty
536
private Node create_Object_Property_Node(Visconte.Onto.Item.OWLItem item)
538
mapping(string:string) attr = ([ ]);
539
attr+=(["id" : ID(item->get_Id(),1)->uref]);
540
attr+=(["label" : item->get_Label()]);
541
attr+=(["with" : ID(item->get_range()->get_Id())->uref]);
542
attr+=(["domain" : ID(item->get_domain()->get_Id())->uref]);
543
attr+=(["lastModified" : (string) item->get_date_of_change()]);
544
return Node(XML_ELEMENT,OBJECT_PROPERTY_NODE,attr,"");
547
* <p>this method creates an DatatypeProperty Node in visconte format</p>
549
* @param item - the OWLDatatypeProperty
551
private Node create_Datatype_Property_Node(Visconte.Onto.Item.OWLItem item)
553
mapping(string:string) attr = ([ ]);
554
attr+=(["id" : ID(item->get_Id(),1)->uref]);
555
attr+=(["label" : item->get_Label()]);
556
attr+=(["type" : item->get_range()]);
557
attr+=(["lastModified" : (string) item->get_date_of_change()]);
558
return Node(XML_ELEMENT,DATA_TYPE_NODE,attr,"");
563
* <p>this method creates an DatatypeProperty Node in visconte format</p>
565
* @param item - the OWLDatatypeProperty
567
private Node create_Individual_Node(Visconte.Onto.Item.OWLItem item)
570
mapping(string:string) attr = ([ ]);
572
attr+=(["id" : ID(item->get_Id(),1)->uref]);
573
attr+=(["label" : item->get_Label()]);
574
attr+=(["domain" : ID(item->get_model_class()->get_Id())->uref]);
575
attr+=(["domainName" : item->get_model_class()->get_Label()]);
576
attr+=(["lastModified" : (string) item->get_date_of_change()]);
577
if(item->is_document_term())
579
mapping steam_properties = item->get_steam_properties();
580
attr+=(["objectID" : (string) steam_properties->objectid]);
581
attr+=(["mimetype" : (string) steam_properties->mimetype]);
584
individual = Node(XML_ELEMENT,INDIVIDUAL_NODE,attr,"");
585
array property_map = item->get_property_map();
586
foreach(property_map, array property_definition)
588
OWLProperty property = property_definition[0];
589
string value = property_definition[1];
590
mapping(string:string) attr = ([ ]);
591
attr+=(["propertyId" : ID(property->get_Id(),1)->uref ]);
593
attr+=(["label" : property->get_Label() ]);
595
if(property->ITEMTYPE==Visconte.Onto.Item.OWLItem.OBJECT_PROPERTY)
597
attr+=(["range" : ID(property->get_range()->get_Id(),1)->uref ]);
598
attr+=(["type" : "object"]);
599
attr+=(["value" : ID(value)->uref ]);
605
attr+=(["range" : property->get_range() ]);
606
attr+=(["type" : "data"]);
607
attr+=(["value" : (string) value]);
610
individual->add_child(Node(XML_ELEMENT,INDIVIDUAL_PROPERTY,attr,""));