Example usage for javax.xml.namespace QName getNamespaceURI

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

Introduction

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

Prototype

public String getNamespaceURI() 

Source Link

Document

Get the Namespace URI of this QName.

Usage

From source file:org.apache.axis2.addressing.EndpointReferenceHelper.java

/**
 * Creates an <code>OMElement</code> based on the properties of the endpoint
 * reference. The output may differ based on the addressing namespace that is
 * in effect when this method is called. If the http://www.w3.org/2005/08/addressing
 * namespace is in effect, and a metadata property has been defined for the
 * endpoint reference, then there will be a metadata element to contain the
 * property in the output. If the http://schemas.xmlsoap.org/ws/2004/08/addressing
 * namespace is in effect, however, then no metadata element will be included
 * in the output, even if a metadata property element has been defined.
 *
 * @param factory//from www  .j a v a  2  s  .c  om
 * @param epr
 * @param qname
 * @param addressingNamespace
 * @return
 * @throws AxisFault
 */
public static OMElement toOM(OMFactory factory, EndpointReference epr, QName qname, String addressingNamespace)
        throws AxisFault {
    OMElement eprElement = null;

    if (log.isDebugEnabled()) {
        log.debug("toOM: Factory, " + factory);
        log.debug("toOM: Endpoint reference, " + epr);
        log.debug("toOM: Element qname, " + qname);
        log.debug("toOM: Addressing namespace, " + addressingNamespace);
    }

    if (addressingNamespace == null) {
        throw new AxisFault("Addressing namespace cannot be null.");
    }

    if (qname.getPrefix() != null) {
        OMNamespace wrapNs = factory.createOMNamespace(qname.getNamespaceURI(), qname.getPrefix());
        if (factory instanceof SOAPFactory) {
            eprElement = ((SOAPFactory) factory).createSOAPHeaderBlock(qname.getLocalPart(), wrapNs);
        } else {
            eprElement = factory.createOMElement(qname.getLocalPart(), wrapNs);
        }

        OMNamespace wsaNS = factory.createOMNamespace(addressingNamespace,
                AddressingConstants.WSA_DEFAULT_PREFIX);
        OMElement addressE = factory.createOMElement(AddressingConstants.EPR_ADDRESS, wsaNS, eprElement);
        String address = epr.getAddress();
        addressE.setText(address);

        ArrayList addressAttributes = epr.getAddressAttributes();
        if (addressAttributes != null) {
            Iterator attrIter = addressAttributes.iterator();
            while (attrIter.hasNext()) {
                OMAttribute omAttribute = (OMAttribute) attrIter.next();
                AttributeHelper.importOMAttribute(omAttribute, addressE);
            }
        }

        List metaData = epr.getMetaData();
        if (metaData != null && AddressingConstants.Final.WSA_NAMESPACE.equals(addressingNamespace)) {
            OMElement metadataE = factory.createOMElement(AddressingConstants.Final.WSA_METADATA, wsaNS,
                    eprElement);
            for (int i = 0, size = metaData.size(); i < size; i++) {
                OMElement omElement = (OMElement) metaData.get(i);
                metadataE.addChild(ElementHelper.importOMElement(omElement, factory));
            }

            ArrayList metadataAttributes = epr.getMetadataAttributes();
            if (metadataAttributes != null) {
                Iterator attrIter = metadataAttributes.iterator();
                while (attrIter.hasNext()) {
                    OMAttribute omAttribute = (OMAttribute) attrIter.next();
                    AttributeHelper.importOMAttribute(omAttribute, metadataE);
                }
            }
        }

        Map referenceParameters = epr.getAllReferenceParameters();
        if (referenceParameters != null) {
            OMElement refParameterElement = factory
                    .createOMElement(AddressingConstants.EPR_REFERENCE_PARAMETERS, wsaNS, eprElement);
            Iterator iterator = referenceParameters.values().iterator();
            while (iterator.hasNext()) {
                OMElement omElement = (OMElement) iterator.next();
                refParameterElement.addChild(ElementHelper.importOMElement(omElement, factory));
            }
        }

        List attributes = epr.getAttributes();
        if (attributes != null) {
            for (int i = 0, size = attributes.size(); i < size; i++) {
                OMAttribute omAttribute = (OMAttribute) attributes.get(i);
                AttributeHelper.importOMAttribute(omAttribute, eprElement);
            }
        }

        // add xs:any
        List extensibleElements = epr.getExtensibleElements();
        if (extensibleElements != null) {
            for (int i = 0, size = extensibleElements.size(); i < size; i++) {
                OMElement omElement = (OMElement) extensibleElements.get(i);
                eprElement.addChild(ElementHelper.importOMElement(omElement, factory));
            }
        }
    } else {
        throw new AxisFault("prefix must be specified");
    }

    return eprElement;
}

