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.axis.encoding.SerializationContextImpl.java

/**
 * Indicates whether the object should be interpretted as a primitive
 * for the purposes of multi-ref processing.  A primitive value
 * is serialized directly instead of using id/href pairs.  Thus
 * primitive serialization/deserialization is slightly faster.
 * @param value to be serialized//from  www .  java  2 s.c om
 * @return true/false
 */
public boolean isPrimitive(Object value)
{
    if (value == null) return true;

    Class javaType = value.getClass();

    if (javaType.isPrimitive()) return true;

    if (javaType == String.class) return true;
    if (Calendar.class.isAssignableFrom(javaType)) return true;
    if (Date.class.isAssignableFrom(javaType)) return true;
    if (HexBinary.class.isAssignableFrom(javaType)) return true;
    if (Element.class.isAssignableFrom(javaType)) return true;
    if (javaType == byte[].class) return true;

    // There has been discussion as to whether arrays themselves should
    // be regarded as multi-ref.
    // Here are the three options:
    //   1) Arrays are full-fledged Objects and therefore should always be
    //      multi-ref'd  (Pro: This is like java.  Con: Some runtimes don't
    //      support this yet, and it requires more stuff to be passed over the wire.)
    //   2) Arrays are not full-fledged Objects and therefore should
    //      always be passed as single ref (note the elements of the array
    //      may be multi-ref'd.) (Pro:  This seems reasonable, if a user
    //      wants multi-referencing put the array in a container.  Also
    //      is more interop compatible.  Con: Not like java serialization.)
    //   3) Arrays of primitives should be single ref, and arrays of
    //      non-primitives should be multi-ref.  (Pro: Takes care of the
    //      looping case.  Con: Seems like an obtuse rule.)
    //
    // Changing the code from (1) to (2) to see if interop fairs better.
    if (javaType.isArray()) return true;

    // Note that java.lang wrapper classes (i.e. java.lang.Integer) are
    // not primitives unless the corresponding type is an xsd type.
    // (If the wrapper maps to a soap encoded primitive, it can be nillable
    // and multi-ref'd).
    QName qName = getQNameForClass(javaType);
    if (qName != null && Constants.isSchemaXSD(qName.getNamespaceURI())) {
        if (SchemaUtils.isSimpleSchemaType(qName)) {
            return true;
        }
    }

    return false;
}

From source file:org.apache.axis.encoding.SerializationContextImpl.java

/**
 * Writes (using the Writer) the start tag for element QName along with the
 * indicated attributes and namespace mappings.
 * @param qName is the name of the element
 * @param attributes are the attributes to write
 *//*from   w ww  .j a  va  2  s  .c  om*/
public void startElement(QName qName, Attributes attributes)
    throws IOException
{
    java.util.ArrayList vecQNames = null;
    if (log.isDebugEnabled()) {
        log.debug(Messages.getMessage("startElem00",
                "[" + qName.getNamespaceURI() + "]:" + qName.getLocalPart()));
    }

    if (startOfDocument && sendXMLDecl) {
        writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        startOfDocument = false;
    }

    if (writingStartTag) {
        writer.write('>');
        if (pretty) writer.write('\n');
        indent++;
    }

    if (pretty) for (int i=0; i<indent; i++) writer.write(' ');
    String elementQName = qName2String(qName, true);
    writer.write('<');

    writer.write(elementQName);

    if (attributes != null) {
        for (int i = 0; i < attributes.getLength(); i++) {
            String qname = attributes.getQName(i);
            writer.write(' ');

            String prefix = "";
            String uri = attributes.getURI(i);
            if (uri != null && uri.length() > 0) {
                if (qname.length() == 0) {
                    // If qname isn't set, generate one
                    prefix = getPrefixForURI(uri);
                } else {
                    // If it is, make sure the prefix looks reasonable.
                    int idx = qname.indexOf(':');
                    if (idx > -1) {
                        prefix = qname.substring(0, idx);
                        prefix = getPrefixForURI(uri,
                                                 prefix, true);
                    }
                }
                if (prefix.length() > 0) {
                    qname = prefix + ':' + attributes.getLocalName(i);
                } else {
                    qname = attributes.getLocalName(i);
                }
            } else {
               qname = attributes.getQName(i);
                if(qname.length() == 0)
                    qname = attributes.getLocalName(i);
            }

            if (qname.startsWith("xmlns")) {
              if (vecQNames == null) vecQNames = new ArrayList();
              vecQNames.add(qname);
            }
            writer.write(qname);
            writer.write("=\"");
            writer.write(XMLUtils.xmlEncodeString(attributes.getValue(i)));
            writer.write('"');
        }
    }

    if (noNamespaceMappings) {
        nsStack.push();
    } else {
        for (Mapping map=nsStack.topOfFrame(); map!=null; map=nsStack.next()) {
            StringBuffer sb = new StringBuffer("xmlns");
            if (map.getPrefix().length() > 0) {
                sb.append(':');
                sb.append(map.getPrefix());
            }
            if ((vecQNames==null) || (vecQNames.indexOf(sb.toString())==-1)) {
                writer.write(' ');
                sb.append("=\"");
                sb.append(map.getNamespaceURI());
                sb.append('"');
                writer.write(sb.toString());
            }
        }

        noNamespaceMappings = true;
    }

    writingStartTag = true;

    elementStack.push(elementQName);

    onlyXML=true;
}

