1 package fr.ove.openmath.compounder;
2
3 import java.io.*;
4 import java.util.*;
5 import fr.inria.openmath.omapi.*;
6 import fr.ove.openmath.OpenMathizable;
7 import fr.ove.openmath.jome.ctrl.linear.events.*;
8 import fr.ove.openmath.jome.ctrl.om.*;
9 import fr.ove.openmath.jome.ctrl.amto.*;
10 import fr.ove.openmath.jome.Jome;
11
12
13 /***
14 * The handler for the OpenMath parser of the OpenMath compounder
15 *
16 * @author © 2000 DIRAT Laurent
17 * @version 1.0 11/11/2000
18 */
19 public class OMCompounderParserHandler extends ParserAdapter implements java.io.Serializable {
20 /***
21 * A stack for context management.
22 */
23 private Stack stackContext = new Stack();
24
25 /***
26 * A stack for symbol management.
27 */
28 private Stack stackSymbol = new Stack();
29
30
31
32
33
34
35
36
37
38 /***
39 * A stack for counting the number of operands of the current symbol
40 */
41 private Stack stackSymbolOperands = new Stack();
42
43
44 /***
45 * The list of the elements to compose
46 */
47 private Hashtable elements;
48
49 /***
50 * The compounded OpenMath Object
51 */
52 private StringBuffer compounded = new StringBuffer();
53
54 /***
55 * The different contexts all along the parsing.
56 */
57 private static final byte CREATE_OBJECT = 0;
58 private static final byte WAIT_FOR_OBJECT = 1;
59 private static final byte WAIT_FOR_END_OBJECT = 2;
60
61 private static final byte CREATE_APPLICATION = 3;
62
63 private static final byte CREATE_ATTRIBUTION = 4;
64 private static final byte CREATE_ATTRIBUT_PAIRS = 5;
65 private static final byte END_ATTRIBUT_PAIRS = 6;
66 private static final byte END_ATTRIBUTION = 7;
67
68 private static final byte CREATE_ERROR = 8;
69
70 private static final byte CREATE_BIDING = 9;
71 private static final byte CREATE_BIDING_VARIABLES = 10;
72 private static final byte WAIT_FOR_VARIABLES = 11;
73 private static final byte CREATE_BIDING_OBJECT = 12;
74 private static final byte END_BIDING = 13;
75
76 private Locator locator;
77
78
79
80
81
82 private boolean isApply = false;
83
84 /***
85 * The constructor.<BR>
86 * formula must be the root of an empty one.
87 */
88 public OMCompounderParserHandler(Hashtable elements) {
89 this.elements = elements;
90 }
91
92
93 /***
94 * Return the compounded OpenMath Object.
95 */
96 public String getCompounded() {
97 return compounded.toString();
98 }
99
100 /***
101 * Pushes the context in the stack.
102 * @param context the context to push.
103 */
104 private void pushContext(byte context) {
105 stackContext.push(new Byte(context));
106 }
107
108 /***
109 * Pops the context which is on the top of the stack.
110 */
111 private byte popContext() {
112 return ((Byte) stackContext.pop()).byteValue();
113 }
114
115 /***
116 * Returns the context which is on the top of the stack.<BR>
117 * The returned context still remains into the stack.
118 */
119 private byte getContext() {
120 return ((Byte) stackContext.peek()).byteValue();
121 }
122
123
124 /***
125 * Throws an OpenMath exception.
126 * @param message the message to display.
127 * @param e a specific exception to throw.
128 * @see fr.inria.openmath.omapi.OMException
129 */
130 private void throwOME(String message, Exception e) throws OMException {
131 if (locator != null) {
132 throw new OMException(
133 message + " (at line:" + locator.getLineNumber() + " col:"
134 + locator.getColumnNumber() + ")", e);
135 } else {
136 throw new OMException(message, e);
137 }
138 }
139
140 /***
141 * Throws an OpenMath exception.
142 * @param message the message to display.
143 * @param code the code of the excpetion thrown.
144 * @see fr.inria.openmath.omapi.OMException
145 */
146 private void throwOME(String message, short code) throws OMException {
147 if (locator != null) {
148 throw new OMException(
149 message + " (at line:" + locator.getLineNumber() + " col:"
150 + locator.getColumnNumber() + ")", code);
151 } else {
152 throw new OMException(message, code);
153 }
154
155 }
156
157 /***
158 * Throws an OpenMath exception.
159 * @param message the message to display.
160 * @see fr.inria.openmath.omapi.OMException
161 */
162 private void throwOME(String message) throws OMException {
163 throwOME(message, OMException.OME_GENERIC);
164 }
165
166
167 /********************************************/
168
169
170
171 /********************************************/
172
173
174
175
176 /***
177 * Receives a Locator for parse events.
178 *
179 * <p>By default, do nothing. Application writers may override this
180 * method in a subclass if they wish to store the locator for use
181 * with other events.</p>
182 *
183 * @param locator A locator for all OpenMath parse events.
184 * @see fr.inria.openmath.omapi.ParserHandler#setLocator
185 * @see fr.inria.openmath.omapi.Locator
186 */
187 public void setLocator(Locator locator) {
188 }
189
190 /***
191 * Receives notification of the beginning of parse (of a set of OpenMath-objects).
192 *
193 * <p>By default, do nothing. Application writers may override this
194 * method in a subclass.</p>
195 *
196 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
197 */
198 public void startParse() throws OMException {
199 }
200
201 /***
202 * Receives notification of the end of parse.
203 *
204 * <p>By default, do nothing. Application writers may override this
205 * method in a subclass.</p>
206 *
207 * <p>The OpenMath parser will invoke this method only once, and it will
208 * be the last method invoked during the parse. The parser shall
209 * not invoke this method until it has either abandoned parsing
210 * (because of an unrecoverable error) or reached the end of
211 * the input (no more OpenMath objects).</p>
212 *
213 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
214 */
215 public void endParse() throws OMException {
216 }
217
218 /***
219 * Receives notification of the beginning of a object element.
220 *
221 * <p>By default, do nothing. Application writers may override this
222 * method in a subclass.</p>
223 *
224 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
225 * @see #endObject
226 */
227 public void startObject() throws OMException {
228
229 stackContext.removeAllElements();
230 stackSymbol.removeAllElements();
231 stackSymbolOperands.removeAllElements();
232
233 if (!stackContext.empty())
234 throwOME("Malformed object. Unexpected start of object found", OMException.OME_SYNTAX);
235
236 pushContext(CREATE_OBJECT);
237
238 compounded.setLength(0);
239 compounded.append("<OMOBJ>");
240 }
241
242 /***
243 * Receives notification of the end of an object element.
244 *
245 * <p>By default, do nothing. Application writers may override this
246 * method in a subclass.</p>
247 *
248 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
249 * @see #startObject
250 */
251 public void endObject() throws OMException {
252 if (!stackContext.empty()) {
253 popContext();
254
255 if (!stackContext.empty())
256 throwOME("Malformed object. Something wrong occured");
257 }
258 else
259 throwOME("Malformed object. Something wrong occured");
260
261 compounded.append("</OMOBJ>");
262 }
263
264 /***
265 * Receives notification of the beginning of a application element.
266 *
267 * <p>By default, do nothing. Application writers may override this
268 * method in a subclass.</p>
269 *
270 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
271 * @see #endApplication
272 */
273 public void startApplication() throws OMException {
274 if (!stackSymbol.empty()) {
275 Symbol currentSymbol = (Symbol) stackSymbol.peek();
276
277
278 if (!currentSymbol.equals("", "")) {
279
280 byte numOperands = ((Byte) stackSymbolOperands.pop()).byteValue();
281
282 numOperands++;
283 stackSymbolOperands.push(new Byte(numOperands));
284 }
285 }
286
287 if (!stackContext.empty()) {
288
289 compounded.append("<OMA>");
290
291 byte context = popContext();
292 switch (context) {
293 case CREATE_APPLICATION:
294 case CREATE_BIDING_OBJECT:
295 pushContext(context);
296 case CREATE_OBJECT:
297 case WAIT_FOR_OBJECT:
298 case CREATE_BIDING:
299 pushContext(CREATE_APPLICATION);
300 break;
301 case WAIT_FOR_END_OBJECT:
302 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
303 case CREATE_ATTRIBUTION:
304 throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
305 case CREATE_ATTRIBUT_PAIRS:
306 throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
307 case END_ATTRIBUT_PAIRS:
308 throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
309 case END_ATTRIBUTION:
310 throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
311 case CREATE_ERROR:
312 throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
313 case CREATE_BIDING_VARIABLES:
314 throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
315 case WAIT_FOR_VARIABLES:
316 throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
317 case END_BIDING:
318 throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
319 }
320 }
321 else
322 throwOME("Malformed object. Something wrong occured");
323 }
324
325 /***
326 * Receives notification of the end of an application element.
327 *
328 * <p>By default, do nothing. Application writers may override this
329 * method in a subclass.</p>
330 *
331 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
332 * @see #startApplication
333 */
334 public void endApplication() throws OMException {
335 Symbol symbol;
336 Symbol topSymbol;
337
338
339
340
341 if (!stackContext.empty()) {
342
343 compounded.append("</OMA>");
344
345 byte context = popContext();
346 switch (context) {
347 case WAIT_FOR_OBJECT:
348 popContext();
349
350 symbol = (Symbol) stackSymbol.pop();
351
352 stackSymbolOperands.pop();
353
354 if (!stackContext.empty()) {
355 switch (getContext()) {
356 case CREATE_OBJECT:
357 pushContext(WAIT_FOR_END_OBJECT);
358 case CREATE_APPLICATION:
359 case CREATE_ERROR:
360 pushContext(WAIT_FOR_OBJECT);
361 break;
362 case CREATE_BIDING:
363 pushContext(CREATE_BIDING_VARIABLES);
364 break;
365 case CREATE_BIDING_OBJECT:
366 popContext();
367 popContext();
368 pushContext(END_BIDING);
369 break;
370 case CREATE_ATTRIBUT_PAIRS:
371 pushContext(END_ATTRIBUT_PAIRS);
372 break;
373 case CREATE_ATTRIBUTION:
374 pushContext(END_ATTRIBUTION);
375 break;
376 }
377 }
378 else
379 pushContext(WAIT_FOR_END_OBJECT);
380
381 break;
382
383 case CREATE_OBJECT:
384 case CREATE_APPLICATION:
385 case CREATE_BIDING:
386 case CREATE_BIDING_OBJECT:
387 throwOME("Malformed object. An object was expected", OMException.OME_NODE_NOT_FOUND);
388 case WAIT_FOR_END_OBJECT:
389 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
390 case CREATE_ATTRIBUTION:
391 throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
392 case CREATE_ATTRIBUT_PAIRS:
393 throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
394 case END_ATTRIBUT_PAIRS:
395 throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
396 case END_ATTRIBUTION:
397 throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
398 case CREATE_ERROR:
399 throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
400 case CREATE_BIDING_VARIABLES:
401 throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
402 case WAIT_FOR_VARIABLES:
403 throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
404 case END_BIDING:
405 throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
406 }
407 }
408 else
409 throwOME("Malformed object. Something wrong occured");
410
411 }
412
413
414 /***
415 * Receives notification of the beginning of a attribution element.
416 *
417 * <p>By default, do nothing. Application writers may override this
418 * method in a subclass.</p>
419 *
420 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
421 * @see #endAttribution
422 */
423 public void startAttribution() throws OMException {
424
425
426
427 if (!stackContext.empty()) {
428 compounded.append("<OMATP>");
429
430 byte context = popContext();
431 switch (context) {
432 case CREATE_APPLICATION:
433
434
435 stackSymbol.push(new Symbol("", ""));
436 stackSymbolOperands.push(new Byte(Byte.MAX_VALUE));
437
438 case CREATE_BIDING:
439 case WAIT_FOR_VARIABLES:
440 case CREATE_BIDING_OBJECT:
441 pushContext(context);
442 case CREATE_OBJECT:
443 case WAIT_FOR_OBJECT:
444 pushContext(CREATE_ATTRIBUTION);
445
446
447
448
449
450 break;
451
452 case WAIT_FOR_END_OBJECT:
453 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
454 case CREATE_ATTRIBUTION:
455 throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
456 case CREATE_ATTRIBUT_PAIRS:
457 throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
458 case END_ATTRIBUT_PAIRS:
459 throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
460 case END_ATTRIBUTION:
461 throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
462 case CREATE_ERROR:
463 throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
464 case CREATE_BIDING_VARIABLES:
465 throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
466 case END_BIDING:
467 throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
468 }
469 }
470 else
471 throwOME("Malformed object. Something wrong occured");
472 }
473
474 /***
475 * Receives notification of the end of an attribution element.
476 *
477 * <p>By default, do nothing. Application writers may override this
478 * method in a subclass.</p>
479 *
480 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
481 * @see #startAttribution
482 */
483 public void endAttribution() throws OMException {
484
485
486
487 if (!stackContext.empty()) {
488
489 compounded.append("</OMATP>");
490
491 byte context = popContext();
492 switch (context) {
493 case END_ATTRIBUTION:
494
495
496
497
498
499
500
501
502 if (!stackContext.empty()) {
503 switch (getContext()) {
504 case CREATE_OBJECT:
505 pushContext(WAIT_FOR_END_OBJECT);
506 case CREATE_ERROR:
507 pushContext(WAIT_FOR_OBJECT);
508 break;
509 case CREATE_BIDING:
510 pushContext(CREATE_BIDING_VARIABLES);
511 break;
512 case WAIT_FOR_VARIABLES:
513 popContext();
514 pushContext(CREATE_BIDING_OBJECT);
515 break;
516 case CREATE_BIDING_OBJECT:
517 popContext();
518 popContext();
519 pushContext(END_BIDING);
520 break;
521 case CREATE_ATTRIBUT_PAIRS:
522 pushContext(END_ATTRIBUT_PAIRS);
523 break;
524 case CREATE_ATTRIBUTION:
525 pushContext(END_ATTRIBUTION);
526 break;
527 }
528 }
529 else
530 pushContext(WAIT_FOR_END_OBJECT);
531
532 break;
533
534 case CREATE_OBJECT:
535 case WAIT_FOR_OBJECT:
536 case CREATE_APPLICATION:
537 case CREATE_BIDING:
538 case CREATE_BIDING_OBJECT:
539 throwOME("Malformed object. An object was expected", OMException.OME_NODE_NOT_FOUND);
540 case WAIT_FOR_END_OBJECT:
541 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
542 case CREATE_ATTRIBUTION:
543 throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
544 case CREATE_ATTRIBUT_PAIRS:
545 throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
546 case END_ATTRIBUT_PAIRS:
547 throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
548 case CREATE_ERROR:
549 throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
550 case CREATE_BIDING_VARIABLES:
551 throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
552 case WAIT_FOR_VARIABLES:
553 throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
554 case END_BIDING:
555 throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
556 }
557 }
558 else
559 throwOME("Malformed object. Something wrong occured");
560
561 }
562
563 /***
564 * Receives notification of the beginning of an attribute-pairs element.
565 *
566 * <p>By default, do nothing. Application writers may override this
567 * method in a subclass.</p>
568 *
569 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
570 *
571 * @see #endAttributePairs
572 */
573 public void startAttributePairs() throws OMException {
574
575
576 if (!stackContext.empty()) {
577
578 compounded.append("<OMATTR>");
579
580 byte context = popContext();
581 switch (context) {
582 case CREATE_ATTRIBUTION:
583
584
585
586
587 pushContext(context);
588 pushContext(CREATE_ATTRIBUT_PAIRS);
589 break;
590
591 case CREATE_OBJECT:
592 case WAIT_FOR_OBJECT:
593 case CREATE_APPLICATION:
594 case CREATE_BIDING:
595 case CREATE_BIDING_OBJECT:
596 throwOME("Malformed object. An object was expected", OMException.OME_NODE_NOT_FOUND);
597 case WAIT_FOR_END_OBJECT:
598 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
599 case CREATE_ATTRIBUT_PAIRS:
600 throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
601 case END_ATTRIBUT_PAIRS:
602 throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
603 case END_ATTRIBUTION:
604 throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
605 case CREATE_ERROR:
606 throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
607 case CREATE_BIDING_VARIABLES:
608 throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
609 case WAIT_FOR_VARIABLES:
610 throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
611 case END_BIDING:
612 throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
613 }
614 }
615 else
616 throwOME("Malformed object. Something wrong occured");
617 }
618
619 /***
620 * Receives notification of the end of an attribute-pairs element.
621 *
622 * <p>By default, do nothing. Application writers may override this
623 * method in a subclass.</p>
624 *
625 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
626 * @see #startAttribution
627 */
628 public void endAttributePairs() throws OMException {
629
630
631
632 if (!stackContext.empty()) {
633
634 compounded.append("</OMATTR>");
635
636 byte context = popContext();
637 switch (context) {
638 case END_ATTRIBUT_PAIRS:
639
640
641
642
643
644
645 if (!stackContext.empty()) {
646 popContext();
647 pushContext(WAIT_FOR_OBJECT);
648 }
649 else
650 throwOME("Malformed object. Something wrong occured");
651
652 break;
653
654 case CREATE_OBJECT:
655 case WAIT_FOR_OBJECT:
656 case CREATE_APPLICATION:
657 case CREATE_BIDING:
658 case CREATE_BIDING_OBJECT:
659 throwOME("Malformed object. An object was expected", OMException.OME_NODE_NOT_FOUND);
660 case WAIT_FOR_END_OBJECT:
661 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
662 case CREATE_ATTRIBUTION:
663 throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
664 case CREATE_ATTRIBUT_PAIRS:
665 throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
666 case END_ATTRIBUTION:
667 throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
668 case CREATE_ERROR:
669 throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
670 case CREATE_BIDING_VARIABLES:
671 throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
672 case WAIT_FOR_VARIABLES:
673 throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
674 case END_BIDING:
675 throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
676 }
677 }
678 else
679 throwOME("Malformed object. Something wrong occured");
680 }
681
682 /***
683 * Receives notification of the beginning of a Bind element.
684 *
685 * <p>By default, do nothing. Application writers may override this
686 * method in a subclass.</p>
687 *
688 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
689 *
690 * @see #endBind
691 */
692 public void startBind() throws OMException {
693
694
695
696 if (!stackContext.empty()) {
697
698 compounded.append("<OMBIND>");
699
700 byte context = popContext();
701 switch (context) {
702 case CREATE_APPLICATION:
703
704
705 stackSymbol.push(new Symbol("", ""));
706 stackSymbolOperands.push(new Byte(Byte.MAX_VALUE));
707
708 case CREATE_BIDING:
709 case CREATE_BIDING_OBJECT:
710 pushContext(context);
711 case CREATE_OBJECT:
712 case WAIT_FOR_OBJECT:
713 pushContext(CREATE_BIDING);
714
715
716
717
718
719 break;
720
721 case WAIT_FOR_END_OBJECT:
722 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
723 case CREATE_ATTRIBUTION:
724 throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
725 case CREATE_ATTRIBUT_PAIRS:
726 throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
727 case END_ATTRIBUT_PAIRS:
728 throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
729 case END_ATTRIBUTION:
730 throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
731 case CREATE_ERROR:
732 throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
733 case CREATE_BIDING_VARIABLES:
734 throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
735 case WAIT_FOR_VARIABLES:
736 throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
737 case END_BIDING:
738 throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
739 }
740 }
741 else
742 throwOME("Malformed object. Something wrong occured");
743 }
744
745
746
747
748 /***
749 * Receives notification of the beginning of a BVars element.
750 *
751 * <p>By default, do nothing. Application writers may override this
752 * method in a subclass.</p>
753 *
754 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
755 *
756 * @see #endBVars
757 */
758 public void startBVars() throws OMException {
759
760
761 if (!stackContext.empty()) {
762
763 compounded.append("<OMBVAR>");
764
765 byte context = popContext();
766 switch (context) {
767 case CREATE_BIDING_VARIABLES:
768 pushContext(WAIT_FOR_VARIABLES);
769 break;
770
771 case CREATE_OBJECT:
772 case WAIT_FOR_OBJECT:
773 case CREATE_BIDING:
774 case CREATE_BIDING_OBJECT:
775 throwOME("Malformed object. An object was expected", OMException.OME_NODE_NOT_FOUND);
776 case CREATE_APPLICATION:
777 throwOME("Malformed object. Application expected", OMException.OME_NODE_NOT_FOUND);
778 case WAIT_FOR_VARIABLES:
779 throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
780 case WAIT_FOR_END_OBJECT:
781 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
782 case CREATE_ATTRIBUTION:
783 throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
784 case CREATE_ATTRIBUT_PAIRS:
785 throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
786 case END_ATTRIBUT_PAIRS:
787 throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
788 case END_ATTRIBUTION:
789 throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
790 case CREATE_ERROR:
791 throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
792 case END_BIDING:
793 throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
794 }
795 }
796 else
797 throwOME("Malformed object. Something wrong occured");
798 }
799
800 /***
801 * Receives notification of the beginning of a BVars element.
802 *
803 * <p>By default, do nothing. Application writers may override this
804 * method in a subclass.</p>
805 *
806 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
807 *
808 * @see #startBVars
809 */
810 public void endBVars() throws OMException {
811
812
813 if (!stackContext.empty()) {
814
815 compounded.append("</OMBVAR>");
816
817 byte context = popContext();
818
819 switch (context) {
820 case WAIT_FOR_VARIABLES:
821 pushContext(CREATE_BIDING_OBJECT);
822 break;
823
824 case CREATE_OBJECT:
825 case WAIT_FOR_OBJECT:
826 case CREATE_BIDING:
827 case CREATE_BIDING_OBJECT:
828 throwOME("Malformed object. An object was expected", OMException.OME_NODE_NOT_FOUND);
829 case CREATE_APPLICATION:
830 throwOME("Malformed object. Application expected", OMException.OME_NODE_NOT_FOUND);
831 case CREATE_BIDING_VARIABLES:
832 throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
833 case WAIT_FOR_END_OBJECT:
834 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
835 case CREATE_ATTRIBUTION:
836 throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
837 case CREATE_ATTRIBUT_PAIRS:
838 throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
839 case END_ATTRIBUT_PAIRS:
840 throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
841 case END_ATTRIBUTION:
842 throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
843 case CREATE_ERROR:
844 throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
845 case END_BIDING:
846 throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
847 }
848 }
849 else
850 throwOME("Malformed object. Something wrong occured");
851 }
852
853
854 /***
855 * Receives notification of the beginning of a Bind element.
856 *
857 * <p>By default, do nothing. Application writers may override this
858 * method in a subclass.</p>
859 *
860 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
861 *
862 * @see #endBind
863 */
864 public void endBind() throws OMException {
865
866
867 if (!stackContext.empty()) {
868
869 compounded.append("</OMBIND>");
870
871 byte context = popContext();
872 switch (context) {
873 case END_BIDING:
874
875
876 if (!stackContext.empty()) {
877 switch (getContext()) {
878 case CREATE_OBJECT:
879 pushContext(WAIT_FOR_END_OBJECT);
880 break;
881 case CREATE_APPLICATION:
882 case CREATE_ERROR:
883 pushContext(WAIT_FOR_OBJECT);
884 break;
885 case CREATE_BIDING:
886 pushContext(CREATE_BIDING_VARIABLES);
887 break;
888 case WAIT_FOR_VARIABLES:
889 pushContext(CREATE_BIDING_OBJECT);
890 break;
891 case CREATE_ATTRIBUT_PAIRS:
892 pushContext(END_ATTRIBUT_PAIRS);
893 break;
894 case CREATE_ATTRIBUTION:
895 pushContext(END_ATTRIBUTION);
896 break;
897 }
898 }
899 else
900 pushContext(WAIT_FOR_END_OBJECT);
901
902 break;
903
904 case CREATE_OBJECT:
905 case WAIT_FOR_OBJECT:
906 case CREATE_APPLICATION:
907 case CREATE_BIDING:
908 case CREATE_BIDING_OBJECT:
909 throwOME("Malformed object. An object was expected", OMException.OME_NODE_NOT_FOUND);
910 case WAIT_FOR_END_OBJECT:
911 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
912 case CREATE_ATTRIBUTION:
913 throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
914 case CREATE_ATTRIBUT_PAIRS:
915 throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
916 case END_ATTRIBUT_PAIRS:
917 throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
918 case END_ATTRIBUTION:
919 throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
920 case CREATE_ERROR:
921 throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
922 case CREATE_BIDING_VARIABLES:
923 throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
924 case WAIT_FOR_VARIABLES:
925 throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
926 }
927 }
928 else
929 throwOME("Malformed object. Something wrong occured");
930
931 }
932
933 /***
934 * Receives notification of the beginning of a error element.
935 *
936 * <p>By default, do nothing. Application writers may override this
937 * method in a subclass.</p>
938 *
939 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
940 *
941 * @see #endError
942 */
943 public void startError() throws OMException {
944
945
946 if (!stackContext.empty()) {
947
948 compounded.append("<OME>");
949
950 byte context = popContext();
951 switch (context) {
952 case CREATE_APPLICATION:
953
954
955
956
957
958
959 stackSymbol.push(new Symbol("", ""));
960 stackSymbolOperands.push(new Byte(Byte.MAX_VALUE));
961
962 case CREATE_OBJECT:
963 pushContext(context);
964 case WAIT_FOR_OBJECT:
965 case CREATE_BIDING:
966 case CREATE_BIDING_OBJECT:
967 pushContext(CREATE_ERROR);
968
969
970
971 break;
972 case WAIT_FOR_END_OBJECT:
973 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
974 case CREATE_ATTRIBUTION:
975 throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
976 case CREATE_ATTRIBUT_PAIRS:
977 throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
978 case END_ATTRIBUT_PAIRS:
979 throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
980 case END_ATTRIBUTION:
981 throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
982 case CREATE_ERROR:
983 throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
984 case CREATE_BIDING_VARIABLES:
985 throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
986 case WAIT_FOR_VARIABLES:
987 throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
988 case END_BIDING:
989 throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
990 }
991 }
992 else
993 throwOME("Malformed object. Something wrong occured");
994 }
995
996 /***
997 * Receives notification of the end of an error element.
998 *
999 * <p>By default, do nothing. Application writers may override this
1000 * method in a subclass.</p>
1001 *
1002 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
1003 * @see #startError
1004 */
1005 public void endError() throws OMException {
1006
1007
1008 if (!stackContext.empty()) {
1009
1010 compounded.append("</OME>");
1011
1012 byte context = popContext();
1013 switch (context) {
1014 case WAIT_FOR_OBJECT:
1015
1016
1017
1018
1019
1020
1021 if (!stackContext.empty()) {
1022 switch (getContext()) {
1023 case CREATE_OBJECT:
1024 pushContext(WAIT_FOR_END_OBJECT);
1025 break;
1026 case CREATE_APPLICATION:
1027 pushContext(WAIT_FOR_OBJECT);
1028 break;
1029 case CREATE_ERROR:
1030
1031
1032 popContext();
1033 popContext();
1034 pushContext(WAIT_FOR_END_OBJECT);
1035 break;
1036 case CREATE_BIDING:
1037 pushContext(CREATE_BIDING_VARIABLES);
1038 break;
1039 case WAIT_FOR_VARIABLES:
1040 pushContext(CREATE_BIDING_OBJECT);
1041 break;
1042 case CREATE_ATTRIBUT_PAIRS:
1043 pushContext(END_ATTRIBUT_PAIRS);
1044 break;
1045 case CREATE_ATTRIBUTION:
1046 pushContext(END_ATTRIBUTION);
1047 break;
1048 }
1049 }
1050 else
1051 pushContext(WAIT_FOR_END_OBJECT);
1052
1053 break;
1054
1055 case CREATE_OBJECT:
1056 case CREATE_APPLICATION:
1057 case CREATE_BIDING:
1058 case CREATE_BIDING_OBJECT:
1059 throwOME("Malformed object. An object was expected", OMException.OME_NODE_NOT_FOUND);
1060 case WAIT_FOR_END_OBJECT:
1061 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
1062 case CREATE_ATTRIBUTION:
1063 throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
1064 case CREATE_ATTRIBUT_PAIRS:
1065 throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
1066 case END_ATTRIBUT_PAIRS:
1067 throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1068 case END_ATTRIBUTION:
1069 throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
1070 case CREATE_ERROR:
1071 throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1072 case CREATE_BIDING_VARIABLES:
1073 throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
1074 case WAIT_FOR_VARIABLES:
1075 throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
1076 case END_BIDING:
1077 throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
1078 }
1079 }
1080 else
1081 throwOME("Malformed object. Something wrong occured");
1082
1083 }
1084
1085
1086 /***
1087 * Receives notification of an Integer element.
1088 *
1089 * <p>By default, do nothing. Application writers may override this
1090 * method in a subclass.</p>
1091 *
1092 * @param value the value embeded in this Integer element. This is an infinite precision integer.
1093 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
1094 * @see fr.inria.openmath.omapi.BigInt
1095 */
1096 public void readInteger(BigInt value) throws OMException {
1097
1098 Symbol symbol;
1099
1100 if (!stackContext.empty()) {
1101 byte context = popContext();
1102
1103 switch (context) {
1104 case CREATE_OBJECT:
1105 insertInteger(value);
1106 pushContext(WAIT_FOR_END_OBJECT);
1107 break;
1108 case WAIT_FOR_OBJECT:
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119 if (!stackContext.empty()) {
1120
1121 byte superContext = getContext();
1122 if (superContext == CREATE_APPLICATION) {
1123 Symbol currentSymbol = (Symbol) stackSymbol.peek();
1124
1125
1126 if (!currentSymbol.equals("", "")) {
1127
1128 byte numOperands = ((Byte) stackSymbolOperands.pop()).byteValue();
1129 numOperands++;
1130
1131 stackSymbolOperands.push(new Byte(numOperands));
1132 }
1133 }
1134
1135 insertInteger(value);
1136
1137 switch (superContext) {
1138 case CREATE_ERROR:
1139 case CREATE_APPLICATION:
1140 pushContext(WAIT_FOR_OBJECT);
1141 break;
1142 case CREATE_BIDING:
1143 pushContext(CREATE_BIDING_VARIABLES);
1144 break;
1145 case CREATE_ATTRIBUT_PAIRS:
1146 pushContext(END_ATTRIBUT_PAIRS);
1147 break;
1148 case CREATE_ATTRIBUTION:
1149 pushContext(END_ATTRIBUTION);
1150 break;
1151 }
1152 }
1153 else {
1154 insertInteger(value);
1155 pushContext(WAIT_FOR_END_OBJECT);
1156 }
1157
1158 break;
1159
1160 case CREATE_BIDING:
1161
1162
1163 pushContext(context);
1164 pushContext(CREATE_BIDING_VARIABLES);
1165 break;
1166 case CREATE_BIDING_OBJECT:
1167 insertInteger(value);
1168 popContext();
1169 pushContext(END_BIDING);
1170 break;
1171 case CREATE_APPLICATION:
1172 throwOME("Malformed application. Can't apply an Integer to something", OMException.OME_SYNTAX);
1173 case WAIT_FOR_END_OBJECT:
1174 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
1175 case CREATE_ATTRIBUTION:
1176 throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
1177 case CREATE_ATTRIBUT_PAIRS:
1178 throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
1179 case END_ATTRIBUT_PAIRS:
1180 throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1181 case END_ATTRIBUTION:
1182 throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
1183 case CREATE_ERROR:
1184 throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1185 case CREATE_BIDING_VARIABLES:
1186 throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
1187 case WAIT_FOR_VARIABLES:
1188 throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
1189 case END_BIDING:
1190 throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
1191 }
1192 }
1193 else
1194 throwOME("Malformed object. Something wrong occured");
1195 }
1196
1197 /***
1198 * Receives notification of a floating-point number element.
1199 *
1200 * <p>By default, do nothing. Application writers may override this
1201 * method in a subclass.</p>
1202 *
1203 * @param value the value embeded in this Float element.
1204 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
1205 *
1206 */
1207 public void readFloat(double value) throws OMException {
1208
1209 Symbol symbol;
1210
1211 if (!stackContext.empty()) {
1212 byte context = popContext();
1213
1214 switch (context) {
1215 case CREATE_OBJECT:
1216 insertFloat(value);
1217 pushContext(WAIT_FOR_END_OBJECT);
1218 break;
1219 case WAIT_FOR_OBJECT:
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230 if (!stackContext.empty()) {
1231
1232 byte superContext = getContext();
1233 if (superContext == CREATE_APPLICATION) {
1234 Symbol currentSymbol = (Symbol) stackSymbol.peek();
1235
1236
1237 if (!currentSymbol.equals("", "")) {
1238
1239 byte numOperands = ((Byte) stackSymbolOperands.pop()).byteValue();
1240
1241 numOperands++;
1242 stackSymbolOperands.push(new Byte(numOperands));
1243 }
1244 }
1245
1246 insertFloat(value);
1247
1248 switch (superContext) {
1249 case CREATE_ERROR:
1250 case CREATE_APPLICATION:
1251 pushContext(WAIT_FOR_OBJECT);
1252 break;
1253 case CREATE_BIDING:
1254 pushContext(CREATE_BIDING_VARIABLES);
1255 break;
1256 case CREATE_ATTRIBUT_PAIRS:
1257 pushContext(END_ATTRIBUT_PAIRS);
1258 break;
1259 case CREATE_ATTRIBUTION:
1260 pushContext(END_ATTRIBUTION);
1261 break;
1262 }
1263 }
1264 else {
1265 insertFloat(value);
1266 pushContext(WAIT_FOR_END_OBJECT);
1267 }
1268
1269 break;
1270
1271 case CREATE_BIDING:
1272
1273
1274 pushContext(context);
1275 pushContext(CREATE_BIDING_VARIABLES);
1276 break;
1277 case CREATE_BIDING_OBJECT:
1278 insertFloat(value);
1279 popContext();
1280 pushContext(END_BIDING);
1281 break;
1282 case CREATE_APPLICATION:
1283 throwOME("Malformed application. Can't apply an Integer to something", OMException.OME_SYNTAX);
1284 case WAIT_FOR_END_OBJECT:
1285 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
1286 case CREATE_ATTRIBUTION:
1287 throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
1288 case CREATE_ATTRIBUT_PAIRS:
1289 throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
1290 case END_ATTRIBUT_PAIRS:
1291 throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1292 case END_ATTRIBUTION:
1293 throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
1294 case CREATE_ERROR:
1295 throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1296 case CREATE_BIDING_VARIABLES:
1297 throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
1298 case WAIT_FOR_VARIABLES:
1299 throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
1300 case END_BIDING:
1301 throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
1302 }
1303 }
1304 else
1305 throwOME("Malformed object. Something wrong occured");
1306 }
1307
1308 /***
1309 * Receives notification of a string element.
1310 *
1311 * <p>By default, do nothing. Application writers may override this
1312 * method in a subclass.</p>
1313 *
1314 * @param value the value embeded in this String element.
1315 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
1316 *
1317 */
1318 public void readString(String value) throws OMException {
1319
1320
1321 if (!stackContext.empty()) {
1322
1323 compounded.append("<OMSTR>" + value + "</OMSTR>");
1324
1325 byte context = popContext();
1326 switch (context) {
1327 case CREATE_OBJECT:
1328
1329
1330
1331
1332
1333 pushContext(WAIT_FOR_END_OBJECT);
1334 break;
1335 case WAIT_FOR_OBJECT:
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347 if (!stackContext.empty()) {
1348
1349 byte superContext = getContext();
1350 if (superContext == CREATE_APPLICATION) {
1351
1352
1353 Symbol currentSymbol = (Symbol) stackSymbol.peek();
1354
1355
1356 if (!currentSymbol.equals("", "")) {
1357
1358 byte numOperands = ((Byte) stackSymbolOperands.pop()).byteValue();
1359
1360 numOperands++;
1361 stackSymbolOperands.push(new Byte(numOperands));
1362 }
1363 }
1364
1365
1366
1367
1368
1369
1370
1371 switch (superContext) {
1372 case CREATE_ERROR:
1373 case CREATE_APPLICATION:
1374 pushContext(WAIT_FOR_OBJECT);
1375 break;
1376 case CREATE_BIDING:
1377 pushContext(CREATE_BIDING_VARIABLES);
1378 break;
1379 case CREATE_ATTRIBUT_PAIRS:
1380 pushContext(END_ATTRIBUT_PAIRS);
1381 break;
1382 case CREATE_ATTRIBUTION:
1383 pushContext(END_ATTRIBUTION);
1384 break;
1385 }
1386 }
1387 else {
1388
1389
1390
1391
1392
1393
1394 pushContext(WAIT_FOR_END_OBJECT);
1395 }
1396
1397 break;
1398
1399
1400 case CREATE_BIDING:
1401
1402
1403
1404
1405 pushContext(context);
1406 pushContext(CREATE_BIDING_VARIABLES);
1407 break;
1408 case CREATE_BIDING_OBJECT:
1409
1410
1411
1412
1413 popContext();
1414 pushContext(END_BIDING);
1415 break;
1416 case CREATE_APPLICATION:
1417
1418 pushContext(context);
1419 pushContext(WAIT_FOR_OBJECT);
1420 break;
1421 case WAIT_FOR_END_OBJECT:
1422 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
1423 case CREATE_ATTRIBUTION:
1424 throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
1425 case CREATE_ATTRIBUT_PAIRS:
1426 throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
1427 case END_ATTRIBUT_PAIRS:
1428 throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1429 case END_ATTRIBUTION:
1430 throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
1431 case CREATE_ERROR:
1432 throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1433 case CREATE_BIDING_VARIABLES:
1434 throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
1435 case WAIT_FOR_VARIABLES:
1436 throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
1437 case END_BIDING:
1438 throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
1439 }
1440 }
1441 else
1442 throwOME("Malformed object. Something wrong occured");
1443 }
1444
1445 /***
1446 * Receives notification of a variable element.
1447 *
1448 * <p>By default, do nothing. Application writers may override this
1449 * method in a subclass.</p>
1450 *
1451 * @param name the name of this Variable element.
1452 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
1453 *
1454 */
1455 public void readVariable(String name) throws OMException {
1456
1457
1458 if (!stackContext.empty()) {
1459 byte context = popContext();
1460
1461 switch (context) {
1462 case CREATE_OBJECT:
1463 insertVariable(name);
1464 pushContext(WAIT_FOR_END_OBJECT);
1465 break;
1466 case WAIT_FOR_OBJECT:
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477 if (!stackContext.empty()) {
1478
1479 byte superContext = getContext();
1480 if (superContext == CREATE_APPLICATION) {
1481
1482 Symbol currentSymbol = (Symbol) stackSymbol.peek();
1483
1484
1485 if (!currentSymbol.equals("", "")) {
1486
1487 byte numOperands = ((Byte) stackSymbolOperands.pop()).byteValue();
1488
1489 numOperands++;
1490 stackSymbolOperands.push(new Byte(numOperands));
1491 }
1492 }
1493
1494 insertVariable(name);
1495
1496 switch (superContext) {
1497 case CREATE_ERROR:
1498 case CREATE_APPLICATION:
1499 pushContext(WAIT_FOR_OBJECT);
1500 break;
1501 case CREATE_BIDING:
1502 pushContext(CREATE_BIDING_VARIABLES);
1503 break;
1504 case CREATE_ATTRIBUT_PAIRS:
1505 pushContext(END_ATTRIBUT_PAIRS);
1506 break;
1507 case CREATE_ATTRIBUTION:
1508 pushContext(END_ATTRIBUTION);
1509 break;
1510 }
1511 }
1512 else {
1513 insertVariable(name);
1514 pushContext(WAIT_FOR_END_OBJECT);
1515 }
1516
1517 break;
1518
1519
1520 case CREATE_BIDING:
1521
1522
1523 pushContext(context);
1524 pushContext(CREATE_BIDING_VARIABLES);
1525 break;
1526 case CREATE_BIDING_OBJECT:
1527 insertVariable(name);
1528 popContext();
1529 pushContext(END_BIDING);
1530 break;
1531 case CREATE_APPLICATION:
1532
1533
1534 Symbol symbol = new Symbol("null", "user_function");
1535 stackSymbol.push(symbol);
1536 stackSymbolOperands.push(new Byte((byte) 0));
1537
1538 compounded.append("<OMV name=\"" + name + "\"/>");
1539
1540 pushContext(context);
1541 pushContext(WAIT_FOR_OBJECT);
1542 break;
1543 case WAIT_FOR_VARIABLES:
1544 compounded.append("<OMV name=\"" + name + "\"/>");
1545 pushContext(context);
1546 break;
1547 case WAIT_FOR_END_OBJECT:
1548 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
1549 case CREATE_ATTRIBUTION:
1550 throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
1551 case CREATE_ATTRIBUT_PAIRS:
1552 throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
1553 case END_ATTRIBUT_PAIRS:
1554 throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1555 case END_ATTRIBUTION:
1556 throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
1557 case CREATE_ERROR:
1558 throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1559 case CREATE_BIDING_VARIABLES:
1560 throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
1561 case END_BIDING:
1562 throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
1563 }
1564 }
1565 else
1566 throwOME("Malformed object. Something wrong occured");
1567 }
1568
1569 /***
1570 * Receives notification of a byteArray element.
1571 *
1572 * <p>By default, do nothing. Application writers may override this
1573 * method in a subclass.</p>
1574 *
1575 * @param value the value embeded in this ByteArray element.
1576 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
1577 *
1578 */
1579 public void readByteArray(byte[] value) throws OMException {
1580
1581
1582 if (!stackContext.empty()) {
1583
1584 compounded.append("<OMB" + value + "</OMB>");
1585
1586 byte context = popContext();
1587 switch (context) {
1588 case CREATE_OBJECT:
1589
1590
1591
1592
1593 pushContext(WAIT_FOR_END_OBJECT);
1594 break;
1595 case WAIT_FOR_OBJECT:
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606 if (!stackContext.empty()) {
1607
1608 byte superContext = getContext();
1609 if (superContext == CREATE_APPLICATION) {
1610
1611
1612 Symbol currentSymbol = (Symbol) stackSymbol.peek();
1613
1614
1615 if (!currentSymbol.equals("", "")) {
1616
1617 byte numOperands = ((Byte) stackSymbolOperands.pop()).byteValue();
1618
1619 numOperands++;
1620 stackSymbolOperands.push(new Byte(numOperands));
1621 }
1622 }
1623
1624
1625
1626
1627
1628
1629
1630 switch (superContext) {
1631 case CREATE_ERROR:
1632 case CREATE_APPLICATION:
1633 pushContext(WAIT_FOR_OBJECT);
1634 break;
1635 case CREATE_BIDING:
1636 pushContext(CREATE_BIDING_VARIABLES);
1637 break;
1638 case CREATE_ATTRIBUT_PAIRS:
1639 pushContext(END_ATTRIBUT_PAIRS);
1640 break;
1641 case CREATE_ATTRIBUTION:
1642 pushContext(END_ATTRIBUTION);
1643 break;
1644 }
1645 }
1646 else {
1647
1648
1649
1650
1651
1652
1653 pushContext(WAIT_FOR_END_OBJECT);
1654 }
1655
1656 break;
1657
1658
1659 case CREATE_BIDING:
1660
1661
1662
1663
1664 pushContext(context);
1665 pushContext(CREATE_BIDING_VARIABLES);
1666 break;
1667 case CREATE_BIDING_OBJECT:
1668
1669
1670
1671
1672 popContext();
1673 pushContext(END_BIDING);
1674 break;
1675 case CREATE_APPLICATION:
1676 throwOME("Malformed application. Can't apply a ByteArray to something", OMException.OME_SYNTAX);
1677 case WAIT_FOR_END_OBJECT:
1678 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
1679 case CREATE_ATTRIBUTION:
1680 throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
1681 case CREATE_ATTRIBUT_PAIRS:
1682 throwOME("Malformed object. Attribute pairs expected", OMException.OME_NODE_NOT_FOUND);
1683 case END_ATTRIBUT_PAIRS:
1684 throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1685 case END_ATTRIBUTION:
1686 throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
1687 case CREATE_ERROR:
1688 throwOME("Malformed object. <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1689 case CREATE_BIDING_VARIABLES:
1690 throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
1691 case WAIT_FOR_VARIABLES:
1692 throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
1693 case END_BIDING:
1694 throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
1695 }
1696 }
1697 else
1698 throwOME("Malformed object. Something wrong occured");
1699 }
1700
1701 /***
1702 * Receives notification of a symbol element.
1703 *
1704 * <p>By default, do nothing. Application writers may override this
1705 * method in a subclass.</p>
1706 *
1707 * @param value the value embeded in this Symbol element.
1708 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
1709 * @see Symbol
1710 */
1711 public void readSymbol(Symbol value) throws OMException {
1712
1713 byte errorCode;
1714 String typeOpe;
1715
1716
1717 if (!stackContext.empty()) {
1718 byte context = popContext();
1719
1720 switch (context) {
1721 case CREATE_APPLICATION:
1722 pushContext(context);
1723
1724
1725 if (true
1726 insertSymbol(value);
1727
1728
1729 stackSymbol.push(value);
1730 stackSymbolOperands.push(new Byte((byte) 0));
1731
1732 pushContext(WAIT_FOR_OBJECT);
1733 }
1734 else
1735 throwOME("Malformed application. "
1736 break;
1737
1738 case CREATE_OBJECT:
1739 insertSymbol(value);
1740 pushContext(WAIT_FOR_END_OBJECT);
1741 break;
1742 case WAIT_FOR_OBJECT:
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753 if (!stackContext.empty()) {
1754
1755 byte superContext = getContext();
1756 if (superContext == CREATE_APPLICATION) {
1757
1758 Symbol currentSymbol = (Symbol) stackSymbol.peek();
1759
1760
1761 if (!currentSymbol.equals("", "")) {
1762
1763 byte numOperands = ((Byte) stackSymbolOperands.pop()).byteValue();
1764
1765 numOperands++;
1766 stackSymbolOperands.push(new Byte(numOperands));
1767 }
1768 }
1769
1770 insertSymbol(value);
1771
1772 switch (superContext) {
1773 case CREATE_ERROR:
1774 case CREATE_APPLICATION:
1775 pushContext(WAIT_FOR_OBJECT);
1776 break;
1777 case CREATE_BIDING:
1778 pushContext(CREATE_BIDING_VARIABLES);
1779 break;
1780 case CREATE_ATTRIBUT_PAIRS:
1781 pushContext(END_ATTRIBUT_PAIRS);
1782 break;
1783 case CREATE_ATTRIBUTION:
1784 pushContext(END_ATTRIBUTION);
1785 break;
1786 }
1787 }
1788 else
1789 insertSymbol(value);
1790
1791 break;
1792
1793 case CREATE_BIDING:
1794 insertSymbol(value);
1795 pushContext(context);
1796 pushContext(CREATE_BIDING_VARIABLES);
1797 break;
1798 case CREATE_BIDING_OBJECT:
1799 insertSymbol(value);
1800 popContext();
1801 popContext();
1802 pushContext(END_BIDING);
1803 break;
1804 case CREATE_ATTRIBUT_PAIRS:
1805 case CREATE_ERROR:
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816 pushContext(context);
1817 pushContext(WAIT_FOR_OBJECT);
1818 break;
1819 case WAIT_FOR_END_OBJECT:
1820 throwOME("Malformed object. End of object expected", OMException.OME_NODE_NOT_FOUND);
1821 case CREATE_ATTRIBUTION:
1822 throwOME("Malformed object. <OMATP> expected", OMException.OME_NODE_NOT_FOUND);
1823 case END_ATTRIBUT_PAIRS:
1824 throwOME("Malformed object. Either </OMATP> or <OMS ...> expected", OMException.OME_NODE_NOT_FOUND);
1825 case END_ATTRIBUTION:
1826 throwOME("Malformed object. </OMATTR> expected", OMException.OME_NODE_NOT_FOUND);
1827 case CREATE_BIDING_VARIABLES:
1828 throwOME("Malformed object. <OMBVAR> expected", OMException.OME_NODE_NOT_FOUND);
1829 case WAIT_FOR_VARIABLES:
1830 throwOME("Malformed object. Variables expected", OMException.OME_SYNTAX);
1831 case END_BIDING:
1832 throwOME("Malformed object. </OMBIND> expected", OMException.OME_NODE_NOT_FOUND);
1833 }
1834 }
1835 else
1836 throwOME("Malformed object. Something wrong occured");
1837 }
1838
1839 /***
1840 * Receives notification of a comment element.
1841 *
1842 * <p>By default, do nothing. Application writers may override this
1843 * method in a subclass.</p>
1844 *
1845 * @param value the value embeded in this Comment element.
1846 * @exception fr.inria.openmath.omapi.OMException Any OpenMath exception.
1847 * @see Comment
1848 */
1849 public void readComment(String value) throws OMException {}
1850
1851 /***
1852 * Inserts the specified symbol.
1853 * @param symbol the specified symbol
1854 */
1855 private void insertSymbol(Symbol symbol) {
1856 compounded.append("<OMS cd=\"" + symbol.getCD() + "\" name=\"" + symbol.getName() + "\"/>");
1857 }
1858
1859 /***
1860 * Insert the specified variable in the OpenMath object.<BR>
1861 * It first checks if the variable identifies an element to compound. If so, the
1862 * correspondind OpenMath object is inserted. Otherwise, the variable is inserted
1863 * @param name the name of the variable.
1864 */
1865 private void insertVariable(String name) {
1866 OpenMathizable omizable = (OpenMathizable) elements.get(name);
1867 if (omizable == null)
1868 compounded.append("<OMV name = \"" + name + "\"/>");
1869 else {
1870 name = omizable.getOpenMath();
1871 if ((name != null) && (name.startsWith("<OMOBJ>"))) {
1872 name = name.substring(7, name.length() - 9);
1873 compounded.append(name);
1874 }
1875 else
1876 compounded.append("<OMV name = \"" + name + "\"/>");
1877 }
1878 }
1879
1880 /***
1881 * Inserts the specified integer value.
1882 * @param value the specified integer.
1883 */
1884 private void insertInteger(BigInt value) {
1885 compounded.append("<OMI>");
1886 compounded.append((value.getSign() != 1) ? "-" : "");
1887 compounded.append(value.getDigits());
1888 compounded.append("</OMI>");
1889 }
1890
1891 /***
1892 * Inserts the specified float value.
1893 * @param value the specified float.
1894 */
1895 private void insertFloat(double value) {
1896 compounded.append("<OMF dec=\"" + value + "\"/>");
1897 }
1898
1899 private void TraceContext(String methodName) {
1900 System.out.println("\n\t\t <--");
1901 System.out.println("\t\t On entre dans la methode " + methodName);
1902 String str = (stackSymbol.empty() == true) ? "null" : ((Symbol) stackSymbol.peek()).toString();
1903 System.out.println("\t\t La valeur courante est " + str);
1904 str = (stackSymbolOperands.empty() == true) ? "null" : ""+((Byte) stackSymbolOperands.peek()).byteValue();
1905 System.out.println("\t\t Le nbre d'operandes est " + str );
1906 System.out.println("\t\t -->");
1907 }
1908 }
1909