From source file:org.apache.axis2.builder.BuilderUtil.java

public static SOAPEnvelope buildsoapMessage(MessageContext messageContext,
        MultipleEntryHashMap requestParameterMap, SOAPFactory soapFactory) throws AxisFault {

    SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope();
    SOAPBody body = soapEnvelope.getBody();
    XmlSchemaElement xmlSchemaElement;//from w  w  w . j ava  2s.  co m
    AxisOperation axisOperation = messageContext.getAxisOperation();
    if (axisOperation != null) {
        AxisMessage axisMessage = axisOperation.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        xmlSchemaElement = axisMessage.getSchemaElement();

        if (xmlSchemaElement == null) {
            OMElement bodyFirstChild = soapFactory.createOMElement(messageContext.getAxisOperation().getName(),
                    body);

            // if there is no schema its piece of cake !! add these to the soap body in any order you like.
            // Note : if there are parameters in the path of the URL, there is no way this can add them
            // to the message.
            createSOAPMessageWithoutSchema(soapFactory, bodyFirstChild, requestParameterMap);
        } else {

            // first get the target namespace from the schema and the wrapping element.
            // create an OMElement out of those information. We are going to extract parameters from
            // url, create OMElements and add them as children to this wrapping element.
            String targetNamespace = xmlSchemaElement.getQName().getNamespaceURI();
            QName bodyFirstChildQName;
            if (targetNamespace != null && !"".equals(targetNamespace)) {
                bodyFirstChildQName = new QName(targetNamespace, xmlSchemaElement.getName());
            } else {
                bodyFirstChildQName = new QName(xmlSchemaElement.getName());
            }
            OMElement bodyFirstChild = soapFactory.createOMElement(bodyFirstChildQName, body);

            // Schema should adhere to the IRI style in this. So assume IRI style and dive in to
            // schema
            XmlSchemaType schemaType = xmlSchemaElement.getSchemaType();
            if (schemaType instanceof XmlSchemaComplexType) {
                XmlSchemaComplexType complexType = ((XmlSchemaComplexType) schemaType);
                XmlSchemaParticle particle = complexType.getParticle();
                if (particle instanceof XmlSchemaSequence || particle instanceof XmlSchemaAll) {
                    XmlSchemaGroupBase xmlSchemaGroupBase = (XmlSchemaGroupBase) particle;
                    Iterator iterator = xmlSchemaGroupBase.getItems().getIterator();

                    // now we need to know some information from the binding operation.

                    while (iterator.hasNext()) {
                        XmlSchemaElement innerElement = (XmlSchemaElement) iterator.next();
                        QName qName = innerElement.getQName();
                        // ignoring the elements without proper type and minoccurs zero
                        if ((innerElement.getSchemaTypeName() == null) && (innerElement.getMinOccurs() == 0)) {
                            continue;
                        }

                        if (qName == null && innerElement.getSchemaTypeName()
                                .equals(org.apache.ws.commons.schema.constants.Constants.XSD_ANYTYPE)) {
                            createSOAPMessageWithoutSchema(soapFactory, bodyFirstChild, requestParameterMap);
                            break;
                        }
                        long minOccurs = innerElement.getMinOccurs();
                        boolean nillable = innerElement.isNillable();
                        String name = qName != null ? qName.getLocalPart() : innerElement.getName();
                        Object value;
                        OMNamespace ns = (qName == null || qName.getNamespaceURI() == null
                                || qName.getNamespaceURI().length() == 0) ? null
                                        : soapFactory.createOMNamespace(qName.getNamespaceURI(), null);

                        // FIXME changed
                        while ((value = requestParameterMap.get(name)) != null) {
                            addRequestParameter(soapFactory, bodyFirstChild, ns, name, value);
                            minOccurs--;
                        }
                        if (minOccurs > 0) {
                            if (nillable) {

                                OMNamespace xsi = soapFactory.createOMNamespace(
                                        Constants.URI_DEFAULT_SCHEMA_XSI, Constants.NS_PREFIX_SCHEMA_XSI);
                                OMAttribute omAttribute = soapFactory.createOMAttribute("nil", xsi, "true");
                                soapFactory.createOMElement(name, ns, bodyFirstChild).addAttribute(omAttribute);

                            } else {
                                throw new AxisFault("Required element " + qName
                                        + " defined in the schema can not be" + " found in the request");
                            }
                        }
                    }
                }
            }
        }
    }
    return soapEnvelope;
}

