1 package com.wutka.dtd;
2
3 import java.io.*;
4
5 /*** Represents the various cardinality values for a DTD item.
6 * <bl>
7 * <li>NONE indicates no cardinality</li>
8 * <li>OPTIONAL indicates an optional value (specified by ?)</li>
9 * <li>ZEROMANY indicates zero-to-many values (specified by *)</li>
10 * <li>ONEMANY indicates an one-to-many values (specified by +)</li>
11 * </bl>
12 *
13 * @author Mark Wutka
14 * @version $Revision: 1.16 $ $Date: 2002/07/19 01:20:11 $ by $Author: wutka $
15 */
16 public class DTDCardinal implements DTDOutput
17 {
18 /*** Indicates no cardinality (implies a single object) */
19 public static final DTDCardinal NONE = new DTDCardinal(0, "NONE");
20
21 /*** Indicates that an item is optional (zero-to-one) */
22 public static final DTDCardinal OPTIONAL = new DTDCardinal(1, "OPTIONAL");
23
24 /*** Indicates that there can be zero-to-many occurrances of an item */
25 public static final DTDCardinal ZEROMANY = new DTDCardinal(2, "ZEROMANY");
26
27 /*** Indicates that there can be one-to-many occurrances of an item */
28 public static final DTDCardinal ONEMANY = new DTDCardinal(3, "ONEMANY");
29
30 public int type;
31 public String name;
32
33 public DTDCardinal(int aType, String aName)
34 {
35 type = aType;
36 name = aName;
37 }
38
39 public boolean equals(Object ob)
40 {
41 if (ob == this) return true;
42 if (!(ob instanceof DTDCardinal)) return false;
43
44 DTDCardinal other = (DTDCardinal) ob;
45 if (other.type == type) return true;
46 return false;
47 }
48
49 /*** Writes the notation for this cardinality value */
50 public void write(PrintWriter out)
51 throws IOException
52 {
53 if (this == NONE) return;
54 if (this == OPTIONAL)
55 {
56 out.print("?");
57 }
58 else if (this == ZEROMANY)
59 {
60 out.print("*");
61 }
62 else if (this == ONEMANY)
63 {
64 out.print("+");
65 }
66 }
67 }