⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lineitem.java

📁 21天精通Java,这是一本英文书
💻 JAVA
字号:
package webservices;

import java.util.Iterator;

import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPException;

public class LineItem
{
  private String _productCode;
  private int _quantity;
  
  public LineItem(String productCode, int quantity)
  {
    _productCode = productCode;
    _quantity = quantity;
  }
  
  public LineItem()
  {
  }
  
  public String getProductCode()
  {
    return _productCode;
  }
  
  public void setProductCode(String productCode)
  {
    _productCode = productCode;
  }

  public int getQuantity()
  {
    return _quantity;
  }
  
  public void setQuantity(int quantity)
  {
    _quantity = quantity;
  }
  
  public void marshal(SOAPElement parent, SOAPEnvelope envelope) throws SOAPException
  {
    Name itemName = envelope.createName("item",
                                        "acme",
                                        "http://acme.com/commerce");
    SOAPElement item = parent.addChildElement(itemName);

    Name productCodeName = envelope.createName("productCode",
                                               "acme",
                                               "http://acme.com/commerce");
    SOAPElement productCode = item.addChildElement(productCodeName);
    productCode.addTextNode(_productCode);

    Name quantityName = envelope.createName("quantity",
                                            "acme",
                                            "http://acme.com/commerce");
    SOAPElement quantity = item.addChildElement(quantityName);
    quantity.addTextNode("" + _quantity);
  }
  
  public void unmarshal(SOAPElement lineItem, SOAPEnvelope envelope) throws SOAPException
  {
    Name productCodeName = envelope.createName("productCode",
                                               "acme",
                                               "http://acme.com/commerce");
    Name quantityName = envelope.createName("quantity",
                                            "acme",
                                            "http://acme.com/commerce");

    Iterator iterator = lineItem.getChildElements(productCodeName);
    
    if (iterator.hasNext())
    {
      SOAPElement element = (SOAPElement)iterator.next();
      _productCode = element.getValue();
    }
    else
    {
      throw new SOAPException("line item SOAPElement is missing product code");
    }

    iterator = lineItem.getChildElements(quantityName);
    
    if (iterator.hasNext())
    {
      SOAPElement element = (SOAPElement)iterator.next();
      _quantity = Integer.parseInt(element.getValue());
    }
    else
    {
      throw new SOAPException("line item SOAPElement is missing quantity");
    }
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -