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

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

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

OMElement.cloneOMElement介绍

[英]Clones this element and its descendants using default options. This method has the same effect as #clone(OMCloneOptions) with default options.
[中]使用默认选项克隆此元素及其子体。此方法与带有默认选项的#clone(OMCloneOptions)具有相同的效果。

代码示例

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

public void addElementToContent(final OMElement element) {
  if (element != null) {
    if (content == null)
      this.content = new ArrayList<>();
    this.content.add(element.cloneOMElement());
  }
}

代码示例来源:origin: wso2/wso2-synapse

/**
 * @param element      XML element
 * @param outputStream Output Stream to write the converted JSON representation.
 * @throws AxisFault
 * @deprecated Use {@link org.apache.synapse.commons.json.JsonUtil#writeAsJson(org.apache.axiom.om.OMElement, java.io.OutputStream)}
 */
public static void toJson(OMElement element, OutputStream outputStream) throws AxisFault {
  JsonUtil.writeAsJson(element.cloneOMElement(), outputStream);
}

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

public void setContent(final Iterator<OMElement> content) {
  if (!Utils.isNullOrEmpty(content)) {
    this.content = new ArrayList<>();
    while (content.hasNext())
      this.content.add(content.next().cloneOMElement());
  } else
    this.content = null;
}

代码示例来源:origin: wso2/wso2-synapse

/**
 * Converts an XML element to its JSON representation and returns it as a String.
 *
 * @param element OMElement to be converted to JSON.
 * @return A String builder instance that contains the converted JSON string.
 */
public static StringBuilder toJsonString(OMElement element) throws AxisFault {
  if (element == null) {
    return new StringBuilder("{}");
  }
  org.apache.commons.io.output.ByteArrayOutputStream byteStream =
      new org.apache.commons.io.output.ByteArrayOutputStream();
  writeAsJson(element.cloneOMElement(), byteStream);
  return new StringBuilder(new String(byteStream.toByteArray()));
}

代码示例来源:origin: org.apache.tuscany.sca/tuscany-databinding-axiom

@Override
public Object copy(Object source,
          DataType sourceDataType,
          DataType targetDataType,
          Operation sourceOperation,
          Operation targetOperation) {
  if ( OMElement.class.isAssignableFrom(source.getClass()) ) {
    try {
      OMElement sourceElement = (OMElement)source;
      return sourceElement.cloneOMElement();
    } catch ( Exception e ) {
      throw new IllegalArgumentException(e);
    }
  }
  return super.copy(source, sourceDataType, targetDataType, sourceOperation, targetOperation);
}

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

@SuppressWarnings("unchecked")
private static OMElement stripNamespace(OMElement element) {
  OMElement parent = OM.createOMElement(new QName("", element.getLocalName()));
  Iterator<OMElement> iter = (Iterator<OMElement>) element.getChildElements();
  while (iter.hasNext()) {
    OMElement child = iter.next();
    child = child.cloneOMElement();
    parent.addChild(child);
  }
  return parent;
}

代码示例来源:origin: org.apache.synapse/synapse-core

public Endpoint create(TemplateEndpoint templateEndpoint, Properties properties) {
  // first go through all the elements and replace with the parameters
  OMElement clonedElement = element.cloneOMElement();
  replaceElement(templateEndpoint, clonedElement);
  return EndpointFactory.getEndpointFromElement(clonedElement, false, properties);
}

代码示例来源:origin: org.apache.synapse/synapse-core

private Object getResultValue(MessageContext synCtx) {
  if (value != null) {
    return value;
  } else if (valueElement != null) {
    // Need to take a clone of the element, otherwise same reference is shared across all the requests
    return valueElement.cloneOMElement();
  } else {
    return convertValue(expression.stringValueOf(synCtx), type);
  }
}

代码示例来源:origin: wso2/wso2-synapse

