Java Code Examples for javax.xml.stream.XMLStreamReader#getAttributeName()

The following examples show how to use javax.xml.stream.XMLStreamReader#getAttributeName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatabaseIO.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a database element from the XML stream reader.
 * 
 * @param xmlReader The reader
 * @return The database object
 */
private Database readDatabaseElement(XMLStreamReader xmlReader) throws XMLStreamException, IOException
{
    Database model = new Database();

    for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++)
    {
        QName attrQName = xmlReader.getAttributeName(idx);

        if (isSameAs(attrQName, QNAME_ATTRIBUTE_NAME))
        {
            model.setName(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_DEFAULT_ID_METHOD))
        {
            model.setIdMethod(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_VERSION))
        {
            model.setVersion(xmlReader.getAttributeValue(idx));
        }
    }
    readTableElements(xmlReader, model);
    consumeRestOfElement(xmlReader);
    return model;
}
 
Example 2
Source File: DatabaseIO.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Reads an index column element from the XML stream reader.
 * 
 * @param xmlReader The reader
 * @return The index column object
 */
private IndexColumn readIndexColumnElement(XMLStreamReader xmlReader) throws XMLStreamException, IOException
{
    IndexColumn indexColumn = new IndexColumn();

    for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++)
    {
        QName attrQName = xmlReader.getAttributeName(idx);

        if (isSameAs(attrQName, QNAME_ATTRIBUTE_NAME))
        {
            indexColumn.setName(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_SIZE))
        {
            indexColumn.setSize(getAttributeValueBeingNullAware(xmlReader, idx));
        }
    }
    consumeRestOfElement(xmlReader);
    return indexColumn;
}
 
Example 3
Source File: DatabaseIO.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Reads an unique index element from the XML stream reader.
 * 
 * @param xmlReader The reader
 * @return The unique index object
 */
private Index readUniqueElement(XMLStreamReader xmlReader) throws XMLStreamException, IOException
{
    Index index = new UniqueIndex();

    for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++)
    {
        QName attrQName = xmlReader.getAttributeName(idx);

        if (isSameAs(attrQName, QNAME_ATTRIBUTE_NAME))
        {
            index.setName(xmlReader.getAttributeValue(idx));
        }
    }
    readUniqueColumnElements(xmlReader, index);
    consumeRestOfElement(xmlReader);
    return index;
}
 
Example 4
Source File: DatabaseIO.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Reads an index element from the XML stream reader.
 * 
 * @param xmlReader The reader
 * @return The index object
 */
private Index readIndexElement(XMLStreamReader xmlReader) throws XMLStreamException, IOException
{
    Index index = new NonUniqueIndex();

    for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++)
    {
        QName attrQName = xmlReader.getAttributeName(idx);

        if (isSameAs(attrQName, QNAME_ATTRIBUTE_NAME))
        {
            index.setName(xmlReader.getAttributeValue(idx));
        }
    }
    readIndexColumnElements(xmlReader, index);
    consumeRestOfElement(xmlReader);
    return index;
}
 
Example 5
Source File: DatabaseIO.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Reads an unique index element from the XML stream reader.
 * 
 * @param xmlReader The reader
 * @return The unique index object
 */
private Index readUniqueElement(XMLStreamReader xmlReader) throws XMLStreamException, IOException
{
    Index index = new UniqueIndex();

    for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++)
    {
        QName attrQName = xmlReader.getAttributeName(idx);

        if (isSameAs(attrQName, QNAME_ATTRIBUTE_NAME))
        {
            index.setName(xmlReader.getAttributeValue(idx));
        }
    }
    readUniqueColumnElements(xmlReader, index);
    consumeRestOfElement(xmlReader);
    return index;
}
 
Example 6
Source File: DatabaseIO.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * Reads an index element from the XML stream reader.
 * 
 * @param xmlReader The reader
 * @return The index object
 */