From source file:org.apache.axis2.client.ServiceClient.java

/**
 * Add a simple header containing some text to be sent with interactions.
 *
 * @param headerName name of header to add
 * @param headerText text content for header
 * @throws AxisFault in case of error// ww w . j  a va2s .  co  m
 */
public void addStringHeader(QName headerName, String headerText) throws AxisFault {
    if (headerName.getNamespaceURI() == null || "".equals(headerName.getNamespaceURI())) {
        throw new AxisFault("Failed to add string header, you have to have namespaceURI for the QName");
    }
    OMElement omElement = OMAbstractFactory.getOMFactory().createOMElement(headerName, null);
    omElement.setText(headerText);
    addHeader(omElement);
}

From source file:org.apache.axis2.client.WSDLBasedPolicyProcessor.java

public void configureOperationPolices(AxisOperation op) throws AxisFault {
    Policy policy = op.getEffectivePolicy();
    if (policy != null) {
        policy = (Policy) policy.normalize(false);

        Set<String> namespaceSet = new HashSet<String>();
        for (List<PolicyComponent> assertionList : policy.getAlternatives()) {
            namespaceSet.clear();//from w  w  w .ja  v a  2 s.  c om

            //First we compute the set of distinct namespaces of assertions
            //of this particular policy alternative.
            for (PolicyComponent assertion : assertionList) {
                if (assertion instanceof Assertion) {
                    QName name = ((Assertion) assertion).getName();
                    String namespaceURI = name.getNamespaceURI();
                    namespaceSet.add(namespaceURI);
                }
            }

            //Compute all modules involved in process assertions that
            //belong to any of the namespaces we found before.
            for (String namespace : namespaceSet) {
                List<AxisModule> modulesToEngage = ns2modules.get(namespace);
                if (modulesToEngage == null) {
                    log.error("Cannot find any modules to process " + namespace + "type assertions");
                    continue;
                } else {
                    engageModulesToAxisDescription(modulesToEngage, op);
                }
            }

            //We only pick the first policy alternative. Other policy
            //alternatives are ignored.  TODO:  maybe we should complain
            //if there are other alternatives given?
            break;
        }
    }
}

From source file:org.apache.axis2.context.externalize.ActivateUtils.java

/**
 * Find the AxisOperation object that matches the criteria
 * /*from  ww w . ja v a2 s .  c o m*/
 * @param service    The AxisService object
 * @param opClassName The class name string for the target object
 *                   (could be a derived class)
 * @param opQName    the name associated with the operation
 * @return the AxisOperation object that matches the given criteria
 */
