jaxp/src/share/classes/com/sun/xml/internal/stream/events/XMLEventAllocatorImpl.java
author tbell
Mon, 20 Apr 2009 22:50:16 -0700
changeset 2669 15024792697e
parent 6 7f561c08de6b
child 3294 8943b2e74175
permissions -rw-r--r--
6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7 6573268: Four JCK-devtools-6a tests report OOM: Java Heap space since JDK7 b14 Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
 * have any questions.
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
package com.sun.xml.internal.stream.events;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
2669
15024792697e 6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents: 6
diff changeset
    28
import com.sun.org.apache.xerces.internal.impl.PropertyManager;
15024792697e 6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents: 6
diff changeset
    29
import java.util.List;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import javax.xml.stream.util.XMLEventAllocator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import javax.xml.stream.*;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import javax.xml.stream.events.*;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import javax.xml.XMLConstants;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import javax.xml.namespace.QName;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
import com.sun.org.apache.xerces.internal.util.NamespaceContextWrapper;
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
import com.sun.org.apache.xerces.internal.util.NamespaceSupport;
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 * Implementation of XMLEvent Allocator.
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 * @author Neeraj.bajaj@sun.com, k.venugopal@sun.com
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
public class XMLEventAllocatorImpl implements XMLEventAllocator {
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
    /** Creates a new instance of XMLEventAllocator */
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
    public XMLEventAllocatorImpl() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
    public javax.xml.stream.events.XMLEvent allocate(javax.xml.stream.XMLStreamReader xMLStreamReader) throws javax.xml.stream.XMLStreamException {
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
        if(xMLStreamReader == null )
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
            throw new XMLStreamException("Reader cannot be null");
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
        //        allocate is not supposed to change the state of the reader so we shouldn't be calling next.
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
        //        return getNextEvent(xMLStreamReader);
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
        return getXMLEvent(xMLStreamReader);
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
    public void allocate(javax.xml.stream.XMLStreamReader xMLStreamReader, javax.xml.stream.util.XMLEventConsumer xMLEventConsumer) throws javax.xml.stream.XMLStreamException {
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
        XMLEvent currentEvent = getXMLEvent(xMLStreamReader);
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
        if(currentEvent != null )
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
            xMLEventConsumer.add(currentEvent);
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
        return;
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
    public javax.xml.stream.util.XMLEventAllocator newInstance() {
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
        return new XMLEventAllocatorImpl();
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
    //REVISIT: shouldn't we be using XMLEventFactory to create events.
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
    XMLEvent getXMLEvent(XMLStreamReader streamReader){
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
        XMLEvent event = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
        //returns the current event
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
        int eventType = streamReader.getEventType();
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
        switch(eventType){
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
            case XMLEvent.START_ELEMENT:{
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
                StartElementEvent startElementEvent = new StartElementEvent(getQName(streamReader));
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
                fillAttributes(startElementEvent,streamReader);
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
                //we might have different XMLStreamReader so check every time for the namespace aware property
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
                //we should be setting namespace related values only when isNamespaceAware is 'true'
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
                if( ((Boolean)streamReader.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE)).booleanValue() ){
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
                    fillNamespaceAttributes(startElementEvent, streamReader);
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
                    setNamespaceContext(startElementEvent,streamReader);
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
                startElementEvent.setLocation(streamReader.getLocation());
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
                event = startElementEvent ;
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
            case XMLEvent.END_ELEMENT:{
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
                EndElementEvent endElementEvent = new EndElementEvent(getQName(streamReader));
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
                endElementEvent.setLocation(streamReader.getLocation());
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
                if( ((Boolean)streamReader.getProperty(XMLInputFactory.IS_NAMESPACE_AWARE)).booleanValue() ){
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
                    fillNamespaceAttributes(endElementEvent,streamReader);
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
                event = endElementEvent ;
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
            case XMLEvent.PROCESSING_INSTRUCTION:{
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
                ProcessingInstructionEvent piEvent = new ProcessingInstructionEvent(streamReader.getPITarget(),streamReader.getPIData());
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
                piEvent.setLocation(streamReader.getLocation());
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
                event = piEvent ;
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
            case XMLEvent.CHARACTERS:{
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
                CharacterEvent cDataEvent = new CharacterEvent(streamReader.getText());
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
                cDataEvent.setLocation(streamReader.getLocation());
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
                event = cDataEvent ;
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
            case XMLEvent.COMMENT:{
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
                CommentEvent commentEvent = new CommentEvent(streamReader.getText());
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
                commentEvent.setLocation(streamReader.getLocation());
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
                event = commentEvent ;
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
            case XMLEvent.START_DOCUMENT:{
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
                StartDocumentEvent sdEvent = new StartDocumentEvent();
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
                sdEvent.setVersion(streamReader.getVersion());
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
                sdEvent.setEncoding(streamReader.getEncoding());
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
                if(streamReader.getCharacterEncodingScheme() != null){
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
                    sdEvent.setDeclaredEncoding(true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
                }else{
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
                    sdEvent.setDeclaredEncoding(false);
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
                }
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
                sdEvent.setStandalone(streamReader.isStandalone());
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
                sdEvent.setLocation(streamReader.getLocation());
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
                event = sdEvent ;
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
            case XMLEvent.END_DOCUMENT:{
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
                EndDocumentEvent endDocumentEvent = new EndDocumentEvent() ;
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
                endDocumentEvent.setLocation(streamReader.getLocation());
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
                event = endDocumentEvent ;
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
            case XMLEvent.ENTITY_REFERENCE:{
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
                EntityReferenceEvent entityEvent =  new EntityReferenceEvent(streamReader.getLocalName(), new EntityDeclarationImpl(streamReader.getLocalName(),streamReader.getText()));
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
                entityEvent.setLocation(streamReader.getLocation());
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
                event = entityEvent;
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
            case XMLEvent.ATTRIBUTE:{
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
                event = null ;
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
            case XMLEvent.DTD:{
2669
15024792697e 6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents: 6
diff changeset
   149
                DTDEvent dtdEvent = new DTDEvent(streamReader.getText());
15024792697e 6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents: 6
diff changeset
   150
                dtdEvent.setLocation(streamReader.getLocation());
15024792697e 6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents: 6
diff changeset
   151
                List entities = (List)streamReader.getProperty(PropertyManager.STAX_ENTITIES);
15024792697e 6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents: 6
diff changeset
   152
                if (entities != null && entities.size() != 0) dtdEvent.setEntities(entities);
15024792697e 6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents: 6
diff changeset
   153
                List notations = (List)streamReader.getProperty(PropertyManager.STAX_NOTATIONS);
15024792697e 6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents: 6
diff changeset
   154
                if (notations != null && notations.size() != 0) dtdEvent.setNotations(notations);
15024792697e 6738894: Merge jaxp fixes from 6 update train into OpenJDK 6 and 7
tbell
parents: 6
diff changeset
   155
                event = dtdEvent;
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
            case XMLEvent.CDATA:{
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
                CharacterEvent cDataEvent = new CharacterEvent(streamReader.getText(),true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
                cDataEvent.setLocation(streamReader.getLocation());
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
                event = cDataEvent ;
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
            case XMLEvent.SPACE:{
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
                CharacterEvent spaceEvent = new CharacterEvent(streamReader.getText(),false,true);
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
                spaceEvent.setLocation(streamReader.getLocation());
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
                event = spaceEvent ;
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
                break;
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
        return event ;
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
    //this function is not used..
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
    protected XMLEvent getNextEvent(XMLStreamReader streamReader) throws XMLStreamException{
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
        //advance the reader to next event.
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
        streamReader.next();
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
        return getXMLEvent(streamReader);
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
    protected void fillAttributes(StartElementEvent event,XMLStreamReader xmlr){
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
        int len = xmlr.getAttributeCount();
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
        QName qname = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
        AttributeImpl attr = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
        NamespaceImpl nattr = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
        for(int i=0; i<len ;i++){
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
            qname = xmlr.getAttributeName(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
            //this method doesn't include namespace declarations
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
            //so we can be sure that there wont be any namespace declaration as part of this function call
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
            //we can avoid this check - nb.
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
            /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
             * prefix = qname.getPrefix();
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
             * localpart = qname.getLocalPart();
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
             * if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE) ) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
             * attr = new NamespaceImpl(localpart,xmlr.getAttributeValue(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
             * }else if (prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)){
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
             * attr = new NamespaceImpl(xmlr.getAttributeValue(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
             * }else{
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
             * attr = new AttributeImpl();
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
             * attr.setName(qname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
             * }
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
             **/
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
            attr = new AttributeImpl();
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
            attr.setName(qname);
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
            attr.setAttributeType(xmlr.getAttributeType(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
            attr.setSpecified(xmlr.isAttributeSpecified(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
            attr.setValue(xmlr.getAttributeValue(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
            event.addAttribute(attr);
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
    protected void fillNamespaceAttributes(StartElementEvent event,XMLStreamReader xmlr){
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
        int count = xmlr.getNamespaceCount();
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
        String uri = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
        String prefix = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
        NamespaceImpl attr = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
        for(int i=0;i< count;i++){
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
            uri = xmlr.getNamespaceURI(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
            prefix = xmlr.getNamespacePrefix(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
            if(prefix == null){
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
                prefix = XMLConstants.DEFAULT_NS_PREFIX;
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
            attr = new NamespaceImpl(prefix,uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
            event.addNamespaceAttribute(attr);
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
    protected void fillNamespaceAttributes(EndElementEvent event,XMLStreamReader xmlr){
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
        int count = xmlr.getNamespaceCount();
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
        String uri = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
        String prefix = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
        NamespaceImpl attr = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
        for(int i=0;i< count;i++){
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
            uri = xmlr.getNamespaceURI(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
            prefix = xmlr.getNamespacePrefix(i);
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
            if(prefix == null){
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
                prefix = XMLConstants.DEFAULT_NS_PREFIX;
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
            }
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
            attr = new NamespaceImpl(prefix,uri);
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
            event.addNamespace(attr);
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
    //Revisit : Creating a new Namespacecontext for now.
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
    //see if we can do better job.
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
    private void setNamespaceContext(StartElementEvent event , XMLStreamReader xmlr){
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
        NamespaceContextWrapper contextWrapper =(NamespaceContextWrapper) xmlr.getNamespaceContext();
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
        NamespaceSupport ns = new NamespaceSupport(contextWrapper.getNamespaceContext());
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
        event.setNamespaceContext(new NamespaceContextWrapper(ns));
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
    private QName getQName(XMLStreamReader xmlr) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
        return new QName(xmlr.getNamespaceURI(), xmlr.getLocalName(),
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
                xmlr.getPrefix());
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
}