From source file:org.apache.axis.encoding.TypeMappingImpl.java

/**
 * Gets the SerializerFactory registered for the specified pair
 * of Java type and XML data type.//  w  w w  .ja  v a2 s .c o m
 *
 * @param javaType - Class of the Java type
 * @param xmlType - Qualified name of the XML data type
 *
 * @return Registered SerializerFactory
 *
 * @throws JAXRPCException - If there is no registered SerializerFactory
 * for this pair of Java type and XML data type
 * java.lang.IllegalArgumentException -
 * If invalid or unsupported XML/Java type is specified
 */
public javax.xml.rpc.encoding.SerializerFactory getSerializer(Class javaType, QName xmlType)
        throws JAXRPCException {

    javax.xml.rpc.encoding.SerializerFactory sf = null;

    // If the xmlType was not provided, get one
    if (xmlType == null) {
        xmlType = getTypeQName(javaType, null);
        // If we couldn't find one, we're hosed, since getTypeQName()
        // already asked all of our delegates.
        if (xmlType == null) {
            return null;
        }
    }

    // Try to get the serializer associated with this pair
    Pair pair = new Pair(javaType, xmlType);

    // Now get the serializer with the pair
    sf = (javax.xml.rpc.encoding.SerializerFactory) pair2SF.get(pair);

    // Need to look into hierarchy of component type.
    // ex) java.util.GregorianCalendar[]
    //     -> java.util.Calendar[]
    if (sf == null && javaType.isArray()) {
        int dimension = 1;
        Class componentType = javaType.getComponentType();
        while (componentType.isArray()) {
            dimension += 1;
            componentType = componentType.getComponentType();
        }
        int[] dimensions = new int[dimension];
        componentType = componentType.getSuperclass();
        Class superJavaType = null;
        while (componentType != null) {
            superJavaType = Array.newInstance(componentType, dimensions).getClass();
            pair = new Pair(superJavaType, xmlType);
            sf = (javax.xml.rpc.encoding.SerializerFactory) pair2SF.get(pair);
            if (sf != null) {
                break;
            }
            componentType = componentType.getSuperclass();
        }
    }

    // check if ArrayOfT(xml)->T[](java) conversion is possible
    if (sf == null && javaType.isArray() && xmlType != null) {
        Pair pair2 = (Pair) qName2Pair.get(xmlType);
        if (pair2 != null && pair2.javaType != null && !pair2.javaType.isPrimitive()
                && ArrayUtil.isConvertable(pair2.javaType, javaType)) {
            sf = (javax.xml.rpc.encoding.SerializerFactory) pair2SF.get(pair2);
        }
    }

    // find serializer with xmlType
    if (sf == null && !javaType.isArray() && !Constants.isSchemaXSD(xmlType.getNamespaceURI())
            && !Constants.isSOAP_ENC(xmlType.getNamespaceURI())) {
        Pair pair2 = (Pair) qName2Pair.get(xmlType);
        if (pair2 != null && pair2.javaType != null && !pair2.javaType.isArray() // for array
                && (javaType.isAssignableFrom(pair2.javaType) || (pair2.javaType.isPrimitive()
                        && javaType == JavaUtils.getWrapperClass(pair2.javaType)))) // for derived type (xsd:restriction) 
        {
            sf = (javax.xml.rpc.encoding.SerializerFactory) pair2SF.get(pair2);
        }
    }

    return sf;
}

From source file:org.apache.axis.encoding.TypeMappingImpl.java

/**
 * Get the QName for this Java class, but only return a specific
 * mapping if there is one.  In other words, don't do special array
 * processing, etc./*from w ww .java2 s  . c om*/
 * 
 * @param javaType
 * @return
 */
public QName getTypeQNameExact(Class javaType, TypeMappingDelegate next) {
    if (javaType == null)
        return null;

    QName xmlType = null;
    Pair pair = (Pair) class2Pair.get(javaType);

    if (isDotNetSoapEncFixNeeded() && pair != null) {
        // Hack alert!
        // If we are in .NET bug compensation mode, skip over any
        // SOAP Encoded types we my find and prefer XML Schema types
        xmlType = pair.xmlType;
        if (Constants.isSOAP_ENC(xmlType.getNamespaceURI()) && !xmlType.getLocalPart().equals("Array")) {
            pair = null;
        }
    }

    if (pair == null && next != null) {
        // Keep checking up the stack...
        xmlType = next.delegate.getTypeQNameExact(javaType, next.next);
    }

    if (pair != null) {
        xmlType = pair.xmlType;
    }

    return xmlType;
}

From source file:org.apache.axis.encoding.TypeMappingImpl.java

