org.apache.axiom.om.OMElement.findNamespace()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(58)

本文整理了Java中org.apache.axiom.om.OMElement.findNamespace()方法的一些代码示例,展示了OMElement.findNamespace()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OMElement.findNamespace()方法的具体详情如下:
包路径:org.apache.axiom.om.OMElement
类名称:OMElement
方法名:findNamespace

OMElement.findNamespace介绍

[英]Finds a namespace with the given uri and prefix, in the scope of the hierarchy.

Searches from the current element and goes up the hiararchy until a match is found. If no match is found, returns null.

Either prefix or uri should be null. Results are undefined if both are specified.
[中]在层次结构的范围内查找具有给定uri和前缀的命名空间。
从当前元素开始搜索,并向上搜索Hiarrchy,直到找到匹配项。如果未找到匹配项,则返回null。
前缀或uri都应为空。如果两者都指定,则结果未定义。

代码示例

代码示例来源:origin: holodeck-b2b/Holodeck-B2B

/**
 * Gets an {@link OMNamespace} object for the ebMS 3 namespace for the SOAP envelope the given element is contained
 * in.
 *
 * @param   e     The element that is contained in the SOAP envelop
 * @return        The {@link OMNamespace} object for the ebMS 3 namespace if it was declared in this SOAP message;
 *                <code>null</code> if there is no namespace declared for ebMS 3
 */
public static OMNamespace getEbms3Namespace(final OMElement e) {
  return e.findNamespace(EbMSConstants.EBMS3_NS_URI, null);
}

代码示例来源:origin: org.apache.abdera/abdera-parser

