WEB开发网
开发学院软件开发Java Java Web 服务,第 2 部分: 深度探索 Axis2:AXIO... 阅读

Java Web 服务,第 2 部分: 深度探索 Axis2:AXIOM

 2009-11-05 00:00:00 来源:WEB开发网   
核心提示: 清单 4. 导航 AXIOM/***Walksubtreeforelement.Thisrecursivelywalksthroughthedocument*nodesunderanelement,accumulatingsummaryinformation.**@paramelementele


清单 4. 导航 AXIOM
  /** 
   * Walk subtree for element. This recursively walks through the document 
   * nodes under an element, accumulating summary information. 
   * 
   * @param element element to be walked 
   * @param summary document summary information 
   */ 
  protected void walkElement(OMElement element, DocumentSummary summary) { 
 
    // include attribute values in summary 
    for (Iterator iter = element.getAllAttributes(); iter.hasNext();) { 
      OMAttribute attr = (OMAttribute)iter.next(); 
      summary.addAttribute(attr.getAttributeValue().length()); 
    } 
 
    // loop through children 
    for (Iterator iter = element.getChildren(); iter.hasNext();) { 
 
      // handle child by type 
      OMNode child = (OMNode)iter.next(); 
      int type = child.getType(); 
      if (type == OMNode.TEXT_NODE) { 
        summary.addContent(((OMText)child).getText().length()); 
      } else if (type == OMNode.ELEMENT_NODE) { 
        summary.addElements(1); 
        walkElement((OMElement)child, summary); 
      } 
 
    } 
  } 
 
  /** 
   * Walk and summarize document. This method walks through the nodes 
   * of the document, accumulating summary information. 
   * 
   * @param doc document representation to be walked 
   * @param summary output document summary information 
   */ 
  protected void walk(Object doc, DocumentSummary summary) { 
    summary.addElements(1); 
    walkElement(((OMDocument)doc).getOMDocumentElement(), summary); 
  } 

上一页  2 3 4 5 6 7 8 9 10  下一页

Tags:Java Web 服务

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接