View Javadoc

1   /*   Copyright 2004 BEA Systems, Inc.
2    *
3    *   Licensed under the Apache License, Version 2.0 (the "License");
4    *   you may not use this file except in compliance with the License.
5    *   You may obtain a copy of the License at
6    *
7    *       http://www.apache.org/licenses/LICENSE-2.0
8    *
9    *   Unless required by applicable law or agreed to in writing, software
10   *   distributed under the License is distributed on an "AS IS" BASIS,
11   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   *   See the License for the specific language governing permissions and
13   *   limitations under the License.
14   */
15  
16  package com.bea.xml.stream.events;
17  
18  import com.bea.xml.stream.util.EmptyIterator;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  import java.util.Iterator;
23  
24  import javax.xml.namespace.QName;
25  import javax.xml.stream.events.Attribute;
26  import javax.xml.stream.events.Namespace;
27  import javax.xml.stream.events.XMLEvent;
28  import javax.xml.stream.events.EndElement;
29  
30  public class EndElementEvent 
31    extends NamedEvent 
32    implements EndElement 
33  {
34    private List outOfScopeNamespaces;
35  
36    public EndElementEvent() {
37      super();
38      init();
39    }
40    protected void init() { 
41      setEventType(XMLEvent.END_ELEMENT); 
42    } 
43    public EndElementEvent(QName name) { 
44      super(name);
45      init();
46    }
47    public Iterator getNamespaces() {
48      if (outOfScopeNamespaces==null)
49        return EmptyIterator.emptyIterator;
50      return outOfScopeNamespaces.iterator();
51    }
52    public void addNamespace(Namespace n) {
53      if (outOfScopeNamespaces == null) 
54        outOfScopeNamespaces = new ArrayList();
55      outOfScopeNamespaces.add(n);
56    }
57    public void reset() {
58      if (outOfScopeNamespaces != null) outOfScopeNamespaces.clear();
59  
60    }
61  
62    public String toString() { 
63      String value = "</"+nameAsString();
64      Iterator ni = getNamespaces();
65      while(ni.hasNext())
66        value = value +" "+ ni.next().toString();
67      value = value+">";
68      return value;
69    }
70  }
71