List of usage examples for javax.xml.stream XMLStreamReader getAttributeName
public QName getAttributeName(int index);
From source file:org.apache.ddlutils.io.DatabaseIO.java
/** * Reads a foreign key element from the XML stream reader. * // w ww. j a v a2 s. co m * @param xmlReader The reader * @return The foreign key object */ private ForeignKey readForeignKeyElement(XMLStreamReader xmlReader) throws XMLStreamException, IOException { ForeignKey foreignKey = new ForeignKey(); for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++) { QName attrQName = xmlReader.getAttributeName(idx); if (isSameAs(attrQName, QNAME_ATTRIBUTE_FOREIGN_TABLE)) { foreignKey.setForeignTableName(xmlReader.getAttributeValue(idx)); } else if (isSameAs(attrQName, QNAME_ATTRIBUTE_NAME)) { foreignKey.setName(xmlReader.getAttributeValue(idx)); } else if (isSameAs(attrQName, QNAME_ATTRIBUTE_ON_UPDATE)) { foreignKey.setOnUpdate(getAttributeValueAsCascadeEnum(xmlReader, idx)); } else if (isSameAs(attrQName, QNAME_ATTRIBUTE_ON_DELETE)) { foreignKey.setOnDelete(getAttributeValueAsCascadeEnum(xmlReader, idx)); } } readReferenceElements(xmlReader, foreignKey); consumeRestOfElement(xmlReader); return foreignKey; }
From source file:org.apache.ddlutils.io.DatabaseIO.java
/** * Reads a reference element from the XML stream reader. * /*from w ww. j a v a 2 s. c o m*/ * @param xmlReader The reader * @return The reference object */ private Reference readReferenceElement(XMLStreamReader xmlReader) throws XMLStreamException, IOException { Reference reference = new Reference(); for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++) { QName attrQName = xmlReader.getAttributeName(idx); if (isSameAs(attrQName, QNAME_ATTRIBUTE_LOCAL)) { reference.setLocalColumnName(xmlReader.getAttributeValue(idx)); } else if (isSameAs(attrQName, QNAME_ATTRIBUTE_FOREIGN)) { reference.setForeignColumnName(xmlReader.getAttributeValue(idx)); } } consumeRestOfElement(xmlReader); return reference; }
From source file:org.apache.ddlutils.io.DatabaseIO.java
/** * Reads an index element from the XML stream reader. * //from w ww .j a va 2 s . c om * @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; }
From source file:org.apache.ddlutils.io.DatabaseIO.java
/** * Reads an unique index element from the XML stream reader. * //from w w w . ja v a 2s.co m * @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; }
From source file:org.apache.ddlutils.io.DatabaseIO.java
/** * Reads an index column element from the XML stream reader. * // w w w . j av a 2 s. c o m * @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; }
From source file:org.apache.ddlutils.io.DataReader.java
/** * Reads a bean from the given xml stream reader. * /* ww w.j a v a2s . c o m*/ * @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); } }
From source file:org.apache.ddlutils.io.DataReader.java
/** * Reads the next column sub element that matches a column specified by the given table object from the xml reader into the given bean. * //from w w w . ja v a 2 s .co m * @param xmlReader The reader * @param data Where to store the values */ private void readColumnSubElement(XMLStreamReader xmlReader, Map data) throws XMLStreamException, DdlUtilsXMLException { QName elemQName = xmlReader.getName(); Map attributes = new HashMap(); boolean usesBase64 = false; for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++) { QName attrQName = xmlReader.getAttributeName(idx); String value = xmlReader.getAttributeValue(idx); if (DatabaseIO.BASE64_ATTR_NAME.equals(attrQName.getLocalPart())) { if ("true".equalsIgnoreCase(value)) { usesBase64 = true; } } else { attributes.put(attrQName.getLocalPart(), value); } } int eventType = XMLStreamReader.START_ELEMENT; StringBuffer content = new StringBuffer(); while (eventType != XMLStreamReader.END_ELEMENT) { eventType = xmlReader.next(); if (eventType == XMLStreamReader.START_ELEMENT) { readColumnDataSubElement(xmlReader, attributes); } else if ((eventType == XMLStreamReader.CHARACTERS) || (eventType == XMLStreamReader.CDATA) || (eventType == XMLStreamReader.SPACE) || (eventType == XMLStreamReader.ENTITY_REFERENCE)) { content.append(xmlReader.getText()); } } String value = content.toString().trim(); if (usesBase64) { value = new String(Base64.decodeBase64(value.getBytes())); } String name = elemQName.getLocalPart(); if ("table-name".equals(name)) { data.put("table-name", value); } else { if ("column".equals(name)) { name = (String) attributes.get("column-name"); } if (attributes.containsKey("column-value")) { value = (String) attributes.get("column-value"); } data.put(name, value); } consumeRestOfElement(xmlReader); }
From source file:org.apache.ddlutils.io.DataReader.java
/** * Reads the next column-name or column-value sub element. * /* w w w .j a va2s . c om*/ * @param xmlReader The reader * @param data Where to store the values */ private void readColumnDataSubElement(XMLStreamReader xmlReader, Map data) throws XMLStreamException, DdlUtilsXMLException { QName elemQName = xmlReader.getName(); boolean usesBase64 = false; for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++) { QName attrQName = xmlReader.getAttributeName(idx); String value = xmlReader.getAttributeValue(idx); if (DatabaseIO.BASE64_ATTR_NAME.equals(attrQName.getLocalPart())) { if ("true".equalsIgnoreCase(value)) { usesBase64 = true; } break; } } String value = xmlReader.getElementText(); if (value != null) { value = value.toString().trim(); if (usesBase64) { value = new String(Base64.decodeBase64(value.getBytes())); } } String name = elemQName.getLocalPart(); if ("column-name".equals(name)) { data.put("column-name", value); } else if ("column-value".equals(name)) { data.put("column-value", value); } consumeRestOfElement(xmlReader); }
From source file:org.apache.ddlutils.io.DataReaderKeys.java
private Identity readBean(XMLStreamReader xmlReader) throws XMLStreamException, DdlUtilsXMLException { QName elemQName = xmlReader.getName(); Table table = _model.findTable(elemQName.getLocalPart(), isCaseSensitive()); if (table == null) { readOverElement(xmlReader);// ww w . j av a 2s .c om return null; } DynaBean bean = _model.createDynaBeanFor(table); for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++) { QName attrQName = xmlReader.getAttributeName(idx); Column column = table.findColumn(attrQName.getLocalPart(), isCaseSensitive()); if (column != null) { setColumnValue(bean, table, column, xmlReader.getAttributeValue(idx)); } } readColumnSubElements(xmlReader, bean, table); //getSink().addBean(bean); //--get keys here Identity id = buildIdentityFromPKs(table, bean); //Hashmap keyval = new Hashmap(); //keyval.put(id.,id); consumeRestOfElement(xmlReader); return id; }
From source file:org.apache.ddlutils.io.DataReaderKeys.java
private void readColumnSubElement(XMLStreamReader xmlReader, DynaBean bean, Table table) throws XMLStreamException, DdlUtilsXMLException { QName elemQName = xmlReader.getName(); boolean usesBase64 = false; for (int idx = 0; idx < xmlReader.getAttributeCount(); idx++) { QName attrQName = xmlReader.getAttributeName(idx); if (DatabaseIO.BASE64_ATTR_NAME.equals(attrQName.getLocalPart()) && "true".equalsIgnoreCase(xmlReader.getAttributeValue(idx))) { usesBase64 = true;// w w w . ja va2 s. c o m break; } } Column column = table.findColumn(elemQName.getLocalPart(), isCaseSensitive()); if (column == null) { _log.warn("Data XML contains an element " + elemQName + " at location " + xmlReader.getLocation() + " but there is no column defined in table " + table.getName() + " with this name. This element will be ignored."); } else { String value = xmlReader.getElementText(); if (value != null) { value = value.trim(); if (usesBase64) { value = new String(Base64.decodeBase64(value.getBytes())); } setColumnValue(bean, table, column, value); } } consumeRestOfElement(xmlReader); }