home *** CD-ROM | disk | FTP | other *** search
/ Online Today 2000 January / Onto0100.iso / pc / JAVA / MSJAVX86.EXE / xmldso.cab / XML4IE3.cab / com / ms / xml / parser / AttDef.class (.txt) next >
Encoding:
Java Class File  |  1997-10-10  |  6.2 KB  |  362 lines

  1. package com.ms.xml.parser;
  2.  
  3. import com.ms.xml.om.Element;
  4. import com.ms.xml.util.Name;
  5. import com.ms.xml.util.XMLOutputStream;
  6. import java.io.IOException;
  7. import java.util.Enumeration;
  8. import java.util.Vector;
  9.  
  10. public class AttDef {
  11.    public static final int CDATA = 0;
  12.    // $FF: renamed from: ID int
  13.    public static final int field_0 = 1;
  14.    public static final int IDREF = 2;
  15.    public static final int IDREFS = 3;
  16.    public static final int ENTITY = 4;
  17.    public static final int ENTITIES = 5;
  18.    public static final int NMTOKEN = 6;
  19.    public static final int NMTOKENS = 7;
  20.    public static final int NOTATION = 8;
  21.    public static final int ENUMERATION = 9;
  22.    public static final int DEFAULT = 0;
  23.    public static final int REQUIRED = 1;
  24.    public static final int IMPLIED = 2;
  25.    public static final int FIXED = 3;
  26.    Name name;
  27.    byte type;
  28.    byte presence;
  29.    Object def;
  30.    Vector values;
  31.  
  32.    private void reportEmpty(Parser var1, String var2) throws ParseException {
  33.       var1.error("Expected " + var1.tokenString(-4, var2) + " insteadof " + var1.tokenString(var1.token, (String)null));
  34.    }
  35.  
  36.    final Object parseAttValue(Element var1, Parser var2, boolean var3) throws ParseException {
  37.       Name var6 = null;
  38.       Object var7;
  39.       switch (this.type) {
  40.          case 0:
  41.             var2.scanString(var2.quote, 38, 38, 60);
  42.             var7 = var2.text;
  43.             if (!var3 && this.presence == 3 && !this.def.toString().equals(var2.text)) {
  44.                this.reportMismatch(var2);
  45.             }
  46.             break;
  47.          case 1:
  48.             ++var2.simplename;
  49.             var2.parseToken(-4, "ID");
  50.             var2.simplename += -1;
  51.             var2.parseToken(39, "string");
  52.             if (!var3) {
  53.                if (this.presence == 3 && (Name)this.def != var2.name) {
  54.                   this.reportMismatch(var2);
  55.                }
  56.  
  57.                Element var9 = var2.dtd.findID(var2.name);
  58.                if (var9 != null) {
  59.                   var2.error("ID " + var6 + " is already used on element " + var9.getTagName());
  60.                }
  61.  
  62.                var2.dtd.addID(var2.name, var1);
  63.             }
  64.  
  65.             var7 = var2.name;
  66.             break;
  67.          case 2:
  68.          case 3:
  69.             Vector var17 = new Vector();
  70.             StringBuffer var19 = new StringBuffer();
  71.             ++var2.simplename;
  72.             int var14 = var2.parseNames(var17, 0, var19);
  73.             var2.simplename += -1;
  74.             if (var14 == 0) {
  75.                this.reportEmpty(var2, "IDREF");
  76.             }
  77.  
  78.             if (var14 > 1 && this.type == 2) {
  79.                var2.error("IDREF type attribute \"" + this.name + "\" cannot refer to more than one ID.");
  80.             }
  81.  
  82.             if (!var3) {
  83.                --var14;
  84.  
  85.                for(; var14 >= 0; --var14) {
  86.                   var6 = (Name)var17.elementAt(var14);
  87.                   if (this.presence == 3) {
  88.                      if (this.type == 3) {
  89.                         this.checkFixed(var6, var2);
  90.                      } else if ((Name)this.def != var6) {
  91.                         this.reportMismatch(var2);
  92.                      }
  93.                   }
  94.  
  95.                   if (var2.dtd.findID(var6) == null) {
  96.                      var2.dtd.addIDCheck(var6, var2.reader.line, var2.reader.column - 1, var2.reader.owner);
  97.                   }
  98.                }
  99.             }
  100.  
  101.             var7 = this.type == 2 ? var6 : var17;
  102.             break;
  103.          case 4:
  104.          case 5:
  105.             StringBuffer var18 = new StringBuffer();
  106.             Vector var16 = new Vector();
  107.             ++var2.nouppercase;
  108.             int var12 = var2.parseNames(var16, 0, var18);
  109.             var2.nouppercase += -1;
  110.             if (var12 == 0) {
  111.                this.reportEmpty(var2, "ENTITY name");
  112.             }
  113.  
  114.             if (var12 > 1 && this.type == 4) {
  115.                var2.error("ENTITY type attribute \"" + this.name + "\" cannot refer to more than one entity.");
  116.             }
  117.  
  118.             --var12;
  119.  
  120.             for(; var12 >= 0; --var12) {
  121.                var6 = (Name)var16.elementAt(var12);
  122.                if (var2.dtd.findEntity(var6) == null) {
  123.                   var2.error("Couldn't find entity '" + var6 + "'");
  124.                }
  125.  
  126.                if (!var3 && this.presence == 3) {
  127.                   if (this.type == 5) {
  128.                      this.checkFixed(var6, var2);
  129.                   } else if (var6 != (Name)this.def) {
  130.                      this.reportMismatch(var2);
  131.                   }
  132.                }
  133.             }
  134.  
  135.             var7 = this.type == 4 ? var6 : var16;
  136.             break;
  137.          case 6:
  138.          case 7:
  139.             StringBuffer var8 = new StringBuffer();
  140.             Vector var5 = new Vector();
  141.             ++var2.nametoken;
  142.             int var10 = var2.parseNames(var5, 0, var8);
  143.             var2.nametoken += -1;
  144.             if (var10 == 0) {
  145.                this.reportEmpty(var2, "NMTOKEN");
  146.             }
  147.  
  148.             if (var10 > 1 && this.type == 6) {
  149.                var2.error("NMTOKEN type attribute \"" + this.name + "\" cannot refer to more than one name token.");
  150.             }
  151.  
  152.             if (!var3 && this.presence == 3) {
  153.                if (this.type == 6) {
  154.                   if ((Name)this.def != (Name)var5.elementAt(0)) {
  155.                      this.reportMismatch(var2);
  156.                   }
  157.                } else {
  158.                   for(int var11 = this.values.size() - 1; var11 >= 0; --var11) {
  159.                      this.checkFixed((Name)this.values.elementAt(var11), var2);
  160.                   }
  161.                }
  162.             }
  163.  
  164.             var7 = this.type == 6 ? var5.elementAt(0) : var5;
  165.             break;
  166.          case 8:
  167.          case 9:
  168.             if (this.type == 9) {
  169.                ++var2.nametoken;
  170.             }
  171.  
  172.             var2.parseToken(-4, "name");
  173.             if (this.type == 9) {
  174.                var2.nametoken += -1;
  175.             }
  176.  
  177.             var2.parseToken(39, "string");
  178.  
  179.             int var4;
  180.             for(var4 = this.values.size() - 1; var4 >= 0 && (Name)this.values.elementAt(var4) != var2.name; --var4) {
  181.             }
  182.  
  183.             if (var4 < 0) {
  184.                var2.error("Attribute value '" + var2.name + "' is  not in the allowed set.");
  185.             }
  186.  
  187.             if (!var3 && this.presence == 3 && var2.name != this.def) {
  188.                this.reportMismatch(var2);
  189.             }
  190.  
  191.             var7 = var2.name;
  192.             break;
  193.          default:
  194.             var7 = null;
  195.       }
  196.  
  197.       return var7;
  198.    }
  199.  
  200.    private void reportMismatch(Parser var1) throws ParseException {
  201.       var1.error("Attribute " + this.name + " should have the fixed value \"" + this.def + "\"");
  202.    }
  203.  
  204.    private void checkFixed(Name var1, Parser var2) throws ParseException {
  205.       Vector var3 = (Vector)this.def;
  206.  
  207.       int var4;
  208.       for(var4 = var3.size() - 1; var4 >= 0 && (Name)var3.elementAt(var4) != var1; --var4) {
  209.       }
  210.  
  211.       if (var4 < 0) {
  212.          var2.error("Attribue value " + var1 + " is not in the fixed value set.");
  213.       }
  214.  
  215.    }
  216.  
  217.    void save(Name var1, XMLOutputStream var2) throws IOException {
  218.       var2.writeQualifiedName(this.name, var1);
  219.       switch (this.type) {
  220.          case 0:
  221.             var2.writeChars(" CDATA");
  222.             break;
  223.          case 1:
  224.             var2.writeChars(" ID");
  225.             break;
  226.          case 2:
  227.             var2.writeChars(" IDREF");
  228.             break;
  229.          case 3:
  230.             var2.writeChars(" IDREFS");
  231.             break;
  232.          case 4:
  233.             var2.writeChars(" ENTITY");
  234.             break;
  235.          case 5:
  236.             var2.writeChars(" ENTITIES");
  237.             break;
  238.          case 6:
  239.             var2.writeChars(" NMTOKEN");
  240.             break;
  241.          case 7:
  242.             var2.writeChars(" NMTOKENS");
  243.             break;
  244.          case 8:
  245.             var2.writeChars(" NOTATION");
  246.          case 9:
  247.             var2.writeChars(" (");
  248.  
  249.             for(int var3 = 0; var3 < this.values.size(); ++var3) {
  250.                Name var4 = (Name)this.values.elementAt(var3);
  251.                if (this.type == 8) {
  252.                   var2.writeQualifiedName(var4, var1);
  253.                } else {
  254.                   var2.writeChars(var4.toString());
  255.                }
  256.  
  257.                if (var3 < this.values.size() - 1) {
  258.                   var2.write(124);
  259.                }
  260.             }
  261.  
  262.             var2.write(41);
  263.       }
  264.  
  265.       switch (this.presence) {
  266.          case 0:
  267.          case 3:
  268.             if (this.presence == 3) {
  269.                var2.writeChars(" #FIXED");
  270.             }
  271.  
  272.             if (this.def != null) {
  273.                var2.writeChars(" ");
  274.                switch (this.type) {
  275.                   case 0:
  276.                   case 1:
  277.                   case 2:
  278.                   case 6:
  279.                   case 9:
  280.                      var2.writeQuotedString(this.def.toString());
  281.                      return;
  282.                   case 3:
  283.                   case 5:
  284.                   case 7:
  285.                      var2.write(34);
  286.                      int var5 = 0;
  287.                      Enumeration var6 = ((Vector)this.def).elements();
  288.  
  289.                      while(var6.hasMoreElements()) {
  290.                         if (var5++ > 0) {
  291.                            var2.write(124);
  292.                         }
  293.  
  294.                         if (this.type == 5) {
  295.                            var2.writeQualifiedName((Name)var6.nextElement(), var1);
  296.                         } else {
  297.                            var2.writeChars(var6.nextElement().toString());
  298.                         }
  299.                      }
  300.  
  301.                      var2.write(34);
  302.                      return;
  303.                   case 4:
  304.                   case 8:
  305.                      var2.write(34);
  306.                      var2.writeQualifiedName((Name)this.def, var1);
  307.                      var2.write(34);
  308.                      return;
  309.                }
  310.             }
  311.          default:
  312.             return;
  313.          case 1:
  314.             var2.writeChars(" #REQUIRED");
  315.             return;
  316.          case 2:
  317.             var2.writeChars(" #IMPLIED");
  318.       }
  319.    }
  320.  
  321.    public Object getDefault() {
  322.       return this.def;
  323.    }
  324.  
  325.    public Name getName() {
  326.       return this.name;
  327.    }
  328.  
  329.    public int getType() {
  330.       return this.type;
  331.    }
  332.  
  333.    public int getPresence() {
  334.       return this.presence;
  335.    }
  336.  
  337.    final Object parseAttribute(Element var1, Parser var2) throws ParseException {
  338.       var2.parseToken(39, "string");
  339.       return this.parseAttValue(var1, var2, false);
  340.    }
  341.  
  342.    AttDef(Name var1, int var2) {
  343.       this(var1, var2, (Object)null, 0, (Vector)null);
  344.    }
  345.  
  346.    AttDef(Name var1, int var2, Vector var3) {
  347.       this(var1, var2, (Object)null, 0, var3);
  348.    }
  349.  
  350.    AttDef(Name var1, int var2, Object var3, int var4) {
  351.       this(var1, var2, var3, var4, (Vector)null);
  352.    }
  353.  
  354.    AttDef(Name var1, int var2, Object var3, int var4, Vector var5) {
  355.       this.name = var1;
  356.       this.type = (byte)var2;
  357.       this.def = var3;
  358.       this.presence = (byte)var4;
  359.       this.values = var5;
  360.    }
  361. }
  362.