[BACK]Return to CMO_TREE.java CVS log [TXT][DIR] Up to [local] / OpenXM / src / OpenMath / ORG / openxm / tam

File: [local] / OpenXM / src / OpenMath / ORG / openxm / tam / CMO_TREE.java (download)

Revision 1.3, Sun Dec 3 12:40:40 2000 UTC (23 years, 7 months ago) by ohara
Branch: MAIN
CVS Tags: R_1_3_1-2, RELEASE_1_3_1_13b, RELEASE_1_2_3_12, RELEASE_1_2_3, RELEASE_1_2_2_KNOPPIX_b, RELEASE_1_2_2_KNOPPIX, RELEASE_1_2_2, RELEASE_1_2_1, KNOPPIX_2006, HEAD, DEB_REL_1_2_3-9
Changes since 1.2: +6 -1 lines

allowQ() methods are added.

In order to prevent a MathcapViolation,
we must inspect a CMObject by allowQ() before sending it to OXstream.

/**
 * $OpenXM: OpenXM/src/OpenMath/ORG/openxm/tam/CMO_TREE.java,v 1.3 2000/12/03 12:40:40 ohara Exp $
 */
package ORG.openxm.tam;

import java.io.*;

/**
 * CMO $B7A<0$N(B TREE $B7?$rI=$7$^$9(B.
 * $B$3$l$O(B OpenMath $B$N(B Content Dictionary $B$GDj5A$5$l$F$$$k%*%V%8%'%/%H$r(B
 * $BI=$9%/%i%9$G$9(B.
 */
final public class CMO_TREE extends CMO{
  private String name,cdname;
  private CMO_LIST leaves;

  /**
   * leaves $B$rMWAG$H$7(B cdname $B$GDj5A$5$l$F$$$k(B name $B$rI=$9(B TREE $B$r:n@.$7$^$9(B.
   * $B%;%^%s%F%#%C%/%9$O%A%'%C%/$5$l$^$;$s(B.
   */
  public CMO_TREE(String name,String cdname,CMO_LIST leaves){
    this.name = name;
    this.cdname = cdname;
    this.leaves = leaves;
  }

  /**
   * $BL>A0$rF@$^$9(B.
   */
  public String getName(){
    return name;
  }

  /**
   * $BL>A0$,Dj5A$5$l$F$$$k(B CD $B$NL>A0$rF@$^$9(B.
   */
  public String getCDName(){
    return cdname;
  }

  /**
   * $BMWAG$rF@$^$9(B.
   */
  public CMO_LIST getLeaves(){
    return leaves;
  }

  public int DISCRIMINATOR(){
    return CMO.TREE;
  }

    public boolean allowQ (int[] datacap) {
		return CMO.allowQ_tag(datacap, DISCRIMINATOR()) 
			&& leaves.allowQ(datacap);
    }

  public void sendByObject(OpenXMstream os)
       throws IOException,MathcapViolation{
    new CMO_STRING(name).write(os);
    new CMO_STRING(cdname).write(os);
    leaves.write(os);
  }

  static protected CMO receive(OpenXMstream is) throws IOException{
    String name,cdname;
    CMO_LIST leaves;
    CMO tmp;

    tmp = CMO.receive(is);
    if(!(tmp instanceof CMO_STRING)){
      System.err.println("not CMOobject");
    }
    name = ((CMO_STRING)tmp).getString();

    tmp = CMO.receive(is);
    if(!(tmp instanceof CMO_STRING)){
      System.err.println("not CMOobject");
    }
    cdname = ((CMO_STRING)tmp).getString();

    tmp = CMO.receive(is);
    if(!(tmp instanceof CMO_LIST)){
      System.err.println("not CMOobject");
    }
    leaves = (CMO_LIST)tmp;

    return new CMO_TREE(name,cdname,leaves);
  }

  public String toCMOexpressionByObject(){
    return "CMO_TREE,"+ name +","+ cdname +","+ leaves.toCMOexpression();
  }
}