Skip to main content
summaryrefslogtreecommitdiffstats
blob: b330f9249405fe3423bfa92d0ebce637f23426f6 (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*******************************************************************************
 * Copyright (c) 2004, 2005 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.jst.jsp.core.internal.contentmodel;



import java.util.Hashtable;
import java.util.Iterator;

import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
import org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNamespace;
import org.eclipse.wst.xml.core.internal.contentmodel.CMNode;
import org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper;

public class CMDocumentWrapperImpl implements CMDocument, CMNodeWrapper {

	class CMNamedNodeMapImpl implements CMNamedNodeMap {

		protected Hashtable table = new Hashtable();

		public CMNamedNodeMapImpl() {
			super();
		}

		Hashtable getHashtable() {
			return table;
		}

		public int getLength() {
			return table.size();
		}

		public CMNode getNamedItem(String name) {
			return (CMNode) table.get(name);
		}

		public CMNode item(int index) {
			Object result = null;
			int size = table.size();
			if (index < size) {
				Iterator values = iterator();
				for (int i = 0; i <= index; i++) {
					result = values.next();
				}
			}
			return (CMNode) result;
		}

		public Iterator iterator() {
			return table.values().iterator();
		}

		public void setNamedItem(String name, CMNode aNode) {
			if (name != null && aNode != null)
				table.put(name, aNode);
		}
	}

	public class CMNamespaceImpl implements CMNamespace {
		public String getNodeName() {
			return CMDocumentWrapperImpl.this.getURI();
		}

		public int getNodeType() {
			return CMNode.NAME_SPACE;
		}

		public String getPrefix() {
			return CMDocumentWrapperImpl.this.getPrefix();
		}

		public Object getProperty(String property) {
			return null;
		}

		public String getURI() {
			return CMDocumentWrapperImpl.this.getURI();
		}

		public boolean supports(String feature) {
			return false;
		}
	}

	private CMDocument fDocument;
	private CMNamedNodeMap fElements = null;
	private CMNamedNodeMap fEntities = null;
	private CMNamespace fNamespace = new CMNamespaceImpl();
	private String fPrefix;
	private String fURI;

	public CMDocumentWrapperImpl(String newURI, String newPrefix, CMDocument tld) {
		fURI = newURI;
		fPrefix = newPrefix;
		fDocument = tld;
	}

	/**
	 * 
	 * @return org.eclipse.wst.xml.core.internal.contentmodel.CMDocument
	 */
	public CMDocument getDocument() {
		return fDocument;
	}

	/**
	 * getElements method
	 * @return CMNamedNodeMap
	 *
	 * Returns CMNamedNodeMap of ElementDeclaration
	 */
	public CMNamedNodeMap getElements() {
		if (fElements == null) {
			int length = getDocument().getElements().getLength();
			CMNamedNodeMapImpl elements = new CMNamedNodeMapImpl();
			for (int i = 0; i < length; i++) {
				CMElementDeclaration ed = new CMElementDeclarationWrapperImpl(fPrefix, (CMElementDeclaration) getDocument().getElements().item(i));
				elements.setNamedItem(ed.getNodeName(), ed);
			}
			fElements = elements;
		}
		return fElements;
	}

	/**
	 * getEntities method
	 * @return CMNamedNodeMap
	 *
	 * Returns CMNamedNodeMap of EntityDeclaration
	 */
	public CMNamedNodeMap getEntities() {
		if (fEntities == null) {
			fEntities = getDocument().getEntities();
		}
		return fEntities;
	}

	/**
	 * getNamespace method
	 * @return CMNamespace
	 */
	public CMNamespace getNamespace() {
		return fNamespace;
	}

	/**
	 * getNodeName method
	 * @return java.lang.String
	 */
	public String getNodeName() {
		return getDocument().getNodeName();
	}

	/**
	 * getNodeType method
	 * @return int
	 *
	 * Returns one of :
	 *
	 */
	public int getNodeType() {
		return getDocument().getNodeType();
	}

	public CMNode getOriginNode() {
		return fDocument;
	}

	/**
	 * 
	 * @return java.lang.String
	 */
	public String getPrefix() {
		return fPrefix;
	}

	/**
	 * getProperty method
	 * @return java.lang.Object
	 *
	 * Returns the object property desciped by the propertyName
	 *
	 */
	public Object getProperty(String propertyName) {
		return getDocument().getProperty(propertyName);
	}

	/**
	 * 
	 * @return java.lang.String
	 */
	public String getURI() {
		return fURI;
	}

	/**
	 * supports method
	 * @return boolean
	 *
	 * Returns true if the CMNode supports a specified property
	 *
	 */
	public boolean supports(String propertyName) {
		return getDocument().supports(propertyName);
	}
}

Back to the top