List of usage examples for javax.xml.stream XMLStreamReader getAttributeValue
public String getAttributeValue(int index);
From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java
/** * add attributes/*from w w w . ja v a2 s .c o m*/ * * @param NameCreator nc * @param element SOAPElement which is the target of the new attributes * @param reader XMLStreamReader whose cursor is at START_ELEMENT * @throws SOAPException */ protected void addAttributes(NameCreator nc, SOAPElement element, XMLStreamReader reader) throws SOAPException { if (log.isDebugEnabled()) { log.debug("addAttributes: Entry"); } // Add the attributes from the reader int size = reader.getAttributeCount(); for (int i = 0; i < size; i++) { QName qName = reader.getAttributeName(i); String prefix = reader.getAttributePrefix(i); String value = reader.getAttributeValue(i); Name name = nc.createName(qName.getLocalPart(), prefix, qName.getNamespaceURI()); element.addAttribute(name, value); try { if (log.isDebugEnabled()) { log.debug("Setting attrType"); } String namespace = qName.getNamespaceURI(); Attr attr = null; // This is an org.w3c.dom.Attr if (namespace == null || namespace.length() == 0) { attr = element.getAttributeNode(qName.getLocalPart()); } else { attr = element.getAttributeNodeNS(namespace, qName.getLocalPart()); } if (attr != null) { String attrType = reader.getAttributeType(i); attr.setUserData(SAAJConverter.OM_ATTRIBUTE_KEY, attrType, null); if (log.isDebugEnabled()) { log.debug("Storing attrType in UserData: " + attrType); } } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("An error occured while processing attrType: " + e.getMessage()); } } } if (log.isDebugEnabled()) { log.debug("addAttributes: Exit"); } }
From source file:org.apache.ddlutils.io.DatabaseIO.java
/** * Reads a database element from the XML stream reader. * //from www. j a va 2 s . co m * @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; }
From source file:org.apache.ddlutils.io.DatabaseIO.java
/** * Reads a table element from the XML stream reader. * /*from w ww . j a v a 2s . c o m*/ * @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)) { table.setName(xmlReader.getAttributeValue(idx)); } else if (isSameAs(attrQName, QNAME_ATTRIBUTE_DESCRIPTION)) { table.setDescription(xmlReader.getAttributeValue(idx)); } } readTableSubElements(xmlReader, table); consumeRestOfElement(xmlReader); return table; }
From source file:org.apache.ddlutils.io.DatabaseIO.java
/** * Reads a column element from the XML stream reader. * //from ww w . j ava 2 s . c om * @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; }
From source file:org.apache.ddlutils.io.DatabaseIO.java
/** * Reads a foreign key element from the XML stream reader. * //from ww w . j ava 2 s . c o 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 w w . j a va2s.c om*/ * @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 ww w . jav a 2 s.c o m*/ * @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 .j a va2s . 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. * //from w w w . j a va 2 s .co 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.DatabaseIO.java
/** * Returns the value of the indicated attribute of the current element as a string. * This method can handle "null" in which case it returns a null object. * //w w w. j a v a 2 s.c o m * @param xmlReader The xml reader * @param attributeIdx The index of the attribute * @return The attribute's value */ private String getAttributeValueBeingNullAware(XMLStreamReader xmlReader, int attributeIdx) throws DdlUtilsXMLException { String value = xmlReader.getAttributeValue(attributeIdx); return "null".equalsIgnoreCase(value) ? null : value; }