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.7. Generic to Original Syntax Converter<br />

<br />

<br />

%m.LBra%a.name%m.RBra%n<br />

<br />

..(other patterns)..<br />

<br />

ServerType standalone<br />

Listing 4.9: Example FStr<br />

Listing 4.10: Apache parameter with a single value<br />

Note that in the example, the FStr is assigned to the Engine block and not to the block<br />

pattern. This happens because there are cases where the same pattern has different formats in<br />

a configuration file language. For example, a parameter in an Apache configuration file might<br />

have one (Listing 4.10) or multiple values (Listing 4.11), or an XML el<strong>em</strong>ent might have one<br />

(Listing 4.12) or multiple sub-el<strong>em</strong>ents (Listing 4.13), which leads to multiple format strings.<br />

Therefore, FStr cannot be factorized in a single field, like Metadata.<br />

4.7 Generic to Original Syntax Converter<br />

The Generic to Original syntax Converter contains two classes, PrinterMain and Printer.<br />

The first is used to interact with the user, while the second contains methods for the interpreta-<br />

tion and printing of the file in generic syntax (i.e., XML). Following is a <strong>de</strong>eper explanation of<br />

both classes.<br />

The PrinterMain class impl<strong>em</strong>ents a main method which receives the location of the XML<br />

file in argument. It imports the XML document from the file to m<strong>em</strong>ory using the Java XML<br />

parsing API. Then, PrinterMain sends the document pointer and a stream to the Printer and<br />

the latter prints the final configuration file in original syntax to the stream in argument.<br />

The Printer class manages the printing of XML el<strong>em</strong>ents insi<strong>de</strong> an XML file. It impl<strong>em</strong>ents<br />

a single visible method, print.<br />

The print method is called by PrinterMain to print the entire XML document into a con-<br />

figuration file in its original syntax. It receives a stream and a No<strong>de</strong>List object as arguments.<br />

No<strong>de</strong>List refers to a DOM interface for the representation of lists of No<strong>de</strong> objects, whereas<br />

each No<strong>de</strong> object stands for XML components, such as el<strong>em</strong>ents, attributes or text no<strong>de</strong>s. Since<br />

the XML standard <strong>de</strong>fines XML documents as having a single root no<strong>de</strong>, PrinterMain calls<br />

Listing 4.11: Apache parameter with multiple values<br />

DirectoryIn<strong>de</strong>x in<strong>de</strong>x.html in<strong>de</strong>x.htm in<strong>de</strong>x.shtml<br />

<strong>de</strong>fault.htm <strong>de</strong>fault.html in<strong>de</strong>x.php<br />

48

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

Saved successfully!

Ooh no, something went wrong!