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 of operators which have the sigma format :
10 *
11 * @author © 2000 DIRAT Laurent
12 * @version 1.0 21/02/2000
13 */
14 public class MapsToSigmaFormater 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 Formater formater;
26
27 String objectId = fts.getResourceIdentifier();
28
29
30 if (fts.getNbChildren() == 3) {
31
32 FormulaTreeStructure argument = (FormulaTreeStructure) fts.getChild(0).getChild(0);
33 FormulaTreeStructure lowerBound = (FormulaTreeStructure) fts.getChild(1).getChild(0);
34 FormulaTreeStructure upperBound = (FormulaTreeStructure) fts.getChild(2).getChild(0);
35
36
37
38
39 if ((lowerBound.isOperator() && ((Operator) lowerBound).getTheOperator().equals("="))) {
40 if (lowerBound.getNbChildren() == 2) {
41 FormulaTreeStructure child0 = (FormulaTreeStructure) lowerBound.getChild(0);
42 FormulaTreeStructure child1 = (FormulaTreeStructure) lowerBound.getChild(1);
43 if (child0.getResourceIdentifier().equals("VARIABLE")
44
45
46 formatedObject += omFormater.writeStartApplication();
47
48 formatedObject += omFormater.writeSymbol(objectId);
49
50 formatedObject += omFormater.writeStartApplication();
51 formatedObject += omFormater.writeSymbol("interval", "integer_interval");
52
53 objectId = child1.getResourceIdentifier();
54 formater = formaterRepository.getFormater(objectId);
55 formatedObject = formater.format(formatedObject, formaterRepository, child1);
56
57
58
59 objectId = upperBound.getResourceIdentifier();
60 formater = formaterRepository.getFormater(objectId);
61
62 formatedObject = formater.format(formatedObject, formaterRepository, upperBound);
63
64 formatedObject += omFormater.writeEndApplication();
65
66
67 formatedObject += omFormater.writeStartBinding();
68 formatedObject += omFormater.writeSymbol("lambda");
69
70
71 formatedObject += omFormater.writeStartBoundVariables();
72
73 objectId = child0.getResourceIdentifier();
74 formater = formaterRepository.getFormater(objectId);
75 formatedObject = formater.format(formatedObject, formaterRepository, child0);
76
77 formatedObject += omFormater.writeEndBoundVariables();
78
79
80 objectId = argument.getResourceIdentifier();
81 formater = formaterRepository.getFormater(objectId);
82 formatedObject = formater.format(formatedObject, formaterRepository, argument);
83
84 formatedObject += omFormater.writeEndBinding();
85 formatedObject += omFormater.writeEndApplication();
86
87 }
88 }
89 }
90 }
91
92 return formatedObject;
93 }
94 }