public static AxisOperation findOperation(AxisService service, String opClassName, QName opQName) {
    if (service == null) {
        return null;
    }

    Iterator ito = service.getOperations();

    // Previous versions of Axis2 didn't use a namespace on the operation name, so they wouldn't
    // have externalized a namespace.  If that's the case, only compare the localPart of the
    // operation name
    String namespace = opQName.getNamespaceURI();
    boolean ignoreNamespace = false;
    if (namespace == null || "".equals(namespace)) {
        ignoreNamespace = true;
    }

    while (ito.hasNext()) {
        AxisOperation operation = (AxisOperation) ito.next();

        String tmpOpName = operation.getClass().getName();
        QName tmpOpQName = operation.getName();

        if ((tmpOpName.equals(opClassName))
                && ((ignoreNamespace && (tmpOpQName.getLocalPart().equals(opQName.getLocalPart()))
                        || (tmpOpQName.equals(opQName))))) {

            if (log.isTraceEnabled()) {
                log.trace("ObjectStateUtils:findOperation(service): ignoreNamespace [" + ignoreNamespace
                        + "] returning  [" + opClassName + "]   [" + opQName.toString() + "]");
            }

            return operation;
        }
    }

    // trace point
    if (log.isTraceEnabled()) {
        log.trace("ObjectStateUtils:findOperation(service): ignoreNamespace [" + ignoreNamespace
                + " classname [" + opClassName + "]  QName [" + opQName.toString() + "]  returning  [null]");
    }

    return null;
}

From source file:org.apache.axis2.corba.receivers.CorbaInOnlyMessageReceiver.java

private void invoke(MessageContext inMessage) throws AxisFault {
    String methodName = null;/*from   ww  w. j a v  a  2  s .co  m*/
    try {
        AxisOperation op = inMessage.getOperationContext().getAxisOperation();
        AxisService service = inMessage.getAxisService();
        OMElement methodElement = inMessage.getEnvelope().getBody().getFirstElement();

        AxisMessage inAxisMessage = op.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        String messageNameSpace;
        QName elementQName;
        methodName = op.getName().getLocalPart();

        Invoker invoker = (Invoker) invokerCache.get(methodName);
        if (invoker == null) {
            if (orb == null) {
                Parameter orbParam = service.getParameter(ORB_LITERAL);
                orb = orbParam != null ? (ORB) orbParam.getValue() : CorbaUtil.getORB(service);
            }
            org.omg.CORBA.Object obj = CorbaUtil.resolveObject(service, orb);
            Parameter idlParameter = service.getParameter(IDL_LITERAL);
            if (idlParameter == null)
                throw new CorbaInvocationException("No IDL found");
            IDL idl = (IDL) idlParameter.getValue();
            invoker = CorbaUtil.getInvoker(service, obj, idl, methodName);
            invokerCache.put(methodName, invoker);
        }

        if (inAxisMessage != null) {
            if (inAxisMessage.getElementQName() != null) {
                elementQName = inAxisMessage.getElementQName();
                messageNameSpace = elementQName.getNamespaceURI();
                OMNamespace namespace = methodElement.getNamespace();
                if (messageNameSpace != null) {
                    if (namespace == null || !messageNameSpace.equals(namespace.getNamespaceURI())) {
                        throw new AxisFault("namespace mismatch require " + messageNameSpace + " found "
                                + methodElement.getNamespace().getNamespaceURI());
                    }
                } else if (namespace != null) {
                    throw new AxisFault("namespace mismatch. Axis Oepration expects non-namespace "
                            + "qualified element. But received a namespace qualified element");
                }

                Object[] objectArray = CorbaUtil.extractParameters(methodElement,
                        invoker.getParameterMembers());
                invoker.setParameters(objectArray);
            }
            invoker.invoke();
        }
    } catch (CorbaInvocationException e) {
        String msg;
        Throwable cause = e.getCause();
        if (cause != null) {
            msg = cause.getMessage();
            if (msg == null) {
                msg = "Exception occurred while trying to invoke service method " + methodName;
            }
            //log.error(msg, e);
            if (cause instanceof AxisFault) {
                throw (AxisFault) cause;
            }
        } else {
            msg = e.getMessage();
        }
        throw new AxisFault(msg);
    }
}

