Example usage for javax.xml.namespace QName getLocalPart

List of usage examples for javax.xml.namespace QName getLocalPart

Introduction

In this page you can find the example usage for javax.xml.namespace QName getLocalPart.

Prototype

public String getLocalPart() 

Source Link

Document

Get the local part of this QName.

Usage

From source file:org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.ServiceProcessor.java

private int isNonWrappable(BindingOperationInfo bop) {
    QName operationName = bop.getName();
    MessageInfo bodyMessage = null;/*from   www.  j  a v  a 2 s .  c  o m*/
    QName headerMessage = null;
    SoapHeader header = null;
    boolean containParts = false;
    boolean isSameMessage = false;
    boolean isNonWrappable = false;
    boolean allPartsHeader = false;
    int result = this.noHEADER;

    // begin process input
    if (bop.getInput() != null && bop.getInput().getExtensors(ExtensibilityElement.class) != null) {
        List<ExtensibilityElement> extensors = bop.getInput().getExtensors(ExtensibilityElement.class);
        if (extensors != null) {
            for (ExtensibilityElement ext : extensors) {
                if (SOAPBindingUtil.isSOAPBody(ext)) {
                    bodyMessage = getMessage(operationName, true);
                }
                if (SOAPBindingUtil.isSOAPHeader(ext)) {
                    header = SOAPBindingUtil.getSoapHeader(ext);
                    headerMessage = header.getMessage();
                    if (header.getPart().length() > 0) {
                        containParts = true;
                    }
                }
            }
        }

        if (headerMessage != null && bodyMessage != null
                && headerMessage.getNamespaceURI().equalsIgnoreCase(bodyMessage.getName().getNamespaceURI())
                && headerMessage.getLocalPart().equalsIgnoreCase(bodyMessage.getName().getLocalPart())) {
            isSameMessage = true;
        }

        isNonWrappable = isSameMessage && containParts;
        // if is nonwrapple then return
        if (isNonWrappable) {
            result = this.inHEADER;
        }
    }
    isSameMessage = false;
    containParts = false;

    // process output
    if (bop.getOutput() != null && bop.getOutput().getExtensors(ExtensibilityElement.class) != null) {
        List<ExtensibilityElement> extensors = bop.getOutput().getExtensors(ExtensibilityElement.class);
        if (extensors != null) {
            for (ExtensibilityElement ext : extensors) {
                if (SOAPBindingUtil.isSOAPBody(ext)) {
                    bodyMessage = getMessage(operationName, false);
                }
                if (SOAPBindingUtil.isSOAPHeader(ext)) {
                    header = SOAPBindingUtil.getSoapHeader(ext);
                    headerMessage = header.getMessage();
                    if (header.getPart().length() > 0) {
                        containParts = true;
                    }
                }
            }
        }
        if (headerMessage != null && bodyMessage != null
                && headerMessage.getNamespaceURI().equalsIgnoreCase(bodyMessage.getName().getNamespaceURI())
                && headerMessage.getLocalPart().equalsIgnoreCase(bodyMessage.getName().getLocalPart())) {
            isSameMessage = true;
            if (bodyMessage.getMessagePartsNumber() == 1) {
                allPartsHeader = true;
            }

        }
        isNonWrappable = isSameMessage && containParts;
        if (isNonWrappable && allPartsHeader) {
            result = this.resultHeader;
        }
        if (isNonWrappable && !allPartsHeader) {
            result = this.outHEADER;
        }
    }

    return result;
}

From source file:org.apache.ddlutils.io.DatabaseIO.java

/**
 * Compares the given qnames. This specifically ignores the namespace
 * uri of the other qname if the namespace of the current element is
 * empty./*from   w  w  w.j av a  2 s.  c  o  m*/
 * 
 * @param curElemQName The qname of the current element
 * @param qName        The qname to compare to
 * @return <code>true</code> if they are the same
 */
private boolean isSameAs(QName curElemQName, QName qName) {
    if (StringUtils.isEmpty(curElemQName.getNamespaceURI())) {
        return qName.getLocalPart().equals(curElemQName.getLocalPart());
    } else {
        return qName.equals(curElemQName);
    }
}

From source file:org.apache.ddlutils.io.DatabaseIO.java

/**
 * Writes the start of the specified XML element to the given XML writer.
 * /* w w w.  j a va 2  s  .c o  m*/
 * @param xmlWriter The xml writer
 * @param qName     The qname of the XML element
 */
private void writeElementStart(PrettyPrintingXmlWriter xmlWriter, QName qName) throws DdlUtilsXMLException {
    xmlWriter.writeElementStart(qName.getNamespaceURI(), qName.getLocalPart());
}

From source file:org.apache.ddlutils.io.DatabaseIO.java

/**
 * Writes an attribute to the given XML writer.
 * /*from   w  w  w.  j  a v a  2  s  . c  om*/
 * @param xmlWriter The xml writer
 * @param qName     The qname of the attribute
 * @param value     The value; if empty, then nothing is written
 */
private void writeAttribute(PrettyPrintingXmlWriter xmlWriter, QName qName, String value)
        throws DdlUtilsXMLException {
    if (value != null) {
        xmlWriter.writeAttribute(null, qName.getLocalPart(), value);
    }
}

From source file:org.apache.ddlutils.io.DataReader.java

/**
 * Reads a bean from the given xml stream reader.
 * // ww w. j a v  a 2s  . com
 * @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  . j  a v  a  2s  .  c  om
 * @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.
 *  //from  w  w  w .  java 2s . co  m
 * @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);/*from  w  ww. j a  va 2  s. com*/
        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;//from  w  w  w. ja  va2 s. co  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);
}