public final boolean equals(Object obj) { if (this == obj) { return true; } else if (obj instanceof OMAttribute) { try { OMAttribute other = (OMAttribute) obj; // TODO: using getNamespace is not efficient because it will create a new OMNamespace // instance return coreGetLocalName().equals(other.getLocalName()) && ObjectUtils.equals(getNamespace(), other.getNamespace()) && getAttributeValue().equals(other.getAttributeValue()); } catch (CoreModelException ex) { throw AxiomExceptionTranslator.translate(ex); } } else { return false; } }
@Override public void serialize( final javax.xml.namespace.QName parentQName, final javax.xml.stream.XMLStreamWriter xmlWriter, final boolean serializeType) throws javax.xml.stream.XMLStreamException { java.lang.String prefix = null; java.lang.String namespace = null; prefix = parentQName.getPrefix(); namespace = parentQName.getNamespaceURI(); this.writeStartElement(prefix, namespace, parentQName.getLocalPart(), xmlWriter); if (serializeType) { final java.lang.String namespacePrefix = this.registerPrefix( xmlWriter, "http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2"); if ((namespacePrefix != null) && (namespacePrefix.trim().length() > 0)) { this.writeAttribute( "xsi", "http://www.w3.org/2001/XMLSchema-instance", "type", namespacePrefix + ":nfeCabecMsg", xmlWriter); } else { this.writeAttribute( "xsi", "http://www.w3.org/2001/XMLSchema-instance", "type", "nfeCabecMsg", xmlWriter); } } if (this.localExtraAttributes != null) { for (OMAttribute localExtraAttribute : this.localExtraAttributes) { this.writeAttribute( localExtraAttribute.getNamespace().getNamespaceURI(), localExtraAttribute.getLocalName(), localExtraAttribute.getAttributeValue(), xmlWriter); } } if (this.localVersaoDadosTracker) { namespace = "http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2"; this.writeStartElement(null, namespace, "versaoDados", xmlWriter); if (this.localVersaoDados == null) { // write the nil attribute throw new org.apache.axis2.databinding.ADBException("versaoDados cannot be null!!"); } else { xmlWriter.writeCharacters(this.localVersaoDados); } xmlWriter.writeEndElement(); } if (this.localCUFTracker) { namespace = "http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2"; this.writeStartElement(null, namespace, "cUF", xmlWriter); if (this.localCUF == null) { // write the nil attribute throw new org.apache.axis2.databinding.ADBException("cUF cannot be null!!"); } else { xmlWriter.writeCharacters(this.localCUF); } xmlWriter.writeEndElement(); } xmlWriter.writeEndElement(); }
/** * Builds a SOAPEnvelope from DOM Document. * * @param doc - The dom document that contains a SOAP message * @param useDoom * @return * @throws WSSecurityException */ public static SOAPEnvelope getSOAPEnvelopeFromDOMDocument(Document doc, boolean useDoom) throws WSSecurityException { if (useDoom) { try { // Get processed headers SOAPEnvelope env = (SOAPEnvelope) doc.getDocumentElement(); ArrayList processedHeaderQNames = new ArrayList(); SOAPHeader soapHeader = env.getHeader(); if (soapHeader != null) { Iterator headerBlocs = soapHeader.getChildElements(); while (headerBlocs.hasNext()) { OMElement element = (OMElement) headerBlocs.next(); SOAPHeaderBlock header = null; if (element instanceof SOAPHeaderBlock) { header = (SOAPHeaderBlock) element; // If a header block is not an instance of SOAPHeaderBlock, it means that // it is a header we have added in rampart eg. EncryptedHeader and should // be converted to SOAPHeaderBlock for processing } else { header = soapHeader.addHeaderBlock(element.getLocalName(), element.getNamespace()); Iterator attrIter = element.getAllAttributes(); while (attrIter.hasNext()) { OMAttribute attr = (OMAttribute) attrIter.next(); header.addAttribute( attr.getLocalName(), attr.getAttributeValue(), attr.getNamespace()); } Iterator nsIter = element.getAllDeclaredNamespaces(); while (nsIter.hasNext()) { OMNamespace ns = (OMNamespace) nsIter.next(); header.declareNamespace(ns); } // retrieve all child nodes (including any text nodes) // and re-attach to header block Iterator children = element.getChildren(); while (children.hasNext()) { OMNode child = (OMNode) children.next(); child.detach(); header.addChild(child); } element.detach(); soapHeader.build(); header.setProcessed(); } if (header.isProcessed()) { processedHeaderQNames.add(element.getQName()); } } } XMLStreamReader reader = ((OMElement) doc.getDocumentElement()).getXMLStreamReader(); StAXSOAPModelBuilder stAXSOAPModelBuilder = new StAXSOAPModelBuilder(reader, null); SOAPEnvelope envelope = stAXSOAPModelBuilder.getSOAPEnvelope(); // Set the processed flag of the processed headers SOAPHeader header = envelope.getHeader(); for (Iterator iter = processedHeaderQNames.iterator(); iter.hasNext(); ) { QName name = (QName) iter.next(); Iterator omKids = header.getChildrenWithName(name); if (omKids.hasNext()) { ((SOAPHeaderBlock) omKids.next()).setProcessed(); } } envelope.build(); return envelope; } catch (FactoryConfigurationError e) { throw new WSSecurityException(e.getMessage()); } } else { try { ByteArrayOutputStream os = new ByteArrayOutputStream(); XMLUtils.outputDOM(doc.getDocumentElement(), os, true); ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray()); StAXSOAPModelBuilder stAXSOAPModelBuilder = new StAXSOAPModelBuilder( XMLInputFactory.newInstance().createXMLStreamReader(bais), null); return stAXSOAPModelBuilder.getSOAPEnvelope(); } catch (Exception e) { throw new WSSecurityException(e.getMessage()); } } }