From source file:org.apache.axis2.corba.receivers.CorbaInOutAsyncMessageReceiver.java

private void invoke(MessageContext inMessage, MessageContext outMessage) throws AxisFault {
    String methodName = null;//w  ww.ja  v  a2  s . c o m
    try {
        AxisOperation op = inMessage.getOperationContext().getAxisOperation();
        AxisService service = inMessage.getAxisService();
        OMElement methodElement = inMessage.getEnvelope().getBody().getFirstElement();

        AxisMessage inAxisMessage = op.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        String messageNameSpace = null;
        QName elementQName;
        methodName = op.getName().getLocalPart();

        Invoker invoker = (Invoker) invokerCache.get(methodName);
        if (invoker == null) {
            if (orb == null) {
                Parameter orbParam = service.getParameter(ORB_LITERAL);
                orb = orbParam != null ? (ORB) orbParam.getValue() : CorbaUtil.getORB(service);
            }
            org.omg.CORBA.Object obj = CorbaUtil.resolveObject(service, orb);
            Parameter idlParameter = service.getParameter(IDL_LITERAL);
            if (idlParameter == null)
                throw new CorbaInvocationException("IDL not found");
            IDL idl = (IDL) idlParameter.getValue();
            invoker = CorbaUtil.getInvoker(service, obj, idl, methodName);
            invokerCache.put(methodName, invoker);
        }

        Object resObject = null;
        Member[] params = null;
        Object[] outParamValues = null;
        if (inAxisMessage != null) {
            if (inAxisMessage.getElementQName() != null) {
                elementQName = inAxisMessage.getElementQName();
                messageNameSpace = elementQName.getNamespaceURI();
                OMNamespace namespace = methodElement.getNamespace();
                if (messageNameSpace != null) {
                    if (namespace == null || !messageNameSpace.equals(namespace.getNamespaceURI())) {
                        throw new AxisFault("namespace mismatch require " + messageNameSpace + " found "
                                + methodElement.getNamespace().getNamespaceURI());
                    }
                } else if (namespace != null) {
                    throw new AxisFault("namespace mismatch. Axis Oepration expects non-namespace "
                            + "qualified element. But received a namespace qualified element");
                }

                Object[] objectArray = CorbaUtil.extractParameters(methodElement,
                        invoker.getParameterMembers());
                invoker.setParameters(objectArray);
                params = invoker.getParameterMembers();
                outParamValues = invoker.getOutParameterValuess();
            }
            resObject = invoker.invoke();
        }
        SOAPFactory fac = getSOAPFactory(inMessage);

        AxisMessage outaxisMessage = op.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
        if (messageNameSpace == null) {
            QName qname = outaxisMessage.getElementQName();
            if (qname != null) {
                messageNameSpace = qname.getNamespaceURI();
            }
        }
        // Handling the response
        CorbaUtil.processResponse(resObject, params, outParamValues, invoker.getReturnType(), service,
                methodName, fac, messageNameSpace, outMessage);
    } catch (CorbaInvocationException e) {
        String msg;
        Throwable cause = e.getCause();
        if (cause != null) {
            msg = cause.getMessage();
            if (msg == null) {
                msg = "Exception occurred while trying to invoke service method " + methodName;
            }
            //log.error(msg, e);
            if (cause instanceof AxisFault) {
                throw (AxisFault) cause;
            }
        } else {
            msg = e.getMessage();
        }
        throw new AxisFault(msg);
    }
}

From source file:org.apache.axis2.corba.receivers.CorbaMessageReceiver.java