private Index readIndexElement(XMLStreamReader xmlReader) throws XMLStreamException, IOException
{
    Index index = new NonUniqueIndex();

    for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++)
    {
        QName attrQName = xmlReader.getAttributeName(idx);

        if (isSameAs(attrQName, QNAME_ATTRIBUTE_NAME))
        {
            index.setName(xmlReader.getAttributeValue(idx));
        }
    }
    readIndexColumnElements(xmlReader, index);
    consumeRestOfElement(xmlReader);
    return index;
}
 
Example 7
Source File: DatabaseIO.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
     * Reads a table element from the XML stream reader.
     * 
     * @param xmlReader The reader
     * @return The table object
     */
    private Table readTableElement(XMLStreamReader xmlReader) throws XMLStreamException, IOException
    {
        Table table = new Table();

        for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++)
        {
            QName attrQName = xmlReader.getAttributeName(idx);

            if (isSameAs(attrQName, QNAME_ATTRIBUTE_NAME))
            {
// GemStone changes BEGIN
                // check for fully qualified name
                String tableName = xmlReader.getAttributeValue(idx);
                int dotPos = tableName.indexOf('.');
                if (dotPos > 0) {
                  table.setSchema(tableName.substring(0, dotPos));
                  table.setName(tableName.substring(dotPos + 1));
                }
                else {
                  table.setName(tableName);
                }
                /* (original code)
                table.setName(xmlReader.getAttributeValue(idx));
                */
// GemStone changes END
            }
            else if (isSameAs(attrQName, QNAME_ATTRIBUTE_DESCRIPTION))
            {
                table.setDescription(xmlReader.getAttributeValue(idx));
            }
        }
        readTableSubElements(xmlReader, table);
        consumeRestOfElement(xmlReader);
        return table;
    }
 
Example 8
Source File: XMLStreamReaderUtil.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public AttributesImpl(XMLStreamReader reader) {
    if (reader == null) {

        // this is the case when we call getAttributes() on the
        // reader when it is not on a start tag
        atInfos = new AttributeInfo[0];
    } else {

        // this is the normal case
        int index = 0;
        int namespaceCount = reader.getNamespaceCount();
        int attributeCount = reader.getAttributeCount();
        atInfos = new AttributeInfo[namespaceCount + attributeCount];
        for (int i=0; i<namespaceCount; i++) {
            String namespacePrefix = reader.getNamespacePrefix(i);

            // will be null if default prefix. QName can't take null
            if (namespacePrefix == null) {
                namespacePrefix = "";
            }
            atInfos[index++] = new AttributeInfo(
                new QName(XMLNS_NAMESPACE_URI,
                    namespacePrefix,
                    "xmlns"),
                reader.getNamespaceURI(i));
        }
        for (int i=0; i<attributeCount; i++) {
            atInfos[index++] = new AttributeInfo(
                reader.getAttributeName(i),
                reader.getAttributeValue(i));
        }
    }
}
 
Example 9
Source File: WSDLGenerationTester.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void compareStartElement(XMLStreamReader orig, XMLStreamReader actual)
    throws Exception {
    Assert.assertEquals("Start element is not matched", orig.getName(), actual.getName());
    int origAttrCount = orig.getAttributeCount();
    int actualAttrCount = actual.getAttributeCount();
    for (int i = 0; i < origAttrCount; i++) {
        QName origAttrName = orig.getAttributeName(i);
        if ("location".equals(origAttrName.getLocalPart())
            || "schemaLocation".equals(origAttrName.getLocalPart())) {
            //skip this atribute
            origAttrCount--;
        } else {
            String s1 = orig.getAttributeValue(origAttrName.getNamespaceURI(),
                                               origAttrName.getLocalPart());
            String s2 = actual.getAttributeValue(origAttrName.getNamespaceURI(),
                                                 origAttrName.getLocalPart());

            if (!s1.equals(s2)
                && (s1.contains(":") || s2.contains(":"))) {
                s1 = mapToQName(orig, s1);
                s2 = mapToQName(actual, s2);
            }

            Assert.assertEquals("Attribute " + origAttrName + " not found or value not matching",
                                s1, s2);
        }
    }
    for (int i = 0; i < actualAttrCount; i++) {
        QName actualAttrName = actual.getAttributeName(i);
        if ("location".equals(actualAttrName.getLocalPart())
            || "schemaLocation".equals(actualAttrName.getLocalPart())) {
            //skip this atribute
            actualAttrCount--;
        }
    }
    Assert.assertEquals("Attribute count is not matched for element " + orig.getName(),
                        origAttrCount,
                        actualAttrCount);
}
 
Example 10
Source File: XMLStreamReaderUtil.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public AttributesImpl(XMLStreamReader reader) {
    if (reader == null) {

        // this is the case when we call getAttributes() on the
        // reader when it is not on a start tag
        atInfos = new AttributeInfo[0];
    } else {

        // this is the normal case
        int index = 0;
        int namespaceCount = reader.getNamespaceCount();
        int attributeCount = reader.getAttributeCount();
        atInfos = new AttributeInfo[namespaceCount + attributeCount];
        for (int i=0; i<namespaceCount; i++) {
            String namespacePrefix = reader.getNamespacePrefix(i);

            // will be null if default prefix. QName can't take null
            if (namespacePrefix == null) {
                namespacePrefix = "";
            }
            atInfos[index++] = new AttributeInfo(
                new QName(XMLNS_NAMESPACE_URI,
                    namespacePrefix,
                    "xmlns"),
                reader.getNamespaceURI(i));
        }
        for (int i=0; i<attributeCount; i++) {
            atInfos[index++] = new AttributeInfo(
                reader.getAttributeName(i),
                reader.getAttributeValue(i));
        }
    }
}
 
Example 11
Source File: XMLStreamReaderUtil.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public AttributesImpl(XMLStreamReader reader) {
    if (reader == null) {

        // this is the case when we call getAttributes() on the
        // reader when it is not on a start tag
        atInfos = new AttributeInfo[0];
    } else {

        // this is the normal case
        int index = 0;
        int namespaceCount = reader.getNamespaceCount();
        int attributeCount = reader.getAttributeCount();
        atInfos = new AttributeInfo[namespaceCount + attributeCount];
        for (int i=0; i<namespaceCount; i++) {
            String namespacePrefix = reader.getNamespacePrefix(i);

            // will be null if default prefix. QName can't take null
            if (namespacePrefix == null) {
                namespacePrefix = "";
            }
            atInfos[index++] = new AttributeInfo(
                new QName(XMLNS_NAMESPACE_URI,
                    namespacePrefix,
                    "xmlns"),
                reader.getNamespaceURI(i));
        }
        for (int i=0; i<attributeCount; i++) {
            atInfos[index++] = new AttributeInfo(
                reader.getAttributeName(i),
                reader.getAttributeValue(i));
        }
    }
}
 
Example 12
Source File: EntityTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void printAttributes(XMLStreamReader xmlr) {
    if (xmlr.getAttributeCount() > 0) {
        int count = xmlr.getAttributeCount();
        for (int i = 0; i < count; i++) {
            output += xmlr.getAttributeName(i);
            output += "=";
            output += xmlr.getAttributeValue(i);
            /*
             * String name = xmlr.getAttributeName(i) ; String value =
             * xmlr.getAttributeValue(i) ;
             * System.out.println(name+"="+value);
             */
        }
    }
}
 
Example 13
Source File: XMLStreamReaderUtil.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public AttributesImpl(XMLStreamReader reader) {
    if (reader == null) {

        // this is the case when we call getAttributes() on the
        // reader when it is not on a start tag
        atInfos = new AttributeInfo[0];
    } else {

        // this is the normal case
        int index = 0;
        int namespaceCount = reader.getNamespaceCount();
        int attributeCount = reader.getAttributeCount();
        atInfos = new AttributeInfo[namespaceCount + attributeCount];
        for (int i=0; i<namespaceCount; i++) {
            String namespacePrefix = reader.getNamespacePrefix(i);

            // will be null if default prefix. QName can't take null
            if (namespacePrefix == null) {
                namespacePrefix = "";
            }
            atInfos[index++] = new AttributeInfo(
                new QName(XMLNS_NAMESPACE_URI,
                    namespacePrefix,
                    "xmlns"),
                reader.getNamespaceURI(i));
        }
        for (int i=0; i<attributeCount; i++) {
            atInfos[index++] = new AttributeInfo(
                reader.getAttributeName(i),
                reader.getAttributeValue(i));
        }
    }
}
 
