View Javadoc

1   package fr.ove.openmath.jome.formaters.om;
2   
3   import fr.ove.utils.*;
4   import fr.ove.openmath.jome.model.*;
5   import fr.ove.openmath.jome.formaters.om.*;
6   
7   /***
8   * Formats the formula tree structure as its corresponding OpenMath object.<BR>
9   * This is the formater for the lambda expressions
10  *
11  * @author © 2000 DIRAT Laurent
12  * @version 1.0 22/02/2000
13  */
14  public class LambdaFormater implements Formater {
15      /***
16      * Returns the specified object formatted as a string.
17      * @param formatedObject the formatted object (for structured object, could represents the beginning).
18      * @param formaterRepository where the different other formaters are.
19      * @param obj the object to format.
20      */
21      public String format(String formatedObject, FormaterRepository formaterRepository, Object obj) {
22          OpenMathFormater omFormater = (OpenMathFormater) formaterRepository;
23          FormulaTreeStructure fts = (FormulaTreeStructure) obj;
24          
25          FormulaTreeStructure ftsChild;
26          Formater formater;
27          
28          String objectId = fts.getResourceIdentifier();
29          
30          // CrČation du bind
31          formatedObject += omFormater.writeStartBinding();
32          formatedObject += omFormater.writeSymbol(objectId);
33          // On met les variables liČes.
34          formatedObject += omFormater.writeStartBoundVariables();
35          
36          FormulaTreeStructure child = (FormulaTreeStructure) fts.getChild(1);
37          objectId = child.getResourceIdentifier();
38          formater = formaterRepository.getFormater(objectId);
39          formatedObject = formater.format(formatedObject, formaterRepository, child);
40          
41          int nbChildren = fts.getNbChildren();
42          for (int i = 2; i < nbChildren; i++) {
43              child = (FormulaTreeStructure) fts.getChild(i);
44              formatedObject = formater.format(formatedObject, formaterRepository, child);
45          }
46          
47          formatedObject += omFormater.writeEndBoundVariables();
48          
49          // On met maintenant l'objet du bind.
50          child = (FormulaTreeStructure) fts.getChild(0);
51          objectId = child.getResourceIdentifier();
52          formater = formaterRepository.getFormater(objectId);
53          formatedObject = formater.format(formatedObject, formaterRepository, child);
54          
55          formatedObject += omFormater.writeEndBinding();
56          
57          return formatedObject;
58      }
59  }