public Endpoint create(TemplateEndpoint templateEndpoint, Properties properties) {
  // first go through all the elements and replace with the parameters
  OMElement clonedElement = element.cloneOMElement();
  replaceElement(templateEndpoint, clonedElement);
  return EndpointFactory.getEndpointFromElement(clonedElement, false, properties);
}

代码示例来源:origin: wso2/wso2-synapse

private Object getResultValue(MessageContext synCtx) {
  if (value != null) {
    return value;
  } else if (valueElement != null) {
    //Need to clone to prevent same reference sharing accross all requests
    return valueElement.cloneOMElement();
  } else {
    if(expression != null) {
      return convertValue(expression.stringValueOf(synCtx), type);
    }
  }
  return null;
}

代码示例来源:origin: org.apache.sandesha2/sandesha2-core

public static EndpointReference cloneEPR (EndpointReference epr) {
  EndpointReference newEPR = new EndpointReference (epr.getAddress());
  Map<QName, OMElement> referenceParams = epr.getAllReferenceParameters();
  
  if (referenceParams != null) {
    for (Iterator<Entry<QName, OMElement>> entries = referenceParams.entrySet().iterator(); entries
        .hasNext();) {
      Entry<QName, OMElement> entry = entries.next();
      Object referenceParam = entry.getValue();
      if (referenceParam instanceof OMElement) {
        OMElement clonedElement = ((OMElement) referenceParam)
            .cloneOMElement();
        clonedElement.setText("false");
        newEPR.addReferenceParameter(clonedElement);
      }
    }
  }
  
  return newEPR;
}

代码示例来源:origin: org.apache.tuscany.sca/tuscany-binding-jms-runtime

@Override
public Object wrap(OMElement template, OMElement os) {
  OMElement wrapper;
  if (os != null) {
    OMNamespace ns = os.declareNamespace(template.getNamespace().getNamespaceURI(), "");
    wrapper = factory.createOMElement(template.getLocalName(), ns);
    wrapper.addChild(os);
  } else {
    wrapper = template.cloneOMElement();
  }
  return wrapper;
}

代码示例来源:origin: org.wso2.carbon.commons/org.wso2.carbon.reporting.template.core

private void addParam(String dsname, String className) throws JaxenException {
  AXIOMXPath xpathExpression = new AXIOMXPath("//a:parameter");
  xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports");
  OMElement documentElement = document.getOMDocumentElement();
  List nodeList = xpathExpression.selectNodes(documentElement);
  OMElement element = (OMElement) nodeList.get(0);
  OMElement newParam = element.cloneOMElement();
  newParam.getAttribute(new QName("name")).setAttributeValue(dsname);
  newParam.getAttribute(new QName("class")).setAttributeValue(className);
  documentElement.addChild(newParam);
}

代码示例来源:origin: org.apache.synapse/synapse-core

private void addCustomHeader(MessageContext synCtx, String value) {
  SOAPEnvelope env = synCtx.getEnvelope();
  if (env == null) {
    return;
  }
  SOAPFactory fac = (SOAPFactory) env.getOMFactory();
  SOAPHeader header = env.getOrCreateHeader();
  if (!isImplicit()) {
    SOAPHeaderBlock hb = header.addHeaderBlock(qName.getLocalPart(),
        fac.createOMNamespace(qName.getNamespaceURI(), qName.getPrefix()));
    hb.setText(value);
  } else if (hasEmbeddedXml()) {
    for (OMElement e : embeddedXmlContent) {
      // Don't attach the original OMElement here.
      // If another mediator down the line, changes the OM, we are in trouble.
      header.addChild(e.cloneOMElement());
    }
  }
}

代码示例来源:origin: org.wso2.carbon.commons/org.wso2.carbon.reporting.template.core

private void addDataSourcesParams() throws JaxenException {
  OMElement documentElement = document.getOMDocumentElement();
  OMElement tempDocument = documentElement.cloneOMElement();
  refreshReport();
  int count = 0;
  for (String aSubReport : subReports) {
    count++;
    if (count != 1) addParam("TableDataSource" + count, "net.sf.jasperreports.engine.JRDataSource");
    dataSourceNames[count-1] = "TableDataSource"+count;
    addParam(aSubReport, "net.sf.jasperreports.engine.JasperReport");
  }
  reloadContent(tempDocument);
}

代码示例来源:origin: wso2/wso2-synapse

public OMElement serializeEndpointTemplate(Template template, OMElement parent) {
    OMElement templateElement =
        fac.createOMElement("template", SynapseConstants.SYNAPSE_OMNAMESPACE);

    templateElement.addAttribute(fac.createOMAttribute("name", nullNS, template.getName()));

    List<String> parameters = template.getParameters();
    for (String entry : parameters) {
      OMElement paramElement = fac.createOMElement(
          new QName(SynapseConstants.SYNAPSE_NAMESPACE, "parameter"));

      paramElement.addAttribute(fac.createOMAttribute("name", nullNS, entry));
      templateElement.addChild(paramElement);
    }

    templateElement.addChild(template.getElement().cloneOMElement());

    if (parent != null) {
      parent.addChild(templateElement);
    }

    return templateElement;
  }
}

代码示例来源:origin: org.apache.synapse/synapse-core

public OMElement serializeEndpointTemplate(Template template, OMElement parent) {
    OMElement templateElement =
        fac.createOMElement("template", SynapseConstants.SYNAPSE_OMNAMESPACE);

    templateElement.addAttribute(fac.createOMAttribute("name", nullNS, template.getName()));

    List<String> parameters = template.getParameters();
    for (String entry : parameters) {
      OMElement paramElement = fac.createOMElement("parameter",
          SynapseConstants.SYNAPSE_OMNAMESPACE);
      paramElement.addAttribute(fac.createOMAttribute("name", nullNS, entry));
      templateElement.addChild(paramElement);
    }

    templateElement.addChild(template.getElement().cloneOMElement());

    if (parent != null) {
      parent.addChild(templateElement);
    }

    return templateElement;
  }
}

代码示例来源:origin: wso2/wso2-synapse

public void testEntrySerializationScenarioOne() throws Exception {
  String inputXml = "<localEntry xmlns=\"http://ws.apache.org/ns/synapse\" key=\"key\" " +
    "><description>description</description><foo/></localEntry>";
  OMElement inputOM = createOMElement(inputXml);
  Entry entry = EntryFactory.createEntry(inputOM.cloneOMElement(), new Properties());
  OMElement resultOM = EntrySerializer.serializeEntry(entry, null);
  assertTrue(compare(resultOM, inputOM));
}

代码示例来源:origin: wso2/wso2-synapse

public void testEntrySerializationScenarioThree() throws Exception {
    String inputXml = "<localEntry xmlns=\"http://ws.apache.org/ns/synapse\" key=\"key\" " +
      "/>";
    OMElement inputOM = createOMElement(inputXml);
    Entry entry = EntryFactory.createEntry(inputOM.cloneOMElement(), new Properties());
    OMElement resultOM = EntrySerializer.serializeEntry(entry, null);
    assertTrue(compare(resultOM, inputOM));
  }
}

代码示例来源:origin: wso2/wso2-synapse

public void testEntrySerializationScenarioTwo() throws Exception {
  String inputXml = "<localEntry xmlns=\"http://ws.apache.org/ns/synapse\" key=\"key\"" +
    "><description>description</description></localEntry>";
  OMElement inputOM = createOMElement(inputXml);
  Entry entry = EntryFactory.createEntry(inputOM.cloneOMElement(), new Properties());
  OMElement resultOM = EntrySerializer.serializeEntry(entry, null);
  assertTrue(compare(resultOM, inputOM));
}

相关文章

微信公众号

最新文章

更多