john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

XMLElementAttribute

package net.kittyandbear.xml;
//2012-03-18 johnpfeiffer   is xmleventfactory too heavy to keep in memory?

import java.util.Iterator;
import java.util.concurrent.ConcurrentLinkedQueue;

import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.events.Attribute;

public class XMLElementAttribute
{
    private ConcurrentLinkedQueue <Attribute> attributeQueue = null;
    private ConcurrentLinkedQueue <Attribute> namespaceQueue = null;
    XMLEventFactory factory = null;

    XMLElementAttribute( String attributeName , String attributeValue )
    {
        if( attributeName == null )
        {   throw new NullPointerException( "attributeName cannot be null" );
        }
        if( attributeValue == null )
        {   throw new NullPointerException( "attributeValue cannot be null" );
        }
        if( attributeName.isEmpty() )
        {   throw new IllegalArgumentException( "attributeName cannot be empty" );
        }
        if( attributeValue.isEmpty() )
        {   throw new IllegalArgumentException( "attributeValue cannot be empty" );
        }

        try{
            factory = XMLEventFactory.newInstance();
            Attribute attribute = factory.createAttribute( attributeName , attributeValue );
            attributeQueue = new ConcurrentLinkedQueue <Attribute>();
            attributeQueue.add( attribute );
            namespaceQueue = new ConcurrentLinkedQueue <Attribute>();

        }catch( Exception e )
        {   e.printStackTrace();
        }
    }

    Iterator <Attribute> getAttributeIterator()
    {       return attributeQueue.iterator();
    }
    Iterator <Attribute> getNamespaceIterator()
    {       return namespaceQueue.iterator();
    }

    void add( String attributeName , String attributeValue )
    {
        if( attributeName == null )
        {   throw new NullPointerException( "attributeName cannot be null" );
        }
        if( attributeValue == null )
        {   throw new NullPointerException( "attributeValue cannot be null" );
        }
        if( attributeName.isEmpty() )
        {   throw new IllegalArgumentException( "attributeName cannot be empty" );
        }
        if( attributeValue.isEmpty() )
        {   throw new IllegalArgumentException( "attributeValue cannot be empty" );
        }

        try{
            Attribute attribute = factory.createAttribute( attributeName , attributeValue );
            attributeQueue.add( attribute );

        }catch( Exception e )
        {   e.printStackTrace();
        }
    }

} //end class

  • « ResourceTest
  • XMLWriter Main »

Published

Mar 18, 2012

Category

java-classes

~169 words

Tags

  • classes 92
  • java 252
  • xml 22
  • xmlelementattribute 1