Skip to main content
summaryrefslogtreecommitdiffstats
blob: a86ddfbf180334de03d236d942286ff2ca945e6d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*******************************************************************************
 * Copyright (c) 2001, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.wst.dtd.core.internal.saxparser;

import java.util.Enumeration;
import java.util.Vector;

public final class AttNode {
	//
	// attType
	//
	public static final int CDATA = 0, ID = 1, IDREF = 2, IDREFS = 3, ENTITY = 4, ENTITIES = 5, NMTOKEN = 6, NMTOKENS = 7, NOTATION = 8, ENUMERATION = 9, PEREFERENCE = 10;

	//
	// Keep this array in-sync with the ATTTYPE definitions
	//
	private static final String[] fgAttTypeString = {"CDATA", // 0 //$NON-NLS-1$
				"ID", // 1 //$NON-NLS-1$
				"IDREF", // 2 //$NON-NLS-1$
				"IDREFS", // 3 //$NON-NLS-1$
				"ENTITY", // 4 //$NON-NLS-1$
				"ENTITIES", // 5 //$NON-NLS-1$
				"NMTOKEN", // 6 //$NON-NLS-1$
				"NMTOKENS", // 7 //$NON-NLS-1$
				"NOTATION", // 8 //$NON-NLS-1$
				"ENUMERATION", // 9 (replaced with "NMTOKEN" by SAX //$NON-NLS-1$
								// AttributeList handler)
				"%ENTITYREFERENCE;"}; //$NON-NLS-1$

	//
	// attDefaultType
	//
	public static final int NOFIXED = 1, // AttValue
				REQUIRED = 2, // #REQUIRED
				IMPLIED = 3, // #IMPLIED
				FIXED = 4; // #FIXED AttValue

	public String name = null;
	public String type = null;
	public String defaultType = null;
	public String defaultValue = null;
	public Vector enumList = null; // list of Notations or Enum values

	public int getDeclaredType() {
		int t = -1;
		if (type == null)
			return t;

		if (type.startsWith("%") && type.endsWith(";")) //$NON-NLS-1$ //$NON-NLS-2$
			return PEREFERENCE;

		for (int i = 0; i < fgAttTypeString.length; i++) {
			if (type.equals(fgAttTypeString[i])) {
				t = i;
				break;
			}
		}
		return t;
	}

	public Enumeration elements() {
		if (enumList == null)
			enumList = new Vector();
		return enumList.elements();
	}

	public int getDefaultType() {
		if (defaultType == null)
			return -1;

		if (defaultType.startsWith("%") && defaultType.endsWith(";")) //$NON-NLS-1$ //$NON-NLS-2$
			return PEREFERENCE;
		else if (defaultType.equals("#REQUIRED")) //$NON-NLS-1$
			return REQUIRED;
		else if (defaultType.equals("#IMPLIED")) //$NON-NLS-1$
			return IMPLIED;
		else if (defaultType.equals("#FIXED")) //$NON-NLS-1$
			return FIXED;
		else
			return NOFIXED;
	}

	public String toString() {
		return "Att Name: " + name + " Type: " + type + " defaultType: " + defaultType + " defaultValue: " + defaultValue; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
	}
}

Back to the top