private void invoke(MessageContext inMessage, MessageContext outMessage) throws AxisFault {
    String methodName = null;// www  .  j a va 2s. c  o  m
    try {
        AxisOperation op = inMessage.getOperationContext().getAxisOperation();
        AxisService service = inMessage.getAxisService();
        OMElement methodElement = inMessage.getEnvelope().getBody().getFirstElement();
        AxisMessage inAxisMessage = op.getMessage(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
        String messageNameSpace = null;
        QName elementQName;
        methodName = op.getName().getLocalPart();

        Invoker invoker = (Invoker) invokerCache.get(methodName);
        if (invoker == null) {
            if (orb == null) {
                Parameter orbParam = service.getParameter(ORB_LITERAL);
                orb = orbParam != null ? (ORB) orbParam.getValue() : CorbaUtil.getORB(service);
            }
            org.omg.CORBA.Object obj = CorbaUtil.resolveObject(service, orb);
            Parameter idlParameter = service.getParameter(IDL_LITERAL);
            if (idlParameter == null)
                throw new CorbaInvocationException("IDL not found");
            IDL idl = (IDL) idlParameter.getValue();
            invoker = CorbaUtil.getInvoker(service, obj, idl, methodName);
            invokerCache.put(methodName, invoker);
        }

        Object resObject = null;
        Member[] params = null;
        Object[] outParamValues = null;
        if (inAxisMessage != null) {
            if (inAxisMessage.getElementQName() != null) {
                elementQName = inAxisMessage.getElementQName();
                messageNameSpace = elementQName.getNamespaceURI();
                OMNamespace namespace = methodElement.getNamespace();
                if (messageNameSpace != null) {
                    if (namespace == null) {
                        throw new AxisFault("namespace mismatch require " + messageNameSpace + " found none");
                    }
                    if (!messageNameSpace.equals(namespace.getNamespaceURI())) {
                        throw new AxisFault("namespace mismatch require " + messageNameSpace + " found "
                                + methodElement.getNamespace().getNamespaceURI());
                    }
                } else if (namespace != null) {
                    throw new AxisFault("namespace mismatch. Axis Oepration expects non-namespace "
                            + "qualified element. But received a namespace qualified element");
                }
                Object[] objectArray = CorbaUtil.extractParameters(methodElement,
                        invoker.getParameterMembers());
                invoker.setParameters(objectArray);
            }
            resObject = invoker.invoke();
            params = invoker.getParameterMembers();
            outParamValues = invoker.getOutParameterValuess();
        }

        if (messageNameSpace == null) {
            AxisMessage outaxisMessage = op.getMessage(WSDLConstants.MESSAGE_LABEL_OUT_VALUE);
            QName qname = outaxisMessage.getElementQName();
            if (qname != null) {
                messageNameSpace = qname.getNamespaceURI();
            }
        }

        // Handling the response
        SOAPFactory fac = getSOAPFactory(inMessage);
        CorbaUtil.processResponse(resObject, params, outParamValues, invoker.getReturnType(), service,
                methodName, fac, messageNameSpace, outMessage);
    } catch (CorbaInvocationException e) {
        String msg;
        Throwable cause = e.getCause();
        if (cause != null) {
            msg = cause.getMessage();
            if (msg == null) {
                msg = "Exception occurred while trying to invoke service method " + methodName;
            }
            //log.error(msg, e);
            if (cause instanceof AxisFault) {
                throw (AxisFault) cause;
            }
        } else {
            msg = e.getMessage();
        }
        throw new AxisFault(msg, e);
    }
}

From source file:org.apache.axis2.corba.receivers.CorbaUtil.java

private static OMNamespace getNameSpaceForType(SOAPFactory fac, AxisService service,
        CompositeDataType dataType) {//from   w ww . ja v  a  2 s . co  m
    TypeTable typeTable = service.getTypeTable();
    String fullname = (dataType.getModule() != null) ? dataType.getModule() + dataType.getName()
            : dataType.getName();
    fullname = fullname.replaceAll(CompositeDataType.MODULE_SEPERATOR, ".");
    QName qname = typeTable.getQNamefortheType(fullname);
    if (qname == null)
        return null;
    return fac.createOMNamespace(qname.getNamespaceURI(), qname.getPrefix());
}

From source file:org.apache.axis2.databinding.utils.ConverterUtil.java

public static void serializeAnyType(Object value, XMLStreamWriter xmlStreamWriter) throws XMLStreamException {
    if (value instanceof String) {
        serializeAnyType("string", value.toString(), xmlStreamWriter);
    } else if (value instanceof Integer) {
        serializeAnyType("int", value.toString(), xmlStreamWriter);
    } else if (value instanceof Boolean) {
        serializeAnyType("boolean", value.toString(), xmlStreamWriter);
    } else if (value instanceof URI) {
        serializeAnyType("anyURI", value.toString(), xmlStreamWriter);
    } else if (value instanceof Byte) {
        serializeAnyType("byte", value.toString(), xmlStreamWriter);
    } else if (value instanceof Date) {
        serializeAnyType("date", convertToString((Date) value), xmlStreamWriter);
    } else if (value instanceof Calendar) {
        serializeAnyType("dateTime", convertToString((Calendar) value), xmlStreamWriter);
    } else if (value instanceof Time) {
        serializeAnyType("time", convertToString((Time) value), xmlStreamWriter);
    } else if (value instanceof Float) {
        serializeAnyType("float", value.toString(), xmlStreamWriter);
    } else if (value instanceof Long) {
        serializeAnyType("long", value.toString(), xmlStreamWriter);
    } else if (value instanceof Double) {
        serializeAnyType("double", value.toString(), xmlStreamWriter);
    } else if (value instanceof Short) {
        serializeAnyType("short", value.toString(), xmlStreamWriter);
    } else if (value instanceof BigDecimal) {
        serializeAnyType("decimal", ((BigDecimal) value).toPlainString(), xmlStreamWriter);
    } else if (value instanceof DataHandler) {
        addTypeAttribute(xmlStreamWriter, "base64Binary");
        try {/* ww  w  . ja  v a 2  s  .  c  o  m*/
            XMLStreamWriterUtils.writeDataHandler(xmlStreamWriter, (DataHandler) value, null, true);
        } catch (IOException ex) {
            throw new XMLStreamException("Unable to read data handler", ex);
        }
    } else if (value instanceof QName) {
        QName qNameValue = (QName) value;
        String prefix = xmlStreamWriter.getPrefix(qNameValue.getNamespaceURI());
        if (prefix == null) {
            prefix = BeanUtil.getUniquePrefix();
            xmlStreamWriter.writeNamespace(prefix, qNameValue.getNamespaceURI());
            xmlStreamWriter.setPrefix(prefix, qNameValue.getNamespaceURI());
        }
        String attributeValue = qNameValue.getLocalPart();
        if (!prefix.equals("")) {
            attributeValue = prefix + ":" + attributeValue;
        }
        serializeAnyType("QName", attributeValue, xmlStreamWriter);
    } else if (value instanceof UnsignedByte) {
        serializeAnyType("unsignedByte", convertToString((UnsignedByte) value), xmlStreamWriter);
    } else if (value instanceof UnsignedLong) {
        serializeAnyType("unsignedLong", convertToString((UnsignedLong) value), xmlStreamWriter);
    } else if (value instanceof UnsignedShort) {
        serializeAnyType("unsignedShort", convertToString((UnsignedShort) value), xmlStreamWriter);
    } else if (value instanceof UnsignedInt) {
        serializeAnyType("unsignedInt", convertToString((UnsignedInt) value), xmlStreamWriter);
    } else if (value instanceof PositiveInteger) {
        serializeAnyType("positiveInteger", convertToString((PositiveInteger) value), xmlStreamWriter);
    } else if (value instanceof NegativeInteger) {
        serializeAnyType("negativeInteger", convertToString((NegativeInteger) value), xmlStreamWriter);
    } else if (value instanceof NonNegativeInteger) {
        serializeAnyType("nonNegativeInteger", convertToString((NonNegativeInteger) value), xmlStreamWriter);
    } else if (value instanceof NonPositiveInteger) {
        serializeAnyType("nonPositiveInteger", convertToString((NonPositiveInteger) value), xmlStreamWriter);
    } else {
        throw new XMLStreamException("Unknow type can not serialize");
    }
}