Example 14
Source File: XMLStreamReaderUtil.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public AttributesImpl(XMLStreamReader reader) {
    if (reader == null) {

        // this is the case when we call getAttributes() on the
        // reader when it is not on a start tag
        atInfos = new AttributeInfo[0];
    } else {

        // this is the normal case
        int index = 0;
        int namespaceCount = reader.getNamespaceCount();
        int attributeCount = reader.getAttributeCount();
        atInfos = new AttributeInfo[namespaceCount + attributeCount];
        for (int i=0; i<namespaceCount; i++) {
            String namespacePrefix = reader.getNamespacePrefix(i);

            // will be null if default prefix. QName can't take null
            if (namespacePrefix == null) {
                namespacePrefix = "";
            }
            atInfos[index++] = new AttributeInfo(
                new QName(XMLNS_NAMESPACE_URI,
                    namespacePrefix,
                    "xmlns"),
                reader.getNamespaceURI(i));
        }
        for (int i=0; i<attributeCount; i++) {
            atInfos[index++] = new AttributeInfo(
                reader.getAttributeName(i),
                reader.getAttributeValue(i));
        }
    }
}
 
Example 15
Source File: XMLStreamReaderUtil.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public AttributesImpl(XMLStreamReader reader) {
    if (reader == null) {

        // this is the case when we call getAttributes() on the
        // reader when it is not on a start tag
        atInfos = new AttributeInfo[0];
    } else {

        // this is the normal case
        int index = 0;
        int namespaceCount = reader.getNamespaceCount();
        int attributeCount = reader.getAttributeCount();
        atInfos = new AttributeInfo[namespaceCount + attributeCount];
        for (int i=0; i<namespaceCount; i++) {
            String namespacePrefix = reader.getNamespacePrefix(i);

            // will be null if default prefix. QName can't take null
            if (namespacePrefix == null) {
                namespacePrefix = "";
            }
            atInfos[index++] = new AttributeInfo(
                new QName(XMLNS_NAMESPACE_URI,
                    namespacePrefix,
                    "xmlns"),
                reader.getNamespaceURI(i));
        }
        for (int i=0; i<attributeCount; i++) {
            atInfos[index++] = new AttributeInfo(
                reader.getAttributeName(i),
                reader.getAttributeValue(i));
        }
    }
}
 
Example 16
Source File: DataReader.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Reads a bean from the given xml stream reader.
 * 
 * @param xmlReader The reader
 */
private void readBean(XMLStreamReader xmlReader) throws XMLStreamException, DdlUtilsXMLException
{
    QName    elemQName  = xmlReader.getName();
    Location location   = xmlReader.getLocation();
    Map      attributes = new HashMap();
    String   tableName  = null;

    for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++)
    {
        QName attrQName = xmlReader.getAttributeName(idx);

        attributes.put(isCaseSensitive() ? attrQName.getLocalPart() : attrQName.getLocalPart().toLowerCase(),
                       xmlReader.getAttributeValue(idx));
    }
    readColumnSubElements(xmlReader, attributes);

    if ("table".equals(elemQName.getLocalPart()))
    {
        tableName = (String)attributes.get("table-name");
    }
    else
    {
        tableName  = elemQName.getLocalPart();
    }

    Table table = _model.findTable(tableName, isCaseSensitive());

    if (table == null)
    {
        _log.warn("Data XML contains an element " + elemQName + " at location " + location +
                  " but there is no table defined with this name. This element will be ignored.");
    }
    else
    {
        DynaBean bean = _model.createDynaBeanFor(table);

        for (int idx = 0; idx < table.getColumnCount(); idx++)
        {
            Column column = table.getColumn(idx);
            String value  = (String)attributes.get(isCaseSensitive() ? column.getName() : column.getName().toLowerCase());

            if (value != null)
            {
                setColumnValue(bean, table, column, value);
            }
        }
        getSink().addBean(bean);
        consumeRestOfElement(xmlReader);
    }
}
 
