• Like
  • Save
Structs in Uniface
Upcoming SlideShare
Loading in...5
×
 

Structs in Uniface

on

  • 727 views

Structs are key to the architecture of how we are building the Uniface 10 IDE, so we will share details on best practices learnt from the Uniface 10 development ...

Structs are key to the architecture of how we are building the Uniface 10 IDE, so we will share details on best practices learnt from the Uniface 10 development
The presentation topics:
• The purpose of structs
• Using structs
• Best practices

Statistics

Views

Total Views
727
Views on SlideShare
705
Embed Views
22

Actions

Likes
1
Downloads
37
Comments
0

2 Embeds 22

http://www.linkedin.com 18
https://twitter.com 4

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • A Struct is a tree-like data structure in memory that is used to dynamically manipulate complex data.It can be used to transform complex data from or to XML or Uniface component data.And in one of the coming releaseswe’ll plan to introduce JSON transformation. From talking with Adrian I’ve learned that most of the development work is already done. We just need to finalize it.
  • A Struct is a collection of data objects, or nodes, that are hierarchically organized under a single root node.A node that has a parent node is a Struct member.A member can be a Struct itself, in which case it is called a nested Struct.
  • A Struct exists only in memory, and it exists only as long as there is a struct variable or parameter that refers to it (or one of its members).
  • Shortdemoofhow a Struct „looks“ like.
  • A Struct is a data structure consisting of one top node and zero or more sub-nodes called members.Each member can hold a scalar data value (such as a number, string, or date), or it can hold another (nested) Struct.
  • A Struct or Struct member can have a name. If it has a name, the name is case-sensitive. If it is a nested Struct, it is known to its parent by its name. The name can consist of an empty string ("").Members of a Struct can have the same name. Struct members are sequentially ordered. They can be addressed by their index position, making it possible to address a specific member, even if it has the same name as another member, or no name.
  • A Struct leaf is a Struct member that has no value, or only a single scalar value.However, adding another value (member) to a Struct leaf implicitly changes it to a nested Struct. The value of the former leaf is now held in a nameless Struct, known as a scalar Struct, and the nested Struct has a mixed data structure.
  • A book is, for example, a complex data structure that can be represented by a Struct.This illustrates a number of characteristics of a Struct:+ For example, the Book Struct contains members called Title, Preface, and Chapter. + A Struct member can have a value. This can be: - A scalar value: for example, the value of first Title member is the string "Getting Started". - A Struct: for example, each Chapter is a nested Struct because it has child members. +A Struct can hold a mixture of both scalar members and nested Struct members. For example, the Book Struct contains two scalar members (Title and Preface) and two nested Structs (Chapter).+ Members of a Struct can have the same name. For example, there are multiple members called Chapter and Section. Thus, if a struct variable references a Struct by name, it contains a collection of references to all Structs with that name.+ Struct members are sequentially ordered.They can be addressed by their index position, making it possible to address a specific member, even if it has the same name as another member, or no name.
  • A struct variable does not contain the value. Instead, it contains zero or more references to Struct nodes. One struct variable can contain multiple references to different Struct nodes, and several variables can refer to one Struct node.
  • Several struct variables can refer to the same Struct. For example, the variable vBook and vStruct both refer to the struct Book.A single Struct variable can refer to multiple Structs, which makes it possible to manipulate a group of Structs, instead of handling them individually. For example, the struct variable vChapters contains a collection of Structs named Chapter.
  • Structs can be passed as parameters by reference or by value.The content of a struct parameter is not a Struct, but zero or more references to Struct nodes, just as it is for struct variables. This is in contrast to scalar data types such as string. The default behavior is to pass Struct parameters by reference in partner operations and entries, and by value in public operations. When passed by reference, the parameter passes a copy of the reference to the called entry or operation, so an additional reference to the same struct is created. When passed by value, a copy of the Struct is made.
  • It is possible to override the default behavior by explicitly defining how Struct parameters are passed using the byRef or byVal qualifiers. This can be useful if you know that the calling and receiving component instances are running in the same process.If neither the byRef nor the byVal qualifiers are used, the default behavior depends on whether the parameter is declared in a public operation or not. However, because of the functional difference between the two, it is advisable to explicitly specify the intended qualifier. References are memory pointers so it is only possible to pass them between Proc modules that share the same memory. This is always the case for partner operations and entries, but may not be the case for public operations.If an operation with a byref struct parameter is activated in a component running in a different process, this will result in the following error:-73 "Operation with byref-Struct parameter cannot be activated across processes"
  • Returns a collection of references to all Struct members with the specified name.
  • Access members by name; for example, get all Struct members named chapter:vBookStruct->chapter
  • When used with the * asterisk wildcard, it returns a collection of references to all members of a Struct. Important: The * wildcard can only be used after the dereference operator. It cannot be used in constructs such as vStruct->c* (De-reference c asteriskwildcard) to get all Structs whose names begin with c.
  • When used with the * asterisk wildcard, it returns a collection of references to all members of a Struct. Important: The * wildcard can only be used after the dereference operator. It cannot be used in constructs such as vStruct->c* (De-reference c asteriskwildcard) to get all Structs whose names begin with c.
  • Get a collection of Structs; for example, get all members of the Struct referred to by variable vBookStruct:vBookStruct->*This returns the title, preface, and all chapter members.
  • Returns a reference to a single member of a Struct based on its index position in the collection of references.
  • Access members by name and index; for example, get the second member named chapter.+ vBookStruct->chapter{2}When can also access a Struct from a collection by its index position only, regardless of its name (this is done using the asterisk wildcard); for example, get the second member in a Struct+ vBookStruct->*{2}
  • struct: Data type for variables and parameters$newstruct: Create a new, empty Struct componentToStruct: Convert Uniface component data into a Struct structToComponent: Load data from a Struct into a Uniface component xmlToStruct: Convert XML data into a StructstructToXml: Convert Struct data into XML $equalStructRefs: Checks whether struct variables point to the same Struct.
  • $dbgString: Get a string that represents the Struct or Struct collection. $dbgStringPlain: Get a string that represents the Struct or Struct collection, but without annotations. $collSize: Get the number of Structs in the collection$memberCount: Get the number of members in a Struct. $isLeaf: Check whether a Struct is a Struct leaf (the logical end point in a Struct tree)$isScalar: Check whether a Struct is a scalar Struct. $istags: Check whether the Struct is a $tags Struct for another Struct
  • $index: Get or set the index of the Struct in a Struct collection.$name: Get the name of a Struct$parent: Get or set the parent of the Struct. $scalar: Get or set the scalar members of a Struct$tags: Get or set annotations for a Struct.
  • Although most Struct functions only return information, there are three functions that can be used to change data.You can use: $index to insert a member into a Struct at the specified index.$parent to move a Struct member from one Struct to another.$tags to set the value of annotations, or define your own annotations for use in conversion routines.
  • Struct annotations are descriptive data elements that are also known as tags.They contain information that is used to correctly convert data to and from specific formats, or to interpret data correctly.
  • Each Struct node has a special child Struct to hold annotations. This Struct can be accessed using the $tags Struct function and is therefore known as the $tags Struct. Unlike normal Struct members, annotations have no specific position inside the Struct, and are therefore not counted or treated as members of the Struct. This is in contrast to, for example, XML processing instructions, which are treated as normal Struct members because their position in an XML document is relevant, even if they are not part of the document contents.
  • Struct annotations are specific to a complex data format. Structs converted from Uniface component structures have only one annotation tag set, u_type, which indicates the type of Uniface object a Struct (or Struct member) represents. There are more annotation tags available for XML-based Structs. The Proc conversion routines componentToStruct and xmlToStruct set annotations, whereas structToComponent and structToXml use the annotations to guide the conversion process. For example, when transforming from XML to Uniface, a tag called xmlClass contains information about how the data was stored in the source XML (for example, attribute or element). This is useful when doing a round-trip conversion, so no information is lost.Some data formats have their own metadata, which can be added as annotations. For example, the XML DOCTYPE specification and XML Declaration are required in XML data. Because annotations always apply to a specific format, they are ignored when converting to other formats and will be lost. For example, XML annotations are ignored when converting from a Struct to a component.
  • When converting between XML and Structs using xmlToStruct or structToXml, you can set and retrieve annotations that provide information that guides the conversion (or reverse conversion).Use the $tags function to set or get the value of an annotation for a specific Struct.
  • Here is a list of annotation Tags for XML-Struct Conversions
  • A Struct can be explicitly created using the $newstruct Proc function (vStruct = $newstruct)
  • Or it can be implicitly created in the following ways: Assigning a value to a struct variable or parameter.
  • Or it can be implicitly created in the following ways: Assigning a value to an allowed Struct function ($name, $parent, or $scalar) or to $tags. vStruct->$name = "My Book“Note: Struct access operators, such as the de-reference operator (->) and the index operator ({N}), enable you to address Structs and their members by name and index number. Struct functions enable you to get and set the values and properties of Structs and their members, and insert, copy, move, and remove them.
  • Or it can be implicitly created in the following ways: A Proc conversion instruction, such as xmlToStruct or componentToStruct is used. For example:xmlToStruct vStruct, "Book.xml"
  • A Struct exists in memory as long as there is a struct variable or parameter that points to it. There is no Proc command to delete a Struct. Instead, a Struct is deleted as soon as it is no longer referenced by any struct variable or parameter, or it is no longer owned by another Struct. For example, reassigning the vStruct variable to another value deletes the Struct it refers to.
  • For example, reassigning the vStruct1 variable to another value deletes the Struct it refers to.vStruct1 = ""However, the Struct referenced by vStruct2 continues to exist.
  • For example, reassigning the vStruct1 variable to another value deletes the Struct it refers to.vStruct1 = ""However, the Struct referenced by vStruct2 continues to exist.
  • For example, reassigning the vStruct1 variable to another value deletes the Struct it refers to.vStruct1 = ""However, the Struct referenced by vStruct2 continues to exist.
  • With the struct data type Uniface enables you to perform dynamic transformations of complex data structures.For example:+ Convert XML data received from web services into data structures that easily can be accessed within Uniface, such as a component data structure+ Convert the data in a Uniface component into a nested XML data structure+ Merge data from different components for use in another component+ Extract desired information from any type of complex data structure
  • You can use the Proc instructions xmlToStruct and structToXml to convert complex data from and to XML.XML can be much more complex than Uniface component data because it supports unlimited levels of nesting. It also has data types that are not recognized by Uniface, and doctype declarations and schemas which define the structure but are not actually required in the Struct itself. For example, XML comments, DOCTYPE declaration, and namespace declarations are usually ignored when converting to Structs (although they can be included if required). If you are converting from a Struct to XML, and you need these XML constructs in the output, you need to explicitly define them.A basic Struct that represents XML data has the following structure:1. Top-level Struct for the document; can optionally have attributes for an XML declaration.2. Named Struct node with element name3. Named Struct with attribute name; attribute Structs must precede any child elements4. Named Struct leaf with element name5. Named Struct with application name
  • Transform an XML stream with a CD catalog1. Element Title is converted to an attribute2. A Prices element is added3. The Price element is moved so that it‘s a child of Prices4. An Currency attribute is added to Price with the value „USD“5. Add price in Euro: The Price element is copied and the value of currency is changed to „EUR“ (plus price is recalculated)6. Add price in British Pound: The Price element is copied again and the value of currency is changed to „GBP“ (plus price is recalculated)
  • Describe the different assignments:1. Struct (variable): assign reference to a „new“ struct2. Struct member: copy structHow to add a level to struct?
  • You can use the Proc instructions componentToStruct and structToComponent to convert complex data from and to Uniface components.A Struct that represents the data in a Uniface component has the following structure:1. Named top-level Struct with the name of the component2. Named Struct nodes for each entity in the component structure3. Named Struct node with the fixed name OCC for each occurrence in an entity4. Named Struct leaf with the name of the field5. Named Struct nodes for each entity that is a child of an occurrence. Entity and field names may be partially qualified (FIELDNAME.ENTNAME) or fully qualified (ENTITY.MODEL for an entity or FIELD.ENTITY.MODEL for a field). Field names can normally be unqualified, as they are implicitly qualified by the location within the context of an entity. In case of conflict (identical names of a field and an entity drawn on the same level), names must be fully qualified, or tags can be used to specify the type of the object. For each Struct member, the u_type annotation defines the type of Uniface object that the Struct represents: component, entity, occurrence or fieldWhen converting to Structs, componentToStruct automatically provides the u_type annotation. When converting from Structs (structToComponent), the outcome may be undefined if the Struct name matches more than one field or entity.
  • Next we‘ll transform the component data with the structure we can see on the left (3 nested entites, CUSTOMER, ADDRESS and COUNTRY).And we‘ll convert it to a single entity with the structure we can see on the right.Ho are we going to do this?1. We copy the data to a struct2. We move the field nodes of COUNTRY and ADDRESSentity to the level of the CUSTOMER node3. Next we‘ll rename the (former) node NM.COUNTRY to COUNTRY4. Then we rename the node CUSTOMER to NEWCUSTOMER5. And in the last step we‘ll copy the data to the destination entity
  • Howtoremove a level?
  • The ability to transform complex data from one format to another is a common requirement. For example, web services often use and produce XML that does not directly correspond to Uniface data structures such as entities and lists. For Uniface applications to consume or produce complex data, it needs to be converted to or from Uniface entities, lists, or XML streams.
  • Recursive loop. Adding a level for the OCC struct node.
  • What is an XML Schema?The purpose of an XML Schema is to define the legal building blocks of an XML document, just like a DTD.An XML Schema: + defines elements that can appear in a document + defines attributes that can appear in a document + defines which elements are child elements + defines the order of child elements + defines the number of child elements + defines whether an element is empty or can include text + defines data types for elements and attributes + defines default and fixed values for elements and attributes
  • Here are the two XSD files we‘ll use for the next demo:1. The paramater.xsd that describes the Uniface return parameter of the Web Service operation we‘re calling (NAMESPACE:urn:uniface:applic:complexparameter)2. The musiccityplex.xsd that describes the data returned by the Web Service operation we‘re calling (NAMESPACE:urn:uniface:applic:musiccityplex)
  • Structs are key to the architecture of how we are building the Uniface 10 IDE.
  • Now here are some best practices the Uniface 10 development team has gathered while building the version 10 IDE.These are not specifically related to Structs. The lessons learned boil down to basic programming principles with respect to (dynamic) loops. And this is not only applicable to structs, but also to (for example) a collection of entity occurrences or a list with members.
  • Now here are some best practices the Uniface 10 development team has gathered while building the version 10 IDE.These are not specifically related to Structs. The lessons learned boil down to basic programming principles with respect to (dynamic) loops. And this is not only applicable to structs, but also to (for example) a collection of entity occurrences or a list with members.

