« Back to AAU Project

Names, IDs and XML files of ADOxx

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Names, IDs and XML files of ADOxx
community documentation xml-adl importexport
Answer
3/27/14 11:08 AM
  1. Why objects' names should be different in ADOxx? Is it possibile to change this feature?
  2. In Adoxx-XML file, Why the refrence between models and sub-models is based on names not IDs? Is it possible to cover this feature?
  3. Is it possible to create an object  in a model and refer to that object (with the same ID) in other sub-models?

Uniqueness Condition in Object names
Answer
10/16/13 11:15 AM as a reply to Fadi.
With respect to unique object names, this is an intended behaviour, that 2 instances derived from the same class need to have a unique name, therefore by default (creating a new object the following logic is applied: "Classname" + ObjectID. To overcome this limitation, it is possible to define a new attribute that holds a none-unique name of the object and also allows same naming of same-class instances. The object's name can be generated using event and script logic:
To enable this feature please follow the steps below:
a) Define a new attribute of type STRING, named "Denomination"
b) Add the new attribute in the ATTRREP of the class so that it appears in the notebook of the instance. For the "Name" attribute define it as write-protected, meaning that the value can not be changed by the user, but by the event-based script
1NOTEBOOK
2CHAPTER "Description"
3ATTR "Denomination"
4ATTR "Name" write-protected

c) Update/modify the GRAPHREP so that the new attribute is visualized instead of the "Name" attribute
 1GRAPHREP
 2SHADOW off
 3# Tyres
 4ELLIPSE x:-0.5cm rx:0.3cm ry:0.3cm
 5ELLIPSE x:0.5cm rx:0.3cm ry:0.3cm
 6# Body
 7LINE x1:-0.2cm x2:0.2cm
 8LINE x1:-0.8cm x2:-1cm
 9LINE x1:0.8cm x2:1cm
10LINE x1:1cm x2:1cm y2:-0.5cm
11LINE x1:-1cm x2:-1cm y2:-0.5cm
12LINE x1:-1cm x2:1cm y1:-0.5cm y2:-0.5cm
13# Roof
14LINE x1:-0.5cm x2:-0.3cm y1:-0.5cm y2:-0.9cm
15LINE x1:0.5cm x2:0.3cm y1:-0.5cm y2:-0.9cm
16LINE x1:-0.3cm x2:0.3cm y1:-0.9cm y2:-0.9cm
17# Windows
18LINE y1:-0.5cm y2:-.9cm
19
20ATTR "Denomination" y:0.7cm w:c h:c

c) Define an event listener to update the "Name" attribute. It is important to decide on which event this should be triggered, our proposal would be to run it before a model is saved. The actual logic how an objectname is only available as a FIXME in this snipplet. Please make sure to update the code accordingly. The code snipplet should be added in the "External coupling" library attribute of the dynamic library.

 1ON_EVENT "BeforeSaveModel" {
 2    # modelid : integer
 3    # origin : string Origin of the save action call. "new", "save", "saveas-new" or "saveas-save".
 4    # persist for the event the modelid
 5    SETL saveModelID:(modelid)
 6    CC "Core" GET_ALL_OBJS modelid: (saveModelID)
 7    SETL lObjIDs:(objids)
 8    # iterate through all objects in the model
 9    FOR sObjID in:(lObjIDs) {
10      # FIXME: logic to generate the name should be added here
11      SETL sObjName:("NewObjectName")
12      # save the objectname in the object
13      CC "Core" SET_ATTR_VAL objid: (VAL sObjID) attrname: ("Name") val:(sObjName)
14    }   
15}

IDs in XML Export
Answer
10/16/13 12:01 PM as a reply to Fadi.
Currently relations and INTERREF attributes are resolved through nameclass and modeltype names. This can be extended using a post-processing of information available in the XML export using XSLT technology to resolve IDs. A change of the ASC files to produce the export would be possible, but limits the upgrade capabilities of the platform since any change there would need to be migrated to new versions. the following approach is suggested:

a) Export n models using the available XML interface
b) Apply a transformation using SAXON as parser and transformer, included in the platforms tools folder
c) Modify/Update the XML according to the needs of the respective node IREF and RELATION

Please find below the snipplets of code to establish this functionality:

1) AdoScript Interface: can be added on a menu item or on an event, please make sure to resolve the modelids for export correctly, in this snipplet this is performed through user interaction

 1 
 2  # Interact with user to determine the export models
 3  CC "ImportExport" SHOW_EXPORT_DLG title: ("Advanced XML export") filedescription:"XML files" fileextension:"*.xml"
 4  IF (endbutton = "cancel") {
 5    EXIT 
 6  }
 7  # Result file after transformation
 8  SETL sTranformationResult: (filename)
 9  # construct the necessary file pointers
10  CC "Application" GET_PATH (filename) path-only append-delimiter
11  SETL sExportPath: (path)
12  SETL sADOXMLExportFile: (sExportPath + "adoxml.xml")
13  SETL sXSLFile: (sExportPath + "updateADOXML.xsl") 
14  CC "AdoScript" GET_CWD
15  SETL sADOxxWorkingDir: (cwd)
16  # Export ADOxml to the file space for further processing
17  CC "Documentation" XML_MODELS modelids: (modelids) mgroupids: (mgroupids) attrprofs: (attrprofids) apgroups: (apgroupids)
18  # Get rid of namespace to simplify the transformation
19  SETL sModifiedXml: (replall(xml, " xmlns=\"@boc-eu.com/boc-is/adonis.model.document;1\"", ""))
20  CC "AdoScript" FWRITE file: (sADOXMLExportFile) text: (sModifiedXml) binary:0
21  # Copy the transformation file
22  CC "AdoScript" FCOPY from: ("db:\\updateADOXML.xsl")  to: (sXSLFile)
23  # Run XSL transformation
24  SYSTEM ("java -jar \""+sADOxxWorkingDir+"\\tools\\saxonb8j\\saxon8.jar\" -t -o \""+sTranformationResult+"\" \"" +sADOXMLExportFile+ "\" \"" +sXSLFile + "\"") with-console-window
25  # clean up, comment in if you want only the export result
26  #CC "AdoScript" FILE_DELETE file: (sADOXMLExportFile)
27  #CC "AdoScript" FILE_DELETE file: (sXSLFile)
28  CC "AdoScript" INFOBOX "Export and transformation completed successfully."


2) XSL Transformation "updateADOXML.xsl" as used from the library file management in the script above

 1<?xml version="1.0"?>
 2<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 3
 4<!--Identity template, provides default behavior that copies all content into the output -->
 5    <xsl:template match="@*|node()">
 6        <xsl:copy>
 7            <xsl:apply-templates select="@*|node()"/>
 8        </xsl:copy>
 9    </xsl:template>
10    <!-- modify from relation -->
11    <xsl:template match="from">
12      <xsl:variable name="instance" select="@instance"/>
13      <xsl:variable name="class" select="@class"/>
14        <xsl:element name="from">
15        <xsl:attribute name="id"><xsl:value-of select="ancestor::model//instance[@name=$instance and @class = $class]/@id"/></xsl:attribute>
16        <xsl:attribute name="instance"><xsl:value-of select="$instance"/></xsl:attribute>
17        <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
18      </xsl:element>
19    </xsl:template>
20   
21    <!-- modify to relation -->
22    <xsl:template match="to">
23      <xsl:variable name="instance" select="@instance"/>
24      <xsl:variable name="class" select="@class"/>
25        <xsl:element name="to">
26        <xsl:attribute name="id"><xsl:value-of select="ancestor::model//instance[@name=$instance and @class = $class]/@id"/></xsl:attribute>
27        <xsl:attribute name="instance"><xsl:value-of select="$instance"/></xsl:attribute>
28        <xsl:attribute name="class"><xsl:value-of select="$class"/></xsl:attribute>
29      </xsl:element>
30    </xsl:template>
31   
32    <!-- modify to iref -->
33    <xsl:template match="iref">
34        <xsl:element name="iref">
35        <xsl:copy-of select="@*"/>
36        <xsl:variable name="tmodelname" select="@tmodelname"/>
37        <xsl:variable name="tmodelver" select="@tmodelver"/>
38        <xsl:variable name="tmodeltype" select="@tmodeltype"/>
39        <xsl:variable name="modelnode" select="//model[@name = $tmodelname and @version = $tmodelver and @modeltype = $tmodeltype]"/>
40        <xsl:choose>
41          <xsl:when test="@type = 'modelreference'">
42            <xsl:attribute name="tmodelid"><xsl:value-of select="$modelnode/@id"/></xsl:attribute>
43          </xsl:when>
44          <xsl:when test="@type = 'objectreference'">
45            <xsl:variable name="tclassname" select="@tclassname"/>
46            <xsl:variable name="tobjname" select="@tobjname"/>
47             <xsl:attribute name="tmodelid"><xsl:value-of select="$modelnode/@id"/></xsl:attribute>
48             <xsl:attribute name="tobjid"><xsl:value-of select="$modelnode/descendant::instance[@name=$tobjname and @class=$tclassname]/@id"/></xsl:attribute>
49          </xsl:when>
50          <xsl:otherwise><!--do not do anything --></xsl:otherwise>
51        </xsl:choose>
52      </xsl:element>
53    </xsl:template>
54   
55</xsl:stylesheet>
Attachments: sample_INPUT.xml (10.4k), sample_OUTPUT.xml (9.6k), updateADOXML.xsl (2.5k)

Object reference
Answer
10/16/13 12:03 PM as a reply to Fadi.
The possible to reference objects is established through the INTERREF attribute in ADOxx. Links/Pointers to instances of modeltypes and classes can be realized, whereas these pointers have a meaning (=name) and cardinalities. Based upon these links mechanisms can be established to retrieve, update, modify instances connected with each other. To provide you with a meaningful example, I would kindly ask you for more details to understand what kind of scenario you intend to realize.