List of usage examples for javax.xml.namespace QName getLocalPart
public String getLocalPart()
Get the local part of this QName
.
From source file:org.apache.axis.encoding.SerializationContext.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 ava 2 s . co m public void startElement(QName qName, Attributes attributes) throws IOException { java.util.ArrayList vecQNames = null; if (debugEnabled) { log.debug(Messages.getMessage("startElem00", "[" + qName.getNamespaceURI() + "]:" + qName.getLocalPart())); } if (startOfDocument && sendXMLDecl) { writeXMLDeclaration(); } 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 (writeXMLType != null) { attributes = setTypeAttribute(attributes, writeXMLType); writeXMLType = null; } 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("=\""); getEncoder().writeEncoded(writer, attributes.getValue(i)); writer.write('"'); } } if (noNamespaceMappings) { nsStack.push(); } else { for (Mapping map = nsStack.topOfFrame(); map != null; map = nsStack.next()) { if (!(map.getNamespaceURI().equals(Constants.NS_URI_XMLNS) && map.getPrefix().equals("xmlns")) && !(map.getNamespaceURI().equals(Constants.NS_URI_XML) && map.getPrefix().equals("xml"))) { 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.SerializationContext.java
/** * Obtains the type attribute that should be serialized and returns the new list of Attributes * @param attributes of the qname//from w w w . ja v a 2s .co m * @param type is the qname of the type * @return new list of Attributes */ public Attributes setTypeAttribute(Attributes attributes, QName type) { SchemaVersion schema = SchemaVersion.SCHEMA_2001; if (msgContext != null) { schema = msgContext.getSchemaVersion(); } if (type == null || type.getLocalPart().indexOf(SymbolTable.ANON_TOKEN) >= 0 || ((attributes != null) && (attributes.getIndex(schema.getXsiURI(), "type") != -1))) return attributes; AttributesImpl attrs = new AttributesImpl(); if (attributes != null && 0 < attributes.getLength()) attrs.setAttributes(attributes); String prefix = getPrefixForURI(schema.getXsiURI(), "xsi"); attrs.addAttribute(schema.getXsiURI(), "type", prefix + ":type", "CDATA", attributeQName2String(type)); return attrs; }
From source file:org.apache.axis.encoding.SerializationContext.java
/** * Returns the java class for serialization. * If the xmlType is xsd:anyType or javaType is array or javaType is java.lang.Object * the java class for serialization is the class of obj. * If the obj is not array and the obj's class does not match with the javaType, * the java class for serialization is the javaType. * Otherwise, the java class for serialization is the obj's class. * /*from ww w. j a v a 2 s . c o m*/ * @param xmlType the qname of xml type * @param javaType the java class from serializer * @param obj the object to serialize * @return the java class for serialization */ private Class getActualJavaClass(QName xmlType, Class javaType, Object obj) { Class cls = obj.getClass(); if ((xmlType != null && Constants.isSchemaXSD(xmlType.getNamespaceURI()) && "anyType".equals(xmlType.getLocalPart())) || (javaType != null && (javaType.isArray() || javaType == Object.class))) { return cls; } if (javaType != null && !javaType.isAssignableFrom(cls) && !cls.isArray()) { return javaType; } return cls; }
From source file:org.apache.axis.encoding.SerializationContextImpl.java
/** * Convert QName to a string of the form <prefix>:<localpart> * @param qName//from w w w .ja va2s .co m * @return prefixed qname representation for serialization. */ public String qName2String(QName qName, boolean writeNS) { String prefix = null; String namespaceURI = qName.getNamespaceURI(); if (namespaceURI.length() == 0) { if (writeNS) { // If this is unqualified (i.e. prefix ""), set the default // namespace to "" String defaultNS = nsStack.getNamespaceURI(""); if (defaultNS != null && defaultNS.length() > 0) { registerPrefixForURI("", ""); } } } else { prefix = getPrefixForURI(namespaceURI); } if ((prefix == null) || (prefix.length() == 0)) return qName.getLocalPart(); StringBuffer sb = new StringBuffer(prefix); sb.append(':'); sb.append(qName.getLocalPart()); return sb.toString(); }
From source file:org.apache.axis.encoding.SerializationContextImpl.java
/** * Convert attribute QName to a string of the form <prefix>:<localpart> * There are slightly different rules for attributes: * - There is no default namespace/* w w w . ja v a2 s . c o m*/ * - any attribute in a namespace must have a prefix * * @param qName QName * @return prefixed qname representation for serialization. */ public String attributeQName2String(QName qName) { String prefix = null; if (qName.getNamespaceURI().length() > 0) { prefix = getPrefixForURI(qName.getNamespaceURI(), null, true); } if ((prefix == null) || (prefix.length() == 0)) return qName.getLocalPart(); StringBuffer sb = new StringBuffer(prefix); sb.append(':'); sb.append(qName.getLocalPart()); return sb.toString(); }
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 *///w w w . java 2 s. co m 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.SerializationContextImpl.java
/** * Obtains the type attribute that should be serialized and returns the new list of Attributes * @param attributes of the qname//w ww . j a va 2 s . c o m * @param type is the qname of the type * @return new list of Attributes */ public Attributes setTypeAttribute(Attributes attributes, QName type) { if (type == null || type.getLocalPart().indexOf(SymbolTable.ANON_TOKEN) >= 0 || ((attributes != null) && (attributes.getIndex(Constants.URI_DEFAULT_SCHEMA_XSI, "type") != -1))) return attributes; AttributesImpl attrs = new AttributesImpl(); if (attributes != null && 0 < attributes.getLength() ) attrs.setAttributes(attributes); String prefix = getPrefixForURI(Constants.URI_DEFAULT_SCHEMA_XSI, "xsi"); attrs.addAttribute(Constants.URI_DEFAULT_SCHEMA_XSI, "type", prefix + ":type", "CDATA", attributeQName2String(type)); return attrs; }
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 www . j a v a2 s . c o m * * @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 . j av a2 s . c o m //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 w w . j a va2 s . c om */ public MessageElement(QName name) { this(name.getNamespaceURI(), name.getLocalPart()); }