Structs in Uniface Structs in Uniface Presentation Transcript

  • | STRUCTS IN UNIFACE Daniel Iseli Uniface CSS
  • Agenda • The purpose of structs • Using structs • Best practices
  • The purpose of structs
  • The purpose of structs What is a struct?  Tree-like data structure  Manipulate complex data dynamically  Transform complex data:  XML data  Uniface component data  JSON (coming soon)
  • The purpose of structs What is a struct? • Collection of data objects / nodes • Organized hierarchically under single root node • Struct member: node that has a parent node • Nested Struct: member that is Struct
  • The purpose of structs What is a struct? • A Struct only exists: • In memory • As long as referenced by struct variable / parameter
  • 1 Demo
  • The purpose of structs Structs and Members • Struct consists of: • One top node • 0-n sub-nodes (members) • Each member can hold: • A scalar data value (e.g. number, string, or date) • Or another (nested) Struct
  • The purpose of structs Structs and Members • Struct / Struct member can have a name • Is case-sensitive • Can be an empty string • Members can have the same name. • Members are sequentially ordered
  • The purpose of structs Struct Leaves • Struct member that has: • No value • Or only single scalar value • Adding member to leaf: • Changes to nested Struct • Value of former leaf held in nameless Struct (scalar Struct)
  • The purpose of structs Struct Example
  • The purpose of structs Struct Variables • Does not contain value • Contains 0-n references to nodes • Can contain multiple references to different nodes • Several variables can refer to one Struct node.
  • The purpose of structs Struct Variables
  • The purpose of structs Struct Parameters • Structs can be passed as parameters: • By reference • By value • Default behavior: • By reference: partner operations and entries • By value: public operations
  • The purpose of structs Struct Parameters • Behavior can be changed during declaration • Limitation of by reference: • Only works with locals instances • Passing to remote instance will throw error
  • vBookStruct->chapter The purpose of structs Struct Access Operators • De-reference operator: -><name> • Collection of members with specified name
  • The purpose of structs Struct Access Operators vBookStruct->chapter
  • vBookStruct->*vBookStruct->* The purpose of structs Struct Access Operators • De-reference operator: ->* • Special case: returns collection to all members
  • vBookStruct->*vBookStruct->c* The purpose of structs Struct Access Operators • De-reference operator: ->* • Special case: returns collection to all members
  • The purpose of structs Struct Access Operators vBookStruct->*
  • vBookStruct->chapter{2} The purpose of structs Struct Access Operators • Struct index operator: {index} • Reference to single member based on index position in collection of references
  • The purpose of structs Struct Access Operators vBookStruct->chapter{2}
  • The purpose of structs Proc for Manipulating Structs • Struct data type • $newstruct • componentToStruct • structToComponent • xmlToStruct • structToXml • $equalStructRefs
  • The purpose of structs Struct Functions • $dbgString • $dbgStringPlain • $collSize • $memberCount • $isLeaf • $isScalar • $istags
  • The purpose of structs Struct Functions • $index • $name • $parent • $scalar • $tags
  • The purpose of structs Setting Struct Functions • Most functions only return information • Functions that can change data: • $index • $parent • $tags
  • The purpose of structs Struct Annotations • Descriptive data elements • Known as tags • Contain information to: • Correctly convert data to / from specific formats • Interpret data correctly
  • The purpose of structs Struct Annotations • Each node has special child • Node accessed using $tags • No specific position • Not counted / treated as members
  • The purpose of structs Struct Annotations for Data Conversion • Specific for complex data format • componentToStruct / xmlToStruct: • Set annotations • structToComponent / structToXml: • Use annotations for conversion process
  • The purpose of structs Struct Annotations for Data Conversion <?xml version='1.0' ?> <!DOCTYPE UNIFACE PUBLIC "UNIFACE.DTD" "UNIFACE.DTD"> <UNIFACE release="9.6" xmlengine="2.0"> <TABLE> [] [$tags] [xmlVersion] = 1.0 [xmlClass] = document [UNIFACE] [$tags] [xmlClass] = element [release] = "9.6" [$tags] [xmlClass] = attribute [xmlengine] = "2.0" [$tags] [xmlClass] = attribute [TABLE] [$tags] [xmlClass] = element xmlToStruct
  • The purpose of structs Struct Annotations for XML Tag Values xmlClass document element attribute … xmlNamespaceURI Value of the namespace string xmlNamespaceAlias Value of the alias string xmlVersion Value of the version attribute in the <?xml … ?> declaration xmlEncoding Value of the encoding attribute in the <?xml … ?> declaration xmlStandAlone Value of the standalone attribute in the <?xml … ?> declaration xmlDataType Data type xmlTypeNamespace Namespace of URI of a schema-defined data type
  • The purpose of structs Struct Annotations for XML Tag Values xmlTypeCategory simple complex xmlAttrMode #IMPLIED #REQUIRED #FIXED xmlPublicID Formal Public Id used to identify the DTD xmlSystemID URI for the file containing the DTD xmlNotation Name of notation declaration
  • The purpose of structs Creating Structs (Explicitly) • $newstruct variables struct vStruct endvariables vStruct = $newstruct
  • The purpose of structs variables struct vStruct endvariables vStruct = "My Book" Creating Structs (Implicitly) • Assigning value to a struct variable / parameter
  • The purpose of structs variables struct vStruct endvariables vStruct->$name = "My Book" Creating Structs (Implicitly) • Assigning value to: • $name • $parent • $scalar • $tags
  • The purpose of structs variables struct vStruct endvariables xmlToStruct vStruct, "Book.xml" Creating Structs (Implicitly) • Proc conversion instruction: • xmlToStruct • componentToStruct
  • The purpose of structs Deleting Structs • No Proc command • Deleted when: • not referenced by struct variable/parameter • not owned by another Struct variables struct vStruct endvariables vStruct = ""
  • The purpose of structs Deleting Structs vStruct1 = ""
  • The purpose of structs Deleting Structs vStruct1 = ""
  • The purpose of structs Deleting Structs vStruct1 = ""
  • Using structs
  • Using structs Transforming Complex Data Using Structs struct data type enables dynamic transformations of complex data. For example: • XML from web services into component data structure • Component data into a nested XML data • Merge data from different components • Extract information from any type of complex data
  • Using structs Structs for XML Data Basic Struct that represents XML data: 1. Top-level Struct for document 2. Named node with element name 3. Named with attribute name 4. Named leaf with element name 5. Named Struct with application name
  • Demo <?xml version="1.0"?> <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> </CATALOG> <?xml version="1.0"?> <CATALOG> <CD TITLE="Empire Burlesque"> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <YEAR>1985</YEAR> <PRICES> <PRICE CURRENCY="USD">10.90</PRICE> <PRICE CURRENCY="EUR">10.00</PRICE> <PRICE CURRENCY="GBP">8.50</PRICE> </PRICES> </CD> </CATALOG> Transform XML -> XML
  • 2 Demo
  • Using structs Structs for Uniface Component Data Struct that represents Uniface component data 1. Top-level Struct with component name 2. Named nodes for entities 3. Fixed named node OCC 4. Named leaf with field name 5. Named nodes for inner entites
  • Demo Transform CMP -> CMP
  • 3 Demo
  • Using structs Music City Web Service Example • Calling Music City Web Service • Returned XML Data converted to Struct • Struct transformed to match component structure • Struct loaded into component
  • <?xml version="1.0" encoding="UTF-8"?> <ufnc:parameter xmlns:ufnc="urn:uniface:applic:complexparameter"> <ns0:artists xmlns:ns0="urn:uniface:applic:musiccityplex"> <ns0:artist> <ns0:artist_id>333</ns0:artist_id> <ns0:gid>703c7062-cc25-47e0-919e-ef740b88c725</ns0:gid> <ns0:name>Chris von Sneidern</ns0:name> <ns0:begin_date_year>0000</ns0:begin_date_year> <ns0:begin_date_month>00</ns0:begin_date_month> <ns0:begin_date_day>00</ns0:begin_date_day> <ns0:end_date_year>0</ns0:end_date_year> <ns0:end_date_month>0</ns0:end_date_month> <ns0:end_date_day>0</ns0:end_date_day> <ns0:type>Person</ns0:type> <ns0:gender/> <ns0:country> <ns0:code>US</ns0:code> <ns0:name>United States</ns0:name> </ns0:country> <ns0:comment/> <ns0:ipi_code/> <ns0:last_updated>2011-12-11T08:39:58.00</ns0:last_updated> <ns0:artist_credit_name> <ns0:position>0</ns0:position> <ns0:join_phrase>N</ns0:join_phrase> <ns0:artist_credit> <ns0:artist_count>1</ns0:artist_count> <ns0:ref_count>122</ns0:ref_count> <ns0:created>2012-02-14T14:17:01.00</ns0:created> <ns0:release_group> <ns0:type>Album</ns0:type> <ns0:comment/> <ns0:name>Sight &amp; … </ns0:release_group> Using structs Music City Web Service Example Transform XML -> CMP
  • 4 Demo
  • Using structs xmlToStruct vs. xmlToStruct/schema • xmlToStruct: • Uniface data type of all elements/attributes is string. • xmlToStruct/schema: • Elements/attributes with predefined data types included as scalar Structs of matching Uniface data types. • Values are converted to Uniface format.
  • Using structs XML Schemas • What is a schema? • XML Schema is an XML-based alternative to DTD. • An XML schema describes the structure of an XML document. • The XML Schema language is also referred to as XML Schema Definition (XSD).
  • <!– parameter.xsd --> <?xml version="1.0" encoding="UTF-8"?> <xsd:schema elementFormDefault="qualified" targetNamespace="urn:uniface:applic:complexparameter" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ufnc="urn:uniface:applic:complexparameter"> <xsd:element name="parameter" type="ufnc:parameter" /> <xsd:complexType name="parameter"> <xsd:sequence> <xsd:any minOccurs="0" /> </xsd:sequence> </xsd:complexType> </xsd:schema> <!– musiccityplex.xsd --> <?xml version="1.0" encoding="utf-8"?> <xsd:schema elementFormDefault="qualified" targetNamespace="urn:uniface:applic:musiccityplex" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:mc="urn:uniface:applic:musiccityplex"> <xsd:element name="artists" type="mc:artists"/> <xsd:complexType name="artists"> <xsd:sequence> <xsd:element name="artist" type="mc:artist“ minOccurs="0" maxOccurs="unbounded" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="artist"> <xsd:sequence> <xsd:element name="artist_id" type="xsd:int"/> <xsd:element name="gid" type="xsd:string"/> <xsd:element name="name" type="xsd:string"/> <xsd:element name="begin_date_year" type="xsd:short" …/> … <xsd:element name="country" type="mc:country" …/> … <xsd:element name="last_updated" type="xsd:dateTime"/> … </xsd:sequence> </xsd:complexType> Using structs Music City Web Service Example (2) • XSD Samples:
  • ; Create Schema List vSchemaList = "" vItems = "" putitem/id vItems, "NAMESPACE", % "urn:uniface:applic:complexparameter" putitem/id vItems, "LOCATION", "parameter.xsd" putitem vSchemaList, -1, vItems vItems = "" putitem/id vItems, "NAMESPACE", % "urn:uniface:applic:musiccityplex" putitem/id vItems, "LOCATION", "musiccityplex.xsd" putitem vSchemaList, -1, vItems ; xmltostruct/schema xmltostruct/schema $Struct$, vXmlData, vSchemaList Using structs Music City Web Service Example (2) • How to use:
  • 5 Demo
  • Need more info? Go to:
  • Best practices
  • Best practices Struct usage in the IDE10
  • Best practices Struct usage in the IDE10 Controller View View View Repository Structured data exchange managed using Structs
  • Best practices Struct usage in the IDE10 Some direct spin offs:  More efficient use of Memory  Performance improvements  Consistency improvement  Documentation improvements  A lot of improvements available in release 9.6.02
  • ; Do vStruct2 = vStruct->Node11->Node21 vStruct2->Node31 = "A" vStruct2->Node32 = "B" vStruct2->Node33 = "C" vStruct2->Node33 = "D" ; Don’t vStruct->Node11->Node21->Node31 = "A" vStruct->Node11->Node21->Node32 = "B" vStruct->Node11->Node21->Node33 = "C" vStruct->Node11->Node21->Node33 = "D" Best practices What to avoid?  Minimize loops through the Struct  Minimize amount of Proc code in the deepest branches
  • ; Do vStruct2 = vStruct->Node11->Node21 vStruct2->Node31 = "A" vStruct2->Node32 = "B" vStruct2->Node33 = "C" vStruct2->Node33 = "D" Best practices What to avoid?  Minimize loops through the Struct  Minimize amount of Proc code in the deepest branches
  • ; Do N = vStruct->$collSize while (I <= N) ; ... ; Don’t while (I <= vStruct->$collSize) ; ... Best practices What to avoid?  Use by reference wherever possible, instead of by value  Minimize usage of $collsize and $membercount  Adress Struct members with ->*{index} instead of -><name>{index} where possible
  • ; Do N = vStruct->$collSize while (I <= N) ; ... Best practices What to avoid?  Use by reference wherever possible, instead of by value  Minimize usage of $collsize and $membercount  Adress Struct members with ->*{index} instead of -><name>{index} where possible
  • Summary: • Structs are used for manipulating complex data • Structs can be used for transforming data sent to and received from web services • Structs will play an increasingly important role in Uniface (e.g. Uniface 10)