---
title: "读取oracle-agile plm 的bom 并 expand"
author: "maxwell"
date: "2008-08-20T10:30:44Z"
tags: []
slug: "oracle-agile-plm-bom-expand"
draft: false
lastmod: "2008-08-20T10:30:44Z"
id: 230386
url: "https://maxwell.iteye.com/blog/230386"
---

package com.agile.test;

/\**  
 * Created by IntelliJ IDEA.  
 * User: 

 * Date: Aug 19, 2008  
 * Time: 12:45:44 PM  
 * To change this template use File | Settings | File Templates.  
 \*/  
import com.agile.px.\*;  
import com.agile.api.\*;

import java.util.List;

public class HWPX implements ICustomAction{

    public ActionResult doAction(IAgileSession agileSession,  
                                       INode node,  
                                       IDataObject affectedObject) {

        try {  
            IItem part = null;  
            if(affectedObject!=null) {  
                part = (IItem)agileSession.getObject(IItem.OBJECT\_TYPE,affectedObject.getObjectId());  
            }  
            int size = 0;  
            if(part!=null) {  
                size = countBom(part);  
                return new ActionResult(ActionResult.STRING, String.valueOf(size));  
            }  
            return new ActionResult(ActionResult.STRING, "hello world!!!");  
        } catch (APIException e) {  
            return new ActionResult(ActionResult.STRING, "Exception");  
        }  
    }  
    private int countBom(IItem part) throws APIException{  
        ITable bomTable = part.getTable(ItemConstants.TABLE\_BOM);  
        int size = 1;  
        ITwoWayIterator iter = bomTable.getTableIterator();

        while(iter.hasNext()) {  
            IRow subRow = (IRow)iter.next();  
            IItem subPart = (IItem)subRow.getReferent();  
            size = size + countBom(subPart);  
        }

        return size;  
    }  
}