Example 17
Source File: DatabaseIO.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Reads a column element from the XML stream reader.
 * 
 * @param xmlReader The reader
 * @return The column object
 */
private Column readColumnElement(XMLStreamReader xmlReader) throws XMLStreamException, IOException
{
    Column column = new Column();

    for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++)
    {
        QName attrQName = xmlReader.getAttributeName(idx);

        if (isSameAs(attrQName, QNAME_ATTRIBUTE_NAME))
        {
            column.setName(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_PRIMARY_KEY))
        {
            column.setPrimaryKey(getAttributeValueAsBoolean(xmlReader, idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_REQUIRED))
        {
            column.setRequired(getAttributeValueAsBoolean(xmlReader, idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_TYPE))
        {
            column.setType(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_SIZE))
        {
            column.setSize(getAttributeValueBeingNullAware(xmlReader, idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_DEFAULT))
        {
            column.setDefaultValue(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_AUTO_INCREMENT))
        {
            column.setAutoIncrement(getAttributeValueAsBoolean(xmlReader, idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_DESCRIPTION))
        {
            column.setDescription(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_JAVA_NAME))
        {
            column.setJavaName(xmlReader.getAttributeValue(idx));
        }
    }
    consumeRestOfElement(xmlReader);
    return column;
}
 
Example 18
Source File: StAXEncoder.java    From exificient with MIT License 4 votes vote down vote up
public void encode(XMLStreamReader xmlStream) throws XMLStreamException,
		EXIException, IOException {

	// StartDocument should be initial state
	assert (xmlStream.getEventType() == XMLStreamConstants.START_DOCUMENT);

	writeStartDocument();

	while (xmlStream.hasNext()) {
		int event = xmlStream.next();
		switch (event) {
		case XMLStreamConstants.START_DOCUMENT:
			// should have happened beforehand
			throw new EXIException("Unexpected START_DOCUMENT event");
		case XMLStreamConstants.END_DOCUMENT:
			this.writeEndDocument();
			break;
		case XMLStreamConstants.START_ELEMENT:
			QName qn = xmlStream.getName();
			String pfx = qn.getPrefix();
			writeStartElement(pfx, qn.getLocalPart(), qn.getNamespaceURI());
			// parse NS declarations
			int nsCnt = xmlStream.getNamespaceCount();
			for (int i = 0; i < nsCnt; i++) {
				String nsPfx = xmlStream.getNamespacePrefix(i);
				nsPfx = nsPfx == null ? Constants.XML_DEFAULT_NS_PREFIX
						: nsPfx;
				String nsUri = xmlStream.getNamespaceURI(i);
				this.writeNamespace(nsPfx, nsUri);
			}
			// parse attributes
			int atCnt = xmlStream.getAttributeCount();
			for (int i = 0; i < atCnt; i++) {
				QName atQname = xmlStream.getAttributeName(i);
				this.writeAttribute(atQname.getPrefix(),
						atQname.getNamespaceURI(), atQname.getLocalPart(),
						xmlStream.getAttributeValue(i));
			}

			break;
		case XMLStreamConstants.END_ELEMENT:
			writeEndElement();
			break;
		case XMLStreamConstants.NAMESPACE:
			break;
		case XMLStreamConstants.CHARACTERS:
			this.writeCharacters(xmlStream.getTextCharacters(),
					xmlStream.getTextStart(), xmlStream.getTextLength());
			break;
		case XMLStreamConstants.SPACE:
			// @SuppressWarnings("unused")
			String ignorableSpace = xmlStream.getText();
			writeCharacters(ignorableSpace);
			break;
		case XMLStreamConstants.ATTRIBUTE:
			// @SuppressWarnings("unused")
			// int attsX = xmlStream.getAttributeCount();
			break;
		case XMLStreamConstants.PROCESSING_INSTRUCTION:
			this.writeProcessingInstruction(xmlStream.getPITarget(),
					xmlStream.getPIData());
			break;
		case XMLStreamConstants.COMMENT:
			this.writeComment(xmlStream.getText());
			break;
		case XMLStreamConstants.DTD:
			// TODO DTD
			break;
		case XMLStreamConstants.ENTITY_REFERENCE:
			// TODO ER
			break;
		default:
			System.out.println("Event '" + event + "' not supported!");
		}
	}

	// this.flush();
}
 
Example 19
Source File: DatabaseIO.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Reads a column element from the XML stream reader.
 * 
 * @param xmlReader The reader
 * @return The column object
 */
private Column readColumnElement(XMLStreamReader xmlReader) throws XMLStreamException, IOException
{
    Column column = new Column();

    for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++)
    {
        QName attrQName = xmlReader.getAttributeName(idx);

        if (isSameAs(attrQName, QNAME_ATTRIBUTE_NAME))
        {
            column.setName(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_PRIMARY_KEY))
        {
            column.setPrimaryKey(getAttributeValueAsBoolean(xmlReader, idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_REQUIRED))
        {
            column.setRequired(getAttributeValueAsBoolean(xmlReader, idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_TYPE))
        {
            column.setType(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_SIZE))
        {
            column.setSize(getAttributeValueBeingNullAware(xmlReader, idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_DEFAULT))
        {
            column.setDefaultValue(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_AUTO_INCREMENT))
        {
            column.setAutoIncrement(getAttributeValueAsBoolean(xmlReader, idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_DESCRIPTION))
        {
            column.setDescription(xmlReader.getAttributeValue(idx));
        }
        else if (isSameAs(attrQName, QNAME_ATTRIBUTE_JAVA_NAME))
        {
            column.setJavaName(xmlReader.getAttributeValue(idx));
        }
    }
    consumeRestOfElement(xmlReader);
    return column;
}
 
Example 20
Source File: DataReader.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
/**
 * Reads a bean from the given xml stream reader.
 * 
 * @param xmlReader The reader
 */
private void readBean(XMLStreamReader xmlReader) throws XMLStreamException, DdlUtilsXMLException
{
    QName    elemQName  = xmlReader.getName();
    Location location   = xmlReader.getLocation();
    Map      attributes = new HashMap();
    String   tableName  = null;

    for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++)
    {
        QName attrQName = xmlReader.getAttributeName(idx);

        attributes.put(isCaseSensitive() ? attrQName.getLocalPart() : attrQName.getLocalPart().toLowerCase(),
                       xmlReader.getAttributeValue(idx));
    }
    readColumnSubElements(xmlReader, attributes);

    if ("table".equals(elemQName.getLocalPart()))
    {
        tableName = (String)attributes.get("table-name");
    }
    else
    {
        tableName  = elemQName.getLocalPart();
    }

    Table table = _model.findTable(tableName, isCaseSensitive());

    if (table == null)
    {
        _log.warn("Data XML contains an element " + elemQName + " at location " + location +
                  " but there is no table defined with this name. This element will be ignored.");
    }
    else
    {
        DynaBean bean = _model.createDynaBeanFor(table);

        for (int idx = 0; idx < table.getColumnCount(); idx++)
        {
            Column column = table.getColumn(idx);
            String value  = (String)attributes.get(isCaseSensitive() ? column.getName() : column.getName().toLowerCase());

            if (value != null)
            {
                setColumnValue(bean, table, column, value);
            }
        }
        getSink().addBean(bean);
        consumeRestOfElement(xmlReader);
    }
}