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.axis2.jaxws.marshaller.impl.alt.RPCLitMethodMarshaller.java
/** * @param opDesc/* www .j a va2 s .c om*/ * @return qualified qname to use in the rpc message to represent the operation (per WSI BP) */ private static QName getRPCOperationQName(OperationDescription opDesc, boolean isRequest) { QName qName = opDesc.getName(); String localPart = qName.getLocalPart(); String uri = null; if (isRequest) { uri = opDesc.getBindingInputNamespace(); } else { uri = opDesc.getBindingOutputNamespace(); } String prefix = "rpcOp"; // Prefer using an actual prefix qName = new QName(uri, localPart, prefix); return qName; }
From source file:org.apache.axis2.jaxws.message.impl.BlockImpl.java
/** * Called if we have passed the pivot point but someone wants to output the block. The actual * block implementation may choose to override this setting. *//*from w w w. j a v a 2s . com*/ protected XMLStreamReader _postPivot_getXMLStreamReader() throws XMLStreamException, WebServiceException { if (log.isDebugEnabled()) { QName theQName = isQNameAvailable() ? getQName() : new QName("unknown"); log.debug( "The Block for " + theQName + " is already consumed and therefore it is only partially read."); log.debug("If you need this block preserved, please set the " + Constants.SAVE_REQUEST_MSG + " property on the MessageContext."); } QName qName = getQName(); String text = ""; if (qName.getNamespaceURI().length() > 0) { text = "<prefix:" + qName.getLocalPart() + " xmlns:prefix='" + qName.getNamespaceURI() + "'/>"; } else { text = "<" + qName.getLocalPart() + "/>"; } StringReader sr = new StringReader(text); return StAXUtils.createXMLStreamReader(sr); }
From source file:org.apache.axis2.jaxws.message.impl.XMLSpineImpl.java
public void setBodyBlock(int index, Block block) throws WebServiceException { // Forces the parser to read all of the blocks getNumBodyBlocks();//from w w w.java 2s . c o m block.setParent(getParent()); OMElement bElement = _getBodyBlockParent(); OMElement om = this._getChildOMElement(bElement, index); // The block is supposed to represent a single element. // But if it does not represent an element , the following will fail. QName qName = block.getQName(); OMNamespace ns = soapFactory.createOMNamespace(qName.getNamespaceURI(), qName.getPrefix()); OMElement newOM = _createOMElementFromBlock(qName.getLocalPart(), ns, block, soapFactory, false); if (om == null) { bElement.addChild(newOM); } else { om.insertSiblingBefore(newOM); om.detach(); } }
From source file:org.apache.axis2.jaxws.message.impl.XMLSpineImpl.java
public void setBodyBlock(Block block) throws WebServiceException { // Forces the parser to read all of the blocks getNumBodyBlocks();/*from ww w.j av a2s . co m*/ block.setParent(getParent()); // Remove all of the children OMElement bElement = _getBodyBlockParent(); Iterator it = bElement.getChildren(); while (it.hasNext()) { it.next(); it.remove(); } if (block.isElementData()) { // If the block is element data then it is safe to create // an OMElement representing the block // The block is supposed to represent a single element. // But if it does not represent an element , the following will fail. QName qName = block.getQName(); OMNamespace ns = soapFactory.createOMNamespace(qName.getNamespaceURI(), qName.getPrefix()); OMElement newOM = _createOMElementFromBlock(qName.getLocalPart(), ns, block, soapFactory, false); bElement.addChild(newOM); } else { // This needs to be fixed, but for now we will require that there must be an // element...otherwise no block is added try { QName qName = block.getQName(); OMNamespace ns = soapFactory.createOMNamespace(qName.getNamespaceURI(), qName.getPrefix()); OMElement newOM = _createOMElementFromBlock(qName.getLocalPart(), ns, block, soapFactory, false); bElement.addChild(newOM); } catch (Throwable t) { if (log.isDebugEnabled()) { log.debug("An attempt was made to pass a Source or String that does not " + "have an xml element. Processing continues with an empty payload."); } } } }
From source file:org.apache.axis2.jaxws.message.impl.XMLSpineImpl.java
public void setOperationElement(QName operationQName) { OMElement opElement = this._getBodyBlockParent(); if (!(opElement instanceof SOAPBody)) { OMNamespace ns = soapFactory.createOMNamespace(operationQName.getNamespaceURI(), operationQName.getPrefix()); opElement.setLocalName(operationQName.getLocalPart()); opElement.setNamespace(ns);//from w w w. j a v a 2s.c om // Necessary to avoid duplicate namespaces later. opElement.declareNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi"); } }
From source file:org.apache.axis2.jaxws.message.impl.XMLSpineImpl.java
private Block _getBlockFromOMElement(OMElement om, Object context, BlockFactory blockFactory, boolean setComplete) throws WebServiceException { try {// ww w . j a va 2s . co m QName qName = om.getQName(); OMNamespace ns = om.getNamespace(); // Save the ROLE // TODO Need to do the same for RELAY and MUSTUNDERSTAND String role = null; if (om instanceof SOAPHeaderBlock) { role = ((SOAPHeaderBlock) om).getRole(); } /* TODO We could gain performance if OMSourcedElement exposed a getDataSource method if (om instanceof OMSourcedElementImpl && ((OMSourcedElementImpl) om).getDataSource() instanceof Block) { Block oldBlock = (Block) ((OMSourcedElementImpl) om).getDataSource(); Block newBlock = blockFactory.createFrom(oldBlock, context); newBlock.setParent(getParent()); if (newBlock != oldBlock) { // Replace the OMElement with the OMSourcedElement that delegates to the block OMSourcedElementImpl newOM = new OMSourcedElementImpl(qName, soapFactory, newBlock); om.insertSiblingBefore(newOM); om.detach(); } return newBlock; } */ // Create the block Block block = blockFactory.createFrom(om, context, qName); block.setParent(getParent()); if (om instanceof SOAPHeaderBlock) { block.setProperty(SOAPHeaderBlock.ROLE_PROPERTY, role); } // Get the business object to force a parse block.getBusinessObject(false); // Replace the OMElement with the OMSourcedElement that delegates to the block OMElement newOM = _createOMElementFromBlock(qName.getLocalPart(), ns, block, soapFactory, (om.getParent() instanceof SOAPHeader)); om.insertSiblingBefore(newOM); // We want to set the om element and its parents to complete to // shutdown the parsing. if (setComplete) { // Get the root of the document OMElement root = om; while (root.getParent() instanceof OMElement) { root = (OMElement) root.getParent(); } try { if (!root.isComplete() && root.getBuilder() != null && !root.getBuilder().isCompleted()) { // Forward the parser to the end so it will close while (root.getBuilder().next() != XMLStreamConstants.END_DOCUMENT) { //do nothing } } } catch (Exception e) { // Log and continue if (log.isDebugEnabled()) { log.debug("Builder next error:" + e.getMessage()); log.trace(JavaUtils.stackToString(e)); } } OMContainer o = om; while (o != null && o instanceof OMContainerEx) { ((OMContainerEx) o).setComplete(true); if ((o instanceof OMNode) && (((OMNode) o).getParent()) instanceof OMContainer) { o = ((OMNode) o).getParent(); } else { o = null; } } } om.detach(); return block; } catch (XMLStreamException xse) { throw ExceptionFactory.makeWebServiceException(xse); } }
From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java
/** * Create child SOAPElement//from ww w . ja v a 2s .c o m * * @param parent SOAPElement * @param name Name * @return */ protected SOAPElement createElement(SOAPElement parent, QName qName) throws SOAPException { SOAPElement child; if (parent instanceof SOAPEnvelope) { if (qName.getNamespaceURI().equals(parent.getNamespaceURI())) { if (qName.getLocalPart().equals("Body")) { child = ((SOAPEnvelope) parent).addBody(); } else { child = ((SOAPEnvelope) parent).addHeader(); } } else { child = parent.addChildElement(qName); } } else if (parent instanceof SOAPBody) { if (qName.getNamespaceURI().equals(parent.getNamespaceURI()) && qName.getLocalPart().equals("Fault")) { child = ((SOAPBody) parent).addFault(); } else { child = ((SOAPBody) parent).addBodyElement(qName); } } else if (parent instanceof SOAPHeader) { child = ((SOAPHeader) parent).addHeaderElement(qName); } else if (parent instanceof SOAPFault) { // This call assumes that the addChildElement implementation // is smart enough to add "Detail" or "SOAPFaultElement" objects. child = parent.addChildElement(qName); } else if (parent instanceof Detail) { child = ((Detail) parent).addDetailEntry(qName); } else { child = parent.addChildElement(qName); } return child; }
From source file:org.apache.axis2.jaxws.message.util.impl.SAAJConverterImpl.java
/** * add attributes/*w ww .java2s.c om*/ * * @param NameCreator nc * @param element SOAPElement which is the target of the new attributes * @param reader XMLStreamReader whose cursor is at START_ELEMENT * @throws SOAPException */ protected void addAttributes(NameCreator nc, SOAPElement element, XMLStreamReader reader) throws SOAPException { if (log.isDebugEnabled()) { log.debug("addAttributes: Entry"); } // Add the attributes from the reader int size = reader.getAttributeCount(); for (int i = 0; i < size; i++) { QName qName = reader.getAttributeName(i); String prefix = reader.getAttributePrefix(i); String value = reader.getAttributeValue(i); Name name = nc.createName(qName.getLocalPart(), prefix, qName.getNamespaceURI()); element.addAttribute(name, value); try { if (log.isDebugEnabled()) { log.debug("Setting attrType"); } String namespace = qName.getNamespaceURI(); Attr attr = null; // This is an org.w3c.dom.Attr if (namespace == null || namespace.length() == 0) { attr = element.getAttributeNode(qName.getLocalPart()); } else { attr = element.getAttributeNodeNS(namespace, qName.getLocalPart()); } if (attr != null) { String attrType = reader.getAttributeType(i); attr.setUserData(SAAJConverter.OM_ATTRIBUTE_KEY, attrType, null); if (log.isDebugEnabled()) { log.debug("Storing attrType in UserData: " + attrType); } } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("An error occured while processing attrType: " + e.getMessage()); } } } if (log.isDebugEnabled()) { log.debug("addAttributes: Exit"); } }
From source file:org.apache.axis2.jaxws.spi.handler.BaseHandlerResolver.java
/** * The old match algorithm combines the namespace and localpart into * a single string to do the matching. Unfortunately this will cause * the pure wildcard (*) pattern to fail. And in addition, it may cause * other patterns to succeed. Prefer the doesPatternMatch_Official algorithm * @param portInfoQName// w ww. j a va 2 s .co m * @param pattern * @return */ private static boolean doesPatternMatch_Old(QName portInfoQName, QName pattern) { if (pattern == null) return true; // build up the strings according to the regular expression defined at http://java.sun.com/xml/ns/javaee/javaee_web_services_1_2.xsd // use the prefix, not the literal namespace String portInfoPrefix = portInfoQName.getNamespaceURI(); //Prefix(); String portInfoLocalPart = portInfoQName.getLocalPart(); String portInfoString = ((portInfoPrefix == null) || (portInfoPrefix.equals(""))) ? "" : portInfoPrefix + ":"; portInfoString += portInfoLocalPart; String patternStringPrefix = pattern.getNamespaceURI(); //Prefix(); String patternInfoLocalPart = pattern.getLocalPart(); String patternString = ((patternStringPrefix == null) || (patternStringPrefix.equals(""))) ? "" : patternStringPrefix + ":"; patternString += patternInfoLocalPart; // now match the portInfoQName to the user pattern // But first, convert the user pattern to a regular expression. Remember, the only non-QName character allowed is "*", which // is a wildcard, with obvious restrictions on what characters can match (for example, a .java filename cannot contain perentheses). // We'll just use part of the above reg ex to form the appropriate restrictions on the user-specified "*" character: Pattern userp = Pattern.compile(patternString.replace("*", "(\\w|\\.|-|_)*")); Matcher userm = userp.matcher(portInfoString); boolean match = userm.matches(); if (log.isDebugEnabled()) { if (!match) { log.debug("Pattern match failed: \"" + portInfoString + "\" does not match \"" + patternString + "\""); } else { log.debug("Pattern match succeeded: \"" + portInfoString + "\" matches \"" + patternString + "\""); } } return match; }
From source file:org.apache.axis2.jaxws.spi.handler.BaseHandlerResolver.java
/** * Determine if the indicated qname matches the pattern * @param qName//from ww w . j av a2s.c om * @param pattern * @return */ private static boolean doesPatternMatch_Official(QName qName, QName pattern) { if (log.isDebugEnabled()) { log.debug("entry pattern=" + pattern + " qname=" + qName); } if (pattern == null) { if (log.isDebugEnabled()) { log.debug("Successful Match: Pattern is null"); } return true; } // Do a pattern match on the local part of the qname. String patternLocalPart = pattern.getLocalPart(); String localPart = qName.getLocalPart(); // Replace the wildcard (*) references in the QName with an appropriate regular expression. String regEx = patternLocalPart.replace("*", "(\\w|\\.|-|_)*"); Pattern userp = Pattern.compile(regEx); Matcher userm = userp.matcher(localPart); boolean match = userm.matches(); if (!match) { if (log.isDebugEnabled()) { log.debug("No Match: The local name does not match the regex pattern: " + regEx); } return false; } // Now do the matching with the namespace. // If the entire pattern is a wildcard (*), then all namespaces are acceptable. // For example: // <port-name-pattern>*</port-name-pattern> // // In such cases, the assumption is that the pattern namespace will be empty. String patternNamespace = pattern.getNamespaceURI(); String namespace = qName.getNamespaceURI(); if (patternNamespace.length() == 0) { // By definition, a namespace will never be null. if (log.isDebugEnabled()) { log.debug("Successful Match: The local name matches and the pattern namespace is empty."); } return true; } // If a namespace is specified, it will be done via a prefix. For example: // <port-name-pattern>p:MyPortName</port-name-pattern> // Thus according to the current pattern structure there is no way to // specify wildcards for the namespace portion of the match if (patternNamespace.equals(namespace)) { if (log.isDebugEnabled()) { log.debug("Successful Match: The local names and namespaces match."); } return true; } if (log.isDebugEnabled()) { log.debug("No Match"); } return false; }