Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 0330abcd68b711df3ae38112280e523d924335e6 (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
/*
* Copyright (c) 2002 IBM Corporation and others.
* All rights reserved.   This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
* 
* Contributors:
*   IBM - Initial API and implementation
*   Jens Lukowski/Innoopract - initial renaming/restructuring
* 
*/
package org.eclipse.wst.sse.core.contentmodel;

import java.util.Iterator;
import java.util.NoSuchElementException;

import org.eclipse.wst.contentmodel.CMDocument;
import org.eclipse.wst.contentmodel.CMNamedNodeMap;
import org.eclipse.wst.contentmodel.CMNamespace;
import org.eclipse.wst.contentmodel.CMNode;

/**
 * This class can be used to intialize specific 
 * variables that need a content model, until the 
 * true content model is available. This prevents 
 * having to do lots of null checks.
 */
public class NullContentModel implements CMDocument {

	private class NullCMNamedNodeMap implements CMNamedNodeMap {
		public int getLength() {
			return 0;
		}

		public CMNode getNamedItem(String name) {
			return null;
		}

		public CMNode item(int index) {
			return null;
		}

		public Iterator iterator() {
			return new NullIterator();
		}

	}

	private class NullIterator implements Iterator {
		public NullIterator() {
		}

		public boolean hasNext() {
			return false;
		}

		public Object next() {
			throw new NoSuchElementException();
		}

		public void remove() {
			throw new UnsupportedOperationException("can not remove regions via iterator"); //$NON-NLS-1$

		}

	}

	public NullContentModel() {
		super();
	}

	public CMNamedNodeMap getElements() {
		return new NullCMNamedNodeMap();
	}

	public CMNamedNodeMap getEntities() {
		return new NullCMNamedNodeMap();
	}

	public CMNamespace getNamespace() {
		return null;
	}

	public String getNodeName() {
		return null;
	}

	public int getNodeType() {
		return 0;
	}

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

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

}

Back to the top