Start page

Mykola Zharkikh (Kyiv)

Personal site

?

Collectors and transitions

And what does the node attribute link top? And what is the purpose of Link class?

Collectors

Collector is a node of any class, except Link, which has non-zero attribute link or another attribute(s) that is (are) the node id. With this information, Smereka using it for collecting attributes that will be used during the compiling page from the node-collector.

The process of attributes collecting is very similar to the inheritance of properties from superclass to subclasses in object-oriented programming system. Specifically, Smereka do as follow: first, it selects all the attributes for the current node (it always do this regardless of collecting). If the attribute-pointer for collecting not zero, this destination node loaded. Smereka examines the attributes of this node and adds those which are not yet in the collection. Cycle of loading and adding repeats until one of the following conditions occurs:

1. Attribute-pointer is zero;

2. Attribute-pointer points to the non-existent node;

3. Attribute-pointer points to one of the nodes, which have been visited already (ie there is tree structure errors such as circular references, when node A refers to the node B and node B refers to the node A).

So, if node-collector has an its own attribute, the value of this attribute for the linked nodes will be ignored, but if it has no such attribute – it will inherit the value from the first node of the chain, which owns this attribute.

Please be aware that collecting method defined in the context of the Node, but this method is called in context of Page. By default, Smereka performs collecting for link attribute for all pages in view mode, and does not do any collecting in edit mode. Other page templates can perform or not perform collecting at its discretion, do collecting for multiple attributes, etc. This provides additional flexibility in the process of web pages compilation.

Please be aware that in the collecting process node access level is ignored. Therefore, during compiling public pages data from a "secret" nodes can be used.

For example, one want to prevent unregistered site user to browse price list for your products, and so protects the price list node with certain access level; but public description of your products may refer to this protected node and select prices of the goods from it.

Of course, the Smereka programmer can fully or partially abandon the mechanism for collecting and using link attribute for any other purpose.

Transitions

Transition is a node of Linkclass, which has non-zero link attribute. In such case Smereka make dereferencing instead of attributes collecting: destination node load, and if it also belongs to the Link class, dereferencing cycle continues. It ends in one of the following cases:

1. The node does not belong to the Link class – we successfully got reference destination;

2. Attribute link is zero;

3. Attribute link points to non-existent node;

4. Attribute link points to one of the nodes, which have been visited already (ie there is tree structure errors such as circular references, when node A refers to the node B and node B refers to the node A).

Please be aware that during dereferencing node access level is ignored. It is checked only when the dereferencing process is successfully completed (case 1). Therefore, using the Transition did not give the user access to "secret" node, to see which he has no rights.

In other words, node-transition display the target node in its own context (carries an explicit internal "redirect"); but node-collector without own attributes set display the target node in the collector's context (carries blind internal "redirect"); but in both cases "redirect" provided by Smereka itself, without the use of http protocol mechanisms, so we take that word "redirect" in quotes and name it as internal.

Practical example

Consider the application of Smereka for sample Internet Shop Mercedes. First we create something like a next tree:

Product

Manufacturers

Car Colors

Now we need to fill the directory. Today we offer a Mercedes 600 (black), Mercedes 601 (silver), Lexus 21 (silver) and Lexus 21M (spotted). (And what is the "spotted" color ? Is it some kind of green ? Buy, see, do not regret it:).

To do this, we expect Car class provide attributes Manufacturer, Model, Color.

Now our tree takes the following form (in brackets include the own node attributes):

Product

Manufacturers

Mercedes

1. [Manufacturer="Mercedes" Model="600" color="black"]

2. [Manufacturer="Mercedes" Model="601" color="Silver"]

Lexus

3. [Manufacturer="Lexus" Model="21" color="Silver"]

4. [Manufacturer="Lexus" Model="21M" color="Moore"]

Car Colors

But there are a large group of buyers who choose cars not for power, convenience, safety, and even the number of wheels, and looks only if it fits to the hair. So, you need the catalog section "Colors". How to fill it?

Approach 1 – duplication

Copy each node with a car description to the Smereka clipboard and insert a duplicate in the appropriate position in colors directory:

Product

Manufacturers

Mercedes

1. [Manufacturer="Mercedes" Model="600" color="black"]

2. [Manufacturer="Mercedes" Model="601" color="Silver"]

Lexus

3. [Manufacturer="Lexus" Model="21" color="Silver"]

4. [Manufacturer="Lexus" Model="21M" color="spotted"]

Car Colors

Black

5. [Manufacturer="Mercedes" Model="600" color="black"]

Silver

6. [Manufacturer="Mercedes" Model="601" color="Silver"]

7. [Manufacturer="Lexus" Model="21" color="Silver"]

