Skip to main content
summaryrefslogtreecommitdiffstats
blob: bae83f7a74799b27b47095093cee0ac75c851785 (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
package org.eclipse.jst.jsf.facelet.core.internal.cm;

import java.util.Iterator;

import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
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;

/**
 * A namespace a specific to a document, where it's tag name prefix is known.
 *
 */
class DocumentNamespaceCMAdapter implements CMNamedNodeMap, CMDocument
{
    private final String                    _prefix;
    private final NamespaceCMAdapter        _adapter;
    
    public DocumentNamespaceCMAdapter(final NamespaceCMAdapter adapter, final String prefix)
    {
        _prefix = prefix;
        _adapter = adapter;
    }
    
    public int getLength()
    {
        return _adapter.getLength();
    }

    public CMNode getNamedItem(String name)
    {
        CMNode  node = _adapter.getNamedItem(name);
        
        if (node != null)
        {
            node =  new DocumentElementCMAdapter((ElementCMAdapter) node,_prefix);
        }
        return node;
    }

    public CMNode item(int index)
    {
        CMNode  item = _adapter.item(index);
        
        if (item != null)
        {
            item = new DocumentElementCMAdapter((ElementCMAdapter) item,_prefix);
        }
        return item;
    }

    public Iterator<?> iterator()
    {
        return new WrappingIterator(_adapter.iterator());
    }

    private class WrappingIterator implements Iterator<CMNode>
    {
        private Iterator<?>   _it;
        
        public WrappingIterator(final Iterator<?> it)
        {
            _it = it;
        }
        public boolean hasNext()
        {
            return _it.hasNext();
        }

        public CMNode next()
        {
            CMNode node = (CMNode) _it.next();
            node = getNamedItem(node.getNodeName());
            return node;
        }

        public void remove()
        {
            throw new UnsupportedOperationException(""); //$NON-NLS-1$
        }
    }

    public CMNamedNodeMap getElements()
    {
        return this;
    }

    public CMNamedNodeMap getEntities()
    {
        //not changing entities
        return _adapter.getEntities();
    }

    public CMNamespace getNamespace()
    {
        return new CMNamespaceImpl(_adapter.getNamespace(), _prefix);
    }

    public String getNodeName()
    {
        // not changing node name
        return _adapter.getNodeName();
    }

    public int getNodeType()
    {
        return _adapter.getNodeType();
    }

    public Object getProperty(String propertyName)
    {
        return _adapter.getProperty(propertyName);
    }

    public boolean supports(String propertyName)
    {
        return _adapter.supports(propertyName);
    }

    private static class CMNamespaceImpl implements CMNamespace
    {
        private final CMNamespace   _proxy;
        private final String        _prefix;
        
        CMNamespaceImpl(CMNamespace proxy, final String prefix)
        {
            _proxy = proxy;
            _prefix = prefix;
        }

        public String getPrefix()
        {
            return _prefix;
        }

        public String getURI()
        {
            return _proxy.getURI();
        }

        public String getNodeName()
        {
            return _proxy.getNodeName();
        }

        public int getNodeType()
        {
            return _proxy.getNodeType();
        }

        public Object getProperty(String propertyName)
        {
            return _proxy.getProperty(propertyName);
        }

        public boolean supports(String propertyName)
        {
            return _proxy.supports(propertyName);
        }
    }
}

Back to the top