private static OMNamespace getOrCreateNamespace(QName qname, OMContainer parent, OMFactory factory) {
  String namespace = qname.getNamespaceURI();
  String prefix = qname.getPrefix();
  if (parent != null && parent instanceof OMElement) {
    OMNamespace ns = ((OMElement)parent).findNamespace(namespace, prefix);
    if (ns != null)
      return ns;
  }
  return factory.createOMNamespace(qname.getNamespaceURI(), qname.getPrefix());
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-impl

protected String doGetPrefix(String namespaceURI) {
  OMNamespace ns = element.findNamespace(namespaceURI, null);
  return ns == null ? null : ns.getPrefix();
}

代码示例来源:origin: org.apache.ws.commons.axiom/om-aspects

protected String doGetPrefix(String namespaceURI) {
  OMNamespace ns = element.findNamespace(namespaceURI, null);
  return ns == null ? null : ns.getPrefix();
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-common-impl

protected String doGetPrefix(String namespaceURI) {
  OMNamespace ns = element.findNamespace(namespaceURI, null);
  return ns == null ? null : ns.getPrefix();
}

代码示例来源:origin: org.wso2.carbon.registry/org.wso2.carbon.registry.common.ui

public static String getNamespaceURI(String name, OMElement currentElement) {
  String prefix = getPrefix(name);
  OMNamespace namespace = null;
  if (prefix != null) {
    namespace = currentElement.findNamespace(null, prefix);
  } else {
    // if the prefix is null we can't assume the namespace is null
    namespace = currentElement.getDefaultNamespace();
  }
  if (namespace == null) {
    return null;
  }
  return namespace.getNamespaceURI();
}

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-impl

OMNamespace ns;
if (attrNamespaceURI.length() > 0) {
  ns = element.findNamespace(attrNamespaceURI, attrPrefix);
  if (ns == null) {
    throw new SAXException("Unbound namespace " + attrNamespaceURI);

代码示例来源:origin: org.apache.ws.commons.axiom/om-aspects

OMNamespace ns;
if (attrNamespaceURI.length() > 0) {
  ns = element.findNamespace(attrNamespaceURI, attrPrefix);
  if (ns == null) {
    throw new SAXException("Unbound namespace " + attrNamespaceURI);

代码示例来源:origin: org.springframework.ws/org.springframework.ws

public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
  OMContainer parent = getParent();
  OMElement element = factory.createOMElement(localName, null, parent);
  for (Map.Entry<String, String> entry : namespaces.entrySet()) {
    String prefix = entry.getKey();
    if (prefix.length() == 0) {
      element.declareDefaultNamespace((String) entry.getValue());
    }
    else {
      element.declareNamespace((String) entry.getValue(), prefix);
    }
  }
  QName qname = QNameUtils.toQName(uri, qName);
  element.setLocalName(qname.getLocalPart());
  element.setNamespace(element.findNamespace(qname.getNamespaceURI(), qname.getPrefix()));
  for (int i = 0; i < atts.getLength(); i++) {
    QName attrName = QNameUtils.toQName(atts.getURI(i), atts.getQName(i));
    String value = atts.getValue(i);
    if (!atts.getQName(i).startsWith("xmlns")) {
      OMNamespace namespace = factory.createOMNamespace(attrName.getNamespaceURI(), attrName.getPrefix());
      OMAttribute attribute = factory.createOMAttribute(attrName.getLocalPart(), namespace, value);
      element.addAttribute(attribute);
    }
  }
  elements.add(element);
}

代码示例来源:origin: com.github.veithen.visualwas/connector

public void createOMElement(OMElement operationElement, OMNamespace xsiNS, Object value, InvocationContextImpl context) {
    OMFactory factory = operationElement.getOMFactory();
    OMElement element = factory.createOMElement(name, null, operationElement);
    QName type;
    // TODO: quick and dirty hack: the WebSphere SOAP connector doesn't use xsi:nil in all cases; once we have determined the logic (and have enough test cases), this needs to be cleaned up
    if (value != null || (valueHandler instanceof ObjectHandler && ((ObjectHandler)valueHandler).getType().isArray())) {
      type = valueHandler.setValue(element, value, context);
    } else {
      element.addAttribute("nil", "true", xsiNS);
      type = valueHandler.getXMLType(context);
    }
    OMNamespace ns = element.findNamespace(type.getNamespaceURI(), null);
    if (ns == null) {
      ns = element.declareNamespace(type.getNamespaceURI(), type.getPrefix());
    }
    // TODO: parameter order of addAttribute is not consistent
    // TODO: there should be a method to add an attribute with a QName value
    element.addAttribute("type", ns.getPrefix() + ":" + type.getLocalPart(), xsiNS);
  }
}

代码示例来源:origin: org.wso2.bpel/ode-bpel-epr

String attrPrefix = attr.getPrefix();
if (attrNs != null)
  attrOmNs = omElement.findNamespace(attrNs,null);
if (attrOmNs == null && attrPrefix != null)
  attrOmNs = omElement.findNamespace(null, attrPrefix);
omElement.addAttribute(attr.getLocalName(), attr.getValue(), attrOmNs);

代码示例来源:origin: org.apache.ws.commons.axiom/axiom-api

/**
 * Method processAttributes.
 *
 * @param node
 */
protected void processAttributes(OMElement node) {
  int attribCount = parser.getAttributeCount();
  for (int i = 0; i < attribCount; i++) {
    String uri = parser.getAttributeNamespace(i);
    String prefix = parser.getAttributePrefix(i);
    OMNamespace namespace = null;
    if (uri != null && uri.length() > 0) {
      // prefix being null means this elements has a default namespace or it has inherited
      // a default namespace from its parent
      namespace = node.findNamespace(uri, prefix);
      if (namespace == null) {
        namespace = node.declareNamespace(uri, prefix);
      }
    }
    // todo if the attributes are supposed to namespace qualified all the time
    // todo then this should throw an exception here
    OMAttribute attr = node.addAttribute(parser.getAttributeLocalName(i),
             parser.getAttributeValue(i), namespace);
    attr.setAttributeType(parser.getAttributeType(i));
    if (attr instanceof OMAttributeEx) {
      ((OMAttributeEx)attr).setSpecified(parser.isAttributeSpecified(i));
    }
  }
}

相关文章

微信公众号

最新文章

更多