Other

8. [Manufacturer="Lexus" Model="21M" color="spotted"]

Our goal achieved, but if the 600-Mercedes goes out of fashion and will be replaced by the 609 – then we'll have to adjust each such node separately.

Approach 2 – transitions

With this approach, we insert in the colors directory not duplicate descriptions of cars, but transitions to the original descriptions:

Product

Manufacturers

Mercedes

1. [Manufacturer="Mercedes" Model="600" color="black"]

2. [Manufacturer="Mercedes" Model="601" color="Silver"]

Lexus

3. [Manufacturer="Lexus" Model="21" color="Silver"]

4. [Manufacturer="Lexus" Model="21M" color="spotted"]

Car Colors

Black

[Transition, link="1"]

Silver

[Transition, link="2"]

[Transition, link="3"]

Other

[Transition, link="4"]

The goal again reached and now to replace the 600th Mercedes with 609th, one must fix only one attribute in the node 1.

Certain shortcomings of this approach is that every time a fastidious buyer clicks on the product in the "Color" directory, he sees a description of the goods in the "Producers" directory. May be the next silver model went to the better, but to see it, we must again look colors directory.

Approach 3 – simple collectors

In this approach, the colors directory contain Car class nodes with attribute link which points to the full product descriptions:

Product

Manufacturers

Mercedes

1. [Manufacturer="Mercedes" Model="600" color="black"]

2. [Manufacturer="Mercedes" Model="601" color="Silver"]

Lexus

3. [Manufacturer="Lexus" Model="21" color="Silver"]

4. [Manufacturer="Lexus" Model="21M" color="spotted"]

Car Colors

Black

[Car, link="1"]

Silver

[Car, link="2"]

[Car, link="3"]

Other

[Car, link="4"]

Since the nodes in the color catalog have no own attributes, they inherit all the attributes of the respective nodes from producers directory. From the user's view the behavior of such directory is the same as the directory with duplicated nodes, but it is easier to maintain.

Approach 4 – complex collectors

The disadvantage of all three approaches is that the common attributes for the related goods are duplicated in the description of each product. With collectors one can make a rationalization:

Reference [hidden]

Manufacturers [hidden]

9. [Manufacturer="Mercedes"] [hidden]

10. [Manufacturer="Lexus"] [hidden]

Product

Manufacturers

Mercedes

1. [Car, link="9" Model="600" color="black"]

2. [Car, link="9" Model="601" color="Silver"]

Lexus

3. [Car, link="10" Model="21" color="Silver"]

4. [Car, link="10" Model="21M" color="spotted"]

Car Colors

Black

[Car, link="1"]

Silver

[Car, link="2"]

[Car, link="3"]

Other

[Car, link="4"]

The difference is in creating producers directory, hidden from the user. This directory consists of Car class nodes, having only the common attributes for all products. In our case – it is only Manufacturer. Because elements of this directory are hidden, the buyer will not be confused by the proposal Mercedes-not-600.

However, when the buyer clicks in the colors catalog on a black car, Smereka see that this Car has no own attributes and collect attributes Model, Color from the node 1. Since the last node, in turn, is a collector, Smereka continues collecting the attributes and selects the attribute Manufacturer from hidden node 9.

In this way, collectors provide a unique mechanism of hierarchical data normalization, when instead of actual data appear pointers to nodes store the data.

Approach 5 – two collectors

Developing ideas of the previous approach, add a colors dictionary :

Reference [hidden]

Manufacturers [hidden]

9. [Manufacturer="Mercedes"] [hidden]

10. [Manufacturer="Lexus"] [hidden]

Colors [hidden]

11. [Car Color="Black"] [hidden]

12. [Car Color="Silver"] [hidden]

13. [Car Color="spotted"] [hidden]

Product

Manufacturers

Mercedes

1. [Car, link="9" Model="600" ColorLink="11"]

2. [Car, link="9" Model="601" ColorLink="12"]

Lexus

3. [Car, link="10" Model="21" ColorLink="12"]

4. [Car, link="10" Model="21M" ColorLink="13" color="Blue"]

Car Colors

Black

[Car, link="1"]

Silver

[Car, link="2"]

[Car, link="3"]

Other

[Car, link="4"]

Here we have expanded the definition of Car class by adding ColorLink attribute and made sure that the page template describing the car performed collecting not only for the standard attributes, but also for ColorLink attribute.

With this approach, if a Car has its own Color attribute, ColorLink attribute that tries to add the color values from the dictionary will be ignored. In our example, the color changed for Lexus 21M to "Blue".

In turn, if one the modified dictionary entry 11 from the "black" to "dark", it automatically affect all products that contain a link to this dictionary item.