18.04.2013 Views

Dissertaç ˜ao de Mestrado Mestrado em Engenharia Informática Jo ...

Dissertaç ˜ao de Mestrado Mestrado em Engenharia Informática Jo ...

Dissertaç ˜ao de Mestrado Mestrado em Engenharia Informática Jo ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4. AN IMPLEMENTATION 4.6. Generation of Original Syntax<br />

<br />

<br />

[<br />

]<br />

<br />

<br />

Listing 4.8: Example Metadata<br />

not know what application is being configured at that moment. Therefore, it cannot <strong>de</strong>termine<br />

what <strong>de</strong>limiters to print on a given pattern (e.g., INI “[]” or XML block <strong>de</strong>limiters), or how to<br />

print th<strong>em</strong> (e.g., INI single hea<strong>de</strong>r or XML hea<strong>de</strong>r and footer). So, to print a file to its original<br />

syntax, there should be enough information regarding the original syntax, in the generic syntax,<br />

for the Printer.<br />

One way to know what <strong>de</strong>limiters should be print is to store th<strong>em</strong> in a field in the be-<br />

ginning of the file in generic syntax. As the pattern <strong>de</strong>limiters are immutable throughout the<br />

configuration file (i.e., comments always start with # in an Apache configuration file), infor-<br />

mation regarding th<strong>em</strong> can be unified in a special Metadata field in the beginning of the file.<br />

This makes it possible for the Printer to query Metadata to know what to print on a certain<br />

pattern.<br />

The format of a pattern is of great importance as well. The same pattern might have differ-<br />

ent formats in two different configuration file languages. For instance, an INI block has only<br />

one block hea<strong>de</strong>r, whereas an XML block (i.e., el<strong>em</strong>ent) has a hea<strong>de</strong>r and a footer. Again, since<br />

the Printer does not know what application it is configuring at the moment, it does not know<br />

whether to print a pattern one way or the other.<br />

To solve this probl<strong>em</strong>, a format string which <strong>de</strong>scribes how a pattern looks like is associated<br />

with each pattern, forming an FStr field. In this way, the Printer gets the FStr from a pattern<br />

and prints it accordingly. A format string may be composed of the following:<br />

%a.name The value of the attribute named name in the current el<strong>em</strong>ent is printed;<br />

%e The value of the current el<strong>em</strong>ent is printed;<br />

%m.name The value of the el<strong>em</strong>ent named name in Metadata is printed;<br />

%c The format string is in the next child of the current el<strong>em</strong>ent;<br />

%s A space is printed;<br />

%n A new line is printed;<br />

Let’s consi<strong>de</strong>r the following hea<strong>de</strong>r in an INI configuration file:<br />

[Engine]<br />

The corresponding Metadata is <strong>de</strong>picted in Listing 4.8 and the FStr will look like Listing 4.9.<br />

47

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!