public Class getClassForQName(QName xmlType, Class javaType, TypeMappingDelegate next) {
    if (xmlType == null) {
        return null;
    }//from   www.ja  v  a 2  s.  c  om

    //log.debug("getClassForQName xmlType =" + xmlType);

    if (javaType != null) {
        // Looking for an exact match first
        Pair pair = new Pair(javaType, xmlType);
        if (pair2DF.get(pair) == null) {
            if (next != null) {
                javaType = next.getClassForQName(xmlType, javaType);
            }
        }
    }

    if (javaType == null) {
        //look for it in our map
        Pair pair = (Pair) qName2Pair.get(xmlType);
        if (pair == null && next != null) {
            //on no match, delegate
            javaType = next.getClassForQName(xmlType);
        } else if (pair != null) {
            javaType = pair.javaType;
        }
    }

    //log.debug("getClassForQName javaType =" + javaType);
    if (javaType == null && shouldDoAutoTypes()) {
        String pkg = Namespaces.getPackage(xmlType.getNamespaceURI());
        if (pkg != null) {
            String className = xmlType.getLocalPart();
            if (pkg.length() > 0) {
                className = pkg + "." + className;
            }
            try {
                javaType = ClassUtils.forName(className);
                internalRegister(javaType, xmlType, new BeanSerializerFactory(javaType, xmlType),
                        new BeanDeserializerFactory(javaType, xmlType));
            } catch (ClassNotFoundException e) {
            }
        }
    }
    return javaType;
}

From source file:org.apache.axis.message.MessageElement.java

/**
 * constructor declaring the qualified name of the node
 * @param name naming information/*from  w ww.  jav  a  2s  .com*/
 */
public MessageElement(QName name) {
    this(name.getNamespaceURI(), name.getLocalPart());
}

From source file:org.apache.axis.message.MessageElement.java

/**
 * constructor declaring the qualified name of the node
 * and its value//from  w w  w .ja v  a 2 s .c om
 * @param name naming information
 * @param value value of the node
 */
public MessageElement(QName name, Object value) {
    this(name.getNamespaceURI(), name.getLocalPart());
    objectValue = value;
}

From source file:org.apache.axis.message.MessageElement.java

/**
 * set the name and namespace of this element
 * @param qName qualified name//from  www .j  av  a2  s  .c o  m
 */
public void setQName(QName qName) {
    this.name = qName.getLocalPart();
    this.namespaceURI = qName.getNamespaceURI();
}

From source file:org.apache.axis.message.MessageElement.java

/** This is the public output() method, which will always simply use
 * the recorded SAX stream for this element if it is available.  If
 * not, this method calls outputImpl() to allow subclasses and
 * programmatically created messages to serialize themselves.
 *
 * @param outputContext the SerializationContext we will write to.
 *//*from  w  w  w  .  jav  a 2s  .  c om*/
public final void output(SerializationContext outputContext) throws Exception {
    if ((recorder != null) && (!_isDirty)) {
        recorder.replay(startEventIndex, endEventIndex, new SAXOutputter(outputContext));
        return;
    }

    // Turn QName attributes into strings
    if (qNameAttrs != null) {
        for (int i = 0; i < qNameAttrs.size(); i++) {
            QNameAttr attr = (QNameAttr) qNameAttrs.get(i);
            QName attrName = attr.name;
            setAttribute(attrName.getNamespaceURI(), attrName.getLocalPart(),
                    outputContext.qName2String(attr.value));
        }
    }

    /**
     * Write the encoding style attribute IF it's different from
     * whatever encoding style is in scope....
     */
    if (encodingStyle != null) {
        MessageContext mc = outputContext.getMessageContext();
        SOAPConstants soapConstants = (mc != null) ? mc.getSOAPConstants() : SOAPConstants.SOAP11_CONSTANTS;
        if (parent == null) {
            // don't emit an encoding style if its "" (literal)
            if (!"".equals(encodingStyle)) {
                setAttribute(soapConstants.getEnvelopeURI(), Constants.ATTR_ENCODING_STYLE, encodingStyle);
            }
        } else if (!encodingStyle.equals(((MessageElement) parent).getEncodingStyle())) {
            setAttribute(soapConstants.getEnvelopeURI(), Constants.ATTR_ENCODING_STYLE, encodingStyle);
        }
    }

    outputImpl(outputContext);
}

From source file:org.apache.axis.message.MessageElement.java

/**
 * get an iterator over child elements/*from   w  w  w  . j a v a  2  s.  c o m*/
 * @param qname namespace/element name of parts to find.
 * This iterator is not (currently) susceptible to change in the element
 * list during its lifetime, though changes in the contents of the elements
 * are picked up.
 * @return an iterator.
 */
public Iterator getChildElements(QName qname) {
    initializeChildren();
    int num = children.size();
    Vector c = new Vector(num);
    for (int i = 0; i < num; i++) {
        MessageElement child = (MessageElement) children.get(i);
        Name cname = child.getElementName();
        if (cname.getURI().equals(qname.getNamespaceURI())
                && cname.getLocalName().equals(qname.getLocalPart())) {
            c.add(child);
        }
    }
    return c.iterator();
}